googlefonts / googlefonts/glyphsLib
glyphsLib failing to add Italic Angle if metric isn’t already in a master ("ValueError: 'italic angle' is not in list")
- Dominant language
- Python
- Stars
- 201
- Forks
- 56
- Avg merge
- 17m
- Merged PRs (30d)
- 1
Description
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:
```py
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:
```console
Traceback (most recent call last):
File "/Users/stephennixon/type-repos/VintageVoyageDesign/../font-tools/set-glyphs-italic-angle.py", line 37, in
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:
https://github.com/googlefonts/glyphsLib/blob/e2ebf5b517d59bec0c9437da3a748c58f2999911/Lib/glyphsLib/classes.py#L1780-L1782
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!
Contributor guide
Research direction
Start in Lib/glyphsLib/classes.py at the _set_metric method and the metricLabels handling around the referenced lines. Reproduce the assignment with a source whose masters lack an Italic Angle metric. Done means setting master.italicAngle succeeds and the updated source can be saved without manually adding the metric first.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100