mwshinn / CanD

6 stars 3 forks source link

Intermittently occuring font-related error #2

Closed jbburt closed 4 years ago

jbburt commented 4 years ago

Max,

I'm wondering if you can help me diagnose an issue that may or may not be idiosyncratic. I sometimes (but not always) get a font-related RuntimeError when using Canvas. I think I've found the source of the error but I'm not sure how to fix it.

Sometimes when I run a script that uses Canvas, the following statement is printed to console when writing the figure to file:

/System/Library/Fonts/Helvetica.ttc normal 7 normal roman

while other times, the following statement is printed to console:

/Library/Fonts/Helvetica.ttf normal 7 normal roman

In the latter case, the file is written successfully. In the former case, the message "The PDF backend does not currently support the selected font." is written to console followed by "RuntimeError: TrueType font is missing table". These two scenarios occur while running the exact same script. I confirmed that the PDF backend being used (module://backend_interagg) is the same in both scenarios. I don't understand how the location of the font on my file system is determined under the hood or why it randomly varies across repeated iterations.

Any advice?

mwshinn commented 4 years ago

Thanks for the bug report!

So basically, the matplotlib font engine is really buggy and nondeterministic. So when you search for a Helvetica font, it will sometimes find the ttc and sometimes find the ttf file, but matplotlib doesn't support ttc files. This has also been a problem with it sometimes finding the wrong font weight (e.g. light vs thin) in large font families. One workaround is to install a different version of Helvetica as a ttf such that there is only one version by that name, e.g. Helvetica Neue or Helvetica Now. Then, it will be unambiguous to the Matplotlib font engine.

I am looking into solutions for this, whether that is by trying to rewrite the matplotlib font manager and submit a patch to them, or just find another package to manage fonts internally to canvas and then link that in with matplotlib. I will keep you posted.

jbburt commented 4 years ago

Thanks!

mwshinn commented 4 years ago

Let's keep this open for now, then I can close it when I find a better way to deal with fonts.

mwshinn commented 4 years ago

I implemented a new font manager. I haven't tested it yet as extensively as I would like, but the functionality is now present. Note that this changes the interface a bit, so you probably don't want to convert over to this new version until the first official release. (The interface might change more before the first official release.)

jbburt commented 4 years ago

Awesome, thanks!