This commit is contained in:
arpruss
2018-07-14 15:46:02 -05:00
parent 16ddaf0bc6
commit d696e861aa
2 changed files with 50 additions and 1 deletions

View File

@@ -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)]))

49
dumpscad.py Normal file
View File

@@ -0,0 +1,49 @@
import re
import sys
from zttf.ttfile import TTFile
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: {} <font filename>".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")