sanitize drawing scale
This commit is contained in:
parent
dd81cbfb99
commit
035f441e7a
@ -2,7 +2,7 @@
|
|||||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||||
<name>Normalize Drawing Scale</name>
|
<name>Normalize Drawing Scale</name>
|
||||||
<id>fablabchemnitz.de.normalize_drawing_scale</id>
|
<id>fablabchemnitz.de.normalize_drawing_scale</id>
|
||||||
<param name="remove_viewbox" type="bool" gui-text="Remove viewBox and set document units to px" gui-description="Removes viewBox attribute from svg:svg. Warning: this disabled the feature to change the document units to anything else than px unit.">false</param>
|
<label appearance="header">This will also reset the viewbox origin to x0,y0</label>
|
||||||
<param name="target_scale" type="float" min="0.001" max="9999.000" precision="3" gui-text="Target scale (%)" gui-description="Default is 100%">100.0</param>
|
<param name="target_scale" type="float" min="0.001" max="9999.000" precision="3" gui-text="Target scale (%)" gui-description="Default is 100%">100.0</param>
|
||||||
<effect needs-live-preview="false">
|
<effect needs-live-preview="false">
|
||||||
<object-type>all</object-type>
|
<object-type>all</object-type>
|
||||||
|
@ -7,7 +7,6 @@ from lxml import etree
|
|||||||
class NormalizeDrawingScale(inkex.EffectExtension):
|
class NormalizeDrawingScale(inkex.EffectExtension):
|
||||||
|
|
||||||
def add_arguments(self, pars):
|
def add_arguments(self, pars):
|
||||||
pars.add_argument('--remove_viewbox', type=inkex.Boolean, default=True)
|
|
||||||
pars.add_argument('--target_scale', type=float, default=100.0)
|
pars.add_argument('--target_scale', type=float, default=100.0)
|
||||||
|
|
||||||
def effect(self):
|
def effect(self):
|
||||||
@ -48,9 +47,9 @@ class NormalizeDrawingScale(inkex.EffectExtension):
|
|||||||
#inkex.errormsg("visualScaleX: {:0.6f}".format(visualScaleX))
|
#inkex.errormsg("visualScaleX: {:0.6f}".format(visualScaleX))
|
||||||
#inkex.errormsg("formatScaleX: {:0.6f}".format(formatScaleX))
|
#inkex.errormsg("formatScaleX: {:0.6f}".format(formatScaleX))
|
||||||
|
|
||||||
if inkscapeScale == targetScale: #strange rule. might break sth.
|
#if inkscapeScale == targetScale: #strange rule. might break sth.
|
||||||
inkex.utils.debug("Nothing to do. Scale is already 100%")
|
# inkex.utils.debug("Nothing to do. Scale is already 100%")
|
||||||
return
|
# return
|
||||||
|
|
||||||
if visualScaleX == 0.0: #seems there is no viewBox attribute, then ...
|
if visualScaleX == 0.0: #seems there is no viewBox attribute, then ...
|
||||||
#inkex.errormsg("viewBox attribute is missing in svg:svg. Applying new one ...")
|
#inkex.errormsg("viewBox attribute is missing in svg:svg. Applying new one ...")
|
||||||
@ -59,7 +58,6 @@ class NormalizeDrawingScale(inkex.EffectExtension):
|
|||||||
if round(visualScaleX, 5) != targetScale or self.options.remove_viewbox is True:
|
if round(visualScaleX, 5) != targetScale or self.options.remove_viewbox is True:
|
||||||
#set scale to 100% (we adjust viewBox)
|
#set scale to 100% (we adjust viewBox)
|
||||||
sc = (1 / (targetScale / inkscapeScale))
|
sc = (1 / (targetScale / inkscapeScale))
|
||||||
if self.options.remove_viewbox is False:
|
|
||||||
viewBoxNew = '0 0 {} {}'.format(docWidth_fin / targetScale, docHeight_fin / targetScale)
|
viewBoxNew = '0 0 {} {}'.format(docWidth_fin / targetScale, docHeight_fin / targetScale)
|
||||||
#inkex.errormsg("viewBox modifying to: {}".format(viewBoxNew))
|
#inkex.errormsg("viewBox modifying to: {}".format(viewBoxNew))
|
||||||
#inkex.errormsg("width modifying to: {}{}".format(docWidth_fin, format_units))
|
#inkex.errormsg("width modifying to: {}{}".format(docWidth_fin, format_units))
|
||||||
@ -67,13 +65,7 @@ class NormalizeDrawingScale(inkex.EffectExtension):
|
|||||||
self.svg.set('viewBox', viewBoxNew)
|
self.svg.set('viewBox', viewBoxNew)
|
||||||
self.svg.set('width', "{}{}".format(docWidth_fin, format_units))
|
self.svg.set('width', "{}{}".format(docWidth_fin, format_units))
|
||||||
self.svg.set('height', "{}{}".format(docHeight_fin, format_units))
|
self.svg.set('height', "{}{}".format(docHeight_fin, format_units))
|
||||||
else:
|
|
||||||
#inkex.errormsg("viewBox popping; setting back to px ...")
|
|
||||||
self.svg.pop('viewBox')
|
|
||||||
self.document.getroot().set('inkscape:document-units', 'px')
|
|
||||||
self.svg.set('width', docWidth_fin)
|
|
||||||
self.svg.set('height', docHeight_fin)
|
|
||||||
namedView.attrib[inkex.addNS('document-units', 'inkscape')] = 'px'
|
|
||||||
|
|
||||||
translation_matrix = [[sc, 0.0, 0.0], [0.0, sc, 0.0]]
|
translation_matrix = [[sc, 0.0, 0.0], [0.0, sc, 0.0]]
|
||||||
#select each top layer and apply the transformation to scale
|
#select each top layer and apply the transformation to scale
|
||||||
|
Loading…
Reference in New Issue
Block a user