summaryrefslogtreecommitdiff
path: root/lib/elements
diff options
context:
space:
mode:
Diffstat (limited to 'lib/elements')
-rw-r--r--lib/elements/auto_fill.py8
-rw-r--r--lib/elements/element.py18
-rw-r--r--lib/elements/fill.py9
-rw-r--r--lib/elements/polyline.py3
-rw-r--r--lib/elements/satin_column.py6
-rw-r--r--lib/elements/stroke.py5
6 files changed, 32 insertions, 17 deletions
diff --git a/lib/elements/auto_fill.py b/lib/elements/auto_fill.py
index 6eb1f10c..08ae67f7 100644
--- a/lib/elements/auto_fill.py
+++ b/lib/elements/auto_fill.py
@@ -1,10 +1,10 @@
import math
-from .. import _
-from .element import param, Patch
-from ..utils import cache
-from .fill import Fill
from shapely import geometry as shgeo
+from ..i18n import _
+from ..utils import cache
from ..stitches import auto_fill
+from .element import param, Patch
+from .fill import Fill
class AutoFill(Fill):
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):
diff --git a/lib/elements/fill.py b/lib/elements/fill.py
index a74a897d..52a42260 100644
--- a/lib/elements/fill.py
+++ b/lib/elements/fill.py
@@ -1,10 +1,13 @@
-from .. import _, PIXELS_PER_MM
-from .element import param, EmbroideryElement, Patch
-from ..utils import cache
from shapely import geometry as shgeo
import math
+
+from .element import param, EmbroideryElement, Patch
+from ..i18n import _
+from ..svg import PIXELS_PER_MM
+from ..utils import cache
from ..stitches import running_stitch, auto_fill, legacy_fill
+
class Fill(EmbroideryElement):
element_name = _("Fill")
diff --git a/lib/elements/polyline.py b/lib/elements/polyline.py
index 6ded9fd1..5c474237 100644
--- a/lib/elements/polyline.py
+++ b/lib/elements/polyline.py
@@ -1,5 +1,6 @@
-from .. import _, Point
from .element import param, EmbroideryElement, Patch
+from ..i18n import _
+from ..utils.geometry import Point
from ..utils import cache
diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py
index d22f5145..3593db64 100644
--- a/lib/elements/satin_column.py
+++ b/lib/elements/satin_column.py
@@ -1,9 +1,9 @@
from itertools import chain, izip
+from shapely import geometry as shgeo, ops as shops
-from .. import _, Point
from .element import param, EmbroideryElement, Patch
-from ..utils import cache
-from shapely import geometry as shgeo, ops as shops
+from ..i18n import _
+from ..utils import cache, Point
class SatinColumn(EmbroideryElement):
diff --git a/lib/elements/stroke.py b/lib/elements/stroke.py
index 360e3744..48662b6d 100644
--- a/lib/elements/stroke.py
+++ b/lib/elements/stroke.py
@@ -1,7 +1,8 @@
import sys
-from .. import _, Point
+
from .element import param, EmbroideryElement, Patch
-from ..utils import cache
+from ..i18n import _
+from ..utils import cache, Point
warned_about_legacy_running_stitch = False