From de6885ec3d0a8a44744e3ec8ed3677e7209d44ca Mon Sep 17 00:00:00 2001 From: Marc Foley Date: Mon, 6 Jul 2020 15:21:26 +0100 Subject: [PATCH] wip markFeatureWriter: only allow Nonspacing Marks to be classified as GDEF marks --- .../featureWriters/markFeatureWriter.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Lib/ufo2ft/featureWriters/markFeatureWriter.py b/Lib/ufo2ft/featureWriters/markFeatureWriter.py index 125d685f3..e9eb9987e 100644 --- a/Lib/ufo2ft/featureWriters/markFeatureWriter.py +++ b/Lib/ufo2ft/featureWriters/markFeatureWriter.py @@ -8,6 +8,8 @@ from ufo2ft.featureWriters import BaseFeatureWriter, ast from ufo2ft.util import unicodeInScripts, classifyGlyphs from ufo2ft.fontInfoData import getAttrWithFallback +from fontTools.subset import Subsetter +import unicodedata class AbstractMarkPos(object): @@ -257,6 +259,21 @@ def shouldContinue(self): return False return super(MarkFeatureWriter, self).shouldContinue() + def _getNonSpacingMarkGlyphs(self, ttfont): + encoded_mark_glyphs = set() + cmap = ttfont.getBestCmap() + for uni, glyph_name in cmap.items(): + glyph_type = unicodedata.category(chr(uni)) + if glyph_type == "Mn": + encoded_mark_glyphs.add(glyph_name) + + # Get unencoded mark glyphs using fontTools.subset + subsetter = Subsetter() + subsetter.glyph_names_requested = encoded_mark_glyphs + subsetter.options.notdef_glyph = False + subsetter._closure_glyphs(ttfont) + return subsetter.glyphs_retained + def _getAnchorLists(self): gdefClasses = self.context.gdefClasses if gdefClasses.base is not None: @@ -265,6 +282,7 @@ def _getAnchorLists(self): else: # no GDEF table defined in feature file, include all glyphs include = None + nonSpacingMarkGlyphs = self._getNonSpacingMarkGlyphs(self.context.compiler.ttFont) result = OrderedDict() for glyphName, glyph in self.getOrderedGlyphSet().items(): if include is not None and glyphName not in include: @@ -277,6 +295,11 @@ def _getAnchorLists(self): "unnamed anchor discarded in glyph '%s'", glyphName ) continue + if anchorName.startswith("_") and glyphName not in nonSpacingMarkGlyphs: + self.log.warning( + "mark anchor discarded from base glyph '%s'", glyphName + ) + continue if anchorName in anchorDict: self.log.warning( "duplicate anchor '%s' in glyph '%s'", anchorName, glyphName