_addName() method fails in “Add STAT” script, starting in FontTools 4.47.2 #3442
-
I have a script that adds a STAT table to variable fonts. This seemed to work well up until just recently. Digging in a bit, I’m finding that it works up to FontTools ~/type-repos/lang-gothic main ✗ 13d15h ⚑ ◒
▶ python sources/01-build-scripts/helpers/add-STAT.py fonts/ArrowType-LangGothic-v0.4/Desktop/Variable
fonts/ArrowType-LangGothic-v0.4/Desktop/Variable/AT-LangGothic-Variable.ttf
<fontTools.ttLib.ttFont.TTFont object at 0x10143ef50>
Traceback (most recent call last):
File "/Users/stephennixon/type-repos/lang-gothic/sources/01-build-scripts/helpers/add-STAT.py", line 127, in <module>
main()
File "/Users/stephennixon/type-repos/lang-gothic/sources/01-build-scripts/helpers/add-STAT.py", line 113, in main
update_fvar(tt)
File "/Users/stephennixon/type-repos/lang-gothic/sources/01-build-scripts/helpers/add-STAT.py", line 95, in update_fvar
instance.postscriptNameID = _addName(nametable, ps_name, 256)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/stephennixon/type-repos/lang-gothic/venv/lib/python3.11/site-packages/fontTools/otlLib/builder.py", line 2892, in _addName
nameTable = ttFont["name"]
~~~~~~^^^^^^^^
TypeError: 'table__n_a_m_e' object is not subscriptable I’m using a script that is closely modeled off of a previous Google Fonts "gen_stat.py" example script, such as is used at https://github.com/googlefonts/literata/blob/0c2761b727a1b3a7cffd313c37f0f5163dfc7a63/sources/v_3.021/gen_stat.py. My guess is, this change occurred at #3406, but I don’t yet understand what exactly is going wrong. I’ll try to dig in a bit further and update this as I learn more, but wanted to log this in case I’m missing something obvious. If there is something obvious (like a deprecated method or something), I’d super appreciate any pointers! Thanks so much. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
that script is using a private function |
Beta Was this translation helpful? Give feedback.
-
Ah, thanks so much for the help! I should have been able to see that, but I really appreciate the help in getting there faster. I'll take a look at whether I can use a public method instead, and if it's not simple, I'll update the args for now. Thanks again! Feel free to close this if there is no issue here. |
Beta Was this translation helpful? Give feedback.
that script is using a private function
_addName
, which changed the type of the first parameter to be a TTFont instance (previously was a name table object). Besides the general recommendation not to use private methods, you can try to change your script so that it passes the font itself to the function