Specifying Text Alignment Within SVG Exports
To avoid confusion, I thought I'd separate out this issue from my previous post about clean SVG text exports.
I'd like my center-aligned text to export from Illustrator to SVG like this:
<text id="example_id" x="329" y="403" text-anchor="middle">Example Text</text>
Unfortunately Illustrator always seems to export it like this:
<text id="example_id" transform="translate(301 403)"><tspan x="0" y="0">Example Text</tspan></text>
So, regardless of whether you've set your text to be left-aligned, center-aligned or right-aligned, Adobe Illustrator always calculates and exports it as left-aligned text that is visually in the correct place.
However we are using the SVGs as part of a UI and we are dynamically changing some text elements to arbitrary user-defined strings - so we need replacement text to be centered too.
Currently I am doing this by manually editing the files to include text-anchor="middle" within the text specification (and changing the X offset accordingly through trial-and-error), but ideally I'd like to find some way to coerce Illustrator to specify text-anchor="middle" for me.
Any ideas?
