Skip to content

Commit 83863c3

Browse files
committed
Move samples out of piet and into local crate
- Cargo manifests have been cleaned up a bit - `piet` now no longer includes fonts within the crate published, making it smaller - `piet::Error::InvalidSampleArgs` is removed, which is specific to samples
1 parent fb6b4b7 commit 83863c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+149
-106
lines changed

.github/workflows/snapshot.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
uses: actions-rs/cargo@v1
3232
with:
3333
command: run
34-
args: --manifest-path=piet-cairo/Cargo.toml --example=test-picture -- --all --out=cairo_samples --compare=./piet/snapshots/cairo
34+
args: --bin samples-cairo --features cairo -- --all --out=cairo_samples --compare=./piet-test/snapshots/cairo
3535
if: contains(matrix.os, 'ubuntu')
3636

3737
- name: upload failures (ubuntu+cairo)
@@ -45,7 +45,7 @@ jobs:
4545
uses: actions-rs/cargo@v1
4646
with:
4747
command: run
48-
args: --manifest-path=piet-coregraphics/Cargo.toml --example=test-picture -- --all --out=coregraphics_samples --compare=./piet/snapshots/coregraphics
48+
args: --bin samples-coregraphics --features coregraphics -- --all --out=coregraphics_samples --compare=./piet-test/snapshots/coregraphics
4949
if: contains(matrix.os, 'macOS')
5050

5151
- name: upload failures (macOS)
@@ -59,7 +59,7 @@ jobs:
5959
uses: actions-rs/cargo@v1
6060
with:
6161
command: run
62-
args: --manifest-path=piet-direct2d/Cargo.toml --example=test-picture -- --all --out=d2d_samples --compare=./piet/snapshots/d2d
62+
args: --bin samples-direct2d --features direct2d -- --all --out=d2d_samples --compare=./piet-test/snapshots/d2d
6363
if: contains(matrix.os, 'windows')
6464

6565
- name: upload failures (d2d)

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "snapshots"]
2-
path = piet/snapshots
2+
path = piet-test/snapshots
33
url = https://github.com/linebender/piet-snapshots.git

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Piet uses 'snapshot testing' to verify that changes do not unexpectedly modify
44
behaviour. During CI, sample pictures are generated by the various `picture_{}`
5-
files in `piet`'s [`samples`] module, and the results are compared against
5+
files in the [`piet-test`] crate, and the results are compared against
66
previously generated versions.
77

88
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.
2929
`piet-snapshots`. Rebasing would cause the revision to be rewritten, which would
3030
mean that the commit referenced by the submodule would no longer exist.
3131

32-
[`samples`]: https://github.com/linebender/piet/tree/master/piet/src/samples
32+
[`piet-test`]: https://github.com/linebender/piet/tree/master/piet-test
3333
[`piet-snapshots`]: https://github.com/linebender/piet-snapshots
3434
[persisting workflow data using artifacts]: https://docs.github.com/en/actions/configuring-and-managing-workflows/persisting-workflow-data-using-artifacts

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ default-members = [
1616
"piet-common",
1717
"piet-web",
1818
"piet-web/examples/basic",
19-
"piet-svg"
19+
"piet-svg",
20+
"piet-test"
2021
]

piet-cairo/Cargo.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
[package]
22
name = "piet-cairo"
33
version = "0.5.0"
4+
edition = "2018"
45
authors = ["Raph Levien <[email protected]>"]
56
description = "Cairo backend for piet 2D graphics abstraction."
7+
readme = "../README.md"
68
license = "MIT/Apache-2.0"
79
repository = "https://github.com/linebender/piet"
8-
readme = "../README.md"
9-
edition = "2018"
1010
keywords = ["graphics", "2d"]
1111
categories = ["rendering::graphics-api"]
1212

1313
[dependencies]
1414
piet = { version = "=0.5.0", path = "../piet" }
1515

16+
xi-unicode = "0.3.0"
17+
unicode-segmentation = "1.3.0"
18+
1619
cairo-rs = { version = "0.15.1", default-features = false } # We don't need glib
1720
pango = { version = "0.15.2", features = ["v1_44"] }
1821
pangocairo = "0.15.1"
19-
unicode-segmentation = "1.3.0"
20-
xi-unicode = "0.3.0"
2122

