From b78899df5f623123fbd200732c414dd5ea269ed9 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Wed, 18 Nov 2026 18:28:05 +0100 Subject: [PATCH] New Document: Photo, Print and Art & Illustration list the blank document presets PresetCategory::standard() (PhotoCraft's categories) takes the lists measured for photocraft#14040: Photo gains the default size, 3 x 2, 2 x 3 and 8 x 10; Print gains A6, B5, C4, C5, C6 and DL in ISO order; Art & Illustration lists the 1000 and 2000 pixel grids, Poster, a portrait Postcard, 1080p and 720p. DocumentPreset::pixel_sized marks the grids: they show and apply their pixels at the print resolution instead of a size in inches. --- .../form_dialogs/new_document/cards.rs | 2 +- .../form_dialogs/new_document/presets.rs | 99 ++++++++++++++----- .../tests/it/form_dialogs/new_document.rs | 90 +++++++++++++++++ 3 files changed, 164 insertions(+), 27 deletions(-) diff --git a/crates/ui-patterns/src/patterns/form_dialogs/new_document/cards.rs b/crates/ui-patterns/src/patterns/form_dialogs/new_document/cards.rs index 515e182eec..a5937fd098 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/new_document/cards.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/new_document/cards.rs @@ -253,7 +253,7 @@ fn cards_of(tab: TabId, session: &Session, values: &DocumentOptions, read: &Read let preset_card = |preset: &DocumentPreset| { let preset = session.orientation.map_or_else(|| preset.clone(), |orientation| preset.turned(orientation)); let mut settings = preset.options(setup.print_ppi, setup.screen_ppi); - if preset.is_print() && !matches!(values.unit, UnitKind::Pixels | UnitKind::Percent) { + if preset.in_inches() && !matches!(values.unit, UnitKind::Pixels | UnitKind::Percent) { settings.unit = values.unit; } Card { diff --git a/crates/ui-patterns/src/patterns/form_dialogs/new_document/presets.rs b/crates/ui-patterns/src/patterns/form_dialogs/new_document/presets.rs index fc9e0c208b..b5e8a47c30 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/new_document/presets.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/new_document/presets.rs @@ -265,12 +265,14 @@ pub struct DocumentPreset { pub pixels_per_inch: f64, /// Picking the card turns Artboards on (Photoshop's Web and Mobile presets). pub artboard: bool, + /// A print preset sized in pixels (a pixel grid): it shows and applies its pixels, at the app's print resolution. + pub pixel_sized: bool, } impl DocumentPreset { /// The card `id`, named `name` in English, for a page of `width` x `height` pixels at `pixels_per_inch`. pub const fn new(id: &'static str, name: &'static str, width: u32, height: u32, pixels_per_inch: f64) -> Self { - Self { id, name, width, height, pixels_per_inch, artboard: false } + Self { id, name, width, height, pixels_per_inch, artboard: false, pixel_sized: false } } /// The card turns Artboards on when picked. @@ -280,12 +282,25 @@ impl DocumentPreset { self } - /// Whether the preset is for print (300 ppi and up): its card and fields show inches at the app's print resolution; - /// screen presets stay in pixels. + /// The card keeps its pixels: it shows and applies them at the app's print resolution instead of keeping a page + /// size in inches. + #[must_use] + pub const fn pixel_sized(mut self) -> Self { + self.pixel_sized = true; + self + } + + /// Whether the preset is for print (300 ppi and up): it takes the app's print resolution; screen presets take the + /// screen resolution. pub fn is_print(&self) -> bool { self.pixels_per_inch >= 300.0 } + /// Whether the card and fields show the preset in inches: a print preset that is not [`pixel_sized`](Self::pixel_sized). + pub fn in_inches(&self) -> bool { + self.is_print() && !self.pixel_sized + } + /// The preset turned to `orientation`; a square preset stays as it is. #[must_use] pub fn turned(&self, orientation: Orientation) -> DocumentPreset { @@ -296,14 +311,15 @@ impl DocumentPreset { DocumentPreset { width: self.height, height: self.width, ..self.clone() } } - /// The preset as settings: the unit (inches for print, pixels for screen) and the resolution moved to the app's - /// print or screen resolution, keeping a print preset's physical size. + /// The preset as settings: the unit (inches for print, pixels for screen and pixel-sized presets) and the + /// resolution moved to the app's print or screen resolution, keeping a print preset's physical size and any other + /// preset's pixels. pub fn options(&self, print_ppi: f64, screen_ppi: f64) -> DocumentOptions { - let print = self.is_print(); - let wanted = if print { print_ppi } else { screen_ppi }; + let inches = self.in_inches(); + let wanted = if self.is_print() { print_ppi } else { screen_ppi }; let (width, height, pixels_per_inch) = if !(wanted.is_finite() && wanted > 0.0) { (self.width, self.height, self.pixels_per_inch) - } else if print { + } else if inches { let scale = wanted / self.pixels_per_inch; let pixels = |side: u32| (f64::from(side) * scale).round().clamp(1.0, MAX_DOCUMENT_SIDE) as u32; (pixels(self.width), pixels(self.height), wanted) @@ -313,7 +329,7 @@ impl DocumentPreset { DocumentOptions { size: PixelSize::new(width, height), pixels_per_inch, - unit: if print { UnitKind::Inches } else { UnitKind::Pixels }, + unit: if inches { UnitKind::Inches } else { UnitKind::Pixels }, ..DocumentOptions::default() } } @@ -345,12 +361,15 @@ impl PresetCategory { "photo", "Photo", vec![ + DocumentPreset::new(DEFAULT_ID, "Default Size", 2100, 1500, 300.0), + DocumentPreset::new("landscape-3x2", "Landscape, 3 x 2", 900, 600, 300.0), DocumentPreset::new("landscape-6x4", "Landscape, 6 x 4", 1800, 1200, 300.0), DocumentPreset::new("landscape-7x5", "Landscape, 7 x 5", 2100, 1500, 300.0), DocumentPreset::new("landscape-10x8", "Landscape, 10 x 8", 3000, 2400, 300.0), + DocumentPreset::new("portrait-2x3", "Portrait, 2 x 3", 600, 900, 300.0), DocumentPreset::new("portrait-4x6", "Portrait, 4 x 6", 1200, 1800, 300.0), DocumentPreset::new("portrait-5x7", "Portrait, 5 x 7", 1500, 2100, 300.0), - DocumentPreset::new("square-5x5", "Square, 5 x 5", 1500, 1500, 300.0), + DocumentPreset::new("portrait-8x10", "Portrait, 8 x 10", 2400, 3000, 300.0), ], ), PresetCategory::new( @@ -361,20 +380,28 @@ impl PresetCategory { DocumentPreset::new("legal", "Legal", 2550, 4200, 300.0), DocumentPreset::new("tabloid", "Tabloid", 3300, 5100, 300.0), DocumentPreset::new("a4", "A4", 2480, 3508, 300.0), - DocumentPreset::new("a3", "A3", 3508, 4961, 300.0), + DocumentPreset::new("a6", "A6", 1240, 1748, 300.0), DocumentPreset::new("a5", "A5", 1748, 2480, 300.0), - DocumentPreset::new("b3", "B3", 4169, 5906, 300.0), + DocumentPreset::new("a3", "A3", 3508, 4961, 300.0), + DocumentPreset::new("b5", "B5", 2079, 2953, 300.0), DocumentPreset::new("b4", "B4", 2953, 4169, 300.0), + DocumentPreset::new("b3", "B3", 4169, 5906, 300.0), + DocumentPreset::new("c4", "C4", 2705, 3827, 300.0), + DocumentPreset::new("c5", "C5", 1913, 2705, 300.0), + DocumentPreset::new("c6", "C6", 1346, 1913, 300.0), + DocumentPreset::new("dl", "DL", 1299, 2598, 300.0), ], ), PresetCategory::new( "art", "Art & Illustration", vec![ + DocumentPreset::new("grid-1000", "1000 pixel grid", 1000, 1000, 300.0).pixel_sized(), + DocumentPreset::new("grid-2000", "2000 pixel grid", 2000, 2000, 300.0).pixel_sized(), DocumentPreset::new("poster", "Poster", 5400, 7200, 300.0), - DocumentPreset::new("postcard", "Postcard", 1800, 1200, 300.0), - DocumentPreset::new("comic-book", "Comic Book", 1988, 3075, 300.0), - DocumentPreset::new("square-12x12", "Square, 12 x 12", 3600, 3600, 300.0), + DocumentPreset::new("postcard", "Postcard", 1200, 1800, 300.0), + DocumentPreset::new("video-1080p", "1080p", 1920, 1080, 72.0), + DocumentPreset::new("video-720p", "720p", 1280, 720, 72.0), ], ), PresetCategory::new( @@ -461,24 +488,34 @@ craft_ui::words! { /// The names of the built-in presets, in the order of `PRESET_IDS`. pub struct NewDocumentPresetWords { names: array [ + "newDocumentPreset.landscape3x2" = "Landscape, 3 x 2", "newDocumentPreset.landscape6x4" = "Landscape, 6 x 4", "newDocumentPreset.landscape7x5" = "Landscape, 7 x 5", "newDocumentPreset.landscape10x8" = "Landscape, 10 x 8", + "newDocumentPreset.portrait2x3" = "Portrait, 2 x 3", "newDocumentPreset.portrait4x6" = "Portrait, 4 x 6", "newDocumentPreset.portrait5x7" = "Portrait, 5 x 7", - "newDocumentPreset.square5x5" = "Square, 5 x 5", + "newDocumentPreset.portrait8x10" = "Portrait, 8 x 10", "newDocumentPreset.letter" = "Letter", "newDocumentPreset.legal" = "Legal", "newDocumentPreset.tabloid" = "Tabloid", "newDocumentPreset.a4" = "A4", - "newDocumentPreset.a3" = "A3", + "newDocumentPreset.a6" = "A6", "newDocumentPreset.a5" = "A5", - "newDocumentPreset.b3" = "B3", + "newDocumentPreset.a3" = "A3", + "newDocumentPreset.b5" = "B5", "newDocumentPreset.b4" = "B4", + "newDocumentPreset.b3" = "B3", + "newDocumentPreset.c4" = "C4", + "newDocumentPreset.c5" = "C5", + "newDocumentPreset.c6" = "C6", + "newDocumentPreset.dl" = "DL", + "newDocumentPreset.grid1000" = "1000 pixel grid", + "newDocumentPreset.grid2000" = "2000 pixel grid", "newDocumentPreset.poster" = "Poster", "newDocumentPreset.postcard" = "Postcard", - "newDocumentPreset.comicBook" = "Comic Book", - "newDocumentPreset.square12x12" = "Square, 12 x 12", + "newDocumentPreset.video1080p" = "1080p", + "newDocumentPreset.video720p" = "720p", "newDocumentPreset.webMostCommon" = "Web Most Common", "newDocumentPreset.webMinimum" = "Web Minimum", "newDocumentPreset.webLarge" = "Web Large", @@ -499,25 +536,35 @@ craft_ui::words! { } /// The ids of the built-in presets, in the order of `PresetWords::names`. -const PRESET_IDS: [&str; 33] = [ +const PRESET_IDS: [&str; 43] = [ + "landscape-3x2", "landscape-6x4", "landscape-7x5", "landscape-10x8", + "portrait-2x3", "portrait-4x6", "portrait-5x7", - "square-5x5", + "portrait-8x10", "letter", "legal", "tabloid", "a4", - "a3", + "a6", "a5", - "b3", + "a3", + "b5", "b4", + "b3", + "c4", + "c5", + "c6", + "dl", + "grid-1000", + "grid-2000", "poster", "postcard", - "comic-book", - "square-12x12", + "video-1080p", + "video-720p", "web-most-common", "web-minimum", "web-large", diff --git a/crates/ui-patterns/tests/it/form_dialogs/new_document.rs b/crates/ui-patterns/tests/it/form_dialogs/new_document.rs index 27f9dcf8ed..631cf3aa6f 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/new_document.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/new_document.rs @@ -174,3 +174,93 @@ fn pixel_aspect_lists_the_custom_entries_and_shows_an_unknown_id_as_square() { fixture.click(&row).idle(10); assert!(shows(&fixture, "DVCPRO HD 1080 (1.5)") && shows(&fixture, "Mine"), "the built-in ratios, then the app's"); } + +/// The names of the standard category `id`, in card order. +fn standard_names(id: &str) -> Vec<&'static str> { + let categories = craft_ui::patterns::form_dialogs::PresetCategory::standard(); + categories.iter().find(|category| category.id == id).expect("a standard category").presets.iter().map(|preset| preset.name).collect() +} + +/// The standard preset `name` of category `id`. +fn standard_preset(id: &str, name: &str) -> craft_ui::patterns::form_dialogs::DocumentPreset { + let categories = craft_ui::patterns::form_dialogs::PresetCategory::standard(); + let category = categories.into_iter().find(|category| category.id == id).expect("a standard category"); + category.presets.into_iter().find(|preset| preset.name == name).expect("a standard preset") +} + +#[trial] +fn photo_print_and_art_list_the_blank_document_presets() { + assert_eq!( + standard_names("photo"), + [ + "Default Size", + "Landscape, 3 x 2", + "Landscape, 6 x 4", + "Landscape, 7 x 5", + "Landscape, 10 x 8", + "Portrait, 2 x 3", + "Portrait, 4 x 6", + "Portrait, 5 x 7", + "Portrait, 8 x 10" + ] + ); + assert_eq!(standard_names("print"), ["Letter", "Legal", "Tabloid", "A4", "A6", "A5", "A3", "B5", "B4", "B3", "C4", "C5", "C6", "DL"]); + assert_eq!(standard_names("art"), ["1000 pixel grid", "2000 pixel grid", "Poster", "Postcard", "1080p", "720p"]); + // ISO 216 / ISO 269 sizes in millimetres, at 300 ppi. + let mm = |side: f64| (side / 25.4 * 300.0).round() as u32; + for (name, width, height) in [ + ("A3", 297.0, 420.0), + ("A4", 210.0, 297.0), + ("A5", 148.0, 210.0), + ("A6", 105.0, 148.0), + ("B3", 353.0, 500.0), + ("B4", 250.0, 353.0), + ("B5", 176.0, 250.0), + ("C4", 229.0, 324.0), + ("C5", 162.0, 229.0), + ("C6", 114.0, 162.0), + ("DL", 110.0, 220.0), + ] { + let preset = standard_preset("print", name); + assert_eq!((preset.width, preset.height, preset.pixels_per_inch), (mm(width), mm(height), 300.0), "{name}"); + } + let photo = standard_preset("photo", "Portrait, 8 x 10"); + assert_eq!((photo.width, photo.height), (2400, 3000)); + let postcard = standard_preset("art", "Postcard"); + assert_eq!((postcard.width, postcard.height, postcard.pixels_per_inch), (1200, 1800, 300.0), "4 x 6 in, portrait"); + let video = standard_preset("art", "720p"); + assert_eq!((video.width, video.height, video.pixels_per_inch), (1280, 720, 72.0)); +} + +#[trial] +fn the_pixel_grids_keep_their_pixels_at_the_print_resolution() { + use craft_ui::runtime::env::UnitKind; + let grid = standard_preset("art", "1000 pixel grid"); + assert!(grid.is_print() && !grid.in_inches()); + for (print, screen) in [(300.0, 72.0), (200.0, 96.0)] { + let options = grid.options(print, screen); + assert_eq!( + (options.size.width, options.size.height, options.pixels_per_inch, options.unit), + (1000, 1000, print, UnitKind::Pixels), + "{print} ppi" + ); + } + // A print preset keeps its inches at the print resolution; a screen preset its pixels at the screen resolution. + let postcard = standard_preset("art", "Postcard").options(200.0, 96.0); + assert_eq!((postcard.size.width, postcard.size.height, postcard.pixels_per_inch, postcard.unit), (800, 1200, 200.0, UnitKind::Inches)); + let video = standard_preset("art", "720p").options(200.0, 96.0); + assert_eq!((video.size.width, video.size.height, video.pixels_per_inch, video.unit), (1280, 720, 96.0, UnitKind::Pixels)); +} + +#[trial] +fn the_art_tab_shows_the_grids_in_pixels_and_the_postcard_in_inches() { + let mut options = DocumentOptions::default(); + let mut fixture = Fixture::new(move |ui| { + let _ = NewDocumentDialog::new(Bind::bound(&mut options)).show(ui); + }); + fixture.room(Vec2::new(1400.0, 1000.0)).idle(30); + let art = fixture.by_label("Art & Illustration").expect("the Art & Illustration tab"); + fixture.click(&art).idle(10); + assert!(shows(&fixture, "1000 × 1000 px @ 300 ppi"), "the grid's card is in pixels"); + assert!(shows(&fixture, "4 × 6 in @ 300 ppi"), "the postcard's card is in inches"); +}