Skip to content

Commit

Permalink
Merge pull request #649 from googlefonts/ufo2glyphs-preserve-DS-axis-…
Browse files Browse the repository at this point in the history
…order

ufo2glyphs: preserve DS axis order
  • Loading branch information
madig authored Dec 7, 2020
2 parents b0dc84c + 1509654 commit 3d20bdb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
23 changes: 4 additions & 19 deletions Lib/glyphsLib/builder/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,29 +269,14 @@ def font_uses_axis_locations(font):


def to_glyphs_axes(self):
weight = None
width = None
customs = []
axes_parameter = []
for axis in self.designspace.axes:
if axis.tag == "wght":
weight = axis
axes_parameter.append({"Name": axis.name or "Weight", "Tag": "wght"})
elif axis.tag == "wdth":
width = axis
axes_parameter.append({"Name": axis.name or "Width", "Tag": "wdth"})
else:
customs.append(axis)

axes_parameter = []
if weight is not None:
axes_parameter.append({"Name": weight.name or "Weight", "Tag": "wght"})
# TODO: (jany) store other data about this axis?

if width is not None:
axes_parameter.append({"Name": width.name or "Width", "Tag": "wdth"})
# TODO: (jany) store other data about this axis?

for custom in customs:
axes_parameter.append({"Name": custom.name, "Tag": custom.tag})
# TODO: (jany) store other data about this axis?
axes_parameter.append({"Name": axis.name, "Tag": axis.tag})

if axes_parameter and not _is_subset_of_default_axes(axes_parameter):
self.font.customParameters["Axes"] = axes_parameter
Expand Down
15 changes: 11 additions & 4 deletions tests/builder/axes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from fontTools import designspaceLib
from glyphsLib import to_glyphs, to_designspace, to_ufos
from glyphsLib.classes import GSFont, GSFontMaster
from glyphsLib.builder.axes import get_regular_master
from glyphsLib.builder.axes import _is_subset_of_default_axes, get_regular_master

"""
Goal: check how files with custom axes are roundtripped.
Expand All @@ -47,6 +47,10 @@
("IJKL", "Third custom"),
("MNOP", "Fourth custom"),
],
[("opsz", "First custom"), ("wght", "Second custom")],
# Test that standard axis definitions don't generate an Axes custom parameter.
[("wght", "Weight"), ("wdth", "Width")],
[("wdth", "Width"), ("wght", "Weight")],
],
)
def test_weight_width_custom(axes, ufo_module):
Expand All @@ -57,9 +61,12 @@ def test_weight_width_custom(axes, ufo_module):

font = to_glyphs(doc)

assert font.customParameters["Axes"] == [
{"Tag": tag, "Name": name} for tag, name in axes
]
if _is_subset_of_default_axes([{"Name": n, "Tag": t} for t, n in axes]):
assert font.customParameters["Axes"] is None
else:
assert font.customParameters["Axes"] == [
{"Tag": tag, "Name": name} for tag, name in axes
]

doc = to_designspace(font, ufo_module=ufo_module)

Expand Down

0 comments on commit 3d20bdb

Please sign in to comment.