2223
[dev-dependencies]
23-
piet = { version = "=0.5.0", path = "../piet", features = ["samples"] }
24-
cairo-rs = { version = "0.15.1", default-features = false, features = ["png"] }
2524
criterion = "0.3"
2625

2726
[[bench]]

piet-common/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
22
name = "piet-common"
33
version = "0.5.0"
4+
edition = "2018"
45
authors = ["Raph Levien <[email protected]>"]
56
description = "Selection of a single preferred back-end for piet"
7+
readme = "README.md"
68
license = "MIT/Apache-2.0"
79
repository = "https://github.com/linebender/piet"
8-
readme = "README.md"
9-
edition = "2018"
1010
keywords = ["graphics", "2d"]
1111

1212
[features]
@@ -35,6 +35,7 @@ serde = ["piet/serde"]
3535
[dependencies]
3636
piet = { version = "=0.5.0", path = "../piet" }
3737
piet-web = { version = "=0.5.0", path = "../piet-web", optional = true }
38+
3839
cfg-if = "1.0"
3940
png = { version = "0.17", optional = true }
4041

piet-coregraphics/Cargo.toml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
[package]
22
name = "piet-coregraphics"
33
version = "0.5.0"
4+
edition = "2018"
45
authors = ["Jeff Muizelaar <[email protected]>, Raph Levien <[email protected]>, Colin Rofls <[email protected]>"]
56
description = "CoreGraphics backend for piet 2D graphics abstraction."
7+
readme = "../README.md"
68
license = "MIT/Apache-2.0"
79
repository = "https://github.com/linebender/piet"
8-
readme = "../README.md"
9-
edition = "2018"
1010
keywords = ["graphics", "2d"]
1111
categories = ["rendering::graphics-api"]
1212

1313
[dependencies]
1414
piet = { version = "=0.5.0", path = "../piet" }
1515

16+
associative-cache = "1.0"
17+
1618
foreign-types = "0.3.2"
1719
core-graphics = "0.22.2"
1820
core-text = "19.0.0"
1921
core-foundation = "0.9"
2022
core-foundation-sys = "0.8"
21-
associative-cache = "1.0"
22-
23-
[dev-dependencies]
24-
piet = { version = "=0.5.0", path = "../piet", features = ["samples"] }
25-
png = "0.17"

piet-direct2d/Cargo.toml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
[package]
22
name = "piet-direct2d"
33
version = "0.5.0"
4+
edition = "2018"
45
authors = ["Raph Levien <[email protected]>"]
56
description = "Direct2D backend for piet 2D graphics abstraction."
7+
readme = "../README.md"
68
license = "MIT/Apache-2.0"
79
repository = "https://github.com/linebender/piet"
8-
readme = "../README.md"
9-
edition = "2018"
1010
keywords = ["graphics", "2d"]
1111
categories = ["rendering::graphics-api"]
1212

1313
[dependencies]
1414
piet = { version = "=0.5.0", path = "../piet" }
15+
1516
utf16_lit = "2.0"
1617
associative-cache = "1.0"
1718

1819
wio = "0.2.2"
1920
winapi = { version = "0.3.8", features = ["d2d1", "d2d1_1", "d2d1effects", "d2dbasetypes", "dcommon", "d3d11", "dxgi", "winnls"] }
2021
dwrote = { version = "0.11.0", default_features = false }
21-
22-
[dev-dependencies]
23-
piet = { version = "=0.5.0", path = "../piet", features = ["samples"] }
24-
image = "0.24.0"

piet-svg/Cargo.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
[package]
22
name = "piet-svg"
33
version = "0.5.0"
4+
edition = "2018"
45
authors = ["Benjamin Saunders <[email protected]>"]
56
description = "SVG backend for piet 2D graphics abstraction."
6-
edition = "2018"
7+
readme = "../README.md"
78
license = "MIT/Apache-2.0"
89
repository = "https://github.com/linebender/piet"
910
keywords = ["graphics", "2d"]
@@ -14,13 +15,14 @@ default = []
1415
evcxr = ["evcxr_runtime"]
1516

