Skip to content

Commit

Permalink
Update resvg & co.
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmicHorrorDev committed Nov 23, 2023
1 parent 767e3b8 commit 5b3708a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 37 deletions.
50 changes: 33 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ html5ever = "0.26.0"
image = "0.24.7"
clap = { version = "4.3.24", features = ["cargo"] }
copypasta = "0.10.0"
resvg = "0.32.0"
usvg = "0.32.0"
resvg = "0.33"
usvg = "0.33"
tiny-skia = "0.9.1"
anyhow = "1.0.75"
dirs = "5.0.1"
Expand Down
34 changes: 16 additions & 18 deletions src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::io;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::time::Instant;
use usvg::{TreeParsing, TreeTextToPath};
use usvg::{Size as UsvgSize, TreeParsing, TreeTextToPath};
use wgpu::util::DeviceExt;
use wgpu::{BindGroup, Device, TextureFormat};

Expand Down Expand Up @@ -208,25 +208,23 @@ impl Image {
image
} else {
let opt = usvg::Options::default();
let mut rtree = usvg::Tree::from_data(&image_data, &opt).unwrap();
let mut fontdb = usvg::fontdb::Database::new();
fontdb.load_system_fonts();
rtree.convert_text(&fontdb);
let pixmap_size = rtree.size.to_screen_size();
let mut pixmap = tiny_skia::Pixmap::new(
(pixmap_size.width() as f32 * hidpi_scale) as u32,
(pixmap_size.height() as f32 * hidpi_scale) as u32,
)
.context("Couldn't create svg pixmap")
.unwrap();
resvg::render(
&rtree,
resvg::FitTo::Zoom(hidpi_scale),
tiny_skia::Transform::default(),
pixmap.as_mut(),
)
.context("Svg failed to render")
.unwrap();
let mut tree = usvg::Tree::from_data(&image_data, &opt).unwrap();
tree.size = tree.size.scale_to(
UsvgSize::new(
tree.size.width() * hidpi_scale as f64,
tree.size.height() * hidpi_scale as f64,
)
.unwrap(),
);
tree.convert_text(&fontdb);
let rtree = resvg::Tree::from_usvg(&tree);
let pixmap_size = resvg::IntSize::from_usvg(rtree.size);
let mut pixmap = tiny_skia::Pixmap::new(pixmap_size.width(), pixmap_size.height())
.context("Couldn't create svg pixmap")
.unwrap();
rtree.render(tiny_skia::Transform::default(), &mut pixmap.as_mut());
ImageData::new(
ImageBuffer::from_raw(pixmap.width(), pixmap.height(), pixmap.data().into())
.context("Svg buffer has invalid dimensions")
Expand Down

0 comments on commit 5b3708a

Please sign in to comment.