diff --git a/Cargo.lock b/Cargo.lock index 1f80fa3..1b9a6e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,6 +42,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + [[package]] name = "ash" version = "0.33.3+1.2.191" @@ -596,7 +602,16 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16cb54cd28cb3d2e964d9444ca185676a94fd9b7cce5f02b22c717947ed8e9a2" dependencies = [ - "arrayvec", + "arrayvec 0.5.2", +] + +[[package]] +name = "kurbo" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a53776d271cfb873b17c618af0298445c88afc52837f3e948fa3fafd131f449" +dependencies = [ + "arrayvec 0.7.2", ] [[package]] @@ -755,8 +770,7 @@ dependencies = [ [[package]] name = "moscato" version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8372f6cdc8b2c431750a9c4edbc8d9c511ef1a68472aaa02500493414a407c64" +source = "git+https://github.com/dfrg/pinot#59db153ff83420449a909dfaace18466bddbf814" dependencies = [ "pinot", ] @@ -954,7 +968,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f00543608fb5ee6063f5ff1259246ae23073c1a5e413e643d0469da3d4b7b4de" dependencies = [ - "kurbo", + "kurbo 0.7.1", "unic-bidi", ] @@ -1012,7 +1026,7 @@ version = "0.1.0" dependencies = [ "bytemuck", "clap", - "kurbo", + "kurbo 0.7.1", "piet-gpu", "piet-gpu-hal", "rand", @@ -1031,8 +1045,8 @@ name = "piet-scene" version = "0.1.0" dependencies = [ "bytemuck", + "kurbo 0.8.3", "moscato", - "pinot", "smallvec", ] diff --git a/piet-scene/Cargo.toml b/piet-scene/Cargo.toml index df66483..e80cbb8 100644 --- a/piet-scene/Cargo.toml +++ b/piet-scene/Cargo.toml @@ -7,5 +7,5 @@ edition = "2021" [dependencies] bytemuck = { version = "1.7.2", features = ["derive"] } smallvec = "1.8.0" -pinot = "0.1.5" -moscato = "0.1.2" +moscato = { git = "https://github.com/dfrg/pinot" } +kurbo = { version = "0.8.3", optional = true } diff --git a/piet-scene/src/glyph/mod.rs b/piet-scene/src/glyph/mod.rs index 3bfa36c..690873c 100644 --- a/piet-scene/src/glyph/mod.rs +++ b/piet-scene/src/glyph/mod.rs @@ -14,7 +14,7 @@ // // Also licensed under MIT license, at your choice. -pub use pinot; +pub use moscato::pinot; use crate::brush::{Brush, Color}; use crate::geometry::Affine; diff --git a/piet-scene/src/lib.rs b/piet-scene/src/lib.rs index a72ff54..4f8da3d 100644 --- a/piet-scene/src/lib.rs +++ b/piet-scene/src/lib.rs @@ -20,3 +20,96 @@ pub mod glyph; pub mod path; pub mod resource; pub mod scene; + +/// Implement conversions to and from Kurbo types when the `kurbo` feature is +/// enabled. +#[cfg(feature = "kurbo")] +mod kurbo_conv { + use super::geometry::{Affine, Point, Rect}; + use super::path::Element; + + impl From for Point { + fn from(p: kurbo::Point) -> Self { + Self::new(p.x as f32, p.y as f32) + } + } + + impl From for kurbo::Point { + fn from(p: Point) -> kurbo::Point { + Self::new(p.x as f64, p.y as f64) + } + } + + impl From for Affine { + fn from(a: kurbo::Affine) -> Self { + let c = a.as_coeffs(); + Self { + xx: c[0] as f32, + yx: c[1] as f32, + xy: c[2] as f32, + yy: c[3] as f32, + dx: c[4] as f32, + dy: c[5] as f32, + } + } + } + + impl From for kurbo::Affine { + fn from(a: Affine) -> Self { + Self::new([ + a.xx as f64, + a.yx as f64, + a.yx as f64, + a.yy as f64, + a.dx as f64, + a.dy as f64, + ]) + } + } + + impl From for Rect { + fn from(r: kurbo::Rect) -> Self { + Self { + min: Point::new(r.x0 as f32, r.y0 as f32), + max: Point::new(r.x1 as f32, r.y1 as f32), + } + } + } + + impl From for kurbo::Rect { + fn from(r: Rect) -> Self { + Self { + x0: r.min.x as f64, + y0: r.min.y as f64, + x1: r.max.x as f64, + y1: r.max.y as f64, + } + } + } + + impl From for Element { + fn from(e: kurbo::PathEl) -> Self { + use kurbo::PathEl::*; + match e { + MoveTo(p0) => Self::MoveTo(p0.into()), + LineTo(p0) => Self::LineTo(p0.into()), + QuadTo(p0, p1) => Self::QuadTo(p0.into(), p1.into()), + CurveTo(p0, p1, p2) => Self::CurveTo(p0.into(), p1.into(), p2.into()), + ClosePath => Self::Close, + } + } + } + + impl From for kurbo::PathEl { + fn from(e: Element) -> Self { + use Element::*; + match e { + MoveTo(p0) => Self::MoveTo(p0.into()), + LineTo(p0) => Self::LineTo(p0.into()), + QuadTo(p0, p1) => Self::QuadTo(p0.into(), p1.into()), + CurveTo(p0, p1, p2) => Self::CurveTo(p0.into(), p1.into(), p2.into()), + Close => Self::ClosePath, + } + } + } +}