From 4ad6b0db134e75dbf9845ea6c9577b0beb3d5ef8 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 27 May 2024 16:22:19 -0600 Subject: [PATCH] [CFF2ToCFF] Map charset to CIDs This seems to fix the case of ttx not handling the results. I *think* this fixes the rest of the issues I've been seeing with this conversion. --- Lib/fontTools/cffLib/CFF2ToCFF.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Lib/fontTools/cffLib/CFF2ToCFF.py b/Lib/fontTools/cffLib/CFF2ToCFF.py index 6002069a2..f929cc968 100644 --- a/Lib/fontTools/cffLib/CFF2ToCFF.py +++ b/Lib/fontTools/cffLib/CFF2ToCFF.py @@ -100,6 +100,21 @@ def _convertCFF2ToCFF(cff, otFont): if width != private.defaultWidthX: cs.program.insert(0, width - private.nominalWidthX) + mapping = { + name: ("cid" + str(n) if n else ".notdef") + for n, name in enumerate(topDict.charset) + } + topDict.charset = [ + "cid" + str(n) if n else ".notdef" for n in range(len(topDict.charset)) + ] + charStrings.charStrings = { + mapping[name]: v for name, v in charStrings.charStrings.items() + } + + # I'm not sure why the following is *not* necessary. And it breaks + # the output if I add it. + # topDict.ROS = ("Adobe", "Identity", 0) + def convertCFF2ToCFF(font, *, updatePostTable=True): cff = font["CFF2"].cff