diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index f3ac6121f..93ecc592b 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -31,7 +31,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: run - args: --manifest-path=piet-cairo/Cargo.toml --example=test-picture -- --all --out=cairo_samples --compare=./piet/snapshots/cairo + args: --bin samples-cairo --features cairo -- --all --out=cairo_samples --compare=./piet-test/snapshots/cairo if: contains(matrix.os, 'ubuntu') - name: upload failures (ubuntu+cairo) @@ -45,7 +45,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: run - args: --manifest-path=piet-coregraphics/Cargo.toml --example=test-picture -- --all --out=coregraphics_samples --compare=./piet/snapshots/coregraphics + args: --bin samples-coregraphics --features coregraphics -- --all --out=coregraphics_samples --compare=./piet-test/snapshots/coregraphics if: contains(matrix.os, 'macOS') - name: upload failures (macOS) @@ -59,7 +59,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: run - args: --manifest-path=piet-direct2d/Cargo.toml --example=test-picture -- --all --out=d2d_samples --compare=./piet/snapshots/d2d + args: --bin samples-direct2d --features direct2d -- --all --out=d2d_samples --compare=./piet-test/snapshots/d2d if: contains(matrix.os, 'windows') - name: upload failures (d2d) diff --git a/.gitmodules b/.gitmodules index d055c48a2..77d77886b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "snapshots"] - path = piet/snapshots + path = piet-test/snapshots url = https://github.com/linebender/piet-snapshots.git diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 11879ef42..8a582d615 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ Piet uses 'snapshot testing' to verify that changes do not unexpectedly modify behaviour. During CI, sample pictures are generated by the various `picture_{}` -files in `piet`'s [`samples`] module, and the results are compared against +files in the [`piet-test`] crate, and the results are compared against previously generated versions. The previously generated versions are stored in a separate repository, @@ -29,6 +29,6 @@ or @raphlinus (or another administrator) to set it up for you. `piet-snapshots`. Rebasing would cause the revision to be rewritten, which would mean that the commit referenced by the submodule would no longer exist. -[`samples`]: https://github.com/linebender/piet/tree/master/piet/src/samples +[`piet-test`]: https://github.com/linebender/piet/tree/master/piet-test [`piet-snapshots`]: https://github.com/linebender/piet-snapshots [persisting workflow data using artifacts]: https://docs.github.com/en/actions/configuring-and-managing-workflows/persisting-workflow-data-using-artifacts diff --git a/Cargo.toml b/Cargo.toml index 3d17ec591..c97d669ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,5 +16,6 @@ default-members = [ "piet-common", "piet-web", "piet-web/examples/basic", - "piet-svg" + "piet-svg", + "piet-test" ] diff --git a/piet-cairo/Cargo.toml b/piet-cairo/Cargo.toml index 80b55cb87..06abc0388 100644 --- a/piet-cairo/Cargo.toml +++ b/piet-cairo/Cargo.toml @@ -1,27 +1,26 @@ [package] name = "piet-cairo" version = "0.5.0" +edition = "2018" authors = ["Raph Levien "] description = "Cairo backend for piet 2D graphics abstraction." +readme = "../README.md" license = "MIT/Apache-2.0" repository = "https://github.com/linebender/piet" -readme = "../README.md" -edition = "2018" keywords = ["graphics", "2d"] categories = ["rendering::graphics-api"] [dependencies] piet = { version = "=0.5.0", path = "../piet" } +xi-unicode = "0.3.0" +unicode-segmentation = "1.3.0" + cairo-rs = { version = "0.15.1", default-features = false } # We don't need glib pango = { version = "0.15.2", features = ["v1_44"] } pangocairo = "0.15.1" -unicode-segmentation = "1.3.0" -xi-unicode = "0.3.0" [dev-dependencies] -piet = { version = "=0.5.0", path = "../piet", features = ["samples"] } -cairo-rs = { version = "0.15.1", default-features = false, features = ["png"] } criterion = "0.3" [[bench]] diff --git a/piet-common/Cargo.toml b/piet-common/Cargo.toml index 4697bc124..8100621ec 100644 --- a/piet-common/Cargo.toml +++ b/piet-common/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "piet-common" version = "0.5.0" +edition = "2018" authors = ["Raph Levien "] description = "Selection of a single preferred back-end for piet" +readme = "README.md" license = "MIT/Apache-2.0" repository = "https://github.com/linebender/piet" -readme = "README.md" -edition = "2018" keywords = ["graphics", "2d"] [features] @@ -35,6 +35,7 @@ serde = ["piet/serde"] [dependencies] piet = { version = "=0.5.0", path = "../piet" } piet-web = { version = "=0.5.0", path = "../piet-web", optional = true } + cfg-if = "1.0" png = { version = "0.17", optional = true } diff --git a/piet-coregraphics/Cargo.toml b/piet-coregraphics/Cargo.toml index 40274df83..e8f84e2c0 100644 --- a/piet-coregraphics/Cargo.toml +++ b/piet-coregraphics/Cargo.toml @@ -1,25 +1,22 @@ [package] name = "piet-coregraphics" version = "0.5.0" +edition = "2018" authors = ["Jeff Muizelaar , Raph Levien , Colin Rofls "] description = "CoreGraphics backend for piet 2D graphics abstraction." +readme = "../README.md" license = "MIT/Apache-2.0" repository = "https://github.com/linebender/piet" -readme = "../README.md" -edition = "2018" keywords = ["graphics", "2d"] categories = ["rendering::graphics-api"] [dependencies] piet = { version = "=0.5.0", path = "../piet" } +associative-cache = "1.0" + foreign-types = "0.3.2" core-graphics = "0.22.2" core-text = "19.0.0" core-foundation = "0.9" core-foundation-sys = "0.8" -associative-cache = "1.0" - -[dev-dependencies] -piet = { version = "=0.5.0", path = "../piet", features = ["samples"] } -png = "0.17" diff --git a/piet-direct2d/Cargo.toml b/piet-direct2d/Cargo.toml index e472e7420..28608040e 100644 --- a/piet-direct2d/Cargo.toml +++ b/piet-direct2d/Cargo.toml @@ -1,24 +1,21 @@ [package] name = "piet-direct2d" version = "0.5.0" +edition = "2018" authors = ["Raph Levien "] description = "Direct2D backend for piet 2D graphics abstraction." +readme = "../README.md" license = "MIT/Apache-2.0" repository = "https://github.com/linebender/piet" -readme = "../README.md" -edition = "2018" keywords = ["graphics", "2d"] categories = ["rendering::graphics-api"] [dependencies] piet = { version = "=0.5.0", path = "../piet" } + utf16_lit = "2.0" associative-cache = "1.0" wio = "0.2.2" winapi = { version = "0.3.8", features = ["d2d1", "d2d1_1", "d2d1effects", "d2dbasetypes", "dcommon", "d3d11", "dxgi", "winnls"] } dwrote = { version = "0.11.0", default_features = false } - -[dev-dependencies] -piet = { version = "=0.5.0", path = "../piet", features = ["samples"] } -image = "0.24.0" diff --git a/piet-svg/Cargo.toml b/piet-svg/Cargo.toml index ff54d42ac..dcf1626f1 100644 --- a/piet-svg/Cargo.toml +++ b/piet-svg/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "piet-svg" version = "0.5.0" +edition = "2018" authors = ["Benjamin Saunders "] description = "SVG backend for piet 2D graphics abstraction." -edition = "2018" +readme = "../README.md" license = "MIT/Apache-2.0" repository = "https://github.com/linebender/piet" keywords = ["graphics", "2d"] @@ -14,13 +15,14 @@ default = [] evcxr = ["evcxr_runtime"] [dependencies] +piet = { version = "=0.5.0", path = "../piet" } + +svg = "0.10.0" base64 = "0.13.0" -evcxr_runtime = { version = "1.1.0", optional = true } font-kit = "0.10.1" -image = { version = "0.24.0", default-features = false, features = ["png"] } -piet = { version = "=0.5.0", path = "../piet" } rustybuzz = "0.4.0" -svg = "0.10.0" +evcxr_runtime = { version = "1.1.0", optional = true } +image = { version = "0.24.0", default-features = false, features = ["png"] } [dev-dependencies] -piet = { version = "=0.5.0", path = "../piet", features = ["samples"] } +piet-test = { path = "../piet-test" } diff --git a/piet-svg/examples/basic-svg.rs b/piet-svg/examples/basic-svg.rs index 201ad6675..ea38f3eb5 100644 --- a/piet-svg/examples/basic-svg.rs +++ b/piet-svg/examples/basic-svg.rs @@ -2,7 +2,8 @@ use std::io; -use piet::{samples, RenderContext}; +use piet::RenderContext; +use piet_test::samples; fn main() { let test_picture_number = std::env::args() diff --git a/piet-test/Cargo.toml b/piet-test/Cargo.toml new file mode 100644 index 000000000..3b167a404 --- /dev/null +++ b/piet-test/Cargo.toml @@ -0,0 +1,37 @@ +[package] +name = "piet-test" +version = "0.0.0" +edition = "2018" +publish = false + +[[bin]] +name = "samples-cairo" +required-features = ["cairo"] + +[[bin]] +name = "samples-direct2d" +required-features = ["direct2d"] + +[[bin]] +name = "samples-coregraphics" +required-features = ["coregraphics"] + +[features] +cairo = ["piet-cairo", "cairo-rs"] +direct2d = ["piet-direct2d", "winapi"] +coregraphics = ["piet-coregraphics", "core-graphics"] + +[dependencies] +piet = { path = "../piet" } +piet-cairo = { path = "../piet-cairo", optional = true } +piet-direct2d = { path = "../piet-direct2d", optional = true } +piet-coregraphics = { path = "../piet-coregraphics", optional = true } + +png = "0.17" +pico-args = "0.4.0" +os_info = { version = "3.0.0", default-features = false } +image = { version = "0.24", default-features = false, features = ["png"] } + +core-graphics = { version = "0.22.2", optional = true } +winapi = { version = "0.3.8", features = ["dxgi"], optional = true } +cairo-rs = { version = "0.15.1", default-features = false, features = ["png"], optional = true } diff --git a/piet-test/README.md b/piet-test/README.md new file mode 100644 index 000000000..84b9736fa --- /dev/null +++ b/piet-test/README.md @@ -0,0 +1,3 @@ +# piet-test: Sample images and common tests + +See [CONTRIBUTING.md](../CONTRIBUTING.md) on instructions on updating the reference snapshots. diff --git a/piet-test/snapshots b/piet-test/snapshots new file mode 160000 index 000000000..b251dc46b --- /dev/null +++ b/piet-test/snapshots @@ -0,0 +1 @@ +Subproject commit b251dc46b75ed13b0d685405b4618dfc8ae931f9 diff --git a/piet-cairo/examples/test-picture.rs b/piet-test/src/bin/samples-cairo.rs similarity index 94% rename from piet-cairo/examples/test-picture.rs rename to piet-test/src/bin/samples-cairo.rs index 18d59690e..12826c6fa 100644 --- a/piet-cairo/examples/test-picture.rs +++ b/piet-test/src/bin/samples-cairo.rs @@ -6,15 +6,16 @@ use std::process::Command; use cairo::{Context, Format, ImageSurface}; -use piet::{samples, RenderContext}; +use piet::RenderContext; use piet_cairo::CairoRenderContext; +use piet_test::samples; const HIDPI: f64 = 2.0; const FILE_PREFIX: &str = "cairo-test-"; fn main() { let sys_info = additional_system_info(); - samples::samples_main(run_sample, FILE_PREFIX, Some(&sys_info)); + samples::samples_main("samples-cairo", run_sample, FILE_PREFIX, Some(&sys_info)); } fn run_sample(idx: usize, base_dir: &Path) -> Result<(), Box> { diff --git a/piet-coregraphics/examples/test-picture.rs b/piet-test/src/bin/samples-coregraphics.rs similarity index 69% rename from piet-coregraphics/examples/test-picture.rs rename to piet-test/src/bin/samples-coregraphics.rs index 0d2bac281..690ee8b40 100644 --- a/piet-coregraphics/examples/test-picture.rs +++ b/piet-test/src/bin/samples-coregraphics.rs @@ -8,14 +8,15 @@ use core_graphics::color_space::CGColorSpace; use core_graphics::context::CGContext; use piet::kurbo::Size; -use piet::{samples, RenderContext}; +use piet::RenderContext; use piet_coregraphics::CoreGraphicsContext; +use piet_test::samples; const SCALE: f64 = 2.0; const FILE_PREFIX: &str = "coregraphics-test-"; fn main() { - samples::samples_main(run_sample, FILE_PREFIX, None); + samples::samples_main("samples-coregraphics", run_sample, FILE_PREFIX, None); } fn run_sample(idx: usize, base_dir: &Path) -> Result<(), Box> { @@ -33,17 +34,18 @@ fn run_sample(idx: usize, base_dir: &Path) -> Result<(), Box CGContext { diff --git a/piet-direct2d/examples/test-picture.rs b/piet-test/src/bin/samples-direct2d.rs similarity index 96% rename from piet-direct2d/examples/test-picture.rs rename to piet-test/src/bin/samples-direct2d.rs index 1562d96fd..756bc641a 100644 --- a/piet-direct2d/examples/test-picture.rs +++ b/piet-test/src/bin/samples-direct2d.rs @@ -4,14 +4,15 @@ use std::path::Path; use winapi::shared::dxgi::DXGI_MAP_READ; -use piet::{samples, RenderContext}; +use piet::RenderContext; use piet_direct2d::{D2DRenderContext, D2DText}; +use piet_test::samples; const HIDPI: f32 = 2.0; const FILE_PREFIX: &str = "d2d-test-"; fn main() { - samples::samples_main(run_sample, FILE_PREFIX, None); + samples::samples_main("samples-direct2d", run_sample, FILE_PREFIX, None); } fn run_sample(number: usize, base_dir: &Path) -> Result<(), Box> { diff --git a/piet-test/src/lib.rs b/piet-test/src/lib.rs new file mode 100644 index 000000000..876357560 --- /dev/null +++ b/piet-test/src/lib.rs @@ -0,0 +1 @@ +pub mod samples; diff --git a/piet/src/samples/mod.rs b/piet-test/src/samples/mod.rs similarity index 96% rename from piet/src/samples/mod.rs rename to piet-test/src/samples/mod.rs index 263a9f4dc..b8a6bd4cb 100644 --- a/piet/src/samples/mod.rs +++ b/piet-test/src/samples/mod.rs @@ -7,8 +7,8 @@ use std::fs::File; use std::io::BufWriter; use std::path::{Path, PathBuf}; -use crate::kurbo::Size; -use crate::{Error, RenderContext}; +use piet::kurbo::Size; +use piet::{Error, RenderContext}; mod picture_0; mod picture_1; @@ -85,6 +85,7 @@ struct Args { /// testing environment, such as the versions of various dependencies; this /// will be appended to the GENERATED_BY file. pub fn samples_main( + binary: &str, f: fn(usize, &Path) -> Result<(), BoxErr>, prefix: &str, env_info: Option<&str>, @@ -94,7 +95,7 @@ pub fn samples_main( if args.help { eprintln!("Piet Sample Image Generator\n"); - print_help_text(); + print_help_text(binary); std::process::exit(1); } @@ -144,7 +145,7 @@ pub fn samples_main( eprintln!("caused by: {}", err); e = err; } - print_help_text(); + print_help_text(binary); std::process::exit(1); } else { std::process::exit(0); @@ -181,7 +182,7 @@ impl Args { }; if !(args.help || args.all || args.number.is_some() || args.compare_dir.is_some()) { - Err(Box::new(Error::InvalidSampleArgs)) + Err("Must pass either --all or a number".into()) } else { Ok(args) } @@ -411,16 +412,16 @@ impl std::fmt::Display for FailureReason { } } -fn print_help_text() { +fn print_help_text(binary: &str) { eprintln!( "Options: -$ ./test_picture {{ | --all}} [--out=] [--compare=] [--help] +$ ./{binary} {{ | --all}} [--out=] [--compare=] [--help] Required Args --all | If 'all', generate all the example pictures. If a number, then generate that number picture (number must be between - 0 and {} + 0 and {sample_idx_max} Optional Args --out= Save the results to the directory 'dir'. Defaults to the @@ -432,6 +433,7 @@ Optional Args Flags --help Print this help message and exit. ", - SAMPLE_COUNT - 1 + binary = binary, + sample_idx_max = SAMPLE_COUNT - 1 ); } diff --git a/piet/src/samples/picture_0.rs b/piet-test/src/samples/picture_0.rs similarity index 97% rename from piet/src/samples/picture_0.rs rename to piet-test/src/samples/picture_0.rs index edc470263..2a9b770d2 100644 --- a/piet/src/samples/picture_0.rs +++ b/piet-test/src/samples/picture_0.rs @@ -1,7 +1,7 @@ //! A wide assortment of graphics meant to show off many different uses of piet -use crate::kurbo::{Affine, BezPath, Line, Point, Rect, RoundedRect, Size, Vec2}; -use crate::{ +use piet::kurbo::{Affine, BezPath, Line, Point, Rect, RoundedRect, Size, Vec2}; +use piet::{ Color, Error, FontFamily, ImageFormat, InterpolationMode, RenderContext, Text, TextAttribute, TextLayout, TextLayoutBuilder, }; diff --git a/piet/src/samples/picture_1.rs b/piet-test/src/samples/picture_1.rs similarity index 95% rename from piet/src/samples/picture_1.rs rename to piet-test/src/samples/picture_1.rs index 632b38fde..7b8a4b0ff 100644 --- a/piet/src/samples/picture_1.rs +++ b/piet-test/src/samples/picture_1.rs @@ -1,7 +1,7 @@ //! Rendering a cubic Bézier curve with its control points and handles -use crate::kurbo::{BezPath, Line, Point, Size}; -use crate::{Color, Error, RenderContext}; +use piet::kurbo::{BezPath, Line, Point, Size}; +use piet::{Color, Error, RenderContext}; pub const SIZE: Size = Size::new(400., 200.); diff --git a/piet/src/samples/picture_10.rs b/piet-test/src/samples/picture_10.rs similarity index 87% rename from piet/src/samples/picture_10.rs rename to piet-test/src/samples/picture_10.rs index 90cf6f38e..888eb9662 100644 --- a/piet/src/samples/picture_10.rs +++ b/piet-test/src/samples/picture_10.rs @@ -1,7 +1,7 @@ //! Show the relationship between the layout rect and the inking/image rect. -use crate::kurbo::{Size, Vec2}; -use crate::{Color, Error, RenderContext, Text, TextAttribute, TextLayout, TextLayoutBuilder}; +use piet::kurbo::{Size, Vec2}; +use piet::{Color, Error, RenderContext, Text, TextAttribute, TextLayout, TextLayoutBuilder}; pub const SIZE: Size = Size::new(400., 400.); diff --git a/piet/src/samples/picture_11.rs b/piet-test/src/samples/picture_11.rs similarity index 90% rename from piet/src/samples/picture_11.rs rename to piet-test/src/samples/picture_11.rs index da363c289..c6f42c326 100644 --- a/piet/src/samples/picture_11.rs +++ b/piet-test/src/samples/picture_11.rs @@ -1,7 +1,7 @@ //! Visualize results of hit-testing -use crate::kurbo::{Circle, Line, Point, Size}; -use crate::{Color, Error, RenderContext, Text, TextLayout, TextLayoutBuilder}; +use piet::kurbo::{Circle, Line, Point, Size}; +use piet::{Color, Error, RenderContext, Text, TextLayout, TextLayoutBuilder}; pub const SIZE: Size = Size::new(880., 800.); pub const DOT_RADIUS: f64 = 2.0; @@ -20,25 +20,25 @@ pub fn draw(rc: &mut R) -> Result<(), Error> { let layout_en_start = rc .text() .new_text_layout(TEXT_EN) - .alignment(crate::TextAlignment::Start) + .alignment(piet::TextAlignment::Start) .max_width(200.0) .build()?; let layout_en_center = rc .text() .new_text_layout(TEXT_EN) - .alignment(crate::TextAlignment::Center) + .alignment(piet::TextAlignment::Center) .max_width(200.0) .build()?; let layout_ar_start = rc .text() .new_text_layout(TEXT_AR) - .alignment(crate::TextAlignment::Start) + .alignment(piet::TextAlignment::Start) .max_width(200.0) .build()?; let layout_ar_just = rc .text() .new_text_layout(TEXT_AR) - .alignment(crate::TextAlignment::Justified) + .alignment(piet::TextAlignment::Justified) .max_width(200.0) .build()?; let ar_y = ((SIZE.height - layout_ar_start.size().height * 2.0) / 2.0 - 32.0).max(0.0); diff --git a/piet/src/samples/picture_12.rs b/piet-test/src/samples/picture_12.rs similarity index 97% rename from piet/src/samples/picture_12.rs rename to piet-test/src/samples/picture_12.rs index ecfdb8a8b..40742edee 100644 --- a/piet/src/samples/picture_12.rs +++ b/piet-test/src/samples/picture_12.rs @@ -1,7 +1,7 @@ //! range attributes should override default attributes -use crate::kurbo::{Size, Vec2}; -use crate::{ +use piet::kurbo::{Size, Vec2}; +use piet::{ Color, Error, FontFamily, RenderContext, Text, TextAttribute, TextLayout, TextLayoutBuilder, }; diff --git a/piet/src/samples/picture_13.rs b/piet-test/src/samples/picture_13.rs similarity index 97% rename from piet/src/samples/picture_13.rs rename to piet-test/src/samples/picture_13.rs index 1750fdf60..5100fc2aa 100644 --- a/piet/src/samples/picture_13.rs +++ b/piet-test/src/samples/picture_13.rs @@ -1,7 +1,7 @@ //! Using custom font families. -use crate::kurbo::{Size, Vec2}; -use crate::{ +use piet::kurbo::{Size, Vec2}; +use piet::{ Color, Error, FontFamily, FontStyle, FontWeight, RenderContext, Text, TextLayout, TextLayoutBuilder, }; diff --git a/piet/src/samples/picture_14.rs b/piet-test/src/samples/picture_14.rs similarity index 96% rename from piet/src/samples/picture_14.rs rename to piet-test/src/samples/picture_14.rs index 297b1e48a..0add543ce 100644 --- a/piet/src/samples/picture_14.rs +++ b/piet-test/src/samples/picture_14.rs @@ -1,7 +1,7 @@ //! Setting font weight when a variable font has a 'wght' axis -use crate::kurbo::{Size, Vec2}; -use crate::{ +use piet::kurbo::{Size, Vec2}; +use piet::{ Color, Error, FontFamily, FontWeight, RenderContext, Text, TextLayout, TextLayoutBuilder, }; diff --git a/piet/src/samples/picture_15.rs b/piet-test/src/samples/picture_15.rs similarity index 96% rename from piet/src/samples/picture_15.rs rename to piet-test/src/samples/picture_15.rs index 337beb0a6..4330e5e4d 100644 --- a/piet/src/samples/picture_15.rs +++ b/piet-test/src/samples/picture_15.rs @@ -4,8 +4,8 @@ //! //! 1. clear ignores clipping and transforms -use crate::kurbo::{Affine, Circle, Rect, Size}; -use crate::{Color, Error, RenderContext}; +use piet::kurbo::{Affine, Circle, Rect, Size}; +use piet::{Color, Error, RenderContext}; pub const SIZE: Size = Size::new(400., 400.); diff --git a/piet/src/samples/picture_2.rs b/piet-test/src/samples/picture_2.rs similarity index 93% rename from piet/src/samples/picture_2.rs rename to piet-test/src/samples/picture_2.rs index 3309f5d96..52d130fef 100644 --- a/piet/src/samples/picture_2.rs +++ b/piet-test/src/samples/picture_2.rs @@ -1,7 +1,7 @@ //! A bunch of image test cases. -use crate::kurbo::{Rect, Size}; -use crate::{Color, Error, ImageFormat, InterpolationMode, RenderContext}; +use piet::kurbo::{Rect, Size}; +use piet::{Color, Error, ImageFormat, InterpolationMode, RenderContext}; pub const SIZE: Size = Size::new(400., 200.); @@ -67,6 +67,7 @@ fn make_image_data(width: usize, height: usize, format: ImageFormat) -> Vec result[ix + 2] = b; } ImageFormat::Grayscale => result[ix] = a, + other => unimplemented!("image format: {:?}", other), } } } diff --git a/piet/src/samples/picture_3.rs b/piet-test/src/samples/picture_3.rs similarity index 91% rename from piet/src/samples/picture_3.rs rename to piet-test/src/samples/picture_3.rs index 7d8c44313..6a811bd54 100644 --- a/piet/src/samples/picture_3.rs +++ b/piet-test/src/samples/picture_3.rs @@ -1,7 +1,7 @@ //! Rendering stroke styles. -use crate::kurbo::{Affine, BezPath, Line, Size}; -use crate::{Color, Error, LineCap, LineJoin, RenderContext, StrokeStyle}; +use piet::kurbo::{Affine, BezPath, Line, Size}; +use piet::{Color, Error, LineCap, LineJoin, RenderContext, StrokeStyle}; pub const SIZE: Size = Size::new(400., 200.); diff --git a/piet/src/samples/picture_4.rs b/piet-test/src/samples/picture_4.rs similarity index 95% rename from piet/src/samples/picture_4.rs rename to piet-test/src/samples/picture_4.rs index 6c16c5380..7e225b8cd 100644 --- a/piet/src/samples/picture_4.rs +++ b/piet-test/src/samples/picture_4.rs @@ -1,7 +1,7 @@ //! Gradients. -use crate::kurbo::{Point, Rect, Size, Vec2}; -use crate::{ +use piet::kurbo::{Point, Rect, Size, Vec2}; +use piet::{ Color, Error, FixedGradient, FixedLinearGradient, FixedRadialGradient, GradientStop, RenderContext, }; diff --git a/piet/src/samples/picture_5.rs b/piet-test/src/samples/picture_5.rs similarity index 97% rename from piet/src/samples/picture_5.rs rename to piet-test/src/samples/picture_5.rs index 2c7f5ad99..b738eedc0 100644 --- a/piet/src/samples/picture_5.rs +++ b/piet-test/src/samples/picture_5.rs @@ -1,7 +1,7 @@ //! range attributes should override default attributes -use crate::kurbo::{Size, Vec2}; -use crate::{ +use piet::kurbo::{Size, Vec2}; +use piet::{ Color, Error, FontFamily, FontStyle, FontWeight, RenderContext, Text, TextAttribute, TextLayout, TextLayoutBuilder, }; diff --git a/piet/src/samples/picture_6.rs b/piet-test/src/samples/picture_6.rs similarity index 97% rename from piet/src/samples/picture_6.rs rename to piet-test/src/samples/picture_6.rs index 59f052217..bf66cee72 100644 --- a/piet/src/samples/picture_6.rs +++ b/piet-test/src/samples/picture_6.rs @@ -1,7 +1,7 @@ //! Gradients. -use crate::kurbo::{Circle, Point, Rect, RoundedRect, Size, Vec2}; -use crate::{ +use piet::kurbo::{Circle, Point, Rect, RoundedRect, Size, Vec2}; +use piet::{ Color, Error, FixedGradient, FixedLinearGradient, FixedRadialGradient, GradientStop, LineCap, LineJoin, RenderContext, StrokeStyle, }; diff --git a/piet/src/samples/picture_7.rs b/piet-test/src/samples/picture_7.rs similarity index 96% rename from piet/src/samples/picture_7.rs rename to piet-test/src/samples/picture_7.rs index 168c3a381..d92d6bad5 100644 --- a/piet/src/samples/picture_7.rs +++ b/piet-test/src/samples/picture_7.rs @@ -1,7 +1,7 @@ //! Text layouts -use crate::kurbo::{Rect, Size}; -use crate::{Color, Error, RenderContext, Text, TextAlignment, TextAttribute, TextLayoutBuilder}; +use piet::kurbo::{Rect, Size}; +use piet::{Color, Error, RenderContext, Text, TextAlignment, TextAttribute, TextLayoutBuilder}; pub const SIZE: Size = Size::new(800., 800.); static SAMPLE_EN: &str = r#"This essay is an effort to build an ironic political myth faithful to feminism, socialism, and materialism. Perhaps more faithful as blasphemy is faithful, than as reverent worship and identification. Blasphemy has always seemed to require taking things very seriously. I know no better stance to adopt from within the secular-religious, evangelical traditions of United States politics, including the politics of socialist-feminism."#; diff --git a/piet/src/samples/picture_8.rs b/piet-test/src/samples/picture_8.rs similarity index 98% rename from piet/src/samples/picture_8.rs rename to piet-test/src/samples/picture_8.rs index 94fef9b52..00ac8c15c 100644 --- a/piet/src/samples/picture_8.rs +++ b/piet-test/src/samples/picture_8.rs @@ -1,7 +1,7 @@ //! Styled text -use crate::kurbo::Size; -use crate::{ +use piet::kurbo::Size; +use piet::{ Color, Error, FontFamily, FontStyle, FontWeight, RenderContext, Text, TextAlignment, TextAttribute, TextLayoutBuilder, }; diff --git a/piet/src/samples/picture_9.rs b/piet-test/src/samples/picture_9.rs similarity index 97% rename from piet/src/samples/picture_9.rs rename to piet-test/src/samples/picture_9.rs index 171cef274..af7ca1a20 100644 --- a/piet/src/samples/picture_9.rs +++ b/piet-test/src/samples/picture_9.rs @@ -1,7 +1,7 @@ //! Verifying line metrics and text layout geometry behave as intended. -use crate::kurbo::{Line, Size, Vec2}; -use crate::{ +use piet::kurbo::{Line, Size, Vec2}; +use piet::{ Color, Error, FontFamily, RenderContext, Text, TextAlignment, TextAttribute, TextLayout, TextLayoutBuilder, }; diff --git a/piet-web/Cargo.toml b/piet-web/Cargo.toml index 979584f47..e8b16964d 100644 --- a/piet-web/Cargo.toml +++ b/piet-web/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "piet-web" version = "0.5.0" +edition = "2018" authors = ["Raph Levien "] description = "Web canvas backend for piet 2D graphics abstraction." license = "MIT/Apache-2.0" repository = "https://github.com/linebender/piet" readme = "../README.md" -edition = "2018" keywords = ["graphics", "2d"] categories = ["rendering::graphics-api", "wasm"] diff --git a/piet-web/examples/basic/Cargo.toml b/piet-web/examples/basic/Cargo.toml index da17b734f..777faa322 100644 --- a/piet-web/examples/basic/Cargo.toml +++ b/piet-web/examples/basic/Cargo.toml @@ -11,12 +11,21 @@ crate-type = ["cdylib"] default = ["console_error_panic_hook"] [dependencies] -piet = { path = "../../../piet", features = ["samples"] } +piet = { path = "../../../piet" } piet-web = { path = "../.." } +piet-test = { path = "../../../piet-test" } wasm-bindgen = "0.2.30" console_error_panic_hook = { version = "0.1.6", optional = true } [dependencies.web-sys] version = "0.3.10" -features = ["console", "CanvasRenderingContext2d", "Window", "Document", "Element", "HtmlElement", "HtmlCanvasElement"] +features = [ + "console", + "CanvasRenderingContext2d", + "Window", + "Document", + "Element", + "HtmlElement", + "HtmlCanvasElement" +] diff --git a/piet-web/examples/basic/src/lib.rs b/piet-web/examples/basic/src/lib.rs index f38b95330..91ae3df3f 100644 --- a/piet-web/examples/basic/src/lib.rs +++ b/piet-web/examples/basic/src/lib.rs @@ -4,7 +4,8 @@ use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; use web_sys::{window, HtmlCanvasElement}; -use piet::{samples, RenderContext}; +use piet::RenderContext; +use piet_test::samples; use piet_web::WebRenderContext; //TODO: figure out how to dynamically select the sample? diff --git a/piet/Cargo.toml b/piet/Cargo.toml index 9291b7fef..65d974c2e 100644 --- a/piet/Cargo.toml +++ b/piet/Cargo.toml @@ -1,26 +1,22 @@ [package] name = "piet" +edition = "2018" version = "0.5.0" authors = ["Raph Levien "] description = "An abstraction for 2D graphics." +readme = "../README.md" license = "MIT/Apache-2.0" repository = "https://github.com/linebender/piet" -readme = "../README.md" -edition = "2018" keywords = ["graphics", "2d"] categories = ["rendering::graphics-api"] -include = ["src/**/*", "Cargo.toml", "snapshots/resources/*"] +include = ["src/**/*", "Cargo.toml"] [dependencies] image = { version = "0.24.0", optional = true, default-features = false } kurbo = "0.8.2" -pico-args = { version = "0.4.0", optional = true } -png = { version = "0.17", optional = true } -os_info = { version = "3.0.0", optional = true, default-features = false } unic-bidi = "0.9" [features] -samples = ["pico-args", "png", "os_info"] # passing on all the image features. AVIF is not supported because it does not # support decoding, and thats al we use `Image` for. diff --git a/piet/snapshots b/piet/snapshots deleted file mode 160000 index 4c3ab87f0..000000000 --- a/piet/snapshots +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4c3ab87f0b0461144fa844442f05d508d9e5ffc9 diff --git a/piet/src/error.rs b/piet/src/error.rs index effe299fe..72668983e 100644 --- a/piet/src/error.rs +++ b/piet/src/error.rs @@ -22,9 +22,6 @@ pub enum Error { MissingFont, /// Font data could not be loaded. FontLoadingFailed, - /// The arguments provided to the CLI were invalid. - #[cfg(feature = "samples")] - InvalidSampleArgs, } impl fmt::Display for Error { @@ -44,8 +41,6 @@ impl fmt::Display for Error { write!(f, "Backend error: ")?; e.fmt(f) } - #[cfg(feature = "samples")] - Error::InvalidSampleArgs => write!(f, "Must pass either --all or a number"), } } } diff --git a/piet/src/lib.rs b/piet/src/lib.rs index 9ca8d9cab..40d915ca6 100644 --- a/piet/src/lib.rs +++ b/piet/src/lib.rs @@ -40,9 +40,6 @@ mod render_context; mod shapes; mod text; -#[cfg(feature = "samples")] -pub mod samples; - pub use crate::color::*; pub use crate::conv::*; pub use crate::error::*;