Skip to content

Fix bug in COLRv1 glyph splitting, layers start_idx=0, and ot-rounding#1768

Merged
anthrotype merged 4 commits into
mainfrom
colr-fixes
Nov 20, 2025
Merged

Fix bug in COLRv1 glyph splitting, layers start_idx=0, and ot-rounding#1768
anthrotype merged 4 commits into
mainfrom
colr-fixes

Conversation

@anthrotype

Copy link
Copy Markdown
Member

Fixes #1766 and #1767

plus, use OtRound to round gradient's geometry as fontTools does

we now match ttx-diff resources/testdata/glyphs3/COLRv1-manyshapes-per-glyph.glyphs with "output is indentical"

`Colrv1RunType` only stored gradient colors when determining if consecutive
shapes should be grouped into the same run. Two shapes with identical colors
but different gradient geometry (e.g., different angles for linear gradients)
were incorrectly treated as the same run and merged into a single `.colorN`
glyph.

Fixes #1766
When building `PaintColrLayers`, the code computed `start_idx` from
`layer_list.num_layers`, which was always 0 during processing. The field was
only set once at the very end of all processing. This caused all glyphs to
incorrectly reference layers starting at index 0, making them share/overwrite
each other's layers.

Fixes #1767
This fixes two issues with gradient coordinate rounding:

1. Compound rounding error: When calculating perpendicular points for linear
gradients (when p2 is not explicitly provided), the code rounded p0 and p1 to
i16 first, then calculated the perpendicular from the rounded values. This caused compound rounding errors.

2. Wrong rounding mode: Used Rust's `.round()` (round half away from zero) instead of fontTools' `otRound` (round half up per OpenType spec).

@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!

@anthrotype anthrotype added this pull request to the merge queue Nov 20, 2025
Merged via the queue into main with commit 5f267e1 Nov 20, 2025
12 checks passed
@anthrotype anthrotype deleted the colr-fixes branch November 20, 2025 14: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.

gradient start/stop ignored when splitting COLRv1 glyphs

2 participants