Reputation: 3474
I am using canvg in order to render some SVG into an image. Currently SVG to canvas part is working just fine. However I am unable to determine why the generated canvas changes when a pointer enters it. Do I really have to copy the generated canvas, or am I missing something?
svgElement.each(function () {
var canvas = document.createElement("canvas");
//convert SVG into a XML string
var xml = (new XMLSerializer()).serializeToString(this);
// Removing the name space as IE throws an error
xml = xml.replace(/xmlns=\"http:\/\/www\.w3\.org\/2000\/svg\"/, '');
// Rounded svg dimensions
var width = Math.floor(svgElement.width());
var height = Math.floor(svgElement.height());
// Draw the SVG onto a canvas
canvas.width = width;
canvas.height = height;
$(canvas).css('border', '2px solid red');
canvg(canvas, xml, {
ignoreDimensions: true,
scaleWidth: width,
scaleHeight: height
});
$('body').append(canvas); // When pointer enters the canvas it changes
// I can copy the canvas and that copy won't change on pointer enter.
$(this).hide();
}
Verified on Firefox DE 47 and Chrome 49 under MacOS X El Capitan (also my friend verified that this is happening under Windows on both Firefox and Chrome).
Upvotes: 1
Views: 412
Reputation: 136618
You have to use the ignoreMouse
option :
updated fiddle : http://jsfiddle.net/35t6fkvj/7/
canvg(canvas, xml, {
ignoreDimensions: true,
scaleWidth: width,
scaleHeight: height,
ignoreMouse: true
});
Not sure why it thinks it should add some mouse events though
Upvotes: 2