summaryrefslogtreecommitdiff
path: root/lib/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'lib/extensions')
-rw-r--r--lib/extensions/letters_to_font.py18
-rw-r--r--lib/extensions/zigzag_line_to_satin.py16
2 files changed, 26 insertions, 8 deletions
diff --git a/lib/extensions/letters_to_font.py b/lib/extensions/letters_to_font.py
index 56a33ad8..d4d9e60a 100644
--- a/lib/extensions/letters_to_font.py
+++ b/lib/extensions/letters_to_font.py
@@ -39,6 +39,7 @@ class LettersToFont(InkstitchExtension):
glyphs = list(Path(font_dir).rglob(file_format.lower()))
document = self.document.getroot()
+ group = None
for glyph in glyphs:
letter = self.get_glyph_element(glyph)
label = "GlyphLayer-%s" % letter.get(INKSCAPE_LABEL, ' ').split('.')[0][-1]
@@ -59,15 +60,20 @@ class LettersToFont(InkstitchExtension):
document.insert(0, group)
group.set('style', 'display:none')
+ # We found no glyphs, no need to proceed
+ if group is None:
+ return
+
# users may be confused if they get an empty document
# make last letter visible again
group.set('style', None)
- # In most cases trims are inserted with the imported letters.
- # Let's make sure the trim symbol exists in the defs section
- ensure_symbol(document, 'trim')
+ if self.options.import_commands == "symbols":
+ # In most cases trims are inserted with the imported letters.
+ # Let's make sure the trim symbol exists in the defs section
+ ensure_symbol(document, 'trim')
- self.insert_baseline(document)
+ self.insert_baseline()
def get_glyph_element(self, glyph):
stitch_plan = generate_stitch_plan(str(glyph), self.options.import_commands)
@@ -77,5 +83,5 @@ class LettersToFont(InkstitchExtension):
stitch_plan.attrib.pop(INKSCAPE_GROUPMODE)
return stitch_plan
- def insert_baseline(self, document):
- document.namedview.add_guide(position=0.0, name="baseline")
+ def insert_baseline(self):
+ self.svg.namedview.add_guide(position=0.0, name="baseline")
diff --git a/lib/extensions/zigzag_line_to_satin.py b/lib/extensions/zigzag_line_to_satin.py
index 167f4b91..b71bf6a0 100644
--- a/lib/extensions/zigzag_line_to_satin.py
+++ b/lib/extensions/zigzag_line_to_satin.py
@@ -23,11 +23,12 @@ class ZigzagLineToSatin(InkstitchExtension):
self.arg_parser.add_argument("-l", "--reduce-rungs", type=inkex.Boolean, default=False, dest="reduce_rungs")
def effect(self):
- if not self.svg.selection or not self.get_elements():
+ nodes = self.get_selection(self.svg.selection)
+ if not nodes:
inkex.errormsg(_("Please select at least one stroke to convert to a satin column."))
return
- for node in self.svg.selection:
+ for node in nodes:
d = []
point_list = list(node.get_path().end_points)
# find duplicated nodes (= do not smooth)
@@ -49,6 +50,17 @@ class ZigzagLineToSatin(InkstitchExtension):
node.set('d', " ".join(d))
node.set('inkstitch:satin_column', True)
+ def get_selection(self, nodes):
+ selection = []
+ for node in nodes:
+ # we only apply to path elements, no use in converting ellipses or rectangles, etc.
+ if node.TAG == "path":
+ selection.append(node)
+ elif node.TAG == "g":
+ for element in node.descendants():
+ selection.extend(self.get_selection(element))
+ return selection
+
def _get_sharp_edge_nodes(self, point_list):
points = []
sharp_edges = []