我想使用 Java 将 SVG 转换为 PNG/JPG,大多数结果都指向使用 Batik。
但是,我遇到的问题是 Batik 似乎不能很好地处理 CSS 样式功能。
这是我正在尝试转换的示例 SVG:
<svg xmlns="http://www.w3.org/2000/svg" class="graphdiagram" viewBox="-642.5 -415 1285 830">
<g class="layer relationships"/>
<g class="layer nodes">
<circle class="node node-id-0" r="19.7810942818944" fill="rgb(247, 247, 249)" stroke="rgba(0, 0, 0, 0.298039)" stroke-width="0.909091px" cx="0" cy="0"/>
<g class="caption">
<text class="caption node" text-anchor="middle" alignment-baseline="central" x="0" y="0" fill="rgb(51, 51, 51)" font-size="14px" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif">Foo</text>
</g>
</g>
<g class="layer properties"/>
<g class="layer overlay">
<circle class="node overlay" r="20.235639781894402" stroke="none" fill="rgba(255, 255, 255, 0)" cx="0" cy="0"/>
<circle class="node ring" r="25.235639781894402" fill="none" stroke="rgba(255, 255, 255, 0)" stroke-width="10px" cx="0" cy="0"/>
</g>
</svg>
batik 会抛出如下错误:
ERROR: null
Enclosed Exception:
http://www.w3.org/2000/svg:
The attribute "stroke" represents an invalid CSS value ("rgba(0, 0, 0, 0.298039)").
Original message:
The "stroke" property does not support function values.
***** CSSEngine: exception property.syntax.error:org.w3c.dom.DOMException: The "stroke" property does not support function values.
AttrValue:rgba(0, 0, 0, 0.298039)
有没有一种简单的方法可以让 Batik 与 CSS3 语法很好地配合 - 或者我是否要编写一个解析函数来手动设置笔画不透明度等?
最佳答案
如果 Batik 不支持 rgba 颜色值,则可以根据需要使用 lines-opacity
和/或 fill-opacity
作为解决方法。
所以代替:
stroke="rgba(0, 0, 0, 0.298039)"
您可以使用:
stroke="rgb(0, 0, 0)" stroke-opacity="0.298039"
关于css - 有没有办法让 Batik 与 CSS3 样式兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37783282/