update misc/glyphs-scripts/copy-guides.py

This commit is contained in:
Rasmus Andersson 2022-07-07 12:40:50 -07:00
parent bfbf71f0c4
commit 0d2f80760a

View file

@ -1,4 +1,4 @@
#MenuTitle: Copy guides from Regular & Italic to other masters #MenuTitle: Copy global guides from roman to italic masters
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import GlyphsApp import GlyphsApp
import copy import copy
@ -6,38 +6,21 @@ import copy
Glyphs.clearLog() Glyphs.clearLog()
font = Glyphs.font font = Glyphs.font
romanMasterName = "Regular" romanMasters = [m for m in font.masters if m.italicAngle == 0.0]
italicMasterName = "Italic" #print(romanMasters)
guidesRoman = None def find_matching_roman(im):
guidesItalic = None wght = im.axes[0]
opsz = im.axes[2]
for rm in romanMasters:
if wght == rm.axes[0] and opsz == rm.axes[2]:
return rm
guideNames = [ for im in font.masters:
"cap center", # 0 if im.italicAngle == 0.0:
"low center", # 1 continue
"", rm = find_matching_roman(im)
"", if rm is None:
] raise Exception("rm not found (im=%r)" % im.name)
print(im.name, '<-', rm.name)
for master in font.masters: im.guides = [copy.copy(g) for g in rm.guides]
if master.name == "Regular":
guidesRoman = master.guides
if master.name == "Italic":
guidesItalic = master.guides
# rename guides (order is horizontal top to bottom, then vertical)
for i in range(0, len(guidesRoman)):
guidesRoman[i].name = guideNames[i]
guidesItalic[i].name = guideNames[i]
if regularGuides is None:
print("mainMasterName=%r master not found" % mainMasterName)
else:
for master in font.masters:
print(master.name)
if master.name.find("Italic") != -1:
if master.name != guidesItalic:
master.guides = [copy.copy(u) for u in guidesItalic]
else:
if master.name != guidesRoman:
master.guides = [copy.copy(u) for u in guidesRoman]