mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 06:21:16 +01:00
The fragment shader picks one horizontal and one vertical band from the fragment position and walks only that band's curve list, so a curve must be listed in every band its bounding box reaches into. The encoder computed those bounding boxes from the unquantized control points, but the shader only ever sees the coordinates after they are rounded to quarter font units. When rounding pushed a curve's extreme across a band boundary, the curve was left out of the band it now reached into. Fragments landing in that sliver never saw the curve, so their winding number was off by one and the pixel came out empty in the middle of a filled area -- a thin black line through the glyph, appearing and disappearing as the font size moves the pixel grid. The rounding error is at most an eighth of a font unit, so this is invisible for an integer-coordinate glyph rendered at its own upem. It gets easy to hit when the coordinates are fractional: CFF glyphs after cu2qu, or any font whose hb_font_t scale is not its upem. With hb_font_set_scale(font, 163, 163), as in issue #6131, more than half of the glyphs of util/gpu/default-font.ttf had at least one band the shader could reach but that did not list the curve. Compute the bounds (and the is_horizontal/is_vertical tests) from the quantized control points instead, and widen the band range by 1/1024 of a band so that the double arithmetic here cannot disagree with the shader's float32 band index right at a boundary. Verified with a CPU port of _hb_gpu_slug_single: comparing the banded lookup against a walk over every curve of the glyph, at sizes 39, 47 and 107 with scale 163, default-font.ttf had 27 wrong pixels before and none after. Encoded atlas size grows by 0.12%. Adds test_encode_band_membership, which checks the invariant directly on the encoded blob and fails before this change. Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>