io: retain note popup normalization and target layered TIFF tests

This commit is contained in:
Dylan M. Taylor committed 2026-11-15 15:14:57 -05:00
1 parent e879da042c
commit 2d74ae4aab
2 files changed
+12 -4

No files matched your search

+9 -2
View File
@@ -67,7 +67,7 @@ fn shared_writer_matches_valid_legacy_bytes() {
for x in [0.0, -5.5, f64::from(i32::MAX), f64::INFINITY] {
let note = Note { text: text.into(), author: "ä✓".repeat(180), modified: "date".into(), position: [x, 2.5], ..Default::default() };
let extra = vec![vec![0, 0, 0, 8, b's', b'n', b'd', b'A']];
assert_eq!(write_anno(&[note.clone()], &extra).unwrap(), legacy_anno(&[note], &extra));
assert_eq!(write_anno(std::slice::from_ref(&note), &extra).unwrap(), legacy_anno(&[note], &extra));
}
}
}
@@ -80,7 +80,14 @@ fn every_export_path_refuses_excess_notes() {
assert!(crate::document_to_psd(&d).is_err());
assert!(crate::document_to_psd_with(&d, &Default::default()).is_err());
assert!(crate::encode_with(&d, "psd", &Default::default(), &photocraft_raster::Interrupt::NONE).is_err());
assert!(crate::encode_with(&d, "tiff", &Default::default(), &photocraft_raster::Interrupt::NONE).is_err());
// Flat TIFF intentionally does not encode annotations. Exercise the actual layered
// Photoshop-data path; Multichannel has no TIFF layer representation.
if mode != photocraft_doc::ColorMode::Multichannel {
d.layers.push(photocraft_doc::Layer::raster("notes layer", d.pixel_format()));
let opts = crate::ExportOptions { tiff_layers: true, ..Default::default() };
assert!(crate::tiff_layers::would_write_layers(&d));
assert!(crate::encode_with(&d, "tiff", &opts, &photocraft_raster::Interrupt::NONE).is_err());
}
}
}
#[test]
+3 -2
View File
@@ -204,8 +204,9 @@ pub fn export_blocks(doc: &Document, mut blocks: Vec<photocraft_doc::PsdGlobalBl
let entries = raw.as_deref().and_then(|d| parse_entries(d));
let parsed: Option<Vec<Note>> = entries.as_ref().map(|e| e.iter().filter_map(|e| if let Entry::Text(n) = e { Some(n.clone()) } else { None }).collect());
// Unedited decoded notes retain the original bounded block, even when its legacy
// single-byte text would exceed the UTF-16 writer budget after conversion.
if parsed.as_deref() == Some(doc.notes.as_slice()) || (entries.is_none() && doc.notes.is_empty()) {
// single-byte text would exceed the UTF-16 writer budget after conversion. An all-zero
// popup still needs the established default-rectangle normalization on save (#939).
if (parsed.as_deref() == Some(doc.notes.as_slice()) && doc.notes.iter().all(|n| n.popup != [0.0; 4])) || (entries.is_none() && doc.notes.is_empty()) {
return Ok(blocks);
}
// Compare in stored precision (colours are 16-bit, positions whole pixels, empty popups get a