added PNG output

This commit is contained in:
Adam Mayer 2017-12-24 13:20:28 -05:00
parent 5ff95991ea
commit c87b0b24e3
3 changed files with 31 additions and 2 deletions

View File

@ -62,3 +62,17 @@ def plot2svg():
p.read(f)
p.write()
def plot2png():
parser = argparse.ArgumentParser("plot2png",
description="Convert a set of Apple 410 Color Plotter commands to a PNG")
parser.add_argument('PLOT', help='The plotter file to process. "-" will read plotter commands from standard input.')
args = parser.parse_args()
if args.PLOT == '-':
f = sys.stdin
else:
f = open(args.PLOT)
p = CairoPlotter(sys.stdout.buffer,'PNG')
p.read(f)
p.write()

View File

@ -22,9 +22,18 @@ LW = 5
class CairoPlotter:
def __init__(self, path):
self.surface = cairo.SVGSurface(path, W, H)
def __init__(self, path, surftype = 'SVG'):
self.surftype = surftype
if surftype == 'SVG':
self.surface = cairo.SVGSurface(path, W, H)
elif surftype == 'PNG':
self.path = path
self.surface = cairo.ImageSurface(cairo.Format.RGB24,W,H)
self.context = cairo.Context(self.surface)
if surftype == 'PNG':
self.context.rectangle(0,0,W,H)
self.context.set_source_rgb(1.0,1.0,1.0)
self.context.fill()
#self.context.scale(W,H)
self.context.select_font_face("monospace")
self.pennum = 0
@ -141,6 +150,11 @@ class CairoPlotter:
def write(self):
self.finish_path()
if self.surftype == 'PNG':
if self.path == '-':
self.surface.write_to_png(sys.stdout)
else:
self.surface.write_to_png(self.path)
self.surface.finish()
def process_cmd(self,command):

View File

@ -55,6 +55,7 @@ setup(
'apple410=apple410.cmdline:main',
'a410svg2plot=apple410.cmdline:svg2plot',
'a410plot2svg=apple410.cmdline:plot2svg',
'a410plot2png=apple410.cmdline:plot2png',
],
},
)