Draw SVG on HTML5 Canvas with support for font element

后端 未结 3 2011
甜味超标
甜味超标 2020-12-01 02:08

Is there a good library for converting SVG to HTML canvas that supports the font element? I have already tried canvg, but it does not support Font.

3条回答
  •  暖寄归人
    2020-12-01 02:55

    In case you have the svg embedded into HTML or as a raw source you can use a data URL to convert the svg to a HTML image element which you then can draw on the canvas:

    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);
    

提交回复
热议问题