typemytype / drawbot

http://www.drawbot.com
Other
398 stars 61 forks source link

[VF] Script fails with KeyError: 'NSCTVariationAxisName' #485

Closed rsms closed 1 year ago

rsms commented 1 year ago

When trying to use a variable font, I get the following error: KeyError: 'NSCTVariationAxisName'

Repro font: Inter.var.ttf.zip

Repro script:

fill(1,1,1)
rect(0, 0, width(), height())
fill(0,0,0)
t = FormattedString(
    font="Inter.var.ttf",
    fontSize=32,
    fontVariations={"wght":400})
t.append("hello")
path = BezierPath()
path.text(t, (width()/2,height()/2))
path.removeOverlap()
drawPath(path)

Error output

Traceback (most recent call last):
  File "vfbug1.py", line 7, in <module>
  File "drawBot/drawBotDrawingTools.pyc", line 1893, in FormattedString
  File "drawBot/context/baseContext.pyc", line 1095, in __init__
  File "drawBot/context/baseContext.pyc", line 1103, in _setAttribute
  File "drawBot/context/baseContext.pyc", line 1610, in fontVariations
  File "drawBot/context/baseContext.pyc", line 1627, in listFontVariations
  File "drawBot/misc.pyc", line 374, in wrapper
  File "drawBot/context/tools/variation.pyc", line 42, in getVariationAxesForFont
  File "objc/_convenience_mapping.pyc", line 18, in __getitem__objectForKey_
  File "objc/_convenience.pyc", line 113, in container_unwrap
KeyError: 'NSCTVariationAxisName'
justvanrossum commented 1 year ago

The problem is that the font doesn't contain the name table IDs that the fvar axes refer to.

The solution is that DrawBot should fall back to the tag in this case.