[ot] Change Version to be an integer instead of float
API Change: This will change XML output for GSUB/GPOS/GDEF/MATH/BASE/JSTF/... Scripts that set the Version for those to 1.0 or other float values also need fixing. A warning is emitted when code or XML needs fix.
This commit is contained in:
parent
a30b6250cb
commit
402d726692
@ -1582,13 +1582,13 @@ def prune_post_subset(self, options):
|
||||
table.MarkGlyphSetsDef and
|
||||
not table.MarkGlyphSetsDef.Coverage):
|
||||
table.MarkGlyphSetsDef = None
|
||||
if table.Version == 0x00010002/0x10000:
|
||||
table.Version = 1.0
|
||||
if table.Version == 0x00010002:
|
||||
table.Version = 0x00010000
|
||||
return bool(table.LigCaretList or
|
||||
table.MarkAttachClassDef or
|
||||
table.GlyphClassDef or
|
||||
table.AttachList or
|
||||
(table.Version >= 0x00010002/0x10000 and table.MarkGlyphSetsDef))
|
||||
(table.Version >= 0x00010002 and table.MarkGlyphSetsDef))
|
||||
|
||||
@_add_method(ttLib.getTableClass('kern'))
|
||||
def prune_pre_subset(self, font, options):
|
||||
|
@ -267,28 +267,35 @@ class Version(BaseConverter):
|
||||
def read(self, reader, font, tableDict):
|
||||
value = reader.readLong()
|
||||
assert (value >> 16) == 1, "Unsupported version 0x%08x" % value
|
||||
return fi2fl(value, 16)
|
||||
return value
|
||||
def write(self, writer, font, tableDict, value, repeatIndex=None):
|
||||
if value < 0x10000:
|
||||
value = fl2fi(value, 16)
|
||||
value = int(round(value))
|
||||
newValue = self.fromFloat(value)
|
||||
log.warning("Table version value is a float: %g; fix code to use hex instead: %08x", value, newValue)
|
||||
value = newValue
|
||||
assert (value >> 16) == 1, "Unsupported version 0x%08x" % value
|
||||
writer.writeLong(value)
|
||||
def xmlRead(self, attrs, content, font):
|
||||
value = attrs["value"]
|
||||
value = float(int(value, 0)) if value.startswith("0") else float(value)
|
||||
if value >= 0x10000:
|
||||
value = fi2fl(value, 16)
|
||||
value = int(value, 0) if value.startswith("0") else float(value)
|
||||
if value < 0x10000:
|
||||
newValue = self.fromFloat(value)
|
||||
log.warning("Table version value is a float: %g; fix XML to use hex instead: %08x", value, newValue)
|
||||
value = newValue
|
||||
return value
|
||||
def xmlWrite(self, xmlWriter, font, value, name, attrs):
|
||||
if value >= 0x10000:
|
||||
value = fi2fl(value, 16)
|
||||
if value % 1 != 0:
|
||||
# Write as hex
|
||||
value = "0x%08x" % fl2fi(value, 16)
|
||||
if value < 0x10000:
|
||||
newValue = self.fromFloat(value)
|
||||
log.warning("Table version value is a float: %g; fix code to use hex instead: %08x", value, newValue)
|
||||
value = newValue
|
||||
value = "0x%08x" % value
|
||||
xmlWriter.simpletag(name, attrs + [("value", value)])
|
||||
xmlWriter.newline()
|
||||
|
||||
@staticmethod
|
||||
def fromFloat(v):
|
||||
return fl2fi(v, 16)
|
||||
|
||||
|
||||
class Struct(BaseConverter):
|
||||
|
||||
|
@ -644,8 +644,8 @@ otData = [
|
||||
('Offset', 'AttachList', None, None, 'Offset to list of glyphs with attachment points-from beginning of GDEF header (may be NULL)'),
|
||||
('Offset', 'LigCaretList', None, None, 'Offset to list of positioning points for ligature carets-from beginning of GDEF header (may be NULL)'),
|
||||
('Offset', 'MarkAttachClassDef', None, None, 'Offset to class definition table for mark attachment type-from beginning of GDEF header (may be NULL)'),
|
||||
('Offset', 'MarkGlyphSetsDef', None, 'int(round(Version*0x10000)) >= 0x00010002', 'Offset to the table of mark set definitions-from beginning of GDEF header (may be NULL)'),
|
||||
('LOffset', 'VarStore', None, 'int(round(Version*0x10000)) >= 0x00010003', 'Offset to variation store (may be NULL)'),
|
||||
('Offset', 'MarkGlyphSetsDef', None, 'Version >= 0x00010002', 'Offset to the table of mark set definitions-from beginning of GDEF header (may be NULL)'),
|
||||
('LOffset', 'VarStore', None, 'Version >= 0x00010003', 'Offset to variation store (may be NULL)'),
|
||||
]),
|
||||
|
||||
('AttachList', [
|
||||
|
@ -230,7 +230,7 @@ def _add_HVAR(font, model, master_ttfs, axes):
|
||||
assert "HVAR" not in font
|
||||
HVAR = font["HVAR"] = newTable('HVAR')
|
||||
hvar = HVAR.table = ot.HVAR()
|
||||
hvar.Version = 1.0
|
||||
hvar.Version = 0x00010000
|
||||
hvar.VarStore = varStore
|
||||
hvar.AdvWidthMap = advanceMapping
|
||||
hvar.LsbMap = hvar.RsbMap = None
|
||||
|
Loading…
x
Reference in New Issue
Block a user