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:
commit
78689687ff
2 changed files with 19 additions and 9 deletions
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue