This commit is contained in:
arpruss
2018-07-18 09:33:06 -05:00
parent f3d6d31c4e
commit a7d9930ef5
3 changed files with 27 additions and 21 deletions

View File

@@ -30,10 +30,12 @@ if __name__ == '__main__':
print("Units "+str(f.units_per_em)) print("Units "+str(f.units_per_em))
print("MacStyle "+str(f.tables[b'head'].mac_style)) print("MacStyle "+str(f.tables[b'head'].mac_style))
for c in chars: for c in chars:
glyph = f.char_to_glyph(c) try:
print(("Width %d %d %d " % (c, f.glyph_metrics[glyph][0], f.glyph_metrics[glyph][1]))+chr(c)) glyph = f.char_to_glyph(c)
for c2 in chars: print(("Width %d %d %d " % (c, f.glyph_metrics[glyph][0], f.glyph_metrics[glyph][1]))+chr(c))
r = f.char_to_glyph(c2) for c2 in chars:
if (glyph,r) in f.glyph_kern: r = f.char_to_glyph(c2)
print("Kern %d %d %d" % (c, c2, f.glyph_kern[(glyph,r)])) if (glyph,r) in f.glyph_kern:
print("Kern %d %d %d" % (c, c2, f.glyph_kern[(glyph,r)]))
except:
pass

View File

@@ -20,6 +20,7 @@ if __name__ == '__main__':
print("Usage: {} <font filename>".format(sys.argv[0])) print("Usage: {} <font filename>".format(sys.argv[0]))
sys.exit(0) sys.exit(0)
t = TTFile(sys.argv[1])
t = TTFile(sys.argv[1]) t = TTFile(sys.argv[1])
if not t.is_valid: if not t.is_valid:
print("Invalid") print("Invalid")
@@ -27,9 +28,9 @@ if __name__ == '__main__':
f = t.faces[0] f = t.faces[0]
glyphs = {} glyphs = {}
for c in range(0,65536): for c in range(0, 65536):
try: try:
g = f.char_to_glyph(c) g = f.char_to_glyph(c+0xF000 if f.name == "Webdings" and c<256 else c)
if g: if g:
glyphs[c] = g glyphs[c] = g
except: except:
@@ -62,16 +63,19 @@ if __name__ == '__main__':
f.tables[b'os2'].typo_line_gap, f.tables[b'os2'].typo_line_gap,
f.units_per_em)) f.units_per_em))
for c in chars: for c in chars:
glyph = f.char_to_glyph(c) try:
box = glyphBox(f,glyph) glyph = glyphs[c]
line = " [%s,%d,%d,%d,%d,%d,%d,[" % ( describeChar(c), f.glyph_metrics[glyph][0], box = glyphBox(f,glyph)
f.glyph_metrics[glyph][1], box[0], box[1], box[2], box[3] ) line = " [%s,%d,%d,%d,%d,%d,%d,[" % ( describeChar(c), f.glyph_metrics[glyph][0],
kerns=[] f.glyph_metrics[glyph][1], box[0], box[1], box[2], box[3] )
for c2 in chars: kerns=[]
r = f.char_to_glyph(c2) for c2 in chars:
if (glyph,r) in f.glyph_kern: r = f.char_to_glyph(c2)
kerns.append("[%s,%d]" % (describeChar(c2), f.glyph_kern[(glyph,r)])) if (glyph,r) in f.glyph_kern:
line += ','.join(kerns)+"]]," kerns.append("[%s,%d]" % (describeChar(c2), f.glyph_kern[(glyph,r)]))
print(line) line += ','.join(kerns)+"]],"
print(line)
except:
pass
print(" ]\n];\n") print(" ]\n];\n")

View File

@@ -451,7 +451,7 @@ class TTF_cmap(PackedFormat):
break break
def char_to_glyph(self, char, fh): def char_to_glyph(self, char, fh):
for p in self.PREFS: for p in self.tables: #PREFS:
if p in self.tables and self.tables[p].has_map_data: if p in self.tables and self.tables[p].has_map_data:
for rng in self.tables[p].map_data.ranges: for rng in self.tables[p].map_data.ranges:
if rng.end < char: if rng.end < char: