aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/fonttools/fontTools/cffLib
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-06-11 11:48:44 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-06-12 09:58:01 +0300
commita26a1f012a93e209458200c2ba8ae484a45a6c54 (patch)
tree593bfd3677bce7f893c30c81dcc4fc36f1360782 /contrib/python/fonttools/fontTools/cffLib
parent07f57e35443ab7f09471caf2dbf1afbcced4d9f7 (diff)
downloadydb-a26a1f012a93e209458200c2ba8ae484a45a6c54.tar.gz
Intermediate changes
Diffstat (limited to 'contrib/python/fonttools/fontTools/cffLib')
-rw-r--r--contrib/python/fonttools/fontTools/cffLib/CFF2ToCFF.py32
-rw-r--r--contrib/python/fonttools/fontTools/cffLib/CFFToCFF2.py26
-rw-r--r--contrib/python/fonttools/fontTools/cffLib/__init__.py2
-rw-r--r--contrib/python/fonttools/fontTools/cffLib/transforms.py5
4 files changed, 52 insertions, 13 deletions
diff --git a/contrib/python/fonttools/fontTools/cffLib/CFF2ToCFF.py b/contrib/python/fonttools/fontTools/cffLib/CFF2ToCFF.py
index 5dc48a7fcb..689412ce2b 100644
--- a/contrib/python/fonttools/fontTools/cffLib/CFF2ToCFF.py
+++ b/contrib/python/fonttools/fontTools/cffLib/CFF2ToCFF.py
@@ -2,7 +2,13 @@
from fontTools.ttLib import TTFont, newTable
from fontTools.misc.cliTools import makeOutputFileName
-from fontTools.cffLib import TopDictIndex, buildOrder, topDictOperators
+from fontTools.cffLib import (
+ TopDictIndex,
+ buildOrder,
+ buildDefaults,
+ topDictOperators,
+ privateDictOperators,
+)
from .width import optimizeWidths
from collections import defaultdict
import logging
@@ -36,16 +42,32 @@ def _convertCFF2ToCFF(cff, otFont):
if hasattr(topDict, "VarStore"):
raise ValueError("Variable CFF2 font cannot be converted to CFF format.")
- if hasattr(topDict, "Private"):
- privateDict = topDict.Private
- else:
- privateDict = None
opOrder = buildOrder(topDictOperators)
topDict.order = opOrder
+ for key in topDict.rawDict.keys():
+ if key not in opOrder:
+ del topDict.rawDict[key]
+ if hasattr(topDict, key):
+ delattr(topDict, key)
fdArray = topDict.FDArray
charStrings = topDict.CharStrings
+ defaults = buildDefaults(privateDictOperators)
+ order = buildOrder(privateDictOperators)
+ for fd in fdArray:
+ fd.setCFF2(False)
+ privateDict = fd.Private
+ privateDict.order = order
+ for key in order:
+ if key not in privateDict.rawDict and key in defaults:
+ privateDict.rawDict[key] = defaults[key]
+ for key in privateDict.rawDict.keys():
+ if key not in order:
+ del privateDict.rawDict[key]
+ if hasattr(privateDict, key):
+ delattr(privateDict, key)
+
for cs in charStrings.values():
cs.decompile()
cs.program.append("endchar")
diff --git a/contrib/python/fonttools/fontTools/cffLib/CFFToCFF2.py b/contrib/python/fonttools/fontTools/cffLib/CFFToCFF2.py
index 78347c6667..37463a5b9b 100644
--- a/contrib/python/fonttools/fontTools/cffLib/CFFToCFF2.py
+++ b/contrib/python/fonttools/fontTools/cffLib/CFFToCFF2.py
@@ -43,7 +43,15 @@ def _convertCFFToCFF2(cff, otFont):
fdArray = topDict.FDArray if hasattr(topDict, "FDArray") else None
charStrings = topDict.CharStrings
globalSubrs = cff.GlobalSubrs
- localSubrs = [getattr(fd.Private, "Subrs", []) for fd in fdArray] if fdArray else []
+ localSubrs = (
+ [getattr(fd.Private, "Subrs", []) for fd in fdArray]
+ if fdArray
+ else (
+ [topDict.Private.Subrs]
+ if hasattr(topDict, "Private") and hasattr(topDict.Private, "Subrs")
+ else []
+ )
+ )
for glyphName in charStrings.keys():
cs, fdIndex = charStrings.getItemAndSelector(glyphName)
@@ -70,13 +78,21 @@ def _convertCFFToCFF2(cff, otFont):
for glyphName in charStrings.keys():
cs, fdIndex = charStrings.getItemAndSelector(glyphName)
program = cs.program
- if fdIndex == None:
- fdIndex = 0
+
+ thisLocalSubrs = (
+ localSubrs[fdIndex]
+ if fdIndex
+ else (
+ getattr(topDict.Private, "Subrs", [])
+ if hasattr(topDict, "Private")
+ else []
+ )
+ )
# Intentionally use custom type for nominalWidthX, such that any
# CharString that has an explicit width encoded will throw back to us.
extractor = T2WidthExtractor(
- localSubrs[fdIndex] if localSubrs else [],
+ thisLocalSubrs,
globalSubrs,
nominalWidthXError,
0,
@@ -94,7 +110,7 @@ def _convertCFFToCFF2(cff, otFont):
op = program.pop(0)
bias = extractor.localBias if op == "callsubr" else extractor.globalBias
subrNumber += bias
- subrSet = localSubrs[fdIndex] if op == "callsubr" else globalSubrs
+ subrSet = thisLocalSubrs if op == "callsubr" else globalSubrs
subrProgram = subrSet[subrNumber].program
program[:0] = subrProgram
# Now pop the actual width
diff --git a/contrib/python/fonttools/fontTools/cffLib/__init__.py b/contrib/python/fonttools/fontTools/cffLib/__init__.py
index 9cfdebaa11..c192ec77af 100644
--- a/contrib/python/fonttools/fontTools/cffLib/__init__.py
+++ b/contrib/python/fonttools/fontTools/cffLib/__init__.py
@@ -1470,7 +1470,7 @@ class CharsetConverter(SimpleConverter):
else: # offset == 0 -> no charset data.
if isCID or "CharStrings" not in parent.rawDict:
# We get here only when processing fontDicts from the FDArray of
- # CFF-CID fonts. Only the real topDict references the chrset.
+ # CFF-CID fonts. Only the real topDict references the charset.
assert value == 0
charset = None
elif value == 0:
diff --git a/contrib/python/fonttools/fontTools/cffLib/transforms.py b/contrib/python/fonttools/fontTools/cffLib/transforms.py
index 0772d85e21..91f6999fe6 100644
--- a/contrib/python/fonttools/fontTools/cffLib/transforms.py
+++ b/contrib/python/fonttools/fontTools/cffLib/transforms.py
@@ -342,7 +342,7 @@ def _cs_drop_hints(charstring):
del charstring._hints
-def remove_hints(cff):
+def remove_hints(cff, *, removeUnusedSubrs: bool = True):
for fontname in cff.keys():
font = cff[fontname]
cs = font.CharStrings
@@ -404,7 +404,8 @@ def remove_hints(cff):
]:
if hasattr(priv, k):
setattr(priv, k, None)
- remove_unused_subroutines(cff)
+ if removeUnusedSubrs:
+ remove_unused_subroutines(cff)
def _pd_delete_empty_subrs(private_dict):