diff --git a/examples/misc/font_indexing.py b/examples/misc/font_indexing.py index 7625671968bd..5599eb313707 100644 --- a/examples/misc/font_indexing.py +++ b/examples/misc/font_indexing.py @@ -1,28 +1,23 @@ """ ============= -Font Indexing +Font indexing ============= -A little example that shows how the various indexing into the font -tables relate to one another. Mainly for mpl developers.... - +This example shows how the font tables relate to one another. """ + +import os + import matplotlib -from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, KERNING_UNFITTED, KERNING_UNSCALED +from matplotlib.ft2font import ( + FT2Font, KERNING_DEFAULT, KERNING_UNFITTED, KERNING_UNSCALED) -fname = matplotlib.get_data_path() + '/fonts/ttf/DejaVuSans.ttf' -font = FT2Font(fname) +font = FT2Font( + os.path.join(matplotlib.get_data_path(), 'fonts/ttf/DejaVuSans.ttf')) font.set_charmap(0) codes = font.get_charmap().items() -#dsu = [(ccode, glyphind) for ccode, glyphind 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 = {} @@ -31,6 +26,7 @@ name = font.get_glyph_name(glyphind) coded[name] = ccode glyphd[name] = glyphind + # print(glyphind, ccode, hex(int(ccode)), name) code = coded['A'] glyph = font.load_char(code) diff --git a/examples/misc/ftface_props.py b/examples/misc/ftface_props.py index b40a892715ae..2458addcbca2 100644 --- a/examples/misc/ftface_props.py +++ b/examples/misc/ftface_props.py @@ -1,22 +1,23 @@ """ -============ -Ftface Props -============ +=============== +Font properties +=============== -This is a demo script to show you how to use all the properties of an -FT2Font object. These describe global font properties. For -individual character metrics, use the Glyph object, as returned by -load_char +This example lists the attributes of an `FT2Font` object, which describe global +font properties. For individual character metrics, use the `Glyph` object, as +returned by `load_char`. """ + +import os + import matplotlib import matplotlib.ft2font as ft -#fname = '/usr/local/share/matplotlib/VeraIt.ttf' -fname = matplotlib.get_data_path() + '/fonts/ttf/DejaVuSans-Oblique.ttf' -#fname = '/usr/local/share/matplotlib/cmr10.ttf' - -font = ft.FT2Font(fname) +font = ft.FT2Font( + # Use a font shipped with Matplotlib. + os.path.join(matplotlib.get_data_path(), + 'fonts/ttf/DejaVuSans-Oblique.ttf')) print('Num faces :', font.num_faces) # number of faces in file print('Num glyphs :', font.num_glyphs) # number of glyphs in the face @@ -61,7 +62,3 @@ 'External stream'): bitpos = getattr(ft, style.replace(' ', '_').upper()) - 1 print('%-17s:' % style, bool(font.style_flags & (1 << bitpos))) - -print(dir(font)) - -print(font.get_kerning)