From f48551f3f55a7d4cc06b1c9551ec5906ac6c274a Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Wed, 16 Oct 2024 11:42:03 +0300 Subject: [PATCH] [postProcessor] fontTools.varLib.cff.convertCFFtoCFF2 is deprecated Try importing fontTools.cffLib.CFFToCFF2.convertCFFToCFF2 first, and confine the width stripping to when the deprecated method is used, as it is already fixed in FontTools. --- Lib/ufo2ft/postProcessor.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Lib/ufo2ft/postProcessor.py b/Lib/ufo2ft/postProcessor.py index c5378c60..0eeb8661 100644 --- a/Lib/ufo2ft/postProcessor.py +++ b/Lib/ufo2ft/postProcessor.py @@ -318,19 +318,22 @@ def _get_cff_version(otf): @staticmethod def _convert_cff_to_cff2(otf): - from fontTools.varLib.cff import convertCFFtoCFF2 - logger.info("Converting CFF table to CFF2") - # convertCFFtoCFF2 doesn't strip T2CharStrings' widths, so we do it ourselves - # https://github.com/fonttools/fonttools/issues/1835 - charstrings = otf["CFF "].cff[0].CharStrings - for glyph_name in otf.getGlyphOrder(): - cs = charstrings[glyph_name] - cs.decompile() - cs.program = _stripCharStringWidth(cs.program) + try: + from fontTools.cffLib.CFFToCFF2 import convertCFFToCFF2 + except ImportError: + from fontTools.varLib.cff import convertCFFtoCFF2 as convertCFFToCFF2 + + # convertCFFtoCFF2 doesn't strip T2CharStrings' widths, so we do it ourselves + # https://github.com/fonttools/fonttools/issues/1835 + charstrings = otf["CFF "].cff[0].CharStrings + for glyph_name in otf.getGlyphOrder(): + cs = charstrings[glyph_name] + cs.decompile() + cs.program = _stripCharStringWidth(cs.program) - convertCFFtoCFF2(otf) + convertCFFToCFF2(otf) @classmethod def _subroutinize(cls, backend, otf, cffVersion):