BigBadaboom / androidsvg

SVG rendering library for Android
http://bigbadaboom.github.io/androidsvg/
Apache License 2.0
1.21k stars 231 forks source link

Support fonts #285

Open abdelba opened 4 months ago

abdelba commented 4 months ago

I initially created a feature request on Coil library but was redirected here because it uses AndroidSvg internally.

I'm just copy/pasting the initial text below and replace Coil with Android SVG.

Is your feature request related to a problem? Please describe.

Android SVG currently does not support SVG fonts, so they don’t display correctly. This limitation impacts the appearance and functionality of SVG files that use custom SVG fonts.

Describe the solution you'd like

I’d like Android SVG to support SVG fonts so that they render properly. This enhancement would improve the design capabilities and visual fidelity of SVGs that use these fonts.

Additional context

Supporting SVG fonts will make Android SVG more versatile for designers. Here’s a small SVG example using SVG fonts to illustrate the issue:

<svg width="200" height="100" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <font id="MyFont" horiz-adv-x="1000">
      <font-face font-family="MyCustomFont" units-per-em="1000" />
      <glyph unicode="A" d="M100 0 L200 0 L150 100 Z" />
      <glyph unicode="B" d="M100 0 L200 0 L200 100 L100 100 Z" />
    </font>
  </defs>
  <text x="10" y="50" font-family="MyCustomFont" font-size="50">
    AB
  </text>
</svg>

The example defines a simple SVG font with two glyphs ("A" and "B") and uses it in the element. When SVG fonts are supported, this example should render the letters "A" and "B" using the custom shapes defined in the font.

Here’s a screenshot showing the issue with the current rendering in Coil SVG (via AndroidSVG): 351862594-e18095d0-815e-4e8d-b51f-e4967fcb2b99-2

And here’s a screenshot of the correct rendering with SVG font support: Capture d’écran 2024-07-24 à 21 55 59