diff options
Diffstat (limited to 'Lib/fontTools/pens/t2CharStringPen.py')
-rw-r--r-- | Lib/fontTools/pens/t2CharStringPen.py | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/Lib/fontTools/pens/t2CharStringPen.py b/Lib/fontTools/pens/t2CharStringPen.py index 89340d1e..0fddec1a 100644 --- a/Lib/fontTools/pens/t2CharStringPen.py +++ b/Lib/fontTools/pens/t2CharStringPen.py @@ -1,37 +1,12 @@ # Copyright (c) 2009 Type Supply LLC # Author: Tal Leming -from fontTools.misc.py23 import * -from fontTools.misc.fixedTools import otRound +from fontTools.misc.roundTools import otRound, roundFunc from fontTools.misc.psCharStrings import T2CharString from fontTools.pens.basePen import BasePen from fontTools.cffLib.specializer import specializeCommands, commandsToProgram -def t2c_round(number, tolerance=0.5): - if tolerance == 0: - return number # no-op - rounded = otRound(number) - # return rounded integer if the tolerance >= 0.5, or if the absolute - # difference between the original float and the rounded integer is - # within the tolerance - if tolerance >= .5 or abs(rounded - number) <= tolerance: - return rounded - else: - # else return the value un-rounded - return number - -def makeRoundFunc(tolerance): - if tolerance < 0: - raise ValueError("Rounding tolerance must be positive") - - def roundPoint(point): - x, y = point - return t2c_round(x, tolerance), t2c_round(y, tolerance) - - return roundPoint - - class T2CharStringPen(BasePen): """Pen to draw Type 2 CharStrings. @@ -45,7 +20,7 @@ class T2CharStringPen(BasePen): def __init__(self, width, glyphSet, roundTolerance=0.5, CFF2=False): super(T2CharStringPen, self).__init__(glyphSet) - self.roundPoint = makeRoundFunc(roundTolerance) + self.round = roundFunc(roundTolerance) self._CFF2 = CFF2 self._width = width self._commands = [] @@ -53,7 +28,7 @@ class T2CharStringPen(BasePen): def _p(self, pt): p0 = self._p0 - pt = self._p0 = self.roundPoint(pt) + pt = self._p0 = (self.round(pt[0]), self.round(pt[1])) return [pt[0]-p0[0], pt[1]-p0[1]] def _moveTo(self, pt): |