Add aspect ratio to scaling
This commit is contained in:
parent
f83deb7b33
commit
5034f80090
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||||
<name>Scale To Size (Replaced by default transform scale)</name>
|
<name>Scale To Size (Replaced by default transform scale)</name>
|
||||||
<id>fablabchemnitz.de.scale_to_size</id>
|
<id>fablabchemnitz.de.scale_to_size</id>
|
||||||
<param name="unit" gui-text="Unit" type="optiongroup" appearance="combo">
|
<param name="unit" gui-text="Unit" type="optiongroup" appearance="combo">
|
||||||
<option value="mm">mm</option>
|
<option value="mm">mm</option>
|
||||||
<option value="cm">cm</option>
|
<option value="cm">cm</option>
|
||||||
@ -9,22 +9,23 @@
|
|||||||
<option value="pt">pt</option>
|
<option value="pt">pt</option>
|
||||||
<option value="px">px</option>
|
<option value="px">px</option>
|
||||||
</param>
|
</param>
|
||||||
<param name="expected_size" type="float" min="0.001" max="10000.0" gui-text="Expected size: ">10.0</param>
|
<param name="expected_size" type="float" min="0.001" max="10000.0" gui-text="Expected size: ">10.0</param>
|
||||||
<param name="scale_type" type="optiongroup" appearance="combo" gui-text="Scaling type:">
|
<param name="scale_type" type="optiongroup" appearance="combo" gui-text="Scaling type:">
|
||||||
<option value="Horizontal">Horizontal</option>
|
<option value="Horizontal">Horizontal</option>
|
||||||
<option value="Vertical">Vertical</option>
|
<option value="Vertical">Vertical</option>
|
||||||
<option value="Uniform">Uniform</option>
|
<option value="Uniform">Uniform</option>
|
||||||
</param>
|
</param>
|
||||||
<label>This effect will measure the selected paths and scale them to have the given size. Does not work for objects (you need to convert)!</label>
|
<param name="keep_aspect" type="bool" gui-text="Keep aspect ratio" gui-description="Does not apply for uniform scaling.">true</param>
|
||||||
<effect>
|
<label>This effect will measure the selected paths and scale them to have the given size. Does not work for objects (you need to convert)!</label>
|
||||||
<object-type>all</object-type>
|
<effect>
|
||||||
<effects-menu>
|
<object-type>all</object-type>
|
||||||
<submenu name="FabLab Chemnitz">
|
<effects-menu>
|
||||||
<submenu name="Transformations"/>
|
<submenu name="FabLab Chemnitz">
|
||||||
</submenu>
|
<submenu name="Transformations" />
|
||||||
</effects-menu>
|
</submenu>
|
||||||
</effect>
|
</effects-menu>
|
||||||
<script>
|
</effect>
|
||||||
<command location="inx" interpreter="python">scale_to_size.py</command>
|
<script>
|
||||||
</script>
|
<command location="inx" interpreter="python">scale_to_size.py</command>
|
||||||
|
</script>
|
||||||
</inkscape-extension>
|
</inkscape-extension>
|
@ -17,6 +17,7 @@ class ScaleToSize(inkex.EffectExtension):
|
|||||||
|
|
||||||
def add_arguments(self, pars):
|
def add_arguments(self, pars):
|
||||||
pars.add_argument('--unit')
|
pars.add_argument('--unit')
|
||||||
|
pars.add_argument("--keep_aspect", type=inkex.Boolean, default=True, help="Does not apply for uniform scaling")
|
||||||
pars.add_argument("--expected_size", type=float, default=1.0, help="The expected size of the object")
|
pars.add_argument("--expected_size", type=float, default=1.0, help="The expected size of the object")
|
||||||
pars.add_argument("--scale_type", default="Horizontal", help="Scale type (Uniform, Horizontal, Vertical)")
|
pars.add_argument("--scale_type", default="Horizontal", help="Scale type (Uniform, Horizontal, Vertical)")
|
||||||
pars.add_argument("--description")
|
pars.add_argument("--description")
|
||||||
@ -37,11 +38,16 @@ class ScaleToSize(inkex.EffectExtension):
|
|||||||
bbox = element.bounding_box()
|
bbox = element.bounding_box()
|
||||||
new_horiz_scale = self.options.expected_size * unit_factor / bbox.width
|
new_horiz_scale = self.options.expected_size * unit_factor / bbox.width
|
||||||
new_vert_scale = self.options.expected_size * unit_factor / bbox.height
|
new_vert_scale = self.options.expected_size * unit_factor / bbox.height
|
||||||
|
|
||||||
if self.options.scale_type == "Horizontal":
|
if self.options.scale_type == "Horizontal":
|
||||||
translation_matrix = [[new_horiz_scale, 0.0, 0.0], [0.0, 1.0, 0.0]]
|
if self.options.keep_aspect is False:
|
||||||
|
translation_matrix = [[new_horiz_scale, 0.0, 0.0], [0.0, 1.0, 0.0]]
|
||||||
|
else:
|
||||||
|
translation_matrix = [[new_horiz_scale, 0.0, 0.0], [0.0, new_horiz_scale, 0.0]]
|
||||||
elif self.options.scale_type == "Vertical":
|
elif self.options.scale_type == "Vertical":
|
||||||
translation_matrix = [[1.0, 0.0, 0.0], [0.0, new_vert_scale, 0.0]]
|
if self.options.keep_aspect is False:
|
||||||
|
translation_matrix = [[1.0, 0.0, 0.0], [0.0, new_vert_scale, 0.0]]
|
||||||
|
else:
|
||||||
|
translation_matrix = [[new_vert_scale, 0.0, 0.0], [0.0, new_vert_scale, 0.0]]
|
||||||
else: #Uniform
|
else: #Uniform
|
||||||
translation_matrix = [[new_horiz_scale, 0.0, 0.0], [0.0, new_vert_scale, 0.0]]
|
translation_matrix = [[new_horiz_scale, 0.0, 0.0], [0.0, new_vert_scale, 0.0]]
|
||||||
element.transform = Transform(translation_matrix) * element.composed_transform()
|
element.transform = Transform(translation_matrix) * element.composed_transform()
|
||||||
|
Reference in New Issue
Block a user