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,
|
||||
VarInt16,
|
||||
VarUInt16,
|
||||
IntValue,
|
||||
FloatValue,
|
||||
)
|
||||
from fontTools.misc.fixedTools import otRound
|
||||
|
||||
|
||||
class BuildCallback(enum.Enum):
|
||||
@ -96,7 +99,6 @@ class TableBuilder:
|
||||
def _convert(self, dest, field, converter, value):
|
||||
tupleClass = getattr(converter, "tupleClass", None)
|
||||
enumClass = getattr(converter, "enumClass", None)
|
||||
simpleValueClass = getattr(converter, "valueClass", None)
|
||||
|
||||
if tupleClass:
|
||||
value = convertTupleClass(tupleClass, value)
|
||||
@ -112,8 +114,10 @@ class TableBuilder:
|
||||
else:
|
||||
value = enumClass(value)
|
||||
|
||||
elif simpleValueClass:
|
||||
value = simpleValueClass(value)
|
||||
elif isinstance(converter, IntValue):
|
||||
value = otRound(value)
|
||||
elif isinstance(converter, FloatValue):
|
||||
value = float(value)
|
||||
|
||||
elif isinstance(converter, Struct):
|
||||
if converter.repeat:
|
||||
|
@ -216,8 +216,6 @@ class SimpleValue(BaseConverter):
|
||||
return self.fromString(attrs["value"])
|
||||
|
||||
class IntValue(SimpleValue):
|
||||
valueClass = int
|
||||
|
||||
@staticmethod
|
||||
def fromString(value):
|
||||
return int(value, 0)
|
||||
@ -297,7 +295,6 @@ class Tag(SimpleValue):
|
||||
writer.writeTag(value)
|
||||
|
||||
class GlyphID(SimpleValue):
|
||||
valueClass = str
|
||||
staticSize = 2
|
||||
typecode = "H"
|
||||
def readArray(self, reader, font, tableDict, count):
|
||||
@ -337,7 +334,6 @@ class NameID(UShort):
|
||||
|
||||
|
||||
class FloatValue(SimpleValue):
|
||||
valueClass = float
|
||||
@staticmethod
|
||||
def fromString(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