added PNG output
This commit is contained in:
parent
5ff95991ea
commit
c87b0b24e3
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue