Use more specific patterns for bundled mathtext fonts by QuLogic · Pull Request #32302 · matplotlib/matplotlib · GitHub
Skip to content

Use more specific patterns for bundled mathtext fonts - #32302

Open
QuLogic wants to merge 2 commits into
matplotlib:mainfrom
QuLogic:mathtext-fonts
Open

Use more specific patterns for bundled mathtext fonts#32302
QuLogic wants to merge 2 commits into
matplotlib:mainfrom
QuLogic:mathtext-fonts

Conversation

@QuLogic

@QuLogic QuLogic commented Sep 5, 2026

Copy link
Copy Markdown
Member

PR summary

Because we previously only asked for a font family (and sometimes a weight/style), mathtext fonts were at the whim of rcParams for all other settings. This could mean that we would look for an non-existent weight, or even set the normal font to italic unintentionally.

The fonts that are available for mathtext are (for now) fixed and bundled, and we only intend for them to work with the exact fonts we have. So use more specific fontconfig patterns that should always match the fonts that we have.

While it could be possible to simply hard-code these paths relative to our data path, it seems that way back in 157a059, that implementation was changed to findfont intentionally to avoid duplicate embeddings.

Also remove a redundant test.

AI Disclosure

None

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • [n/a] Plotting related features are demonstrated in an example
  • [n/a] New features and API changes have release notes
  • [n/a] Documentation complies with general and docstring guidelines

This test just checks `get_sfnt_table('head')` for DejaVu Sans, but
there is a more comprehensive test of all SFNT tables in
`test_ft2font.py::test_ft2font_get_sfnt_table`.
@QuLogic QuLogic added this to the v3.11.2 milestone Sep 5, 2026
@QuLogic QuLogic linked an issue Sep 5, 2026 that may be closed by this pull request
@QuLogic
QuLogic force-pushed the mathtext-fonts branch 2 times, most recently from 6d04047 to 83feec5 Compare September 5, 2026 06:45
Because we previously only asked for a font family (and sometimes a
weight/style), mathtext fonts were at the whim of rcParams for all other
settings. This could mean that we would look for an non-existent weight,
or even set the normal font to italic unintentionally.

The fonts that are available for mathtext are (for now) fixed and
bundled, and we only intend for them to work with the exact fonts we
have. So use more specific fontconfig patterns that should always match
the fonts that we have.

While it could be possible to simply hard-code these paths relative to
our data path, it seems that way back in
157a059, that implementation was
changed to `findfont` intentionally to avoid duplicate embeddings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Font lookup when rendering math text

1 participant