Skip to content

Commit

Permalink
Add option to *not* group mark classes within same mark lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed Nov 14, 2023
1 parent efb4658 commit 7ffaae8
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions Lib/ufo2ft/featureWriters/markFeatureWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,15 @@ class MarkFeatureWriter(BaseFeatureWriter):
If the `quantization` argument is given in the filter options, the resulting
anchors are rounded to the nearest multiple of the quantization value.
Mark-to-base or mark-to-ligature attachments that reference non-overlapping
mark classes get grouped in the same lookup. If a mark glyph is in more than
one mark class, then additional lookups are generated for those as required.
If you prefer to have as many mark-to-base and mark-to-liga lookups as there
are mark classes, you can disable this with `groupMarkClasses=False`.
"""

options = dict(quantization=1)
options = dict(quantization=1, groupMarkClasses=True)

tableTag = "GPOS"
features = frozenset(["mark", "mkmk", "abvm", "blwm"])
Expand Down Expand Up @@ -546,12 +552,24 @@ def _groupAttachments(self, attachments):
# through different anchor names, we may have to split the attachment
# into two attachments, using null anchors instead of one or the other
# mark class in each split attachment.
markGlyphToMarkClasses = defaultdict(set)
for attachment in attachments:
for markGlyph, markClasses in attachment.getMarkGlyphToMarkClasses():
markGlyphToMarkClasses[markGlyph].update(markClasses)
groupedMarkClasses = self._groupMarkClasses(markGlyphToMarkClasses)
self._logIfAmbiguous(attachments, groupedMarkClasses)
if self.options.groupMarkClasses:
markGlyphToMarkClasses = defaultdict(set)
for attachment in attachments:
for markGlyph, markClasses in attachment.getMarkGlyphToMarkClasses():
markGlyphToMarkClasses[markGlyph].update(markClasses)
groupedMarkClasses = self._groupMarkClasses(markGlyphToMarkClasses)
self._logIfAmbiguous(attachments, groupedMarkClasses)
else:
# this will generate one lookup per mark class, and sort them
# lexicographically by the anchor name, so the lookup for e.g.
# '_top.alt01' will occur *after* the one for `_top` (the last wins) thus
# allowing some degree of control on potentially ambiguous attachments
# https://github.com/googlefonts/ufo2ft/issues/762
# https://github.com/googlefonts/ufo2ft/issues/591
groupedMarkClasses = [
[markClass.name]
for _, markClass in sorted(self.context.markClasses.items())
]
lookups = []
for markClasses in groupedMarkClasses:
lookup = []
Expand Down

0 comments on commit 7ffaae8

Please sign in to comment.