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

Method addfont

lib/matplotlib/font_manager.py:1269–1308  ·  view source on GitHub ↗

Cache the properties of the font at *path* to make it available to the `FontManager`. The type of font is inferred from the path suffix. Parameters ---------- path : str or path-like Notes ----- This method is useful for adding a cu

(self, path)

Source from the content-addressed store, hash-verified

1267 timer.cancel()
1268
1269 def addfont(self, path):
1270 """
1271 Cache the properties of the font at *path* to make it available to the
1272 `FontManager`. The type of font is inferred from the path suffix.
1273
1274 Parameters
1275 ----------
1276 path : str or path-like
1277
1278 Notes
1279 -----
1280 This method is useful for adding a custom font without installing it in
1281 your operating system. See the `FontManager` singleton instance for
1282 usage and caveats about this function.
1283 """
1284 # Convert to string in case of a path as
1285 # afmFontProperty and FT2Font expect this
1286 path = os.fsdecode(path)
1287 if Path(path).suffix.lower() == ".afm":
1288 with open(path, "rb") as fh:
1289 font = _afm.AFM(fh)
1290 prop = afmFontProperty(path, font)
1291 self.afmlist.append(prop)
1292 else:
1293 font = ft2font.FT2Font(path)
1294 prop = ttfFontProperty(font)
1295 self.ttflist.append(prop)
1296 for alt_name, alt_weight in _get_font_alt_names(font, prop.name):
1297 self.ttflist.append(
1298 dataclasses.replace(prop, name=alt_name, weight=alt_weight))
1299
1300 for face_index in range(1, font.num_faces):
1301 subfont = ft2font.FT2Font(path, face_index=face_index)
1302 prop = ttfFontProperty(subfont)
1303 self.ttflist.append(prop)
1304 for alt_name, alt_weight in _get_font_alt_names(subfont, prop.name):
1305 self.ttflist.append(
1306 dataclasses.replace(prop, name=alt_name, weight=alt_weight))
1307
1308 self._findfont_cached.cache_clear()
1309
1310 @property
1311 def defaultFont(self):

Callers 4

__init__Method · 0.95
test_mathtext_fallbackFunction · 0.80
test_addfont_as_pathFunction · 0.80

Calls 4

PathClass · 0.85
afmFontPropertyFunction · 0.85
ttfFontPropertyFunction · 0.85
_get_font_alt_namesFunction · 0.85

Tested by 3

test_mathtext_fallbackFunction · 0.64
test_addfont_as_pathFunction · 0.64