From 63565100c3ffa1f122b43a98a4e6d3a81989ac99 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Thu, 29 Sep 2016 18:22:02 +0200 Subject: Add ZEICHENSATZ dumper --- convertCharset.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 convertCharset.py diff --git a/convertCharset.py b/convertCharset.py new file mode 100755 index 0000000..59163aa --- /dev/null +++ b/convertCharset.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 + +""" +Convert file ZEICHENSATZ from graphics package to PNG files +""" + +from eumel import * + +class ZeichensatzDataspace(Dataspace): + TYPE = 0x44c + + def __init__ (self, fd): + Dataspace.__init__ (self, fd) + + # just an array with 255 elements + self.rows = [] + for i in range (255): + self.rows.append (self.parseText ()) + self.parseHeap () + +if __name__ == '__main__': + import argparse, sys, cairo, math + + def transform (w, h, x, y): + return ((2+x), (11-y)) + + parser = argparse.ArgumentParser(description='Convert ZEICHENSATZ dataspace to PNG') + parser.add_argument ('-v', '--verbose', help='Enable debugging messages', action='store_true') + parser.add_argument ('file', help='Input file') + parser.add_argument ('prefix', help='Output prefix') + args = parser.parse_args () + + if args.verbose: + logging.basicConfig (level=logging.DEBUG) + else: + logging.basicConfig (level=logging.WARNING) + + m = [] + with open (args.file, 'rb') as fd: + ds = ZeichensatzDataspace (fd) + # no character with code 0 + for (j, r) in zip (range (1, len (ds.rows)+1), ds.rows): + if len (r) == 0: + continue + + out = '{}{:03d}.png'.format (args.prefix, j) + logging.info ('Converting character {} to {}'.format (j, out)) + w, h = 1024, 1024 + surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h) + ctx = cairo.Context(surface) + ctx.scale (64, 64) + ctx.set_line_width (0.1) + ctx.set_source_rgb (1, 0, 0) + + r = bytes (r) + lastxy = (0, 0) + for i in range (0, len (r), 4): + x0, y0, x1, y1 = struct.unpack ('