Skip to content

Commit

Permalink
update, refined and fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mhfan committed Nov 30, 2024
1 parent dd36601 commit 2b43b16
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -58,6 +57,7 @@ jobs:
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
Cargo.lock
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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

Expand All @@ -72,5 +75,5 @@ panic = 'abort'
lto = 'fat' # true

[workspace]
#members = [ "wcnvs" ]
members = [ "wcnvs" ]

11 changes: 7 additions & 4 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ fn convert_nodes<R: io::Read, W: io::Write>(tvg: &mut TinyVG<R, W>,
}

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),
}
Expand All @@ -81,8 +82,9 @@ fn convert_nodes<R: io::Read, W: io::Write>(tvg: &mut TinyVG<R, W>,
}

fn convert_path(path: &skia::Path, trfm: &usvg::Transform) -> Vec<Segment> {
impl From<skia::Point> for Point { //unsafe { std::mem::transmute(pt) }
#[allow(non_local_definitions)] impl From<skia::Point> 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![]);
Expand Down Expand Up @@ -122,8 +124,9 @@ fn convert_paint<R: io::Read, W: io::Write>(tvg: &mut TinyVG<R, W>,
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
Expand Down
3 changes: 2 additions & 1 deletion src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<R: io::Read, W: io::Write> Render for TinyVG<R, W> {
line_cap: skia::LineCap::Round, ..Default::default() };
let err_msg = "Fail to build path";

impl From<Rect> for skia::Rect {
#[allow(non_local_definitions)] impl From<Rect> 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() }
Expand Down Expand Up @@ -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<R, W>,
style: &Style, trfm: skia::Transform) ->
Result<skia::Paint<'a>, &'static str> {
Expand Down
4 changes: 2 additions & 2 deletions src/render_b2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<R: io::Read, W: io::Write> Render for TinyVG<R, W> {
(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 _ }
Expand Down Expand Up @@ -160,7 +160,7 @@ fn process_segcmd(path: &mut BLPath, cmd: &SegInstr) {

fn convert_style<R: io::Read, W: io::Write>(img: &TinyVG<R, W>,
style: &Style) -> Box<dyn B2DStyle> {
impl From<RGBA8888> for BLRgba32 {
#[allow(non_local_definitions)] impl From<RGBA8888> 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
Expand Down
4 changes: 2 additions & 2 deletions src/render_evg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl<R: io::Read, W: io::Write> Render for TinyVG<R, W> {
(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(), }
Expand Down Expand Up @@ -156,7 +156,7 @@ fn process_segcmd(path: &VGPath, cmd: &SegInstr) {
}

fn style_to_stencil<R: io::Read, W: io::Write>(img: &TinyVG<R, W>, style: &Style) -> Stencil {
impl From<RGBA8888> for GF_Color {
#[allow(non_local_definitions)] impl From<RGBA8888> 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
Expand Down
1 change: 0 additions & 1 deletion src/tinyvg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ impl From<TryFromIntError> 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<R: io::Read, W: io::Write> {
pub header: Header, // In-memory representation of a TinyVG file
pub color_table: Vec<RGBA8888>, // colors used in this image
Expand Down
4 changes: 2 additions & 2 deletions tests/intvg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

0 comments on commit 2b43b16

Please sign in to comment.