relative path for fonts triggered CoreText error in terminal
hey all!
let's take the following example:
from drawBot as dB
dB.newDrawing()
dB.newPage(1000, 1000)
dB.font("RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf")
dB.text("hello", (100, 100))
dB.saveImage("hello.pdf")
dB.endDrawing()
it works fine both in the app and from terminal. If, instead, I have the font placed in a folder that I have to access relatively, like this:
from drawBot as dB
dB.newDrawing()
dB.newPage(1000, 1000)
dB.font("../font/RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf")
dB.text("hello", (100, 100))
dB.saveImage("hello.pdf")
dB.endDrawing()
in the terminal, it triggers the following traceback
2022-05-06 12:22:28.246 python[10359:104404] CoreText note: Client requested name "../font/RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf", it will get Times-Roman rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].
2022-05-06 12:22:28.246 python[10359:104404] CoreText note: Set a breakpoint on CTFontLogSystemFontNameRequest to debug.
in the app works fine!
Does it matter which font you use?
Apparently it does not, I tried RobotoFlex and one I am working on, but, they are bot variable fonts
I'll test a few more and report
A static font from Source Serif Pro triggers the same error:
2022-05-06 12:48:21.179 python[10684:119799] CoreText note: Client requested name "../font/Source_Serif_Pro/SourceSerifPro-BoldItalic.ttf", it will get Times-Roman rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].
from the app it works fine
some testing: the “CoreText note" is reproducible with py3.10 pyobjc8.5
it does not happen with py3.7 pyobjc8.5
in both python version a pdf is written with the correct font.
reproducible with python py3.10, not with py3.7...
import AppKit
AppKit.NSFont.fontWithName_size_("../relativePath/font.otf", 10)
instead of trying to retrieve the font by name first, check if the font name is an existing path.
see https://github.com/typemytype/drawbot/blob/5dd8e8781cf80771291c8de2c957b06ec263cfb1/drawBot/context/baseContext.py#L2645-L2664
the problem is that dot prefixed font names are system font and this seems not to be allowed when requesting a font with AppKit.NSFont.fontWithName_size_
other solution: when a fontNameOrPath starts with a "." it must be a path
dot prefixed fonts doesnt work anyhow...