Batik Creeps Towards 1.5 Release

After being horrifyingly quiet for a long time, the Batik SVG Toolkit has a new version. Beta 5 fixes bugs and adds features. One thing the documentation doesn’t really talk about much (at least anywhere I could find) is how to make use of its extensions for things like text wrapping. With SVG as it was originally there was no way to just wrap multiple lines of text within a space. That made some things that should be easy really, really, hard. That was because you had to figure out on your own where text was supposed to break due to font sizes, line widths, word breaks, etc. rather than leaving it to the rendering engine in your SVG renderer.

But Batik has extensions to add this and some other capabilities. So code that used to look like this:

<!-- Card Text -->
<text x="78" y="570" style="font-family:Times New Roman; font-size:27">
Threshold -- Mystic Zealot gets +1/+1</text>
<text x="78" y="600" style="font-family:Times New Roman; font-size:27">
and has flying. <tspan style="font-style:italic">(You have threshold as</tspan></text>
<text x="78" y="630" style="font-family:Times New Roman; font-size:27">
<tspan style="font-style:italic">long as seven or more cards are in your</tspan></text>
<text x="78" y="660" style="font-family:Times New Roman; font-size:27">
<tspan style="font-style:italic">graveyard.)</tspan></text>
<text x="78" y="700" style="font-family:Times New Roman; font-size:27; font-style:italic">
Nomad youths aspire to one of two roles in</text>
<text x="78" y="730" style="font-family:Times New Roman; font-size:27; font-style:italic">
the tribe: priest or warrior. Their secret</text>
<text x="78" y="760" style="font-family:Times New Roman; font-size:27; font-style:italic">
dream is to become both.</text>

can now look like this:

<!-- Card Text -->
<flowText font-size="27" font-family="Times New Roman" xml:space="preserve" xmlns="http://xml.apache.org/batik/ext">
<flowRegion>
<rect x="68" y="540" width="480" height="258"/>
</flowRegion>
<flowDiv>
<flowPara>Threshold -- Mystic Zealot gets +1/+1 and has flying.
<flowSpan font-style="italic">(You have threshold as long as seven or more cards are in your graveyard.)</flowSpan></flowPara>
<flowPara top-margin="10" font-style="italic">Nomad youths aspire to one of two roles in the tribe: priest or warrior.
Their secret dream is to become both.</flowPara>
</flowDiv>
</flowText>

Now which one would you rather work with? Just be sure to start up the Squiggle SVG browser that comes with Batik using the command “java -jar extensions/batik-squiggle-ext.jar”. If you do you can run the flowText.svg and flowTextAlign.svg files in the samples/extensions directory and they will work correctly. If you specify the regular Squiggle jar file the extensions won’t be loaded and neither of their examples will work.

Advertisements