allow to pass 'round' parameter in ttGlyphPen, optimize for noRound

This commit is contained in:
Cosimo Lupo 2023-06-08 11:41:07 +01:00
parent 86777525a6
commit 5c0f05cc42
No known key found for this signature in database
GPG Key ID: DF65A8A5A119C9A8
2 changed files with 7 additions and 5 deletions

View File

@ -1,5 +1,5 @@
from array import array
from typing import Any, Dict, Optional, Tuple
from typing import Any, Callable, Dict, Optional, Tuple
from fontTools.misc.fixedTools import MAX_F2DOT14, floatToFixedToFloat
from fontTools.misc.loggingTools import LogMixin
from fontTools.pens.pointPen import AbstractPointPen
@ -131,7 +131,8 @@ class _TTGlyphBasePen:
self,
componentFlags: int = 0x04,
dropImpliedOnCurves: bool = False,
roundCoordinates: bool = True,
*,
round: Callable[[float], int] = otRound,
) -> Glyph:
"""
Returns a :py:class:`~._g_l_y_f.Glyph` object representing the glyph.
@ -162,8 +163,7 @@ class _TTGlyphBasePen:
glyph.program.fromBytecode(b"")
if dropImpliedOnCurves:
dropImpliedOnCurvePoints(glyph)
if roundCoordinates:
glyph.coordinates.toInt()
glyph.coordinates.toInt(round=round)
return glyph

View File

@ -13,8 +13,8 @@ from fontTools.misc.fixedTools import (
floatToFixed as fl2fi,
floatToFixedToStr as fl2str,
strToFixedToFloat as str2fl,
otRound,
)
from fontTools.misc.roundTools import noRound, otRound
from fontTools.misc.vector import Vector
from numbers import Number
from . import DefaultTable
@ -2322,6 +2322,8 @@ class GlyphCoordinates(object):
self._a.extend(p)
def toInt(self, *, round=otRound):
if round is noRound:
return
a = self._a
for i in range(len(a)):
a[i] = round(a[i])