From 473bf99b6d96cb92b9421d68c8f7225f341bb5c1 Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Sat, 14 Sep 2024 09:07:38 +0200 Subject: [PATCH 1/4] Add GDEF to reproduce the .width AttributeError bug --- .../MutatorSansBoldWideMutated.ufo/features.fea | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tests/data/MutatorSans/MutatorSansBoldWideMutated.ufo/features.fea b/Tests/data/MutatorSans/MutatorSansBoldWideMutated.ufo/features.fea index 769bd3f6..3af4ed8c 100644 --- a/Tests/data/MutatorSans/MutatorSansBoldWideMutated.ufo/features.fea +++ b/Tests/data/MutatorSans/MutatorSansBoldWideMutated.ufo/features.fea @@ -1 +1,9 @@ include(features_test.fea) + +table GDEF { + GlyphClassDef + [ A ], + [ ], + [ macroncmb ], + ; +} GDEF; From dafb1bfa75d594ef2291fb5b7c60a6afc848a0c4 Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Sat, 14 Sep 2024 09:38:04 +0200 Subject: [PATCH 2/4] Also fetch advance width, ufo2ft sometimes needs it --- Lib/fontgoggles/compile/ufoCompiler.py | 41 +++++++++++++++++++------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/Lib/fontgoggles/compile/ufoCompiler.py b/Lib/fontgoggles/compile/ufoCompiler.py index c54af62d..189b27ec 100644 --- a/Lib/fontgoggles/compile/ufoCompiler.py +++ b/Lib/fontgoggles/compile/ufoCompiler.py @@ -35,7 +35,7 @@ def compileUFOToFont(ufoPath): if ".notdef" not in glyphOrder: # We need a .notdef glyph, so let's make one. glyphOrder.insert(0, ".notdef") - cmap, revCmap, anchors = fetchCharacterMappingAndAnchors(glyphSet, ufoPath, ufo2=ufo2) + widths, cmap, revCmap, anchors = fetchGlyphInfo(glyphSet, ufoPath, ufo2=ufo2) fb = FontBuilder(round(info.unitsPerEm)) fb.setupGlyphOrder(glyphOrder) fb.setupCharacterMap(cmap) @@ -46,7 +46,7 @@ def compileUFOToFont(ufoPath): # changes. ttFont["FGAx"] = newTable("FGAx") ttFont["FGAx"].data = pickle.dumps(anchors) - ufo = MinimalFontObject(ufoPath, reader, revCmap, anchors) + ufo = MinimalFontObject(ufoPath, reader, widths, revCmap, anchors) feaComp = FeatureCompiler(ufo, ttFont) try: feaComp.compile() @@ -68,13 +68,15 @@ def compileUFOToPath(ufoPath, ttPath): ttFont.save(ttPath, reorderTables=False) -_unicodeOrAnchorGLIFPattern = re.compile(rb'(<\s*(anchor|unicode)\s+([^>]+)>)') +_tagGLIFPattern = re.compile(rb'(<\s*(advance|anchor|unicode)\s+([^>]+)>)') _ufo2AnchorPattern = re.compile(rb"\s+(]+move[^>]+name[^>]+>)\s+") _unicodeAttributeGLIFPattern = re.compile(rb'hex\s*=\s*\"([0-9A-Fa-f]+)\"') +_widthAttributeGLIFPattern = re.compile(rb'width\s*=\s*\"([0-9A-Fa-f]+)\"') -def fetchCharacterMappingAndAnchors(glyphSet, ufoPath, glyphNames=None, ufo2=False): +def fetchGlyphInfo(glyphSet, ufoPath, glyphNames=None, ufo2=False): # This seems about 2.3 times faster than reader.getCharacterMapping() + widths = {} cmap = {} # unicode: glyphName revCmap = {} anchors = {} # glyphName: [(anchorName, x, y), ...] @@ -86,12 +88,13 @@ def fetchCharacterMappingAndAnchors(glyphSet, ufoPath, glyphNames=None, ufo2=Fal if b"