def test_set_custom_round_float_func(self): default = _ROUND_FLOAT_FUNC try: setRoundFloatFunction(round2) self.assertEqual(_roundNumber(0.55, 1), 0.6) self.assertEqual(_roundNumber(-1.555, 2), -1.55) finally: setRoundIntegerFunction(default)
def test_set_custom_round_integer_func(self): default = _ROUND_INTEGER_FUNC try: setRoundIntegerFunction(otRound) self.assertEqual(_roundNumber(0.5), 1) self.assertEqual(_roundNumber(-1.5), -1) finally: setRoundIntegerFunction(default)
def _round(self, **kwargs): """ Subclasses may override this method. """ from fontMath.mathFunctions import setRoundIntegerFunction setRoundIntegerFunction(normalizers.normalizeVisualRounding) mathInfo = self._toMathInfo(guidelines=False) mathInfo = mathInfo.round() self._fromMathInfo(mathInfo, guidelines=False)
def _interpolate(self, factor, minInfo, maxInfo, round=True, suppressError=True): """ Subclasses may override this method. """ from fontMath.mathFunctions import setRoundIntegerFunction setRoundIntegerFunction(normalizers.normalizeVisualRounding) minInfo = minInfo._toMathInfo() maxInfo = maxInfo._toMathInfo() result = interpolate(minInfo, maxInfo, factor) if result is None and not suppressError: raise FontPartsError( ("Info from font '%s' and font '%s' could not be " "interpolated.") % (minInfo.font.name, maxInfo.font.name)) if round: result = result.round() self._fromMathInfo(result)
def _interpolate(self, factor, minKerning, maxKerning, round=True, suppressError=True): """ This is the environment implementation of :meth:`BaseKerning.interpolate`. * **factor** will be an :ref:`type-int-float`, ``tuple`` or ``list``. * **minKerning** will be a :class:`BaseKerning` object. * **maxKerning** will be a :class:`BaseKerning` object. * **round** will be a ``bool`` indicating if the interpolated kerning should be rounded. * **suppressError** will be a ``bool`` indicating if incompatible data should be ignored. Subclasses may override this method. """ import fontMath from fontMath.mathFunctions import setRoundIntegerFunction setRoundIntegerFunction(normalizers.normalizeVisualRounding) kerningGroupCompatibility = self._testKerningGroupCompatibility( minKerning, maxKerning, suppressError=suppressError) if not kerningGroupCompatibility: self.clear() else: minKerning = fontMath.MathKerning(kerning=minKerning, groups=minKerning.font.groups) maxKerning = fontMath.MathKerning(kerning=maxKerning, groups=maxKerning.font.groups) result = interpolate(minKerning, maxKerning, factor) if round: result.round() self.clear() result.extractKerning(self.font)