Skip to content

Commit

Permalink
Call convert_text on svg node before rendering
Browse files Browse the repository at this point in the history
`tiny-skia` does not support text rendering, so we
convert the text nodes to path nodes prior to that.
  • Loading branch information
hecrj committed Nov 11, 2023
1 parent 751ea77 commit 2aaaf2c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ ouroboros = "0.17"
palette = "0.7"
qrcode = { version = "0.12", default-features = false }
raw-window-handle = "0.5"
resvg = "0.35"
resvg = "0.36"
rustc-hash = "1.0"
smol = "1.0"
softbuffer = "0.2"
syntect = "5.1"
sysinfo = "0.28"
thiserror = "1.0"
tiny-skia = "0.10"
tiny-skia = "0.11"
tokio = "1.0"
tracing = "0.1"
twox-hash = { version = "1.0", default-features = false }
Expand Down
14 changes: 12 additions & 2 deletions tiny_skia/src/vector.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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);
}

Expand Down

0 comments on commit 2aaaf2c

Please sign in to comment.