diff --git a/Lib/fontTools/pens/ttGlyphPen.py b/Lib/fontTools/pens/ttGlyphPen.py index f828502ee..11b9584b2 100644 --- a/Lib/fontTools/pens/ttGlyphPen.py +++ b/Lib/fontTools/pens/ttGlyphPen.py @@ -170,9 +170,14 @@ class _TTGlyphBasePen: components.append(component) return components - def glyph(self, componentFlags: int = 0x4, preserveTopology=True) -> Glyph: + def glyph(self, componentFlags: int = 0x04, dropImpliedOnCurves=False) -> Glyph: """ Returns a :py:class:`~._g_l_y_f.Glyph` object representing the glyph. + + Args: + componentFlags: Flags to use for component glyphs. (default: 0x04) + + dropImpliedOnCurves: Whether to remove implied-oncurve points. (default: False) """ if not self._isClosed(): raise PenError("Didn't close last contour.") @@ -184,7 +189,7 @@ class _TTGlyphBasePen: glyph.flags = array("B", self.types) glyph.coordinates.toInt() - if not preserveTopology: + if dropImpliedOnCurves: drop_implied_oncurves(glyph) self.init() diff --git a/Tests/pens/ttGlyphPen_test.py b/Tests/pens/ttGlyphPen_test.py index 382602f02..0d7167073 100644 --- a/Tests/pens/ttGlyphPen_test.py +++ b/Tests/pens/ttGlyphPen_test.py @@ -639,10 +639,10 @@ class CubicGlyfTest: ] @pytest.mark.parametrize( - "preserveTopology, segment_pen_commands, point_pen_commands, expected_coordinates, expected_flags, expected_endPts", + "dropImpliedOnCurves, segment_pen_commands, point_pen_commands, expected_coordinates, expected_flags, expected_endPts", [ ( # Two curves that do NOT merge; request merging - False, + True, [ ("moveTo", ((0, 0),)), ("curveTo", ((0, 1), (1, 2), (2, 2))), @@ -665,7 +665,7 @@ class CubicGlyfTest: [6], ), ( # Two curves that merge; request merging - False, + True, [ ("moveTo", ((0, 0),)), ("curveTo", ((0, 1), (1, 2), (2, 2))), @@ -688,7 +688,7 @@ class CubicGlyfTest: [5], ), ( # Two curves that merge; request NOT merging - True, + False, [ ("moveTo", ((0, 0),)), ("curveTo", ((0, 1), (1, 2), (2, 2))), @@ -711,7 +711,7 @@ class CubicGlyfTest: [6], ), ( # Two (duplicate) contours - False, + True, [ ("moveTo", ((0, 0),)), ("curveTo", ((0, 1), (1, 2), (2, 2))), @@ -776,7 +776,7 @@ class CubicGlyfTest: ) def test_cubic_topology( self, - preserveTopology, + dropImpliedOnCurves, segment_pen_commands, point_pen_commands, expected_coordinates, @@ -795,7 +795,7 @@ class CubicGlyfTest: for pen in (spen, ppen): - glyph = pen.glyph(preserveTopology=preserveTopology) + glyph = pen.glyph(dropImpliedOnCurves=dropImpliedOnCurves) assert list(glyph.coordinates) == expected_coordinates assert list(glyph.flags) == expected_flags