O'Reilly logo

Java™ Drawing with Apache Batik: A Tutorial by Alexander Kolesnikov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using tspan elements

You can make your text more structured by placing different text fragments into tspan elements and enclosing them with the text element, like this:

<text>
    <tspan>One piece of text</tspan>
    <tspan>Some other text</tspan>
    <tspan>More text</tspan>
</text>

You can assign different attributes to a tspan element. In addition, you can assign common attributes to the text in the tspan elements by placing the attributes in the enclosing text element.

Let us modify our SVG Writer in such a way that it will take the first four words from the entered text and display each of them in a different tspan element, using a different set of attributes.

Since the drawText method will have to be changed significantly, it makes sense to build another ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required