androidsvg
androidsvg copied to clipboard
Support alignment-baseline and dominant-baseline
The library unsupported vertical alignment text
SVG
<?xml version='1.0' encoding='utf-8'?>
<svg height='40' width='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'>
<rect x="0" y="0" width="40" height="40" fill="white" stroke="black"/>
<path d="M 0 20 H 40" stroke="black"/>
<path d="M 20 0 V 40" stroke="black"/>
<text x='20' y='20' text-anchor='middle'
alignment-baseline='middle' dominant-baseline='middle'
font-size='14'>Test</text>
</svg>
The resulting picture
Picture in browser
I'm not sure that this is going to be possible. I don't think the current Android APIs provide a way to control the typeface baseline table..
Maybe support only three values: hanging, middle, baseline? And do it in the same way as an text-anchor
if (anchor != Style.TextAnchor.Start) {
float textWidth = calculateTextWidth(obj);
if (anchor == Style.TextAnchor.Middle) {
x -= (textWidth / 2);
} else {
x -= textWidth; // 'End' (right justify)
}
}
Yes. Some values could be emulated/approximated.

