8000 Numpydocify FontManager.findfont() by timhoffm · Pull Request #13815 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Numpydocify FontManager.findfont() #13815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2019
Merged
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
55 changes: 40 additions & 15 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,28 +1177,53 @@ def score_size(self, size1, size2):
def findfont(self, prop, fontext='ttf', directory=None,
fallback_to_default=True, rebuild_if_missing=True):
"""
Search the font list for the font that most closely matches
the :class:`FontProperties` *prop*.

:meth:`findfont` performs a nearest neighbor search. Each
font is given a similarity score to the target font
properties. The first font with the highest score is
returned. If no matches below a certain threshold are found,
the default font (usually DejaVu Sans) is returned.

`directory`, is specified, will only return fonts from the
given directory (or subdirectory of that directory).
Find a font that most closely matches the given font properties.

Parameters
----------
prop : str or `~matplotlib.font_manager.FontProperties`
The font properties to search for. This can be either a
`.FontProperties` object or a string defining a
`fontconfig patterns`_.

fontext : {'ttf', 'afm'}, optional, default: 'ttf'
The extension of the font file:

- 'ttf': TrueType and OpenType fonts (.ttf, .ttc, .otf)
- 'afm': Adobe Font Metrics (.afm)

directory : str, optional
If given, only search this directory and its subdirectories.
fallback_to_default : bool
If True, will fallback to the default font family (usually
"DejaVu Sans" or "Helvetica") if the first lookup hard-fails.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand the behavior for fallback_to_default=False. This also returns "DejaVu Sans". Not sure if this is a bug. Anyway, we're missing documentation for the non-fallback result.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In one case we still try to match the font size, weight, and style (italic, bold, etc.) but not in the other. TBH I doubt the distinction really matters and would suggest just deprecating that argument (can be done in a separate PR, of course).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I'll take care of that later in a separate PR.

rebuild_if_missing : bool
Whether to rebuild the font cache and search again if no match
is found.

Returns
-------
fontfile : str
The filename of the best matching font.

Notes
-----
This performs a nearest neighbor search. Each font is given a
similarity score to the target font properties. The first font with
the highest score is returned. If no matches below a certain
threshold are found, the default font (usually DejaVu Sans) is
returned.

The result is cached, so subsequent lookups don't have to
perform the O(n) nearest neighbor search.

If `fallback_to_default` is True, will fallback to the default
font family (usually "DejaVu Sans" or "Helvetica") if
the first lookup hard-fails.

See the `W3C Cascading Style Sheet, Level 1
<http://www.w3.org/TR/1998/REC-CSS2-19980512/>`_ documentation
for a description of the font finding algorithm.

.. _fontconfig patterns:
https://www.freedesktop.org/software/fontconfig/fontconfig-user.html

"""
# Pass the relevant rcParams (and the font manager, as `self`) to
# _findfont_cached so to prevent using a stale cache entry after an
Expand Down
0