[gpos] Keep GPOS variation-index deltas fractional#403
Merged
Conversation
This was referenced Jul 3, 2026
behdad
force-pushed
the
gpos-fractional-var-delta
branch
3 times, most recently
from
July 3, 2026 18:45
9a8e7e5 to
2fa4583
Compare
GPOS Device/VariationIndex deltas -- both value-record adjustments and anchor coordinates -- were computed with ItemVariationStore::compute_delta, which rounds the delta to whole font units, and then scaled to output units. That double rounding discards up to half a font unit of the advance, placement, or attachment adjustment. HarfBuzz instead keeps the delta fractional and rounds only once, after scaling: Device::get_x_delta is em_scalef_x(get_delta()), i.e. roundf(delta * scale / upem), used for both value records and Anchor::get_anchor. For variable fonts this made the "harfrust" shaper disagree with "ot" by sub-font-unit amounts on non-default instances (#402, e.g. SFNSItalic at weights other than the default). Compute the deltas with compute_float_delta and scale them with new Scale::scale_x_f/scale_y_f helpers that mirror HarfBuzz's em_multf (roundf(v * scale / upem)), keeping f32 arithmetic to match it. resolve_anchor now returns fractional font units, and its cursive and mark callers round once when scaling. The static value-record path stays on the integer scale, matching HarfBuzz (static -> em_scale, device -> em_scalef). Bump the read-fonts dependency to 0.41.0, which makes the FloatItemDelta::to_f64 accessor public (googlefonts/fontations#1954); compute_float_delta's result is read through it. Advances now match the "ot" shaper exactly (0.000000px) for SFNSItalic across weights 100-900; the harfrust and HarfBuzz shape suites pass with no regressions. Fixes: #402 Assisted-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
behdad
force-pushed
the
gpos-fractional-var-delta
branch
from
July 3, 2026 18:55
2fa4583 to
e09971c
Compare
This was referenced Jul 3, 2026
Merged
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.
Fixes #402
Problem
GPOS Device/VariationIndex deltas — both value-record adjustments and anchor
coordinates — were read via
ItemVariationStore::compute_delta, which roundsthe delta to whole font units, and then scaled to output units. That double
rounding discards up to half a font unit of the advance / placement /
attachment adjustment.
HarfBuzz instead keeps the delta fractional and rounds only once, after scaling
to output units (
Device::get_x_deltaisem_scalef_x(get_delta()), i.e.roundf(delta * scale / upem), used for both value records andAnchor::get_anchor). For variable fonts this made theharfrustshaperdisagree with
otby sub-font-unit amounts on non-default instances — e.g.SFNSItalic.ttfshaping"System italic font at weight N"at weights otherthan the default (#402).
Fix
Read the deltas with
compute_float_deltaand scale them with newScale::scale_x_f/scale_y_fhelpers that mirror HarfBuzz'sem_multf(
roundf(v * scale / upem)), keepingf32arithmetic to match HarfBuzz. Thestatic value-record path stays on the integer scale, matching HarfBuzz
(static →
em_scale, device →em_scalef).resolve_anchornow returnsfractional font units, and its cursive and mark callers round once when
scaling.
Requires read-fonts 0.41.0
This bumps the
read-fontsdependency to 0.41.0 for the publicFloatItemDelta::to_f64accessor (googlefonts/fontations#1954). CI will buildonce read-fonts 0.41.0 is published on crates.io.
Testing
SFNSItalic.ttfadvances now match theotshaper exactly (0.000000px):hb-shape --shaper harfrustvs--shaper otis byte-identical acrossweights 100–900.
cargo test -p harfrust: 6027 passed, 0 failed.meson test --suite shape: 3/3 OK (8912 subtests), 0 failures.