mpl.font_manager¶
A module for finding, managing, and using fonts across platforms.
This module provides a single FontManager instance that can
be shared across backends and platforms. The findfont()
function returns the best TrueType (TTF) font file in the local or
system font path that matches the specified FontProperties
instance. The FontManager also handles Adobe Font Metrics
(AFM) font files for use by the PostScript backend.
The design is based on the W3C Cascading Style Sheet, Level 1 (CSS1) font specification. Future versions may implement the Level 2 or 2.1 specifications.
Experimental support is included for using fontconfig on Unix
variant platforms (Linux, OS X, Solaris). To enable it, set the
constant USE_FONTCONFIG in this file to True. Fontconfig has
the advantage that it is the standard way to look up fonts on X11
platforms, so if a font is installed, it is much more likely to be
found.
Functions¶
OSXInstalledFonts([directories, fontext]) |
Get list of font files on OS X - ignores font suffix by default. |
afmFontProperty(fontpath, font) |
A function for populating a FontKey instance by extracting information from the AFM font file. |
createFontList(fontfiles[, fontext]) |
A function to create a font lookup list. |
findSystemFonts([fontpaths, fontext]) |
Search for fonts in the specified font paths. |
findfont(prop, **kw) |
|
generate_fontconfig_pattern(d) |
Given a dictionary of key/value pairs, generates a fontconfig pattern string. |
get_cachedir(*args, **kwargs) |
Return the location of the cache directory. |
get_fontconfig_fonts([fontext]) |
Grab a list of all the fonts that are being tracked by fontconfig by making a system call to fc-list. |
get_fontext_synonyms(fontext) |
Return a list of file extensions extensions that are synonyms for the given file extension fileext. |
is_opentype_cff_font(filename) |
Returns True if the given font is a Postscript Compact Font Format Font embedded in an OpenType wrapper. |
is_string_like(obj) |
Return True if obj looks like a string |
list_fonts(directory, extensions) |
Return a list of all fonts matching any of the extensions, possibly upper-cased, found recursively under the directory. |
pickle_dump(data, filename) |
Equivalent to pickle.dump(data, open(filename, ‘w’)) but closes the file to prevent filehandle leakage. |
pickle_load(filename) |
Equivalent to pickle.load(open(filename, ‘r’)) but closes the file to prevent filehandle leakage. |
ttfFontProperty(font) |
A function for populating the FontKey by extracting information from the TrueType font file. |
ttfdict_to_fnames(d) |
flatten a ttfdict to all the filenames it contains |
weight_as_number(weight) |
Return the weight property as a numeric value. |
win32FontDirectory() |
Return the user-specified font directory for Win32. |
win32InstalledFonts([directory, fontext]) |
Search for fonts in the specified font directory, or use the system directories if none given. |
Classes¶
FontEntry([fname, name, style, variant, ...]) |
A class for storing Font properties. |
FontManager([size, weight]) |
On import, the FontManager singleton instance creates a list of TrueType fonts based on the font properties: name, style, variant, weight, stretch, and size. |
FontProperties([family, style, variant, ...]) |
A class for storing and manipulating font properties. |
Iterable |
|
TempCache() |
A class to store temporary caches that are (a) not saved to disk and (b) invalidated whenever certain font-related rcParams—namely the family lookup lists—are changed or the font cache is reloaded. |