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

Read anchors #41

Merged
merged 6 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 22 additions & 1 deletion src/fontra_glyphs/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import glyphsLib
import openstep_plist
from fontra.core.classes import (
Anchor,
Axes,
Component,
DiscreteFontAxis,
Expand Down Expand Up @@ -345,9 +346,17 @@ def gsLayerToFontraLayer(gsLayer, globalAxisNames):
for gsComponent in gsLayer.components
]

anchors = [
gsAnchorToFontraAnchor(gsAnchor)
for gsAnchor in gsLayer.anchors
]

return Layer(
glyph=StaticGlyph(
xAdvance=gsLayer.width, path=pen.getPath(), components=components
xAdvance=gsLayer.width,
path=pen.getPath(),
components=components,
anchors=anchors
)
)

Expand All @@ -364,6 +373,18 @@ def gsComponentToFontraComponent(gsComponent, gsLayer, globalAxisNames):
return component


def gsAnchorToFontraAnchor(gsAnchor):
ollimeier marked this conversation as resolved.
Show resolved Hide resolved
anchor = Anchor(
name=gsAnchor.name,
x=gsAnchor.position.x,
y=gsAnchor.position.x,
ollimeier marked this conversation as resolved.
Show resolved Hide resolved
# TODO: gsAnchor.orientation -> Type: int
# If the position of the anchor is relaive to the LSB (0), center (2) or RSB (1).
justvanrossum marked this conversation as resolved.
Show resolved Hide resolved
customData=gsAnchor.userData if gsAnchor.userData else dict(),
)
return anchor


def disambiguateLocalAxisName(axisName, globalAxisNames):
return f"{axisName} (local)" if axisName in globalAxisNames else axisName

Expand Down
66 changes: 63 additions & 3 deletions tests/data/GlyphsUnitTestSans3.fontra/glyphs/A^1.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,27 @@
}
]
},
"xAdvance": 753
"xAdvance": 753,
"anchors": [
{
"name": "bottom",
"x": 377,
"y": 377,
"customData": {}
},
{
"name": "ogonek",
"x": 678,
"y": 678,
"customData": {}
},
{
"name": "top",
"x": 377,
"y": 377,
"customData": {}
}
]
}
},
"Light (layer #0)": {
Expand Down Expand Up @@ -155,7 +175,27 @@
}
]
},
"xAdvance": 593
"xAdvance": 593,
"anchors": [
{
"name": "bottom",
"x": 297,
"y": 297,
"customData": {}
},
{
"name": "ogonek",
"x": 548,
"y": 548,
"customData": {}
},
{
"name": "top",
"x": 297,
"y": 297,
"customData": {}
}
]
}
},
"Regular (layer #1)": {
Expand Down Expand Up @@ -222,7 +262,27 @@
}
]
},
"xAdvance": 657
"xAdvance": 657,
"anchors": [
{
"name": "bottom",
"x": 329,
"y": 329,
"customData": {}
},
{
"name": "ogonek",
"x": 591,
"y": 591,
"customData": {}
},
{
"name": "top",
"x": 329,
"y": 329,
"customData": {}
}
]
}
}
},
Expand Down
144 changes: 135 additions & 9 deletions tests/data/GlyphsUnitTestSans3.fontra/glyphs/_part.shoulder.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,21 @@
}
]
},
"xAdvance": 560
"xAdvance": 560,
"anchors": [
{
"name": "_connect",
"x": 250,
"y": 250,
"customData": {}
},
{
"name": "connect",
"x": 530,
"y": 530,
"customData": {}
}
]
}
},
"Bold / LowCrotch (layer #8)": {
Expand Down Expand Up @@ -267,7 +281,21 @@
}
]
},
"xAdvance": 560
"xAdvance": 560,
"anchors": [
{
"name": "_connect",
"x": 250,
"y": 250,
"customData": {}
},
{
"name": "connect",
"x": 530,
"y": 530,
"customData": {}
}
]
}
},
"Bold / NarrowShoulder (layer #7)": {
Expand Down Expand Up @@ -359,7 +387,21 @@
}
]
},
"xAdvance": 560
"xAdvance": 560,
"anchors": [
{
"name": "_connect",
"x": 250,
"y": 250,
"customData": {}
},
{
"name": "connect",
"x": 520,
"y": 520,
"customData": {}
}
]
}
},
"Light (layer #0)": {
Expand Down Expand Up @@ -451,7 +493,21 @@
}
]
},
"xAdvance": 501
"xAdvance": 501,
"anchors": [
{
"name": "_connect",
"x": 117,
"y": 117,
"customData": {}
},
{
"name": "connect",
"x": 411,
"y": 411,
"customData": {}
}
]
}
},
"Light / LowCrotch (layer #4)": {
Expand Down Expand Up @@ -543,7 +599,21 @@
}
]
},
"xAdvance": 501
"xAdvance": 501,
"anchors": [
{
"name": "_connect",
"x": 117,
"y": 117,
"customData": {}
},
{
"name": "connect",
"x": 411,
"y": 411,
"customData": {}
}
]
}
},
"Light / NarrowShoulder (layer #3)": {
Expand Down Expand Up @@ -635,7 +705,21 @@
}
]
},
"xAdvance": 501
"xAdvance": 501,
"anchors": [
{
"name": "_connect",
"x": 117,
"y": 117,
"customData": {}
},
{
"name": "connect",
"x": 381,
"y": 381,
"customData": {}
}
]
}
},
"Regular (layer #1)": {
Expand Down Expand Up @@ -727,7 +811,21 @@
}
]
},
"xAdvance": 528
"xAdvance": 528,
"anchors": [
{
"name": "_connect",
"x": 167,
"y": 167,
"customData": {}
},
{
"name": "connect",
"x": 455,
"y": 455,
"customData": {}
}
]
}
},
"Regular / LowCrotch (layer #6)": {
Expand Down Expand Up @@ -819,7 +917,21 @@
}
]
},
"xAdvance": 528
"xAdvance": 528,
"anchors": [
{
"name": "_connect",
"x": 167,
"y": 167,
"customData": {}
},
{
"name": "connect",
"x": 455,
"y": 455,
"customData": {}
}
]
}
},
"Regular / NarrowShoulder (layer #5)": {
Expand Down Expand Up @@ -911,7 +1023,21 @@
}
]
},
"xAdvance": 528
"xAdvance": 528,
"anchors": [
{
"name": "_connect",
"x": 167,
"y": 167,
"customData": {}
},
{
"name": "connect",
"x": 425,
"y": 425,
"customData": {}
}
]
}
}
}
Expand Down
Loading
Loading