GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ENH: Allow fonts to be addressed by any of their SFNT family names by Cemonix · Pull Request #31183 · matplotlib/matplotlib

Conversation

@Cemonix

@Cemonix Cemonix commented Feb 20, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

PR summary

Closes #4822

A TTF/OTF font file can advertise its family name in multiple places in the
OpenType name table. FreeType exposes one name (typically from the
Macintosh-platform Name ID 1 slot), but other entries carry equally valid names
that users reasonably expect to work:

  • Name ID 1, other platform — some fonts store different names on the Mac
    and Microsoft platforms. For example, Ubuntu Light stores "Ubuntu" in the
    Mac slot and "Ubuntu Light" in the Microsoft slot.
  • Name ID 16 — Typographic/Preferred Family: groups more than the
    traditional four styles (Regular, Bold, Italic, Bold Italic) under one name.
  • Name ID 21 — WWS Family: an even narrower grouping (weight/width/slope
    only).

Previously, only the FreeType-derived name was registered, so users had to use
an unintuitive weight-based workaround:

# Before
matplotlib.rcParams['font.family'] = 'Ubuntu'
matplotlib.rcParams['font.weight'] = 300

This PR adds _get_font_alt_names() and calls it from FontManager.addfont()
to register a separate FontEntry for each alternative name found. Each
alternate entry derives its weight from the corresponding subfamily string
(ID 2/17/22) on the same platform, so that the font's role within its named
family is reflected correctly (e.g. Ubuntu Light is weight 400/"Regular" within
the "Ubuntu Light" family, even though its absolute typographic weight is 300).

After this change:

matplotlib.rcParams['font.family'] = 'Ubuntu Light'

PR checklist

  • closes Light font variants cannot be accessed by common name #4822 is in the body of the PR description to link the related issue
  • new and changed code is tested
  • Plotting related features are demonstrated in an example
  • New Features and API Changes are noted with a directive and release note
  • Documentation complies with general and docstring guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions

github-actions Bot commented Feb 20, 2026

Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the first-contribution label Feb 20, 2026
@Cemonix
Cemonix force-pushed the fix-font-alt-family-names branch 4 times, most recently from 38ef911 to 837a43a Compare February 21, 2026 10:18
@tacaswell

tacaswell commented Feb 23, 2026

Copy link
Copy Markdown
Member

This seems reasonable on a quick read to me, but @QuLogic needs to review this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic

QuLogic commented Feb 23, 2026

Copy link
Copy Markdown
Member

It probably makes sense to add more names where available, but I'm uncertain whether, e.g., Ubuntu Light should be regular weight, or a Light suffix should trigger a lower weight instead.

IIRC, @anntzer last looked at the algorithm here, and is probably best suited to deciding.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@melissawm melissawm added topic: text/fonts status: needs review labels Feb 25, 2026
@anntzer

anntzer commented Feb 26, 2026

Copy link
Copy Markdown
Contributor
  • I agree that there's something not so clear about whether family = "Ubuntu Light" should match with weight = "Regular" (in that it's the "Regular" "Ubuntu Light" font). Maybe we need FontProperties attributes to have an "unset" value (differing from "Regular")? How does e.g. CSS matching (which is very well specified) work in that case?
  • How does the name detection compare with fontconfig's algorithm (at https://cgit.freedesktop.org/fontconfig/tree/src/fcfreetype.c#n1384)?
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Cemonix

Cemonix commented Feb 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the questions! I reviewed fontconfig's FcFreeTypeQueryFaceInternal and the CSS font matching spec to understand this better.

Re: fontconfig comparison:

The approach is very similar - both iterate over name IDs (1/16/21 for family, 2/17/22 for subfamily) on Mac and Microsoft platforms, then parse the subfamily string for weight keywords.

The main difference: fontconfig uses -1 as "unset" and defaults to FC_WEIGHT_MEDIUM if no weight is found, while my code defaults to 400 immediately when no keyword matches.

Re: "unset" vs 400:

I chose 400 to match matplotlib's existing behavior and CSS semantics. In CSS, an unspecified weight always resolves to a numeric value (typically 400/"normal") before font matching begins. So when a user requests family='Ubuntu Light' without specifying weight, they get the "Regular" variant of that family.

However, I'm open to using a sentinel value (like None) if you think that better represents these alternate families. The tradeoff is it would require changes to the scoring function to handle unset weights.

Re: CSS matching:

CSS Fonts Level 4 spec defines normal = 400, and the matching algorithm searches outward from the requested weight when exact matches aren't available. There's no concept of "unset weight" in the matching algorithm - it always works with numeric values.

Let me know if you'd prefer a different approach for handling the weights.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@melissawm melissawm added this to First Time Contributors Mar 6, 2026
@melissawm melissawm moved this to Needs review in First Time Contributors Mar 6, 2026
QuLogic
QuLogic reviewed Mar 20, 2026
View reviewed changes

