From c70bbc3b7b3af1934b7c2356afaa2420d365419e Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Sun, 26 May 2024 10:54:51 +0700 Subject: [PATCH] Remove download command, keep download directory. (#586) This still allows loading from the download directory, but removes the command that would download to it, allowing people to populate it themselves. The files downloaded were parsed with the `vello_svg` parser, but that was removed from here and moved to its own home, so files loaded would need some preprocessing (to be defined elsewhere). --- Cargo.lock | 288 +----------------- README.md | 7 - examples/headless/src/main.rs | 4 +- examples/scenes/Cargo.toml | 6 - examples/scenes/src/download.rs | 214 ------------- .../scenes/src/download/default_downloads.rs | 106 ------- examples/scenes/src/lib.rs | 62 +--- examples/scenes/src/svg.rs | 36 +-- examples/with_winit/src/lib.rs | 10 +- 9 files changed, 28 insertions(+), 705 deletions(-) delete mode 100644 examples/scenes/src/download.rs delete mode 100644 examples/scenes/src/download/default_downloads.rs diff --git a/Cargo.lock b/Cargo.lock index 837d8284b..d0190871d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -215,12 +215,6 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - [[package]] name = "bit-set" version = "0.5.3" @@ -269,16 +263,6 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" -[[package]] -name = "byte-unit" -version = "4.0.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da78b32057b8fdfc352504708feeba7216dcd65a2c9ab02978cbd288d1279b6c" -dependencies = [ - "serde", - "utf8-width", -] - [[package]] name = "bytemuck" version = "1.16.0" @@ -574,31 +558,6 @@ version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" -[[package]] -name = "crossterm" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" -dependencies = [ - "bitflags 1.3.2", - "crossterm_winapi", - "libc", - "mio", - "parking_lot", - "signal-hook", - "signal-hook-mio", - "winapi", -] - -[[package]] -name = "crossterm_winapi" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" -dependencies = [ - "winapi", -] - [[package]] name = "cursor-icon" version = "1.1.0" @@ -658,12 +617,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f25c0e292a7ca6d6498557ff1df68f32c99850012b6ea401cf8daf771f22ff53" -[[package]] -name = "dyn-clone" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" - [[package]] name = "env_filter" version = "0.1.0" @@ -801,15 +754,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" -[[package]] -name = "form_urlencoded" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" -dependencies = [ - "percent-encoding", -] - [[package]] name = "fsevent-sys" version = "4.1.0" @@ -836,24 +780,6 @@ dependencies = [ "parking_lot", ] -[[package]] -name = "fuzzy-matcher" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54614a3312934d066701a80f20f15fa3b56d67ac7722b39eea5b4c9dd1d66c94" -dependencies = [ - "thread_local", -] - -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - [[package]] name = "gethostname" version = "0.4.3" @@ -1067,16 +993,6 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" -[[package]] -name = "idna" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "image" version = "0.25.1" @@ -1130,23 +1046,6 @@ dependencies = [ "libc", ] -[[package]] -name = "inquire" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fddf93031af70e75410a2511ec04d49e758ed2f26dad3404a934e0fb45cc12a" -dependencies = [ - "bitflags 2.5.0", - "crossterm", - "dyn-clone", - "fuzzy-matcher", - "fxhash", - "newline-converter", - "once_cell", - "unicode-segmentation", - "unicode-width", -] - [[package]] name = "instant" version = "0.1.12" @@ -1456,15 +1355,6 @@ dependencies = [ "jni-sys", ] -[[package]] -name = "newline-converter" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b6b097ecb1cbfed438542d16e84fd7ad9b0c76c8a65b7f9039212a3d14dc7f" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "notify" version = "6.1.1" @@ -1903,21 +1793,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832" -[[package]] -name = "ring" -version = "0.17.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" -dependencies = [ - "cc", - "cfg-if", - "getrandom", - "libc", - "spin", - "untrusted", - "windows-sys 0.52.0", -] - [[package]] name = "roxmltree" version = "0.19.0" @@ -1956,37 +1831,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rustls" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" -dependencies = [ - "log", - "ring", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls-pki-types" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" - -[[package]] -name = "rustls-webpki" -version = "0.102.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3bce581c0dd41bce533ce695a1437fa16a7ab5ac3ccfa99fe1a620a7885eabf" -dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", -] - [[package]] name = "ryu" version = "1.0.18" @@ -2007,15 +1851,12 @@ name = "scenes" version = "0.0.0" dependencies = [ "anyhow", - "byte-unit", "clap", "getrandom", "image", - "inquire", "instant", "rand", "roxmltree", - "ureq", "vello", ] @@ -2084,36 +1925,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "signal-hook" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" -dependencies = [ - "libc", - "signal-hook-registry", -] - -[[package]] -name = "signal-hook-mio" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" -dependencies = [ - "libc", - "mio", - "signal-hook", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "simd-adler32" version = "0.3.7" @@ -2199,12 +2010,6 @@ dependencies = [ "serde", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "spirv" version = "0.3.0+sdk-1.3.268.0" @@ -2238,12 +2043,6 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "svg_fmt" version = "0.4.3" @@ -2348,21 +2147,6 @@ dependencies = [ "strict-num", ] -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - [[package]] name = "toml_datetime" version = "0.6.6" @@ -2445,27 +2229,12 @@ version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c591d83f69777866b9126b24c6dd9a18351f177e49d625920d19f989fd31cf8" -[[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "unicode-normalization" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" -dependencies = [ - "tinyvec", -] - [[package]] name = "unicode-segmentation" version = "1.11.0" @@ -2484,46 +2253,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" -[[package]] -name = "untrusted" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" - -[[package]] -name = "ureq" -version = "2.9.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d11a831e3c0b56e438a28308e7c810799e3c118417f342d30ecec080105395cd" -dependencies = [ - "base64 0.22.1", - "flate2", - "log", - "once_cell", - "rustls", - "rustls-pki-types", - "rustls-webpki", - "url", - "webpki-roots", -] - -[[package]] -name = "url" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "utf8-width" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3" - [[package]] name = "utf8parse" version = "0.2.1" @@ -2668,7 +2397,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca821da8c1ae6c87c5e94493939a206daa8587caff227c6032e0061a3d80817f" dependencies = [ "anyhow", - "base64 0.21.7", + "base64", "log", "rustc-demangle", "serde_json", @@ -2921,15 +2650,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki-roots" -version = "0.26.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3de34ae270483955a94f4b21bdaaeb83d508bb84a01435f393818edb0012009" -dependencies = [ - "rustls-pki-types", -] - [[package]] name = "wgpu" version = "0.20.0" @@ -3481,12 +3201,6 @@ dependencies = [ "syn 2.0.63", ] -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" - [[package]] name = "zune-core" version = "0.4.12" diff --git a/README.md b/README.md index db54a3325..077c024bf 100644 --- a/README.md +++ b/README.md @@ -142,13 +142,6 @@ It also includes a collection of test scenes showing the capabilities of `vello` cargo run -p with_winit ``` -Some default test scenes can be downloaded from Wikimedia Commons using the `download` subcommand. -This also supports downloading from user-provided URLS. - -```shell -cargo run -p with_winit -- download -``` - ### Bevy diff --git a/examples/headless/src/main.rs b/examples/headless/src/main.rs index ff976ab2a..d206b298e 100644 --- a/examples/headless/src/main.rs +++ b/examples/headless/src/main.rs @@ -6,7 +6,7 @@ use std::num::NonZeroUsize; use std::path::{Path, PathBuf}; use anyhow::{anyhow, bail, Context, Result}; -use clap::{CommandFactory, Parser}; +use clap::Parser; use scenes::{ImageCache, SceneParams, SceneSet, SimpleText}; use vello::kurbo::{Affine, Vec2}; use vello::util::RenderContext; @@ -20,7 +20,7 @@ fn main() -> Result<()> { #[cfg(not(target_arch = "wasm32"))] env_logger::init(); let args = Args::parse(); - let scenes = args.args.select_scene_set(Args::command)?; + let scenes = args.args.select_scene_set()?; if let Some(scenes) = scenes { let mut scene_idx = None; for (idx, scene) in scenes.scenes.iter().enumerate() { diff --git a/examples/scenes/Cargo.toml b/examples/scenes/Cargo.toml index c1c7f9c53..3300e5cae 100644 --- a/examples/scenes/Cargo.toml +++ b/examples/scenes/Cargo.toml @@ -19,11 +19,5 @@ instant = { workspace = true } # for pico_svg roxmltree = "0.19.0" -# Used for the `download` command -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] -byte-unit = "4.0.19" -inquire = "0.7.5" -ureq = "2.9.7" - [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { version = "0.2.15", features = ["js"] } diff --git a/examples/scenes/src/download.rs b/examples/scenes/src/download.rs deleted file mode 100644 index 820dc24c6..000000000 --- a/examples/scenes/src/download.rs +++ /dev/null @@ -1,214 +0,0 @@ -// Copyright 2022 the Vello Authors -// SPDX-License-Identifier: Apache-2.0 OR MIT - -use std::io::Seek; -use std::path::{Path, PathBuf}; - -use anyhow::{bail, Context, Result}; -use byte_unit::Byte; -use clap::Args; -use std::io::Read; -mod default_downloads; - -#[derive(Args, Debug)] -pub(crate) struct Download { - #[clap(long)] - /// Directory to download the files into - #[clap(default_value_os_t = default_directory())] - pub directory: PathBuf, - /// Set of files to download. Use `name@url` format to specify a file prefix - downloads: Option>, - /// Whether to automatically install the default set of files - #[clap(long)] - auto: bool, - /// The size limit for each individual file (ignored if the default files are downloaded) - #[clap(long, default_value = "10 MB")] - size_limit: Byte, -} - -fn default_directory() -> PathBuf { - let mut result = Path::new(env!("CARGO_MANIFEST_DIR")) - .parent() - .unwrap() - .join("assets"); - result.push("downloads"); - result -} - -impl Download { - pub fn action(&self) -> Result<()> { - let mut to_download = vec![]; - if let Some(downloads) = &self.downloads { - to_download = downloads - .iter() - .map(|it| Self::parse_download(it)) - .collect(); - } else { - let mut accepted = self.auto; - let downloads = default_downloads::default_downloads() - .into_iter() - .filter(|it| { - let file = it.file_path(&self.directory); - !file.exists() - }) - .collect::>(); - if !accepted { - if !downloads.is_empty() { - println!( - "Would you like to download a set of default svg files? These files are:" - ); - for download in &downloads { - let builtin = download.builtin.as_ref().unwrap(); - println!( - "{} ({}) under license {} from {}", - download.name, - byte_unit::Byte::from_bytes(builtin.expected_size.into()) - .get_appropriate_unit(false), - builtin.license, - builtin.info - ); - } - - // For rustfmt, split prompt into its own line - const PROMPT: &str = - "Would you like to download a set of default svg files, as explained above?"; - accepted = inquire::Confirm::new(PROMPT).with_default(false).prompt()?; - } else { - println!("Nothing to download! All default downloads already created"); - } - } - if accepted { - to_download = downloads; - } - } - let mut completed_count = 0; - let mut failed_count = 0; - for (index, download) in to_download.iter().enumerate() { - println!( - "{index}: Downloading {} from {}", - download.name, download.url - ); - match download.fetch(&self.directory, self.size_limit) { - Ok(()) => completed_count += 1, - Err(e) => { - failed_count += 1; - eprintln!("Download failed with error: {e}"); - let cont = if self.auto { - false - } else { - inquire::Confirm::new("Would you like to try other downloads?") - .with_default(false) - .prompt()? - }; - if !cont { - println!("{} downloads complete", completed_count); - if failed_count > 0 { - println!("{} downloads failed", failed_count); - } - let remaining = to_download.len() - (completed_count + failed_count); - if remaining > 0 { - println!("{} downloads skipped", remaining); - } - return Err(e); - } - } - } - } - println!("{} downloads complete", completed_count); - if failed_count > 0 { - println!("{} downloads failed", failed_count); - } - debug_assert!(completed_count + failed_count == to_download.len()); - Ok(()) - } - - fn parse_download(value: &str) -> SVGDownload { - if let Some(at_index) = value.find('@') { - let name = &value[0..at_index]; - let url = &value[at_index + 1..]; - SVGDownload { - name: name.to_string(), - url: url.to_string(), - builtin: None, - } - } else { - let end_index = value.rfind(".svg").unwrap_or(value.len()); - let url_with_name = &value[0..end_index]; - let name = url_with_name - .rfind('/') - .map(|v| &url_with_name[v + 1..]) - .unwrap_or(url_with_name); - SVGDownload { - name: name.to_string(), - url: value.to_string(), - builtin: None, - } - } - } -} - -struct SVGDownload { - name: String, - url: String, - builtin: Option, -} - -impl SVGDownload { - fn file_path(&self, directory: &Path) -> PathBuf { - directory.join(&self.name).with_extension("svg") - } - - fn fetch(&self, directory: &Path, size_limit: Byte) -> Result<()> { - let mut size_limit = size_limit.get_bytes().try_into()?; - let mut limit_exact = false; - if let Some(builtin) = &self.builtin { - size_limit = builtin.expected_size; - limit_exact = true; - } - // If we're expecting an exact version of the file, it's worth not fetching - // the file if we know it will fail - if limit_exact { - let head_response = ureq::head(&self.url).call()?; - let content_length = head_response.header("content-length"); - if let Some(Ok(content_length)) = content_length.map(|it| it.parse::()) { - if content_length != size_limit { - bail!( - "Size is not as expected for download. Expected {}, server reported {}", - Byte::from_bytes(size_limit.into()).get_appropriate_unit(true), - Byte::from_bytes(content_length.into()).get_appropriate_unit(true) - ) - } - } - } - let mut file = std::fs::OpenOptions::new() - .create_new(true) - .write(true) - .open(self.file_path(directory)) - .context("Creating file")?; - let mut reader = ureq::get(&self.url).call()?.into_reader(); - - std::io::copy( - // ureq::into_string() has a limit of 10MiB so we must use the reader - &mut (&mut reader).take(size_limit), - &mut file, - )?; - if reader.read_exact(&mut [0]).is_ok() { - bail!("Size limit exceeded"); - } - if limit_exact { - let bytes_downloaded = file.stream_position().context("Checking file limit")?; - if bytes_downloaded != size_limit { - bail!( - "Builtin downloaded file was not as expected. Expected {size_limit}, received {bytes_downloaded}.", - ); - } - } - Ok(()) - } -} - -struct BuiltinSvgProps { - expected_size: u64, - license: &'static str, - info: &'static str, -} diff --git a/examples/scenes/src/download/default_downloads.rs b/examples/scenes/src/download/default_downloads.rs deleted file mode 100644 index 7a22a363f..000000000 --- a/examples/scenes/src/download/default_downloads.rs +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2022 the Vello Authors -// SPDX-License-Identifier: Apache-2.0 OR MIT - -// This content cannot be formatted by rustfmt because of the long strings, so it's in its own file -use super::{BuiltinSvgProps, SVGDownload}; - -pub(super) fn default_downloads() -> Vec { - vec![ - SVGDownload { - builtin:Some(BuiltinSvgProps { - info: "https://commons.wikimedia.org/wiki/File:CIA_WorldFactBook-Political_world.svg", - license: "Public Domain", - expected_size: 12771150, - }), - url: "https://upload.wikimedia.org/wikipedia/commons/7/72/Political_Map_of_the_World_%28august_2013%29.svg".to_string(), - name: "CIA World Map".to_string() - }, - SVGDownload { - builtin:Some(BuiltinSvgProps { - info: "https://commons.wikimedia.org/wiki/File:World_-_time_zones_map_(2014).svg", - license: "Public Domain", - expected_size: 5235172, - }), - url: "https://upload.wikimedia.org/wikipedia/commons/c/c6/World_-_time_zones_map_%282014%29.svg".to_string(), - name: "Time Zones Map".to_string() - }, - SVGDownload { - builtin:Some(BuiltinSvgProps { - info: "https://commons.wikimedia.org/wiki/File:Coat_of_arms_of_Poland-official.svg", - license: "Public Domain", - expected_size: 10747708, - }), - url: "https://upload.wikimedia.org/wikipedia/commons/3/3e/Coat_of_arms_of_Poland-official.svg".to_string(), - name: "Coat of Arms of Poland".to_string() - }, - SVGDownload { - builtin:Some(BuiltinSvgProps { - info: "https://commons.wikimedia.org/wiki/File:Coat_of_arms_of_the_Kingdom_of_Yugoslavia.svg", - license: "Public Domain", - expected_size: 15413803, - }), - url: "https://upload.wikimedia.org/wikipedia/commons/5/58/Coat_of_arms_of_the_Kingdom_of_Yugoslavia.svg".to_string(), - name: "Coat of Arms of the Kingdom of Yugoslavia".to_string() - }, - SVGDownload { - builtin:Some(BuiltinSvgProps { - info: "https://github.com/RazrFalcon/resvg-test-suite", - license: "MIT", - expected_size: 383, - }), - url: "https://raw.githubusercontent.com/RazrFalcon/resvg-test-suite/master/tests/painting/stroke-dashoffset/default.svg".to_string(), - name: "SVG Stroke Dasharray Test".to_string() - }, - SVGDownload { - builtin:Some(BuiltinSvgProps { - info: "https://github.com/RazrFalcon/resvg-test-suite", - license: "MIT", - expected_size: 342, - }), - url: "https://raw.githubusercontent.com/RazrFalcon/resvg-test-suite/master/tests/painting/stroke-linecap/butt.svg".to_string(), - name: "SVG Stroke Linecap Butt Test".to_string() - }, - SVGDownload { - builtin:Some(BuiltinSvgProps { - info: "https://github.com/RazrFalcon/resvg-test-suite", - license: "MIT", - expected_size: 344, - }), - url: "https://raw.githubusercontent.com/RazrFalcon/resvg-test-suite/master/tests/painting/stroke-linecap/round.svg".to_string(), - name: "SVG Stroke Linecap Round Test".to_string() - }, - SVGDownload { - builtin:Some(BuiltinSvgProps { - info: "https://github.com/RazrFalcon/resvg-test-suite", - license: "MIT", - expected_size: 346, - }), - url: "https://raw.githubusercontent.com/RazrFalcon/resvg-test-suite/master/tests/painting/stroke-linecap/square.svg".to_string(), - name: "SVG Stroke Linecap Square Test".to_string() - }, SVGDownload { - builtin:Some(BuiltinSvgProps { - info: "https://github.com/RazrFalcon/resvg-test-suite", - license: "MIT", - expected_size: 381, - }), - url: "https://github.com/RazrFalcon/resvg-test-suite/raw/master/tests/painting/stroke-linejoin/miter.svg".to_string(), - name: "SVG Stroke Linejoin Bevel Test".to_string() - }, SVGDownload { - builtin:Some(BuiltinSvgProps { - info: "https://github.com/RazrFalcon/resvg-test-suite", - license: "MIT", - expected_size: 381, - }), - url: "https://github.com/RazrFalcon/resvg-test-suite/raw/master/tests/painting/stroke-linejoin/round.svg".to_string(), - name: "SVG Stroke Linejoin Round Test".to_string() - },SVGDownload { - builtin:Some(BuiltinSvgProps { - info: "https://github.com/RazrFalcon/resvg-test-suite", - license: "MIT", - expected_size: 351, - }), - url: "https://github.com/RazrFalcon/resvg-test-suite/raw/master/tests/painting/stroke-miterlimit/default.svg".to_string(), - name: "SVG Stroke Miterlimit Test".to_string() - }, - ] -} diff --git a/examples/scenes/src/lib.rs b/examples/scenes/src/lib.rs index db6fc4271..f3c83f890 100644 --- a/examples/scenes/src/lib.rs +++ b/examples/scenes/src/lib.rs @@ -1,8 +1,6 @@ // Copyright 2022 the Vello Authors // SPDX-License-Identifier: Apache-2.0 OR MIT -#[cfg(not(target_arch = "wasm32"))] -pub mod download; mod images; mod mmark; mod pico_svg; @@ -12,9 +10,7 @@ mod test_scenes; use std::path::PathBuf; use anyhow::{anyhow, Result}; -use clap::{Args, Subcommand}; -#[cfg(not(target_arch = "wasm32"))] -use download::Download; +use clap::Args; pub use images::ImageCache; pub use simple_text::SimpleText; pub use svg::{default_scene, scene_from_files}; @@ -78,53 +74,25 @@ pub struct Arguments { /// Format is CSS style hexadecimal (#RGB, #RGBA, #RRGGBB, #RRGGBBAA) or /// an SVG color name such as "aliceblue" pub base_color: Option, - #[clap(subcommand)] - command: Option, -} - -#[derive(Subcommand, Debug)] -enum Command { - /// Download SVG files for testing. By default, downloads a set of files from wikipedia - #[cfg(not(target_arch = "wasm32"))] - Download(Download), } impl Arguments { - pub fn select_scene_set( - &self, - #[allow(unused)] command: impl FnOnce() -> clap::Command, - ) -> Result> { - if let Some(command) = &self.command { - command.action()?; - Ok(None) + pub fn select_scene_set(&self) -> Result> { + // There is no file access on WASM, and on Android we haven't set up the assets + // directory. + // TODO: Upload the assets directory on Android + // Therefore, only render the `test_scenes` (including one SVG example) + #[cfg(any(target_arch = "wasm32", target_os = "android"))] + return Ok(Some(test_scenes())); + #[cfg(not(any(target_arch = "wasm32", target_os = "android")))] + if self.test_scenes { + Ok(test_scenes()) + } else if let Some(svgs) = &self.svgs { + scene_from_files(svgs) } else { - // There is no file access on WASM, and on Android we haven't set up the assets - // directory. - // TODO: Upload the assets directory on Android - // Therefore, only render the `test_scenes` (including one SVG example) - #[cfg(any(target_arch = "wasm32", target_os = "android"))] - return Ok(Some(test_scenes())); - #[cfg(not(any(target_arch = "wasm32", target_os = "android")))] - if self.test_scenes { - Ok(test_scenes()) - } else if let Some(svgs) = &self.svgs { - scene_from_files(svgs) - } else { - default_scene(command) - } - .map(Some) - } - } -} - -impl Command { - fn action(&self) -> Result<()> { - match self { - #[cfg(not(target_arch = "wasm32"))] - Command::Download(download) => download.action(), - #[cfg(target_arch = "wasm32")] - _ => unreachable!("downloads not supported on wasm"), + default_scene() } + .map(Some) } } diff --git a/examples/scenes/src/svg.rs b/examples/scenes/src/svg.rs index 7336895b3..a6fb7a9a9 100644 --- a/examples/scenes/src/svg.rs +++ b/examples/scenes/src/svg.rs @@ -16,56 +16,34 @@ use vello::{ use crate::{ExampleScene, SceneParams, SceneSet}; pub fn scene_from_files(files: &[PathBuf]) -> Result { - scene_from_files_inner(files, || ()) + scene_from_files_inner(files) } -pub fn default_scene(command: impl FnOnce() -> clap::Command) -> Result { +pub fn default_scene() -> Result { let assets_dir = Path::new(env!("CARGO_MANIFEST_DIR")) .join("../assets/") .canonicalize()?; - let mut has_empty_directory = false; - let result = scene_from_files_inner( - &[ - assets_dir.join("Ghostscript_Tiger.svg"), - assets_dir.join("downloads"), - ], - || has_empty_directory = true, - )?; - if has_empty_directory { - let mut command = command(); - command.build(); - println!( - "No test files have been downloaded. Consider downloading some using the subcommand:" - ); - let subcmd = command.find_subcommand_mut("download").unwrap(); - subcmd.print_help()?; - } - Ok(result) + scene_from_files_inner(&[ + assets_dir.join("Ghostscript_Tiger.svg"), + assets_dir.join("downloads"), + ]) } -fn scene_from_files_inner( - files: &[PathBuf], - mut empty_dir: impl FnMut(), -) -> std::result::Result { +fn scene_from_files_inner(files: &[PathBuf]) -> std::result::Result { let mut scenes = Vec::new(); for path in files { if path.is_dir() { - let mut count = 0; let start_index = scenes.len(); for file in read_dir(path)? { let entry = file?; if let Some(extension) = Path::new(&entry.file_name()).extension() { if extension == "svg" { - count += 1; scenes.push(example_scene_of(entry.path())); } } } // Ensure a consistent order within directories scenes[start_index..].sort_by_key(|scene| scene.config.name.to_lowercase()); - if count == 0 { - empty_dir(); - } } else { scenes.push(example_scene_of(path.to_owned())); } diff --git a/examples/with_winit/src/lib.rs b/examples/with_winit/src/lib.rs index bfcdb0b19..6666d20fc 100644 --- a/examples/with_winit/src/lib.rs +++ b/examples/with_winit/src/lib.rs @@ -6,7 +6,7 @@ use std::collections::HashSet; use std::num::NonZeroUsize; use std::sync::Arc; -use clap::{CommandFactory, Parser}; +use clap::Parser; use scenes::{ImageCache, SceneParams, SceneSet, SimpleText}; use vello::kurbo::{Affine, Vec2}; use vello::peniko::Color; @@ -703,7 +703,7 @@ pub fn main() -> anyhow::Result<()> { .format_timestamp(Some(env_logger::TimestampPrecision::Millis)) .init(); let args = parse_arguments(); - let scenes = args.args.select_scene_set(Args::command)?; + let scenes = args.args.select_scene_set()?; if let Some(scenes) = scenes { let event_loop = EventLoop::::with_user_event().build()?; #[allow(unused_mut)] @@ -826,11 +826,7 @@ fn android_main(app: AndroidApp) { .build() .expect("Required to continue"); let args = parse_arguments(); - let scenes = args - .args - .select_scene_set(|| Args::command()) - .unwrap() - .unwrap(); + let scenes = args.args.select_scene_set().unwrap().unwrap(); let render_cx = RenderContext::new(); run(event_loop, args, scenes, render_cx);