From fadca6a3627698a17a71b8605a3bc2c9464432ad Mon Sep 17 00:00:00 2001 From: Zimond Date: Mon, 15 Aug 2022 14:38:46 +0800 Subject: [PATCH] feat: upgrade resvg/usvg to 0.23 --- Cargo.toml | 11 +++++------ src/lib.rs | 12 ++++++------ src/options.rs | 6 +++--- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 899c29c3..b645edc9 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["cdylib"] env_logger = "0.9.0" fontdb = "0.9.1" log = "0.4" -resvg = { version = "0.22.0", default-features = false, features = [ +resvg = { version = "0.23.0", default-features = false, features = [ "filter", "dump-svg", ] } @@ -20,7 +20,6 @@ resvg = { version = "0.22.0", default-features = false, features = [ serde = { version = "1", features = ["derive"] } serde_json = "1" svgtypes = "0.8.1" -tiny-skia = "0.6.3" thiserror = "1.0.30" png = "0.17.5" pathfinder_geometry = "0.5.1" @@ -35,7 +34,7 @@ mimalloc-rust = { version = "0.2" } [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen = "0.2.81" js-sys = "0.3.58" -usvg = { version = "0.22.0", default-features = false, features = [ +usvg = { version = "0.23.0", default-features = false, features = [ "export", "filter", ] } @@ -43,7 +42,7 @@ usvg = { version = "0.22.0", default-features = false, features = [ [target.'cfg(not(target_arch = "wasm32"))'.dependencies] napi = { version = "2.7.0", features = ["serde-json", "async"] } napi-derive = "2.6.0" -usvg = { version = "0.22.0", default-features = false, features = [ +usvg = { version = "0.23.0", default-features = false, features = [ "export", "filter", "text", @@ -60,5 +59,5 @@ opt-level = 3 codegen-units = 1 [patch.crates-io] -resvg = { git = "https://github.com/zimond/resvg", rev = "cab0b15" } -usvg = { git = "https://github.com/zimond/resvg", rev = "cab0b15" } +resvg = { git = "https://github.com/zimond/resvg", rev = "dc405c4" } +usvg = { git = "https://github.com/zimond/resvg", rev = "dc405c4" } diff --git a/src/lib.rs b/src/lib.rs index 205b1d6b..8f7a207f 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,7 @@ use pathfinder_geometry::vector::Vector2F; #[cfg(not(target_arch = "wasm32"))] use napi_derive::napi; use options::JsOptions; -use tiny_skia::Pixmap; +use resvg::tiny_skia::Pixmap; use usvg::{ImageKind, NodeKind}; #[cfg(target_arch = "wasm32")] use wasm_bindgen::{ @@ -407,12 +407,12 @@ impl Resvg { let no_fill = p.fill.is_none() || p.fill .as_ref() - .map(|f| f.opacity.value() == 0.0) + .map(|f| f.opacity.get() == 0.0) .unwrap_or_default(); let no_stroke = p.stroke.is_none() || p.stroke .as_ref() - .map(|f| f.opacity.value() == 0.0) + .map(|f| f.opacity.get() == 0.0) .unwrap_or_default(); if no_fill && no_stroke { return None; @@ -465,7 +465,7 @@ impl Resvg { if let Some(stroke) = p.stroke.as_ref() { if !no_stroke { let mut style = StrokeStyle::default(); - style.line_width = stroke.width.value() as f32; + style.line_width = stroke.width.get() as f32; style.line_join = LineJoin::Miter(style.line_width); style.line_cap = match stroke.linecap { usvg::LineCap::Butt => LineCap::Butt, @@ -556,12 +556,12 @@ impl Resvg { let _image = resvg::render( &self.tree, self.js_options.fit_to, - tiny_skia::Transform::default(), + resvg::tiny_skia::Transform::default(), pixmap.as_mut(), ); // Crop the SVG - let crop_rect = tiny_skia::IntRect::from_ltrb( + let crop_rect = resvg::tiny_skia::IntRect::from_ltrb( self.js_options.crop.left, self.js_options.crop.top, self.js_options diff --git a/src/options.rs b/src/options.rs index 40d90cb8..fdebd101 100644 --- a/src/options.rs +++ b/src/options.rs @@ -7,9 +7,9 @@ use crate::error::Error; use fontdb::Database; #[cfg(not(target_arch = "wasm32"))] use napi::{bindgen_prelude::Buffer, Either}; -use resvg::ScreenSize; +use resvg::tiny_skia::Pixmap; +use resvg::usvg::ScreenSize; use serde::{Deserialize, Deserializer}; -use tiny_skia::Pixmap; use usvg::{ImageHrefResolver, ImageKind, OptionsRef}; /// Image fit options. @@ -197,7 +197,7 @@ impl JsOptions { let mut pixmap = Pixmap::new(size.width(), size.height()).unwrap(); if let Some(bg) = background { - let color = tiny_skia::Color::from_rgba8(bg.red, bg.green, bg.blue, bg.alpha); + let color = resvg::tiny_skia::Color::from_rgba8(bg.red, bg.green, bg.blue, bg.alpha); pixmap.fill(color); } Ok(pixmap)