summaryrefslogtreecommitdiff
path: root/lib/elements/element.py
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2018-05-01 21:21:07 -0400
committerLex Neva <github.com@lexneva.name>2018-05-01 21:21:07 -0400
commit05daffb7e01db55879eb24f3c00532324a5d41af (patch)
tree43ff5d954e035e0e8b5a507b9c1bf9d6b4d3338d /lib/elements/element.py
parent1b31806423c8fec4040fed6d1009db016860b763 (diff)
refactor everything out of lib/__init__.py
Diffstat (limited to 'lib/elements/element.py')
-rw-r--r--lib/elements/element.py18
1 files changed, 14 insertions, 4 deletions
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."""
@@ -146,6 +148,15 @@ class EmbroideryElement(object):
@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):
width = self.get_style("stroke-width")
@@ -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):