Font family with number inside falls back to default font
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 4.1k
- Forks
- 348
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 3
Description
Hey @RazrFalcon how's it going?
There is weird bug that is happening from as long as I remember when handling texts. When providing `font-family` with number in its name for text elements (i.e `Nunito Sans 12pt` or `Sans Serif 4`) ReSVG fallbacks to default family (`Times New Roman` for `Nunito Sans 12pt`) even though the family is present in the fontdb.
It fails inside: `crates/usvg/src/parser/text.rs` on
```
let mut families = parse_font_families(font_families) // fails here
.ok()
.log_none(|| {
log::warn!(
"Failed to parse {} value: '{}'. Falling back to {}.",
AId::FontFamily,
font_families,
state.opt.font_family
)
})
.unwrap_or_default(); // falls back to default empty vector
```
Inside `svgtypes/src/stream.rs` on (I assume) `parse_ident` function. I don't fully understand what is going on there, but the error is `InvalidIdent`.
I wouldn't bother with this, however some of the Google Fonts files (those I named) are parsed into fontdb with numbers inside family names. And basically it's not possible to use them because of the bug (or maybe numbers are not allowed by SVG specs?).
Example SVG (really any text element with specified font-family):
```
```
Example font: https://fonts.google.com/specimen/Nunito+Sans
(Yes it's called Nunito Sans but family name inside the file is with `{number}pt`)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided SVG and inspect crates/usvg/src/parser/text.rs, especially parse_font_families, then follow the InvalidIdent path into svgtypes/src/stream.rs and parse_ident. Done means font-family values such as “Nunito Sans 12pt” are accepted and the matching fontdb family is used instead of the default.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100