From 5034f8009069a5ac7c2aa53b3815bab8029fbdac Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Mon, 27 Dec 2021 16:27:10 +0100 Subject: [PATCH] Add aspect ratio to scaling --- .../scale_to_size/scale_to_size.inx | 41 ++++++++++--------- .../scale_to_size/scale_to_size.py | 12 ++++-- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/extensions/fablabchemnitz/scale_to_size/scale_to_size.inx b/extensions/fablabchemnitz/scale_to_size/scale_to_size.inx index 840a7649..7c471b7e 100644 --- a/extensions/fablabchemnitz/scale_to_size/scale_to_size.inx +++ b/extensions/fablabchemnitz/scale_to_size/scale_to_size.inx @@ -1,7 +1,7 @@ - Scale To Size (Replaced by default transform scale) - fablabchemnitz.de.scale_to_size + Scale To Size (Replaced by default transform scale) + fablabchemnitz.de.scale_to_size @@ -9,22 +9,23 @@ - 10.0 - - - - - - - - all - - - - - - - + 10.0 + + + + + + true + + + all + + + + + + + \ No newline at end of file diff --git a/extensions/fablabchemnitz/scale_to_size/scale_to_size.py b/extensions/fablabchemnitz/scale_to_size/scale_to_size.py index cb39997b..3a04e191 100644 --- a/extensions/fablabchemnitz/scale_to_size/scale_to_size.py +++ b/extensions/fablabchemnitz/scale_to_size/scale_to_size.py @@ -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()