Java 蜡染-如何找到TextNode的“填充”颜色?
我正在尝试使用Batik执行SVG转换,并且一切正常,只是我似乎无法找到原始SVG文档的fill属性值存储在Batik TextNode元素的何处。因此,在我的SVG中,我有以下内容:Java 蜡染-如何找到TextNode的“填充”颜色?,java,svg,batik,Java,Svg,Batik,我正在尝试使用Batik执行SVG转换,并且一切正常,只是我似乎无法找到原始SVG文档的fill属性值存储在Batik TextNode元素的何处。因此,在我的SVG中,我有以下内容: <text x="276.1875" y="120.390625" text-anchor="middle" font="10px "Arial"" stroke="none" fill="#ffffff" style="-webkit-tap-highlig
<text x="276.1875" y="120.390625" text-anchor="middle" font="10px "Arial""
stroke="none" fill="#ffffff" style="-webkit-tap-highlight-color: rgb(0, 0, 0); text-anchor: middle; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 10px; line-height: normal; font-family: Arial;"
font-size="10px" font-family="Arial">
<tspan dy="3.5" >Proportion </tspan>
</text>
public void paint(TextNode node, Graphics2D g2d )
{
AttributedCharacterIterator aci = node.getAttributedCharacterIterator();
Paint colourInfo = (Paint)aci.getAttribute(TextAttribute.FOREGROUND); //null
Paint bgInfo = (Paint)aci.getAttribute(TextAttribute.BACKGROUND); //null
// do actual painting
}
事实上,通过TextAttribute和GVT自定义文本属性,我可以找到与颜色相关的大多数属性都返回空值。aci对象确实有一个非空属性列表,但我无法从调试器中找出键是什么,因为它们都是在属性列表中设置的
Graphics2D对象的现有paint属性通常设置为它刚刚绘制的块的颜色,这意味着如果我不更改内容,我只会使所有文本显示为与背景相同的颜色,从而使其难以阅读
如何找到原始SVG中提供的这些文本节点的颜色?据了解,TextNode分为TextRun,在TextRun中,您可以访问AttributedCharacterIterator的PAINT\u INFO属性,如下所示:
AttributedCharacterIterator runaci = textRun.getACI();
char c = runaci.first();
TextPaintInfo tpi = (TextPaintInfo) runaci.getAttribute(PAINT_INFO);
if ( tpi == null || !tpi.visible )
{
return y;
}
g2d.setPaint(tpi.fillPaint);
TextPaintInfo包含原始SVG中与显示文本相关的数据