mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-20 17:37:10 +01:00
Color Settings: profile prompts finish where they were asked; CMYK falls back through its displayed Lab
- Convert to Working Space between CMYK spaces with no direct transform goes through the Lab the source displays (black-point compensated), so dark inks keep their appearance instead of being compensated twice. - An open that waits on the Profile Mismatch dialog keeps the automation roots it was asked under: OK reads linked files and installs the document under them. - A paste that runs at once remembers the document it was asked in. When another document is active by the time OK is pressed, it pastes nothing.
This commit is contained in:
1 parent
f71437f2a1
commit
2ab15e8acf
4 files changed
+87
-14
No files matched your search
@@ -592,8 +592,9 @@ impl Cms {
|
||||
/// space that looks the same, converted with `intent` (Edit → Color Settings › Convert to
|
||||
/// Working Space). RGB converts directly from profile to profile, with this context's
|
||||
/// black-point compensation. CMYK converts between two loaded profiles through ProPhoto RGB
|
||||
/// ([`IccProfile::to_same_model_of`]), and through Lab when either space is built in. Grey and
|
||||
/// Lab colours stay as they are.
|
||||
/// ([`IccProfile::to_same_model_of`]), and through the Lab it displays as
|
||||
/// ([`Self::cmyk_display_lab`]) when either space is built in. Grey and Lab colours stay as they
|
||||
/// are.
|
||||
pub fn convert_into(&self, dest: &Cms, c: &Color, intent: Intent) -> Color {
|
||||
match *c {
|
||||
Color::Rgb { r, g, b } => {
|
||||
@@ -615,7 +616,7 @@ impl Cms {
|
||||
};
|
||||
let [c, m, y, k] = match direct.as_deref() {
|
||||
Some(&[c, m, y, k]) => [c, m, y, k],
|
||||
_ => dest.lab_to_cmyk(self.cmyk_to_lab(inks), intent),
|
||||
_ => dest.lab_to_cmyk(self.cmyk_display_lab(inks), intent),
|
||||
};
|
||||
Color::Cmyk { c, m, y, k }
|
||||
}
|
||||
|
||||
@@ -495,3 +495,25 @@ fn convert_into_keeps_the_appearance() {
|
||||
assert_eq!(wide.convert_into(&working, &c, Intent::RelativeColorimetric), c);
|
||||
}
|
||||
}
|
||||
|
||||
/// With black-point compensation on, Generic CMYK displays its press black as black, so dark inks
|
||||
/// converted out of it keep that appearance: into Device CMYK, and into another document whose
|
||||
/// CMYK space is also Generic CMYK.
|
||||
#[test]
|
||||
fn convert_into_keeps_compensated_dark_inks() {
|
||||
let generic = cms();
|
||||
let device = Cms::new(&ColorSettings { cmyk: DEVICE_CMYK.into(), ..Default::default() }).unwrap();
|
||||
let other_generic = Cms::new(&ColorSettings { rgb: WIDE_GAMUT_RGB.into(), ..Default::default() }).unwrap();
|
||||
for ink in [
|
||||
Color::Cmyk { c: 0.6, m: 0.5, y: 0.5, k: 0.9 },
|
||||
Color::Cmyk { c: 0.0, m: 0.0, y: 0.0, k: 1.0 },
|
||||
Color::Cmyk { c: 0.3, m: 0.2, y: 0.2, k: 0.75 },
|
||||
] {
|
||||
for dest in [&device, &other_generic] {
|
||||
let moved = generic.convert_into(dest, &ink, Intent::RelativeColorimetric);
|
||||
assert!(matches!(moved, Color::Cmyk { .. }), "{ink:?} → {moved:?}");
|
||||
let d = delta_e2000(generic.lab(&ink), dest.lab(&moved));
|
||||
assert!(d < 2.0, "{ink:?} → {moved:?}: ΔE {d}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,12 +13,14 @@
|
||||
//! Pasting ([`PASTE_KIND`]): colors copied from a document whose profile is not this document's ask
|
||||
//! whether to keep their numbers or convert them. OK runs the paste with `profileMismatch`; Cancel
|
||||
//! pastes nothing. Fields: `mismatches` (as `clipboard.profileMismatch` lists them), `choice`
|
||||
//! (`preserveNumbers` | `convert`), `__command` and `__params` (the paste to run).
|
||||
//! (`preserveNumbers` | `convert`), `__command` and `__params` (the paste to run), and `__doc` (the
|
||||
//! uid of the document it was asked in).
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_color::cms::{self, ProfileKind};
|
||||
use vectorcraft_engine::cmd::colormgmt::ProfileChoice;
|
||||
use vectorcraft_engine::cmd::fileio::{self, ReadFile};
|
||||
use vectorcraft_engine::file_access::ScopeHandle;
|
||||
|
||||
use super::swatch_options::{grid, label};
|
||||
use super::{DialogResult, DialogSpec};
|
||||
@@ -53,6 +55,9 @@ pub(crate) struct PendingOpen {
|
||||
file: ReadFile,
|
||||
/// Where it was read from: it goes on the recent files once it opens.
|
||||
path: Option<String>,
|
||||
/// The automation roots in force where the open was asked for: its linked files are read, and
|
||||
/// the document is installed, under them.
|
||||
scope: ScopeHandle,
|
||||
}
|
||||
|
||||
/// The choices of a mismatch (`missing`: of a missing profile), as (`choice`, label).
|
||||
@@ -91,7 +96,7 @@ pub fn open_or_ask(app: &mut VectorcraftApp, file: ReadFile, path: Option<String
|
||||
"choice": q.default.id(),
|
||||
"assignProfile": q.working,
|
||||
});
|
||||
app.pending_profile_open = Some(PendingOpen { file, path });
|
||||
app.pending_profile_open = Some(PendingOpen { file, path, scope: ScopeHandle::capture() });
|
||||
app.ui.dialog = Some(Dialog::new(OPEN_KIND, fields));
|
||||
return Ok(json!({ "dialog": OPEN_KIND }));
|
||||
}
|
||||
@@ -142,21 +147,22 @@ fn open_body(_: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool
|
||||
false
|
||||
}
|
||||
|
||||
/// OK: open the waiting file as chosen. A choice the file refuses keeps the dialog open.
|
||||
/// OK: open the waiting file as chosen, under the automation roots of the open. A choice the file
|
||||
/// refuses keeps the dialog open.
|
||||
fn open_confirm(app: &mut VectorcraftApp, d: &Dialog) -> DialogResult {
|
||||
let choice = open_choice(d)?;
|
||||
let Some(mut pending) = app.pending_profile_open.take() else {
|
||||
app.ui.dialog = None;
|
||||
return Ok(Value::Null);
|
||||
};
|
||||
if let Err(e) = pending.file.answer(choice) {
|
||||
if let Err(e) = pending.scope.clone().run(|| pending.file.answer(choice)) {
|
||||
app.pending_profile_open = Some(pending);
|
||||
return Err(e.to_string());
|
||||
}
|
||||
app.ui.dialog = None;
|
||||
let PendingOpen { file, path } = pending;
|
||||
let PendingOpen { file, path, scope } = pending;
|
||||
let name = file.name();
|
||||
match fileio::open_read(&mut app.session, file) {
|
||||
scope.run(|| match fileio::open_read(&mut app.session, file) {
|
||||
Ok(r) => {
|
||||
crate::io::opened(app, &r);
|
||||
if let Some(p) = &path {
|
||||
@@ -169,7 +175,7 @@ fn open_confirm(app: &mut VectorcraftApp, d: &Dialog) -> DialogResult {
|
||||
crate::io::report_open_error(app, &name, &e);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Cancel, or the dialog closed some other way: the waiting file doesn't open.
|
||||
@@ -195,7 +201,8 @@ pub fn ask_paste(app: &mut VectorcraftApp, command: &str, params: &Value) -> Opt
|
||||
let mismatches = found["mismatches"].as_array().filter(|a| !a.is_empty())?.clone();
|
||||
// The policy of the first model starts chosen.
|
||||
let choice = mismatches[0]["default"].as_str().unwrap_or("preserveNumbers").to_string();
|
||||
let fields = json!({ "mismatches": mismatches, "choice": choice, "__command": command, "__params": params });
|
||||
let doc = app.session.active().map(|st| st.uid);
|
||||
let fields = json!({ "mismatches": mismatches, "choice": choice, "__command": command, "__params": params, DOC: doc });
|
||||
// A deferred paste this dialog asked about gives way to the new one.
|
||||
if app.ui.dialog.as_ref().is_some_and(|d| d.kind == PASTE_KIND) {
|
||||
crate::placing::cancel_swatch_paste(app);
|
||||
@@ -226,18 +233,28 @@ fn paste_body(_: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool
|
||||
false
|
||||
}
|
||||
|
||||
/// OK: run the paste with the choice; any Swatch Conflict question comes next.
|
||||
/// The field that holds the uid of the document the paste question is about.
|
||||
const DOC: &str = "__doc";
|
||||
|
||||
/// OK: run the paste with the choice; any Swatch Conflict question comes next. When another
|
||||
/// document has become the active one since a paste that runs at once asked, it closes as Cancel
|
||||
/// does and pastes nothing.
|
||||
fn paste_confirm(app: &mut VectorcraftApp, d: &Dialog) -> DialogResult {
|
||||
let choice = d.str("choice");
|
||||
if !paste_choices().iter().any(|(v, _)| *v == choice) {
|
||||
let key = "choice";
|
||||
return Err(format!("`{key}` must be one of {}", "preserveNumbers, convert"));
|
||||
}
|
||||
let deferred = d.fields.get("__deferredPaste").and_then(Value::as_u64);
|
||||
if deferred.is_none() && d.fields.get(DOC).and_then(Value::as_u64) != app.session.active().map(|st| st.uid) {
|
||||
app.ui.dialog = None;
|
||||
return Ok(json!({}));
|
||||
}
|
||||
let mut params = d.fields.get("__params").cloned().filter(Value::is_object).unwrap_or_else(|| json!({}));
|
||||
params["profileMismatch"] = json!(choice);
|
||||
app.ui.dialog = None;
|
||||
// A paste that waited for its clipboard runs in the context it was given in.
|
||||
crate::placing::confirm_swatch_paste(app, &d.str("__command"), params, d.fields.get("__deferredPaste").and_then(Value::as_u64))
|
||||
crate::placing::confirm_swatch_paste(app, &d.str("__command"), params, deferred)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -27,10 +27,40 @@ fn rgb_profile(app: &VectorcraftApp) -> Option<String> {
|
||||
vectorcraft_engine::cmd::colormgmt::doc_profiles(&app.session.doc().unwrap().doc).0
|
||||
}
|
||||
|
||||
/// An open asked under automation roots finishes under them, though OK is pressed outside them: its
|
||||
/// linked files are read, and the document is installed, with the roots of the open. `tagged` asks
|
||||
/// with the settings in force.
|
||||
fn open_asked_under_roots(app: &mut VectorcraftApp, tagged: &[u8]) {
|
||||
use vectorcraft_engine::file_access;
|
||||
let dir = crate::tests_folder::Folder::new("profile-mismatch-scope");
|
||||
let roots = file_access::AutomationRoots::new(&[dir.as_path()], &[]).unwrap();
|
||||
let r = file_access::confine(roots.as_ref(), || crate::io::open_bytes(app, "tagged.vectorcraft", tagged, None)).unwrap();
|
||||
assert_eq!(r, json!({ "dialog": OPEN_KIND }));
|
||||
assert!(file_access::current().is_none(), "OK is pressed outside the roots");
|
||||
super::super::confirm(app).unwrap();
|
||||
assert!(app.session.doc().unwrap().opened_by.is_some(), "installed under the roots of the open");
|
||||
}
|
||||
|
||||
/// Another document becomes the active one while the paste question is open: OK pastes nothing, into
|
||||
/// neither document, and the document the paste was asked in is active again afterward. `count`
|
||||
/// counts the active document's objects.
|
||||
fn paste_asked_before_another_document_is_active(app: &mut VectorcraftApp, count: impl Fn(&VectorcraftApp) -> usize) {
|
||||
let (asked_in, before) = (app.session.active_index().unwrap(), count(app));
|
||||
assert_eq!(app.run("edit.paste", json!({})).unwrap(), json!({ "dialog": PASTE_KIND }));
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
let other = count(app);
|
||||
super::super::confirm(app).unwrap();
|
||||
assert!(app.ui.dialog.is_none());
|
||||
assert_eq!(count(app), other, "nothing pasted into the document now active");
|
||||
app.run("document.activate", json!({ "index": asked_in })).unwrap();
|
||||
assert_eq!(count(app), before, "nor into the one it was asked in");
|
||||
}
|
||||
|
||||
/// With Color Settings' Ask boxes on, File › Open asks about a document whose profile is not the
|
||||
/// working space, or that has none, and opens it as chosen; Cancel doesn't open it, and a refused
|
||||
/// choice keeps the dialog. Paste asks about colors from another profile and pastes as chosen. With
|
||||
/// the boxes off, nothing asks.
|
||||
/// the boxes off, nothing asks. An open asked under automation roots finishes under them, and a
|
||||
/// paste asked in one document pastes nothing once another is active.
|
||||
#[test]
|
||||
fn opening_and_pasting_ask_about_profiles() {
|
||||
const CHILD: &str = "VECTORCRAFT_TEST_PROFILE_PROMPTS";
|
||||
@@ -88,6 +118,8 @@ fn opening_and_pasting_ask_about_profiles() {
|
||||
assert_eq!(app.session.documents().len(), docs + 1);
|
||||
assert_eq!(rgb_profile(&app).as_deref(), Some(cms::WIDE_GAMUT_RGB), "kept, though the policy converts");
|
||||
|
||||
open_asked_under_roots(&mut app, &tagged);
|
||||
|
||||
// Missing Profiles: Ask When Opening, and a choice the file refuses.
|
||||
app.run("edit.colorSettings", json!({"askMismatchOpen": false, "askMissingOpen": true, "rgbPolicy": "preserveEmbedded"})).unwrap();
|
||||
crate::io::open_bytes(&mut app, "plain.vectorcraft", &plain, None).unwrap();
|
||||
@@ -127,6 +159,7 @@ fn opening_and_pasting_ask_about_profiles() {
|
||||
app.run("edit.paste", json!({})).unwrap();
|
||||
super::super::cancel(&mut app);
|
||||
assert_eq!(count(&app), before);
|
||||
paste_asked_before_another_document_is_active(&mut app, count);
|
||||
app.run("edit.colorSettings", json!({"askMismatchPaste": false})).unwrap();
|
||||
let r = app.run("edit.paste", json!({})).unwrap();
|
||||
assert_eq!(r["profileMismatch"][0]["choice"], "preserveNumbers");
|
||||
|
||||
Reference in new issue
Block a user