From ada4f67f331127ccfb13a9abd9f956f2320592a9 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 14:23:29 -0800 Subject: [PATCH 1/2] Proof Setup: a loaded CMYK profile's black follows black-point compensation A loaded ICC CMYK profile as the device to simulate showed its darkest ink without the color settings' black-point compensation, so Simulate Black Ink made no difference there. It now shows it as the working CMYK proof of the same profile does, and Simulate Black Ink shows the press black as gray. Cancel and turning Preview off now put back the proof view the dialog found even when its device profile was removed since, and redraw the documents. Running Proof Setup again while the dialog is open keeps the open dialog, so Cancel still restores the first view. The Preserve CMYK Numbers tests put the working color settings back when they end, a failing run included, and the mask test checks the proofed square's coverage against the unmasked K100 square and the page. --- crates/color/src/cms.rs | 9 +++ crates/color/src/cms/tests_icc.rs | 19 ++++++ crates/engine/tests/color_settings.rs | 43 +++++++++--- crates/ui-egui/src/dialogs/proof_setup.rs | 80 +++++++++++++++++++++-- 4 files changed, 135 insertions(+), 16 deletions(-) diff --git a/crates/color/src/cms.rs b/crates/color/src/cms.rs index b3f312879b..0a873cd5df 100644 --- a/crates/color/src/cms.rs +++ b/crates/color/src/cms.rs @@ -446,6 +446,15 @@ impl Cms { CmykSpace::Generic(g) => g.to_srgb(cmyk, absolute, bpc), CmykSpace::Device => naive_cmyk_to_rgb(cmyk), CmykSpace::Icc(p) => { + // With black-point compensation the profile's black maps onto sRGB black, as + // `cmyk_to_srgb` shows the working space. + if bpc + && !absolute + && let Some(srgb) = builtin_rgb_cache(SRGB) + && let Some(v) = p.to_rgb_of(&srgb, &cmyk, Intent::RelativeColorimetric, true) + { + return v; + } let i = if absolute { Intent::AbsoluteColorimetric } else { Intent::RelativeColorimetric }; p.to_srgb(&cmyk, i).unwrap_or_else(|| naive_cmyk_to_rgb(cmyk)) } diff --git a/crates/color/src/cms/tests_icc.rs b/crates/color/src/cms/tests_icc.rs index 2c1d96638b..3506bcb856 100644 --- a/crates/color/src/cms/tests_icc.rs +++ b/crates/color/src/cms/tests_icc.rs @@ -187,6 +187,25 @@ fn black_point_compensation_maps_the_darkest_ink_to_rgb_black() { assert_eq!(abs(true), abs(false)); } +/// A loaded ICC CMYK profile as Proof Setup's device shows its darkest ink with the settings' +/// black-point compensation, as the working CMYK proof of the same profile does, and Simulate +/// Black Ink shows it as the lighter gray the press prints. +#[test] +fn simulate_black_ink_shows_a_loaded_cmyk_profiles_black_as_gray() { + let c = icc_cmyk(true); + let k100 = [0.0, 0.0, 0.0, 1.0]; + let device = ProofSetup { target: ProofTarget::Cmyk(c.settings().cmyk.clone()), ..Default::default() }; + let plain = c.proof_cmyk_to_srgb(k100, &device); + let working = c.proof_cmyk_to_srgb(k100, &ProofSetup { target: ProofTarget::WorkingCmyk, ..Default::default() }); + assert!(plain.iter().zip(working).all(|(a, b)| (a - b).abs() < 0.01), "device {plain:?}, working {working:?}"); + let black = c.proof_cmyk_to_srgb(k100, &ProofSetup { simulate_black: true, ..device.clone() }); + assert!(plain.iter().zip(black).all(|(a, b)| b > a + 0.03), "black ink {black:?}, without {plain:?}"); + // Without black-point compensation the device shows the darkest ink as the press prints it. + let off = icc_cmyk(false); + let plain_off = off.proof_cmyk_to_srgb(k100, &ProofSetup { target: ProofTarget::Cmyk(off.settings().cmyk.clone()), ..Default::default() }); + assert!(plain_off.iter().zip(black).all(|(a, b)| (a - b).abs() < 0.02), "without compensation {plain_off:?}, black ink {black:?}"); +} + /// #1584: every built-in profile (RGB, CMYK and gray) has each tag on a 4-byte boundary and a size /// that is a multiple of 4 (ICC.1 §7.1.2), and still reads back as the same space. #[test] diff --git a/crates/engine/tests/color_settings.rs b/crates/engine/tests/color_settings.rs index 17444e4c50..289b24436e 100644 --- a/crates/engine/tests/color_settings.rs +++ b/crates/engine/tests/color_settings.rs @@ -20,6 +20,22 @@ fn settings() -> MutexGuard<'static, ()> { SETTINGS.lock().unwrap_or_else(|e| e.into_inner()) } +/// The working Color Settings as a test found them, put back when it ends (a failing one too) +/// before the next test takes its turn. +struct Restored(cms::ColorSettings, #[allow(dead_code)] MutexGuard<'static, ()>); + +impl Drop for Restored { + fn drop(&mut self) { + let _ = cms::set_active(&self.0); + } +} + +/// [`settings`], with the working Color Settings put back afterwards. +fn restored_settings() -> Restored { + let g = settings(); + Restored(cms::working_settings(), g) +} + #[test] fn color_settings_lists_profiles_and_validates() { let _g = settings(); @@ -929,8 +945,7 @@ fn saved_color_settings_that_cannot_be_used_leave_the_defaults() { /// proofs the same way. Without it the proof starts from the drawn pixels, which are the same. #[test] fn preserve_cmyk_numbers_proofs_each_color_from_its_inks() { - let _g = settings(); - let old = cms::active_settings(); + let _g = restored_settings(); let mut s = session(); s.execute("edit.colorSettings", &json!({"cmyk": cms::DEVICE_CMYK})).unwrap(); let k50 = json!({"c": 0, "m": 0, "y": 0, "k": 50}); @@ -968,7 +983,6 @@ fn preserve_cmyk_numbers_proofs_each_color_from_its_inks() { let tint = cms::active().proof_srgb([1.0; 3], &paper).map(|v| (v * 255.0).round() as i32); let opts = RenderOptions { proof: Some(paper), background: Some([255, 255, 255, 255]), ..Default::default() }; let bare = pixel(&Renderer::new().render(&doc, 200, 200, Affine::IDENTITY, &opts).pixels, 50, 115); - cms::set_active(&old).unwrap(); assert_eq!(a, b, "the two builds show as one gray in Device CMYK"); assert_eq!(pa, pb, "proofed from the pixels, they stay one gray"); assert!(ca != cb, "proofed from their inks, they print differently: {ca:?} vs {cb:?}"); @@ -982,8 +996,7 @@ fn preserve_cmyk_numbers_proofs_each_color_from_its_inks() { /// mask covers the same in a pattern's tile as outside one. #[test] fn preserve_cmyk_numbers_leaves_mask_images_in_pattern_tiles_as_they_are() { - let _g = settings(); - let old = cms::active_settings(); + let _g = restored_settings(); let mut s = session(); // A K100 square masked by a blue image, the same at (0, 0) and as a pattern's tile. let masked = |s: &mut Session, x: f64| { @@ -1003,6 +1016,9 @@ fn preserve_cmyk_numbers_leaves_mask_images_in_pattern_tiles_as_they_are() { exec(&mut s, "object.pattern.make", json!({"ids": [tile.0], "name": "Masked Tile", "edit": false})); let band = rect(&mut s, 0.0, 100.0, 200.0, 40.0); exec(&mut s, "paint.setFill", json!({"ids": [band.0], "swatch": "Masked Tile"})); + // An unmasked K100 square, for the color the masked one covers the page with. + let solid = rect(&mut s, 100.0, 0.0, 20.0, 20.0); + exec(&mut s, "paint.setFill", json!({"ids": [solid.0], "color": {"c": 0, "m": 0, "y": 0, "k": 100}})); let proof = vectorcraft_render::proof::ProofSetup { target: vectorcraft_render::proof::ProofTarget::Cmyk(cms::GENERIC_CMYK.into()), preserve_numbers: true, @@ -1010,18 +1026,25 @@ fn preserve_cmyk_numbers_leaves_mask_images_in_pattern_tiles_as_they_are() { }; let doc = s.doc().unwrap().doc.clone(); let pixel = |px: &[u8], x: usize, y: usize| [px[(y * 200 + x) * 4], px[(y * 200 + x) * 4 + 1], px[(y * 200 + x) * 4 + 2]]; + // The masked square, the middle of a tile (the tiles start at the art's left and top edges, + // every 20 points), the unmasked square and the bare page. let shown = |proof: Option| { let opts = RenderOptions { proof, background: Some([255, 255, 255, 255]), ..Default::default() }; let px = Renderer::new().render(&doc, 200, 200, Affine::IDENTITY, &opts).pixels; - // The middle of a tile: the tiles start at the art's left and top edges, every 20 points. - (pixel(&px, 10, 10), pixel(&px, 50, 130)) + (pixel(&px, 10, 10), pixel(&px, 50, 130), pixel(&px, 110, 10), pixel(&px, 190, 60)) }; - let (plain, plain_tile) = shown(None); - let (proofed, proofed_tile) = shown(Some(proof)); - cms::set_active(&old).unwrap(); + let (plain, plain_tile, plain_k, plain_page) = shown(None); + let (proofed, proofed_tile, proofed_k, proofed_page) = shown(Some(proof)); let near = |a: [u8; 3], b: [u8; 3]| a.iter().zip(b).all(|(a, b)| (i32::from(*a) - i32::from(b)).abs() <= 2); assert!(plain != [255; 3] && near(plain, plain_tile), "the tile shows the masked square: {plain:?} vs {plain_tile:?}"); assert!(near(proofed, proofed_tile), "the tile's mask covers as the square's does: {proofed:?} vs {proofed_tile:?}"); + // The proof changes the ink's color but not how much of the page the mask lets it cover. + let channel = |v: [u8; 3], i: usize| f32::from(v[i]); + let cover = (0..3).map(|i| (channel(plain_page, i) - channel(plain, i)) / (channel(plain_page, i) - channel(plain_k, i))).sum::() / 3.0; + assert!(cover > 0.02 && cover < 0.98, "the mask covers part of the square: {cover}"); + let want: [u8; 3] = + std::array::from_fn(|i| (channel(proofed_page, i) + cover * (channel(proofed_k, i) - channel(proofed_page, i))).round() as u8); + assert!(near(proofed, want), "the proofed square keeps the mask's coverage: {proofed:?} vs {want:?}"); } /// Edit › Color Settings' color management policies decide what opening a document tagged with diff --git a/crates/ui-egui/src/dialogs/proof_setup.rs b/crates/ui-egui/src/dialogs/proof_setup.rs index 7e534de2f4..69c0655eef 100644 --- a/crates/ui-egui/src/dialogs/proof_setup.rs +++ b/crates/ui-egui/src/dialogs/proof_setup.rs @@ -34,8 +34,12 @@ const LABEL_W: f32 = 140.0; pub(super) const SPEC: DialogSpec = DialogSpec { heading: |_| tl!("Proof Setup").into(), body, confirm, min_width: 420.0, ..DialogSpec::FORM }; -/// Open the dialog on the current proof setup. +/// Open the dialog on the current proof setup. While it is open, it stays as it is, so Cancel +/// still puts back the view it found first. pub fn open(app: &mut VectorcraftApp) { + if app.ui.dialog.as_ref().is_some_and(|d| d.kind == KIND) { + return; + } let v = proof::view(); let s = &v.setup; let device = match &s.target { @@ -147,12 +151,30 @@ fn preview(app: &mut VectorcraftApp, d: &mut Dialog) { } } -/// Put back the proof view the dialog found. +/// Put back the proof view the dialog found and redraw the documents. The view is set directly, +/// not through `view.proofSetup`, which refuses a device profile removed since it was set. fn restore(app: &mut VectorcraftApp, d: &Dialog) { - if let Some(before) = d.fields.get(BEFORE).cloned() - && let Err(e) = app.run(CMD, before) - { - app.ui.status = e; + let Some(before) = d.fields.get(BEFORE) else { return }; + let text = |k: &str| before.get(k).and_then(Value::as_str).unwrap_or_default(); + let on = |k: &str| before.get(k).and_then(Value::as_bool).unwrap_or_default(); + let (Some(target), Some(intent)) = (ProofTarget::parse(text("target")), Intent::parse(text("intent"))) else { return }; + let mut v = proof::view(); + let was = v.clone(); + v.setup.target = target; + v.setup.intent = intent; + v.setup.simulate_paper = on("simulatePaper"); + v.setup.preserve_numbers = on("preserveNumbers"); + v.setup.simulate_black = on("simulateBlack"); + v.proof_colors = on("proof"); + if v == was { + return; + } + proof::set_view(v); + let uids: Vec = app.session.documents().iter().map(|d| d.uid).collect(); + for uid in uids { + if let Some(d) = app.session.document_mut(uid) { + d.revision += 1; + } } } @@ -268,6 +290,52 @@ mod tests { assert_eq!(proof::view(), before, "Cancel puts the view back"); } + /// Cancel and Preview off put back a proof view whose device profile was removed after it was + /// set, and redraw the documents. + #[test] + fn cancel_puts_back_a_view_whose_profile_was_removed() { + let _v = DefaultView::new(); + let (mut app, ctx) = app(); + let name = "Proof Setup Removed RGB"; + cms::register_icc(&cms::icc_bytes(cms::DISPLAY_P3).unwrap(), Some(name.into())).unwrap(); + app.run("view.proofSetup", json!({"target": format!("rgb:{name}"), "proof": true})).unwrap(); + app.run("color.removeProfile", json!({"name": name})).unwrap(); + let before = proof::view(); + assert_eq!(before.setup.target, ProofTarget::Rgb(name.into()), "removing the profile leaves it the device"); + app.run("ui.proofSetupDialog", json!({})).unwrap(); + app.ui.dialog.as_mut().unwrap().fields.insert("device".into(), json!(WORKING)); + frame(&mut app, &ctx); + assert_eq!(proof::view().setup.target, ProofTarget::WorkingCmyk, "the preview shows the working CMYK"); + app.ui.dialog.as_mut().unwrap().fields.insert("preview".into(), json!(false)); + frame(&mut app, &ctx); + assert_eq!(proof::view(), before, "Preview off puts the view back"); + app.ui.dialog.as_mut().unwrap().fields.insert("preview".into(), json!(true)); + frame(&mut app, &ctx); + let revision = app.session.doc().unwrap().revision; + super::super::cancel(&mut app); + assert!(app.ui.dialog.is_none()); + assert_eq!(proof::view(), before, "Cancel puts the view back"); + assert!(app.session.doc().unwrap().revision > revision, "the document redraws"); + } + + /// Run again while the dialog is open, Proof Setup keeps the dialog as it is, so Cancel still + /// puts back the view it found the first time. + #[test] + fn running_proof_setup_again_keeps_the_open_dialog() { + let _v = DefaultView::new(); + let (mut app, ctx) = app(); + let before = proof::view(); + app.run("ui.proofSetupDialog", json!({})).unwrap(); + let rgb = format!("rgb:{}", cms::DISPLAY_P3); + app.ui.dialog.as_mut().unwrap().fields.insert("device".into(), json!(rgb)); + frame(&mut app, &ctx); + assert_eq!(proof::view().setup.target, ProofTarget::Rgb(cms::DISPLAY_P3.into())); + app.run("ui.proofSetupDialog", json!({})).unwrap(); + assert_eq!(app.ui.dialog.as_ref().unwrap().str("device"), rgb, "the open dialog stays as it is"); + super::super::cancel(&mut app); + assert_eq!(proof::view(), before, "Cancel puts back the view the first run found"); + } + /// A device the dialog can't use (a profile that is not loaded) is refused, and the dialog /// stays open with the proof view as it was. #[test] From 322e02954facae8b947b6cf7140752a500b51d74 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 16:32:31 -0800 Subject: [PATCH 2/2] Proof Setup: another dialog in its place undoes its preview When another dialog replaces a previewing Proof Setup dialog, the proof view the dialog found comes back. Opening Proof Setup again starts from that view, and a Proof Setup dialog that comes back from under another dialog previews its settings again. A proof setup that a command sets after the preview starts stays when the preview is undone, whether by another dialog, Preview off or Cancel, and so does Overprint Preview. --- crates/ui-egui/src/dialogs.rs | 6 +- crates/ui-egui/src/dialogs/proof_setup.rs | 231 ++++++++++++++++++++-- crates/ui-egui/src/state.rs | 6 + 3 files changed, 227 insertions(+), 16 deletions(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 57430e1d2d..de19b24dfc 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -811,13 +811,15 @@ pub fn confirm(app: &mut VectorcraftApp) -> DialogResult { } /// After a dialog closes, and each frame: a Missing Fonts dialog that another dialog replaced waits -/// for its turn again, the search a Missing Fonts or Find Linked Files dialog started stops once -/// that dialog is gone, and with no dialog open the choice about a stopped plug-in that another +/// for its turn again, a Proof Setup preview that another dialog replaced is undone, the search a +/// Missing Fonts or Find Linked Files dialog started stops once that dialog is gone, and with no +/// dialog open the choice about a stopped plug-in that another /// dialog replaced opens again, else the questions about the next restored document's linked files /// ([`crate::recovery::ask_next`]), else the next document's Missing Fonts dialog (one dialog at a /// time). pub(crate) fn settle(app: &mut VectorcraftApp) { crate::placing::settle_swatch_paste(app); + proof_setup::restore_replaced(app); missing_fonts::requeue_replaced(app); missing_fonts::stop_when_closed(app); find_links::stop_when_closed(app); diff --git a/crates/ui-egui/src/dialogs/proof_setup.rs b/crates/ui-egui/src/dialogs/proof_setup.rs index 69c0655eef..d07cd4c24e 100644 --- a/crates/ui-egui/src/dialogs/proof_setup.rs +++ b/crates/ui-egui/src/dialogs/proof_setup.rs @@ -40,20 +40,15 @@ pub fn open(app: &mut VectorcraftApp) { if app.ui.dialog.as_ref().is_some_and(|d| d.kind == KIND) { return; } + // A preview whose dialog another one replaced is undone before this dialog takes the view. + restore_replaced(app); let v = proof::view(); let s = &v.setup; let device = match &s.target { ProofTarget::WorkingCmyk | ProofTarget::Cmyk(_) | ProofTarget::Rgb(_) => s.target.id(), _ => WORKING.to_string(), }; - let before = json!({ - "target": s.target.id(), - "intent": s.intent.id(), - "simulatePaper": s.simulate_paper, - "preserveNumbers": s.preserve_numbers, - "simulateBlack": s.simulate_black, - "proof": v.proof_colors, - }); + let before = snapshot(&v); app.ui.dialog = Some(Dialog::new( KIND, json!({ @@ -68,6 +63,19 @@ pub fn open(app: &mut VectorcraftApp) { )); } +/// The parts of the proof view `v` that Cancel puts back, as the dialog keeps them in `BEFORE`. +fn snapshot(v: &proof::ProofView) -> Value { + let s = &v.setup; + json!({ + "target": s.target.id(), + "intent": s.intent.id(), + "simulatePaper": s.simulate_paper, + "preserveNumbers": s.preserve_numbers, + "simulateBlack": s.simulate_black, + "proof": v.proof_colors, + }) +} + /// The devices to simulate, as (`device` value, name shown): the working CMYK space, then every /// CMYK profile and every RGB profile. fn devices() -> Vec<(String, String)> { @@ -136,25 +144,66 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { /// While Preview is on, the canvas shows the dialog's settings, sent again whenever they change; /// turned off, the earlier proof view comes back. fn preview(app: &mut VectorcraftApp, d: &mut Dialog) { + // Back from under another dialog that undid its preview, the dialog starts from the view the + // canvas shows now and previews again. + if d.fields.contains_key(PREVIEWED) && app.ui.proof_preview.is_none() { + d.fields.remove(PREVIEWED); + } if d.bool("preview") { let p = params(d); if d.fields.get(PREVIEWED) != Some(&p) { + // A preview that starts while the canvas shows no preview of this dialog (none yet, or a + // proof setup a command set since) takes the view the canvas shows now as the one to + // put back. + let v = proof::view(); + let start = match &app.ui.proof_preview { + Some((_, previewed)) if dialog_part(&v) == dialog_part(previewed) => None, + _ => Some(snapshot(&v)), + }; match app.run(CMD, p.clone()) { Ok(_) => { + if let Some(before) = start { + d.fields.insert(BEFORE.into(), before); + } d.fields.insert(PREVIEWED.into(), p); + app.ui.proof_preview = d.fields.get(BEFORE).map(|b| (b.clone(), proof::view())); } Err(e) => app.ui.status = e, } } } else if d.fields.remove(PREVIEWED).is_some() { - restore(app, d); + restore(app); } } -/// Put back the proof view the dialog found and redraw the documents. The view is set directly, -/// not through `view.proofSetup`, which refuses a device profile removed since it was set. -fn restore(app: &mut VectorcraftApp, d: &Dialog) { - let Some(before) = d.fields.get(BEFORE) else { return }; +/// Put back the proof view the dialog found before its preview. A proof setup set since the +/// preview (by `view.proofSetup`, for example) stays. +fn restore(app: &mut VectorcraftApp) { + if let Some((before, previewed)) = app.ui.proof_preview.take() + && dialog_part(&proof::view()) == dialog_part(&previewed) + { + set_view(app, &before); + } +} + +/// When another dialog has taken the place of a previewing Proof Setup dialog, put back the proof +/// view that dialog found. +pub(super) fn restore_replaced(app: &mut VectorcraftApp) { + if !app.ui.dialog.as_ref().is_some_and(|d| d.kind == KIND) { + restore(app); + } +} + +/// The parts of a proof view the dialog sets: the device, the intent, the three options and Proof +/// Colors. +fn dialog_part(v: &proof::ProofView) -> (&ProofTarget, Intent, bool, bool, bool, bool) { + let s = &v.setup; + (&s.target, s.intent, s.simulate_paper, s.preserve_numbers, s.simulate_black, v.proof_colors) +} + +/// Set the proof view `before` holds and redraw the documents. The view is set directly, not +/// through `view.proofSetup`, which refuses a device profile removed since it was set. +fn set_view(app: &mut VectorcraftApp, before: &Value) { let text = |k: &str| before.get(k).and_then(Value::as_str).unwrap_or_default(); let on = |k: &str| before.get(k).and_then(Value::as_bool).unwrap_or_default(); let (Some(target), Some(intent)) = (ProofTarget::parse(text("target")), Intent::parse(text("intent"))) else { return }; @@ -180,6 +229,7 @@ fn restore(app: &mut VectorcraftApp, d: &Dialog) { fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { let r = app.run(CMD, params(d))?; + app.ui.proof_preview = None; app.ui.dialog = None; Ok(r) } @@ -187,7 +237,7 @@ fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { /// Cancel: after a preview, the earlier proof view comes back. pub(super) fn cancel(app: &mut VectorcraftApp, d: &Dialog) { if d.fields.contains_key(PREVIEWED) { - restore(app, d); + restore(app); } } @@ -336,6 +386,159 @@ mod tests { assert_eq!(proof::view(), before, "Cancel puts back the view the first run found"); } + /// When another dialog (Saturate) takes the place of a previewing Proof Setup dialog, the proof + /// view the dialog found comes back, and a later Proof Setup starts from that view. + #[test] + fn another_dialog_in_its_place_puts_the_view_back() { + let _v = DefaultView::new(); + let (mut app, ctx) = app(); + let before = proof::view(); + app.run("ui.proofSetupDialog", json!({})).unwrap(); + let rgb = format!("rgb:{}", cms::DISPLAY_P3); + app.ui.dialog.as_mut().unwrap().fields.insert("device".into(), json!(rgb)); + frame(&mut app, &ctx); + assert_eq!(proof::view().setup.target, ProofTarget::Rgb(cms::DISPLAY_P3.into()), "the preview shows"); + app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 50, "height": 50})).unwrap(); + app.run("ui.saturateDialog", json!({})).unwrap(); + frame(&mut app, &ctx); + assert_eq!(app.ui.dialog.as_ref().unwrap().kind, super::super::saturate::KIND); + assert_eq!(proof::view(), before, "the preview is undone"); + super::super::cancel(&mut app); + app.run("ui.proofSetupDialog", json!({})).unwrap(); + assert_eq!(app.ui.dialog.as_ref().unwrap().str("device"), WORKING, "the next Proof Setup starts from the view it found"); + super::super::cancel(&mut app); + assert_eq!(proof::view(), before); + } + + /// Opened again before a frame has drawn the dialog that replaced a previewing Proof Setup + /// dialog, Proof Setup starts from the view the first dialog found, and Cancel keeps it. + #[test] + fn reopened_before_a_frame_starts_from_the_view_it_found() { + let _v = DefaultView::new(); + let (mut app, ctx) = app(); + let before = proof::view(); + app.run("ui.proofSetupDialog", json!({})).unwrap(); + let rgb = format!("rgb:{}", cms::DISPLAY_P3); + app.ui.dialog.as_mut().unwrap().fields.insert("device".into(), json!(rgb)); + frame(&mut app, &ctx); + assert_eq!(proof::view().setup.target, ProofTarget::Rgb(cms::DISPLAY_P3.into()), "the preview shows"); + app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 50, "height": 50})).unwrap(); + app.run("ui.saturateDialog", json!({})).unwrap(); + app.run("ui.proofSetupDialog", json!({})).unwrap(); + assert_eq!(proof::view(), before, "the preview is undone"); + assert_eq!(app.ui.dialog.as_ref().unwrap().str("device"), WORKING); + super::super::cancel(&mut app); + assert_eq!(proof::view(), before, "Cancel keeps the view the first dialog found"); + } + + /// A proof view set after another dialog replaced a previewing Proof Setup dialog, before a + /// frame, stays: the preview is not put back over it. + #[test] + fn a_view_set_after_the_replacement_stays() { + let _v = DefaultView::new(); + let (mut app, ctx) = app(); + app.run("ui.proofSetupDialog", json!({})).unwrap(); + let rgb = format!("rgb:{}", cms::DISPLAY_P3); + app.ui.dialog.as_mut().unwrap().fields.insert("device".into(), json!(rgb)); + frame(&mut app, &ctx); + app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 50, "height": 50})).unwrap(); + app.run("ui.saturateDialog", json!({})).unwrap(); + app.run("view.proofSetup", json!({"target": "protanopia", "proof": true})).unwrap(); + let set = proof::view(); + frame(&mut app, &ctx); + assert_eq!(proof::view(), set, "the view set after the replacement stays"); + super::super::cancel(&mut app); + assert_eq!(proof::view(), set); + } + + /// Overprint Preview turned on during the preview stays on when another dialog replaces the + /// dialog, and the proof setup the dialog found comes back. + #[test] + fn overprint_set_during_the_preview_stays_after_the_replacement() { + let _v = DefaultView::new(); + let (mut app, ctx) = app(); + let before = proof::view(); + app.run("ui.proofSetupDialog", json!({})).unwrap(); + let rgb = format!("rgb:{}", cms::DISPLAY_P3); + app.ui.dialog.as_mut().unwrap().fields.insert("device".into(), json!(rgb)); + frame(&mut app, &ctx); + app.run("view.overprintPreview", json!({"on": true})).unwrap(); + app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 50, "height": 50})).unwrap(); + app.run("ui.saturateDialog", json!({})).unwrap(); + frame(&mut app, &ctx); + let v = proof::view(); + assert!(v.overprint, "Overprint Preview stays on"); + assert_eq!((v.setup, v.proof_colors), (before.setup, before.proof_colors), "the proof setup comes back"); + super::super::cancel(&mut app); + } + + /// Back from under a dialog opened over it (here Saturate, as a file-replacement question is), + /// which undid the preview, the dialog previews its settings again, and Cancel puts back the + /// view it found. + #[test] + fn back_from_under_another_dialog_it_previews_again() { + let _v = DefaultView::new(); + let (mut app, ctx) = app(); + let before = proof::view(); + app.run("ui.proofSetupDialog", json!({})).unwrap(); + let rgb = format!("rgb:{}", cms::DISPLAY_P3); + app.ui.dialog.as_mut().unwrap().fields.insert("device".into(), json!(rgb)); + frame(&mut app, &ctx); + let under = app.ui.dialog.clone().unwrap(); + app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 50, "height": 50})).unwrap(); + app.run("ui.saturateDialog", json!({})).unwrap(); + app.ui.dialog.as_mut().unwrap().fields.insert(super::super::PARENT.into(), serde_json::to_value(under).unwrap()); + frame(&mut app, &ctx); + assert_eq!(proof::view(), before, "the preview is undone while the other dialog shows"); + super::super::cancel(&mut app); + assert_eq!(app.ui.dialog.as_ref().unwrap().kind, KIND, "Proof Setup comes back"); + frame(&mut app, &ctx); + assert_eq!(proof::view().setup.target, ProofTarget::Rgb(cms::DISPLAY_P3.into()), "the preview shows again"); + super::super::cancel(&mut app); + assert_eq!(proof::view(), before, "Cancel puts back the view it found"); + } + + /// A proof setup set by a command while the dialog previews stays when Preview is turned off + /// and when the dialog is canceled. + #[test] + fn a_view_set_while_the_dialog_previews_stays() { + let _v = DefaultView::new(); + let (mut app, ctx) = app(); + app.run("ui.proofSetupDialog", json!({})).unwrap(); + let rgb = format!("rgb:{}", cms::DISPLAY_P3); + app.ui.dialog.as_mut().unwrap().fields.insert("device".into(), json!(rgb)); + frame(&mut app, &ctx); + app.run("view.proofSetup", json!({"target": "protanopia", "proof": true})).unwrap(); + let set = proof::view(); + app.ui.dialog.as_mut().unwrap().fields.insert("preview".into(), json!(false)); + frame(&mut app, &ctx); + assert_eq!(proof::view(), set, "Preview off keeps the view the command set"); + app.ui.dialog.as_mut().unwrap().fields.insert("preview".into(), json!(true)); + frame(&mut app, &ctx); + assert_eq!(proof::view().setup.target, ProofTarget::Rgb(cms::DISPLAY_P3.into()), "the preview shows again"); + super::super::cancel(&mut app); + assert_eq!(proof::view(), set, "Cancel puts back the view the command set"); + } + + /// After a command sets a proof setup while the dialog previews, a changed setting previews + /// again, and Cancel puts back the proof setup the command set. + #[test] + fn a_changed_setting_after_a_command_keeps_the_commands_view_for_cancel() { + let _v = DefaultView::new(); + let (mut app, ctx) = app(); + app.run("ui.proofSetupDialog", json!({})).unwrap(); + let rgb = format!("rgb:{}", cms::DISPLAY_P3); + app.ui.dialog.as_mut().unwrap().fields.insert("device".into(), json!(rgb)); + frame(&mut app, &ctx); + app.run("view.proofSetup", json!({"target": "protanopia", "proof": true})).unwrap(); + let set = proof::view(); + app.ui.dialog.as_mut().unwrap().fields.insert("intent".into(), json!("perceptual")); + frame(&mut app, &ctx); + assert_eq!(proof::view().setup.intent, Intent::Perceptual, "the changed setting previews"); + super::super::cancel(&mut app); + assert_eq!(proof::view(), set, "Cancel puts back the view the command set"); + } + /// A device the dialog can't use (a profile that is not loaded) is refused, and the dialog /// stays open with the proof view as it was. #[test] diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index d2bc85ba9a..0f3b5e1173 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -830,6 +830,11 @@ pub struct UiState { /// [`crate::dialogs::settle`] opens the choice again once no dialog is open. #[serde(skip)] pub stopped_plugin: Option, + /// The proof view the Proof Setup dialog found, and the view its preview shows on the canvas, + /// while the preview shows. When another dialog takes its place, [`crate::dialogs::settle`] + /// puts the first view back, unless the view has changed from the preview since. + #[serde(skip)] + pub proof_preview: Option<(Value, vectorcraft_render::proof::ProofView)>, /// The search the Missing Fonts dialog started (`text.findFontFiles`'s `id`), stopped once the /// dialog is gone. #[serde(skip)] @@ -1317,6 +1322,7 @@ impl Default for UiState { pending_fonts: vec![], fonts_dialog: None, stopped_plugin: None, + proof_preview: None, dialog_search: None, links_search: None, dxf_options: Value::Null,