Skip to content

Instantly share code, notes, and snippets.

@justvanrossum
Created September 15, 2022 11:55
Show Gist options
  • Save justvanrossum/66bbb3d5d5a91c428c8c1ca93eef4743 to your computer and use it in GitHub Desktop.
Save justvanrossum/66bbb3d5d5a91c428c8c1ca93eef4743 to your computer and use it in GitHub Desktop.
Likely incomplete script that converts 'statmake' axis labels to DesignSpace 5 axis labels
import argparse
import sys
from fontTools.designspaceLib import AxisLabelDescriptor, DesignSpaceDocument
def main():
parser = argparse.ArgumentParser(
description="Converts statmake axis labels to DesignSpace 5.0 axis labels"
)
parser.add_argument("input", help="The source .designspace file")
parser.add_argument("output", help="The destination .designspace file")
args = parser.parse_args()
doc = DesignSpaceDocument.fromfile(args.input)
if "org.statmake.stylespace" not in doc.lib:
print("No 'org.statmake.stylespace' found in lib, nothing to do")
return
statAxes = doc.lib["org.statmake.stylespace"]["axes"]
del doc.lib["org.statmake.stylespace"]["axes"]
if not doc.lib["org.statmake.stylespace"]:
del doc.lib["org.statmake.stylespace"]
statAxesByTag = {axis["tag"]: axis for axis in statAxes}
for axis in doc.axes:
statAxis = statAxesByTag[axis.tag]
axis.axisLabels = []
for location in statAxis["locations"]:
labelName = location["name"]
labelNames = None
if isinstance(labelName, dict):
labelNames = labelName
labelName = labelName["en"]
if len(labelNames) == 1:
labelNames = None
axisDesc = AxisLabelDescriptor(
name=labelName,
labelNames=labelNames,
userValue=location["value"],
linkedUserValue=location.get("linked_value"),
elidable="ElidableAxisValueName" in location.get("flags", ()),
)
axis.axisLabels.append(axisDesc)
doc.write(args.output)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment