From 2b43b1616702f5ea7a62d635c320016d63a12fbc Mon Sep 17 00:00:00 2001 From: MeiHui FAN Date: Sat, 30 Nov 2024 10:11:12 +0800 Subject: [PATCH] update, refined and fix clippy warnings --- .github/workflows/rust-ci.yml | 4 ++-- Cargo.toml | 11 +++++++---- src/convert.rs | 11 +++++++---- src/render.rs | 3 ++- src/render_b2d.rs | 4 ++-- src/render_evg.rs | 4 ++-- src/tinyvg.rs | 1 - tests/intvg.rs | 4 ++-- 8 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml index 8fd0342..bc96953 100644 --- a/.github/workflows/rust-ci.yml +++ b/.github/workflows/rust-ci.yml @@ -45,7 +45,6 @@ jobs: #- name: Install toolchain # uses: dtolnay/rust-toolchain@stable - #- uses: Swatinem/rust-cache@v2 - name: Checkout repository uses: actions/checkout@v4 @@ -58,6 +57,7 @@ jobs: ~/.cargo/registry/index/ ~/.cargo/registry/cache/ ~/.cargo/git/db/ + Cargo.lock target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} @@ -89,7 +89,7 @@ jobs: uses: actions/checkout@v4 - run: rustup toolchain install nightly --profile minimal --component llvm-tools - - uses: Swatinem/rust-cache@v2 # should be after rustup + - uses: Swatinem/rust-cache@v2 # should be after rustup - uses: taiki-e/install-action@cargo-llvm-cov # https://github.com/taiki-e/cargo-llvm-cov - name: Generate code coverage # https://github.com/actions-rs/tarpaulin diff --git a/Cargo.toml b/Cargo.toml index bf695d4..4937dae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ keywords = [ "TinyVG", "SVG", "vector-graphic", "EVG", "Blend2D" ] #tiny-skia-path = "0.11" tiny-skia = "0.11" kurbo = "0.11" # Bezier curves utils -usvg = "0.42" +usvg = "0.44" #build-time = { version = "0.1", git = "https://github.com/AlephAlpha/build-time" } png = { version = "0.17", optional = true } @@ -50,12 +50,15 @@ criterion = "0.5" #rexpect = "0.5" [build-dependencies] -cc = { version = "1.0", features = [ "parallel" ] } -bindgen = "0.69" +cc = { version = "1.2", features = [ "parallel" ] } +bindgen = "0.70" chrono = "0.4" glob = "0.3" #walkdir = "2.4" +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage_nightly)'] } + [profile.dev] opt-level = 1 # Enable a small amount of optimization in debug mode @@ -72,5 +75,5 @@ panic = 'abort' lto = 'fat' # true [workspace] -#members = [ "wcnvs" ] +members = [ "wcnvs" ] diff --git a/src/convert.rs b/src/convert.rs index 260e862..837fcc6 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -67,8 +67,9 @@ fn convert_nodes(tvg: &mut TinyVG, } usvg::Node::Image(img) => if img.is_visible() { - match img.kind() { usvg::ImageKind::JPEG(_) | - usvg::ImageKind::PNG(_) | usvg::ImageKind::GIF(_) => + match img.kind() { + usvg::ImageKind::GIF(_) | usvg::ImageKind::WEBP(_) | + usvg::ImageKind::PNG(_) | usvg::ImageKind::JPEG(_) => eprintln!("TinyVG can't support raster images"), usvg::ImageKind::SVG(svg) => convert_nodes(tvg, svg.root(), trfm), } @@ -81,8 +82,9 @@ fn convert_nodes(tvg: &mut TinyVG, } fn convert_path(path: &skia::Path, trfm: &usvg::Transform) -> Vec { - impl From for Point { //unsafe { std::mem::transmute(pt) } + #[allow(non_local_definitions)] impl From for Point { fn from(pt: skia::Point) -> Self { Self { x: pt.x, y: pt.y } } + //unsafe { std::mem::transmute(pt) } } let (mut coll, mut cmds) = (vec![], vec![]); @@ -122,8 +124,9 @@ fn convert_paint(tvg: &mut TinyVG, a: (stop.opacity() * opacity).to_u8() } }; - impl From<(f32, f32)> for Point { // unsafe { std::mem::transmute(pt) } + #[allow(non_local_definitions)] impl From<(f32, f32)> for Point { fn from(pt: (f32, f32)) -> Self { Self { x: pt.0, y: pt.1 } } + // unsafe { std::mem::transmute(pt) } } match paint { usvg::Paint::Pattern(_) => { // trfm should be applied here diff --git a/src/render.rs b/src/render.rs index a6245aa..b00e510 100644 --- a/src/render.rs +++ b/src/render.rs @@ -17,7 +17,7 @@ impl Render for TinyVG { line_cap: skia::LineCap::Round, ..Default::default() }; let err_msg = "Fail to build path"; - impl From for skia::Rect { + #[allow(non_local_definitions)] impl From for skia::Rect { //fn from(r: Rect) -> Self { unsafe { std::mem::transmute(r) } } //fn from(r: Rect) -> Self { skia::Rect::from_ltrb(r.l, r.t, r.r, r.b).unwrap() } fn from(r: Rect) -> Self { skia::Rect::from_xywh(r.x, r.y, r.w, r.h).unwrap() } @@ -164,6 +164,7 @@ fn process_segcmd(pb: &mut skia::PathBuilder, cmd: &SegInstr) { } } +#[allow(non_local_definitions)] fn style_to_paint<'a, R: io::Read, W: io::Write>(img: &TinyVG, style: &Style, trfm: skia::Transform) -> Result, &'static str> { diff --git a/src/render_b2d.rs b/src/render_b2d.rs index daf21d0..a91c24a 100644 --- a/src/render_b2d.rs +++ b/src/render_b2d.rs @@ -17,7 +17,7 @@ impl Render for TinyVG { (self.header.width as f32 * scale).ceil() as _, (self.header.height as f32 * scale).ceil() as _, BLFormat::BL_FORMAT_PRGB32); - impl From<&Rect> for BLRect { // BLBox + #[allow(non_local_definitions)] impl From<&Rect> for BLRect { // BLBox //fn from(rect: &Rect) -> Self { unsafe { std::mem::transmute(rect) } } fn from(r: &Rect) -> Self { //Self { x0: r.l as _, y0: r.t as _, x1: r.r as _, y1: r.b as _ } @@ -160,7 +160,7 @@ fn process_segcmd(path: &mut BLPath, cmd: &SegInstr) { fn convert_style(img: &TinyVG, style: &Style) -> Box { - impl From for BLRgba32 { + #[allow(non_local_definitions)] impl From for BLRgba32 { fn from(color: RGBA8888) -> Self { Self { value: // convert to 0xAARRGGBB (color.a as u32) << 24 | (color.r as u32) << 16 | (color.g as u32) << 8 | color.b as u32 diff --git a/src/render_evg.rs b/src/render_evg.rs index 476f632..33b60ac 100644 --- a/src/render_evg.rs +++ b/src/render_evg.rs @@ -11,7 +11,7 @@ impl Render for TinyVG { (self.header.width as f32 * scale).ceil() as _, (self.header.height as f32 * scale).ceil() as _); - impl From<&Rect> for GF_Rect { + #[allow(non_local_definitions)] impl From<&Rect> for GF_Rect { fn from(rect: &Rect) -> Self { // XXX: screen to world coordinates Self { x: rect.x.into(), y: (rect.y + rect.h).into(), width: rect.w.into(), height: rect.h .into(), } @@ -156,7 +156,7 @@ fn process_segcmd(path: &VGPath, cmd: &SegInstr) { } fn style_to_stencil(img: &TinyVG, style: &Style) -> Stencil { - impl From for GF_Color { + #[allow(non_local_definitions)] impl From for GF_Color { fn from(color: RGBA8888) -> Self { // convert to 0xAARRGGBB (color.a as u32) << 24 | (color.r as u32) << 16 | (color.g as u32) << 8 | color.b as u32 diff --git a/src/tinyvg.rs b/src/tinyvg.rs index 0420f0c..fc2f693 100644 --- a/src/tinyvg.rs +++ b/src/tinyvg.rs @@ -66,7 +66,6 @@ impl From for TVGError { /// /// https://tinyvg.tech/download/specification.txt, https://github.com/TinyVG/sdk, /// https://github.com/lily-mara/tinyvg-rs, https://github.com/dataphract/tinyvg-rs - pub struct TinyVG { pub header: Header, // In-memory representation of a TinyVG file pub color_table: Vec, // colors used in this image diff --git a/tests/intvg.rs b/tests/intvg.rs index 2633da2..096773b 100644 --- a/tests/intvg.rs +++ b/tests/intvg.rs @@ -33,8 +33,8 @@ #[cfg(feature = "b2d")] intvg::render_b2d::Render::render(&tvg, 1.0)?; img.save_png(format!("target/{}.png", stem))?; - TVGImage::load_data(&mut BufReader::new(File::open(&tvgf)?)).map_err( - |err| { eprintln!("Fail to load `{}'", &tvgf); err })?; + TVGImage::load_data(&mut BufReader::new(File::open(&tvgf)?)).inspect_err( + |_| eprintln!("Fail to load `{}'", &tvgf))?; } Ok(()) }