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"?>
|
||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||
<name>Scale To Size (Replaced by default transform scale)</name>
|
||||
<id>fablabchemnitz.de.scale_to_size</id>
|
||||
<name>Scale To Size (Replaced by default transform scale)</name>
|
||||
<id>fablabchemnitz.de.scale_to_size</id>
|
||||
<param name="unit" gui-text="Unit" type="optiongroup" appearance="combo">
|
||||
<option value="mm">mm</option>
|
||||
<option value="cm">cm</option>
|
||||
@ -9,22 +9,23 @@
|
||||
<option value="pt">pt</option>
|
||||
<option value="px">px</option>
|
||||
</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:">
|
||||
<option value="Horizontal">Horizontal</option>
|
||||
<option value="Vertical">Vertical</option>
|
||||
<option value="Uniform">Uniform</option>
|
||||
</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>
|
||||
<effect>
|
||||
<object-type>all</object-type>
|
||||
<effects-menu>
|
||||
<submenu name="FabLab Chemnitz">
|
||||
<submenu name="Transformations"/>
|
||||
</submenu>
|
||||
</effects-menu>
|
||||
</effect>
|
||||
<script>
|
||||
<command location="inx" interpreter="python">scale_to_size.py</command>
|
||||
</script>
|
||||
<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:">
|
||||
<option value="Horizontal">Horizontal</option>
|
||||
<option value="Vertical">Vertical</option>
|
||||
<option value="Uniform">Uniform</option>
|
||||
</param>
|
||||
<param name="keep_aspect" type="bool" gui-text="Keep aspect ratio" gui-description="Does not apply for uniform scaling.">true</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>
|
||||
<effect>
|
||||
<object-type>all</object-type>
|
||||
<effects-menu>
|
||||
<submenu name="FabLab Chemnitz">
|
||||
<submenu name="Transformations" />
|
||||
</submenu>
|
||||
</effects-menu>
|
||||
</effect>
|
||||
<script>
|
||||
<command location="inx" interpreter="python">scale_to_size.py</command>
|
||||
</script>
|
||||
</inkscape-extension>
|
@ -17,6 +17,7 @@ class ScaleToSize(inkex.EffectExtension):
|
||||
|
||||
def add_arguments(self, pars):
|
||||
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("--scale_type", default="Horizontal", help="Scale type (Uniform, Horizontal, Vertical)")
|
||||
pars.add_argument("--description")
|
||||
@ -37,11 +38,16 @@ class ScaleToSize(inkex.EffectExtension):
|
||||
bbox = element.bounding_box()
|
||||
new_horiz_scale = self.options.expected_size * unit_factor / bbox.width
|
||||
new_vert_scale = self.options.expected_size * unit_factor / bbox.height
|
||||
|
||||
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":
|
||||
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
|
||||
translation_matrix = [[new_horiz_scale, 0.0, 0.0], [0.0, new_vert_scale, 0.0]]
|
||||
element.transform = Transform(translation_matrix) * element.composed_transform()
|
||||
|
Reference in New Issue
Block a user