diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2018-06-29 21:26:03 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-29 21:26:03 -0400 |
| commit | 4d7b07ff02e13f237fac8eb8715fe4a6324ea6dc (patch) | |
| tree | f1c29df5f29d5bfefb48513043116b73209f202d /lib/elements/element.py | |
| parent | 7c8cd648a36e10e5ebfb94ce27be76e5ba47f334 (diff) | |
| parent | de4ead1ad467997fa81a4459e194769dfab185e2 (diff) | |
Merge pull request #212 from inkstitch/lexelby-fill-markers
fill start/end
Diffstat (limited to 'lib/elements/element.py')
| -rw-r--r-- | lib/elements/element.py | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/lib/elements/element.py b/lib/elements/element.py index 39437c9f..3c31f1b0 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -4,7 +4,8 @@ from shapely import geometry as shgeo from ..i18n import _ from ..utils import cache -from ..svg import PIXELS_PER_MM, get_viewbox_transform, convert_length, get_doc_size +from ..svg import PIXELS_PER_MM, convert_length, get_doc_size, apply_transforms +from ..commands import find_commands # inkscape-provided utilities import simpletransform @@ -171,10 +172,6 @@ class EmbroideryElement(object): @property def path(self): - return cubicsuperpath.parsePath(self.node.get("d")) - - @cache - def parse_path(self): # A CSP is a "cubic superpath". # # A "path" is a sequence of strung-together bezier curves. @@ -202,22 +199,32 @@ class EmbroideryElement(object): # In a path, each element in the 3-tuple is itself a tuple of (x, y). # Tuples all the way down. Hasn't anyone heard of using classes? - path = self.path - - # start with the identity transform - transform = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]] + return cubicsuperpath.parsePath(self.node.get("d")) - # combine this node's transform with all parent groups' transforms - transform = simpletransform.composeParents(self.node, transform) + @cache + def parse_path(self): + return apply_transforms(self.path, self.node) - # add in the transform implied by the viewBox - viewbox_transform = get_viewbox_transform(self.node.getroottree().getroot()) - transform = simpletransform.composeTransform(viewbox_transform, transform) + @property + @cache + def commands(self): + return find_commands(self.node) - # apply the combined transform to this node's path - simpletransform.applyTransformToPath(transform, path) + @cache + def get_commands(self, command): + return [c for c in self.commands if c.command == command] - return path + @cache + def get_command(self, command): + commands = self.get_commands(command) + + if len(commands) == 1: + return commands[0] + elif len(commands) > 1: + raise ValueError(_("%(id)s has more than one command of type '%(command)s' linked to it") % + dict(id=self.node.get(id), command=command)) + else: + return None def strip_control_points(self, subpath): return [point for control_before, point, control_after in subpath] |
