Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Add support for loading all fonts from collections#30334
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
QuLogic wants to merge3 commits intomatplotlib:text-overhaulChoose a base branch fromQuLogic:ttc-loading
base:text-overhaul
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+112 −27
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This enables loading a non-initial font from collections (`.ttc` files).Currently exposed for `FT2Font` and `font_manager.get_font`.
This should allow listing the metadata from the whole collection, whichwill also pick the right one if specified, though it will not load thespecific index yet.
For backwards-compatibility, the path+index is passed around in alightweight subclass of `str`.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR summary
This turned out to be more straightforward than I expected, but it will probably need a few API decisions to be fully complete.
From bottom to top of the API:
FT2Font
accepts aface_index
parameter to specify which face to load in a collection, and a correspondingface_index
property to check what's loaded.FontManager.get_font
accepts a tuple of font path and face index in places it would accept just a path. But also see the next point.FontManager.findfont
returns astr
-like classFontPath
(name up for debate) which has aface_index
attribute and is accepted byget_font
much like the tuple. If anyone uses them as strings though, it should act pretty much the same.For example, now I can see all variants of Noto Sans CJK:
or all variants of WenQuanYi that we use for tests:
Fixes#3135
TODO
API questions
str | bytes | Path
, I wonder if we should change toos.PathLike
?FontPath
, I'm thinking maybe that's redundant and we should just stick with theFontPath
class only. Do we want to accept the tuple form as well, or should I drop it?FontPath
is a subclass ofstr
which allows using it as astr
as one normally would. That was the minimum implementation needed, but we probably want to flesh that out a bit. At minimum, I think we should implement__eq__
and__hash__
so that you can use it as a dictionary key without clashing with an equivalentstr
. But then do we want to add a deprecation warning when making those comparisons? And after thinking about it a bit more, would anamedtuple
with__eq__
instead be a better choice?PR checklist