Skip to content

Commit

Permalink
fix: upgrade to NAPI-RS 3.0.0-alpha.19 (#929)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn authored Nov 6, 2024
1 parent e41ca24 commit 1304a9e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ base64-simd = "0.8"
cssparser = "0.29"
infer = "0.16"
libavif = { version = "0.14", default-features = false, features = ["codec-aom"] }
napi = { version = "3.0.0-alpha.16", default-features = false, features = ["napi3", "serde-json"] }
napi-derive = { version = "3.0.0-alpha.15", default-features = false }
napi = { version = "3.0.0-alpha.19", default-features = false, features = ["napi3", "serde-json"] }
napi-derive = { version = "3.0.0-alpha.17", default-features = false }
nom = "7"
num_cpus = "1"
regex = "1"
Expand Down
24 changes: 18 additions & 6 deletions src/path.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use napi::{bindgen_prelude::*, JsString};
use napi::bindgen_prelude::*;

use crate::sk::{
FillType as SkFillType, Matrix as SkMatrix, Path as SkPath, PathOp as SkPathOp,
FillType as SkFillType, Matrix as SkMatrix, Path as SkPath, PathOp as SkPathOp, SkiaString,
StrokeCap as SkStrokeCap, StrokeJoin as SkStrokeJoin,
};

Expand Down Expand Up @@ -295,10 +295,9 @@ impl Path {
self
}

#[napi(js_name = "toSVGString")]
pub fn to_svg_string(&self, env: Env) -> Result<JsString> {
let sk_string = self.inner.to_svg_string();
unsafe { env.create_string_from_c_char(sk_string.ptr, sk_string.length as isize) }
#[napi(js_name = "toSVGString", ts_return_type = "string")]
pub fn to_svg_string(&self) -> SkiaString {
self.inner.to_svg_string()
}

#[napi]
Expand Down Expand Up @@ -396,3 +395,16 @@ impl Path {
)
}
}

impl ToNapiValue for SkiaString {
unsafe fn to_napi_value(env: sys::napi_env, val: Self) -> Result<sys::napi_value> {
let mut result = std::ptr::null_mut();
napi::check_status!(sys::napi_create_string_utf8(
env,
val.ptr,
val.length as isize,
&mut result,
))?;
Ok(result)
}
}

0 comments on commit 1304a9e

Please sign in to comment.