[varLib.mutator] Fix changes lost during cherry-picking.
This commit is contained in:
parent
272244a822
commit
92b5e0faaa
@ -17,6 +17,7 @@ from fontTools.varLib.merger import MutatorMerger
|
||||
from fontTools.varLib.varStore import VarStoreInstancer
|
||||
from fontTools.varLib.mvar import MVAR_ENTRIES
|
||||
from fontTools.varLib.iup import iup_delta
|
||||
from fontTools.subset.cffLib import interpolate_cff2_PrivateDict, interpolate_cff2_charstrings
|
||||
import os.path
|
||||
import logging
|
||||
|
||||
@ -31,70 +32,6 @@ for i, (prev, curr) in enumerate(zip(percents[:-1], percents[1:]), start=1):
|
||||
OS2_WIDTH_CLASS_VALUES[half] = i
|
||||
|
||||
|
||||
def interpolate_cff2_PrivateDict(topDict, interpolateFromDeltas):
|
||||
pd_blend_lists = ("BlueValues", "OtherBlues", "FamilyBlues",
|
||||
"FamilyOtherBlues", "StemSnapH",
|
||||
"StemSnapV")
|
||||
pd_blend_values = ("BlueScale", "BlueShift",
|
||||
"BlueFuzz", "StdHW", "StdVW")
|
||||
for fontDict in topDict.FDArray:
|
||||
pd = fontDict.Private
|
||||
vsindex = pd.vsindex if (hasattr(pd, 'vsindex')) else 0
|
||||
for key, value in pd.rawDict.items():
|
||||
if (key in pd_blend_values) and isinstance(value, list):
|
||||
delta = interpolateFromDeltas(vsindex, value[1:])
|
||||
pd.rawDict[key] = otRound(value[0] + delta)
|
||||
elif (key in pd_blend_lists) and isinstance(value[0], list):
|
||||
"""If any argument in a BlueValues list is a blend list,
|
||||
then they all are. The first value of each list is an
|
||||
absolute value. The delta tuples are calculated from
|
||||
relative master values, hence we need to append all the
|
||||
deltas to date to each successive absolute value."""
|
||||
delta = 0
|
||||
for i, val_list in enumerate(value):
|
||||
delta += otRound(interpolateFromDeltas(vsindex,
|
||||
val_list[1:]))
|
||||
value[i] = val_list[0] + delta
|
||||
|
||||
|
||||
def interpolate_cff2_charstrings(topDict, interpolateFromDeltas, glyphOrder):
|
||||
charstrings = topDict.CharStrings
|
||||
for gname in glyphOrder:
|
||||
charstring = charstrings[gname]
|
||||
charstring.decompile()
|
||||
vsindex = charstring.private.vsindex if (
|
||||
hasattr(charstring.private,
|
||||
'vsindex')) else 0
|
||||
num_regions = charstring.private.getNumRegions(vsindex)
|
||||
numMasters = num_regions + 1
|
||||
new_program = []
|
||||
last_i = 0
|
||||
for i, token in enumerate(charstring.program):
|
||||
if token == 'blend':
|
||||
num_args = charstring.program[i - 1]
|
||||
""" The stack is now:
|
||||
..args for following operations
|
||||
num_args values from the default font
|
||||
num_args tuples, each with numMasters-1 delta values
|
||||
num_blend_args
|
||||
'blend'
|
||||
"""
|
||||
argi = i - (num_args*numMasters + 1)
|
||||
end_args = tuplei = argi + num_args
|
||||
while argi < end_args:
|
||||
next_ti = tuplei + num_regions
|
||||
deltas = charstring.program[tuplei:next_ti]
|
||||
delta = interpolateFromDeltas(vsindex, deltas)
|
||||
charstring.program[argi] += otRound(delta)
|
||||
tuplei = next_ti
|
||||
argi += 1
|
||||
new_program.extend(charstring.program[last_i:end_args])
|
||||
last_i = i + 1
|
||||
if last_i != 0:
|
||||
new_program.extend(charstring.program[last_i:])
|
||||
charstring.program = new_program
|
||||
|
||||
|
||||
def instantiateVariableFont(varfont, location, inplace=False):
|
||||
""" Generate a static instance from a variable TTFont and a dictionary
|
||||
defining the desired location along the variable font's axes.
|
||||
@ -151,6 +88,7 @@ def instantiateVariableFont(varfont, location, inplace=False):
|
||||
_SetCoordinates(varfont, glyphname, coordinates)
|
||||
else:
|
||||
glyf = None
|
||||
|
||||
if 'cvar' in varfont:
|
||||
log.info("Mutating cvt/cvar tables")
|
||||
cvar = varfont['cvar']
|
||||
@ -168,11 +106,13 @@ def instantiateVariableFont(varfont, location, inplace=False):
|
||||
if 'CFF2' in varfont:
|
||||
log.info("Mutating CFF2 table")
|
||||
glyphOrder = varfont.getGlyphOrder()
|
||||
topDict = varfont['CFF2'].cff.topDictIndex[0]
|
||||
CFF2= varfont['CFF2']
|
||||
topDict = CFF2.cff.topDictIndex[0]
|
||||
vsInstancer = VarStoreInstancer(topDict.VarStore.otVarStore,
|
||||
fvar.axes, loc)
|
||||
interpolateFromDeltas = vsInstancer.interpolateFromDeltas
|
||||
interpolate_cff2_PrivateDict(topDict, interpolateFromDeltas)
|
||||
CFF2.desubroutinize(varfont)
|
||||
interpolate_cff2_charstrings(topDict, interpolateFromDeltas,
|
||||
glyphOrder)
|
||||
|
||||
@ -245,7 +185,6 @@ def instantiateVariableFont(varfont, location, inplace=False):
|
||||
(gdef.Version >= 0x00010002 and gdef.MarkGlyphSetsDef)):
|
||||
del varfont['GDEF']
|
||||
|
||||
|
||||
addidef = False
|
||||
if glyf:
|
||||
for glyph in glyf.glyphs.values():
|
||||
|
Loading…
x
Reference in New Issue
Block a user