From a7fa03df21ff70f813a19214c126638d4b300181 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:24:12 +0100 Subject: [PATCH 1/4] =?UTF-8?q?File=20Info:=20a=20Copyrighted=20document?= =?UTF-8?q?=20shows=20=C2=A9=20before=20its=20name=20in=20the=20tab=20and?= =?UTF-8?q?=20window=20title=20(#13821)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/engine/src/cmd/file_cmds.rs | 2 +- crates/engine/src/cmd/file_cmds/info.rs | 15 +++- crates/ui-egui/src/canvas/tabs.rs | 15 +++- .../src/file_info_copyright_title_tests.rs | 74 +++++++++++++++++++ 4 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 crates/ui-egui/src/file_info_copyright_title_tests.rs diff --git a/crates/engine/src/cmd/file_cmds.rs b/crates/engine/src/cmd/file_cmds.rs index 633b25ff11f..f9d17326641 100644 --- a/crates/engine/src/cmd/file_cmds.rs +++ b/crates/engine/src/cmd/file_cmds.rs @@ -45,7 +45,7 @@ pub(crate) use batch_run::{batch_action, batch_inputs, batch_keeps_step, batch_s pub use export::{LayerExportReport, SkippedExportLayer, bake_cube, export_layers_report_with, export_layers_with}; use export::{color_lookup_tables, layers_to_files, push_unique}; use info::file_info; -pub use info::{CAMERA_FIELDS, camera_data, read_file_info, write_file_info}; +pub use info::{CAMERA_FIELDS, camera_data, copyright_marked, read_file_info, write_file_info}; #[cfg(test)] use info::{exposure_text, find_element}; pub(crate) use open::{BatchOpen, batch_open_notice, batch_open_params, remember_batch_open}; diff --git a/crates/engine/src/cmd/file_cmds/info.rs b/crates/engine/src/cmd/file_cmds/info.rs index 3f9436349d1..4cec74f0be4 100644 --- a/crates/engine/src/cmd/file_cmds/info.rs +++ b/crates/engine/src/cmd/file_cmds/info.rs @@ -99,6 +99,17 @@ fn find_attr<'a>(xmp: &'a str, prop: &str) -> Option<(usize, usize, &'a str)> { Some((i, v1 + 1, &xmp[v0..v1])) } +/// The packet's `xmpRights:Marked` value, as an element or an attribute. +fn rights_marked(xmp: &str) -> Option<&str> { + find_element(xmp, "xmpRights:Marked").map(|(_, _, v)| v.trim()).or_else(|| find_attr(xmp, "xmpRights:Marked").map(|(_, _, v)| v)) +} + +/// Whether File Info's Copyright Status reads Copyrighted (`xmpRights:Marked` is `True`): the +/// document's tab and window title then start with "© " (#13821). +pub fn copyright_marked(xmp: Option<&str>) -> bool { + xmp.and_then(rights_marked) == Some("True") +} + /// File Info fields read from an XMP packet. pub fn read_file_info(xmp: Option<&str>) -> Value { let mut m = serde_json::Map::new(); @@ -117,11 +128,9 @@ pub fn read_file_info(xmp: Option<&str>) -> Value { }; m.insert(key.into(), v); } - let marked = - find_element(x, "xmpRights:Marked").map(|(_, _, v)| v.trim().to_string()).or_else(|| find_attr(x, "xmpRights:Marked").map(|(_, _, v)| v.to_string())); m.insert( "copyrightStatus".into(), - json!(match marked.as_deref() { + json!(match rights_marked(x) { Some("True") => "copyrighted", Some("False") => "publicDomain", _ => "unknown", diff --git a/crates/ui-egui/src/canvas/tabs.rs b/crates/ui-egui/src/canvas/tabs.rs index 6eafa7b3c1e..75a5cd324bc 100644 --- a/crates/ui-egui/src/canvas/tabs.rs +++ b/crates/ui-egui/src/canvas/tabs.rs @@ -564,7 +564,14 @@ pub(crate) fn tab_title_at(app: &PhotocraftApp, i: usize, zoom: f32) -> String { let layer = active_layer.map(|l| format!("{}, ", l.name)).unwrap_or_default(); // A save in progress: "name @ 100% (Layer 1, RGB/16) - Saving 45%", as Photoshop does (#3389). let saving = crate::jobs_ui::save_progress(app, st.doc.id).map(|s| format!(" - {s}")).unwrap_or_default(); - format!("{} @ {}% ({layer}{model}/{}){}{saving}", st.doc.name, fmt_zoom(zoom), st.doc.depth.bits(), if st.is_dirty() { "*" } else { "" }) + format!("{} @ {}% ({layer}{model}/{}){}{saving}", titled_name(st), fmt_zoom(zoom), st.doc.depth.bits(), if st.is_dirty() { "*" } else { "" }) +} + +/// The document's name as its tab and window title show it: "© name" when File Info marks it +/// Copyrighted, as Photoshop does (#13821). +fn titled_name(st: &photocraft_engine::DocState) -> String { + let copyrighted = photocraft_engine::file_cmds::copyright_marked(st.doc.metadata.xmp.as_deref()); + format!("{}{}", if copyrighted { "\u{a9} " } else { "" }, st.doc.name) } /// The Studio strip's tab name: "name *" when unsaved, "name * - Saving 45%" while it saves (#3389). @@ -812,7 +819,7 @@ pub fn extra_windows(app: &mut PhotocraftApp, ctx: &egui::Context) { let wins = app.ui.windows.clone(); for w in wins.into_iter().filter(|w| w.open) { let Some(st) = app.session.documents().get(w.document) else { continue }; - let title = format!("{} — window {}", st.doc.name, w.id); + let title = format!("{} — window {}", titled_name(st), w.id); let vid = egui::ViewportId::from_hash_of(("docwin", w.id)); let mut builder = crate::os_window::builder().with_title(title).with_inner_size([800.0, 600.0]); if let Some([x, y]) = w.position { @@ -909,3 +916,7 @@ pub(super) fn move_target_after_filter(visible: &[usize], from: usize, to: usize None => document_count.saturating_sub(1), } } + +#[cfg(test)] +#[path = "../file_info_copyright_title_tests.rs"] +mod file_info_copyright_title_tests; diff --git a/crates/ui-egui/src/file_info_copyright_title_tests.rs b/crates/ui-egui/src/file_info_copyright_title_tests.rs new file mode 100644 index 00000000000..02dd5d3096e --- /dev/null +++ b/crates/ui-egui/src/file_info_copyright_title_tests.rs @@ -0,0 +1,74 @@ +//! #13821: a document File Info marks Copyrighted shows "© " before its name in the document tab +//! and the floating document window's title; Public Domain and Unknown show no prefix. + +use serde_json::json; + +use crate::PhotocraftApp; + +use super::{pro_tab_title, titled_name}; + +fn app() -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 40, "height": 30, "name": "oracle"})).unwrap(); + app +} + +fn title(app: &PhotocraftApp) -> String { + pro_tab_title(app, 0) +} + +fn status(app: &mut PhotocraftApp, status: &str) { + app.run("file.fileInfo", json!({"copyrightStatus": status})).unwrap(); +} + +#[test] +fn copyrighted_puts_the_copyright_sign_before_the_name() { + let mut app = app(); + assert_eq!(title(&app), "oracle @ 100% (RGB/8)"); + status(&mut app, "copyrighted"); + assert_eq!(title(&app), "\u{a9} oracle @ 100% (RGB/8)*"); + assert_eq!(titled_name(&app.session.documents()[0]), "\u{a9} oracle", "the floating window's title has it too"); +} + +#[test] +fn public_domain_and_unknown_show_no_prefix() { + let mut app = app(); + status(&mut app, "copyrighted"); + status(&mut app, "publicDomain"); + assert_eq!(title(&app), "oracle @ 100% (RGB/8)*"); + status(&mut app, "copyrighted"); + status(&mut app, "unknown"); + assert_eq!(title(&app), "oracle @ 100% (RGB/8)*"); + assert_eq!(titled_name(&app.session.documents()[0]), "oracle"); +} + +#[test] +fn undo_and_redo_take_the_prefix_with_them() { + let mut app = app(); + status(&mut app, "copyrighted"); + assert!(app.session.undo()); + assert!(title(&app).starts_with("oracle @ "), "{}", title(&app)); + assert!(app.session.redo()); + assert!(title(&app).starts_with("\u{a9} oracle @ "), "{}", title(&app)); +} + +#[test] +fn a_file_opened_with_the_mark_already_set_shows_the_prefix() { + let packets = [ + // Element form, as Photoshop writes it. + ( + r#" True "#, + true, + ), + // Attribute form. + (r#""#, true), + (r#""#, false), + (r#""#, false), + ]; + for (xmp, marked) in packets { + let mut app = app(); + std::sync::Arc::make_mut(&mut app.session.active_mut().unwrap().doc).metadata.xmp = Some(xmp.into()); + let want = if marked { "\u{a9} oracle @ 100% (RGB/8)" } else { "oracle @ 100% (RGB/8)" }; + assert_eq!(title(&app), want, "{xmp}"); + } +} From ddb4750bec3f0ee8d417765f40334dab05168780 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Fri, 13 Nov 2026 21:57:10 +0100 Subject: [PATCH 2/4] File Info: read xmpRights:Marked attributes with either quote and any whitespace (#13821) --- crates/engine/src/cmd/file_cmds/info.rs | 17 ++++++++++++++++- .../src/file_info_copyright_title_tests.rs | 8 ++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/file_cmds/info.rs b/crates/engine/src/cmd/file_cmds/info.rs index 4cec74f0be4..3c9bb379014 100644 --- a/crates/engine/src/cmd/file_cmds/info.rs +++ b/crates/engine/src/cmd/file_cmds/info.rs @@ -101,7 +101,22 @@ fn find_attr<'a>(xmp: &'a str, prop: &str) -> Option<(usize, usize, &'a str)> { /// The packet's `xmpRights:Marked` value, as an element or an attribute. fn rights_marked(xmp: &str) -> Option<&str> { - find_element(xmp, "xmpRights:Marked").map(|(_, _, v)| v.trim()).or_else(|| find_attr(xmp, "xmpRights:Marked").map(|(_, _, v)| v)) + find_element(xmp, "xmpRights:Marked").map(|(_, _, v)| v.trim()).or_else(|| marked_attr(xmp)) +} + +/// Attribute form `xmpRights:Marked="…"` with either quote, any XML whitespace before the name +/// and around the `=`, as XMP writers lay attributes out on their own lines. +fn marked_attr(xmp: &str) -> Option<&str> { + const NAME: &str = "xmpRights:Marked"; + xmp.match_indices(NAME).find_map(|(i, _)| { + if !xmp[..i].ends_with(|c: char| c.is_ascii_whitespace()) { + return None; + } + let rest = xmp[i + NAME.len()..].trim_start().strip_prefix('=')?.trim_start(); + let quote = rest.chars().next().filter(|&c| c == '"' || c == '\'')?; + let body = &rest[quote.len_utf8()..]; + body.find(quote).map(|end| &body[..end]) + }) } /// Whether File Info's Copyright Status reads Copyrighted (`xmpRights:Marked` is `True`): the diff --git a/crates/ui-egui/src/file_info_copyright_title_tests.rs b/crates/ui-egui/src/file_info_copyright_title_tests.rs index 02dd5d3096e..101994112a2 100644 --- a/crates/ui-egui/src/file_info_copyright_title_tests.rs +++ b/crates/ui-egui/src/file_info_copyright_title_tests.rs @@ -64,6 +64,14 @@ fn a_file_opened_with_the_mark_already_set_shows_the_prefix() { (r#""#, true), (r#""#, false), (r#""#, false), + // Single quotes, and the name on its own line or after a tab, with space around the '='. + ("", true), + ("", true), + ("", true), + ("", false), + // Not an attribute: a longer name, or the name with no '='. + ("", false), + ("", false), ]; for (xmp, marked) in packets { let mut app = app(); From 3353c5de09db952feb9d4ff76fc398e68172c664 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:10:57 +0100 Subject: [PATCH 3/4] File Info: changing the status removes every xmpRights:Marked attribute form it reads (#13821) --- crates/engine/src/cmd/file_cmds/info.rs | 21 ++++++++++++------- .../src/file_info_copyright_title_tests.rs | 21 +++++++++++++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/file_cmds/info.rs b/crates/engine/src/cmd/file_cmds/info.rs index 3c9bb379014..0fcbd76359a 100644 --- a/crates/engine/src/cmd/file_cmds/info.rs +++ b/crates/engine/src/cmd/file_cmds/info.rs @@ -101,21 +101,22 @@ fn find_attr<'a>(xmp: &'a str, prop: &str) -> Option<(usize, usize, &'a str)> { /// The packet's `xmpRights:Marked` value, as an element or an attribute. fn rights_marked(xmp: &str) -> Option<&str> { - find_element(xmp, "xmpRights:Marked").map(|(_, _, v)| v.trim()).or_else(|| marked_attr(xmp)) + find_element(xmp, "xmpRights:Marked").map(|(_, _, v)| v.trim()).or_else(|| marked_attr(xmp).map(|(_, _, v)| v)) } /// Attribute form `xmpRights:Marked="…"` with either quote, any XML whitespace before the name -/// and around the `=`, as XMP writers lay attributes out on their own lines. -fn marked_attr(xmp: &str) -> Option<&str> { +/// and around the `=`, as XMP writers lay attributes out on their own lines. Returns (start, end, +/// value) with the whitespace before the name in the span, as [`find_attr`] does, so a rewrite +/// removes every form it reads. +fn marked_attr(xmp: &str) -> Option<(usize, usize, &str)> { const NAME: &str = "xmpRights:Marked"; xmp.match_indices(NAME).find_map(|(i, _)| { - if !xmp[..i].ends_with(|c: char| c.is_ascii_whitespace()) { - return None; - } + let start = i.checked_sub(1).filter(|&s| xmp.as_bytes().get(s).is_some_and(u8::is_ascii_whitespace))?; let rest = xmp[i + NAME.len()..].trim_start().strip_prefix('=')?.trim_start(); let quote = rest.chars().next().filter(|&c| c == '"' || c == '\'')?; - let body = &rest[quote.len_utf8()..]; - body.find(quote).map(|end| &body[..end]) + let v0 = xmp.len() - rest.len() + 1; + let v1 = xmp[v0..].find(quote)? + v0; + Some((start, v1 + 1, &xmp[v0..v1])) }) } @@ -298,6 +299,10 @@ pub fn write_file_info(xmp: Option<&str>, info: &Value) -> String { while let Some((a, b, _)) = find_attr(&x, prop) { x.replace_range(a..b, ""); } + // Marked is also read in single quotes or after a tab or newline (#13821). + while let Some((a, b, _)) = (prop == "xmpRights:Marked").then(|| marked_attr(&x)).flatten() { + x.replace_range(a..b, ""); + } } let get = |k: &str| info.get(k).filter(|_| changed(k)).cloned().unwrap_or(Value::Null); let mut body = String::new(); diff --git a/crates/ui-egui/src/file_info_copyright_title_tests.rs b/crates/ui-egui/src/file_info_copyright_title_tests.rs index 101994112a2..9040577937a 100644 --- a/crates/ui-egui/src/file_info_copyright_title_tests.rs +++ b/crates/ui-egui/src/file_info_copyright_title_tests.rs @@ -80,3 +80,24 @@ fn a_file_opened_with_the_mark_already_set_shows_the_prefix() { assert_eq!(title(&app), want, "{xmp}"); } } + +#[test] +fn changing_the_status_of_an_opened_document_clears_every_attribute_form() { + for attr in ["\n xmpRights:Marked='True'", "\txmpRights:Marked = \"True\"", " xmpRights:Marked=\"True\""] { + let xmp = format!( + r#""# + ); + for steps in [&["unknown"][..], &["publicDomain", "unknown"]] { + let mut app = app(); + std::sync::Arc::make_mut(&mut app.session.active_mut().unwrap().doc).metadata.xmp = Some(xmp.clone().into()); + assert!(title(&app).starts_with("\u{a9} "), "{attr:?}"); + for &s in steps { + status(&mut app, s); + } + assert!(title(&app).starts_with("oracle @ "), "{attr:?} then {steps:?}: {}", title(&app)); + let packet = app.session.documents()[0].doc.metadata.xmp.as_deref().unwrap_or_default().to_string(); + assert!(!packet.contains("xmpRights:Marked"), "{attr:?} then {steps:?} leaves {packet}"); + assert!(packet.contains("rdf:about=\"\""), "the rest of the description stays: {packet}"); + } + } +} From f876d5264701936ccda8d88a0847716722ec2127 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Sat, 14 Nov 2026 00:24:35 +0100 Subject: [PATCH 4/4] File Info: read and remove xmpRights:Marked only as an attribute inside a tag (#13821) --- crates/engine/src/cmd/file_cmds/info.rs | 66 ++++++++++++++----- .../src/file_info_copyright_title_tests.rs | 28 ++++++++ 2 files changed, 77 insertions(+), 17 deletions(-) diff --git a/crates/engine/src/cmd/file_cmds/info.rs b/crates/engine/src/cmd/file_cmds/info.rs index 0fcbd76359a..f278bd6cea4 100644 --- a/crates/engine/src/cmd/file_cmds/info.rs +++ b/crates/engine/src/cmd/file_cmds/info.rs @@ -105,19 +105,52 @@ fn rights_marked(xmp: &str) -> Option<&str> { } /// Attribute form `xmpRights:Marked="…"` with either quote, any XML whitespace before the name -/// and around the `=`, as XMP writers lay attributes out on their own lines. Returns (start, end, -/// value) with the whitespace before the name in the span, as [`find_attr`] does, so a rewrite -/// removes every form it reads. +/// and around the `=`, as XMP writers lay attributes out on their own lines. Only names inside a +/// tag count, not text in another attribute's value, element text, a comment or CDATA. Returns +/// (start, end, value) with the whitespace before the name in the span, as [`find_attr`] does, so +/// a rewrite removes every form it reads. fn marked_attr(xmp: &str) -> Option<(usize, usize, &str)> { - const NAME: &str = "xmpRights:Marked"; - xmp.match_indices(NAME).find_map(|(i, _)| { - let start = i.checked_sub(1).filter(|&s| xmp.as_bytes().get(s).is_some_and(u8::is_ascii_whitespace))?; - let rest = xmp[i + NAME.len()..].trim_start().strip_prefix('=')?.trim_start(); - let quote = rest.chars().next().filter(|&c| c == '"' || c == '\'')?; - let v0 = xmp.len() - rest.len() + 1; - let v1 = xmp[v0..].find(quote)? + v0; - Some((start, v1 + 1, &xmp[v0..v1])) - }) + // The tab title asks every frame, and packets can be megabytes: walk only when the name is there. + if !xmp.contains("xmpRights:Marked") { + return None; + } + let b = xmp.as_bytes(); + let (mut i, mut in_tag, mut quote) = (0, false, None); + while let Some(&c) = b.get(i) { + match (in_tag, quote) { + (_, Some(q)) => quote = (c != q).then_some(q), + (false, None) if c == b'<' => { + let rest = &xmp[i..]; + let skip = [(""), ("")].into_iter().find(|(open, _)| rest.starts_with(open)); + match skip { + Some((_, close)) => i += rest.find(close).map_or(rest.len(), |e| e + close.len()) - 1, + None => in_tag = true, + } + } + (false, None) => {} + (true, None) => match c { + b'>' => in_tag = false, + b'"' | b'\'' => quote = Some(c), + _ if c.is_ascii_whitespace() => { + if let Some((end, v)) = marked_value(xmp, i + 1) { + return Some((i, end, v)); + } + } + _ => {} + }, + } + i += 1; + } + None +} + +/// `xmpRights:Marked = "value"` starting at byte `at`: (end after the closing quote, value). +fn marked_value(xmp: &str, at: usize) -> Option<(usize, &str)> { + let rest = xmp.get(at..)?.strip_prefix("xmpRights:Marked")?.trim_start().strip_prefix('=')?.trim_start(); + let quote = rest.chars().next().filter(|&c| c == '"' || c == '\'')?; + let v0 = xmp.len() - rest.len() + 1; + let v1 = xmp[v0..].find(quote)? + v0; + Some((v1 + 1, &xmp[v0..v1])) } /// Whether File Info's Copyright Status reads Copyrighted (`xmpRights:Marked` is `True`): the @@ -296,11 +329,10 @@ pub fn write_file_info(xmp: Option<&str>, info: &Value) -> String { while let Some((a, b, _)) = find_element(&x, prop) { x.replace_range(a..b, ""); } - while let Some((a, b, _)) = find_attr(&x, prop) { - x.replace_range(a..b, ""); - } - // Marked is also read in single quotes or after a tab or newline (#13821). - while let Some((a, b, _)) = (prop == "xmpRights:Marked").then(|| marked_attr(&x)).flatten() { + // Marked is removed in every attribute form it is read in, and only from tags (#13821). + loop { + let attr = if prop == "xmpRights:Marked" { marked_attr(&x) } else { find_attr(&x, prop) }; + let Some((a, b, _)) = attr else { break }; x.replace_range(a..b, ""); } } diff --git a/crates/ui-egui/src/file_info_copyright_title_tests.rs b/crates/ui-egui/src/file_info_copyright_title_tests.rs index 9040577937a..8dfedd3b0d5 100644 --- a/crates/ui-egui/src/file_info_copyright_title_tests.rs +++ b/crates/ui-egui/src/file_info_copyright_title_tests.rs @@ -101,3 +101,31 @@ fn changing_the_status_of_an_opened_document_clears_every_attribute_form() { } } } + +#[test] +fn the_name_inside_other_text_is_neither_read_nor_removed() { + const RDF: &str = r#""#; + const END: &str = ""; + let headline = r#"photoshop:Headline="Example xmpRights:Marked='True' text""#; + let quoted = [ + format!(""), + "a xmpRights:Marked=\"True\" b".to_string(), + "".to_string(), + "]]>".to_string(), + ]; + for desc in quoted { + let mut app = app(); + std::sync::Arc::make_mut(&mut app.session.active_mut().unwrap().doc).metadata.xmp = Some(format!("{RDF}{desc}{END}").into()); + assert!(title(&app).starts_with("oracle @ "), "text is not the mark: {desc}"); + } + // Beside a real attribute: the status change removes the attribute and keeps the headline. + let mut app = app(); + let xmp = format!("{RDF}{END}"); + std::sync::Arc::make_mut(&mut app.session.active_mut().unwrap().doc).metadata.xmp = Some(xmp.into()); + assert!(title(&app).starts_with("\u{a9} ")); + status(&mut app, "unknown"); + assert!(title(&app).starts_with("oracle @ "), "{}", title(&app)); + let packet = app.session.documents()[0].doc.metadata.xmp.as_deref().unwrap_or_default().to_string(); + assert!(packet.contains(headline), "the headline is unchanged: {packet}"); + assert_eq!(packet.matches("xmpRights:Marked").count(), 1, "only the headline's text is left: {packet}"); +}