Merge pull request #1908 from alec-deason/bug/convert_text

Run convert_text on svg trees so text renders correctly
This commit is contained in:
Héctor Ramón 2023-11-11 04:16:17 +01:00 committed by GitHub
commit 3408ab111f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View file

@ -1,7 +1,8 @@
use crate::core::svg::{Data, Handle};
use crate::core::{Color, Rectangle, Size};
use crate::graphics::text;
use resvg::usvg;
use resvg::usvg::{self, TreeTextToPath};
use rustc_hash::{FxHashMap, FxHashSet};
use std::cell::RefCell;
@ -77,7 +78,7 @@ impl Cache {
let id = handle.id();
if let hash_map::Entry::Vacant(entry) = self.trees.entry(id) {
let svg = match handle.data() {
let mut svg = match handle.data() {
Data::Path(path) => {
fs::read_to_string(path).ok().and_then(|contents| {
usvg::Tree::from_str(
@ -92,6 +93,15 @@ 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");
svg.convert_text(font_system.raw().db_mut());
}
}
let _ = entry.insert(svg);
}