diff options
Diffstat (limited to 'lib/svg')
| -rw-r--r-- | lib/svg/guides.py | 16 | ||||
| -rw-r--r-- | lib/svg/path.py | 10 | ||||
| -rw-r--r-- | lib/svg/tags.py | 127 | ||||
| -rw-r--r-- | lib/svg/units.py | 2 |
4 files changed, 92 insertions, 63 deletions
diff --git a/lib/svg/guides.py b/lib/svg/guides.py index e492a90d..3329940e 100644 --- a/lib/svg/guides.py +++ b/lib/svg/guides.py @@ -3,11 +3,10 @@ # Copyright (c) 2010 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. -from inkex import transforms +from inkex.units import convert_unit from ..utils import Point, cache, string_to_floats from .tags import INKSCAPE_LABEL, SODIPODI_GUIDE, SODIPODI_NAMEDVIEW -from .units import get_doc_size, get_viewbox_transform class InkscapeGuide(object): @@ -20,16 +19,15 @@ class InkscapeGuide(object): def _parse(self): self.label = self.node.get(INKSCAPE_LABEL, "") - doc_size = list(get_doc_size(self.svg)) - - # convert the size from viewbox-relative to real-world pixels - viewbox_transform = get_viewbox_transform(self.svg) - viewbox_transform = transforms.Transform(-transforms.Transform(viewbox_transform)).apply_to_point(doc_size) + doc_size = self.svg.get_page_bbox() + # inkscape's Y axis is reversed from SVG's, and the guide is in inkscape coordinates self.position = Point(*string_to_floats(self.node.get('position'))) + self.position.y = doc_size.y.size - self.position.y - # inkscape's Y axis is reversed from SVG's, and the guide is in inkscape coordinates - self.position.y = doc_size[1] - self.position.y + # convert units to px + unit = self.svg.unit + self.position.y = convert_unit(self.position.y, 'px', unit) # This one baffles me. I think inkscape might have gotten the order of # their vector wrong? diff --git a/lib/svg/path.py b/lib/svg/path.py index 53cf80f2..6c2cbe35 100644 --- a/lib/svg/path.py +++ b/lib/svg/path.py @@ -24,7 +24,7 @@ def compose_parent_transforms(node, mat): trans = node.get('transform') if trans: - mat = inkex.transforms.Transform(trans) * mat + mat = inkex.transforms.Transform(trans) @ mat if node.getparent() is not None: if node.getparent().tag in [SVG_GROUP_TAG, SVG_LINK_TAG]: mat = compose_parent_transforms(node.getparent(), mat) @@ -47,7 +47,7 @@ def get_node_transform(node): # add in the transform implied by the viewBox viewbox_transform = get_viewbox_transform(node.getroottree().getroot()) - transform = viewbox_transform * transform + transform = viewbox_transform @ transform return transform @@ -74,6 +74,12 @@ def get_correction_transform(node, child=False): def line_strings_to_csp(line_strings): + try: + # This lets us accept a MultiLineString or a list. + line_strings = line_strings.geoms + except AttributeError: + pass + return point_lists_to_csp(ls.coords for ls in line_strings) diff --git a/lib/svg/tags.py b/lib/svg/tags.py index 5c1d892a..f0dc69bc 100644 --- a/lib/svg/tags.py +++ b/lib/svg/tags.py @@ -3,14 +3,16 @@ # Copyright (c) 2010 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. -import inkex from lxml import etree +import inkex + etree.register_namespace("inkstitch", "http://inkstitch.org/namespace") inkex.NSS['inkstitch'] = 'http://inkstitch.org/namespace' SVG_PATH_TAG = inkex.addNS('path', 'svg') SVG_POLYLINE_TAG = inkex.addNS('polyline', 'svg') +SVG_POLYGON_TAG = inkex.addNS('polygon', 'svg') SVG_RECT_TAG = inkex.addNS('rect', 'svg') SVG_ELLIPSE_TAG = inkex.addNS('ellipse', 'svg') SVG_CIRCLE_TAG = inkex.addNS('circle', 'svg') @@ -22,12 +24,15 @@ SVG_LINK_TAG = inkex.addNS('a', 'svg') SVG_SYMBOL_TAG = inkex.addNS('symbol', 'svg') SVG_USE_TAG = inkex.addNS('use', 'svg') SVG_IMAGE_TAG = inkex.addNS('image', 'svg') +SVG_CLIPPATH_TAG = inkex.addNS('clipPath', 'svg') +SVG_MASK_TAG = inkex.addNS('mask', 'svg') INKSCAPE_LABEL = inkex.addNS('label', 'inkscape') INKSCAPE_GROUPMODE = inkex.addNS('groupmode', 'inkscape') CONNECTION_START = inkex.addNS('connection-start', 'inkscape') CONNECTION_END = inkex.addNS('connection-end', 'inkscape') CONNECTOR_TYPE = inkex.addNS('connector-type', 'inkscape') +INKSCAPE_DOCUMENT_UNITS = inkex.addNS('document-units', 'inkscape') XLINK_HREF = inkex.addNS('href', 'xlink') @@ -37,60 +42,80 @@ SODIPODI_ROLE = inkex.addNS('role', 'sodipodi') INKSTITCH_LETTERING = inkex.addNS('lettering', 'inkstitch') -EMBROIDERABLE_TAGS = (SVG_PATH_TAG, SVG_POLYLINE_TAG, SVG_RECT_TAG, SVG_ELLIPSE_TAG, SVG_CIRCLE_TAG) +EMBROIDERABLE_TAGS = (SVG_PATH_TAG, SVG_POLYLINE_TAG, SVG_POLYGON_TAG, + SVG_RECT_TAG, SVG_ELLIPSE_TAG, SVG_CIRCLE_TAG) NOT_EMBROIDERABLE_TAGS = (SVG_IMAGE_TAG, SVG_TEXT_TAG) SVG_OBJECT_TAGS = (SVG_ELLIPSE_TAG, SVG_CIRCLE_TAG, SVG_RECT_TAG) INKSTITCH_ATTRIBS = {} inkstitch_attribs = [ - 'ties', - # clone - 'clone', - # polyline - 'polyline', - # fill - 'angle', - 'auto_fill', - 'expand_mm', - 'fill_underlay', - 'fill_underlay_angle', - 'fill_underlay_inset_mm', - 'fill_underlay_max_stitch_length_mm', - 'fill_underlay_row_spacing_mm', - 'fill_underlay_skip_last', - 'max_stitch_length_mm', - 'row_spacing_mm', - 'end_row_spacing_mm', - 'skip_last', - 'staggers', - 'underlay_underpath', - 'underpath', - 'flip', - 'expand_mm', - # stroke - 'manual_stitch', - 'bean_stitch_repeats', - 'repeats', - 'running_stitch_length_mm', - # satin column - 'satin_column', - 'satin_column', - 'running_stitch_length_mm', - 'center_walk_underlay', - 'center_walk_underlay_stitch_length_mm', - 'contour_underlay', - 'contour_underlay_stitch_length_mm', - 'contour_underlay_inset_mm', - 'zigzag_underlay', - 'zigzag_spacing_mm', - 'zigzag_underlay_inset_mm', - 'zigzag_underlay_spacing_mm', - 'e_stitch', - 'pull_compensation_mm', - 'stroke_first', - # Legacy - 'trim_after', - 'stop_after' - ] + 'ties', + 'force_lock_stitches', + # clone + 'clone', + # polyline + 'polyline', + # fill + 'angle', + 'auto_fill', + 'fill_method', + 'contour_strategy', + 'join_style', + 'avoid_self_crossing', + 'clockwise', + 'line_count', + 'skip_start', + 'skip_end', + 'grid_size', + 'reverse', + 'exponent', + 'flip_exponent', + 'scale_axis', + 'scale_start', + 'scale_end', + 'rotate_ripples', + 'expand_mm', + 'fill_underlay', + 'fill_underlay_angle', + 'fill_underlay_inset_mm', + 'fill_underlay_max_stitch_length_mm', + 'fill_underlay_row_spacing_mm', + 'fill_underlay_skip_last', + 'max_stitch_length_mm', + 'row_spacing_mm', + 'end_row_spacing_mm', + 'skip_last', + 'staggers', + 'underlay_underpath', + 'underpath', + 'flip', + 'expand_mm', + # stroke + 'stroke_method', + 'bean_stitch_repeats', + 'repeats', + 'running_stitch_length_mm', + # satin column + 'satin_column', + 'running_stitch_length_mm', + 'center_walk_underlay', + 'center_walk_underlay_stitch_length_mm', + 'center_walk_underlay_repeats', + 'contour_underlay', + 'contour_underlay_stitch_length_mm', + 'contour_underlay_inset_mm', + 'zigzag_underlay', + 'zigzag_spacing_mm', + 'zigzag_underlay_inset_mm', + 'zigzag_underlay_spacing_mm', + 'zigzag_underlay_max_stitch_length_mm', + 'e_stitch', + 'pull_compensation_mm', + 'stroke_first', + # Legacy + 'trim_after', + 'stop_after', + 'manual_stitch', +] for attrib in inkstitch_attribs: INKSTITCH_ATTRIBS[attrib] = inkex.addNS(attrib, 'inkstitch') diff --git a/lib/svg/units.py b/lib/svg/units.py index f229c2c3..e8a21c18 100644 --- a/lib/svg/units.py +++ b/lib/svg/units.py @@ -149,7 +149,7 @@ def get_viewbox_transform(node): sx = sy = max(sx, sy) if 'slice' in aspect_ratio else min(sx, sy) scale_transform = inkex.transforms.Transform("scale(%f, %f)" % (sx, sy)) - transform = transform * scale_transform + transform = transform @ scale_transform except ZeroDivisionError: pass |
