Skip to content

Commit

Permalink
Enable to_path to work on text objects
Browse files Browse the repository at this point in the history
Applying to_path to a text object requires spawning two child Inkscape
processes so execution is quite slow, but at least it now works.

This modification resolves #119.
  • Loading branch information
spakin committed Dec 22, 2023
1 parent ff8d4a5 commit 7c2059c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions simpinkscr/simple_inkscape_scripting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,36 @@ def add_text(self, msg, base=None, **style):
self._inkscape_obj.append(tspan)
return self

def to_path(self, all_curves=False):
'''Convert the text to a path, removing it from the list of
rendered objects.'''
# Store the text's style and transform.
orig_style = self.svg_get('style')
orig_xform = self.svg_get('transform')

# Spawn a child Inkscape to convert the text to a list of paths.
path_objs = apply_action('object-to-path', self)
paths = []
for p in path_objs:
if isinstance(p, SimplePathObject):
paths.append(p)
elif isinstance(p, SimpleGroup):
p.ungroup()

# Spawn another child Inkscape to merge all paths into one.
# Caveat: This operation will fail silently on Inkscape versions
# earlier than 1.2.
union = apply_path_operation('union', paths)[0]

# Convert the path elements to curves if requested.
if all_curves:
union.svg_set('d', self._path_to_curve(union._inkscape_obj))

# Restore the saved style and transform and return the new path.
union.svg_set('style', orig_style)
union.svg_set('transform', orig_xform)
return union


class SimpleMarker(SimpleObject):
'Represent a path marker, which wraps an arbitrary object.'
Expand Down

0 comments on commit 7c2059c

Please sign in to comment.