[scaleUpem] Support CFF/CFF2
This commit is contained in:
parent
0c2f125ba0
commit
d4d8c4ac5b
@ -1037,6 +1037,8 @@ class VarStoreData(object):
|
|||||||
return len(self.data)
|
return len(self.data)
|
||||||
|
|
||||||
def getNumRegions(self, vsIndex):
|
def getNumRegions(self, vsIndex):
|
||||||
|
if vsIndex is None:
|
||||||
|
vsIndex = 0
|
||||||
varData = self.otVarStore.VarData[vsIndex]
|
varData = self.otVarStore.VarData[vsIndex]
|
||||||
numRegions = varData.VarRegionCount
|
numRegions = varData.VarRegionCount
|
||||||
return numRegions
|
return numRegions
|
||||||
|
@ -3,7 +3,6 @@ from fontTools import ttLib
|
|||||||
from fontTools.pens.basePen import NullPen
|
from fontTools.pens.basePen import NullPen
|
||||||
from fontTools.misc.roundTools import otRound
|
from fontTools.misc.roundTools import otRound
|
||||||
from fontTools.misc.loggingTools import deprecateFunction
|
from fontTools.misc.loggingTools import deprecateFunction
|
||||||
from fontTools.varLib.varStore import VarStoreInstancer
|
|
||||||
from fontTools.subset.util import _add_method, _uniq_sort
|
from fontTools.subset.util import _add_method, _uniq_sort
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@ from fontTools.ttLib.ttVisitor import TTVisitor
|
|||||||
import fontTools.ttLib as ttLib
|
import fontTools.ttLib as ttLib
|
||||||
import fontTools.ttLib.tables.otBase as otBase
|
import fontTools.ttLib.tables.otBase as otBase
|
||||||
import fontTools.ttLib.tables.otTables as otTables
|
import fontTools.ttLib.tables.otTables as otTables
|
||||||
|
from fontTools.cffLib import VarStoreData
|
||||||
|
import fontTools.cffLib.specializer as cffSpecializer
|
||||||
from fontTools.misc.fixedTools import otRound
|
from fontTools.misc.fixedTools import otRound
|
||||||
|
|
||||||
|
|
||||||
@ -144,6 +146,41 @@ def visit(visitor, obj, attr, kernTables):
|
|||||||
kernTable[k] = visitor.scale(kernTable[k])
|
kernTable[k] = visitor.scale(kernTable[k])
|
||||||
|
|
||||||
|
|
||||||
|
def _cff_scale(visitor, args):
|
||||||
|
new_args = []
|
||||||
|
for arg in args:
|
||||||
|
if not isinstance(arg, list):
|
||||||
|
new_args.append(visitor.scale(arg))
|
||||||
|
else:
|
||||||
|
num_blends = arg[-1]
|
||||||
|
_cff_scale(visitor, arg)
|
||||||
|
arg[-1] = num_blends
|
||||||
|
new_args.append(arg)
|
||||||
|
args[:] = new_args
|
||||||
|
|
||||||
|
|
||||||
|
@ScalerVisitor.register_attr(
|
||||||
|
(ttLib.getTableClass("CFF "), ttLib.getTableClass("CFF2")), "cff"
|
||||||
|
)
|
||||||
|
def visit(visitor, obj, attr, cff):
|
||||||
|
cff.desubroutinize()
|
||||||
|
topDict = cff.topDictIndex[0]
|
||||||
|
varStore = getattr(topDict, "VarStore", None)
|
||||||
|
getNumRegions = varStore.getNumRegions if varStore is not None else None
|
||||||
|
for fontname in cff.keys():
|
||||||
|
font = cff[fontname]
|
||||||
|
cs = font.CharStrings
|
||||||
|
for g in font.charset:
|
||||||
|
c, _ = cs.getItemAndSelector(g)
|
||||||
|
|
||||||
|
commands = cffSpecializer.programToCommands(
|
||||||
|
c.program, getNumRegions=getNumRegions
|
||||||
|
)
|
||||||
|
for op, args in commands:
|
||||||
|
_cff_scale(visitor, args)
|
||||||
|
c.program[:] = cffSpecializer.commandsToProgram(commands)
|
||||||
|
|
||||||
|
|
||||||
# ItemVariationStore
|
# ItemVariationStore
|
||||||
|
|
||||||
|
|
||||||
@ -229,13 +266,6 @@ def main(args=None):
|
|||||||
font = TTFont(args[0])
|
font = TTFont(args[0])
|
||||||
new_upem = int(args[1])
|
new_upem = int(args[1])
|
||||||
|
|
||||||
if "CFF " in font or "CFF2" in font:
|
|
||||||
print(
|
|
||||||
"fonttools ttLib.scaleUpem: CFF/CFF2 fonts are not supported.",
|
|
||||||
file=sys.stderr,
|
|
||||||
)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
scale_upem(font, new_upem)
|
scale_upem(font, new_upem)
|
||||||
|
|
||||||
print("Writing out.ttf")
|
print("Writing out.ttf")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user