From 05daffb7e01db55879eb24f3c00532324a5d41af Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 1 May 2018 21:21:07 -0400 Subject: refactor everything out of lib/__init__.py --- lib/elements/element.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'lib/elements/element.py') diff --git a/lib/elements/element.py b/lib/elements/element.py index cfca3782..300136dd 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -1,9 +1,10 @@ import sys from copy import deepcopy +from shapely import geometry as shgeo +from ..i18n import _ from ..utils import cache -from shapely import geometry as shgeo -from .. import _, PIXELS_PER_MM, get_viewbox_transform, get_stroke_scale, convert_length +from ..svg import PIXELS_PER_MM, get_viewbox_transform, convert_length, get_doc_size # inkscape-provided utilities import simpletransform @@ -11,6 +12,7 @@ import simplestyle import cubicsuperpath from cspsubdiv import cspsubdiv + class Patch: """A raw collection of stitches with attached instructions.""" @@ -144,6 +146,15 @@ class EmbroideryElement(object): style = simplestyle.parseStyle(self.node.get("style")) return style_name in style + @property + @cache + def stroke_scale(self): + svg = self.node.getroottree().getroot() + doc_width, doc_height = get_doc_size(svg) + viewbox = svg.get('viewBox', '0 0 %s %s' % (doc_width, doc_height)) + viewbox = viewbox.strip().replace(',', ' ').split() + return doc_width / float(viewbox[2]) + @property @cache def stroke_width(self): @@ -153,8 +164,7 @@ class EmbroideryElement(object): return 1.0 width = convert_length(width) - - return width * get_stroke_scale(self.node.getroottree().getroot()) + return width * self.stroke_scale @property def path(self): -- cgit v1.2.3