mirror of
https://github.com/phooky/Apple-410.git
synced 2024-05-28 23:41:32 +00:00
transitioning svg to plot into submodule
This commit is contained in:
parent
a2f0051137
commit
398389f315
|
@ -1,6 +1,7 @@
|
|||
import sys
|
||||
import argparse
|
||||
from . import Apple410
|
||||
from .svg_to_plot import plot_svg
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser("apple410",
|
||||
|
@ -23,9 +24,7 @@ def main():
|
|||
if args.FILE == "-":
|
||||
f = sys.stdin
|
||||
else:
|
||||
f = open(scr)
|
||||
if len(sys.argv) > 1:
|
||||
scr = sys.argv[1]
|
||||
f = open(args.FILE)
|
||||
if args.svg:
|
||||
print("SVG conversion is not yet implemented!")
|
||||
sys.exit(1)
|
||||
|
@ -34,4 +33,17 @@ def main():
|
|||
print("Sending {}".format(line.strip()))
|
||||
a.send(line.strip())
|
||||
|
||||
def svg2plot():
|
||||
parser = argparse.ArgumentParser("svg2plot",
|
||||
description="Convert an SVG to Apple 410 Color Plotter commands",
|
||||
epilog="This is a work in progress and only handles simple paths.")
|
||||
parser.add_argument('-c', '--center', action='store_true',
|
||||
help = 'Center the SVG')
|
||||
parser.add_argument('SVG', help='The SVG to process. "-" will read the SVG from standard input.')
|
||||
args = parser.parse_args()
|
||||
if args.SVG == '-':
|
||||
f = sys.stdin
|
||||
else:
|
||||
f = open(args.SVG)
|
||||
plot_svg(f,center=args.center)
|
||||
|
||||
|
|
|
@ -43,14 +43,7 @@ w=2394
|
|||
h=1700
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
scr = '-'
|
||||
if len(sys.argv) > 1:
|
||||
scr = sys.argv[1]
|
||||
if scr == "-":
|
||||
f = sys.stdin
|
||||
else:
|
||||
f = open(scr)
|
||||
def plot_svg(f, center=False):
|
||||
doc = minidom.parse(f)
|
||||
segs = []
|
||||
for path in doc.getElementsByTagName('path'):
|
||||
|
@ -64,16 +57,18 @@ if __name__ == '__main__':
|
|||
sys.stderr.write("X {} {}\n".format(minx,maxx))
|
||||
sys.stderr.write("Y {} {}\n".format(miny,maxy))
|
||||
(spanx,spany) = (maxx-minx,maxy-miny)
|
||||
xoff = -minx
|
||||
yoff = -miny
|
||||
(s1, s2) = (1.0,1.0)
|
||||
if spanx > w:
|
||||
s1 = spanx/w
|
||||
if spany > h:
|
||||
s2 = spany/h
|
||||
s = max(s1,s2)
|
||||
xoff = xoff/s
|
||||
yoff = yoff/s
|
||||
if center:
|
||||
xoff = w/2 - (minx + spanx/2)/s
|
||||
yoff = w/2 - (miny + spany/2)/s
|
||||
else:
|
||||
xoff = -minx/s
|
||||
yoff = -miny/s
|
||||
segs = map(lambda x: ((x[0][0]/s + xoff,x[0][1]/s + yoff),
|
||||
(x[1][0]/s + xoff,x[1][1]/s + yoff)), segs)
|
||||
last = (0.0,0.0)
|
||||
|
|
Loading…
Reference in New Issue
Block a user