1617
[dependencies]
18+
piet = { version = "=0.5.0", path = "../piet" }
19+
20+
svg = "0.10.0"
1721
base64 = "0.13.0"
18-
evcxr_runtime = { version = "1.1.0", optional = true }
1922
font-kit = "0.10.1"
20-
image = { version = "0.24.0", default-features = false, features = ["png"] }
21-
piet = { version = "=0.5.0", path = "../piet" }
2223
rustybuzz = "0.4.0"
23-
svg = "0.10.0"
24+
evcxr_runtime = { version = "1.1.0", optional = true }
25+
image = { version = "0.24.0", default-features = false, features = ["png"] }
2426

2527
[dev-dependencies]
26-
piet = { version = "=0.5.0", path = "../piet", features = ["samples"] }
28+
piet-test = { path = "../piet-test" }

piet-svg/examples/basic-svg.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
33
use std::io;
44

5-
use piet::{samples, RenderContext};
5+
use piet::RenderContext;
6+
use piet_test::samples;
67

78
fn main() {
89
let test_picture_number = std::env::args()

piet-test/Cargo.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[package]
2+
name = "piet-test"
3+
version = "0.0.0"
4+
edition = "2018"
5+
publish = false
6+
7+
[[bin]]
8+
name = "samples-cairo"
9+
required-features = ["cairo"]
10+
11+
[[bin]]
12+
name = "samples-direct2d"
13+
required-features = ["direct2d"]
14+
15+
[[bin]]
16+
name = "samples-coregraphics"
17+
required-features = ["coregraphics"]
18+
19+
[features]
20+
cairo = ["piet-cairo", "cairo-rs"]
21+
direct2d = ["piet-direct2d", "winapi"]
22+
coregraphics = ["piet-coregraphics", "core-graphics"]
23+
24+
[dependencies]
25+
piet = { path = "../piet" }
26+
piet-cairo = { path = "../piet-cairo", optional = true }
27+
piet-direct2d = { path = "../piet-direct2d", optional = true }
28+
piet-coregraphics = { path = "../piet-coregraphics", optional = true }
29+
30+
png = "0.17"
31+
pico-args = "0.4.0"
32+
os_info = { version = "3.0.0", default-features = false }
33+
34+
core-graphics = { version = "0.22.2", optional = true }
35+
winapi = { version = "0.3.8", features = ["dxgi"], optional = true }
36+
cairo-rs = { version = "0.15.1", default-features = false, features = ["png"], optional = true }

piet-test/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# piet-test: Sample images and common tests
2+
3+
See [CONTRIBUTING.md](../CONTRIBUTING.md) on instructions on updating the reference snapshots.

piet-test/snapshots

Submodule snapshots added at b251dc4

piet-cairo/examples/test-picture.rs renamed to piet-test/src/bin/samples-cairo.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ use std::process::Command;
66

77
use cairo::{Context, Format, ImageSurface};
88

9-
use piet::{samples, RenderContext};
9+
use piet::RenderContext;
1010
use piet_cairo::CairoRenderContext;
11+
use piet_test::samples;
1112

1213
const HIDPI: f64 = 2.0;
1314
const FILE_PREFIX: &str = "cairo-test-";
1415

1516
fn main() {
1617
let sys_info = additional_system_info();
17-
samples::samples_main(run_sample, FILE_PREFIX, Some(&sys_info));
18+
samples::samples_main("samples-cairo", run_sample, FILE_PREFIX, Some(&sys_info));
1819
}
1920

2021
fn run_sample(idx: usize, base_dir: &Path) -> Result<(), Box<dyn std::error::Error>> {

piet-coregraphics/examples/test-picture.rs renamed to piet-test/src/bin/samples-coregraphics.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ use core_graphics::color_space::CGColorSpace;
88
use core_graphics::context::CGContext;
99

1010
use piet::kurbo::Size;
11-
use piet::{samples, RenderContext};
11+
use piet::RenderContext;
1212
use piet_coregraphics::CoreGraphicsContext;
13+
use piet_test::samples;
1314

1415
const SCALE: f64 = 2.0;
1516
const FILE_PREFIX: &str = "coregraphics-test-";
1617

1718
fn main() {
18-
samples::samples_main(run_sample, FILE_PREFIX, None);
19+
samples::samples_main("samples-coregraphics", run_sample, FILE_PREFIX, None);
1920
}
2021

2122
fn run_sample(idx: usize, base_dir: &Path) -> Result<(), Box<dyn std::error::Error>> {

piet-direct2d/examples/test-picture.rs renamed to piet-test/src/bin/samples-direct2d.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ use std::path::Path;
44

55
use winapi::shared::dxgi::DXGI_MAP_READ;
66

7-
use piet::{samples, RenderContext};
7+
use piet::RenderContext;
88
use piet_direct2d::{D2DRenderContext, D2DText};
9+
use piet_test::samples;
910

1011
const HIDPI: f32 = 2.0;
1112
const FILE_PREFIX: &str = "d2d-test-";
1213

1314
fn main() {
14-
samples::samples_main(run_sample, FILE_PREFIX, None);
15+
samples::samples_main("samples-direct2d", run_sample, FILE_PREFIX, None);
1516
}
1617

1718
fn run_sample(number: usize, base_dir: &Path) -> Result<(), Box<dyn std::error::Error>> {

piet-test/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod samples;

piet/src/samples/mod.rs renamed to piet-test/src/samples/mod.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use std::fs::File;
77
use std::io::BufWriter;
88
use std::path::{Path, PathBuf};
99

10-
use crate::kurbo::Size;
11-
use crate::{Error, RenderContext};
10+
use piet::kurbo::Size;
11+
use piet::{Error, RenderContext};
1212

1313
mod picture_0;
1414
mod picture_1;
@@ -85,6 +85,7 @@ struct Args {
8585
/// testing environment, such as the versions of various dependencies; this
8686
/// will be appended to the GENERATED_BY file.
8787
pub fn samples_main(
88+
binary: &str,
8889
f: fn(usize, &Path) -> Result<(), BoxErr>,
8990
prefix: &str,
9091
env_info: Option<&str>,
@@ -94,7 +95,7 @@ pub fn samples_main(
9495

9596
if args.help {
9697
eprintln!("Piet Sample Image Generator\n");
97-
print_help_text();
98+
print_help_text(binary);
9899
std::process::exit(1);
99100
}
100101

@@ -144,7 +145,7 @@ pub fn samples_main(
144145
eprintln!("caused by: {}", err);
145146
e = err;
146147
}
147-
print_help_text();
148+
print_help_text(binary);
148149
std::process::exit(1);
149150
} else {
150151
std::process::exit(0);
@@ -181,7 +182,7 @@ impl Args {
181182
};
182183

183184
if !(args.help || args.all || args.number.is_some() || args.compare_dir.is_some()) {
184-
Err(Box::new(Error::InvalidSampleArgs))
185+
Err("Must pass either --all or a number".into())
185186
} else {
186187
Ok(args)
187188
}
@@ -411,16 +412,16 @@ impl std::fmt::Display for FailureReason {
411412
}
412413
}
413414

414-
fn print_help_text() {
415+
fn print_help_text(binary: &str) {
415416
eprintln!(
416417
"Options:
417418
418-
$ ./test_picture {{<number> | --all}} [--out=<dir>] [--compare=<dir>] [--help]
419+
$ ./{binary} {{<number> | --all}} [--out=<dir>] [--compare=<dir>] [--help]
419420
420421
Required Args
421422
--all | <number> If 'all', generate all the example pictures. If a number,
422423
then generate that number picture (number must be between
423-
0 and {}
424+
0 and {sample_idx_max}
424425
425426
Optional Args
426427
--out=<dir> Save the results to the directory 'dir'. Defaults to the
@@ -432,6 +433,7 @@ Optional Args
432433
Flags
433434
--help Print this help message and exit.
434435
",
435-
SAMPLE_COUNT - 1
436+
binary = binary,
437+
sample_idx_max = SAMPLE_COUNT - 1
436438
);
437439
}

piet/src/samples/picture_0.rs renamed to piet-test/src/samples/picture_0.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A wide assortment of graphics meant to show off many different uses of piet
22
3-
use crate::kurbo::{Affine, BezPath, Line, Point, Rect, RoundedRect, Size, Vec2};
4-
use crate::{
3+
use piet::kurbo::{Affine, BezPath, Line, Point, Rect, RoundedRect, Size, Vec2};
4+
use piet::{
55
Color, Error, FontFamily, ImageFormat, InterpolationMode, RenderContext, Text, TextAttribute,
66
TextLayout, TextLayoutBuilder,
77
};

0 commit comments

Comments
 (0)