I am trying to use Batik to perform an SVG conversion and it is going alright except that I can't seem to find out where the value of the fill
attribute for the original SVG document is stored on the Batik TextNode
element. So in my SVG I have the following:
<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>
This works fine, but when I am using my custom TextPainter
( through a generic Bridge ) to try and process the TextNode I find the following:
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
}
In fact most of the attributes relating to colour that I can find looking through the TextAttribute and GVT custom text attributes are coming back null. The aci
object does have a list of non-null attributes but I can't figure out what the keys are from the debugger as they're all keyed off attribute lists.
The existing paint
property of the Graphics2D
object is usually set to the colour of the block that it has just drawn, meaning if I don't change things, I just get all my text appearing the same colour as the background, making it hard to read.
How can I find the colour for these text nodes that they are provided with in the original SVG?
It transpired that the TextNode
is broken up into TextRun
s and within the TextRun
you can access the PAINT_INFO
property of the AttributedCharacterIterator
like this:
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);
The TextPaintInfo
contains the data from the original SVG pertaining to the displayed text.