diff options
Diffstat (limited to 'Lib/fontTools/pens/ttGlyphPen.py')
-rw-r--r-- | Lib/fontTools/pens/ttGlyphPen.py | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/Lib/fontTools/pens/ttGlyphPen.py b/Lib/fontTools/pens/ttGlyphPen.py index 0b64cb38..866298be 100644 --- a/Lib/fontTools/pens/ttGlyphPen.py +++ b/Lib/fontTools/pens/ttGlyphPen.py @@ -15,22 +15,34 @@ __all__ = ["TTGlyphPen"] class TTGlyphPen(LoggingPen): """Pen used for drawing to a TrueType glyph. - If `handleOverflowingTransforms` is True, the components' transform values - are checked that they don't overflow the limits of a F2Dot14 number: - -2.0 <= v < +2.0. If any transform value exceeds these, the composite - glyph is decomposed. - An exception to this rule is done for values that are very close to +2.0 - (both for consistency with the -2.0 case, and for the relative frequency - these occur in real fonts). When almost +2.0 values occur (and all other - values are within the range -2.0 <= x <= +2.0), they are clamped to the - maximum positive value that can still be encoded as an F2Dot14: i.e. - 1.99993896484375. - If False, no check is done and all components are translated unmodified - into the glyf table, followed by an inevitable `struct.error` once an - attempt is made to compile them. + This pen can be used to construct or modify glyphs in a TrueType format + font. After using the pen to draw, use the ``.glyph()`` method to retrieve + a :py:class:`~._g_l_y_f.Glyph` object representing the glyph. """ def __init__(self, glyphSet, handleOverflowingTransforms=True): + """Construct a new pen. + + Args: + glyphSet (ttLib._TTGlyphSet): A glyphset object, used to resolve components. + handleOverflowingTransforms (bool): See below. + + If ``handleOverflowingTransforms`` is True, the components' transform values + are checked that they don't overflow the limits of a F2Dot14 number: + -2.0 <= v < +2.0. If any transform value exceeds these, the composite + glyph is decomposed. + + An exception to this rule is done for values that are very close to +2.0 + (both for consistency with the -2.0 case, and for the relative frequency + these occur in real fonts). When almost +2.0 values occur (and all other + values are within the range -2.0 <= x <= +2.0), they are clamped to the + maximum positive value that can still be encoded as an F2Dot14: i.e. + 1.99993896484375. + + If False, no check is done and all components are translated unmodified + into the glyf table, followed by an inevitable ``struct.error`` once an + attempt is made to compile them. + """ self.glyphSet = glyphSet self.handleOverflowingTransforms = handleOverflowingTransforms self.init() @@ -136,6 +148,7 @@ class TTGlyphPen(LoggingPen): return components def glyph(self, componentFlags=0x4): + """Returns a :py:class:`~._g_l_y_f.Glyph` object representing the glyph.""" assert self._isClosed(), "Didn't close last contour." components = self._buildComponents(componentFlags) |