Skip to content

Commit

Permalink
feat: upgrade resvg/usvg to 0.23
Browse files Browse the repository at this point in the history
  • Loading branch information
zimond authored and yisibl committed Aug 15, 2022
1 parent 21d782d commit fadca6a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ 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",
] }

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"
Expand All @@ -35,15 +34,15 @@ 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",
] }

[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",
Expand All @@ -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" }
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

1 comment on commit fadca6a

@vercel
Copy link

@vercel vercel bot commented on fadca6a Aug 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

resvg-js – ./

resvg-js-git-main-yisibl.vercel.app
resvg-js.vercel.app
resvg-js-yisibl.vercel.app

Please sign in to comment.