From e18e3c066ff3dbfc1b7445f2bbf79db91adb0d1a Mon Sep 17 00:00:00 2001 From: Timothy Daly <100327160+timothydaly1@users.noreply.github.com> Date: Tue, 13 Oct 2026 02:04:02 -0400 Subject: [PATCH] OpenRaster: never overwrite an .ora with less than the document has (#3806) (#3881) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * OpenRaster: never overwrite an .ora with less than the document has (#3806) File › Save wrote any document back to its .ora, though OpenRaster drops adjustment layers, layer styles, vector masks and clipping, applies masks and fill opacity to the pixels and rasterises type and shape layers; the save then marked the document saved, so the edits were lost without asking. An OpenRaster file now counts as the document's own file only while it holds everything in it. photocraft_io::ora_losses lists what a save would leave out, from the same checks the writer warns with but without encoding anything, and file_cmds::holds says whether a format keeps the whole document (PSD, PSB and .pcraft always; OpenRaster when nothing is lost). When it doesn't: - File › Save opens Save As on a PSD of the same name, with a notice listing what OpenRaster would drop, instead of overwriting the .ora; - a save to an .ora path writes a copy, as Photoshop does for formats that can't keep everything: the document keeps its file and stays unsaved; - automation (app.save, the headless doc.save) refuses a pathless save with the reasons and treats an .ora save as a copy. An sRGB profile is no longer reported as lost, as OpenRaster readers assume sRGB. A plain document still saves back to its .ora. Co-Authored-By: Claude Opus 5.5 * i18n(vi): translate the OpenRaster save notice vi.tsv is now a complete catalog, so the two new strings need Vietnamese rows. Terms follow the catalog's own: Không thể for can't, như for such as, Lưu bản sao for Save a Copy. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_018CiFWEfKibLnwb6oSy6ZBE * i18n(hu, tr): translate the OpenRaster save notice main added complete Hungarian and Turkish catalogs after this branch was cut, so every_tl_literal_is_translated needs their rows for the two new strings. Wording follows each catalog: informal Hungarian with "{name}" after a colon; formal Turkish with Biçim for format. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_018CiFWEfKibLnwb6oSy6ZBE * i18n(sr): translate the OpenRaster save notice Main gained a complete Serbian catalogue (#4436); every_tl_literal_is_translated needs the notice's two strings there too. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 Co-authored-by: Brandon Thomas --- crates/automation/src/headless.rs | 17 ++++--- crates/automation/tests/openraster.rs | 37 +++++++++++++++ crates/engine/src/file_cmds.rs | 32 ++++++++++++- crates/engine/src/file_cmds/tests.rs | 20 ++++++++ crates/io/src/lib.rs | 1 + crates/io/src/ora.rs | 61 ++++++++++++++++++++----- crates/io/src/ora/tests.rs | 50 ++++++++++++++++++++ crates/ui-egui/src/file_dialog/tests.rs | 48 +++++++++++++++++++ crates/ui-egui/src/i18n/cs.tsv | 2 + crates/ui-egui/src/i18n/de.tsv | 2 + crates/ui-egui/src/i18n/el.tsv | 2 + crates/ui-egui/src/i18n/es.tsv | 2 + crates/ui-egui/src/i18n/fr.tsv | 2 + crates/ui-egui/src/i18n/hu.tsv | 2 + crates/ui-egui/src/i18n/id.tsv | 2 + crates/ui-egui/src/i18n/it.tsv | 2 + crates/ui-egui/src/i18n/ja.tsv | 2 + crates/ui-egui/src/i18n/ko.tsv | 2 + crates/ui-egui/src/i18n/nl.tsv | 2 + crates/ui-egui/src/i18n/pl.tsv | 2 + crates/ui-egui/src/i18n/pt-br.tsv | 2 + crates/ui-egui/src/i18n/ru.tsv | 2 + crates/ui-egui/src/i18n/sr.tsv | 2 + crates/ui-egui/src/i18n/tr.tsv | 2 + crates/ui-egui/src/i18n/uk.tsv | 2 + crates/ui-egui/src/i18n/vi.tsv | 2 + crates/ui-egui/src/i18n/zh-hans.tsv | 2 + crates/ui-egui/src/i18n/zh-hant.tsv | 2 + crates/ui-egui/src/lib.rs | 37 +++++++++------ crates/ui-egui/src/menus.rs | 24 ++++++++-- docs/ora.md | 13 +++++- 31 files changed, 337 insertions(+), 43 deletions(-) diff --git a/crates/automation/src/headless.rs b/crates/automation/src/headless.rs index cd92f584a2..d6b3c17102 100644 --- a/crates/automation/src/headless.rs +++ b/crates/automation/src/headless.rs @@ -230,9 +230,11 @@ impl Headless { (None, Some(p)) => { let own = file_cmds::extension(p); let written = format.map(|f| f.trim_start_matches('.').to_ascii_lowercase()).or_else(|| own.clone()); - if !file_cmds::saves_in_place(p) || written != own { + if !file_cmds::holds_at(&doc, p) || written != own { + let lost = file_cmds::losses_at(&doc, p); + let why = if lost.is_empty() { String::new() } else { format!(" (it can't keep: {})", lost.join("; ")) }; return Err(AutomationError::BadRequest(format!( - "pass `path`: without one, only a PSD, PSB or .pcraft file is written back, in its own format, so `{p}` was left unchanged" + "pass `path`: without one, only a PSD, PSB, .pcraft or OpenRaster file that holds the whole document is written back, in its own format, so `{p}` was left unchanged{why}" ))); } PathBuf::from(p) @@ -255,13 +257,14 @@ impl Headless { } }; warnings.extend(photocraft_engine::type_extra_cmds::missing_font_warnings(&doc)); - // A layered document save (PSD, PSB, OpenRaster or .pcraft) is a full write, not a flattened copy: - // record the current revision as saved so the session stops reporting `dirty`, and make - // the file the document's path. A flat export (PNG, JPEG, …) is a copy and leaves both - // alone (#1547). + // A layered document save (PSD, PSB, OpenRaster or .pcraft) that holds the whole document is a + // full write, not a flattened copy: record the current revision as saved so the session + // stops reporting `dirty`, and make the file the document's path. A flat export (PNG, + // JPEG, …), or an OpenRaster file that drops part of it, is a copy and leaves both alone + // (#1547, #3806). let ext = format.map(|f| f.trim_start_matches('.').to_ascii_lowercase()).or_else(|| target.extension().map(|e| e.to_string_lossy().to_ascii_lowercase())); - if ext.as_deref().is_some_and(file_cmds::layered_extension) { + if ext.as_deref().is_some_and(|e| file_cmds::holds(&doc, e)) { // Saving by index must not retarget the next automation command. let previously_active = self.session.active_index(); self.session.set_active(i); diff --git a/crates/automation/tests/openraster.rs b/crates/automation/tests/openraster.rs index fe941c50b4..428ecfffb9 100644 --- a/crates/automation/tests/openraster.rs +++ b/crates/automation/tests/openraster.rs @@ -66,3 +66,40 @@ fn a_corrupt_openraster_file_reports_an_error() { assert!(err.to_string().contains("OpenRaster"), "{err}"); std::fs::remove_dir_all(dir).unwrap(); } + +/// #3806: an OpenRaster file holds only what OpenRaster can. Once the document has an adjustment +/// layer, a pathless save refuses to overwrite the .ora (saying what it would drop), and a save to +/// an .ora path writes a copy: the document keeps its file and stays unsaved. +#[test] +fn an_openraster_file_never_overwrites_what_it_cannot_hold() { + let dir = tmp("lossy"); + let path = dir.join("art.ora"); + let path_str = path.to_str().unwrap(); + let mut h = Headless::trusted_local(); + h.handle("doc.new", json!({"width": 40, "height": 30, "background": "white"})).unwrap(); + exec(&mut h, "layer.new.layer", json!({})); + exec(&mut h, "paint.stroke", json!({"points": [[4, 4], [30, 20]], "size": 6, "hardness": 1.0, "color": "#ff0000"})); + h.handle("doc.save", json!({"path": path_str})).unwrap(); + let original = std::fs::read(&path).unwrap(); + // A Curves adjustment layer: OpenRaster has no adjustment layers. + exec(&mut h, "layer.newAdjustmentLayer.curves", json!({})); + assert!(h.session.active().unwrap().is_dirty()); + let err = h.handle("doc.save", json!({})).unwrap_err().to_string(); + assert!(err.contains("adjustment layers"), "{err}"); + assert_eq!(std::fs::read(&path).unwrap(), original, "the original is untouched"); + assert!(h.session.active().unwrap().is_dirty(), "and the edits are still unsaved"); + // Saving to an .ora path explicitly writes a copy (with the warnings), not the document's file. + let copy = dir.join("copy.ora"); + let saved = h.handle("doc.save", json!({"path": copy.to_str().unwrap()})).unwrap(); + assert!(saved["warnings"].as_array().is_some_and(|w| w.iter().any(|w| w.as_str().is_some_and(|w| w.contains("adjustment layers")))), "{saved}"); + let st = h.session.active().unwrap(); + assert!(st.is_dirty(), "a copy leaves the edits unsaved"); + assert_eq!(st.path.as_deref(), Some(path_str), "the document keeps its file"); + // As PSD it holds everything, so that becomes the document's file. + let psd = dir.join("art.psd"); + h.handle("doc.save", json!({"path": psd.to_str().unwrap()})).unwrap(); + let st = h.session.active().unwrap(); + assert!(!st.is_dirty()); + assert_eq!(st.path.as_deref(), psd.to_str()); + std::fs::remove_dir_all(dir).unwrap(); +} diff --git a/crates/engine/src/file_cmds.rs b/crates/engine/src/file_cmds.rs index 9f274d530d..5e9f7455c8 100644 --- a/crates/engine/src/file_cmds.rs +++ b/crates/engine/src/file_cmds.rs @@ -151,8 +151,9 @@ pub fn extension(path: &str) -> Option { file_name(path).rsplit_once('.').filter(|(base, ext)| !base.is_empty() && !ext.is_empty()).map(|(_, ext)| ext.to_ascii_lowercase()) } -/// Whether a save without a new path may write back to `path`: only layered files (PSD, PSB, -/// .pcraft). A flat file goes through Save As instead, so it is never flattened over the original. +/// Whether a save without a new path may write back to `path` as far as its format goes: only +/// layered files (PSD, PSB, OpenRaster, .pcraft). A flat file goes through Save As instead, so it +/// is never flattened over the original. Whether this document fits is [`holds_at`]. pub fn saves_in_place(path: &str) -> bool { extension(path).is_some_and(|ext| layered_extension(&ext)) } @@ -164,6 +165,33 @@ pub fn layered_extension(ext: &str) -> bool { matches!(ext, "psd" | "psb" | "pcraft" | "ora") } +/// Whether a file in format `ext` (lower-case) holds the whole of `doc`, so it can be the +/// document's own file: PSD, PSB and .pcraft always; OpenRaster only when it drops nothing (no +/// adjustment layers, styles, masks…, [`photocraft_io::ora_losses`]). A save to a format that +/// doesn't hold the document is a copy, and File › Save goes through Save As, so an editable +/// original is never overwritten with less than it had (#3806). +pub fn holds(doc: &photocraft_doc::Document, ext: &str) -> bool { + match ext { + "psd" | "psb" | "pcraft" => true, + "ora" => photocraft_io::ora_losses(doc).is_empty(), + _ => false, + } +} + +/// [`holds`] for the file at `path`. +pub fn holds_at(doc: &photocraft_doc::Document, path: &str) -> bool { + extension(path).is_some_and(|ext| holds(doc, &ext)) +} + +/// What a save of `doc` to `path` would leave out when its format can't hold it: OpenRaster's +/// [`photocraft_io::ora_losses`]; empty for other formats. +pub fn losses_at(doc: &photocraft_doc::Document, path: &str) -> Vec { + match extension(path).as_deref() { + Some("ora") => photocraft_io::ora_losses(doc), + _ => Vec::new(), + } +} + /// Whether `path` names a document template (.psdt). A template opens as a new untitled document /// without its path, so a save never writes over the template. pub fn is_template(path: &str) -> bool { diff --git a/crates/engine/src/file_cmds/tests.rs b/crates/engine/src/file_cmds/tests.rs index 737b14ad8d..fdfcf6c4b5 100644 --- a/crates/engine/src/file_cmds/tests.rs +++ b/crates/engine/src/file_cmds/tests.rs @@ -901,6 +901,26 @@ fn only_layered_files_save_in_place() { assert_eq!(extension("my.dir/name"), None); } +/// #3806: a layered format holds a document only if it keeps everything in it. +#[test] +fn openraster_holds_a_document_only_when_it_drops_nothing() { + let mut s = session(16, 16, 8); + s.execute("layer.new.layer", json!({})).unwrap(); + let plain = doc(&s).clone(); + for p in ["a.psd", "a.psb", "a.pcraft", "a.ora", "A.ORA"] { + assert!(holds_at(&plain, p), "{p}"); + } + for p in ["a.png", "a.tif", "a", ""] { + assert!(!holds_at(&plain, p), "{p}"); + } + assert!(losses_at(&plain, "a.ora").is_empty()); + s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap(); + let adjusted = doc(&s).clone(); + assert!(holds_at(&adjusted, "a.psd") && !holds_at(&adjusted, "a.ora")); + assert!(losses_at(&adjusted, "a.ora").iter().any(|l| l.contains("adjustment layers")), "{:?}", losses_at(&adjusted, "a.ora")); + assert!(losses_at(&adjusted, "a.psd").is_empty()); +} + #[test] fn templates_open_untitled_without_their_path() { assert!(is_template("dir/card.PSDT") && !is_template("card.psd") && !is_template("psdt")); diff --git a/crates/io/src/lib.rs b/crates/io/src/lib.rs index 87f40b12df..b80da66c3c 100644 --- a/crates/io/src/lib.rs +++ b/crates/io/src/lib.rs @@ -49,6 +49,7 @@ mod kra; pub mod linked; mod multichannel_map; mod ora; +pub use ora::losses as ora_losses; pub mod pattern_map; mod pdn; pub mod pixels; diff --git a/crates/io/src/ora.rs b/crates/io/src/ora.rs index dba3c96197..42b2ab7a33 100644 --- a/crates/io/src/ora.rs +++ b/crates/io/src/ora.rs @@ -476,6 +476,8 @@ struct Writer<'a> { next: usize, sample: CSample, warnings: Warnings, + /// Only collect the warnings ([`losses`]): no pixels are rendered or encoded. + dry: bool, } /// Straight RGBA floats as interleaved PNG samples at `sample` depth. @@ -559,6 +561,20 @@ impl Writer<'_> { attrs } + /// What saving a non-group layer's pixels loses: a type, shape, fill or smart object layer + /// becomes pixels, and its pixel mask is applied to them. + fn content_warnings(&mut self, layer: &Layer) { + if !matches!(layer.content, LayerContent::Raster(_)) { + self.warnings.layer(&layer.name, &format!("{} layers are saved to OpenRaster as pixels", layer.content.kind_name().to_lowercase())); + } + if let Some(mask) = layer.mask.as_ref().filter(|m| m.enabled) { + if mask.feather > 0.0 { + self.warnings.layer(&layer.name, "layer mask feathering is not applied in OpenRaster"); + } + self.warnings.layer(&layer.name, "layer masks were applied to the layer pixels"); + } + } + /// The layer's own pixels (straight RGBA floats) and their bounds; its pixel mask applied. fn pixels(&mut self, layer: &Layer) -> (Rect, Vec<[f32; 4]>) { let canvas = self.doc.bounds(); @@ -578,15 +594,10 @@ impl Writer<'_> { solo.mask = None; solo.effects = Default::default(); let r = photocraft_compose::composite_bounds(&solo, canvas).unwrap_or(canvas).intersect(&canvas); - self.warnings.layer(&layer.name, &format!("{} layers are saved to OpenRaster as pixels", layer.content.kind_name().to_lowercase())); (r, photocraft_compose::render_layer(&solo, r).px) } }; if let Some(mask) = layer.mask.as_ref().filter(|m| m.enabled) { - if mask.feather > 0.0 { - self.warnings.layer(&layer.name, "layer mask feathering is not applied in OpenRaster"); - } - self.warnings.layer(&layer.name, "layer masks were applied to the layer pixels"); let mut values = Vec::new(); mask.values_into(rect, &mut values); for (p, m) in buf.iter_mut().zip(values) { @@ -623,6 +634,10 @@ impl Writer<'_> { } _ => { let attrs = self.common(layer); + self.content_warnings(layer); + if self.dry { + continue; + } let (rect, px) = self.pixels(layer); let (rect, px) = if rect.is_empty() { (Rect::from_xywh(0, 0, 1, 1), vec![[0.0; 4]]) } else { (rect, px) }; let src = format!("data/layer{}.png", self.next); @@ -648,10 +663,8 @@ pub(crate) fn export(doc: &Document) -> Result { let mut zip = ZipWriter::new(); // The mimetype must be the first entry, stored, so the type is readable at a fixed offset. zip.add("mimetype", MIMETYPE)?; - let mut w = Writer { doc, zip, xml: String::new(), next: 0, sample, warnings: Warnings::default() }; - if doc.depth == SampleType::F32 { - w.warnings.note("32-bit float layers are saved as 16-bit PNGs"); - } + let mut w = Writer { doc, zip, xml: String::new(), next: 0, sample, warnings: Warnings::default(), dry: false }; + document_warnings(doc, &mut w.warnings); w.xml.push_str(&format!( "\n", doc.size.width, @@ -661,24 +674,48 @@ pub(crate) fn export(doc: &Document) -> Result { )); w.layers(&doc.layers, 1)?; w.xml.push_str("\n"); - let Writer { mut zip, xml, mut warnings, .. } = w; + let Writer { mut zip, xml, warnings, .. } = w; zip.add("stack.xml", xml.as_bytes())?; let merged = photocraft_compose::flatten(doc); zip.add("mergedimage.png", &png(doc.size.width, doc.size.height, &merged.px, sample)?)?; let thumb = photocraft_compose::thumbnail(doc, THUMBNAIL_SIDE); let thumb = Image::from_raw(thumb.width, thumb.height, ChannelLayout::Rgba, CSample::U8, thumb.pixels)?; zip.add("Thumbnails/thumbnail.png", &codecs::encode(&thumb, Format::Png, &codecs::EncodeOptions::default())?)?; + Ok(ExportResult { bytes: zip.finish()?, warnings: warnings.finish() }) +} + +/// What saving `doc` to OpenRaster loses that isn't in a layer. +fn document_warnings(doc: &Document, warnings: &mut Warnings) { + if doc.depth == SampleType::F32 { + warnings.note("32-bit float layers are saved as 16-bit PNGs"); + } if !doc.channels.is_empty() { warnings.note("alpha channels are not saved to OpenRaster"); } if !doc.metadata.text.is_empty() || doc.metadata.xmp.is_some() || doc.metadata.exif.is_some() { warnings.note("metadata (XMP, EXIF, text) is not saved to OpenRaster"); } - if doc.icc_profile.is_some() { + // Readers assume sRGB, so an sRGB document loses nothing by the missing tag. + let srgb = |bytes: &[u8]| photocraft_cms::Profile::parse(bytes).is_ok_and(|p| p.same_colors(photocraft_cms::Builtin::Srgb.profile())); + if doc.icc_profile.as_deref().is_some_and(|b| !srgb(b)) { warnings.note("the colour profile is not saved to OpenRaster; readers assume sRGB"); } if doc.mode == ColorMode::Grayscale { warnings.note("grayscale layers are saved as RGB"); } - Ok(ExportResult { bytes: zip.finish()?, warnings: warnings.finish() }) +} + +/// Everything saving `doc` to OpenRaster would lose (the warnings [`export`] gives), without +/// rendering or encoding anything. Empty when an OpenRaster file holds the whole document, so it +/// can be the document's own file; otherwise a save to OpenRaster is a copy (#3806). +pub fn losses(doc: &Document) -> Vec { + if !matches!(doc.mode, ColorMode::Rgb | ColorMode::Grayscale) { + return vec!["OpenRaster holds RGB layers; convert the document to RGB or Grayscale first".into()]; + } + let mut w = Writer { doc, zip: ZipWriter::new(), xml: String::new(), next: 0, sample: CSample::U8, warnings: Warnings::default(), dry: true }; + document_warnings(doc, &mut w.warnings); + if let Err(e) = w.layers(&doc.layers, 1) { + w.warnings.note(&e.to_string()); + } + w.warnings.finish() } diff --git a/crates/io/src/ora/tests.rs b/crates/io/src/ora/tests.rs index 625630d08c..319414a94d 100644 --- a/crates/io/src/ora/tests.rs +++ b/crates/io/src/ora/tests.rs @@ -397,3 +397,53 @@ fn group_opacity_and_fill_are_combined_without_affecting_raster_opacity() { assert!((back.layers[0].opacity - 0.25).abs() < 1e-6); assert_eq!(back.layers[0].children().unwrap()[0].opacity, 1.0); } + +/// One document per thing OpenRaster can't hold, each also checked against the exporter. +fn lossy_documents() -> Vec<(&'static str, Document)> { + let fmt = PixelFormat::new(ColorMode::Rgb, SampleType::U8, true); + let with = |f: &dyn Fn(&mut Document)| { + let mut d = doc(SampleType::U8); + f(&mut d); + d + }; + vec![ + ("adjustment", with(&|d| d.layers.push(Layer::new("Curves", LayerContent::Adjustment(Adjustment::Invert))))), + ("fill", with(&|d| d.layers.push(Layer::new("Fill", LayerContent::Fill(Fill::Solid(Color::rgba(1.0, 0.0, 0.0, 1.0))))))), + ("mask", { + let mut l = block("Masked", fmt, 0, 0, 20, 20, 9); + l.mask = Some(LayerMask::reveal_all()); + with(&move |d| d.layers.push(l.clone())) + }), + ("clipped", with(&|d| d.layers[1].clipped = true)), + ("fill opacity", with(&|d| d.layers[0].fill_opacity = 0.5)), + ("float", doc(SampleType::F32)), + ("profile", with(&|d| d.icc_profile = Some(photocraft_cms::Builtin::DisplayP3.profile().to_bytes()))), + ("metadata", with(&|d| d.metadata.xmp = Some("".into()))), + ] +} + +/// The exporter's warnings and [`losses`] are one list, so they can't drift apart. +#[test] +fn losses_are_exactly_what_the_exporter_warns_about() { + for (what, d) in lossy_documents() { + let losses = losses(&d); + assert!(!losses.is_empty(), "{what}: OpenRaster can't hold it"); + assert_eq!(losses, export(&d).unwrap().warnings, "{what}"); + } +} + +/// A document of plain pixel layers and groups loses nothing, so its OpenRaster file can stay its +/// own; an sRGB profile isn't a loss, as readers assume sRGB. +#[test] +fn plain_documents_lose_nothing() { + for depth in [SampleType::U8, SampleType::U16] { + let mut d = doc(depth); + assert_eq!(losses(&d), Vec::::new(), "{depth:?}"); + d.icc_profile = Some(photocraft_cms::Builtin::Srgb.profile().to_bytes()); + assert_eq!(losses(&d), Vec::::new(), "{depth:?} tagged sRGB"); + assert_eq!(export(&d).unwrap().warnings, Vec::::new()); + } + let mut cmyk = doc(SampleType::U8); + cmyk.mode = ColorMode::Cmyk; + assert_eq!(losses(&cmyk).len(), 1, "a document OpenRaster can't hold at all"); +} diff --git a/crates/ui-egui/src/file_dialog/tests.rs b/crates/ui-egui/src/file_dialog/tests.rs index 202cc73888..8e19c67b48 100644 --- a/crates/ui-egui/src/file_dialog/tests.rs +++ b/crates/ui-egui/src/file_dialog/tests.rs @@ -726,3 +726,51 @@ fn export_as_with_several_artboards_selected_writes_one_file_each() { got.sort_unstable(); assert_eq!(got, [(10, 25), (20, 15)], "each board at its own size, scaled to 50 %"); } + +/// #3806: File › Save on an OpenRaster file that can't hold the document (here an adjustment +/// layer) doesn't overwrite it: Save As opens on a PSD with a notice saying what the .ora would +/// drop, and the PSD becomes the document's file. A plain document still saves back to its .ora. +#[test] +fn openraster_save_never_overwrites_what_it_cannot_hold() { + let (mut app, open, written) = app(); + app.run("layer.new.layer", json!({})).unwrap(); + app.session.active_mut().unwrap().path = Some("/pics/art.ora".into()); + let ctx = egui::Context::default(); + menus::invoke(&mut app, &ctx, "file.save", json!({})).unwrap(); + assert_eq!(*written.borrow(), ["/pics/art.ora"], "a plain document saves in place"); + app.run("layer.newAdjustmentLayer.invert", json!({})).unwrap(); + let notices = app.ui.notices.len(); + menus::invoke(&mut app, &ctx, "file.save", json!({})).unwrap(); + app.poll_file_dialog(&ctx, None); + assert_eq!(written.borrow().len(), 1, "the .ora is not overwritten"); + assert!(matches!(open.borrow().as_slice(), [(FileDialogRequest::Save { suggested }, _)] if suggested == "/pics/art.psd"), "Save As offers PSD"); + assert_eq!(app.ui.notices.len(), notices + 1); + assert!(app.ui.notices.last().unwrap().lines.iter().any(|l| l.contains("adjustment layers")), "{:?}", app.ui.notices.last().unwrap().lines); + assert!(app.session.active().unwrap().is_dirty(), "the edits are still unsaved"); + answer(&open, Some(FileDialogAnswer::SaveTo("/pics/art.psd".into()))); + app.poll_file_dialog(&ctx, None); + assert_eq!(written.borrow().last().map(String::as_str), Some("/pics/art.psd")); + let st = app.session.active().unwrap(); + assert_eq!(st.path.as_deref(), Some("/pics/art.psd")); + assert!(!st.is_dirty()); +} + +/// Save As to OpenRaster of a document it can't hold writes a copy, as Photoshop does for formats +/// that can't keep everything: the document keeps its file and its unsaved state. An automation +/// save without a path won't overwrite such an .ora either. +#[test] +fn save_as_openraster_of_what_it_cannot_hold_is_a_copy() { + let (mut app, _open, written) = app(); + app.run("layer.newAdjustmentLayer.invert", json!({})).unwrap(); + app.session.active_mut().unwrap().path = Some("/pics/art.psd".into()); + let ctx = egui::Context::default(); + menus::invoke(&mut app, &ctx, "file.saveAs", json!({"path": "/pics/copy.ora"})).unwrap(); + assert_eq!(*written.borrow(), ["/pics/copy.ora"]); + let st = app.session.active().unwrap(); + assert_eq!(st.path.as_deref(), Some("/pics/art.psd"), "the document keeps its file"); + assert!(st.is_dirty()); + app.session.active_mut().unwrap().path = Some("/pics/art.ora".into()); + let err = app.save_automation(None).unwrap_err(); + assert!(err.contains("OpenRaster"), "{err}"); + assert_eq!(written.borrow().len(), 1); +} diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index 495fe5eb1f..201ce4a2ea 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -81,6 +81,8 @@ Save Uložit Save As… Uložit jako… Save a Copy… Uložit kopii… + {name} can't keep everything in this document {name} nedokáže uchovat vše z tohoto dokumentu + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Zvolte formát, který vše zachová, například Photoshop (PSD), nebo uložte kopii. Revert Vrátit k uložené verzi Export Export Quick Export as PNG Rychlý export do PNG diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index de11847575..d8cac0f730 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -77,6 +77,8 @@ Save Speichern Save As… Speichern unter… Save a Copy… Kopie speichern… + {name} can't keep everything in this document {name} kann nicht alles in diesem Dokument erhalten + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Wählen Sie ein Format, das alles erhält, etwa Photoshop (PSD), oder speichern Sie eine Kopie. Revert Zurücksetzen Export Exportieren Quick Export as PNG Schnellexport als PNG diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index 3b81c4b636..337ca4584d 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -58,6 +58,8 @@ Save Αποθήκευση Save As… Αποθήκευση ως… Save a Copy… Αποθήκευση αντιγράφου… + {name} can't keep everything in this document Το {name} δεν μπορεί να κρατήσει όλο το περιεχόμενο αυτού του εγγράφου + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Επιλέξτε μια μορφή που τα κρατά όλα, όπως Photoshop (PSD), ή αποθηκεύστε ένα αντίγραφο. Revert Επαναφορά αποθηκευμένης έκδοσης Export Εξαγωγή Quick Export as PNG Γρήγορη εξαγωγή σε PNG diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index 0a47b7a539..3f262bb12e 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -74,6 +74,8 @@ Save Guardar Save As… Guardar como… Save a Copy… Guardar una copia… + {name} can't keep everything in this document {name} no puede conservar todo lo que tiene este documento + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Elija un formato que lo conserve todo, como Photoshop (PSD), o guarde una copia. Revert Volver Export Exportar Quick Export as PNG Exportación rápida como PNG diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index a3a39498e5..31663c2404 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -79,6 +79,8 @@ Save Enregistrer Save As… Enregistrer sous… Save a Copy… Enregistrer une copie… + {name} can't keep everything in this document {name} ne peut pas conserver tout le contenu de ce document + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Choisissez un format qui conserve tout, comme Photoshop (PSD), ou enregistrez une copie. Revert Revenir à la version enregistrée Export Exporter Quick Export as PNG Exportation rapide au format PNG diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index c0237c621d..545a29aa36 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -218,6 +218,8 @@ Rotate 90° Counter Clockwise Forgatás 90°-kal az óramutató járásával szemben Save Mentés Save a Copy… Másolat mentése… + {name} can't keep everything in this document Nem őrizhető meg minden a dokumentumból ebben a formátumban: {name} + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Válassz olyan formátumot, amely mindent megőriz, például Photoshop (PSD), vagy ments másolatot. Save As… Mentés másként… Save for Web (Legacy)… Mentés webre (régi)… Scale Méretarány diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index ae03ea06e9..2923b01a98 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -72,6 +72,8 @@ Save Simpan Save As… Simpan Sebagai… Save a Copy… Simpan Salinan… + {name} can't keep everything in this document {name} tidak dapat menyimpan semua isi dokumen ini + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Pilih format yang menyimpan semuanya, seperti Photoshop (PSD), atau simpan salinan. Revert Kembalikan Export Ekspor Quick Export as PNG Ekspor Cepat ke PNG diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index ec0b10070b..a4d8805e5a 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -74,6 +74,8 @@ Save Salva Save As… Salva con nome… Save a Copy… Salva una copia… + {name} can't keep everything in this document {name} non può conservare tutto il contenuto di questo documento + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Scegli un formato che conservi tutto, come Photoshop (PSD), oppure salva una copia. Revert Ripristina Export Esporta Quick Export as PNG Esportazione rapida come PNG diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 5e063a6906..45eb2c9c40 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -75,6 +75,8 @@ Save 保存 Save As… 名前を付けて保存… Save a Copy… コピーを保存… + {name} can't keep everything in this document {name} にはこのドキュメントの内容をすべて保存できません + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Photoshop (PSD) などすべてを保持できる形式を選ぶか、コピーを保存してください。 Revert 復帰 Export 書き出し Quick Export as PNG PNG としてクイック書き出し diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index abf32226c8..56f3f5bf07 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -64,6 +64,8 @@ Save 저장 Save As… 다른 이름으로 저장… Save a Copy… 사본 저장… + {name} can't keep everything in this document {name}에는 이 문서의 모든 내용을 저장할 수 없습니다 + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Photoshop(PSD)처럼 모든 내용을 유지하는 형식을 선택하거나 사본을 저장하세요. Revert 되돌리기 Export 내보내기 Quick Export as PNG PNG로 빠르게 내보내기 diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index 7fdaee3d31..3fbe7cf2c8 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -67,6 +67,8 @@ Save Opslaan Save As… Opslaan als… Save a Copy… Kopie opslaan… + {name} can't keep everything in this document {name} kan niet alles in dit document bewaren + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Kies een indeling die alles bewaart, zoals Photoshop (PSD), of sla een kopie op. Revert Terugzetten Export Exporteren Quick Export as PNG Snel exporteren als PNG diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index 44f05e1f04..98adf9dcec 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -74,6 +74,8 @@ Save Zapisz Save As… Zapisz jako… Save a Copy… Zapisz kopię… + {name} can't keep everything in this document {name} nie może zachować wszystkiego z tego dokumentu + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Wybierz format, który zachowa wszystko, na przykład Photoshop (PSD), lub zapisz kopię. Revert Przywróć ostatnio zapisany Export Eksportuj Quick Export as PNG Szybki eksport jako PNG diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index 36c8079824..f2f1034a1e 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -75,6 +75,8 @@ Save Salvar Save As… Salvar como… Save a Copy… Salvar uma cópia… + {name} can't keep everything in this document {name} não consegue manter tudo o que há neste documento + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Escolha um formato que mantenha tudo, como Photoshop (PSD), ou salve uma cópia. Revert Reverter Export Exportar Quick Export as PNG Exportação rápida como PNG diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index 6db38291ef..9a65752621 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -83,6 +83,8 @@ Save Сохранить Save As… Сохранить как… Save a Copy… Сохранить копию… + {name} can't keep everything in this document {name} не может сохранить все содержимое этого документа + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Выберите формат, который сохранит все, например Photoshop (PSD), или сохраните копию. Save… Сохранить… Revert Восстановить Import Импорт diff --git a/crates/ui-egui/src/i18n/sr.tsv b/crates/ui-egui/src/i18n/sr.tsv index 11604ef8b9..c1ca0e8582 100644 --- a/crates/ui-egui/src/i18n/sr.tsv +++ b/crates/ui-egui/src/i18n/sr.tsv @@ -78,6 +78,8 @@ Save Sačuvaj Save As… Sačuvaj kao… Save a Copy… Sačuvaj kopiju… + {name} can't keep everything in this document {name} ne može da sačuva sve iz ovog dokumenta + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Izaberite format koji sve čuva, na primer Photoshop (PSD), ili sačuvajte kopiju. Revert Vrati sačuvano Export Izvoz Quick Export as PNG Brzi izvoz u PNG diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index f7834ec5ea..1eb8e16f42 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -64,6 +64,8 @@ Save Kaydet Save As… Farklı Kaydet… Save a Copy… Bir Kopyasını Kaydet… + {name} can't keep everything in this document {name} bu belgedeki her şeyi koruyamaz + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Photoshop (PSD) gibi her şeyi koruyan bir biçim seçin ya da bir kopyasını kaydedin. Revert Geri Döndür Export Dışa Aktar Quick Export as PNG PNG Olarak Hızlı Dışa Aktarma diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index 8fc8f1b797..921b7b1e03 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -73,6 +73,8 @@ Save Зберегти Save As… Зберегти як… Save a Copy… Зберегти копію… + {name} can't keep everything in this document {name} не може зберегти весь вміст цього документа + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Виберіть формат, який збереже все, наприклад Photoshop (PSD), або збережіть копію. Save… Зберегти… Revert Повернути до збереженого Import Імпорт diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index 3ffe96661b..68acfe2db2 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -156,6 +156,8 @@ Rotate 90° Counter Clockwise Xoay 90° ngược chiều kim đồng hồ Save Lưu Save a Copy… Lưu bản sao… + {name} can't keep everything in this document {name} không thể giữ mọi thứ trong tài liệu này + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. Hãy chọn một định dạng giữ được mọi thứ, như Photoshop (PSD), hoặc lưu bản sao. Save As… Lưu thành… Save for Web (Legacy)… Lưu cho Web (cũ)… Scale Tỷ lệ diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index a3bb7fa704..d8fc715989 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -73,6 +73,8 @@ Save 保存 Save As… 另存为… Save a Copy… 保存副本… + {name} can't keep everything in this document {name} 无法保留此文档中的所有内容 + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. 请选择能保留全部内容的格式,例如 Photoshop (PSD),或存储副本。 Revert 恢复 Export 导出 Quick Export as PNG 快速导出为 PNG diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index e3ddcbb55d..1219fa31d6 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -81,6 +81,8 @@ Save 儲存 Save As… 另存新檔… Save a Copy… 儲存拷貝… + {name} can't keep everything in this document {name} 無法保留此文件中的所有內容 + Choose a format that keeps it, such as Photoshop (PSD), or save a copy. 請選擇能保留全部內容的格式,例如 Photoshop (PSD),或儲存拷貝。 Revert 回復 Export 匯出 Quick Export as PNG 快速匯出為 PNG diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index c10d18ddbd..131a670ee2 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1277,8 +1277,11 @@ impl PhotocraftApp { // masks and layer appearance settings need a layered format even with just one layer. let flat = plain_raster(&st.doc).is_some(); let ext = st.path.as_deref().and_then(|p| std::path::Path::new(p).extension()).map(|e| e.to_string_lossy().to_ascii_lowercase()); + // An OpenRaster file only when it holds the whole document (#3806): else PSD is offered. + let holds_ora = st.path.as_deref().is_some_and(|p| photocraft_engine::file_cmds::holds_at(&st.doc, p)); let writable = ext.is_some_and(|e| { - matches!(e.as_str(), photocraft_format::EXTENSION | "psd" | "psb" | "tif" | "tiff" | "ora") + matches!(e.as_str(), photocraft_format::EXTENSION | "psd" | "psb" | "tif" | "tiff") + || (e == "ora" && holds_ora) || (flat && photocraft_codecs::from_extension(&e).is_some_and(|f| f.caps().write)) }); let suggested = match &st.path { @@ -1348,14 +1351,11 @@ impl PhotocraftApp { return Err("Answer TIFF or Targa Options before starting another save".into()); } if id == "file.save" { - let path = self - .session - .active() - .ok_or("no document")? - .path - .clone() - .filter(|p| photocraft_engine::file_cmds::saves_in_place(p)) - .ok_or("Save writes back only to the document's own PSD, PSB or .pcraft file")?; + let st = self.session.active().ok_or("no document")?; + let path = + st.path.clone().filter(|p| photocraft_engine::file_cmds::holds_at(&st.doc, p)).ok_or( + "Save writes back only to the document's own PSD, PSB, .pcraft or OpenRaster file, and to OpenRaster only when it holds everything", + )?; return self.save_in_place(path); } let path = params.get("path").and_then(Value::as_str).filter(|p| !p.is_empty()).ok_or("Save As needs a `path`")?; @@ -1394,10 +1394,13 @@ impl PhotocraftApp { // A flat file that can't hold the document (its layers, or the layered file it lives in) // is written as a copy, as in Photoshop: the document keeps its file, so Save still // writes the layered original and the edits stay unsaved (#2550). + // An OpenRaster file that can't hold everything (adjustment layers, styles…) is a copy too, + // so the editable document isn't marked saved after losing them (#3806). let st = self.session.active().ok_or("no document")?; - let layered = - |p: &str| photocraft_engine::file_cmds::saves_in_place(p) || matches!(photocraft_engine::file_cmds::extension(p).as_deref(), Some("tif" | "tiff")); - Ok(tiff_layers == Some(false) || (!layered(path) && (plain_raster(&st.doc).is_none() || st.path.as_deref().is_some_and(layered)))) + let tiff = |p: &str| matches!(photocraft_engine::file_cmds::extension(p).as_deref(), Some("tif" | "tiff")); + let holds = photocraft_engine::file_cmds::holds_at(&st.doc, path) || tiff(path); + let lives_layered = st.path.as_deref().is_some_and(|p| photocraft_engine::file_cmds::saves_in_place(p) || tiff(p)); + Ok(tiff_layers == Some(false) || (!holds && (plain_raster(&st.doc).is_none() || lives_layered))) } /// Writes the active document to a known path. `tiff_layers` is the TIFF Options answer: @@ -1449,7 +1452,10 @@ impl PhotocraftApp { // copy, as in the headless server (#2579). let (hooks, arm) = match kind { SaveKind::User => (true, true), - SaveKind::Automation => (false, photocraft_engine::file_cmds::extension(path).is_some_and(|e| photocraft_engine::file_cmds::layered_extension(&e))), + SaveKind::Automation => { + let holds = self.session.documents().iter().find(|st| st.doc.id == doc).is_some_and(|st| photocraft_engine::file_cmds::holds_at(&st.doc, path)); + (false, holds) + } }; self.ui.status = crate::i18n::fmt(tl!("Saved {name}"), &[("name", path)]); if !copy { @@ -1516,8 +1522,9 @@ impl PhotocraftApp { let target = { let state = self.session.active().ok_or("no document")?; // As File › Save: without `path` only a layered file is written back (#416). - path.or_else(|| state.path.clone().filter(|p| photocraft_engine::file_cmds::saves_in_place(p))) - .ok_or("pass `path`: a save without one writes back only to the document's own PSD, PSB or .pcraft file")? + path.or_else(|| state.path.clone().filter(|p| photocraft_engine::file_cmds::holds_at(&state.doc, p))).ok_or( + "pass `path`: a save without one writes back only to the document's own PSD, PSB, .pcraft or OpenRaster file, and to OpenRaster only when it holds everything (adjustment layers, styles and masks don't fit)", + )? }; let reply = |path: &str, warnings: &[String]| json!({"path": path, "warnings": warnings}); // #2017: the File › Save worker path, so the encode doesn't block the frame loop. diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index ee59da8e70..a2f57c585a 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -306,14 +306,28 @@ pub(crate) fn invoke_unguarded(app: &mut PhotocraftApp, ctx: &egui::Context, id: app.ask_folder(|app, path| app.run("file.import.videoFramesToLayers", json!({"path": path})).map_err(|e| e.to_string())) } "file.save" => { - // Writes back only to a layered file; a flat one goes through Save As. + // Writes back only to a layered file that holds the whole document; anything else + // goes through Save As, so the original is never overwritten with less (#3806). let tga_bits = crate::targa_options_ui::bits_param(¶ms, id)?; match params.get("path").and_then(Value::as_str) { Some(path) => app.save_as_with(Some(path.to_string()), tga_bits), - None => match app.session.active().and_then(|d| d.path.clone()).filter(|p| photocraft_engine::file_cmds::saves_in_place(p)) { - Some(path) => app.save_in_place(path), - None => app.save_as_with(None, tga_bits), - }, + None => { + let own = app.session.active().and_then(|d| d.path.clone().map(|p| (photocraft_engine::file_cmds::holds_at(&d.doc, &p), p, d))); + match own { + Some((true, path, _)) => app.save_in_place(path), + Some((false, path, d)) if photocraft_engine::file_cmds::saves_in_place(&path) => { + // Its own file is layered but can't hold what the document has now. + let losses = photocraft_engine::file_cmds::losses_at(&d.doc, &path); + let name = crate::file_open::display_name(&path); + let title = crate::i18n::fmt(tl!("{name} can't keep everything in this document"), &[("name", name.as_str())]); + let mut lines = losses; + lines.push(tl!("Choose a format that keeps it, such as Photoshop (PSD), or save a copy.").to_string()); + crate::notices::post(app, title, lines, false, None); + app.save_as_with(None, tga_bits) + } + _ => app.save_as_with(None, tga_bits), + } + } } } "file.exit" => { diff --git a/docs/ora.md b/docs/ora.md index 263befc00c..19f3c7503e 100644 --- a/docs/ora.md +++ b/docs/ora.md @@ -23,10 +23,18 @@ entry, so an OpenRaster file with another extension still opens as one. Saving reports what OpenRaster can't hold, layer by layer: pixel masks are applied to the layer's pixels, fill opacity is folded into the pixels, text, shape, fill and smart object layers are written as their rendered pixels, and adjustment layers, layer styles, vector masks, -clipping, alpha channels, metadata and the colour profile are left out. Xor and Paint.NET's +clipping, alpha channels, metadata and a colour profile other than sRGB are left out. Xor and Paint.NET's Color Burn and Color Dodge variants have no OpenRaster name and are saved as Normal. CMYK, Lab and other modes are refused with a message to convert first; Grayscale saves as RGB. +An OpenRaster file is the document's own file only while it holds everything in it (#3806). +`photocraft_io::ora_losses` lists what a save would leave out, from the same checks the writer +warns with, without encoding anything. When that list isn't empty, File › Save doesn't overwrite +the `.ora`: Save As opens on a PSD of the same name, with a notice listing what OpenRaster would +drop. A save to an `.ora` path then writes a copy, as Photoshop does for formats that can't keep +everything: the document keeps its file and its unsaved changes. Automation follows the same rule +(`doc.save` and `app.save` without a path refuse, saying why). + OpenRaster elements other than `stack` and `layer` (MyPaint's text, for example), missing layer images and unknown composite operations open with a warning instead of failing the file. Krita's W3C Soft Light (`svg:soft-light`, `krita:soft_light_svg`) and its own Hard Mix open as @@ -46,7 +54,8 @@ are covered by tests. Unit tests (`crates/io/src/ora/tests.rs`) round-trip layers, groups, pass-through, offsets, opacity, visibility, locks and every blend mode at 8 and 16 bit, check masks, rendered layer kinds, the archive layout and malformed input. `crates/automation/tests/openraster.rs` saves, -reopens, edits and saves in place through the agent surface; the CLI test converts both ways. +reopens, edits and saves in place through the agent surface, and checks that a document with an +adjustment layer never overwrites its `.ora`; the CLI test converts both ways. Real-file checks use Krita-authored oracles from [photocraft-corpus](https://github.com/storytold/photocraft-corpus) (`krita/`, made by