Skip to content

Don't set a default size for FT2Font - #30319

Merged
tacaswell merged 1 commit into
matplotlib:text-overhaulfrom
QuLogic:ft2font-size
Jul 16, 2025
Merged

tacaswell merged 1 commit into
matplotlib:text-overhaulfrom
QuLogic:ft2font-size

Conversation

@QuLogic

@QuLogic QuLogic commented Jul 16, 2025

Copy link
Copy Markdown
Member

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

@anntzer anntzer left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
@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
wavebyrd pushed a commit to wavebyrd/matplotlib that referenced this pull request Mar 13, 2026
Don't set a default size for FT2Font
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