Skip to content

[glyf] Round component offsets when calculating bounds - #4374

Merged
behdad merged 1 commit into
fonttools:mainfrom
snowyukitty:fix/nested-composite-instance-bounds
Nov 1, 2026
Merged

behdad merged 1 commit into
fonttools:mainfrom
snowyukitty:fix/nested-composite-instance-bounds

Conversation

@snowyukitty

Copy link
Copy Markdown
Contributor

Refs #3795.

Instancing can leave fractional XY component offsets in memory. GlyphComponent.compile() rounds those offsets when encoding them, but getCoordinates(round=otRound) used the fractional offsets when calculating bounds. A saved nested composite could therefore contain bounds for a different outline than the one it encodes.

Apply the requested rounding function to XY offsets before their transforms. The default noRound path is unchanged. Intermediate transformed coordinates are not additionally rounded. The method documents the rounding behavior.

The regressions cover positive/negative offsets and half ties, default/scaled/unscaled offset conventions, direct and nested components, and unchanged unrounded coordinates. The instancer test creates a nested component in an existing variable-font fixture, generates full and partial instances, saves and reloads them, and checks the stored bounds against arithmetic on the decoded points and offsets.

Validation from the repository root on Linux with Python 3.12:

  • python -m tox -e py,lint,package_readme: passed on the production and test changes; pytest reported 7216 passed, 15 skipped, 2 xfailed, 31 warnings in 81.66s (0:01:21). Black, mypy and wheel/readme validation passed.
  • After finalizing the README contributor entry, python -m tox -e package_readme passed again.
  • The same tox environments passed on the untouched upstream base.
  • With only the original production module restored, the new tests produce 45 expected failures and 14 passing controls.

The original reporter's font is unavailable, so this addresses the reproduced fractional-offset case without claiming to resolve every cause of the linked report. Other Python versions, Windows/macOS and Cython builds were not run locally.

@behdad
behdad merged commit d5318ce into fonttools:main Nov 1, 2026
11 checks passed
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