【发布时间】:2016-11-07 16:14:08
【问题描述】:
我正在尝试使用html2canvas.js (https://html2canvas.hertzen.com/) 通过 JavaScript 截取屏幕截图。但是,当页面包含 SVG 文本元素时,我遇到了问题。
正如您在下面的屏幕截图中所见,文本元素是重复的(并且只有一个副本保留了正确的字体系列)。
这是我的代码
HTML
<svg width="600" height="200" style="background-color:lightblue;">
<text transform="translate(100, 100)" style="font-size:60px; font-family: 'Oswald'">Hello world</text>
</svg>
<br/>
<button id="createCanvasButton">Create canvas !</button>
CSS
@import url(//fonts.googleapis.com/css?family=Oswald);
JS
$('#createCanvasButton').on('click', function() {
html2canvas(document.body).then(function(canvas) {
document.body.appendChild(canvas);
});
});
jsFiddle
https://jsfiddle.net/AndreLovichi/571t86u4/
注意
我一直在寻找类似的问题,我发现了这个问题:SVG Text attribute is doubling - HTML2CANVAS。
但是,NodeParser.prototype.getChildren 上的补丁对我不起作用:剩余的文本元素的字体系列错误。
非常感谢!
【问题讨论】:
标签: javascript canvas svg font-face html2canvas