Code

An extension script to recolor markers to match the path stroke color
authoracspike <acspike@users.sourceforge.net>
Thu, 20 Jul 2006 02:35:35 +0000 (02:35 +0000)
committeracspike <acspike@users.sourceforge.net>
Thu, 20 Jul 2006 02:35:35 +0000 (02:35 +0000)
share/extensions/markers_strokepaint.inx [new file with mode: 0644]
share/extensions/markers_strokepaint.py [new file with mode: 0644]

diff --git a/share/extensions/markers_strokepaint.inx b/share/extensions/markers_strokepaint.inx
new file mode 100644 (file)
index 0000000..2276898
--- /dev/null
@@ -0,0 +1,15 @@
+<inkscape-extension>\r
+     <_name>Markers to Stroke Paint</_name>\r
+    <id>org.ekips.filter.markers.strokepaint</id>\r
+       <dependency type="executable" location="extensions">markers_strokepaint.py</dependency>\r
+       <dependency type="executable" location="extensions">inkex.py</dependency>\r
+    <effect>\r
+               <object-type>all</object-type>\r
+               <effects-menu>\r
+                       <submenu _name="Modify Path"/>\r
+               </effects-menu>\r
+    </effect>\r
+    <script>\r
+        <command reldir="extensions" interpreter="python">markers_strokepaint.py</command>\r
+    </script>\r
+</inkscape-extension>\r
diff --git a/share/extensions/markers_strokepaint.py b/share/extensions/markers_strokepaint.py
new file mode 100644 (file)
index 0000000..f49a37a
--- /dev/null
@@ -0,0 +1,63 @@
+#!/usr/bin/env python \r
+'''\r
+Copyright (C) 2006 Aaron Spike, aaron@ekips.org\r
+\r
+This program is free software; you can redistribute it and/or modify\r
+it under the terms of the GNU General Public License as published by\r
+the Free Software Foundation; either version 2 of the License, or\r
+(at your option) any later version.\r
+\r
+This program is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+GNU General Public License for more details.\r
+\r
+You should have received a copy of the GNU General Public License\r
+along with this program; if not, write to the Free Software\r
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+'''\r
+import copy, inkex, simplestyle\r
+\r
+class MyEffect(inkex.Effect):\r
+    def __init__(self):\r
+        inkex.Effect.__init__(self)\r
+    def xpathSingle(self, path):\r
+        try:\r
+            retval = inkex.xml.xpath.Evaluate(path,self.document,context=self.ctx)[0]\r
+        except:\r
+            retval = None\r
+        return retval\r
+        \r
+    def effect(self):\r
+        self.ctx = inkex.xml.xpath.Context.Context(self.document,processorNss=inkex.NSS)\r
+        defs = self.xpathSingle('/svg/defs')  \r
+        for id, node in self.selected.iteritems():\r
+            mprops = ['marker-start','marker-mid','marker-end']\r
+            style = simplestyle.parseStyle(node.attributes.getNamedItem('style').value)\r
+            \r
+            try:\r
+                stroke = style['stroke']\r
+            except:\r
+                stroke = '#000000'\r
+            \r
+            for mprop in mprops:\r
+                if style.has_key(mprop) and style[mprop] != 'none'and style[mprop][:5] == 'url(#':\r
+                    marker_id = style[mprop][5:-1]\r
+                    old_mnode = self.xpathSingle('/svg/defs/marker[@id="%s"]' % marker_id)\r
+                    mnode = old_mnode.cloneNode(True)\r
+                    new_id = "%s%s" % (marker_id,2)\r
+                    style[mprop] = "url(#%s)" % new_id\r
+                    mnode.attributes.getNamedItem('id').value = new_id\r
+                    defs.appendChild(mnode)\r
+                    \r
+                    children = inkex.xml.xpath.Evaluate('/svg/defs/marker[@id="%s"]//*[@style]' % new_id,self.document,context=self.ctx)\r
+                    for child in children:\r
+                        cstyle = simplestyle.parseStyle(child.attributes.getNamedItem('style').value)\r
+                        if (cstyle.has_key('stroke') and cstyle['stroke'] != 'none') or not cstyle.has_key('stroke'):\r
+                                cstyle['stroke'] = stroke\r
+                        if (cstyle.has_key('fill') and cstyle['fill'] != 'none') or not cstyle.has_key('fill'):\r
+                                cstyle['fill'] = stroke\r
+                        child.attributes.getNamedItem('style').value = simplestyle.formatStyle(cstyle)\r
+            node.attributes.getNamedItem('style').value = simplestyle.formatStyle(style)\r
+e = MyEffect()\r
+e.affect()\r