Merge pull request #2161 from cfrenette/bug/svg-text-not-rendered

Implement a fix for the native renderer not rendering text in SVGs
This commit is contained in:
Héctor Ramón 2023-12-11 10:56:34 +01:00 committed by GitHub
commit 78689687ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 9 deletions

View file

@ -96,7 +96,7 @@ impl Cache {
if let Some(svg) = &mut svg {
if svg.has_text_nodes() {
let mut font_system =
text::font_system().write().expect("Read font system");
text::font_system().write().expect("Write font system");
svg.convert_text(font_system.raw().db_mut());
}

View file

@ -1,9 +1,10 @@
use crate::core::svg;
use crate::core::{Color, Size};
use crate::graphics::text;
use crate::image::atlas::{self, Atlas};
use resvg::tiny_skia;
use resvg::usvg;
use resvg::usvg::{self, TreeTextToPath};
use std::collections::{HashMap, HashSet};
use std::fs;
@ -49,15 +50,15 @@ impl Cache {
return self.svgs.get(&handle.id()).unwrap();
}
let svg = match handle.data() {
svg::Data::Path(path) => {
let tree = fs::read_to_string(path).ok().and_then(|contents| {
let mut svg = match handle.data() {
svg::Data::Path(path) => fs::read_to_string(path)
.ok()
.and_then(|contents| {
usvg::Tree::from_str(&contents, &usvg::Options::default())
.ok()
});
tree.map(Svg::Loaded).unwrap_or(Svg::NotFound)
}
})
.map(Svg::Loaded)
.unwrap_or(Svg::NotFound),
svg::Data::Bytes(bytes) => {
match usvg::Tree::from_data(bytes, &usvg::Options::default()) {
Ok(tree) => Svg::Loaded(tree),
@ -66,6 +67,15 @@ impl Cache {
}
};
if let Svg::Loaded(svg) = &mut svg {
if svg.has_text_nodes() {
let mut font_system =
text::font_system().write().expect("Write font system");
svg.convert_text(font_system.raw().db_mut());
}
}
let _ = self.svgs.insert(handle.id(), svg);
self.svgs.get(&handle.id()).unwrap()
}