@QuLogic QuLogic left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Since you are changing the FontEntrys, I think you would need to bump the FontManager.__version__ to ensure the cache is regenerated.

I also think you may want to target the text-overhaul branch, as I suspect there will be some conflicts that would need resolving.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/matplotlib/font_manager.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the topic: text/fonts label Mar 20, 2026
@Cemonix
Cemonix force-pushed the fix-font-alt-family-names branch from 9e6bdcc to ef596a5 Compare March 20, 2026 17:35
Cemonix and others added 3 commits March 20, 2026 18:55
@Cemonix
ENH: Register all SFNT family names so fonts are addressable by any p…
3374e25
…latform name

A TTF/OTF file can advertise its family name in multiple places in the
SFNT name table.  FreeType exposes the primary name (usually from the
Macintosh-platform Name ID 1 slot), but other entries may carry
different (equally valid) names that users reasonably expect to work:

- Name ID 1 on the other platform (e.g. Ubuntu Light stores "Ubuntu"
  in the Mac slot and "Ubuntu Light" in the Microsoft slot)
- Name ID 16 — Typographic/Preferred Family
- Name ID 21 — WWS Family
@Cemonix
DOC: Add what's new entry for font alternative family name registration
af4ded1
@Cemonix @QuLogic
Fixed the encoding string to match the rest of the file.
b6cde63
Co-authored-by: Elliott Sales de Andrade <[email protected]>
@Cemonix
Cemonix force-pushed the fix-font-alt-family-names branch from ef596a5 to c776974 Compare March 20, 2026 18:03
@Cemonix
Cemonix changed the base branch from main to text-overhaul March 20, 2026 18:03
@github-actions github-actions Bot added the CI: Run cibuildwheel Run wheel building tests on a PR label Mar 20, 2026
@Cemonix

Cemonix commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

Done, also fixed the face-loop conflict in addfont and the set append in the test while rebasing onto text-overhaul.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

QuLogic
QuLogic reviewed Mar 20, 2026
View reviewed changes
Comment thread lib/matplotlib/font_manager.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic QuLogic added this to Font and text overhaul Mar 20, 2026
@github-project-automation github-project-automation Bot moved this to Waiting for other PR in Font and text overhaul Mar 20, 2026
@QuLogic QuLogic moved this from Waiting for other PR to Ready for Review in Font and text overhaul Mar 20, 2026
@QuLogic QuLogic added this to the v3.11.0 milestone Mar 20, 2026
@Cemonix
Cemonix force-pushed the fix-font-alt-family-names branch from c776974 to b6cde63 Compare March 20, 2026 21:47
@github-actions github-actions Bot removed the CI: Run cibuildwheel Run wheel building tests on a PR label Mar 20, 2026
@Cemonix
Bump FontManager cache version for alt family name entries
716796e
QuLogic
QuLogic approved these changes Mar 26, 2026
View reviewed changes

@QuLogic QuLogic left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looking at https://learn.microsoft.com/en-us/typography/opentype/spec/name, it makes sense to me to look at IDs 1/2, 16/17, and 21/22. Maybe that'll be too many, but we'll see if people complain.

And I can see the argument that "Ubuntu Light" -> (name="Ubuntu", weight=100) with a separate entry of (name="Ubuntu Light", weight=400).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Cemonix reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@melissawm melissawm moved this from Needs review to Needs decision in First Time Contributors Mar 26, 2026
ksunden
ksunden approved these changes Mar 27, 2026
View reviewed changes
@ksunden
ksunden merged commit 4efa3c0 into matplotlib:text-overhaul Mar 27, 2026
26 of 36 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-project-automation github-project-automation Bot moved this from Ready for Review to Done in Font and text overhaul Mar 27, 2026
@github-project-automation github-project-automation Bot moved this from Needs decision to Merged in First Time Contributors Mar 27, 2026
@ksunden

ksunden commented Mar 27, 2026

Copy link
Copy Markdown
Member

Merged over known test failures that are resolved by other PRs

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic

QuLogic commented Mar 27, 2026

Copy link
Copy Markdown
Member

Thanks @Cemonix! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again.

Cemonix reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic QuLogic mentioned this pull request Apr 1, 2026
ft2font: Add internal API for accessing font variations #31434
Open
5 tasks
@QuLogic QuLogic removed the status: needs review label Apr 10, 2026
@QuLogic QuLogic mentioned this pull request Apr 11, 2026
Light font variants cannot be accessed by common name #4822
Closed
@QuLogic QuLogic mentioned this pull request Jun 12, 2026
[ENH]: Explicit file paths for font rcParams #28147
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@QuLogic QuLogic QuLogic approved these changes
@ksunden ksunden ksunden approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

first-contribution

Projects

First Time Contributors
Status: Merged
Font and text overhaul
Status: Done

Milestone

v3.11.0

Development

Successfully merging this pull request may close these issues.

Light font variants cannot be accessed by common name

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@Cemonix @tacaswell @QuLogic @anntzer @ksunden @melissawm
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.