From dd02bd704c186b0f4ab0a395986d753b3a6e2432 Mon Sep 17 00:00:00 2001 From: NFSL2001 <33471049+NightFurySL2001@users.noreply.github.com> Date: Wed, 26 Jul 2023 19:59:36 +0800 Subject: [PATCH 1/2] Update opentype.py --- Lib/extractor/formats/opentype.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/extractor/formats/opentype.py b/Lib/extractor/formats/opentype.py index 46dd501..70c49e9 100644 --- a/Lib/extractor/formats/opentype.py +++ b/Lib/extractor/formats/opentype.py @@ -11,7 +11,6 @@ from extractor.exceptions import ExtractorError from extractor.stream import InstructionStream from extractor.tools import RelaxedInfo, copyAttr -from fontFeatures.ttLib import unparse TRUETYPE_INSTRUCTIONS_KEY = "public.truetype.instructions" @@ -1067,6 +1066,7 @@ def _extractOpenTypeKerningFromKern(source): def extractOpenTypeFeatures(source): + from fontFeatures.ttLib import unparse return unparse(source).asFea() From 810278b768c54c1cbab09fc6873eb6c056fd92b0 Mon Sep 17 00:00:00 2001 From: Ben Kiel Date: Fri, 1 Dec 2023 11:20:11 -0600 Subject: [PATCH 2/2] Changes based on feedback @typemytype changed this to do the try/except only if features are asked for, no need to do it if they aren't --- Lib/extractor/formats/opentype.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Lib/extractor/formats/opentype.py b/Lib/extractor/formats/opentype.py index 70c49e9..8b24782 100644 --- a/Lib/extractor/formats/opentype.py +++ b/Lib/extractor/formats/opentype.py @@ -1066,7 +1066,12 @@ def _extractOpenTypeKerningFromKern(source): def extractOpenTypeFeatures(source): - from fontFeatures.ttLib import unparse - return unparse(source).asFea() - - + try: + from fontFeatures.ttLib import unparse + _haveFontFeatures = True + except ImportError: + _haveFontFeatures = False + + if _haveFontFeatures: + return unparse(source).asFea() + return ""