MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / FontManager

Class FontManager

lib/matplotlib/font_manager.py:1195–1716  ·  view source on GitHub ↗

On import, the `FontManager` singleton instance creates a list of ttf and afm fonts and caches their `FontProperties`. The `FontManager.findfont` method does a nearest neighbor search to find the font that most closely matches the specification. If no good enough match is found, t

Source from the content-addressed store, hash-verified

1193
1194
1195class FontManager:
1196 """
1197 On import, the `FontManager` singleton instance creates a list of ttf and
1198 afm fonts and caches their `FontProperties`. The `FontManager.findfont`
1199 method does a nearest neighbor search to find the font that most closely
1200 matches the specification. If no good enough match is found, the default
1201 font is returned.
1202
1203 Fonts added with the `FontManager.addfont` method will not persist in the
1204 cache; therefore, `addfont` will need to be called every time Matplotlib is
1205 imported. This method should only be used if and when a font cannot be
1206 installed on your operating system by other means.
1207
1208 Notes
1209 -----
1210 The `FontManager.addfont` method must be called on the global `FontManager`
1211 instance.
1212
1213 Example usage::
1214
1215 import matplotlib.pyplot as plt
1216 from matplotlib import font_manager
1217
1218 font_dirs = ["/resources/fonts"] # The path to the custom font file.
1219 font_files = font_manager.findSystemFonts(fontpaths=font_dirs)
1220
1221 for font_file in font_files:
1222 font_manager.fontManager.addfont(font_file)
1223 """
1224 # Increment this version number whenever the font cache data
1225 # format or behavior has changed and requires an existing font
1226 # cache files to be rebuilt.
1227 __version__ = '3.11.0'
1228
1229 def __init__(self, size=None, weight='normal'):
1230 self._version = self.__version__
1231
1232 self.__default_weight = weight
1233 self.default_size = size
1234
1235 # Create list of font paths.
1236 paths = [cbook._get_data_path('fonts', subdir)
1237 for subdir in ['ttf', 'afm', 'pdfcorefonts']]
1238 _log.debug('font search path %s', paths)
1239
1240 self.defaultFamily = {
1241 'ttf': 'DejaVu Sans',
1242 'afm': 'Helvetica'}
1243
1244 self.afmlist = []
1245 self.ttflist = []
1246
1247 # Delay the warning by 5s.
1248 try:
1249 timer = threading.Timer(5, lambda: _log.warning(
1250 'Matplotlib is building the font cache; this may take a moment.'))
1251 timer.start()
1252 except RuntimeError:

Callers 1

_load_fontmanagerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…