Skip to content

Commit

Permalink
Send anchor userdata to objectlib (#911)
Browse files Browse the repository at this point in the history
* Allow userData on anchors

* Send anchor userdata to objectlib

* Use object libs, run black

* pyright was being too clever
  • Loading branch information
simoncozens authored Jun 13, 2023
1 parent 5827c1b commit 4e46141
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Lib/glyphsLib/builder/anchors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@


from glyphsLib.types import Point
import uuid

from glyphsLib.builder.constants import OBJECT_LIBS_KEY

__all__ = [
"to_ufo_glyph_anchors",
Expand All @@ -27,6 +30,12 @@ def to_ufo_glyph_anchors(self, glyph, anchors):
for anchor in anchors:
x, y = anchor.position
anchor_dict = {"name": anchor.name, "x": x, "y": y}
if anchor.userData:
identifier = str(uuid.uuid4()).upper()
anchor_dict["identifier"] = identifier
glyph.lib.setdefault(OBJECT_LIBS_KEY, {})[identifier] = dict(
anchor.userData
)
glyph.appendAnchor(anchor_dict)


Expand Down
1 change: 1 addition & 0 deletions Lib/glyphsLib/builder/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

PUBLIC_PREFIX = "public."
GLYPH_ORDER_KEY = PUBLIC_PREFIX + "glyphOrder"
OBJECT_LIBS_KEY = PUBLIC_PREFIX + "objectLibs"

GLYPHS_PREFIX = "com.schriftgestaltung."
GLYPHLIB_PREFIX = GLYPHS_PREFIX + "Glyphs."
Expand Down
7 changes: 7 additions & 0 deletions Lib/glyphsLib/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2830,6 +2830,7 @@ def _serialize_to_plist(self, writer):

def __init__(self, name=None, position=None):
self.name = "" if name is None else name
self._userData = None
if position is None:
self.position = copy.deepcopy(self._defaultsForName["position"])
else:
Expand All @@ -2844,10 +2845,16 @@ def __repr__(self):
def parent(self):
return self._parent

userData = property(
lambda self: UserDataProxy(self),
lambda self, value: UserDataProxy(self).setter(value),
)


GSAnchor._add_parsers(
[
{"plist_name": "pos", "object_name": "position", "converter": Point},
{"plist_name": "userData", "object_name": "_userData", "type": dict},
{"plist_name": "position", "converter": Point},
]
)
Expand Down

0 comments on commit 4e46141

Please sign in to comment.