Add test to expose missed otRound + fix
This commit is contained in:
parent
0353c809cd
commit
5316ae4b8c
@ -19,7 +19,10 @@ from fontTools.ttLib.tables.otConverters import (
|
|||||||
UShort,
|
UShort,
|
||||||
VarInt16,
|
VarInt16,
|
||||||
VarUInt16,
|
VarUInt16,
|
||||||
|
IntValue,
|
||||||
|
FloatValue,
|
||||||
)
|
)
|
||||||
|
from fontTools.misc.fixedTools import otRound
|
||||||
|
|
||||||
|
|
||||||
class BuildCallback(enum.Enum):
|
class BuildCallback(enum.Enum):
|
||||||
@ -96,7 +99,6 @@ class TableBuilder:
|
|||||||
def _convert(self, dest, field, converter, value):
|
def _convert(self, dest, field, converter, value):
|
||||||
tupleClass = getattr(converter, "tupleClass", None)
|
tupleClass = getattr(converter, "tupleClass", None)
|
||||||
enumClass = getattr(converter, "enumClass", None)
|
enumClass = getattr(converter, "enumClass", None)
|
||||||
simpleValueClass = getattr(converter, "valueClass", None)
|
|
||||||
|
|
||||||
if tupleClass:
|
if tupleClass:
|
||||||
value = convertTupleClass(tupleClass, value)
|
value = convertTupleClass(tupleClass, value)
|
||||||
@ -112,8 +114,10 @@ class TableBuilder:
|
|||||||
else:
|
else:
|
||||||
value = enumClass(value)
|
value = enumClass(value)
|
||||||
|
|
||||||
elif simpleValueClass:
|
elif isinstance(converter, IntValue):
|
||||||
value = simpleValueClass(value)
|
value = otRound(value)
|
||||||
|
elif isinstance(converter, FloatValue):
|
||||||
|
value = float(value)
|
||||||
|
|
||||||
elif isinstance(converter, Struct):
|
elif isinstance(converter, Struct):
|
||||||
if converter.repeat:
|
if converter.repeat:
|
||||||
|
@ -216,8 +216,6 @@ class SimpleValue(BaseConverter):
|
|||||||
return self.fromString(attrs["value"])
|
return self.fromString(attrs["value"])
|
||||||
|
|
||||||
class IntValue(SimpleValue):
|
class IntValue(SimpleValue):
|
||||||
valueClass = int
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fromString(value):
|
def fromString(value):
|
||||||
return int(value, 0)
|
return int(value, 0)
|
||||||
@ -297,7 +295,6 @@ class Tag(SimpleValue):
|
|||||||
writer.writeTag(value)
|
writer.writeTag(value)
|
||||||
|
|
||||||
class GlyphID(SimpleValue):
|
class GlyphID(SimpleValue):
|
||||||
valueClass = str
|
|
||||||
staticSize = 2
|
staticSize = 2
|
||||||
typecode = "H"
|
typecode = "H"
|
||||||
def readArray(self, reader, font, tableDict, count):
|
def readArray(self, reader, font, tableDict, count):
|
||||||
@ -337,7 +334,6 @@ class NameID(UShort):
|
|||||||
|
|
||||||
|
|
||||||
class FloatValue(SimpleValue):
|
class FloatValue(SimpleValue):
|
||||||
valueClass = float
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fromString(value):
|
def fromString(value):
|
||||||
return float(value)
|
return float(value)
|
||||||
|
15
Tests/colorLib/table_builder_test.py
Normal file
15
Tests/colorLib/table_builder_test.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
from fontTools.ttLib.tables import otTables # trigger setup to occur
|
||||||
|
from fontTools.ttLib.tables.otConverters import UShort
|
||||||
|
from fontTools.colorLib.table_builder import TableBuilder
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
class WriteMe:
|
||||||
|
value = None
|
||||||
|
|
||||||
|
|
||||||
|
def test_intValue_otRound():
|
||||||
|
dest = WriteMe()
|
||||||
|
converter = UShort("value", None, None)
|
||||||
|
TableBuilder()._convert(dest, "value", converter, 85.6)
|
||||||
|
assert dest.value == 86, "Should have used otRound"
|
Loading…
x
Reference in New Issue
Block a user