Skip to content

Conversation

@QuLogic
Copy link
Member

@QuLogic QuLogic commented Jun 10, 2025

PR summary

This PR is intended to hold all font and text PRs from the project Font and text overhaul

In order to not overwhelm the main repo with the churn of test image replacements, this PR comes from my fork and should only ever have 1 commit more than the text-overhaul branch with the changes to test images.

PR checklist

QuLogic added 4 commits June 12, 2025 18:46
Glyph indices are specific to each font. It does not make sense to fall
back based on glyph index to another font.

This could only really be populated by calling `FT2Font.set_text`, but
even that was fragile. If a fallback font was used for a character with
the same glyph index as a previous character in the main font, then
these lookups could be overwritten to the fallback instead of the main
font, with a completely different character!

Fortunately, nothing actually uses or requires a fallback through glyph
indices.
Remove ttconv backwards-compatibility code
@QuLogic
Copy link
Member Author

QuLogic commented Jun 19, 2025

Also, if you would like to follow along with the figure changes, I've posted a branch that does the changes per merge commit: https://github.com/QuLogic/matplotlib/tree/text-overhaul-figures-per-commit

QuLogic added 8 commits July 7, 2025 19:06
This allows checking that there are no _new_ failures, without
committing the new figures to the repo until the branch is complete.
ci: Preload existing test images from text-overhaul-figures branch
Also, check some expected conditions at parse time instead of somewhere
during use of the data.
ci: Fix image preload with multiple conflicts
@QuLogic QuLogic force-pushed the text-overhaul-figures branch from 2b3f5c5 to b17bef1 Compare July 10, 2025 04:06
For ligatures or complex shapings, multiple characters may map to a
single glyph. In this case, we still want to output a single character
code for the string using the font subset, but the `ToUnicode` map
should give back all the characters.
Previously, this was supposed to "upgrade" type 3 to type 42 if the
number of glyphs overflowed. However, as `CharacterTracker` can suggest
a new subset for other reasons (i.e., multiple glyphs for the same
character or a glyph for multiple characters may go to a second subset),
we do need proper subset handling here as well.

Since that is now done, we can drop the "promotion" from type 3 to type
42, as we don't get too many glyphs in each embedded font.
QuLogic and others added 10 commits October 2, 2025 19:00
Prepare `CharacterTracker` for advanced font features
Font features allow font designers to provide alternate glyphs or
shaping within a single font. These features may be accessed via special
tags corresponding to internal tables of glyphs.

The mplcairo backend supports font features via an elaborate re-use of
the font file path [1]. This commit adds the API to make this officially
supported in the main user API.

[1] https://github.com/matplotlib/mplcairo/blob/v0.6.1/README.rst#font-formats-and-features
The only thing that expected this to work is Type 3 fonts in the PDF
backend, but only to avoid an error when loading a range of characters
(not all of which would be used.) This would introduce an odd behaviour
in that `load_char` could never fail even if the glyph never existed.
You would instead end up with the `null` glyph from the last font.
Previously, in a mathtext string like `r"$\sin x$"`, a thin space would
(correctly) be added between "sin" and "x", but that space would be
missing in expressions like `r"$\max f$"`.  The difference arose because
of the slightly different handling of subscripts and superscripts
after the `\sin` and `\max` operators: `\sin^n` puts the superscript as
a normal exponent, but `\max_x` puts the subscript centered below the
operator name ("overunder symbol).  The previous code for inserting the
thin space did not handle the "overunder" case; fix that.  The new
behavior is tested by the change in test_operator_space, as well as by
mathtext1_dejavusans_06.

The change in mathtext_foo_29 arises because the extra thin space now
inserted after `\limsup` slightly shifts the centering of the whole
string.  Ideally that thin space should be suppressed if there's no
token after the operator, but that's not something currently implemented
either for e.g. `\sin` (compare e.g. the right-alignments in
`text(.5, .9, r"$\sin$", ha="right"); text(.5, .8, r"$\mathrm{sin}$", ha="right"); axvline(.5)`
where the extra thin space after `\sin` is visible), so this patch just
makes things more consistent.
Rename _in_subscript_or_superscript to the more descriptive
_needs_space_after_subsuper; simplify its setting in operatorname();
avoid the need to introduce an extra explicitly-typed spaced_nucleus
variable.
QuLogic and others added 11 commits November 6, 2025 13:14
Remove forced fallback from FT2Font::load_char
This enables loading a non-initial font from collections (`.ttc` files).
Currently exposed for `FT2Font`, only.
This should allow listing the metadata from the whole collection, which
will also pick the right one if specified, though it will not load the
specific index yet.
For backwards-compatibility, the path+index is passed around in a
lightweight subclass of `str`.
Note, this only has an effect if set as the global font. Otherwise, just
the font name is recorded, and the TeX engine's normal lookup is
performed.
Add support for loading all fonts from collections
@QuLogic QuLogic force-pushed the text-overhaul-figures branch from 2c24cd0 to 1c03310 Compare December 18, 2025 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Waiting for other PR

Development

Successfully merging this pull request may close these issues.

4 participants