Skip to content

Commit 46c9bf7

Browse files
committed
[propagate_anchors] Fix propagating cursive anchors
Cursive anchors begin with “entry”/“exit” not end with it. This does not matter for the common case where the anchor name is only “entry” or “exit”, but it breaks if the anchor name has a suffix.
1 parent bcf3fb4 commit 46c9bf7

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
@@ -198,13 +198,13 @@ def anchors_traversing_components(
198198
comb_has_underscore = any(
199199
len(a.name) >= 2 and a.name.startswith("_") for a in anchors
200200
)
201-
comb_has_exit = any(a.name.endswith("exit") for a in anchors)
201+
comb_has_exit = any(a.name.startswith("exit") for a in anchors)
202202
if not (comb_has_underscore or comb_has_exit):
203203
# delete exit anchors we may have taken from earlier components
204204
# (since a glyph should only have one exit anchor, and logically its
205205
# at the end)
206206
all_anchors = {
207-
n: a for n, a in all_anchors.items() if not n.endswith("exit")
207+
n: a for n, a in all_anchors.items() if not n.startswith("exit")
208208
}
209209

210210
component_transform = Transform(*component.transform)
@@ -214,7 +214,7 @@ def anchors_traversing_components(
214214
if (component_idx > 0 or has_underscore) and new_has_underscore:
215215
continue
216216
# skip entry anchors on non-first glyphs
217-
if component_idx > 0 and anchor.name.endswith("entry"):
217+
if component_idx > 0 and anchor.name.startswith("entry"):
218218
continue
219219

220220
new_anchor_name = rename_anchor_for_scale(anchor.name, xscale, yscale)
@@ -223,8 +223,8 @@ def anchors_traversing_components(
223223
and component_number_of_base_glyphs > 0
224224
and not new_has_underscore
225225
and not (
226-
new_anchor_name.endswith("exit")
227-
or new_anchor_name.endswith("entry")
226+
new_anchor_name.startswith("exit")
227+
or new_anchor_name.startswith("entry")
228228
)
229229
):
230230
# dealing with marks like top_1 on a ligature
@@ -256,7 +256,7 @@ def anchors_traversing_components(
256256
not is_ligature
257257
and number_of_base_glyphs == 0
258258
and not name.startswith("_")
259-
and not (name.endswith("exit") or name.endswith("entry"))
259+
and not (name.startswith("exit") or name.startswith("entry"))
260260
and "_" in name
261261
):
262262
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
@@ -830,3 +830,57 @@ def test_propagate_anchors_after_aligining_alternates(test_file):
830830
assert alt_bottom.name == master_bottom.name == "bottom"
831831
assert tuple(alt_bottom.position) == (329, 0)
832832
assert tuple(master_bottom.position) == (301, 0)
833+
834+
835+
def test_entry_anchor_on_non_first_component():
836+
glyphs = (
837+
GlyphSetBuilder()
838+
.add_glyph(
839+
"part1",
840+
lambda glyph: (glyph.add_anchor("top", (10, 0))),
841+
)
842+
.add_glyph(
843+
"part2",
844+
lambda glyph: (glyph.add_anchor("entry.2", (10, 0))),
845+
)
846+
.add_glyph(
847+
"combo",
848+
lambda glyph: (
849+
glyph.add_component("part1", (0, 0)).add_component("part2", (100, 0))
850+
),
851+
)
852+
.build()
853+
)
854+
propagate_all_anchors_impl(glyphs)
855+
856+
new_glyph = glyphs["combo"]
857+
assert_anchors(new_glyph.layers[0].anchors, [("top", (10, 0))])
858+
859+
860+
def test_cursive_anchors_ligature():
861+
glyphs = (
862+
GlyphSetBuilder()
863+
.add_glyph(
864+
"part1_part2",
865+
lambda glyph: (
866+
glyph.add_anchor("entry.1", (10, 0)).add_anchor("exit.1", (100, 0))
867+
),
868+
)
869+
.add_glyph(
870+
"combo",
871+
lambda glyph: (
872+
glyph.set_subCategory("Ligature").add_component("part1_part2", (0, 0))
873+
),
874+
)
875+
.build()
876+
)
877+
propagate_all_anchors_impl(glyphs)
878+
879+
new_glyph = glyphs["combo"]
880+
assert_anchors(
881+
new_glyph.layers[0].anchors,
882+
[
883+
("entry.1", (10, 0)),
884+
("exit.1", (100, 0)),
885+
],
886+
)

0 commit comments

Comments
 (0)