summaryrefslogtreecommitdiffstats
path: root/wgpu/src/image
diff options
context:
space:
mode:
authorLibravatar Cory Frenette <cory@frenette.dev>2023-12-10 22:12:46 -0500
committerLibravatar Cory Frenette <cory@frenette.dev>2023-12-10 22:12:46 -0500
commita2a96adf7a19f8b2f7879fc19ff139b930fb102e (patch)
tree25cf028f5d72f4caf8d960ba3d2b0502d55e334d /wgpu/src/image
parenteaaea414b8544b883c0388a5a92cbb0df7fc6633 (diff)
downloadiced-a2a96adf7a19f8b2f7879fc19ff139b930fb102e.tar.gz
iced-a2a96adf7a19f8b2f7879fc19ff139b930fb102e.tar.bz2
iced-a2a96adf7a19f8b2f7879fc19ff139b930fb102e.zip
implement svg text fix for native renderer
Signed-off-by: Cory Frenette <cory@frenette.dev>
Diffstat (limited to 'wgpu/src/image')
-rw-r--r--wgpu/src/image/vector.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs
index 6582bb82..1efc5342 100644
--- a/wgpu/src/image/vector.rs
+++ b/wgpu/src/image/vector.rs
@@ -2,8 +2,9 @@ use crate::core::svg;
use crate::core::{Color, Size};
use crate::image::atlas::{self, Atlas};
+use iced_graphics::text;
use resvg::tiny_skia;
-use resvg::usvg;
+use resvg::usvg::{self, TreeTextToPath};
use std::collections::{HashMap, HashSet};
use std::fs;
@@ -51,11 +52,23 @@ impl Cache {
let svg = match handle.data() {
svg::Data::Path(path) => {
- let tree = fs::read_to_string(path).ok().and_then(|contents| {
- usvg::Tree::from_str(&contents, &usvg::Options::default())
+ let mut tree =
+ fs::read_to_string(path).ok().and_then(|contents| {
+ usvg::Tree::from_str(
+ &contents,
+ &usvg::Options::default(),
+ )
.ok()
- });
-
+ });
+ // If there are text nodes in the tree load fonts and convert the text to paths
+ if let Some(svg_tree) = &mut tree {
+ if svg_tree.has_text_nodes() {
+ let mut font_system = text::font_system()
+ .write()
+ .expect("Read font system");
+ svg_tree.convert_text(font_system.raw().db_mut());
+ }
+ }
tree.map(Svg::Loaded).unwrap_or(Svg::NotFound)
}
svg::Data::Bytes(bytes) => {