From e761d8b42c178d3e9a940963234d4cd62c777f59 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Tue, 22 Nov 2022 10:21:45 +0100 Subject: Convert to gradient blocks extension (#1844) --- lib/extensions/__init__.py | 2 ++ lib/extensions/gradient_blocks.py | 69 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 lib/extensions/gradient_blocks.py (limited to 'lib/extensions') diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py index f1837c59..5c702ce8 100644 --- a/lib/extensions/__init__.py +++ b/lib/extensions/__init__.py @@ -21,6 +21,7 @@ from .embroider_settings import EmbroiderSettings from .flip import Flip from .generate_palette import GeneratePalette from .global_commands import GlobalCommands +from .gradient_blocks import GradientBlocks from .input import Input from .install import Install from .install_custom_palette import InstallCustomPalette @@ -79,6 +80,7 @@ __all__ = extensions = [StitchPlanPreview, RemoveEmbroiderySettings, Cleanup, BreakApart, + GradientBlocks, ApplyThreadlist, InstallCustomPalette, GeneratePalette, diff --git a/lib/extensions/gradient_blocks.py b/lib/extensions/gradient_blocks.py new file mode 100644 index 00000000..5159149f --- /dev/null +++ b/lib/extensions/gradient_blocks.py @@ -0,0 +1,69 @@ +# Authors: see git history +# +# Copyright (c) 2010 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +from math import degrees + +from inkex import PathElement, errormsg + +from ..elements import FillStitch +from ..elements.gradient_fill import gradient_shapes_and_attributes +from ..i18n import _ +from ..svg import get_correction_transform +from ..svg.tags import INKSTITCH_ATTRIBS +from .base import InkstitchExtension + + +class GradientBlocks(InkstitchExtension): + ''' + This will break apart fill objects with a gradient fill into solid color blocks with end_row_spacing. + ''' + + def effect(self): + if not self.svg.selection: + errormsg(_("Please select at least one object with a gradient fill.")) + return + + if not self.get_elements(): + return + + elements = [element for element in self.elements if (isinstance(element, FillStitch) and self.has_gradient_color(element))] + if not elements: + errormsg(_("Please select at least one object with a gradient fill.")) + return + + for element in elements: + parent = element.node.getparent() + correction_transform = get_correction_transform(element.node) + style = element.node.style + index = parent.index(element.node) + fill_shapes, attributes = gradient_shapes_and_attributes(element, element.shape) + # reverse order so we can always insert with the same index number + fill_shapes.reverse() + attributes.reverse() + for i, shape in enumerate(fill_shapes): + style['fill'] = attributes[i]['color'] + end_row_spacing = attributes[i]['end_row_spacing'] or None + angle = degrees(attributes[i]['angle']) + d = "M " + " ".join([f'{x}, {y}' for x, y in list(shape.exterior.coords)]) + " Z" + block = PathElement(attrib={ + "id": self.uniqueId("path"), + "style": str(style), + "transform": correction_transform, + "d": d, + INKSTITCH_ATTRIBS['angle']: f'{angle: .2f}' + }) + if end_row_spacing: + block.set('inkstitch:end_row_spacing_mm', f'{end_row_spacing: .2f}') + block.set('inkstitch:underpath', False) + parent.insert(index, block) + parent.remove(element.node) + + def has_gradient_color(self, element): + return element.color.startswith('url') and "linearGradient" in element.color + + +if __name__ == '__main__': + e = GradientBlocks() + e.effect() -- cgit v1.2.3 From 43a31ba80ee844699a52341ff7d6ef6b881e6276 Mon Sep 17 00:00:00 2001 From: Claudine Peyrat <88194877+claudinepeyrat06@users.noreply.github.com> Date: Tue, 22 Nov 2022 10:46:44 +0100 Subject: Claudine/lettering with trims (#1866) * add trim after each letter allow to add a trim after each letter * add trim after letter, word or line rewriting everythng * style correction correcting all that is signaled by make style * corrections i don't understand why i add to modify get_command_pos in commands. If I don't i can not add a command at the end of a glyph that ends with a polyline (eg B from Fold) * replace checkbox with dropdown * rename variables in English * use same trim methods for auto_satin and non auto_satin * check if trim option is never strip lines of text Co-authored-by: Claudine Co-authored-by: Kaalleen Co-authored-by: Kaalleen <36401965+kaalleen@users.noreply.github.com> --- lib/extensions/lettering.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'lib/extensions') diff --git a/lib/extensions/lettering.py b/lib/extensions/lettering.py index c870a764..40fd48af 100644 --- a/lib/extensions/lettering.py +++ b/lib/extensions/lettering.py @@ -71,8 +71,9 @@ class LetteringFrame(wx.Frame): self.back_and_forth_checkbox = wx.CheckBox(self, label=_("Stitch lines of text back and forth")) self.back_and_forth_checkbox.Bind(wx.EVT_CHECKBOX, lambda event: self.on_change("back_and_forth", event)) - self.trim_checkbox = wx.CheckBox(self, label=_("Add trims")) - self.trim_checkbox.Bind(wx.EVT_CHECKBOX, lambda event: self.on_change("trim", event)) + self.trim_option_choice = wx.Choice(self, choices=["Never", "after each line", "after each word", "after each letter"], + name=_("Add trim after")) + self.trim_option_choice.Bind(wx.EVT_CHOICE, lambda event: self.on_trim_option_change(event)) # text editor self.text_input_box = wx.StaticBox(self, wx.ID_ANY, label=_("Text")) @@ -105,7 +106,8 @@ class LetteringFrame(wx.Frame): "text": "", "back_and_forth": False, "font": None, - "scale": 100 + "scale": 100, + "trim_option": 0 }) if INKSTITCH_LETTERING in self.group.attrib: @@ -123,7 +125,7 @@ class LetteringFrame(wx.Frame): def apply_settings(self): """Make the settings in self.settings visible in the UI.""" self.back_and_forth_checkbox.SetValue(bool(self.settings.back_and_forth)) - self.trim_checkbox.SetValue(bool(self.settings.trim)) + self.trim_option_choice.SetSelection(self.settings.trim_option) self.set_initial_font(self.settings.font) self.text_editor.SetValue(self.settings.text) self.scale_spinner.SetValue(self.settings.scale) @@ -219,6 +221,10 @@ class LetteringFrame(wx.Frame): self.settings[attribute] = event.GetEventObject().GetValue() self.preview.update() + def on_trim_option_change(self, event=None): + self.settings.trim_option = self.trim_option_choice.GetCurrentSelection() + self.preview.update() + def on_font_changed(self, event=None): font = self.fonts.get(self.font_chooser.GetValue(), self.default_font) self.settings.font = font.marked_custom_font_id @@ -253,13 +259,6 @@ class LetteringFrame(wx.Frame): self.back_and_forth_checkbox.Disable() self.back_and_forth_checkbox.SetValue(False) - if font.auto_satin: - self.trim_checkbox.Enable() - self.trim_checkbox.SetValue(bool(self.settings.trim)) - else: - self.trim_checkbox.Disable() - self.trim_checkbox.SetValue(False) - self.update_preview() self.Layout() @@ -314,7 +313,9 @@ class LetteringFrame(wx.Frame): font = self.fonts.get(self.font_chooser.GetValue(), self.default_font) try: - font.render_text(self.settings.text, destination_group, back_and_forth=self.settings.back_and_forth, trim=self.settings.trim) + font.render_text(self.settings.text, destination_group, back_and_forth=self.settings.back_and_forth, + trim_option=self.settings.trim_option) + except FontError as e: if raise_error: inkex.errormsg(_("Error: Text cannot be applied to the document.\n%s") % e) @@ -400,7 +401,11 @@ class LetteringFrame(wx.Frame): # options left_option_sizer = wx.BoxSizer(wx.VERTICAL) left_option_sizer.Add(self.back_and_forth_checkbox, 1, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT, 5) - left_option_sizer.Add(self.trim_checkbox, 1, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT | wx.BOTTOM, 5) + + trim_option_sizer = wx.BoxSizer(wx.HORIZONTAL) + trim_option_sizer.Add(wx.StaticText(self, wx.ID_ANY, "Add trims"), 0, wx.LEFT | wx.ALIGN_CENTRE_VERTICAL, 5) + trim_option_sizer.Add(self.trim_option_choice, 1, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT | wx.BOTTOM, 5) + left_option_sizer.Add(trim_option_sizer, 0, wx.ALIGN_LEFT, 5) font_scale_sizer = wx.BoxSizer(wx.HORIZONTAL) font_scale_sizer.Add(wx.StaticText(self, wx.ID_ANY, "Scale"), 0, wx.LEFT | wx.ALIGN_CENTRE_VERTICAL, 0) -- cgit v1.2.3