Skip to content

Commit

Permalink
[varLib.merger] Support sparse CursivePos
Browse files Browse the repository at this point in the history
Part of #3168
  • Loading branch information
behdad committed Jul 18, 2023
1 parent 56731a9 commit b14a29c
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
24 changes: 24 additions & 0 deletions Lib/fontTools/varLib/merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,30 @@ def _Lookup_SinglePos_subtables_flatten(lst, font, min_inclusive_rec_format):
return [new]


@AligningMerger.merger(ot.CursivePos)
def merge(merger, self, lst):
# Align them
glyphs, padded = _merge_GlyphOrders(
merger.font,
[l.Coverage.glyphs for l in lst],
[l.EntryExitRecord for l in lst],
)

self.Format = 1
self.Coverage = ot.Coverage()
self.Coverage.glyphs = glyphs
self.EntryExitRecord = []
for _ in glyphs:
rec = ot.EntryExitRecord()
rec.EntryAnchor = ot.Anchor()
rec.EntryAnchor.Format = 1
rec.ExitAnchor = ot.Anchor()
rec.ExitAnchor.Format = 1
self.EntryExitRecord.append(rec)
merger.mergeLists(self.EntryExitRecord, padded)
self.EntryExitCount = len(self.EntryExitRecord)


@AligningMerger.merger(ot.Lookup)
def merge(merger, self, lst):
subtables = merger.lookup_subtables = [l.SubTable for l in lst]
Expand Down
57 changes: 56 additions & 1 deletion Tests/varLib/merger_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,7 @@ def test_expandPaintColrLayers(


class SparsePositioningMergerTest:
def test_sparse_positioning_at_default(self):
def test_zero_kern_at_default(self):
# https://github.com/fonttools/fonttools/issues/3111

pytest.importorskip("ufo2ft")
Expand Down Expand Up @@ -1881,3 +1881,58 @@ def test_sparse_positioning_at_default(self):
font.save(b)

assert font["GDEF"].table.VarStore.VarData[0].Item[0] == [100, -100]

def test_sparse_cursive(self):
# https://github.com/fonttools/fonttools/issues/3168

pytest.importorskip("ufo2ft")
pytest.importorskip("ufoLib2")

from fontTools.designspaceLib import DesignSpaceDocument
from ufo2ft import compileVariableTTF
from ufoLib2 import Font

ds = DesignSpaceDocument()
ds.addAxisDescriptor(
name="wght", tag="wght", minimum=100, maximum=900, default=400
)
ds.addSourceDescriptor(font=Font(), location=dict(wght=100))
ds.addSourceDescriptor(font=Font(), location=dict(wght=400))
ds.addSourceDescriptor(font=Font(), location=dict(wght=900))

ds.sources[0].font.newGlyph("a").unicode = ord("a")
ds.sources[0].font.newGlyph("b").unicode = ord("b")
ds.sources[
0
].font.features.text = """
feature curs {
position cursive a <anchor 400 20> <anchor 0 -20>;
} curs;
"""

ds.sources[1].font.newGlyph("a").unicode = ord("a")
ds.sources[1].font.newGlyph("b").unicode = ord("b")
ds.sources[
1
].font.features.text = """
feature curs {
position cursive a <anchor 500 20> <anchor 0 -20>;
position cursive b <anchor 50 22> <anchor 0 -10>;
} curs;
"""

ds.sources[2].font.newGlyph("a").unicode = ord("a")
ds.sources[2].font.newGlyph("b").unicode = ord("b")
ds.sources[
2
].font.features.text = """
feature curs {
position cursive b <anchor 100 40> <anchor 0 -30>;
} curs;
"""

font = compileVariableTTF(ds, inplace=True)
b = BytesIO()
font.save(b)

assert font["GDEF"].table.VarStore.VarData[0].Item[0] == [-100, 0]

0 comments on commit b14a29c

Please sign in to comment.