2014-10-27 18 views
0

我想使用蜡染来执行SVG转换,除了我似乎无法找到原始SVG文档的fill属性的值存储在Batik TextNode元素中的位置之外,它还行。所以在我的SVG我有以下几点:蜡染 - 如何找到TextNode的“填充”颜色?

<text x="276.1875" y="120.390625" text-anchor="middle" font="10px &quot;Arial&quot;" 
     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> 

这工作得很好,但是当我使用我的自定义TextPainter(通过一个普通的桥),试图处理TextNode我发现以下几点:

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自定义文本属性查找的与颜色有关的大多数属性都会返回null。 aci对象确实具有非空属性的列表,但我无法弄清楚调试器中的密钥是什么,因为它们都是属性列表的关键字。

Graphics2D对象的现有paint属性通常设置为刚刚绘制的块的颜色,这意味着如果我不更改内容,我只是让所有文本显示为与背景相同的颜色,使其难以阅读。

如何才能找到它们在原始SVG中提供的这些文本节点的颜色?

回答

0

据报这TextNode被分成TextRun S和TextRun内可以访问AttributedCharacterIteratorPAINT_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数据显示的文字。