Skip to content

[trak] Keep tracking fractional#404

Merged
behdad merged 1 commit into
mainfrom
trak-fractional-tracking
Jul 3, 2026
Merged

[trak] Keep tracking fractional#404
behdad merged 1 commit into
mainfrom
trak-fractional-tracking

Conversation

@behdad

@behdad behdad commented Jul 3, 2026

Copy link
Copy Markdown
Member

Follow-up to #403, applying the same fix to the AAT trak table.

Problem

The trak tracking value is interpolated by point size and is generally not a
whole font unit, but get_h_tracking / get_v_tracking rounded it to an
integer before scaling. HarfBuzz keeps it fractional and rounds only once,
after scaling to output units (get_h_tracking is
em_scalef_x(get_tracking())).

Fix

Return the fractional tracking and scale it with the Scale::scale_x_f /
scale_y_f helpers (added in #403).

Testing

Comparing the ot and harfrust shapers on SFNSItalic.ttf ("System italic", size 20, weight 500) across point sizes 14–26 in 0.5 steps:

  • Before: at sizes where the tracking interpolates to a fractional value
    (20.5, 21.5, 22.5, 23.5, 24.5, 25.0, 25.5) every glyph's advance differed
    from ot by up to ±0.5 font units (±0.0049px); integer-tracking sizes
    already matched.
  • After: exact 0.000000px match at every size.

cargo test -p harfrust: 6027 passed, 0 failed.

The trak tracking value is interpolated per point size and is
generally not a whole font unit, but get_h_tracking/get_v_tracking
rounded it to an integer before scaling.  HarfBuzz keeps it
fractional and rounds once, after scaling to output units
(get_h_tracking is em_scalef_x(get_tracking())).

Return the fractional tracking and scale it with the Scale::scale_x_f
/scale_y_f helpers.  For SFNSItalic this removes an up-to-half-font-unit
per-glyph advance difference from the "ot" shaper at point sizes where
the tracking interpolates to a fractional value (e.g. 20.5, 24.5);
integer-tracking sizes were already exact.

Assisted-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@behdad behdad requested a review from drott July 3, 2026 19:03
@behdad behdad merged commit 2b953e7 into main Jul 3, 2026
3 checks passed
@behdad behdad deleted the trak-fractional-tracking branch July 3, 2026 19:07
@behdad behdad mentioned this pull request Jul 3, 2026
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.

1 participant