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

Trying to render a subscript ends up with bold font #609

Open
hukka opened this issue Apr 6, 2023 · 1 comment
Open

Trying to render a subscript ends up with bold font #609

hukka opened this issue Apr 6, 2023 · 1 comment
Labels

Comments

@hukka
Copy link

hukka commented Apr 6, 2023

Using a file like

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="500" height="500">
    <rect width="100%" height="100%" fill="white" />
    <text transform="translate(10,100)" font-family="sans-serif" font-size="60px" fill="#000">foo₂</text>
    <text transform="translate(10,200)" font-family="sans-serif" font-size="60px" fill="#000">bar</text>
</svg>

and ./resvg --sans-serif-family "Liberation Sans" simple_subscript_bold.svg simple_subscript_bold.png gives a warning "Warning (in usvg_text_layout:1398): Fallback from Liberation Sans to Noto Sans Mono." and result like
image

However specifying ./resvg --sans-serif-family "Noto Sans Mono" simple_subscript_bold.svg simple_subscript_bold.png doesn't give any warnings and also doesn't render the text in bold:
image

I suppose the problem is that Liberation Sans doesn't have the codepoint 2083 (subscript 2) available: fc-query --format='%{charset}\n' /usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf… 207f 20a3-20a4 … and Noto does (2074-208e). But I would expect then that a regular weight fallback would be used, and preferably a warning why the fallback was used when the requested font does exist.

@RazrFalcon
Copy link
Owner

Yes, the current font fallback algorithm doesn't account for font styles. It simply picks up the first font that has the required glyph. There is an endless amount of work left in the SVG text layout.

And while this is definitely a bug/missing feature, your SVG is partly to blame, because it literally states "use whatever font you want". Which it does.

The solution here would be to use something like:

<text font-family="sans-serif" font-size="60px" fill="#000">
     foo<tspan baseline-shift="sub" font-size="70%">2</tspan>
</text>

This is less magical and way more portable.

@RazrFalcon RazrFalcon added the bug label May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants