@@ -941,12 +941,11 @@ def _normalize_font_family(family):
941
941
942
942
class FontManager :
943
943
"""
944
- On import, the :class:`FontManager` singleton instance creates a
945
- list of TrueType fonts based on the font properties: name, style,
946
- variant, weight, stretch, and size. The :meth:`findfont` method
947
- does a nearest neighbor search to find the font that most closely
948
- matches the specification. If no good enough match is found, a
949
- default font is returned.
944
+ On import, the `FontManager` singleton instance creates a list of ttf and
945
+ afm fonts and caches their `FontProperties`. The `FontManager.findfont`
946
+ method does a nearest neighbor search to find the font that most closely
947
+ matches the specification. If no good enough match is found, the default
948
+ font is returned.
950
949
"""
951
950
# Increment this version number whenever the font cache data
952
951
# format or behavior has changed and requires a existing font
@@ -1196,12 +1195,15 @@ def findfont(self, prop, fontext='ttf', directory=None,
1196
1195
1197
1196
directory : str, optional
1198
1197
If given, only search this directory and its subdirectories.
1198
+
1199
1199
fallback_to_default : bool
1200
1200
If True, will fallback to the default font family (usually
1201
1201
"DejaVu Sans" or "Helvetica") if the first lookup hard-fails.
1202
+
1202
1203
rebuild_if_missing : bool
1203
- Whether to rebuild the font cache and search again if no match
1204
- is found.
1204
+ Whether to rebuild the font cache and search again if the first
1205
+ match appears to point to a nonexisting font (i.e., the font cache
1206
+ contains outdated entries).
1205
1207
1206
1208
Returns
1207
1209
-------
@@ -1225,7 +1227,6 @@ def findfont(self, prop, fontext='ttf', directory=None,
1225
1227
1226
1228
.. _fontconfig patterns:
1227
1229
https://www.freedesktop.org/software/fontconfig/fontconfig-user.html
1228
-
1229
1230
"""
1230
1231
# Pass the relevant rcParams (and the font manager, as `self`) to
1231
1232
# _findfont_cached so to prevent using a stale cache entry after an
@@ -1282,7 +1283,8 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
1282
1283
prop .get_family (), self .defaultFamily [fontext ])
1283
1284
default_prop = prop .copy ()
1284
1285
default_prop .set_family (self .defaultFamily [fontext ])
1285
- return self .findfont (default_prop , fontext , directory , False )
1286
+ return self .findfont (default_prop , fontext , directory ,
1287
+ fallback_to_default = False )
1286
1288
else :
1287
1289
# This is a hard fail -- we can't find anything reasonable,
1288
1290
# so just return the DejaVuSans.ttf
@@ -1300,7 +1302,7 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
1300
1302
'findfont: Found a missing font file. Rebuilding cache.' )
1301
1303
_rebuild ()
1302
1304
return fontManager .findfont (
1303
- prop , fontext , directory , True , False )
1305
+ prop , fontext , directory , rebuild_if_missing = False )
1304
1306
else :
1305
1307
raise ValueError ("No valid font could be found" )
1306
1308
0 commit comments