summaryrefslogtreecommitdiff
path: root/misc/glyphs-scripts/generate-opsz-layers.py
diff options
context:
space:
mode:
authorRasmus <rasmus@notion.se>2022-05-26 21:20:06 +0300
committerGitHub <noreply@github.com>2022-05-26 21:20:06 +0300
commit07960766590650e516a75ce6ceba91b68a5fa551 (patch)
treef0c82cd40cb68950bf8229d14cbc850fec41e5ba /misc/glyphs-scripts/generate-opsz-layers.py
parent633839ad550073f9d12e6cea7964a30523974b68 (diff)
downloadinter-07960766590650e516a75ce6ceba91b68a5fa551.tar.xz
UPM 2048 and opsz axis (#462)
- UPM is adjusted to 2048 - Additional opsz VF axis (multi master) added which will eventually replace the separate Display family - New tooling that uses fontmake instead of Inter's own fontbuild toolchain. (The old toolchain is still supported, i.e. `make -f Makefile_v1.make ...`)
Diffstat (limited to 'misc/glyphs-scripts/generate-opsz-layers.py')
-rw-r--r--misc/glyphs-scripts/generate-opsz-layers.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/misc/glyphs-scripts/generate-opsz-layers.py b/misc/glyphs-scripts/generate-opsz-layers.py
new file mode 100644
index 000000000..11a57a8ef
--- /dev/null
+++ b/misc/glyphs-scripts/generate-opsz-layers.py
@@ -0,0 +1,71 @@
+#MenuTitle: Generate opsz brace layers
+# -*- coding: utf-8 -*-
+import GlyphsApp
+import copy
+
+Font = Glyphs.font
+selectedLayers = Font.selectedLayers
+
+# Glyphs.font.selection - selected glyphs in "Font" tab
+# Glyphs.font.selectedFontMaster
+
+def build_axis_coordinates(g, master):
+ coordinates = {}
+ for i in range(len(g.parent.axes)):
+ axis = g.parent.axes[i]
+ if axis.axisTag == "opsz":
+ coordinates[axis.axisId] = 72
+ else:
+ coordinates[axis.axisId] = master.axes[i]
+ return coordinates
+
+
+def process_glyph(g, axes):
+ print("processing glyph %r" % g.name)
+
+ existing_opsz_layers = {}
+ for layer in g.layers:
+ # print("- %s (%r) %r" % (
+ # layer.name, layer.associatedMasterId, layer.attributes['coordinates']))
+ if layer.attributes['coordinates']:
+ existing_opsz_layers[layer.associatedMasterId] = layer
+ # print("existing_opsz_layers %r" % existing_opsz_layers)
+
+ for master in g.parent.masters:
+ if master.name.startswith("Regular"):
+ # Regular uses dedicated master for opsz
+ continue
+ layer = g.layers[master.id]
+ # print("%s" % layer.name)
+ if master.id in existing_opsz_layers:
+ print("skip layer %s with existing opsz brace layer" % layer.name)
+ continue
+
+ newLayer = layer.copy()
+ # Note: "same name" matters for designspace generation!
+ newLayer.name = "opsz"
+ newLayer.associatedMasterId = master.id
+ newLayer.attributes['coordinates'] = build_axis_coordinates(g, master)
+ g.layers.append(newLayer)
+ print("layer.guides %r" % layer.guides)
+ print("created layer %s (copy of %r)" % (newLayer.name, layer.name))
+
+
+if Glyphs.font and Glyphs.font.selectedLayers:
+ try:
+ Glyphs.font.disableUpdateInterface()
+ glyphs = set([l.parent for l in Glyphs.font.selectedLayers])
+ print(glyphs)
+ axes = {}
+ for i in range(len(Glyphs.font.axes)):
+ axis = Glyphs.font.axes[i]
+ axes[axis.axisTag] = {"index":i, "axis":axis}
+ # print("%r => %r" % (axis.axisTag, axis.axisId))
+ for g in glyphs:
+ try:
+ g.beginUndo()
+ process_glyph(g, axes)
+ finally:
+ g.endUndo()
+ finally:
+ Glyphs.font.enableUpdateInterface()