css - 有没有办法让 Batik 与 CSS3 样式兼容?

标签 css svg batik

我想使用 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/

相关文章:

css - 如何为 div 组件添加一个特殊的 CSS 类以仅在 IE 上运行?

d3.js - SVG 元素中的 Latex 数学方程

javascript - Node.JS - Sharp 的 overrideWith() 函数的 SVG 到图像缓冲区?

java - Batik:当我从线程调用 invokeLater 时出现 IllegalStateException

HTML、CSS 和媒体查询 - 在 Chrome 和 Firefox 上调整大小是不同的

javascript - 将带有类 ID 和图像的 div 添加到容器

javascript - SVG水填充动画

java - 使用 batik 将 SVG 文件转换为 PNG,但没有轴线

java - 从 SVG 文件创建非缓冲的 java.awt.Image

html - 使文本像复选框一样