-
Notifications
You must be signed in to change notification settings - Fork 219
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
Image rendered before all required webfonts are loaded #166
Comments
Thanks, very interesting find. What I can reproduce:
This reminds me of an old problem we used to have with rendering images reliably. Initially both Firefox and WebKit had problems, but over time they got fixed. I did not do a good job in tracking the bug(s) I raised for this, so I would have to dig a little. However, I remember vaguely that the HTML5 specification did not design for the case of the data URIs being included in any kind of loading event. For the browser that meant that there was no way of knowing if the SVG (that we are creating internally) was ready to be rendered. If I am correct and the issue we are facing does indeed rely on how the browser renders the SVG to the canvas, then there's nothing we can do directly. Once the library is done compiling the SVG, the browser is responsible for painting. That said, there might be some room for a clever work around. |
Here's the issue I just mentioned for Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=789249. I might have not filed any against Chrome/WebKit back then. |
Thanks for taking a look, @cburgmer. We're currently getting around this by explicitly loading the fonts as base64 encoded strings (https://gist.github.com/stefanmaric/a5043c0998d9fc35483d) rather than having the browser fetch them on demand. Not a clever work around, but a work around. |
This is interesting. Either you are taping into specific browser behaviour
or I haven't fully understood the problem.
If you look at the intermediate SVG that this library generates (get it via
'.then' handler) then both your approaches should give you the exact same
source. Any URL will be fetched and inlined as dataURI. So your second
approach is just shortcutting this.
The only way I can explain this is that the browser will have already seen
the dataURI in approach #2 hence immediately have a handle on the rendering.
|
To add another data point. Generally loading a webfont into a canvas works, as this is covered by the integration test (https://github.com/cburgmer/rasterizeHTML.js/blob/master/test/manualIntegrationTestForWebkit.html). |
I have faced the same issue.
However, these don't work at all on Safari 12-13. I tried to merge old As a workaround, delaying
(rasterizeHTML.js 1.3.0) Added on 2019/10/15 13:32 (UTC): (Combining Canvas.drawImage() delay) with old c3c04a1#diff-acf7a42b742684614a3809fea6629faaL796
Added on 2019/10/15 14:48 (UTC): About Web fonts, workarounds above improve canvas rendering a bit but still unstable... |
We're seeing problems when multiple versions/character sets of a webfont are required. In this case the text with the superscript and the Japanese text are not rendered, likely because the font has not been loaded in time.
Is it possible to detect when all fonts have been loaded?
Test case
Open https://jsfiddle.net/urmeo3du/8/
Expected
See "HEADER 67ᵗʰ 浜崎あゆみ TEXT" repeated (once as HTML, once rendered on canvas)
Result
"HEADER TEXT" is displayed
Note
You may have to disable cache (eg, keeping the console open) when running the test. Also, subsequent runs of the test may render correctly.
(otherwise, this library is working great; thanks for making it available)
The text was updated successfully, but these errors were encountered: