[read-fonts] Add MATH table and supporting functions. - #2105
Merged
Conversation
MATH describes mathematical typesetting: the constants that position scripts, fractions and radicals, per-glyph italics correction, top accent attachment and kerning, and the variants and assemblies that stretch a delimiter to fit. Chromium reads all four of those groups through HarfBuzz, so the surface is not hypothetical. Two parts of the table needed more than the usual attributes. MathValueRecord carries a device offset measured from the table that contains the record rather than from the record itself, which the generated accessor already handles by taking the parent's offset data. MathKern holds one more kern value than it has correction heights, since the first applies below the lowest height and the last above the highest; `add($height_count, 1)` gives that array its count. The constants are 51 MathValueRecords in a fixed order, where a transposition would be silent -- every field has the same type. The test gives each record a value that encodes its index, so reading them back through the named accessors checks the whole run.
Member
|
does this put to rest (to my great shame) #1269 ? |
Contributor
Author
cmyr
approved these changes
Sep 8, 2026
cmyr
left a comment
Member
There was a problem hiding this comment.
nice and easy now that we've got records-in-tables...
|
|
||
| /// Which corner of a glyph a [`MathKern`] applies to. | ||
| #[derive(Clone, Copy, PartialEq, Eq, Debug)] | ||
| pub enum MathKernSide { |
Member
There was a problem hiding this comment.
'side' seems like a funny word here, is it our choice or are we matching prior art?
Contributor
Author
There was a problem hiding this comment.
fair! renaming to MathKernCorner
| } | ||
|
|
||
| impl Math<'_> { | ||
| /// Whether this is one of the Cambria Math builds that stores |
Most measurements in MATH are a MathValueRecord: a design unit value and an optional offset to a Device or VariationIndex table. Reading one means finding the record, resolving its offset against the table it was read from, and applying the adjustment. MathValue carries the result, and keeps its two halves apart because they are in different units. A device table adjusts by whole pixels, so scaling that into design units needs the units per em, which this table does not know; returning a single number would have to guess at one. A VariationIndex contributes nothing at all: the deltas it names live in an item variation store, and MATH has none. MathConstant numbers the constants the way HarfBuzz does. One macro list defines the enum, its numbering, and the arms that read each field, so a constant cannot be numbered as one field and read from another, and the matches have no catch-all. MathKern hands over its bands rather than searching them. Which band a height falls in depends on whether the comparison happens in design units, in pixels, or in a scaled position -- the last of which also decides which way up the vertical axis is -- and only the caller knows that. has_swapped_min_heights reports the Cambria Math builds that store two constants the wrong way round. It reports the font and leaves the substitution to the caller, so the constants keep saying what the font says.
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.
Broken into two commits for reviewer convenience. The first is just the codegen boilerplate. The second contains all the helper accessor methods. These were specifically designed to map nicely to the
hb_ot_math_*functions because we'll need to implement those to replace HarfBuzz in Chrome. They should generalize to all consumers of this table though and the raw fields/methods are still there.Plan for implementing on the HarfRust side: harfbuzz/harfrust#466