Closed cornmonger closed 3 months ago
This is a problem in fontdb
, which is used by resvg
(and usvg
). There are actually two problems here:
Problem 1 can be solved by bumping the version of the resvg dependency to 0.42.0, initializing a fontdb database object with load_system_fonts()
, and then passing that to the existing usvg
call.
This works for me by altering the command
function in tooling/cli/src/icon.rs
:
let rtree = {
let mut fontdb = usvg::fontdb::Database::new(); //+
fontdb.load_system_fonts(); //+
let opt = usvg::Options {
// Get file's absolute directory.
resources_dir: std::fs::canonicalize(&input)
.ok()
.and_then(|p| p.parent().map(|p| p.to_path_buf())),
fontdb: Arc::new(fontdb), //+
..Default::default()
};
let svg_data = std::fs::read(&input).unwrap();
usvg::Tree::from_data(&svg_data, &opt).unwrap() //*
};
Problem 2 is up to the resvg
/ fontdb
team to solve permanently. A workaround would be to call the system's fc-match
for the handful of generic family names (serif, sans-serif, cursive, fantasy, and monospace) and use the appropriate fontdb setters to pre-configure those, then pass it to usvg
.
Happy to submit a PR for this if needed.
@roylaurie a PR sounds fantastic, thanks for investigating
Ready for review. This fixes the first problem that I mentioned. Details are in the PR.
Describe the bug
cargo tauri icon
is having problems applying the font-family attribute in SVG files. This appears to be the case regardless of whether the font-family is indicated inline in a<text>
element or as a<style>
definition. It warns that it can't find the font and then does not render text when generating icons. Everything else appears to render.This run, for example, is just with no font-family specified at all:
So far, this is reproducible on a relatively fresh install of Ubuntu Desktop 24 as well as an older install of Ubuntu Desktop 23.
Reproduction
cargo tauri icon test.svg
against any SVG with a<text>
element.Here is a test SVG that I can reproduce with (test.svg):
System info:
Expected behavior
No response
Full
tauri info
outputStack trace
Additional context
No response