Is 'align center' (non-flowed) text in SVG code possible?

Post about projects that use Inkscape for web design.
Posts: 1
Joined: Thu Mar 21, 2013 9:04 pm

Is 'align center' (non-flowed) text in SVG code possible?

Postby ravinoff » Thu Mar 21, 2013 9:27 pm

Apparently when you 'align center' text in Inkscape with a (non-flowed text) text frame, the alignment information is not saved in the SVG file. Instead, the position is saved which is the result of this alignment, but stripped of the 'align center' (text-anchor: middle) code.

For a webproject which combines several SVG's and layouts them into a PDF by using a PHP library, we would need to keep this alignment information. And this, since we want to replace the text inside the SVG by using code, while keep the text layout centered. Is there any way to do it?

When using flowed text, the alignment information is kept inside the SVG code but the SVG code gets a lot more complex, and the PHP library we use can't handle it anymore. A black frame is shown above the text.

We would like Inkscape to somehow be able to save this kind of code.
<text x="60" y="70" style="text-anchor: middle;">Variable</text>

Is an Inkscape Extension an option?
Or does anybody know of other FLOSS software that can do this?
Or does some Inkscape function exist that I looked over?


Posts: 78
Joined: Sat Nov 06, 2010 11:25 am

Re: Is 'align center' (non-flowed) text in SVG code possible

Postby Jelle » Fri Mar 29, 2013 5:48 pm

Hello Ravinoff,

The text frame used in Inkscape is not part of the SVG 1.1 standard and as such is not saved as SVG code, but as an InkscapeXML extension. Inkscape then can read it, but no other parsers can. SVG 2.0 seems to inherit this format proposed for SVG 1.2 in 2004!!! This why you should convert a flow text to normal text to get the text:anchor: middle; code in your style. SVG 1.1 itself has plenty of tricks that Inkscape can't handle such as SVG fonts, SMIL (nor any other parser I know of supports all of SVG 1.1 completely), but it knows this one.

However, as you are creating SVG from Php script, why not just add an id or class to the text that you insert and set the style in a CSS style sheet? It is both more elegant code wise and leaner on the data transfer. Using javascript you can also select nodes through the DOM and set classes afterwards on the client side. That gives an extra layer of flexibility and isn't all that complex.


Return to “Inkscape & the Web”

Who is online

Users browsing this forum: No registered users and 3 guests