remove wrapping around from Angle converter, let the struct.error propagate

This commit is contained in:
Cosimo Lupo 2021-07-19 17:52:00 +01:00
parent 7225ac22a6
commit 60f0724144

View File

@ -17,7 +17,6 @@ from .otTables import (lookupTypes, AATStateTable, AATState, AATAction,
InsertionMorphAction, MorxSubtable, VariableFloat, InsertionMorphAction, MorxSubtable, VariableFloat,
VariableInt, ExtendMode as _ExtendMode, VariableInt, ExtendMode as _ExtendMode,
CompositeMode as _CompositeMode) CompositeMode as _CompositeMode)
import math
from itertools import zip_longest from itertools import zip_longest
from functools import partial from functools import partial
import struct import struct
@ -429,16 +428,12 @@ class F2Dot14(FloatValue):
return fl2str(value, 14) return fl2str(value, 14)
class Angle(F2Dot14): class Angle(F2Dot14):
# angles are specified in degrees, and encoded as F2Dot14 fractions of half
# circle: e.g. 1.0 => 180, -0.5 => -90, -2.0 => -360, etc.
factor = 1.0/(1<<14) * 180 # 0.010986328125 factor = 1.0/(1<<14) * 180 # 0.010986328125
@staticmethod
def wrapAround(angle):
# Upon compile/dump, normalize angles that span beyond a full circle.
# We want to keep the orientation after modulo: e.g. -415 => -55, not 305
return angle % math.copysign(360, angle)
def read(self, reader, font, tableDict): def read(self, reader, font, tableDict):
return super().read(reader, font, tableDict) * 180 return super().read(reader, font, tableDict) * 180
def write(self, writer, font, tableDict, value, repeatIndex=None): def write(self, writer, font, tableDict, value, repeatIndex=None):
value = self.wrapAround(value)
super().write(writer, font, tableDict, value / 180, repeatIndex=repeatIndex) super().write(writer, font, tableDict, value / 180, repeatIndex=repeatIndex)
@classmethod @classmethod
def fromString(cls, value): def fromString(cls, value):
@ -446,7 +441,6 @@ class Angle(F2Dot14):
return otRound(float(value) / cls.factor) * cls.factor return otRound(float(value) / cls.factor) * cls.factor
@classmethod @classmethod
def toString(cls, value): def toString(cls, value):
value = cls.wrapAround(value)
return nearestMultipleShortestRepr(value, cls.factor) return nearestMultipleShortestRepr(value, cls.factor)
class Version(SimpleValue): class Version(SimpleValue):