[cffLib.CFF2ToCFF] Fixup

This commit is contained in:
Behdad Esfahbod 2024-05-16 16:16:14 -07:00
parent 1d1b7eb2f2
commit b009b614f3

View File

@ -25,9 +25,6 @@ def convertCFF2ToCFF(cff, otFont):
filled via :meth:`decompile` and e.g. not loaded from XML.)""" filled via :meth:`decompile` and e.g. not loaded from XML.)"""
cff.major = 1 cff.major = 1
topDict = cff.topDictIndex[0]
if hasattr(topDict, "VarStore"):
raise ValueError("Variable CFF2 font cannot be converted to CFF format.")
topDictData = TopDictIndex(None, isCFF2=True) topDictData = TopDictIndex(None, isCFF2=True)
for item in cff.topDictIndex: for item in cff.topDictIndex:
@ -35,6 +32,10 @@ def convertCFF2ToCFF(cff, otFont):
topDictData.append(item) topDictData.append(item)
cff.topDictIndex = topDictData cff.topDictIndex = topDictData
topDict = topDictData[0] topDict = topDictData[0]
if hasattr(topDict, "VarStore"):
raise ValueError("Variable CFF2 font cannot be converted to CFF format.")
if hasattr(topDict, "Private"): if hasattr(topDict, "Private"):
privateDict = topDict.Private privateDict = topDict.Private
else: else:
@ -46,11 +47,13 @@ def convertCFF2ToCFF(cff, otFont):
charStrings = topDict.CharStrings charStrings = topDict.CharStrings
for cs in charStrings.values(): for cs in charStrings.values():
cs.decompile()
cs.program.append("endchar") cs.program.append("endchar")
for subrSets in [cff.GlobalSubrs] + [ for subrSets in [cff.GlobalSubrs] + [
getattr(fd.Private, "Subrs", []) for fd in fdArray getattr(fd.Private, "Subrs", []) for fd in fdArray
]: ]:
for cs in subrSets: for cs in subrSets:
cs.decompile()
cs.program.append("return") cs.program.append("return")
# Add (optimal) width to CharStrings that need it. # Add (optimal) width to CharStrings that need it.