Skip to content

Instantly share code, notes, and snippets.

@anthrotype
Created September 14, 2023 10:30
Show Gist options
  • Save anthrotype/0e38f08a23eaa5d91cf870a8339aa3e0 to your computer and use it in GitHub Desktop.
Save anthrotype/0e38f08a23eaa5d91cf870a8339aa3e0 to your computer and use it in GitHub Desktop.
sample_mark_mkmk_features.py
from ufo2ft.featureWriters.markFeatureWriter import MarkFeatureWriter
from fontTools.feaLib.ast import FeatureFile
from ufoLib2 import Font
fea = FeatureFile()
font = Font()
a = font.newGlyph("a")
a.appendAnchor({"name": "top", "x": 500, "y": 600})
a.appendAnchor({"name": "bottom", "x": 500, "y": -100})
b = font.newGlyph("b")
b.appendAnchor({"name": "bottom", "x": 400, "y": -50})
acutecomb = font.newGlyph("acutecomb")
# matching mark anchor prefixed with "_"
acutecomb.appendAnchor({"name": "_top", "x": 300, "y": 700})
# oh look, we have a mark-to-mark! We can stack acute marks on top of one another
acutecomb.appendAnchor({"name": "top", "x": 400, "y": 900})
brevecomb = font.newGlyph("brevecomb")
brevecomb.appendAnchor({"name": "_top", "x": 250, "y": 650})
ogonekcomb = font.newGlyph("ogonekcomb")
ogonekcomb.appendAnchor({"name": "_bottom", "x": 400, "y": 0})
# mark-to-mark ogoneks?! why not
ogonekcomb.appendAnchor({"name": "bottom", "x": 380, "y": -300})
writer = MarkFeatureWriter()
writer.write(font, fea)
print(fea)
"""
markClass ogonekcomb <anchor 400 0> @MC_bottom;
markClass acutecomb <anchor 300 700> @MC_top;
markClass brevecomb <anchor 250 650> @MC_top;
feature mark {
lookup mark2base {
pos base a
<anchor 500 -100> mark @MC_bottom
<anchor 500 600> mark @MC_top;
pos base b
<anchor 400 -50> mark @MC_bottom;
} mark2base;
} mark;
feature mkmk {
lookup mark2mark_bottom {
@MFS_mark2mark_bottom = [ogonekcomb];
lookupflag UseMarkFilteringSet @MFS_mark2mark_bottom;
pos mark ogonekcomb
<anchor 380 -300> mark @MC_bottom;
} mark2mark_bottom;
lookup mark2mark_top {
@MFS_mark2mark_top = [acutecomb brevecomb];
lookupflag UseMarkFilteringSet @MFS_mark2mark_top;
pos mark acutecomb
<anchor 400 900> mark @MC_top;
} mark2mark_top;
} mkmk;
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment