matplotlib-pyodide icon indicating copy to clipboard operation
matplotlib-pyodide copied to clipboard

Attempts to grab fonts from `${origin}/fonts`?

Open josephrocca opened this issue 1 year ago • 5 comments

Using this example that's linked from the official blog post:

https://jsfiddle.net/gh/get/library/pure/pyodide/pyodide-blog/contents/demos/canvas-renderer-matplotlib/demo-1/

It tries and fails to get https://fiddle.jshell.net/fonts/DejaVuSans.ttf. I tried updating it to the lastest version by replacing the script tag with:

<script src="https://cdn.jsdelivr.net/pyodide/v0.25.1/full/pyodide.js"></script>

and swapping this:

matplotlib.use("module://matplotlib.backends.html5_canvas_backend")

for the newer:

matplotlib.use("module://matplotlib_pyodide.html5_canvas_backend")

But the same issue occurs. I'm guessing this is why the pan/zoom buttons of plots aren't the right size, and don't have any text in them, in the example linked above? (and also in the latest version of Pyodide)

josephrocca avatar Apr 30 '24 14:04 josephrocca

Interesting, thanks for the report. Indeed:

_base_fonts_url = "/fonts/"

should probably be changed to:

from pyodide_js._api.config import indexURL

_base_fonts_url = f"{indexURL}/fonts/"

hoodmane avatar Apr 30 '24 17:04 hoodmane

It seems that jsdelivr returns a 403 for this which is another problem.

hoodmane avatar Apr 30 '24 18:04 hoodmane

@MartinKolarik Could you whitelist .ttf files for Pyodide?

hoodmane avatar May 03 '24 08:05 hoodmane

Should be allowed now! If you run into issues with any specific URL, you can purge the cache via https://www.jsdelivr.com/tools/purge

MartinKolarik avatar May 03 '24 12:05 MartinKolarik

Thanks! Now if I patch it like this:

import matplotlib_pyodide.html5_canvas_backend
matplotlib_pyodide.html5_canvas_backend._base_fonts_url = f"{indexURL}fonts/"

it successfully downloads the font from: https://cdn.jsdelivr.net/pyodide/v0.25.1/full/fonts/DejaVuSans.ttf

I cannot tell the difference in the rendered output though. It looks identical to me whether the font download succeeds or fails.

hoodmane avatar May 03 '24 12:05 hoodmane