Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

On the topic of SVG and Canvas, I think it would be really useful if Canvas had a method similar to drawImage but instead could draw svg.

for example

var circle = document.createElementNS("http://www.w3.org/2000/svg, "circle"); circle.setAttribute("style", "fill:green"); circle.setAttribute("cx", 50); circle.setAttribute("cy", 50); circle.setAttribute("r", 25);

ctx.drawSvg(circle,x,y,w,h);

I think then we could have the best of both worlds, define complex shapes in svg, but use canvas for rendering. The advantage over just using svg is that every shape is in the dom, so if you want to draw 1000 similar shapes the dom gets cluttered.



Yes, that'd be very useful as a built-in. In the meantime, you could use a SVG-on-canvas renderer such as:

http://code.google.com/p/canvg/


Some browsers can render images in canvas that are actually SVG files, but support is a bit patchy outside Webkit, and there are some other issues, but may work for you. http://www.svgopen.org/2010/papers/62-From_SVG_to_Canvas_and...


http://jsbin.com/ibuqi5

Looks great in Chrome for me, aliased in Firefox.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: