Note

Go to the endto download the full example code.

Font indexing#

This example shows how the font tables relate to one another.

(6, 0, 519, 576)36 57 65 86AV -48AV -49AV -16AT -19

importosimportmatplotlibfrommatplotlib.ft2fontimportFT2Font,Kerningfont=FT2Font(os.path.join(matplotlib.get_data_path(),'fonts/ttf/DejaVuSans.ttf'))font.set_charmap(0)codes=font.get_charmap().items()# make a charname to charcode and glyphind dictionarycoded={}glyphd={}forccode,glyphindincodes:name=font.get_glyph_name(glyphind)coded[name]=ccodeglyphd[name]=glyphind# print(glyphind, ccode, hex(int(ccode)), name)code=coded['A']glyph=font.load_char(code)print(glyph.bbox)print(glyphd['A'],glyphd['V'],coded['A'],coded['V'])print('AV',font.get_kerning(glyphd['A'],glyphd['V'],Kerning.DEFAULT))print('AV',font.get_kerning(glyphd['A'],glyphd['V'],Kerning.UNFITTED))print('AV',font.get_kerning(glyphd['A'],glyphd['V'],Kerning.UNSCALED))print('AT',font.get_kerning(glyphd['A'],glyphd['T'],Kerning.UNSCALED))

Gallery generated by Sphinx-Gallery