From 7fe59e4b94c68401a24123845e32bf704ed4dbca Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 26 Nov 2019 16:03:18 +0000 Subject: [PATCH] ttGlyphPen_test: test computing bounds with float coordinates and offsets https://github.com/googlefonts/fontmake/issues/593 This test currently fails. The compositeGlyph.xMax is set to 281, but it should be 282. --- Tests/pens/ttGlyphPen_test.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Tests/pens/ttGlyphPen_test.py b/Tests/pens/ttGlyphPen_test.py index ec9458903..961738d47 100644 --- a/Tests/pens/ttGlyphPen_test.py +++ b/Tests/pens/ttGlyphPen_test.py @@ -239,6 +239,31 @@ class TTGlyphPenTest(TestCase): with self.assertRaises(struct.error): compositeGlyph.compile({'a': baseGlyph}) + def assertGlyphBoundsEqual(self, glyph, bounds): + self.assertEqual((glyph.xMin, glyph.yMin, glyph.xMax, glyph.yMax), bounds) + + def test_round_float_coordinates_and_component_offsets(self): + glyphSet = {} + pen = TTGlyphPen(glyphSet) + + pen.moveTo((0, 0)) + pen.lineTo((0, 1)) + pen.lineTo((367.6, 0)) + pen.closePath() + simpleGlyph = pen.glyph() + + simpleGlyph.recalcBounds(glyphSet) + self.assertGlyphBoundsEqual(simpleGlyph, (0, 0, 368, 1)) + + componentName = 'a' + glyphSet[componentName] = simpleGlyph + + pen.addComponent(componentName, (1, 0, 0, 1, -86.4, 0)) + compositeGlyph = pen.glyph() + + compositeGlyph.recalcBounds(glyphSet) + self.assertGlyphBoundsEqual(compositeGlyph, (-86, 0, 282, 1)) + class _TestGlyph(object): def __init__(self, glyph):