Skip to content

Commit b3612e8

Browse files
authored
Merge pull request #1130 from googlefonts/fix-propagate-cursive-anchors
[propagate_anchors] Fix propagating cursive anchors
2 parents 78b4775 + ab5ec4c commit b3612e8

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

Lib/glyphsLib/builder/transformations/propagate_anchors.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ def anchors_traversing_components(
247247
comb_has_underscore = any(
248248
len(a.name) >= 2 and a.name.startswith("_") for a in anchors
249249
)
250-
comb_has_exit = any(a.name.endswith("exit") for a in anchors)
250+
comb_has_exit = any(a.name.startswith("exit") for a in anchors)
251251
if not (comb_has_underscore or comb_has_exit):
252252
# delete exit anchors we may have taken from earlier components
253253
# (since a glyph should only have one exit anchor, and logically its
254254
# at the end)
255255
all_anchors = {
256-
n: a for n, a in all_anchors.items() if not n.endswith("exit")
256+
n: a for n, a in all_anchors.items() if not n.startswith("exit")
257257
}
258258

259259
component_transform = Transform(*component.transform)
@@ -263,7 +263,7 @@ def anchors_traversing_components(
263263
if (component_idx > 0 or has_underscore) and new_has_underscore:
264264
continue
265265
# skip entry anchors on non-first glyphs
266-
if component_idx > 0 and anchor.name.endswith("entry"):
266+
if component_idx > 0 and anchor.name.startswith("entry"):
267267
continue
268268

269269
new_anchor_name = rename_anchor_for_scale(anchor.name, xscale, yscale)
@@ -272,8 +272,8 @@ def anchors_traversing_components(
272272
and component_number_of_base_glyphs > 0
273273
and not new_has_underscore
274274
and not (
275-
new_anchor_name.endswith("exit")
276-
or new_anchor_name.endswith("entry")
275+
new_anchor_name.startswith("exit")
276+
or new_anchor_name.startswith("entry")
277277
)
278278
):
279279
# dealing with marks like top_1 on a ligature
@@ -305,7 +305,7 @@ def anchors_traversing_components(
305305
not is_ligature
306306
and number_of_base_glyphs == 0
307307
and not name.startswith("_")
308-
and not (name.endswith("exit") or name.endswith("entry"))
308+
and not (name.startswith("exit") or name.startswith("entry"))
309309
and "_" in name
310310
):
311311
suffix = name[name.index("_") + 1 :]

tests/builder/transformations/propagate_anchors_test.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,60 @@ def test_propagate_anchors_after_aligining_alternates(test_file):
861861
assert tuple(master_bottom.position) == (301, 0)
862862

863863

864+
def test_entry_anchor_on_non_first_component():
865+
glyphs = (
866+
GlyphSetBuilder()
867+
.add_glyph(
868+
"part1",
869+
lambda glyph: (glyph.add_anchor("top", (10, 0))),
870+
)
871+
.add_glyph(
872+
"part2",
873+
lambda glyph: (glyph.add_anchor("entry.2", (10, 0))),
874+
)
875+
.add_glyph(
876+
"combo",
877+
lambda glyph: (
878+
glyph.add_component("part1", (0, 0)).add_component("part2", (100, 0))
879+
),
880+
)
881+
.build()
882+
)
883+
propagate_all_anchors_impl(glyphs)
884+
885+
new_glyph = glyphs["combo"]
886+
assert_anchors(new_glyph.layers[0].anchors, [("top", (10, 0))])
887+
888+
889+
def test_cursive_anchors_ligature():
890+
glyphs = (
891+
GlyphSetBuilder()
892+
.add_glyph(
893+
"part1_part2",
894+
lambda glyph: (
895+
glyph.add_anchor("entry.1", (10, 0)).add_anchor("exit.1", (100, 0))
896+
),
897+
)
898+
.add_glyph(
899+
"combo",
900+
lambda glyph: (
901+
glyph.set_subCategory("Ligature").add_component("part1_part2", (0, 0))
902+
),
903+
)
904+
.build()
905+
)
906+
propagate_all_anchors_impl(glyphs)
907+
908+
new_glyph = glyphs["combo"]
909+
assert_anchors(
910+
new_glyph.layers[0].anchors,
911+
[
912+
("entry.1", (10, 0)),
913+
("exit.1", (100, 0)),
914+
],
915+
)
916+
917+
864918
def test_smart_component_anchors():
865919
glyphs = (
866920
GlyphSetBuilder()

0 commit comments

Comments
 (0)