2018-11-15 01:23:06 +00:00
|
|
|
import inkex
|
2018-06-21 19:41:06 +00:00
|
|
|
import simpletransform
|
|
|
|
|
|
|
|
from .units import get_viewbox_transform
|
|
|
|
|
2018-08-22 00:32:50 +00:00
|
|
|
|
2018-06-21 19:41:06 +00:00
|
|
|
def apply_transforms(path, node):
|
2018-07-05 01:44:08 +00:00
|
|
|
transform = get_node_transform(node)
|
|
|
|
|
|
|
|
# apply the combined transform to this node's path
|
|
|
|
simpletransform.applyTransformToPath(transform, path)
|
|
|
|
|
|
|
|
return path
|
|
|
|
|
2018-08-22 00:32:50 +00:00
|
|
|
|
2018-11-15 01:23:06 +00:00
|
|
|
def compose_parent_transforms(node, mat):
|
|
|
|
# This is adapted from Inkscape's simpletransform.py's composeParents()
|
|
|
|
# function. That one can't handle nodes that are detached from a DOM.
|
|
|
|
|
|
|
|
trans = node.get('transform')
|
|
|
|
if trans:
|
|
|
|
mat = simpletransform.composeTransform(simpletransform.parseTransform(trans), mat)
|
|
|
|
if node.getparent() is not None:
|
|
|
|
if node.getparent().tag == inkex.addNS('g', 'svg'):
|
|
|
|
mat = compose_parent_transforms(node.getparent(), mat)
|
|
|
|
return mat
|
|
|
|
|
|
|
|
|
2018-07-05 01:44:08 +00:00
|
|
|
def get_node_transform(node):
|
2018-06-21 19:41:06 +00:00
|
|
|
# start with the identity transform
|
|
|
|
transform = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
|
|
|
|
|
2018-07-30 20:03:27 +00:00
|
|
|
# this if is because sometimes inkscape likes to create paths outside of a layer?!
|
|
|
|
if node.getparent() is not None:
|
|
|
|
# combine this node's transform with all parent groups' transforms
|
2018-11-15 01:23:06 +00:00
|
|
|
transform = compose_parent_transforms(node, transform)
|
2018-06-21 19:41:06 +00:00
|
|
|
|
|
|
|
# add in the transform implied by the viewBox
|
|
|
|
viewbox_transform = get_viewbox_transform(node.getroottree().getroot())
|
|
|
|
transform = simpletransform.composeTransform(viewbox_transform, transform)
|
|
|
|
|
2018-07-05 01:44:08 +00:00
|
|
|
return transform
|
2018-07-30 18:57:54 +00:00
|
|
|
|
2018-08-22 00:32:50 +00:00
|
|
|
|
2018-08-17 02:50:34 +00:00
|
|
|
def get_correction_transform(node, child=False):
|
|
|
|
"""Get a transform to apply to new siblings or children of this SVG node"""
|
2018-07-30 18:57:54 +00:00
|
|
|
|
|
|
|
# if we want to place our new nodes in the same group/layer as this node,
|
|
|
|
# then we'll need to factor in the effects of any transforms set on
|
|
|
|
# the parents of this node.
|
|
|
|
|
2018-08-17 02:50:34 +00:00
|
|
|
if child:
|
|
|
|
transform = get_node_transform(node)
|
|
|
|
else:
|
|
|
|
# we can ignore the transform on the node itself since it won't apply
|
|
|
|
# to the objects we add
|
|
|
|
transform = get_node_transform(node.getparent())
|
2018-07-30 18:57:54 +00:00
|
|
|
|
|
|
|
# now invert it, so that we can position our objects in absolute
|
|
|
|
# coordinates
|
|
|
|
transform = simpletransform.invertTransform(transform)
|
|
|
|
|
|
|
|
return simpletransform.formatTransform(transform)
|
2018-09-29 20:00:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def line_strings_to_csp(line_strings):
|
new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214! This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension. After a few seconds, it will replace your satins with a new set with a logical stitching order. Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps. The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o"). You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches. Any jump stitch over 1mm is trimmed. I might make this configurable in the future but in my tests it seems to do a good job. Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
2018-10-30 23:43:21 +00:00
|
|
|
return point_lists_to_csp(ls.coords for ls in line_strings)
|
|
|
|
|
|
|
|
|
|
|
|
def point_lists_to_csp(point_lists):
|
2018-09-29 20:00:36 +00:00
|
|
|
csp = []
|
|
|
|
|
new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214! This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension. After a few seconds, it will replace your satins with a new set with a logical stitching order. Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps. The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o"). You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches. Any jump stitch over 1mm is trimmed. I might make this configurable in the future but in my tests it seems to do a good job. Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
2018-10-30 23:43:21 +00:00
|
|
|
for point_list in point_lists:
|
2018-09-29 20:00:36 +00:00
|
|
|
subpath = []
|
new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214! This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension. After a few seconds, it will replace your satins with a new set with a logical stitching order. Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps. The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o"). You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches. Any jump stitch over 1mm is trimmed. I might make this configurable in the future but in my tests it seems to do a good job. Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
2018-10-30 23:43:21 +00:00
|
|
|
for point in point_list:
|
|
|
|
# cubicsuperpath is very particular that these must be lists, not tuples
|
|
|
|
point = list(point)
|
2018-09-29 20:00:36 +00:00
|
|
|
# create a straight line as a degenerate bezier
|
new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214! This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension. After a few seconds, it will replace your satins with a new set with a logical stitching order. Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps. The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o"). You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches. Any jump stitch over 1mm is trimmed. I might make this configurable in the future but in my tests it seems to do a good job. Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
2018-10-30 23:43:21 +00:00
|
|
|
subpath.append([point, point, point])
|
2018-09-29 20:00:36 +00:00
|
|
|
csp.append(subpath)
|
|
|
|
|
|
|
|
return csp
|