Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4bf6b54

Browse filesBrowse files
committed
Cleanup font_manager.
- Reword FontManager docstring. - Fix incorrect doc for rebuild_if_missing paramter to findfont. - Pass fallback_to_default/rebuild_if_missing as explicit keyword arguments, rather than positionally (``True, False`` is just too hard to read).
1 parent cbd0409 commit 4bf6b54
Copy full SHA for 4bf6b54

File tree

Expand file treeCollapse file tree

1 file changed

+13
-11
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-11
lines changed

‎lib/matplotlib/font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/font_manager.py
+13-11Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -941,12 +941,11 @@ def _normalize_font_family(family):
941941

942942
class FontManager:
943943
"""
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.
950949
"""
951950
# Increment this version number whenever the font cache data
952951
# format or behavior has changed and requires a existing font
@@ -1196,12 +1195,15 @@ def findfont(self, prop, fontext='ttf', directory=None,
11961195
11971196
directory : str, optional
11981197
If given, only search this directory and its subdirectories.
1198+
11991199
fallback_to_default : bool
12001200
If True, will fallback to the default font family (usually
12011201
"DejaVu Sans" or "Helvetica") if the first lookup hard-fails.
1202+
12021203
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).
12051207
12061208
Returns
12071209
-------
@@ -1225,7 +1227,6 @@ def findfont(self, prop, fontext='ttf', directory=None,
12251227
12261228
.. _fontconfig patterns:
12271229
https://www.freedesktop.org/software/fontconfig/fontconfig-user.html
1228-
12291230
"""
12301231
# Pass the relevant rcParams (and the font manager, as `self`) to
12311232
# _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,
12821283
prop.get_family(), self.defaultFamily[fontext])
12831284
default_prop = prop.copy()
12841285
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)
12861288
else:
12871289
# This is a hard fail -- we can't find anything reasonable,
12881290
# so just return the DejaVuSans.ttf
@@ -1300,7 +1302,7 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
13001302
'findfont: Found a missing font file. Rebuilding cache.')
13011303
_rebuild()
13021304
return fontManager.findfont(
1303-
prop, fontext, directory, True, False)
1305+
prop, fontext, directory, rebuild_if_missing=False)
13041306
else:
13051307
raise ValueError("No valid font could be found")
13061308

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.