FIX: correctly handle generic font families in svg text-as-text mode by tacaswell · Pull Request #23638 · matplotlib/matplotlib · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions lib/matplotlib/backends/backend_svg.py
17 changes: 13 additions & 4 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,9 +1345,12 @@ def findfont(self, prop, fontext='ttf', directory=None,
rc_params = tuple(tuple(mpl.rcParams[key]) for key in [
"font.serif", "font.sans-serif", "font.cursive", "font.fantasy",
"font.monospace"])
return self._findfont_cached(
ret = self._findfont_cached(
prop, fontext, directory, fallback_to_default, rebuild_if_missing,
rc_params)
if isinstance(ret, Exception):
raise ret
return ret

def get_font_names(self):
"""Return the list of available fonts."""
Expand Down Expand Up @@ -1496,8 +1499,11 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
return self.findfont(default_prop, fontext, directory,
fallback_to_default=False)
else:
raise ValueError(f"Failed to find font {prop}, and fallback "
f"to the default font was disabled")
# This return instead of raise is intentional, as we wish to
# cache the resulting exception, which will not occur if it was
# actually raised.
return ValueError(f"Failed to find font {prop}, and fallback "
f"to the default font was disabled")
else:
_log.debug('findfont: Matching %s to %s (%r) with score of %f.',
prop, best_font.name, best_font.fname, best_score)
Expand All @@ -1516,7 +1522,10 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
return self.findfont(
prop, fontext, directory, rebuild_if_missing=False)
else:
raise ValueError("No valid font could be found")
# This return instead of raise is intentional, as we wish to
# cache the resulting exception, which will not occur if it was
# actually raised.
return ValueError("No valid font could be found")

return _cached_realpath(result)

Expand Down
61 changes: 61 additions & 0 deletions lib/matplotlib/tests/test_backend_svg.py