Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip markFeatureWriter: only allow Nonspacing Marks to be classified as GDEF marks #392

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Lib/ufo2ft/featureWriters/markFeatureWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand Down