Skip to content

Commit a2a96ad

Browse files
committed
implement svg text fix for native renderer
Signed-off-by: Cory Frenette <[email protected]>
1 parent eaaea41 commit a2a96ad

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

wgpu/src/image/vector.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use crate::core::svg;
22
use crate::core::{Color, Size};
33
use crate::image::atlas::{self, Atlas};
44

5+
use iced_graphics::text;
56
use resvg::tiny_skia;
6-
use resvg::usvg;
7+
use resvg::usvg::{self, TreeTextToPath};
78
use std::collections::{HashMap, HashSet};
89
use std::fs;
910

@@ -51,11 +52,23 @@ impl Cache {
5152

5253
let svg = match handle.data() {
5354
svg::Data::Path(path) => {
54-
let tree = fs::read_to_string(path).ok().and_then(|contents| {
55-
usvg::Tree::from_str(&contents, &usvg::Options::default())
55+
let mut tree =
56+
fs::read_to_string(path).ok().and_then(|contents| {
57+
usvg::Tree::from_str(
58+
&contents,
59+
&usvg::Options::default(),
60+
)
5661
.ok()
57-
});
58-
62+
});
63+
// If there are text nodes in the tree load fonts and convert the text to paths
64+
if let Some(svg_tree) = &mut tree {
65+
if svg_tree.has_text_nodes() {
66+
let mut font_system = text::font_system()
67+
.write()
68+
.expect("Read font system");
69+
svg_tree.convert_text(font_system.raw().db_mut());
70+
}
71+
}
5972
tree.map(Svg::Loaded).unwrap_or(Svg::NotFound)
6073
}
6174
svg::Data::Bytes(bytes) => {

0 commit comments

Comments
 (0)