Menu

[r1188]: / trunk / htdocs / examples / font_indexing.py  Maximize  Restore  History

Download this file

38 lines (27 with data), 941 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
A little example that shows how the various indexing into the font
tables relate to one another. Mainly for mpl developers....
"""
import matplotlib
from matplotlib.ft2font import FT2Font
fname = matplotlib.get_data_path() + '/cmr10.ttf'
font = FT2Font(fname)
codes = font.get_charmap().items()
dsu = [(ccode, glyphind) for glyphind, ccode in codes]
dsu.sort()
for ccode, glyphind in dsu:
try: name = font.get_glyph_name(glyphind)
except RuntimeError: pass
else: print '% 4d % 4d %s %s'%(glyphind, ccode, hex(int(ccode)), name)
# make a charname to charcode and glyphind dictionary
coded = {}
glyphd = {}
for glyphind, ccode in codes:
name = font.get_glyph_name(glyphind)
coded[name] = ccode
glyphd[name] = glyphind
code = coded['A']
glyph = font.load_char(code)
print glyph.bbox
print 'AV', font.get_kerning(glyphd['A'], glyphd['V'])/64.0
print 'AA', font.get_kerning(glyphd['A'], glyphd['A'])/64.0
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.