Fabric.loadSVGFromString 导致结果扭曲

2024-03-27

我用 inkscape 编辑了 SVG:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg id="svg2816" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
 <defs id="defs2818"></defs>
 <metadata id="metadata2821">
  <rdf:RDF>
   <cc:Work rdf:about="">
    <dc:format>image/svg+xml</dc:format>
    <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
    <dc:title/>
   </cc:Work>
  </rdf:RDF>
 </metadata>
 <g id="layer1" stroke-linejoin="miter" stroke="#ce3762" stroke-linecap="butt">
  <path id="path2828" style="stroke-dasharray:none;" d="M40,3,35,3,20,18,10,18s-5,5,0,10h10l15,15h5v-40z" transform="translate(-5,0)" stroke-miterlimit="4" stroke-width="0.5" fill="#42101e"/>
  <path id="path2830" d="m37,13s2,7.5359,0,15" transform="translate(0,2)" stroke-width="1px" fill="none"/>
  <path id="path2834" d="m40,11s3,10,0,19" transform="translate(0,2)" stroke-width="1px" fill="none"/>
  <path id="path2836" d="m43,6s6,14,0,29" transform="translate(0,2)" stroke-width="1px" fill="none"/>
 </g>
</svg>

它应该看起来像这样:

当我用 Fabricjs 导入它时:

// volumeOnPrint is the string pasted before
fabric.loadSVGFromString(volumeOnPrint, function(objects, options) {
    var widget = new fabric.PathGroup(objects, options);
    // root is my fabricjs canvas
    root.add(widget);
});

它得到:

(背景不是问题,这是我的画布)


事实证明这是 Fabric 中的一个错误。

I just 修复它并推动 https://github.com/kangax/fabric.js/commit/a83b97a4e47f539c602d43de56ba635ce06ba26e新版本(0.9.21)。

一般来说,使用 Inkscape 创建的 SVG 文件比使用 Illustrator 创建的文件更难解析。但我们正在变得越来越好:)

有一个不断增长的视觉测试套件 http://fabricjs.com/svg_rendering/,我在其中添加了您的形状以避免将来出现回归(如果可以的话请告诉我)。小心,因为加载/解析所有形状可能需要一段时间。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Fabric.loadSVGFromString 导致结果扭曲 的相关文章