mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-15 03:39:50 +00:00
Color management: documents behind the front one draw through their own profiles
With Window › Arrange › Tile or floating document windows, every document other than the front one was drawn through the profiles the front document is assigned, since the active color settings are process-wide. - cms::with_active puts other settings in place of the active ones on one thread, fast paths included, and puts them back after (also on a panic). cms::for_document gives the context a document's assigned profiles make, the same one each time for the same profiles and working settings. - Each pane renders its document's art through colormgmt::doc_cms, on the render worker and on the UI thread alike, and draws its paper, artboard colors and transparency grid through the same settings. - Loading or removing a profile redraws the documents assigned it, the ones behind the front one included. - The ink and separation tables keep the tables of up to four color settings, so documents with different CMYK profiles side by side do not rebuild them on each redraw. Placed documents inside a document behind the front one still draw through the front document's profiles.
This commit is contained in:
@@ -9,7 +9,8 @@
|
||||
//! ([`use_front_profiles`]): when they are assigned, when the working settings change, and when the
|
||||
//! document comes to the front or its assignment comes back (an open, a switch, a close, a revert,
|
||||
//! an undo or a rollback, [`Session::sync_front_profiles`]); the working spaces stay as Edit → Color
|
||||
//! Settings set them.
|
||||
//! Settings set them. A document drawn while another is in front draws through its own profiles
|
||||
//! ([`doc_cms`]).
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Arc;
|
||||
@@ -236,6 +237,9 @@ fn load_profile(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
} else if proof_targets(&info.name) {
|
||||
// A new file of the CMYK profile View → Proof Setup targets: redraw.
|
||||
touch_all(s);
|
||||
} else {
|
||||
// Documents behind the front one draw through their own profiles: those assigned it redraw.
|
||||
touch_assigned(s, &info.name);
|
||||
}
|
||||
Ok(json!({"name": info.name, "kind": info.kind, "remembered": remembered}))
|
||||
}
|
||||
@@ -266,9 +270,21 @@ fn remove_profile(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if proof_targets(&info.name) {
|
||||
touch_all(s);
|
||||
}
|
||||
// Documents behind the front one draw through their own profiles: those assigned it redraw.
|
||||
touch_assigned(s, &info.name);
|
||||
Ok(json!({"removed": info.name}))
|
||||
}
|
||||
|
||||
/// Redraw the open documents assigned the profile `name`.
|
||||
fn touch_assigned(s: &mut Session, name: &str) {
|
||||
for d in &mut s.docs {
|
||||
let (rgb, cmyk) = doc_profiles(&d.doc);
|
||||
if [rgb, cmyk].iter().any(|n| n.as_deref() == Some(name)) {
|
||||
d.revision += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether View → Proof Setup targets the CMYK profile `name`.
|
||||
fn proof_targets(name: &str) -> bool {
|
||||
matches!(proof::view().setup.target, ProofTarget::Cmyk(t) if t == name)
|
||||
@@ -285,6 +301,14 @@ pub fn doc_profiles(d: &vectorcraft_doc::Document) -> (Option<String>, Option<St
|
||||
(get(&d.color_profiles.rgb), get(&d.color_profiles.cmyk))
|
||||
}
|
||||
|
||||
/// The color-management context the document draws through: the working settings with its
|
||||
/// assigned profiles in place of the working spaces, whether or not it is in front
|
||||
/// ([`cms::for_document`]).
|
||||
pub fn doc_cms(d: &vectorcraft_doc::Document) -> Arc<cms::Cms> {
|
||||
let (rgb, cmyk) = doc_profiles(d);
|
||||
cms::for_document(rgb.as_deref(), cmyk.as_deref())
|
||||
}
|
||||
|
||||
fn assign_profile(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const C: &str = "edit.assignProfile";
|
||||
let (mut rgb, mut cmyk) = doc_profiles(&s.doc()?.doc);
|
||||
|
||||
Reference in New Issue
Block a user