Skip to content

Commit

Permalink
Fix resvg changes on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
filips123 committed May 1, 2024
1 parent 7d8e703 commit 540d876
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions native/src/integrations/implementation/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use image::imageops::FilterType::Gaussian;
use image::{DynamicImage, Rgba, RgbaImage};
use log::{debug, error, warn};
use reqwest::blocking::Client;
use resvg::usvg::{fontdb, TreeParsing, TreeTextToPath};
use resvg::usvg::fontdb;
use resvg::{tiny_skia, usvg};
use url::Url;
use web_app_manifest::resources::IconResource;
Expand Down Expand Up @@ -256,20 +256,23 @@ fn load_icon(content: &[u8], content_type: &str, size: u32) -> Result<RgbaImage>

let mut pixmap = tiny_skia::Pixmap::new(size, size).context("Invalid target size")?;

let opt = usvg::Options::default();
let mut utree = usvg::Tree::from_data(content, &opt).context("Failed to parse SVG icon")?;

let mut fontdb = fontdb::Database::new();
fontdb.load_system_fonts();
utree.convert_text(&fontdb);

let mut opt = usvg::Options::default();

let resolver = Box::new(move |_: &str, _: &usvg::Options, _: &fontdb::Database| None);
opt.image_href_resolver.resolve_string = resolver;

let tree =
usvg::Tree::from_data(content, &opt, &fontdb).context("Failed to parse SVG icon")?;

let transform = tiny_skia::Transform::from_scale(
size as f32 / utree.size.width(),
size as f32 / utree.size.height(),
size as f32 / tree.size().width(),
size as f32 / tree.size().height(),
);

let rtree = resvg::Tree::from_usvg(&utree);
rtree.render(transform, &mut pixmap.as_mut());
resvg::render(&tree, transform, &mut pixmap.as_mut());

return RgbaImage::from_raw(size, size, pixmap.take()).context("Failed to load SVG icon");
}
Expand Down

0 comments on commit 540d876

Please sign in to comment.