androidsvg icon indicating copy to clipboard operation
androidsvg copied to clipboard

Support alignment-baseline and dominant-baseline

Open anton-shchyrov opened this issue 3 years ago • 3 comments

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

Library picture

Picture in browser

Browser picture

anton-shchyrov avatar Feb 05 '22 21:02 anton-shchyrov

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..

BigBadaboom avatar Feb 06 '22 08:02 BigBadaboom

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)
   }
}

anton-shchyrov avatar Feb 06 '22 11:02 anton-shchyrov

Yes. Some values could be emulated/approximated.

BigBadaboom avatar Feb 06 '22 11:02 BigBadaboom