【问题标题】:svg export in paper.js very slowpaper.js 中的 svg 导出非常慢
【发布时间】:2015-10-14 11:25:17
【问题描述】:

我正在使用project.exportSVG({asString: true}) 和大量路径(千)。 这需要很长时间,有时脚本会冻结。 而project.exportJSON() 函数则非常快。

我认为这可能是因为 exportSVG 创建了一个 DOM 节点,然后从中生成了一个字符串。因为我只需要字符串,像只适用于字符串的 lite 导出之类的东西会很棒。 有没有办法做到这一点?

我使用 SVG 字符串创建一个 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));

【问题讨论】:

    标签: performance svg export paperjs


    【解决方案1】:

    我没有适合你的解决方案,但我可以告诉你原因。看看这个草图:minimal example,您可以看到导出 JSON 只是纸张数据结构和状态的 JSON 表示,而 SVG 需要将纸张输出转换为 SVG 格式。 Júrg 在优化转换方面做得非常好,因此虽然可能会有一些小的增量收益,但转换不太可能接近纸质数据结构的原始转储。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-25
      • 2020-07-04
      • 2019-02-26
      • 2023-03-08
      • 2012-09-04
      • 2023-03-06
      • 1970-01-01
      • 2012-11-12
      相关资源
      最近更新 更多