Page MenuHomePhabricator

librsvg does not support fallback font set (more than one font family)
Open, Needs TriagePublic

Description

When specifying more than one exact font name in the font-family the fallback font is ignored.

font-family="Used Font, Ignored Font, Ignored Font 2"


Version: C librsvg < 2.40.? and Rust librsvg < 2.48.5
Severity: minor

Details

Reference
bz62986

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 2:56 AM
bzimport set Reference to bz62986.
bzimport added a subscriber: Unknown Object (MLST).

Any example testcase / exact steps to reproduce the problem?

Sorry I can't reproduce this any more. So please close / delete this report.

Reopen. Regression error.

The recent C version of librsvg 2.40.? worked.

The 5-year old librsvg 2.44.10 does not support font fallbacks (e.g., font-family="fonta, fontb, fontc").

librsvg 2.48.5 is needed.

Glrx renamed this task from librsvg don't support fallback font set (more than one font family) to librsvg does not support fallback font set (more than one font family).Sep 5 2023, 7:05 PM
Glrx updated the task description. (Show Details)

Just so people know, the problem has not been solved for OWID (Our World in Data) images. See: Phab:T344564. When I tried to upload the latest map (dated Sep 13, 2023 on the map) I was prevented from doing so.
https://commons.wikimedia.org/wiki/File:World_map_of_total_confirmed_COVID-19_deaths_per_million_people_by_country.svg

The message in red letters was "Found unsafe CSS in the style element of uploaded SVG file."

I see lots of stuff between style tags in the SVG code. Is the problem this?:

<style>@import url(https://ourworldindata.org/fonts.css)</style>

That is something recently added by OWID.

The current map on the Commons does not show the overlap problem of Phab:T344564 because someone edited the map and made the text size smaller at the top.

So the MediaWiki problem remains.

I see lots of stuff between style tags in the SVG code. Is the problem this?:

<style>@import url(https://ourworldindata.org/fonts.css)</style>

That is something recently added by OWID.

Yes, that is the problem, but it is a separate issue from this ticket. For security reasons, WMF does not allow uploads that load from external sites.

font-family="Used Font, Ignored Font, Ignored Font 2"

The 5-year old librsvg 2.44.10 does not support font fallbacks (e.g., font-family="fonta, fontb, fontc").

What font is MediaWiki using when it doesn't recognize the "used" font in the font family? What is MediaWiki's last-resort generic font substitution?

For example, when MediaWiki sees this in OWID files for the topmost caption of an OWID image:

style="font-family:&#x27;Playfair Display&#x27;, Georgia, &#x27;Times New Roman&#x27;, &#x27;Liberation Serif&#x27;, serif"

Per T344564 (Font substitution for SVG file to PNG thumbnail replaces serif with sans-serif font): Instead of a serif font (which all those fonts are) MediaWiki is substituting a sans-serif font. What font is it? MediaWiki must not be recognizing "Playfair Display" as a serif font.

So I am assuming that when MediaWiki does not see a font it recognizes (in any way) it has one standard font it uses. What is it?

If it is Liberation Sans, I suggest changing that to Liberation Sans Narrow if possible. Or whatever font it is using change it to the Narrow version. Is this possible? It would fix a lot of problems with text overlapping the edge, etc..

At the bare minimum Mediawiki should show a preview, and then allow the uploader to decide whether to continue the upload.

See also: T351978. SVG file upload: Allow to preview SVG file without external URLs loaded and continue upload after removal of external "@import url". People need to be able to preview the SVG file after the font substitution occurs to see if it looks right.

Is this possible?

Feel free to file separate tickets for separate requests. This ticket's scope is described in its ticket title.

Is this possible?

Feel free to file separate tickets for separate requests. This ticket's scope is described in its ticket title.

This task says that Mediawiki sees only the first font in a font family. And that it needs to see the fallback fonts too.

But I have no idea what Mediawiki is doing now when it doesn't recognize that first font. So I don't know what to ask for. Is it substituting a random font? Is it substituting a specific font? What is that font? Once I know that I have a clue. Getting answers about how Mediawiki deals with SVG files is like pulling teeth.

Getting answers about how Mediawiki deals with SVG files is like pulling teeth.

Feel free to point to on-wiki forum posts, mailing list posts, etc. where you brought up relevant related questions.

MediaWiki uses librsvg to paint SVG files.

The current MW version of librsvg only looks at the first font. If it does not have that font, then librsvg uses a default font.

The actual choice of the default font may be made by the font machinery used in the Unix operating system. MW may be inheriting its default font from the Debian distribution.

For MW, the default font is a sans-serif font. I do not know, but it may be DejaVu Sans. I believe DejaVu Sans has wider text metrics than many sans-serif fonts. DejaVu Sans with font-stretch="condensed" will give a narrower font.

Liberation Sans should have metrics that are similar to Arial and Helvetica, which are common fonts. Specifying the first font as "Liberation Sans" should be reasonable for many files. Liberation Sans/normal is narrower that DejaVu Sans/condensed. Liberation Sans on MW does not have a condensed version.

For tight fits, make the first font "Noto Sans" and set font-stretch="condensed".

Thanks for the rapid reply Glrx!

I do not know if it is DejaVu Sans. It may be according to this:
https://commons.wikimedia.org/wiki/Help:SVG#Font_substitution_and_fallback_fonts
But that info may be old, and not aligned with the current software Mediawiki is using. DejaVu Sans is definitely wider according to this:
https://commons.wikimedia.org/wiki/File:SVG_Text_Font_Test.svg

For MW, the default font is a sans-serif font. I do not know, but it may be DejaVu Sans. I believe DejaVu Sans has wider text metrics than many sans-serif fonts. DejaVu Sans with font-stretch="condensed" will give a narrower font.

Liberation Sans should have metrics that are similar to Arial and Helvetica, which are common fonts. Specifying the first font as "Liberation Sans" should be reasonable for many files.

Back in March 2023 OWID solved the problem just by adding Liberation Sans at the end of their font family list. So between then and July 2023 when I first posted a Phab ticket about the bad font substitution problem, Mediawiki must have lost the ability to look past the first font in a font family list.

So I guess I can just be patient and wait for Mediawiki to again be able to look at all the fonts in a font-family list. Any prognosis on when that might happen? In the meantime for SVG files created specifically for the Commons I wrote this summary:
https://commons.wikimedia.org/wiki/File_talk:Template_map_of_U.S._states_and_District_of_Columbia.svg/Instructions#Font_family