renamed extension cleanup; fixed some handling of elements and styling
This commit is contained in:
parent
788e3cc4fb
commit
6a74979c53
@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||
<name>Fix Global Stroke Width / Opacity / Style</name>
|
||||
<name>Cleanup Styles</name>
|
||||
<id>fablabchemnitz.de.cleanup</id>
|
||||
<param name="stroke_width" type="float" precision="4" min="0" max="5" gui-text="Stroke width">0.1</param>
|
||||
<param name="stroke_width" type="float" precision="4" min="0.0000" max="5.0000" gui-text="Stroke width">0.1000</param>
|
||||
<param name="stroke_units" gui-text="Units" type="optiongroup" appearance="combo">
|
||||
<option value="px">px</option>
|
||||
<option value="pt">pt</option>
|
||||
@ -15,6 +15,7 @@
|
||||
<param name="reset_fill_attributes" type="bool" gui-text="Reset fill style attributes" gui-description="Sets 'fill:none;' to style attribute">true</param>
|
||||
<param name="apply_hairlines" type="bool" gui-text="Add additional hairline style" gui-description="Adds 'vector-effect:non-scaling-stroke;' and '-inkscape-stroke:hairline;' Hint: stroke-width is kept in background. All hairlines still have a valued width.">true</param>
|
||||
<param name="apply_black_strokes" type="bool" gui-text="Apply black strokes where strokes missing" gui-description="Adds 'stroke:#000000;' to style attribute">true</param>
|
||||
<label>This extension works on current selection or for complete document</label>
|
||||
<effect needs-live-preview="true">
|
||||
<object-type>all</object-type>
|
||||
<effects-menu>
|
||||
|
@ -48,6 +48,16 @@ class Cleanup(inkex.EffectExtension):
|
||||
|
||||
#stroke and fill styles can be included in style attribute or they can exist separately (can occure in older SVG files). We do not parse other attributes than style
|
||||
def changeStyle(self, node):
|
||||
nodeDict = []
|
||||
nodeDict.append(inkex.addNS('line','svg'))
|
||||
nodeDict.append(inkex.addNS('polyline','svg'))
|
||||
nodeDict.append(inkex.addNS('polygon','svg'))
|
||||
nodeDict.append(inkex.addNS('circle','svg'))
|
||||
nodeDict.append(inkex.addNS('ellipse','svg'))
|
||||
nodeDict.append(inkex.addNS('rect','svg'))
|
||||
nodeDict.append(inkex.addNS('path','svg'))
|
||||
nodeDict.append(inkex.addNS('g','svg'))
|
||||
if node.tag in nodeDict:
|
||||
if node.attrib.has_key('style'):
|
||||
style = node.get('style')
|
||||
if style:
|
||||
@ -57,9 +67,9 @@ class Cleanup(inkex.EffectExtension):
|
||||
if re.search('(;|^)stroke:(.*?)(;|$)', style) is None: #if "stroke" is None, add one. We need to distinguish because there's also attribute "-inkscape-stroke" that's why we check starting with ^ or ;
|
||||
style += 'stroke:none;'
|
||||
if "stroke-width:" not in style:
|
||||
style += 'stroke-width:' + str(self.svg.unittouu(str(self.options.stroke_width) + self.options.stroke_units)) + ';'
|
||||
style += 'stroke-width:{:1.4f};'.format(self.svg.unittouu(str(self.options.stroke_width) + self.options.stroke_units))
|
||||
if "stroke-opacity:" not in style:
|
||||
style += 'stroke-opacity:' + str(self.options.opacity / 100) + ';'
|
||||
style += 'stroke-opacity:{:1.1f};'.format(self.options.opacity / 100)
|
||||
|
||||
if self.options.apply_hairlines is True:
|
||||
if "vector-effect:non-scaling-stroke" not in style:
|
||||
@ -79,10 +89,10 @@ class Cleanup(inkex.EffectExtension):
|
||||
prop = prop.strip().lower()
|
||||
if prop == 'stroke-width':
|
||||
new_val = self.svg.unittouu(str(self.options.stroke_width) + self.options.stroke_units)
|
||||
declarations[i] = prop + ':' + str(new_val)
|
||||
declarations[i] = prop + ':{:1.4f}'.format(new_val)
|
||||
if prop == 'stroke-opacity':
|
||||
new_val = str(self.options.opacity / 100)
|
||||
declarations[i] = prop + ':' + new_val
|
||||
new_val = self.options.opacity / 100
|
||||
declarations[i] = prop + ':{:1.1f}'.format(new_val)
|
||||
if self.options.reset_style_attributes is True:
|
||||
if prop == 'stroke-dasharray':
|
||||
declarations[i] = ''
|
||||
|
Reference in New Issue
Block a user