Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support fonts #285

Open
abdelba opened this issue Jul 25, 2024 · 1 comment
Open

Support fonts #285

abdelba opened this issue Jul 25, 2024 · 1 comment

Comments

@abdelba
Copy link

abdelba commented Jul 25, 2024

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

@BigBadaboom
Copy link
Owner

Hi abdelba

Thanks for the report. Sorry for not answering sooner.

SVG fonts are deprecated. They have been for a long time. Plus files that use them are pretty rare.

So that means this is a very low priority. It is unlikely that AndroidSVG will ever support them. We use Android's built-in APIs to render all text. Supporting SVG fonts would mean I would have to either: :

  • generate a TTF font at run time, or
  • implement copies of all the rendering APIs in order to display any text using the SVG font.

That's quite a lot of extra work for a rare font format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants