Code

add a function to pull some info from the sodipodi:namedview
authoracspike <acspike@users.sourceforge.net>
Sun, 28 May 2006 03:41:31 +0000 (03:41 +0000)
committeracspike <acspike@users.sourceforge.net>
Sun, 28 May 2006 03:41:31 +0000 (03:41 +0000)
share/extensions/inkex.py

index b8bba3803860d9d3b74154709d3768f91da4ba1b..41fdcd95991c47995414dfc121148370ab3b7632 100755 (executable)
@@ -85,6 +85,21 @@ class Effect:
             stream = sys.stdin
         self.document = reader.fromStream(stream)
         stream.close()
+    def getposinlayer(self):
+        ctx = xml.xpath.Context.Context(self.document,processorNss=NSS)
+        #defaults
+        self.current_layer = self.document.documentElement
+        self.view_center = (0.0,0.0)
+        
+        layername = xml.xpath.Evaluate('//sodipodi:namedview/@inkscape:current-layer',self.document,context=ctx)[0].value
+        layer = xml.xpath.Evaluate('//g[@id="%s"]' % layername,self.document,context=ctx)[0]
+        if layer:
+            self.current_layer = layer
+            
+        x = xml.xpath.Evaluate('//sodipodi:namedview/@inkscape:cx',self.document,context=ctx)[0].value
+        y = xml.xpath.Evaluate('//sodipodi:namedview/@inkscape:cy',self.document,context=ctx)[0].value
+        if x and y:
+            self.view_center = (float(x),float(y))
     def getselected(self):
         """Collect selected nodes"""
         for id in self.options.ids:
@@ -98,6 +113,7 @@ class Effect:
         """Affect an SVG document with a callback effect"""
         self.getoptions()
         self.parse()
+        self.getposinlayer()
         self.getselected()
         self.effect()
         self.output()