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