added custom scale to normalize
This commit is contained in:
parent
b7c9e074bb
commit
b423526564
@ -3,6 +3,7 @@
|
|||||||
<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>
|
<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>
|
||||||
|
<param name="target_scale" type="float" min="0.001" max="9999.000" 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>
|
||||||
<effects-menu>
|
<effects-menu>
|
||||||
|
@ -8,6 +8,7 @@ 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('--remove_viewbox', type=inkex.Boolean, default=True)
|
||||||
|
pars.add_argument('--target_scale', type=float, default=100.0)
|
||||||
|
|
||||||
def effect(self):
|
def effect(self):
|
||||||
namedView = self.document.getroot().find(inkex.addNS('namedview', 'sodipodi'))
|
namedView = self.document.getroot().find(inkex.addNS('namedview', 'sodipodi'))
|
||||||
@ -18,11 +19,17 @@ class NormalizeDrawingScale(inkex.EffectExtension):
|
|||||||
vxMin, vyMin, vxMax, vyMax = self.svg.get_viewbox()
|
vxMin, vyMin, vxMax, vyMax = self.svg.get_viewbox()
|
||||||
vxTotal = vxMax - vxMin
|
vxTotal = vxMax - vxMin
|
||||||
vScaleX = self.svg.unittouu(str(vxTotal / self.svg.width) + doc_units)
|
vScaleX = self.svg.unittouu(str(vxTotal / self.svg.width) + doc_units)
|
||||||
if round(vScaleX, 5) != 1.0 or self.options.remove_viewbox is True:
|
if vScaleX == 0.0: #seems there is no viewBox attribute, then ...
|
||||||
|
#self.msg("viewBox attribute is missing in svg:svg. Applying new one ...")
|
||||||
|
vScaleX = 1.0 #this is the case we deal with px as display unit and we removed the viewBox
|
||||||
|
self.svg.set('viewBox', '0 0 {} {}'.format(targetScale * docWidth, targetScale * docHeight))
|
||||||
|
|
||||||
|
targetScale = self.options.target_scale / 100
|
||||||
|
if round(vScaleX, 5) != targetScale or self.options.remove_viewbox is True:
|
||||||
|
|
||||||
#set scale to 100% (we adjust viewBox)
|
#set scale to 100% (we adjust viewBox)
|
||||||
if self.options.remove_viewbox is False:
|
if self.options.remove_viewbox is False:
|
||||||
self.svg.set('viewBox', '0 0 {} {}'.format(docWidth, docHeight))
|
self.svg.set('viewBox', '0 0 {} {}'.format(targetScale * docWidth, targetScale * docHeight))
|
||||||
else:
|
else:
|
||||||
self.svg.pop('viewBox')
|
self.svg.pop('viewBox')
|
||||||
self.document.getroot().set('inkscape:document-units', 'px')
|
self.document.getroot().set('inkscape:document-units', 'px')
|
||||||
@ -30,7 +37,7 @@ class NormalizeDrawingScale(inkex.EffectExtension):
|
|||||||
self.svg.set('height', docHeight)
|
self.svg.set('height', docHeight)
|
||||||
|
|
||||||
namedView.attrib[inkex.addNS('document-units', 'inkscape')] = 'px'
|
namedView.attrib[inkex.addNS('document-units', 'inkscape')] = 'px'
|
||||||
translation_matrix = [[1/vScaleX, 0.0, 0.0], [0.0, 1/vScaleX, 0.0]]
|
translation_matrix = [[targetScale / vScaleX, 0.0, 0.0], [0.0, targetScale / vScaleX, 0.0]]
|
||||||
|
|
||||||
#select each top layer and apply the transformation to scale
|
#select each top layer and apply the transformation to scale
|
||||||
processed = []
|
processed = []
|
||||||
|
Reference in New Issue
Block a user