set pre-initialized CountReference in VarRegionList.preWrite with fvar.axisCount
so we can reuse CountReference class, as suggested in https://github.com/fonttools/fonttools/pull/1752#issuecomment-547113944 The patch is no shorter though.
This commit is contained in:
parent
e8f5bbcc6a
commit
ebadcd96e6
@ -498,11 +498,6 @@ class OTTableWriter(object):
|
|||||||
return OverflowErrorRecord( (self.tableTag, LookupListIndex, SubTableIndex, itemName, itemIndex) )
|
return OverflowErrorRecord( (self.tableTag, LookupListIndex, SubTableIndex, itemName, itemIndex) )
|
||||||
|
|
||||||
|
|
||||||
class StaticCount(int):
|
|
||||||
"""A count value that should be taken literally, rather than recomputed on compile."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class CountReference(object):
|
class CountReference(object):
|
||||||
"""A reference to a Count value, not a count of references."""
|
"""A reference to a Count value, not a count of references."""
|
||||||
def __init__(self, table, name, size=None, value=None):
|
def __init__(self, table, name, size=None, value=None):
|
||||||
@ -518,6 +513,8 @@ class CountReference(object):
|
|||||||
table[name] = value
|
table[name] = value
|
||||||
else:
|
else:
|
||||||
assert table[name] == value, (name, table[name], value)
|
assert table[name] == value, (name, table[name], value)
|
||||||
|
def getValue(self):
|
||||||
|
return self.table[self.name]
|
||||||
def getCountData(self):
|
def getCountData(self):
|
||||||
v = self.table[self.name]
|
v = self.table[self.name]
|
||||||
if v is None: v = 0
|
if v is None: v = 0
|
||||||
@ -695,12 +692,16 @@ class BaseTable(object):
|
|||||||
# table. We will later store it here.
|
# table. We will later store it here.
|
||||||
# We add a reference: by the time the data is assembled
|
# We add a reference: by the time the data is assembled
|
||||||
# the Count value will be filled in.
|
# the Count value will be filled in.
|
||||||
if not isinstance(value, StaticCount):
|
# We ignore the current count value since it will be recomputed,
|
||||||
# we ignore the current count value since it's being recomputed,
|
# unless it's a CountReference that was already initialized in a custom preWrite.
|
||||||
# unless this is of type StaticCount, which is assumed to be correct.
|
if isinstance(value, CountReference):
|
||||||
value = None
|
ref = value
|
||||||
ref = writer.writeCountReference(table, conv.name, conv.staticSize, value)
|
ref.size = conv.staticSize
|
||||||
table[conv.name] = value
|
writer.writeData(ref)
|
||||||
|
table[conv.name] = ref.getValue()
|
||||||
|
else:
|
||||||
|
ref = writer.writeCountReference(table, conv.name, conv.staticSize)
|
||||||
|
table[conv.name] = None
|
||||||
if conv.isPropagated:
|
if conv.isPropagated:
|
||||||
writer[conv.name] = ref
|
writer[conv.name] = ref
|
||||||
elif conv.isLookupType:
|
elif conv.isLookupType:
|
||||||
|
@ -7,7 +7,7 @@ converter objects from otConverters.py.
|
|||||||
"""
|
"""
|
||||||
from fontTools.misc.py23 import *
|
from fontTools.misc.py23 import *
|
||||||
from fontTools.misc.textTools import pad, safeEval
|
from fontTools.misc.textTools import pad, safeEval
|
||||||
from .otBase import BaseTable, FormatSwitchingBaseTable, ValueRecord, StaticCount
|
from .otBase import BaseTable, FormatSwitchingBaseTable, ValueRecord, CountReference
|
||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
@ -699,8 +699,11 @@ class VarRegionList(BaseTable):
|
|||||||
# https://github.com/khaledhosny/ots/pull/192
|
# https://github.com/khaledhosny/ots/pull/192
|
||||||
fvarTable = font.get("fvar")
|
fvarTable = font.get("fvar")
|
||||||
if fvarTable:
|
if fvarTable:
|
||||||
self.RegionAxisCount = StaticCount(len(fvarTable.axes))
|
self.RegionAxisCount = len(fvarTable.axes)
|
||||||
return self.__dict__.copy()
|
return {
|
||||||
|
**self.__dict__,
|
||||||
|
"RegionAxisCount": CountReference(self.__dict__, "RegionAxisCount")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class SingleSubst(FormatSwitchingBaseTable):
|
class SingleSubst(FormatSwitchingBaseTable):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user