[VARC] Use one varIndexBase only
This commit is contained in:
parent
aad01a9d85
commit
1a1e9e198b
@ -1922,7 +1922,6 @@ class CFF2Index(BaseConverter):
|
|||||||
item.toXML(xmlWriter, font, [("index", i)], name)
|
item.toXML(xmlWriter, font, [("index", i)], name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LookupFlag(UShort):
|
class LookupFlag(UShort):
|
||||||
def xmlWrite(self, xmlWriter, font, value, name, attrs):
|
def xmlWrite(self, xmlWriter, font, value, name, attrs):
|
||||||
xmlWriter.simpletag(name, attrs + [("value", value)])
|
xmlWriter.simpletag(name, attrs + [("value", value)])
|
||||||
|
@ -104,9 +104,8 @@ class VarComponent:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.glyphName = None
|
self.glyphName = None
|
||||||
self.location = {}
|
self.location = {}
|
||||||
self.locationVarIdxBase = NO_VARIATION_INDEX
|
|
||||||
self.transform = DecomposedTransform()
|
self.transform = DecomposedTransform()
|
||||||
self.transformVarIdxBase = NO_VARIATION_INDEX
|
self.varIndexBase = NO_VARIATION_INDEX
|
||||||
|
|
||||||
def decompile(self, data, font):
|
def decompile(self, data, font):
|
||||||
i = 0
|
i = 0
|
||||||
@ -148,10 +147,6 @@ class VarComponent:
|
|||||||
axes = font["fvar"].axes
|
axes = font["fvar"].axes
|
||||||
self.location = {axes[i].axisTag: v for i, v in zip(axisIndices, axisValues)}
|
self.location = {axes[i].axisTag: v for i, v in zip(axisIndices, axisValues)}
|
||||||
|
|
||||||
if flags & VarComponentFlags.AXIS_VALUES_HAVE_VARIATION:
|
|
||||||
self.locationVarIdxBase = struct.unpack(">L", data[i : i + 4])[0]
|
|
||||||
i += 4
|
|
||||||
|
|
||||||
def read_transform_component(data, values):
|
def read_transform_component(data, values):
|
||||||
nonlocal i
|
nonlocal i
|
||||||
if flags & values.flag:
|
if flags & values.flag:
|
||||||
@ -173,8 +168,11 @@ class VarComponent:
|
|||||||
if not (flags & VarComponentFlags.HAVE_SCALE_Y):
|
if not (flags & VarComponentFlags.HAVE_SCALE_Y):
|
||||||
self.transform.scaleY = self.transform.scaleX
|
self.transform.scaleY = self.transform.scaleX
|
||||||
|
|
||||||
if flags & VarComponentFlags.TRANSFORM_HAS_VARIATION:
|
if flags & (
|
||||||
self.transformVarIdxBase = struct.unpack(">L", data[i : i + 4])[0]
|
VarComponentFlags.AXIS_VALUES_HAVE_VARIATION
|
||||||
|
| VarComponentFlags.TRANSFORM_HAS_VARIATION
|
||||||
|
):
|
||||||
|
self.varIndexBase = struct.unpack(">L", data[i : i + 4])[0]
|
||||||
i += 4
|
i += 4
|
||||||
|
|
||||||
return data[i:]
|
return data[i:]
|
||||||
@ -230,12 +228,6 @@ class VarComponent:
|
|||||||
axisValues.byteswap()
|
axisValues.byteswap()
|
||||||
data.append(bytes(axisValues))
|
data.append(bytes(axisValues))
|
||||||
|
|
||||||
if self.locationVarIdxBase != NO_VARIATION_INDEX:
|
|
||||||
flags |= VarComponentFlags.AXIS_VALUES_HAVE_VARIATION
|
|
||||||
data.append(struct.pack(">L", self.locationVarIdxBase))
|
|
||||||
elif flags & VarComponentFlags.AXIS_VALUES_HAVE_VARIATION:
|
|
||||||
flags ^= VarComponentFlags.AXIS_VALUES_HAVE_VARIATION
|
|
||||||
|
|
||||||
def write_transform_component(value, values):
|
def write_transform_component(value, values):
|
||||||
if flags & values.flag:
|
if flags & values.flag:
|
||||||
return struct.pack(
|
return struct.pack(
|
||||||
@ -248,11 +240,11 @@ class VarComponent:
|
|||||||
value = getattr(self.transform, attr_name)
|
value = getattr(self.transform, attr_name)
|
||||||
data.append(write_transform_component(value, mapping_values))
|
data.append(write_transform_component(value, mapping_values))
|
||||||
|
|
||||||
if self.transformVarIdxBase != NO_VARIATION_INDEX:
|
if flags & (
|
||||||
flags |= VarComponentFlags.TRANSFORM_HAS_VARIATION
|
VarComponentFlags.AXIS_VALUES_HAVE_VARIATION
|
||||||
data.append(struct.pack(">L", self.transformVarIdxBase))
|
| VarComponentFlags.TRANSFORM_HAS_VARIATION
|
||||||
elif flags & VarComponentFlags.TRANSFORM_HAS_VARIATION:
|
):
|
||||||
flags ^= VarComponentFlags.TRANSFORM_HAS_VARIATION
|
data.append(struct.pack(">L", self.varIndexBase))
|
||||||
|
|
||||||
return struct.pack(">H", flags) + bytesjoin(data)
|
return struct.pack(">H", flags) + bytesjoin(data)
|
||||||
|
|
||||||
@ -262,6 +254,11 @@ class VarComponent:
|
|||||||
if hasattr(self, "flags"):
|
if hasattr(self, "flags"):
|
||||||
attrs = attrs + [("flags", hex(self.flags))]
|
attrs = attrs + [("flags", hex(self.flags))]
|
||||||
|
|
||||||
|
# TODO Move to an element?
|
||||||
|
if self.varIndexBase != NO_VARIATION_INDEX:
|
||||||
|
attrs = attrs + [("varIndexBase", self.varIndexBase)]
|
||||||
|
|
||||||
|
# TODO Move transform into it's own element?
|
||||||
for attr_name, mapping in VAR_COMPONENT_TRANSFORM_MAPPING.items():
|
for attr_name, mapping in VAR_COMPONENT_TRANSFORM_MAPPING.items():
|
||||||
v = getattr(self.transform, attr_name)
|
v = getattr(self.transform, attr_name)
|
||||||
if v != mapping.defaultValue:
|
if v != mapping.defaultValue:
|
||||||
@ -287,6 +284,9 @@ class VarComponent:
|
|||||||
if "flags" in attrs:
|
if "flags" in attrs:
|
||||||
self.flags = safeEval(attrs["flags"])
|
self.flags = safeEval(attrs["flags"])
|
||||||
|
|
||||||
|
if "varIndexBase" in attrs:
|
||||||
|
self.varIndexBase = safeEval(attrs["varIndexBase"])
|
||||||
|
|
||||||
for attr_name, mapping in VAR_COMPONENT_TRANSFORM_MAPPING.items():
|
for attr_name, mapping in VAR_COMPONENT_TRANSFORM_MAPPING.items():
|
||||||
if attr_name not in attrs:
|
if attr_name not in attrs:
|
||||||
continue
|
continue
|
||||||
@ -318,7 +318,6 @@ class VarComponent:
|
|||||||
|
|
||||||
|
|
||||||
class VarCompositeGlyph(BaseTable):
|
class VarCompositeGlyph(BaseTable):
|
||||||
|
|
||||||
def populateDefaults(self, propagator=None):
|
def populateDefaults(self, propagator=None):
|
||||||
if not hasattr(self, "components"):
|
if not hasattr(self, "components"):
|
||||||
self.components = []
|
self.components = []
|
||||||
@ -351,8 +350,8 @@ class VarCompositeGlyph(BaseTable):
|
|||||||
component.fromXML(name, attrs, content, font)
|
component.fromXML(name, attrs, content, font)
|
||||||
self.components.append(component)
|
self.components.append(component)
|
||||||
|
|
||||||
class VarCompositeGlyphs(BaseTable):
|
|
||||||
|
|
||||||
|
class VarCompositeGlyphs(BaseTable):
|
||||||
def populateDefaults(self, propagator=None):
|
def populateDefaults(self, propagator=None):
|
||||||
if not hasattr(self, "glyphs"):
|
if not hasattr(self, "glyphs"):
|
||||||
self.glyphs = []
|
self.glyphs = []
|
||||||
@ -366,6 +365,7 @@ class VarCompositeGlyphs(BaseTable):
|
|||||||
glyph.fromXML(eltName, eltAttrs, eltContent, font)
|
glyph.fromXML(eltName, eltAttrs, eltContent, font)
|
||||||
self.glyphs.append(glyph)
|
self.glyphs.append(glyph)
|
||||||
|
|
||||||
|
|
||||||
class AATStateTable(object):
|
class AATStateTable(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.GlyphClasses = {} # GlyphID --> GlyphClass
|
self.GlyphClasses = {} # GlyphID --> GlyphClass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user