我使用的project.exportSVG({asString: true})有非常多的路径(Thousend)。这需要很长时间,有时脚本会冻结。另一方面,project.exportJSON()函数非常快。
我认为这可能是因为exportSVG创建了一个DOM节点,然后生成了一个字符串。因为我只需要字符串,像lite export这样的东西,只要使用字符串就会很棒。有没有办法做到这一点?
我使用SVG-string创建一个Blob并通过https://github.com/eligrey/FileSaver.js/保存它
var svg = project.exportSVG({asString: true});
var blob = new Blob([svg], {type: "image/svg+xml;charset=utf-8"});
saveAs(blob, 'test.svg'); 这是我在http://sketch.paperjs.org上运行的测试脚本
for (var i = 0; i < 1000; i++) {
new Path.Circle({
strokeColor: 'red',
radius: 10,
position: [i, i]
});
}
var t_start, t_end;
t_start = new Date().getTime();
project.exportSVG();
t_end = new Date().getTime();
console.log('svg export: ' + (t_end - t_start));
t_start = new Date().getTime();
project.exportJSON();
t_end = new Date().getTime();
console.log('json export: ' + (t_end - t_start));发布于 2015-10-15 20:24:09
我没有办法解决你的问题,但我可以告诉你原因。看一下这个草图:minimal example,您可以看到export JSON只是纸张数据结构和状态的JSON表示,而SVG需要将纸张输出转换为SVG格式。Jürg在优化转换方面做得很好,所以虽然可能会有一些小的增量收益,但转换不太可能接近纸张数据结构的原始转储。
https://stackoverflow.com/questions/33124061
复制相似问题