我正在使用 paper.js(来自 node.js,带有 paper-jsdom 包)创建 SVG 文件,并且我希望使它们尽可能与 Adobe Illustrator 兼容。为此,我尝试重新执行描述的步骤 [here] 。但随后,使用 exportSVG 导出到 SVG函数,我得到了一些完全不同的东西:
paper.js 和 AI 之间的层兼容性似乎不再起作用。那么,我在这里错过了什么吗?是因为我的AI版本(CC 2018)吗?有没有办法绕过这个问题?
最佳答案
我不这么认为Paper.js
SVG 导出与 Illustrator
兼容层模型。
您说这“似乎不再起作用”,但是您是否使其与 Paper.js
的早期版本一起工作?/AI
?
如果没有,我猜您对 Paper.js
中的类比感到困惑。有关其共享层概念的文档。
但这个类比只是因为用户习惯了 AI
层,这使他们能够更好地理解 Paper.js
有效。
由此,我很好奇 AI
是如何做到的能够在 SVG 导出后恢复其图层,以查看您的情况是否有可能的解决方法。
当您导出 AI
时项目为 SVG,您可以选择是否“保留 Illustrator 编辑功能”。
如果不这样做,导出的 SVG 将如下所示:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" id="Calque_1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="1137px" height="937px" viewBox="0 0 1137 937"
enable-background="new 0 0 1137 937" xml:space="preserve">
<g id="Calque_1_1_">
<circle fill="#FF0000" cx="380" cy="238" r="60"/>
</g>
<g id="Calque_2">
<circle fill="#0000FF" cx="569" cy="468" r="60"/>
</g>
</svg>
但是如果您尝试将此 SVG 加载回 AI
,您不会获得 2 个图层,而只会获得一个包含 2 个组的图层(就像使用 Paper.js
导出的 SVG 所做的那样)。
如果您选中“保留 Illustrator 编辑功能”,您将得到截然不同的结果:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
<!ENTITY ns_extend "http://ns.adobe.com/Extensibility/1.0/">
<!ENTITY ns_ai "http://ns.adobe.com/AdobeIllustrator/10.0/">
<!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/">
<!ENTITY ns_vars "http://ns.adobe.com/Variables/1.0/">
<!ENTITY ns_imrep "http://ns.adobe.com/ImageReplacement/1.0/">
<!ENTITY ns_sfw "http://ns.adobe.com/SaveForWeb/1.0/">
<!ENTITY ns_custom "http://ns.adobe.com/GenericCustomNamespace/1.0/">
<!ENTITY ns_adobe_xpath "http://ns.adobe.com/XPath/1.0/">
]>
<svg version="1.0" xmlns:x="&ns_extend;" xmlns:i="&ns_ai;"
xmlns:graph="&ns_graphs;"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1137px"
height="937px"
viewBox="0 0 1137 937" enable-background="new 0 0 1137 937"
xml:space="preserve">
<switch>
<foreignObject requiredExtensions="&ns_ai;" x="0" y="0" width="1"
height="1">
<i:pgfRef xlink:href="#adobe_illustrator_pgf">
</i:pgfRef>
</foreignObject>
<g i:extraneous="self">
<g id="Calque_1">
<circle fill="#FF0000" cx="380" cy="238" r="60"/>
</g>
<g id="Calque_2">
<circle fill="#0000FF" cx="569" cy="468" r="60"/>
</g>
</g>
</switch>
<i:pgf id="adobe_illustrator_pgf">
<![CDATA[
...(huge data skipped)
]]>
</i:pgf>
</svg>
这一次,如果您将其加载回 AI
,您将得到预期的图层。
差异在于 AI
的所有元数据。添加到 SVG 以便将其加载回来,最重要的是 <i:pgf id="adobe_illustrator_pgf">
元素。
有一个thread在 Inskape
中讨论同类问题上下文,看来这个关键数据是一种二进制数据,只有 AI
可以读写。
最后,不幸的是,我认为您或 Paper.js
没有机会可以制作一个映射到 AI
的 SVG 文件内部层模型。
关于node.js - paper.js 和 Adobe Illustrator SVG : layers compatibilty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56757587/