From 16287561a804fd065aa900996cc696d16cf3dd07 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Wed, 4 Sep 2024 17:52:38 +0800 Subject: [PATCH 1/4] fix: image src is null after loaded (#886) --- src/image.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/image.rs b/src/image.rs index d6df8e86..fb8262f3 100644 --- a/src/image.rs +++ b/src/image.rs @@ -238,7 +238,7 @@ impl Image { width: self.width, height: self.height, color_space: self.color_space, - data, + data: Some(data), this_ref: env.create_reference(&this)?, }; let task_output = env.spawn(decoder)?; @@ -299,7 +299,7 @@ struct BitmapDecoder { width: f64, height: f64, color_space: ColorSpace, - data: Uint8Array, + data: Option, this_ref: Ref<()>, } @@ -329,8 +329,17 @@ impl Task for BitmapDecoder { type JsValue = (); fn compute(&mut self) -> Result { - let length = self.data.len(); - let data_ref: &[u8] = &self.data; + let data_ref = match self.data.as_ref() { + Some(data) => data.as_ref(), + None => { + return Ok(DecodedBitmap { + bitmap: DecodeStatus::Empty, + width: self.width, + height: self.height, + }) + } + }; + let length = data_ref.len(); let mut width = self.width; let mut height = self.height; let bitmap = if str::from_utf8(&data_ref[0..10]) == Ok("data:image") { @@ -355,18 +364,18 @@ impl Task for BitmapDecoder { } else { DecodeStatus::Empty } - } else if let Some(kind) = infer::get(&self.data) + } else if let Some(kind) = infer::get(data_ref) && kind.matcher_type() == infer::MatcherType::Image { DecodeStatus::Ok(BitmapInfo { - data: Bitmap::from_buffer(self.data.as_ptr().cast_mut(), length), + data: Bitmap::from_buffer(data_ref.as_ptr().cast_mut(), length), is_svg: false, }) } else if is_svg_image(data_ref, length) { let font = get_font().map_err(SkError::from)?; if (self.width - -1.0).abs() > f64::EPSILON && (self.height - -1.0).abs() > f64::EPSILON { if let Some(bitmap) = Bitmap::from_svg_data_with_custom_size( - self.data.as_ptr(), + data_ref.as_ptr(), length, self.width as f32, self.height as f32, @@ -381,7 +390,7 @@ impl Task for BitmapDecoder { DecodeStatus::InvalidSvg } } else if let Some(bitmap) = - Bitmap::from_svg_data(self.data.as_ptr(), length, self.color_space, &font) + Bitmap::from_svg_data(data_ref.as_ptr(), length, self.color_space, &font) { if let Ok(bitmap) = bitmap { DecodeStatus::Ok(BitmapInfo { @@ -426,11 +435,11 @@ impl Task for BitmapDecoder { self_mut.complete = true; match output.bitmap { DecodeStatus::Ok(bitmap) => { + self_mut.src = self.data.take(); let onload = this.get_named_property_unchecked::("onload")?; if onload.get_type()? == ValueType::Function { let onload_func: Function<(), ()> = Function::from_unknown(onload)?; onload_func.apply(this, ())?; - self_mut.src = Some(self.data.clone()); } self_mut.is_svg = bitmap.is_svg; self_mut.bitmap = Some(bitmap.data); From 00d441004b5c4ce136b709bbee15f26d25124c3c Mon Sep 17 00:00:00 2001 From: LongYinan Date: Wed, 4 Sep 2024 18:02:33 +0800 Subject: [PATCH 2/4] chore: upgrade rust toolchain (#887) --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 831159a1..9c73b13c 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-06-05" +channel = "nightly-2024-09-04" profile = "default" From b103fc2bc77a54c12bb054dda6d8ec98f90af04b Mon Sep 17 00:00:00 2001 From: LongYinan Date: Wed, 4 Sep 2024 21:42:16 +0800 Subject: [PATCH 3/4] feat: upgrade skia to m129 (#888) --- README-zh.md | 2 +- README.md | 2 +- skia | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README-zh.md b/README-zh.md index 3e6aeb4f..a6219d1e 100644 --- a/README-zh.md +++ b/README-zh.md @@ -1,7 +1,7 @@ # `skr canvas` ![CI](https://github.com/Brooooooklyn/canvas/workflows/CI/badge.svg) -![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm128-hotpink) +![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm129-hotpink) [![install size](https://packagephobia.com/badge?p=@napi-rs/canvas)](https://packagephobia.com/result?p=@napi-rs/canvas) [![Downloads](https://img.shields.io/npm/dm/@napi-rs/canvas.svg?sanitize=true)](https://npmcharts.com/compare/@napi-rs/canvas?minimal=true) diff --git a/README.md b/README.md index edd5c7db..98d3ba83 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # `skr canvas` ![CI](https://github.com/Brooooooklyn/canvas/workflows/CI/badge.svg) -![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm128-hotpink) +![Skia Version](https://img.shields.io/badge/Skia-chrome%2Fm129-hotpink) [![install size](https://packagephobia.com/badge?p=@napi-rs/canvas)](https://packagephobia.com/result?p=@napi-rs/canvas) [![Downloads](https://img.shields.io/npm/dm/@napi-rs/canvas.svg?sanitize=true)](https://npmcharts.com/compare/@napi-rs/canvas?minimal=true) diff --git a/skia b/skia index fb67954b..501e9efa 160000 --- a/skia +++ b/skia @@ -1 +1 @@ -Subproject commit fb67954b7e76dc59567dd1f87734ada0cd1bc7f6 +Subproject commit 501e9efaa2fc929ec67c44da6dbaf9335264b559 From 49574ed8a35c95679eefa984ee89947bfcd53ba8 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Wed, 4 Sep 2024 23:43:53 +0800 Subject: [PATCH 4/4] 0.1.55 --- CHANGELOG.md | 14 ++++++++++++++ npm/android-arm64/package.json | 2 +- npm/darwin-arm64/package.json | 2 +- npm/darwin-x64/package.json | 2 +- npm/linux-arm-gnueabihf/package.json | 2 +- npm/linux-arm64-gnu/package.json | 2 +- npm/linux-arm64-musl/package.json | 2 +- npm/linux-x64-gnu/package.json | 2 +- npm/linux-x64-musl/package.json | 2 +- npm/win32-x64-msvc/package.json | 2 +- package.json | 2 +- 11 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5dd7d76..8346f8d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## [0.1.55](https://github.com/Brooooooklyn/canvas/compare/v0.1.54...v0.1.55) (2024-09-04) + + +### Bug Fixes + +* image src is null after loaded ([#886](https://github.com/Brooooooklyn/canvas/issues/886)) ([1628756](https://github.com/Brooooooklyn/canvas/commit/16287561a804fd065aa900996cc696d16cf3dd07)) + + +### Features + +* upgrade skia to m129 ([#888](https://github.com/Brooooooklyn/canvas/issues/888)) ([b103fc2](https://github.com/Brooooooklyn/canvas/commit/b103fc2bc77a54c12bb054dda6d8ec98f90af04b)) + + + ## [0.1.54](https://github.com/Brooooooklyn/canvas/compare/v0.1.53...v0.1.54) (2024-08-17) diff --git a/npm/android-arm64/package.json b/npm/android-arm64/package.json index bcee44cf..bae6f57e 100644 --- a/npm/android-arm64/package.json +++ b/npm/android-arm64/package.json @@ -1,6 +1,6 @@ { "name": "@napi-rs/canvas-android-arm64", - "version": "0.1.54", + "version": "0.1.55", "os": [ "android" ], diff --git a/npm/darwin-arm64/package.json b/npm/darwin-arm64/package.json index f264e34b..7964c204 100644 --- a/npm/darwin-arm64/package.json +++ b/npm/darwin-arm64/package.json @@ -1,6 +1,6 @@ { "name": "@napi-rs/canvas-darwin-arm64", - "version": "0.1.54", + "version": "0.1.55", "os": [ "darwin" ], diff --git a/npm/darwin-x64/package.json b/npm/darwin-x64/package.json index 2398cc3c..24809d0e 100644 --- a/npm/darwin-x64/package.json +++ b/npm/darwin-x64/package.json @@ -1,6 +1,6 @@ { "name": "@napi-rs/canvas-darwin-x64", - "version": "0.1.54", + "version": "0.1.55", "os": [ "darwin" ], diff --git a/npm/linux-arm-gnueabihf/package.json b/npm/linux-arm-gnueabihf/package.json index 334cb7d0..1d134634 100644 --- a/npm/linux-arm-gnueabihf/package.json +++ b/npm/linux-arm-gnueabihf/package.json @@ -1,6 +1,6 @@ { "name": "@napi-rs/canvas-linux-arm-gnueabihf", - "version": "0.1.54", + "version": "0.1.55", "os": [ "linux" ], diff --git a/npm/linux-arm64-gnu/package.json b/npm/linux-arm64-gnu/package.json index 296537b0..ffc744e7 100644 --- a/npm/linux-arm64-gnu/package.json +++ b/npm/linux-arm64-gnu/package.json @@ -1,6 +1,6 @@ { "name": "@napi-rs/canvas-linux-arm64-gnu", - "version": "0.1.54", + "version": "0.1.55", "os": [ "linux" ], diff --git a/npm/linux-arm64-musl/package.json b/npm/linux-arm64-musl/package.json index 5e179ffe..669b8197 100644 --- a/npm/linux-arm64-musl/package.json +++ b/npm/linux-arm64-musl/package.json @@ -1,6 +1,6 @@ { "name": "@napi-rs/canvas-linux-arm64-musl", - "version": "0.1.54", + "version": "0.1.55", "os": [ "linux" ], diff --git a/npm/linux-x64-gnu/package.json b/npm/linux-x64-gnu/package.json index 5453e7d3..93ab4f91 100644 --- a/npm/linux-x64-gnu/package.json +++ b/npm/linux-x64-gnu/package.json @@ -1,6 +1,6 @@ { "name": "@napi-rs/canvas-linux-x64-gnu", - "version": "0.1.54", + "version": "0.1.55", "os": [ "linux" ], diff --git a/npm/linux-x64-musl/package.json b/npm/linux-x64-musl/package.json index 76b0225f..577111ef 100644 --- a/npm/linux-x64-musl/package.json +++ b/npm/linux-x64-musl/package.json @@ -1,6 +1,6 @@ { "name": "@napi-rs/canvas-linux-x64-musl", - "version": "0.1.54", + "version": "0.1.55", "os": [ "linux" ], diff --git a/npm/win32-x64-msvc/package.json b/npm/win32-x64-msvc/package.json index 90ee619a..35d89014 100644 --- a/npm/win32-x64-msvc/package.json +++ b/npm/win32-x64-msvc/package.json @@ -1,6 +1,6 @@ { "name": "@napi-rs/canvas-win32-x64-msvc", - "version": "0.1.54", + "version": "0.1.55", "os": [ "win32" ], diff --git a/package.json b/package.json index e9d61659..2b32d0ac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@napi-rs/canvas", - "version": "0.1.54", + "version": "0.1.55", "description": "Canvas for Node.js with skia backend", "main": "index.js", "repository": {