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
implement inline SVG rendering #267
Comments
could be implemented like this: var img = new Image();
// here attach an onload handler that draws the image on the canvas
// svgSource is the raw svg xml
img.src = "data:image/svg+xml," + encodeURIComponent(svgSource); |
SVG images taint the canvas in Chrome. https://code.google.com/p/chromium/issues/detail?id=68568 Firefox supported this without tainting the canvas from v11 or 12 onwards. A bugfix landed 6 days ago that addressed it for non |
Oh, thx! Nice to know! But we should implement this without taking care of browser issues. By now svg images didn't get rendered at all. Maybe we should exclude browsers that will "destroy" the canvas when drawing svg images. |
Setting |
Hmmm, how does http://fabricjs.com/ handle it? |
Presumably same way as canvg and the others, by actually rendering SVG elements manually to canvas. |
Fabric.js is open source, can we take the parts to render svg from it? https://github.com/kangax/fabric.js |
I'm not really keen on embedding a library +5x the size of html2canvas just to support SVG images. Alternatively, users who need SVG rendering could use one of those libraries to convert the SVG's to canvas before running html2canvas. Besides, once the bug fix lands in Chrome this issue can be resolved for the majority of browsers by just using the native image rendering implementation. |
Can you add a callback with the svg element to allow users to fallback rendered image using 3rd party tools like canvg? |
FYI, the |
@niklasvh, could you comment on the current plans for inline SVG support? From looking at the code, it appears that inline SVG is only supported when using the build that includes fabric.js ( Is there a reason that fabric.js isn't used as a fallback to native rendering, rather than the primary rendering method? Or is the current implementation just temporary? Given the current wide support, it seems like many common cases would be well covered without the extra overhead and loss of fidelity of using fabric.js. It also appears that the presence of inline SVG, when the build with fabric.js is not used, causes the rendering process to fail. This seems pretty draconian compared to the behavior of 0.4 where unsupported elements were ignored. Developers could certainly wrap all calls to html2canvas with a function to remove any non-critical inline SVG (icons and the like), but that seems sub-optimal. Is there any chance the previous behavior could be made available (as an option, if not by default)? Thanks for all of your effort on this issue! |
If any of the above cases aren't true, then there is a bug in which case could you please provide an example test. Hope that answers your questions |
Hey @niklasvh, thanks for the thorough response, I really appreciate it! Also great to hear that support for partial image loading is being considered. Perhaps I was mistaken about how/when fabric is used. So to demonstrate the issue I created the following plunkr: http://run.plnkr.co/UsnuptYpKe8dPFPG/ It contains a simple inline SVG without a After tracing through the code, it appears that Am I misreading the code or misunderstanding how to use it? Thanks again. |
@kevinoid you are right, that's how it should work. 0a7df6d should fix it. All 4 different forms of svg should work correctly now: |
Thanks @niklasvh! That works great for my use cases. I really appreciate the quick fix! I don't mean to be critical, but it appears that 0a7df6d doesn't check for |
By default, But again, if that's not the case, then there is another bug. Your example is 404. |
I think there's a bug since the example is using the default options. But apparently I can't figure out how to use Plunker correctly (perhaps run.plnkr.co expires pages after a few minutes...). See if this works better: http://plnkr.co/edit/tM0yPWOUSjI4eDmIdvW4 |
I am getting |
Oh, interesting. I am getting |
Still don't understand how it gets past the taint test for you, it should just skip the image altogether. |
Still working on testing with the latest Chromium, but I think I might be able to shed some light on how it gets past the taint test: When |
That would explain it, thanks :) |
Sure thing. I was also able to test on Chromium Version 39.0.2166.0 and it didn't taint the canvas. Awesome! |
I'm trying to use this with Highcharts -> Example: http://jsfiddle.net/wiesson/9pbxode0 (just click on the small print button)- It works perfectly with chrome on my Mac, but how to render the SVG correctly on Windows (Chrome)? If you tell me, how to contribute to your tests, I would like to add some Highcharts tests. |
I'm seeing the same on Chrome/Linux (Debian wheezy, x64), though it looks fine if I remove either one of the inline Not completely sure why this doesn't affect Chrome on Mac, but I'm guessing it's related to #479. In the meantime, I implemented a workaround based on the one suggested in highcharts/highcharts#1428 (comment), which should work on all platforms: http://jsfiddle.net/0p4z1mfj/20/ With the magic sauce being: chart: {
// ...
style: {
fontFamily: 'Verdana, Arial, Helvetica, sans-serif'
}
// ... The default font family starts with |
Can you update my example? |
Updated my comment. |
You are right thanks! Here is another example, now with Highstocks: http://jsfiddle.net/wiesson/1rn51t0g - looks definitly more worse than Highcharts ;) Ok, I found a workaround in issue #95 . |
... to render Ext JS Charts:
http://docs.sencha.com/extjs/4.2.1/extjs-build/examples/charts/Area.html
The text was updated successfully, but these errors were encountered: