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

glyphsLib failing to add Italic Angle if metric isn’t already in a master ("ValueError: 'italic angle' is not in list") #998

Open
arrowtype opened this issue Apr 11, 2024 · 2 comments

Comments

@arrowtype
Copy link

I’m attempting to use glyphsLib to set the Italic Angle in masters of a Glyphs source. It seems to work if that metric is already in the masters, but it fails to add it if it doesn’t yet exist.

My code is basically this:

from glyphsLib import GSFont

path = "path/to/glyphs/font.glyphs"

font = GSFont(path)

for master in font.masters:
    master.italicAngle = angle

font.save(path)

However, when I run it, I get the following traceback:

Traceback (most recent call last):
  File "/Users/stephennixon/type-repos/VintageVoyageDesign/../font-tools/set-glyphs-italic-angle.py", line 37, in <module>
    main()
  File "/Users/stephennixon/type-repos/VintageVoyageDesign/../font-tools/set-glyphs-italic-angle.py", line 29, in main
    master.italicAngle = angle
    ^^^^^^^^^^^^^^^^^^
  File "/Users/stephennixon/.pyenv/versions/3.11.3/lib/python3.11/site-packages/glyphsLib/classes.py", line 1907, in italicAngle
    self._set_metric("italic angle", value)
  File "/Users/stephennixon/.pyenv/versions/3.11.3/lib/python3.11/site-packages/glyphsLib/classes.py", line 1782, in _set_metric
    metricIndex = metricLabels.index(metricname)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: 'italic angle' is not in list

This is surprising, as it looks like glyphsLib does try to add a metric if it doesn’t yet exist:

if metricname not in metricLabels:
self.font.metrics.append(GSMetric(type=metricname))
metricIndex = metricLabels.index(metricname)

If I manually add the "Italic Angle" metric using the GlyphsApp UI, the script then does work, but this then defeats the purpose of the script.

Am I doing something wrong? E.g. is it intended that my glyphsLib script should be adding that metric if it doesn’t yet exist? Or, am I interpreting it correctly that glyphsLib is trying but failing to add it, for some reason?

Thanks so much for taking a look and sharing any insights here!

@anthrotype
Copy link
Member

looks like a bug:

metricLabels = [x.type for x in metrics]
if metricname not in metricLabels:
self.font.metrics.append(GSMetric(type=metricname))
metricIndex = metricLabels.index(metricname)

 metricLabels = [x.type for x in metrics] 
 if metricname not in metricLabels: 
     self.font.metrics.append(GSMetric(type=metricname)) 
+    metricLabels.append(metricname)
  metricIndex = metricLabels.index(metricname) 

@schriftgestalt
Copy link
Collaborator

This is working in the Glyphs3 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants