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

[varLib.merger] Support sparse CursivePos #3209

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]