summaryrefslogtreecommitdiff
path: root/lib/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'lib/extensions')
-rw-r--r--lib/extensions/commands_scale_symbols.py3
-rw-r--r--lib/extensions/gradient_blocks.py35
-rw-r--r--lib/extensions/update_svg.py25
3 files changed, 16 insertions, 47 deletions
diff --git a/lib/extensions/commands_scale_symbols.py b/lib/extensions/commands_scale_symbols.py
index 0e5f482a..fec8daf8 100644
--- a/lib/extensions/commands_scale_symbols.py
+++ b/lib/extensions/commands_scale_symbols.py
@@ -14,7 +14,8 @@ class CommandsScaleSymbols(InkstitchExtension):
self.arg_parser.add_argument("-s", "--size", dest="size", type=int, default=100)
def effect(self):
- size = self.options.size / 100
+ # by default commands are scaled down to 0.2
+ size = 0.2 * self.options.size / 100
# scale symbols
svg = self.document.getroot()
diff --git a/lib/extensions/gradient_blocks.py b/lib/extensions/gradient_blocks.py
index b87e5f9e..8e341cc8 100644
--- a/lib/extensions/gradient_blocks.py
+++ b/lib/extensions/gradient_blocks.py
@@ -9,27 +9,23 @@ from inkex import (DirectedLineSegment, LinearGradient, PathElement, Transform,
errormsg)
from shapely import geometry as shgeo
from shapely.affinity import rotate
-from shapely.geometry import Point
-from shapely.ops import nearest_points, split
+from shapely.ops import split
-from ..commands import add_commands
from ..elements import FillStitch
from ..i18n import _
from ..svg import PIXELS_PER_MM, get_correction_transform
from ..svg.tags import INKSTITCH_ATTRIBS
-from .commands import CommandsExtension
from .duplicate_params import get_inkstitch_attributes
+from .base import InkstitchExtension
-class GradientBlocks(CommandsExtension):
+class GradientBlocks(InkstitchExtension):
'''
This will break apart fill objects with a gradient fill into solid color blocks with end_row_spacing.
'''
- COMMANDS = ['starting_point', 'ending_point']
-
def __init__(self, *args, **kwargs):
- CommandsExtension.__init__(self, *args, **kwargs)
+ InkstitchExtension.__init__(self, *args, **kwargs)
self.arg_parser.add_argument("--notebook", type=str, default=0.0)
self.arg_parser.add_argument("--options", type=str, default=0.0)
self.arg_parser.add_argument("--info", type=str, default=0.0)
@@ -64,8 +60,6 @@ class GradientBlocks(CommandsExtension):
end_row_spacing = element.row_spacing / PIXELS_PER_MM * 2
end_row_spacing = f'{end_row_spacing: .2f}'
- previous_color = None
- previous_element = None
for i, shape in enumerate(fill_shapes):
color = attributes[i]['color']
style['fill'] = color
@@ -98,29 +92,8 @@ class GradientBlocks(CommandsExtension):
block.set('inkstitch:fill_underlay_row_spacing_mm', end_row_spacing)
parent.insert(index, block)
- if previous_color == color:
- self._add_block_commands(block, previous_element)
- previous_color = color
- previous_element = block
parent.remove(element.node)
- def _add_block_commands(self, block, previous_element):
- current = FillStitch(block)
- previous = FillStitch(previous_element)
- if previous.shape.is_empty or current.shape.is_empty:
- return
- nearest = nearest_points(current.shape, previous.shape)
- pos_current = self._get_command_postion(current, nearest[0])
- pos_previous = self._get_command_postion(previous, nearest[1])
- add_commands(current, ['ending_point'], pos_current)
- add_commands(previous, ['starting_point'], pos_previous)
-
- def _get_command_postion(self, fill, point):
- center = fill.shape.centroid
- line = DirectedLineSegment((center.x, center.y), (point.x, point.y))
- pos = line.point_at_length(line.length + 20)
- return Point(pos)
-
def _element_to_path(self, shape):
coords = list(shape.exterior.coords)
for interior in shape.interiors:
diff --git a/lib/extensions/update_svg.py b/lib/extensions/update_svg.py
index f620af2d..d51c1fa1 100644
--- a/lib/extensions/update_svg.py
+++ b/lib/extensions/update_svg.py
@@ -3,9 +3,6 @@
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
-from inkex import errormsg
-
-from ..i18n import _
from ..update import update_inkstitch_document
from .base import InkstitchExtension
@@ -14,24 +11,22 @@ class UpdateSvg(InkstitchExtension):
def __init__(self, *args, **kwargs):
InkstitchExtension.__init__(self, *args, **kwargs)
+ self.arg_parser.add_argument("--update-from", type=int, default=0, dest="update_from")
# inkstitch_svg_version history:
# 1 -> v3.0.0, May 2023
# 2 -> v.3.1.0 May 2024
-
- # TODO: When there are more legacy versions than only one, this can be transformed into a user input
- self.update_from = 0
+ # 3 -> v.3.2.0 May2025
def effect(self):
if not self.svg.selection:
- errormsg(_('Please select at least one element to update. '
- 'This extension is designed to help you update copy and pasted elements from old designs.'))
-
- # set the file version to the update_from value, so that the updater knows where to start from
- # the updater will then reset it to the current version after the update has finished
- metadata = self.get_inkstitch_metadata()
- metadata['inkstitch_svg_version'] = self.update_from
-
- update_inkstitch_document(self.document, self.get_selection())
+ update_inkstitch_document(self.document, warn_unversioned=False)
+ else:
+ # set the file version to the update_from value, so that the updater knows where to start from
+ # the updater will then reset it to the current version after the update has finished
+ metadata = self.get_inkstitch_metadata()
+ metadata['inkstitch_svg_version'] = self.options.update_from
+
+ update_inkstitch_document(self.document, self.get_selection(), warn_unversioned=False)
def get_selection(self):
selection = []