summaryrefslogtreecommitdiff
path: root/lib/svg
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2018-08-24 20:52:28 -0400
committerGitHub <noreply@github.com>2018-08-24 20:52:28 -0400
commit1de8487849a3f8f55d126e2687d690226e657fde (patch)
tree1bd891b97f8447cb3f513d073d20cea5d4534461 /lib/svg
parentb3bb975401fe4971170239eea9b928ee13161398 (diff)
parent91eb98cc33602f19dddc186c034aed968e048404 (diff)
Merge pull request #288 from inkstitch/lexelby/style
fix coding style and enforce style checks in build
Diffstat (limited to 'lib/svg')
-rw-r--r--lib/svg/path.py4
-rw-r--r--lib/svg/realistic_rendering.py3
-rw-r--r--lib/svg/svg.py38
-rw-r--r--lib/svg/units.py22
4 files changed, 39 insertions, 28 deletions
diff --git a/lib/svg/path.py b/lib/svg/path.py
index 0a8dcb74..4502b2ea 100644
--- a/lib/svg/path.py
+++ b/lib/svg/path.py
@@ -1,8 +1,8 @@
import simpletransform
-import cubicsuperpath
from .units import get_viewbox_transform
+
def apply_transforms(path, node):
transform = get_node_transform(node)
@@ -11,6 +11,7 @@ def apply_transforms(path, node):
return path
+
def get_node_transform(node):
# start with the identity transform
transform = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
@@ -26,6 +27,7 @@ def get_node_transform(node):
return transform
+
def get_correction_transform(node, child=False):
"""Get a transform to apply to new siblings or children of this SVG node"""
diff --git a/lib/svg/realistic_rendering.py b/lib/svg/realistic_rendering.py
index e31534da..73da3a09 100644
--- a/lib/svg/realistic_rendering.py
+++ b/lib/svg/realistic_rendering.py
@@ -2,7 +2,7 @@ import simplepath
import math
from .units import PIXELS_PER_MM
-from ..utils import cache, Point
+from ..utils import Point
# The stitch vector path looks like this:
# _______
@@ -102,6 +102,7 @@ realistic_filter = """
</filter>
"""
+
def realistic_stitch(start, end):
"""Generate a stitch vector path given a start and end point."""
diff --git a/lib/svg/svg.py b/lib/svg/svg.py
index 48b1343a..b1cc91d9 100644
--- a/lib/svg/svg.py
+++ b/lib/svg/svg.py
@@ -1,4 +1,6 @@
-import simpletransform, simplestyle, inkex
+import simpletransform
+import simplestyle
+import inkex
from .units import get_viewbox_transform
from .tags import SVG_GROUP_TAG, INKSCAPE_LABEL, INKSCAPE_GROUPMODE, SVG_PATH_TAG, SVG_DEFS_TAG
@@ -11,13 +13,13 @@ def color_block_to_point_lists(color_block):
point_lists = [[]]
for stitch in color_block:
- if stitch.trim:
- if point_lists[-1]:
- point_lists.append([])
- continue
+ if stitch.trim:
+ if point_lists[-1]:
+ point_lists.append([])
+ continue
- if not stitch.jump and not stitch.color_change:
- point_lists[-1].append(stitch.as_tuple())
+ if not stitch.jump and not stitch.color_change:
+ point_lists[-1].append(stitch.as_tuple())
return point_lists
@@ -51,13 +53,14 @@ def color_block_to_realistic_stitches(color_block, svg):
'stroke': 'none',
'filter': 'url(#realistic-stitch-filter)'
}),
- 'd': realistic_stitch(start, point),
- 'transform': get_correction_transform(svg)
- }))
+ 'd': realistic_stitch(start, point),
+ 'transform': get_correction_transform(svg)
+ }))
start = point
return paths
+
def color_block_to_paths(color_block, svg):
paths = []
# We could emit just a single path with one subpath per point list, but
@@ -68,13 +71,13 @@ def color_block_to_paths(color_block, svg):
SVG_PATH_TAG,
{'style': simplestyle.formatStyle(
{'stroke': color,
- 'stroke-width': "0.4",
- 'fill': 'none'}),
- 'd': "M" + " ".join(" ".join(str(coord) for coord in point) for point in point_list),
- 'transform': get_correction_transform(svg),
- 'embroider_manual_stitch': 'true',
- 'embroider_trim_after': 'true',
- }))
+ 'stroke-width': "0.4",
+ 'fill': 'none'}),
+ 'd': "M" + " ".join(" ".join(str(coord) for coord in point) for point in point_list),
+ 'transform': get_correction_transform(svg),
+ 'embroider_manual_stitch': 'true',
+ 'embroider_trim_after': 'true',
+ }))
# no need to trim at the end of a thread color
if paths:
@@ -82,6 +85,7 @@ def color_block_to_paths(color_block, svg):
return paths
+
def render_stitch_plan(svg, stitch_plan, realistic=False):
layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']")
if layer is None:
diff --git a/lib/svg/units.py b/lib/svg/units.py
index 126027bc..c4ec82a0 100644
--- a/lib/svg/units.py
+++ b/lib/svg/units.py
@@ -1,13 +1,15 @@
import simpletransform
from ..utils import cache
+from ..i18n import _
# modern versions of Inkscape use 96 pixels per inch as per the CSS standard
PIXELS_PER_MM = 96 / 25.4
# cribbed from inkscape-silhouette
-def parse_length_with_units( str ):
+
+def parse_length_with_units(str):
'''
Parse an SVG value which may or may not have units attached
This version is greatly simplified in that it only allows: no units,
@@ -39,8 +41,8 @@ def parse_length_with_units( str ):
u = '%'
s = s[:-1]
try:
- v = float( s )
- except:
+ v = float(s)
+ except BaseException:
raise ValueError(_("parseLengthWithUnits: unknown unit %s") % s)
return v, u
@@ -53,16 +55,16 @@ def convert_length(length):
return value
if units == 'pt':
- value /= 72
- units = 'in'
+ value /= 72
+ units = 'in'
if units == 'pc':
- value /= 6
- units = 'in'
+ value /= 6
+ units = 'in'
if units == 'cm':
- value *= 10
- units = 'mm'
+ value *= 10
+ units = 'mm'
if units == 'mm':
value = value / 25.4
@@ -75,6 +77,7 @@ def convert_length(length):
raise ValueError(_("Unknown unit: %s") % units)
+
@cache
def get_viewbox(svg):
return svg.get('viewBox').strip().replace(',', ' ').split()
@@ -96,6 +99,7 @@ def get_doc_size(svg):
return doc_width, doc_height
+
@cache
def get_viewbox_transform(node):
# somewhat cribbed from inkscape-silhouette