Note

Go to the endto download the full example code.

Font properties#

This example lists the attributes of anFT2Font object, which describeglobal font properties. For individual character metrics, use theGlyphobject, as returned byload_char.

Num instances:   0Num faces:       1Num glyphs:      5343Family name:     DejaVu SansStyle name:      ObliquePS name:         DejaVuSans-ObliqueNum fixed:       0Bbox:                (-2080, -717, 3398, 2187)EM:                  2048Ascender:            1901Descender:           -483Height:              2384Max adv width:       3461Max adv height:      2384Underline pos:       -175Underline thickness: 90Italic:           TrueBold:             FalseScalable:         TrueFixed Sizes:      FalseFixed Width:      FalseSfnt:             TrueHorizontal:       TrueVertical:         FalseKerning:          TrueFast Glyphs:      FalseMultiple Masters: FalseGlyph Names:      TrueExternal Stream:  TrueHinter:           TrueCid Keyed:        FalseTricky:           FalseColor:            FalseVariation:        FalseSvg:              FalseSbix:             FalseSbix Overlay:     False

importosimportmatplotlibimportmatplotlib.ft2fontasftfont=ft.FT2Font(# Use a font shipped with Matplotlib.os.path.join(matplotlib.get_data_path(),'fonts/ttf/DejaVuSans-Oblique.ttf'))print('Num instances:  ',font.num_named_instances)# number of named instances in fileprint('Num faces:      ',font.num_faces)# number of faces in fileprint('Num glyphs:     ',font.num_glyphs)# number of glyphs in the faceprint('Family name:    ',font.family_name)# face family nameprint('Style name:     ',font.style_name)# face style nameprint('PS name:        ',font.postscript_name)# the postscript nameprint('Num fixed:      ',font.num_fixed_sizes)# number of embedded bitmaps# the following are only available if face.scalableiffont.scalable:# the face global bounding box (xmin, ymin, xmax, ymax)print('Bbox:               ',font.bbox)# number of font units covered by the EMprint('EM:                 ',font.units_per_EM)# the ascender in 26.6 unitsprint('Ascender:           ',font.ascender)# the descender in 26.6 unitsprint('Descender:          ',font.descender)# the height in 26.6 unitsprint('Height:             ',font.height)# maximum horizontal cursor advanceprint('Max adv width:      ',font.max_advance_width)# same for vertical layoutprint('Max adv height:     ',font.max_advance_height)# vertical position of the underline barprint('Underline pos:      ',font.underline_position)# vertical thickness of the underlineprint('Underline thickness:',font.underline_thickness)forflaginft.StyleFlags:name=flag.name.replace('_',' ').title()+':'print(f"{name:17}",flaginfont.style_flags)forflaginft.FaceFlags:name=flag.name.replace('_',' ').title()+':'print(f"{name:17}",flaginfont.face_flags)

Gallery generated by Sphinx-Gallery