views:

38

answers:

2

Hi,

I would like to take a multiline block of text and display it in SVG. I would like to keep the lines as lines. Is there a proper way to do this?

I am using Inkscape for my base drawing and Batik for my rendering. It seems the two do not agree on how to do this.

Inkscape is creating a structure like this:

<flowRoot
       xml:space="preserve"
       id="flowRoot3089"
       style="font-size:16px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
       transform="translate(19.71875,334.88681)">
   <flowRegion id="flowRegion3091">
        <rect id="rect3093" width="50.78125" height="75" x="34.765625" y="155.89932"/>
   </flowRegion>

    <flowPara id="flowPara3123">Item 1</flowPara>
    <flowPara id="flowPara3137">Item 2</flowPara>
    <flowPara id="flowPara3139">Item 3</flowPara>
</flowRoot>

However, this is not acceptable to Batik for some reason.

+1  A: 

This is not acceptable since flow* elements are non-standard elements. It comes from an SVG1.2 draft that has never been accepted and it is designed to wrap text in custom shapes. Only Inkscape and some builds of Opera support it. So, don't use it, at least for the moment.

If you don't need text wrapping (and you don't seem to, but I don't understand what you mean by "I would like to keep the lines as lines"), I suggest you use the basic <text/> element.

Tangui
Opera has never supported the flow* elements. It does however support the SVG Tiny 1.2 textArea element. All this can be seen by the documentation here: http://opera.com/docs/specs
Erik Dahlström
I think you're right @Tangui. The text/tspan technique is awkward as well. I need to create and provide spacing for the tspan elements on the fly adding much complication. (I am inserting the text in Java from Batik. The amount of Text is not know until runtime.)
JeffV
Unfortunately, you can't use XHtml via foreignObject since Batik doesn't support it. You may also use the SVG DOM to get the text length (with the getComputedLength/getStartPositionOfChar/getEndPositionOfChar methods) but I'm not sure this is compatible with your use of Batik.
Tangui
A: 

I'd suggest <text> with <tspan> children. Inkscape can generate that for you quite easily, just don't click and drag an area but instead just click where you want the text and start writing, press return where you want a new line.

Erik Dahlström