typemytype / drawbot

http://www.drawbot.com
Other
406 stars 63 forks source link

Font path error after upgrading to 3.127 #429

Closed gorjious closed 3 years ago

gorjious commented 3 years ago

Upgraded to 3.127 from 3.126 and now getting this error in a file that was previously working: TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

Is this a bug or any suggestions on how to fix this?

The full error message is this:

*** DrawBot warning: font: 'MyFont-Regular' can't be found, using the fallback font 'LucidaGrande' ***
Traceback (most recent call last):
  File "drawbot_test.py", line 352, in <module>
  File "drawBot/drawBotDrawingTools.pyc", line 1893, in FormattedString
  File "drawBot/context/baseContext.pyc", line 1091, in __init__
  File "drawBot/context/baseContext.pyc", line 1185, in append
  File "drawBot/context/baseContext.pyc", line 1105, in _setAttribute
  File "drawBot/context/baseContext.pyc", line 1433, in font
  File "drawBot/misc.pyc", line 374, in wrapper
  File "drawBot/context/baseContext.pyc", line 2630, in getNSFontFromNameOrPath
  File "genericpath.pyc", line 19, in exists
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
justvanrossum commented 3 years ago

Can you post a complete script that reproduces this? It may be specific to the font. If so: can you share the font?

gorjious commented 3 years ago

I'm thinking it was an issue with absolute vs relative paths. I notice that leaving out the first slash causes this error so that may have been it.

However, I am trying to make a simple example to reproduce it, and am running into an issue that in 3.127 "font can't be found" and it doesn't render but in 3.126 it says "font is not installed" yet it still renders.

Screenshot 2021-07-22 at 16 59 29

What should be the correct way of linking both absolute and relative paths?

drawbot_test.zip

justvanrossum commented 3 years ago

Ah, I think I see what's going on: you should not use the output of font(...) as another input for font(...). Just use the full path throughout (using a variable will make it more managable).

Relative file names are relative to the script's parent folder. So if you use "document_fonts/myfont.otf" there should be a folder called "document_fonts" in the same folder as where the script is saved.

The regression you're seeing is that previously, the font was temporarily installed, and could then be accessed by name (the output of font(...)). That is no longer happening, and you should use the filename/path as the font's identifier.

gorjious commented 3 years ago

Ah okay, that makes sense. Everything works now. Thank you, Just.

justvanrossum commented 3 years ago

font(fontNameOrPath) returns None if fontNameOrPath is neither the name of an installed font, nor an existing font file. Passing None to font(None) gives the same error as your example. I think the None returning case should warn, and passing None to font() should give a better error message.