Skip to content

Don't set a default size for FT2Font #30319

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
Jul 16, 2025

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Jul 16, 2025

PR summary

In the interest of handling non-scalable fonts and reducing font initialization, drop the default size from the FT2Font constructor. Non-scalable fonts are sometimes used for bitmap-backed emoji fonts. When we start supporting collection fonts (.ttc), then setting a size is a waste, as we will just need to read the count of fonts within.

The renderer method Renderer.draw_text always sets a size immediately after creating the font object, so this doesn't affect anything in most cases. Only the direct FT2Font tests need changes.

I'm only unsure whether we wish to somehow warn/deprecate when this the size isn't set explicitly.

PR checklist

In the interest of handling non-scalable fonts and reducing font
initialization, drop the default size from the `FT2Font` constructor.
Non-scalable fonts are sometimes used for bitmap-backed emoji fonts.
When we start supporting collection fonts (`.ttc`), then setting a size
is a waste, as we will just need to read the count of fonts within.

The renderer method `Renderer.draw_text` always sets a size immediately
after creating the font object, so this doesn't affect anything in most
cases. Only the direct `FT2Font` tests need changes.
@github-project-automation github-project-automation bot moved this to Waiting for other PR in Font and text overhaul Jul 16, 2025
@QuLogic QuLogic moved this from Waiting for other PR to Ready for Review in Font and text overhaul Jul 16, 2025
Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

Emitting a warning would seem quite tedious to do.

@timhoffm
Copy link
Member

Would it make sense to add an optional size parameter to the constructor so that one does not have to do a separate set_size() call? i.e. optionally initialize as part of construction.

@tacaswell
Copy link
Member

Given that the target consumer of Font objects is the draw method of our Text classes and they already have to always set the font size (you can't trust that it came in with the right size) I'm in favor of waiting for a user to have a need for this outside of our tests.

@tacaswell tacaswell merged commit 7dae1e5 into matplotlib:text-overhaul Jul 16, 2025
36 checks passed
@github-project-automation github-project-automation bot moved this from Ready for Review to Done in Font and text overhaul Jul 16, 2025
@QuLogic QuLogic deleted the ft2font-size branch July 16, 2025 23:06
@QuLogic QuLogic added this to the v3.11.0 milestone Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants