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

[anchor_propagation] fix issue adjusting mark component anchor #975

Merged
merged 3 commits into from
Feb 2, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions Lib/glyphsLib/builder/anchor_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,33 @@ def _componentAnchorFromLib(_glyph, _targetComponent):
and _anchorLib["name"] == _targetComponent.baseGlyph
and _anchorLib["index"] == _glyph.components.index(_targetComponent)
):
return _anchorLib["anchor"]
return _anchorLib["anchor"] or None
return None


def _adjust_anchors(anchor_data, ufo, parent, component):
"""Adjust anchors to which a mark component may have been attached."""
glyph = ufo[component.baseGlyph]
anchor_names = {a.name for a in glyph.anchors}
t = Transform(*component.transformation)
_componentAnchor = _componentAnchorFromLib(parent, component)
for anchor in glyph.anchors:
component_anchor = _componentAnchorFromLib(parent, component)
# ignore the component's named anchor if we don't have it
if component_anchor not in anchor_data:
component_anchor = None
# For each base anchor in the mark component glyph
for anchor in (a for a in glyph.anchors if not a.name.startswith("_")):
# adjust either if component is attached to a specific named anchor
# (e.g. top_2 for a ligature glyph)
# rather than to the standard anchors (top/bottom)
if _componentAnchor and _componentAnchor in anchor_data:
anchor_data[_componentAnchor] = t.transformPoint((anchor.x, anchor.y))
if (
component_anchor
and component_anchor.startswith(anchor.name + "_")
and "_" + anchor.name in anchor_names
):
anchor_data[component_anchor] = t.transformPoint((anchor.x, anchor.y))
# ... or this anchor has data and the component also contains
# the associated mark anchor (e.g. "_top" for "top") ...
elif anchor.name in anchor_data and any(
a.name == "_" + anchor.name for a in glyph.anchors
):
elif anchor.name in anchor_data and "_" + anchor.name in anchor_names:
anchor_data[anchor.name] = t.transformPoint((anchor.x, anchor.y))


Expand Down
8 changes: 4 additions & 4 deletions tests/data/AnchorPropagation.glyphs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,13 +1371,13 @@ layers = (
{
anchors = (
{
name = top;
position = "{129, 252}";
},
{
name = _top;
position = "{130, -70}";
},
{
name = top;
position = "{129, 252}";
}
);
components = (
{
Expand Down
Loading