Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

OpenRaster: layer locks no longer change silently on save (#7018) (#7019)

David Mann44dc7c2c7736
diff --git a/crates/io/src/ora.rs b/crates/io/src/ora.rs
index f36515433..6d1bcfd87 100644
--- a/crates/io/src/ora.rs
+++ b/crates/io/src/ora.rs
@@ -566,6 +566,15 @@ impl Writer<'_> {
if layer.locks.all || layer.locks.pixels {
attrs.push_str(" edit-locked=\"true\"");
}
+ // OpenRaster's one edit lock reopens as Lock All; it has no position lock (#7018).
+ if layer.locks.pixels && !layer.locks.all {
+ self.warnings.layer(&layer.name, "Lock Image Pixels was saved as OpenRaster's edit lock; it reopens as Lock All");
+ }
+ // The Background's position lock is part of being the Background, not one the user set:
+ // every new document has it, and OpenRaster has no Background to keep it on.
+ if layer.locks.position && !layer.locks.all && !self.doc.is_background(layer.id) {
+ self.warnings.layer(&layer.name, "Lock Position is not saved to OpenRaster");
+ }
if layer.locks.transparency {
attrs.push_str(" alpha-preserve=\"true\"");
}
diff --git a/crates/io/src/ora/tests.rs b/crates/io/src/ora/tests.rs
index 4f0b1c4c4..c7c253ef2 100644
--- a/crates/io/src/ora/tests.rs
+++ b/crates/io/src/ora/tests.rs
@@ -494,6 +494,9 @@ fn lossy_documents() -> Vec<(&'static str, Document)> {
}),
("clipped", with(&|d| d.layers[1].clipped = true)),
("fill opacity", with(&|d| d.layers[0].fill_opacity = 0.5)),
+ ("pixel lock", with(&|d| d.layers[0].locks.pixels = true)),
+ // Not the bottom layer: with its transparency lock, `Base` would become the Background.
+ ("position lock", with(&|d| d.layers[1].locks.position = true)),
("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("<x/>".into()))),
@@ -520,6 +523,15 @@ fn plain_documents_lose_nothing() {
d.icc_profile = Some(photocraft_cms::Builtin::Srgb.profile().to_bytes());
assert_eq!(losses(&d), Vec::<String>::new(), "{depth:?} tagged sRGB");
assert_eq!(export(&d).unwrap().warnings, Vec::<String>::new());
+ // OpenRaster's edit-locked and alpha-preserve hold Lock All and Lock Transparent Pixels.
+ d.layers[0].locks.all = true;
+ d.layers[1].locks.transparency = true;
+ assert_eq!(losses(&d), Vec::<String>::new(), "{depth:?} locked");
+ // A Background (every new document's bottom layer) loses nothing for its position lock.
+ d.layers[0].locks.all = false;
+ d.layers[0].locks.position = true;
+ assert!(d.background().is_some());
+ assert_eq!(losses(&d), Vec::<String>::new(), "{depth:?} Background");
}
let mut cmyk = doc(SampleType::U8);
cmyk.mode = ColorMode::Cmyk;