Skip to content

[read-fonts] Add exact variation deltas to HVAR, VVAR and MVAR - #2110

Merged
dfrg merged 1 commit into
mainfrom
read/exact-variation-deltas
Sep 8, 2026
Merged

[read-fonts] Add exact variation deltas to HVAR, VVAR and MVAR#2110
dfrg merged 1 commit into
mainfrom
read/exact-variation-deltas

Conversation

@dfrg

@dfrg dfrg commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Expose 48.16 delta methods for the metrics variation tables. MVAR gets a helper that resolves the IVS once for batch queries.

@cmyr cmyr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good!

Comment thread read-fonts/src/tables/vvar.rs Outdated
/// implementations differ on that.
///
/// Returns `None` where the table says nothing readable about the glyph.
pub fn v_org(&self, glyph_id: GlyphId, coords: &[F2Dot14]) -> Option<F48Dot16> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do generally wonder if these names aren't a bit too concise, but I understand how tsb and bsb would follow from lsb/rsb, which are names already in use, and if we're using those than I can see how you end up here? I'd probably still prefer vert_origin/v_origin though, personally..

@dfrg dfrg Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed that this became worse when the _delta was dropped. Also, I realized that these aren't in our compatibility set so I'm just going to reuse the old names but extend v_org_delta to v_origin_y_delta which is what this actually is.

Should note that when I get to the later glyph metrics work on the new font API, lsb will be spelled h_bearing_x. Perhaps we can make similar changes to these later.

@dfrg
dfrg force-pushed the read/exact-variation-deltas branch from b06b13a to 81bfe72 Compare September 8, 2026 15:35
These accessors rounded each delta to a whole design unit before returning
it. That is what most callers want and what the classic implementations do,
but a caller that rounds differently, or that accumulates several deltas
before rounding, could not recover what was discarded.

They now report what the item variation store computed:

    Hvar::advance_delta, lsb_delta, rsb_delta
    Vvar::advance_delta, tsb_delta, bsb_delta, v_origin_y_delta

all returning Option<F48Dot16>. The error they used to report told a caller
nothing it could act on, and none of them looked.

The names lose what the table already says. HVAR has only widths and VVAR
only heights, so advance_width_delta and advance_height_delta are both just
advance_delta. And v_org_delta spells out what it answers for: the y
coordinate of the vertical origin, the x being half the advance width and
stated by no table at all.

Mvar::at is added alongside, returning an MvarInstance that resolves the
variation store once and answers by tag, rather than resolving it on every
Mvar::metric_delta call.

Callers that rounded the old whole-unit value now round the exact one, so
what they compute is unchanged.
@dfrg
dfrg force-pushed the read/exact-variation-deltas branch from 81bfe72 to 0b1b5a7 Compare September 8, 2026 15:40
@dfrg
dfrg merged commit 6375df9 into main Sep 8, 2026
23 checks passed
@dfrg
dfrg deleted the read/exact-variation-deltas branch September 8, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants