[varLib.cff] Fix merging bug when there are no blends or marking glyphs.

If the CFF2 VF has no blends, or no marking glyphs, the default variation table does not get built; this can be needed later for the PrivateDict.
This commit is contained in:
ReadRoberts 2019-06-12 16:31:29 -07:00
parent a56b1af2f6
commit ec54541e30

View File

@ -161,7 +161,7 @@ def merge_PrivateDicts(top_dicts, vsindex_dict, var_model, fd_map):
For each key, step through each relevant source font Private dict, and For each key, step through each relevant source font Private dict, and
build a list of values to blend. build a list of values to blend.
The 'relevant' source fonts are selected by first getting the right The 'relevant' source fonts are selected by first getting the right
submodel using model_keys[vsindex]. The indices of the submodel using vsindex_dict[vsindex]. The indices of the
subModel.locations are mapped to source font list indices by subModel.locations are mapped to source font list indices by
assuming the latter order is the same as the order of the assuming the latter order is the same as the order of the
var_model.locations. I can then get the index of each subModel var_model.locations. I can then get the index of each subModel
@ -180,7 +180,7 @@ def merge_PrivateDicts(top_dicts, vsindex_dict, var_model, fd_map):
# At the moment, no PrivateDict has a vsindex key, but let's support # At the moment, no PrivateDict has a vsindex key, but let's support
# how it should work. See comment at end of # how it should work. See comment at end of
# merge_charstrings() - still need to optimize use of vsindex. # merge_charstrings() - still need to optimize use of vsindex.
sub_model, model_keys = vsindex_dict[vsindex] sub_model, _ = vsindex_dict[vsindex]
master_indices = [] master_indices = []
for loc in sub_model.locations[1:]: for loc in sub_model.locations[1:]:
i = var_model.locations.index(loc) - 1 i = var_model.locations.index(loc) - 1
@ -317,6 +317,19 @@ def _get_cs(charstrings, glyphName):
return None return None
return charstrings[glyphName] return charstrings[glyphName]
def _add_new_vsindex(model, key, masterSupports, vsindex_dict,
vsindex_by_key, varDataList):
varTupleIndexes = []
for support in model.supports[1:]:
if support not in masterSupports:
masterSupports.append(support)
varTupleIndexes.append(masterSupports.index(support))
var_data = varLib.builder.buildVarData(varTupleIndexes, None, False)
vsindex = len(vsindex_dict)
vsindex_by_key[key] = vsindex
vsindex_dict[vsindex] = (model, [key])
varDataList.append(var_data)
return vsindex
def merge_charstrings(glyphOrder, num_masters, top_dicts, masterModel): def merge_charstrings(glyphOrder, num_masters, top_dicts, masterModel):
@ -365,24 +378,24 @@ def merge_charstrings(glyphOrder, num_masters, top_dicts, masterModel):
# If the charstring required a new model, create # If the charstring required a new model, create
# a VarData table to go with, and set vsindex. # a VarData table to go with, and set vsindex.
key = tuple(v is not None for v in all_cs)
try: try:
key = tuple(v is not None for v in all_cs)
vsindex = vsindex_by_key[key] vsindex = vsindex_by_key[key]
except KeyError: except KeyError:
varTupleIndexes = [] vsindex = _add_new_vsindex(model, key,masterSupports, vsindex_dict,
for support in model.supports[1:]: vsindex_by_key, varDataList)
if support not in masterSupports:
masterSupports.append(support)
varTupleIndexes.append(masterSupports.index(support))
var_data = varLib.builder.buildVarData(varTupleIndexes, None, False)
vsindex = len(vsindex_dict)
vsindex_by_key[key] = vsindex
vsindex_dict[vsindex] = (model, [key])
varDataList.append(var_data)
# We do not need to check for an existing new_cs.private.vsindex, # We do not need to check for an existing new_cs.private.vsindex,
# as we know it doesn't exist yet. # as we know it doesn't exist yet.
if vsindex != 0: if vsindex != 0:
new_cs.program[:0] = [vsindex, 'vsindex'] new_cs.program[:0] = [vsindex, 'vsindex']
# If there is no variation in any of the charstrings, then vsindex_dict
# never gets built. This is could still be needed if there is variation
# in the PrivatDict, so we will build the default data for vsindex = 0.
if not vsindex_dict:
key = (True)*num_masters
_add_new_vsindex(model, key, masterSupports, vsindex_dict,
vsindex_by_key, varDataList)
cvData = CVarData(varDataList=varDataList, masterSupports=masterSupports, cvData = CVarData(varDataList=varDataList, masterSupports=masterSupports,
vsindex_dict=vsindex_dict) vsindex_dict=vsindex_dict)
# XXX To do: optimize use of vsindex between the PrivateDicts and # XXX To do: optimize use of vsindex between the PrivateDicts and