[otBase|otTables] enforce VarStore RegionAxisCount == fvar.AxisCount
even when there are no Regions and thus we can't take the length of VarRegionAxis array. This is to appease older versions of OTS which blindly enforce this rule and reject a VF that has, e.g., an empty HVAR table with no regions if the HVAR.VarStore.VarRegionList.RegionAxisCount != fvar.AxisCount. Fixes https://github.com/fonttools/fonttools/issues/1670 Related: https://github.com/fonttools/fonttools/pull/1671 https://github.com/googlefonts/fontmake/issues/565 https://github.com/khaledhosny/ots/pull/192
This commit is contained in:
parent
d96c92f95e
commit
adc5b2997e
@ -498,6 +498,11 @@ class OTTableWriter(object):
|
|||||||
return OverflowErrorRecord( (self.tableTag, LookupListIndex, SubTableIndex, itemName, itemIndex) )
|
return OverflowErrorRecord( (self.tableTag, LookupListIndex, SubTableIndex, itemName, itemIndex) )
|
||||||
|
|
||||||
|
|
||||||
|
class LiteralCount(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):
|
||||||
@ -690,8 +695,12 @@ 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.
|
||||||
ref = writer.writeCountReference(table, conv.name, conv.staticSize)
|
if not isinstance(value, LiteralCount):
|
||||||
table[conv.name] = None
|
# we ignore the current count value since it's being recomputed,
|
||||||
|
# unless this is a LiteralCount, which is assumed to be already correct.
|
||||||
|
value = None
|
||||||
|
ref = writer.writeCountReference(table, conv.name, conv.staticSize, value)
|
||||||
|
table[conv.name] = value
|
||||||
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
|
from .otBase import BaseTable, FormatSwitchingBaseTable, ValueRecord, LiteralCount
|
||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
@ -687,6 +687,22 @@ class VarIdxMap(BaseTable):
|
|||||||
mapping[glyph] = (outer << 16) | inner
|
mapping[glyph] = (outer << 16) | inner
|
||||||
|
|
||||||
|
|
||||||
|
class VarRegionList(BaseTable):
|
||||||
|
|
||||||
|
def preWrite(self, font):
|
||||||
|
# The OT spec says VarStore.VarRegionList.RegionAxisCount should always
|
||||||
|
# be equal to the fvar.axisCount, and OTS < v8.0.0 enforces this rule
|
||||||
|
# even when the VarRegionList is empty. We can't treat RegionAxisCount
|
||||||
|
# like a normal propagated count (== len(Region[i].VarRegionAxis)),
|
||||||
|
# otherwise it would default to 0 if VarRegionList is empty.
|
||||||
|
# Thus, we force it to always be equal to fvar.axisCount.
|
||||||
|
# https://github.com/khaledhosny/ots/pull/192
|
||||||
|
fvarTable = font.get("fvar")
|
||||||
|
if fvarTable:
|
||||||
|
self.RegionAxisCount = LiteralCount(len(fvarTable.axes))
|
||||||
|
return self.__dict__.copy()
|
||||||
|
|
||||||
|
|
||||||
class SingleSubst(FormatSwitchingBaseTable):
|
class SingleSubst(FormatSwitchingBaseTable):
|
||||||
|
|
||||||
def populateDefaults(self, propagator=None):
|
def populateDefaults(self, propagator=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user