-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Missing fonts in PNG exports #4885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hmm... not sure if this is a bug. |
Certainly looks like a bug to me - thanks for the report @cjacksudo! Did a little poking around - if you ask for an svg download (using My guess is the problem is with this canvas: plotly.js/src/snapshot/toimage.js Line 44 in 5b8b1db
not being appended to the DOM, so it doesn't have access to fonts loaded in the document. Possibly just adding it to the DOM (but putting it offscreen somewhere) would fix the issue? |
Has there been any progress on this? Or is there a temporary work-around? In my case the font isn't even included in svg downloads. |
I just tried the following Codepen and to my surprise, the PNG export does contain the correct font on |
I forked the original Codepen provided in this issue (#4885 (comment)) and replaced
|
@LTribelhorn are you using single quotes? Can you try removing them? See #4885 (comment) for an explanation. |
@antoinerg for what it's worth, I tried your codepen without any luck - the behavior is the same, and the font is not included in the downloaded png. I'm on chrome 86.0.4240.198 |
Thanks @cjacksudo for the quick reply! What is your operating system? Does this one also fail for you: https://codepen.io/antoinerg/pen/pobGgQZ ? |
I'm on macOS (10.15.6). Yeah, I'm seeing the same thing with https://codepen.io/antoinerg/pen/pobGgQZ |
I updated my Codepen to use a dev build of plotly.js which contains a fix. Can someone please confirm it is indeed working on their OS/browser? |
Not working on my machine. |
What's your browser and OS @archmoj ? It works for me both in FF and Chromium on Linux... 😕
Since they are PNG, it shouldn't matter what you use to open them! |
That new codepen still fails for me (Chrome 86 or any other browser, Mac OS 11.0.1) |
Nevermind. It is a |
Still fails for me as well |
It turns out my Codepen was using fonts already installed on my workstation so please disregard my comments above 🤦♂️ The bad news is that we rely on
Therefore, to support custom fonts in SVG/PNG exports via CSS (ultimately the <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
<defs>
<style>
@import url("https://fonts.googleapis.com/css?family=Roboto:400,400i,700,700i");
</style>
</defs>
<style><![CDATA[svg text{stroke:none}]]></style>
<text x="20" y="50" font-family="Roboto">Roboto</text>
</svg> @alexcjohnson is this something we want to support (ie. allow users to specify fonts to embed via some attribute)? |
It would be a bit unfortunate if we needed to require users to explicitly specify these, just to make the downloaded image match what's already in their graph; I was hoping we'd be able to just read out the That sounds like a pain though, and might cause problems in some contexts, so yeah perhaps in the short term we could just accept an option to specify these fonts explicitly. |
@antoinerg Sorry for the late response and thank you very much for your effort. For context: |
EDIT: I see it - confirmed that adding the rule inside of the svg fixes it. |
I still have this issue. MacOS |
While this issue is being resolved, perhaps it should be noted (here and maybe in the documentation as well) that for the png exports to work properly, one should use fonts installed on the system. On Mac OS, what worked for me was looking at what fonts were available in the Font Book. |
Do we have any fix for missing fonts in PNG exports? Any way by which we could override a custom font to image or append anything in the data url generated? @antoinerg |
Hello. I'm running into this exact issue. @antoinerg: Could you elaborate how you did this? I tried adding custom styles with the fonts as data-urls (as mentioned above, maybe I did not get it right) to the svg, but this seems to be ignored by the toImage-function. For different reasons I cannot include fonts hosted on a third party. |
Is there a working workaround for this issue? |
I just ran into this issue. For us the downloaded images had annotations with text that overflowed their containers. I think because the size of the container was calculated with the fonts loaded, but when you download the font aren't there, the text changes size, but the calculation isn't updated. For example: https://ibb.co/fdtWWCL I "fixed" it by making the plot always render with I would be perfectly happy to provide some kind of config that told plotly which fonts to include in the SVG. |
The link is dead. |
Ah yes, sorry about that, I assumed the image board would keep the image around for longer. I could try to re-create the image if that's useful? It was a picture of an annotation where the text was too wide to fit inside its container. |
No thanks :) I can imagine what it could have been. |
How did you put the style inside |
Even though this is a bit of an old issue, I would want to ask about current developments (if there are any). For now, I would be absolutely fine with using a workaround. However, as @ziyuang mentioned before, I don't really understand how I would need to manipulate the html, such that it exports the png with the according custom font. Any assistance would be very much appreciated. |
Safari on macOS 10.14 Mojave or later prohibits using non-default system fonts.
with Firefox, if privacy and security is in Standard mode, the html will render with the local font and the png downloaded will reflect that font.
with Chrome, the html will render with the desired font if the html file is local and the pngs will reflect this, even if you select Don’t allow sites to use fonts installed on your device in Privacy and security>Fonts svgs will reflect the behavior of html rendering based on the browser you open it with. the font styling defined in the plot is reflected in the style argument in certain tags within the svg. so, for example, if you try to use a local font in the html and are using safari and download an svg, if you open the svg in chrome it should render with the font you desired but if you open the svg in Safari it will not. |
Any update on this issue? I am trying font family = Monserrat, even installed it onto my system (Ubuntu 22), but png and SVG exports do not work. Looking for a workaround.. |
Here's an example of a plotly chart with a custom font included:
https://codepen.io/etpinard/pen/jAzVVL
When clicking the "download plot as PNG" option, the downloaded file appears to have a different font than the chart.
Is there something I need to do to make sure that the font is included with the exported image?
The text was updated successfully, but these errors were encountered: