Code

Extensions. Color marker improvements (Bug #692582, Color markers to match stroke...
authorJazzyNico <nicoduf@yahoo.fr>
Wed, 22 Dec 2010 17:38:42 +0000 (18:38 +0100)
committerJazzyNico <nicoduf@yahoo.fr>
Wed, 22 Dec 2010 17:38:42 +0000 (18:38 +0100)
share/extensions/markers_strokepaint.inx
share/extensions/markers_strokepaint.py

index 50c1a1d7ebef781ad2d7e3ab3fffb7552cd1425f..d67430c6032ef3db8c34179e2ff0e77a2735c0f5 100644 (file)
@@ -1,9 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
-     <_name>Color Markers to Match Stroke</_name>
+    <_name>Color Markers to Match Stroke</_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>
+    <dependency type="executable" location="extensions">markers_strokepaint.py</dependency>
+    <dependency type="executable" location="extensions">inkex.py</dependency>
+    <param name="type" type="enum" _gui-text="Replace marker fill with:">
+        <_item value="stroke">stroke color</_item>
+        <_item value="fill">fill color</_item>
+        <_item value="white">opaque white</_item>
+        <_item value="transparency">transparency</_item>
+    </param>
+    <param name="alpha" type="boolean" _gui-text="Assign alpha">true</param>
     <effect>
                <object-type>all</object-type>
                <effects-menu>
index 5f85d69db44df9cb791a901f0c79972cc7c83e89..bf5b530351f690b817f6c7fb4ff22f5d166e0d1d 100644 (file)
@@ -26,8 +26,16 @@ class MyEffect(inkex.Effect):
         self.OptionParser.add_option("-m", "--modify",
                         action="store", type="inkbool", 
                         dest="modify", default=False,
-                        help="do not create a copy, modify the markers")
-        
+                        help="Do not create a copy, modify the markers")
+        self.OptionParser.add_option("-t", "--type",
+                        action="store", type="string", 
+                        dest="fill_type", default="stroke",
+                        help="Replace the marker fill with the object stroke or fill color")
+        self.OptionParser.add_option("-a", "--alpha",
+                        action="store", type="inkbool", 
+                        dest="assign_alpha", default=True,
+                        help="Assign the object fill and stroke alpha to the marker")
+
     def effect(self):
         defs = self.xpathSingle('/svg:svg//svg:defs')
         if defs == None:
@@ -42,10 +50,18 @@ class MyEffect(inkex.Effect):
                 continue
             
             stroke = style.get('stroke', '#000000')
-            
+            stroke_opacity = style.get('stroke-opacity', '1')
+            if (self.options.fill_type == "white"):
+                fill = "#FFFFFF"
+                fill_opacity = "1"
+            else:
+                fill = style.get('fill', '#000000')
+                fill_opacity = style.get('fill-opacity', '1')
+
             for mprop in mprops:
                 if style.has_key(mprop) and style[mprop] != 'none'and style[mprop][:5] == 'url(#':
                     marker_id = style[mprop][5:-1]
+
                     try:
                         old_mnode = self.xpathSingle('/svg:svg//svg:marker[@id="%s"]' % marker_id)
                         if not self.options.modify:
@@ -68,8 +84,20 @@ class MyEffect(inkex.Effect):
                         cstyle = simplestyle.parseStyle(child.get('style'))
                         if ('stroke' in cstyle and cstyle['stroke'] != 'none') or 'stroke' not in cstyle:
                             cstyle['stroke'] = stroke
+                            if (self.options.assign_alpha):
+                                cstyle['stroke-opacity'] = stroke_opacity
                         if ('fill' in cstyle and cstyle['fill'] != 'none') or 'fill' not in cstyle:
-                            cstyle['fill'] = stroke
+                            if (self.options.fill_type == "fill" or self.options.fill_type == "white" ):
+                                cstyle['fill'] = fill
+                                if (self.options.assign_alpha):
+                                    cstyle['fill-opacity'] = fill_opacity
+                            elif (self.options.fill_type == "stroke"):
+                                cstyle['fill'] = stroke
+                                if (self.options.assign_alpha):
+                                    cstyle['fill-opacity'] = stroke_opacity
+                            else:
+                                cstyle['fill'] = "none";
+                                cstyle['fill-opacity'] = "0"
                         child.set('style',simplestyle.formatStyle(cstyle))
             node.set('style',simplestyle.formatStyle(style))