[read-fonts] experimental Font API: add GlobalMetrics - #2111
Merged
Conversation
dfrg
force-pushed
the
read/global-metrics
branch
2 times, most recently
from
September 7, 2026 17:04
1e8fdd9 to
a6e2ec3
Compare
cmyr
approved these changes
Sep 8, 2026
cmyr
left a comment
Member
There was a problem hiding this comment.
looks good, a few ignorable questions inline
|
|
||
| #[derive(Clone)] | ||
| enum Repr { | ||
| Default(Font), |
Member
There was a problem hiding this comment.
Is this only used for variable fonts, or also statics?
Contributor
Author
There was a problem hiding this comment.
Exactly the right question, and the motivation for this change. This allows future code to accept only FontInstance while providing a free (sans atomic counter bump) conversion from Font for both statics and variable fonts at default location.
Comment on lines
+100
to
+105
| impl From<&Font> for FontInstance { | ||
| /// A font is an instance of itself, at the default location. | ||
| fn from(font: &Font) -> Self { | ||
| Self(Repr::Default(font.clone())) | ||
| } | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Good catch. Both conversions make sense here.
Comment on lines
+15
to
+17
| fn widen(value: Fixed) -> F48Dot16 { | ||
| F48Dot16::from_bits(value.to_bits() as i64) | ||
| } |
Member
There was a problem hiding this comment.
should this be a method on Fixed? (maybe not, if it's only internal)
Contributor
Author
There was a problem hiding this comment.
and it already is! Fixed (pun intended?)
dfrg
force-pushed
the
read/exact-variation-deltas
branch
from
September 8, 2026 15:35
b06b13a to
81bfe72
Compare
dfrg
force-pushed
the
read/global-metrics
branch
from
September 8, 2026 15:36
a6e2ec3 to
caa745c
Compare
dfrg
force-pushed
the
read/exact-variation-deltas
branch
from
September 8, 2026 15:40
81bfe72 to
0b1b5a7
Compare
dfrg
force-pushed
the
read/global-metrics
branch
from
September 8, 2026 15:40
caa745c to
11920c5
Compare
…tion GlobalMetrics reads head, maxp, hhea, vhea and OS/2, and applies MVAR at a location. A font states its line metrics three times and the three disagree, so all three are reported and choosing between them is left to the caller. Measurements are exact, since a location can move one off a whole design unit and rounding here would decide for every caller how that fraction is spent. FontInstance drops its size. Size belongs to whatever rasterizes, not to a point in the design space, and nothing read it. What remains is a font and a location, so an instance at the default location is now held as nothing more than its font and building one allocates nothing. Anywhere else it owns what the location implies, behind an Arc so that clones share a single resolution rather than repeating it. An instance at the default location now selects no feature variations. A variable font is meant to keep working for a client that knows nothing of variations, and such a client reaches the default instance without ever consulting that table; selecting there would render the font one way for it and another for everyone else. This changes what a font stating a universal condition set reports at the default location, which previously matched because conditions were evaluated against implicit zeros. Font gains num_glyphs, units_per_em and default_instance.
dfrg
force-pushed
the
read/global-metrics
branch
from
September 8, 2026 15:48
11920c5 to
cd97907
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds font-wide metrics to
FontandFontInstance. The list of metrics is slightly different here than inskrifa::metrics::Metricsbecause this slices the set to the values that don't require theposttable (those will follow later inStyleMetrics). The reasoning is that none of those are required for shaping so we don't want to pull largepost2.0 tables unnecessarily.Also removes any notion of size from
FontInstance(that will come later as someScalertype), soFontInstancebecomes internallyArc'd and we can now create an instance at the default location for free.Requires #2110