From 4ea10eb88fe3b5e7f621d0c7238912640461a531 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Fri, 24 Jan 2025 15:10:18 +0000 Subject: [PATCH] [glyf] fix rounding of bbox for nested transformed components when getCoordinates is asked to round, e.g. from recalcBounds, only round the simple glyphs' coordinates; don't do any rounding for the coordinates of component glyphs otherwise rounding errors would accummulate if a composite glyph contains transformed/nested components --- Lib/fontTools/ttLib/tables/_g_l_y_f.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py index 50f771ab6..095bd3177 100644 --- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py +++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py @@ -1258,7 +1258,11 @@ class Glyph(object): """ if self.numberOfContours > 0: - return self.coordinates, self.endPtsOfContours, self.flags + coordinates = self.coordinates + if round is not noRound: + coordinates = GlyphCoordinates(coordinates) + coordinates.toInt(round=round) + return coordinates, self.endPtsOfContours, self.flags elif self.isComposite(): # it's a composite allCoords = GlyphCoordinates() @@ -1276,7 +1280,6 @@ class Glyph(object): % compo.glyphName ) coordinates = GlyphCoordinates(coordinates) - coordinates.toInt(round=round) if hasattr(compo, "firstPt"): # component uses two reference points: we apply the transform _before_ # computing the offset between the points