From d696e861aa48b0cf4c87a95bfa31ef65cae8492c Mon Sep 17 00:00:00 2001 From: arpruss Date: Sat, 14 Jul 2018 15:46:02 -0500 Subject: [PATCH] foo --- dumpmetrics.py | 2 +- dumpscad.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 dumpscad.py diff --git a/dumpmetrics.py b/dumpmetrics.py index a0e27d9..ed3fde0 100644 --- a/dumpmetrics.py +++ b/dumpmetrics.py @@ -36,4 +36,4 @@ if __name__ == '__main__': r = f.char_to_glyph(c2) if (glyph,r) in f.glyph_kern: print("Kern %d %d %d" % (c, c2, f.glyph_kern[(glyph,r)])) - \ No newline at end of file + diff --git a/dumpscad.py b/dumpscad.py new file mode 100644 index 0000000..61b8adb --- /dev/null +++ b/dumpscad.py @@ -0,0 +1,49 @@ +import re +import sys +from zttf.ttfile import TTFile + + +if __name__ == '__main__': + if len(sys.argv) < 2: + print("Usage: {} ".format(sys.argv[0])) + sys.exit(0) + + t = TTFile(sys.argv[1]) + if not t.is_valid: + print("Invalid") + sys.exit(0) + + f = t.faces[0] + glyphs = {} + for c in range(0,65536): + try: + g = f.char_to_glyph(c) + if g: + glyphs[c] = g + except: + pass + chars = sorted(glyphs.keys()) + + fontID = re.sub(r"[^0-9A-Za-z]", "_", f.name) + if fontID[0].isdigit(): + fontID = "_" + fontID + print("""FONT_%s = [ + ["%s", // family + %d], // style + %d, // ascender + %d, // descender + %f, // units_per_em + METRICS_%s +];""" % (fontID, f.font_family, f.tables[b'head'].mac_style, f.ascender, f.descender, f.units_per_em,fontID)) + print("METRICS_%s = [" % fontID) + for c in chars: + glyph = f.char_to_glyph(c) + line = " [ chr(%d), %d, [" % ( c, f.glyph_metrics[glyph][0] ) + for c2 in chars: + r = f.char_to_glyph(c2) + if (glyph,r) in f.glyph_kern: + line += "[chr(%d),%d]," % (c2, f.glyph_kern[(glyph,r)]) + line += "] ]," + print(line) + print("];\n") +