From 5316ae4b8cef78dc8af3479ee6fa87bb95cc4a6c Mon Sep 17 00:00:00 2001 From: rsheeter Date: Fri, 12 Feb 2021 20:23:06 -0800 Subject: [PATCH] Add test to expose missed otRound + fix --- Lib/fontTools/colorLib/table_builder.py | 10 +++++++--- Lib/fontTools/ttLib/tables/otConverters.py | 4 ---- Tests/colorLib/table_builder_test.py | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 Tests/colorLib/table_builder_test.py diff --git a/Lib/fontTools/colorLib/table_builder.py b/Lib/fontTools/colorLib/table_builder.py index 2ce893a94..18e2de181 100644 --- a/Lib/fontTools/colorLib/table_builder.py +++ b/Lib/fontTools/colorLib/table_builder.py @@ -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: diff --git a/Lib/fontTools/ttLib/tables/otConverters.py b/Lib/fontTools/ttLib/tables/otConverters.py index 6bf6c623d..1b278410b 100644 --- a/Lib/fontTools/ttLib/tables/otConverters.py +++ b/Lib/fontTools/ttLib/tables/otConverters.py @@ -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) diff --git a/Tests/colorLib/table_builder_test.py b/Tests/colorLib/table_builder_test.py new file mode 100644 index 000000000..d0a76f5ad --- /dev/null +++ b/Tests/colorLib/table_builder_test.py @@ -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"