embroidery origin at canvas center and size canvas accordingly

pull/145/head
Lex Neva 2018-04-10 20:43:09 -04:00
rodzic 468c2c1375
commit 28e2250d8c
2 zmienionych plików z 20 dodań i 5 usunięć

Wyświetl plik

@ -37,12 +37,12 @@ def main(embroidery_file):
stop=stitch.flags & STOP,
trim=stitch.flags & TRIM)
dimensions = stitch_plan.dimensions
extents = stitch_plan.extents
svg = etree.Element("svg", nsmap=inkex.NSS, attrib=
{
"width": "%s" % dimensions[0],
"height": "%s" % dimensions[1],
"viewBox": "0 0 %s %s" % dimensions,
"width": str(extents[0] * 2),
"height": str(extents[1] * 2),
"viewBox": "0 0 %s %s" % (extents[0] * 2, extents[1] * 2),
})
render_stitch_plan(svg, stitch_plan)
@ -51,6 +51,10 @@ def main(embroidery_file):
layer.set(INKSCAPE_LABEL, os.path.basename(embroidery_file))
layer.attrib.pop('id')
# Shift the design so that its origin is at the center of the canvas
# Note: this is NOT the same as centering the design in the canvas!
layer.set('transform', 'translate(%s,%s)' % (extents[0], extents[1]))
print etree.tostring(svg)
if __name__ == '__main__':

Wyświetl plik

@ -97,15 +97,26 @@ class StitchPlan(object):
return sum(block.num_stitches for block in self)
@property
def dimensions(self):
def bounding_box(self):
color_block_bounding_boxes = [cb.bounding_box for cb in self]
minx = min(bb[0] for bb in color_block_bounding_boxes)
miny = min(bb[1] for bb in color_block_bounding_boxes)
maxx = max(bb[2] for bb in color_block_bounding_boxes)
maxy = max(bb[3] for bb in color_block_bounding_boxes)
return minx, miny, maxx, maxy
@property
def dimensions(self):
minx, miny, maxx, maxy = self.bounding_box
return (maxx - minx, maxy - miny)
@property
def extents(self):
minx, miny, maxx, maxy = self.bounding_box
return max(-minx, maxx), max(-miny, maxy)
@property
def dimensions_mm(self):
dimensions = self.dimensions