mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-14 19:27:07 -04:00
PDF: a placed image whose file is missing is reported as missing (#299)
A linked image that wasn't found on open has no data; the export warning said it could not be decoded. It now says it is missing and names the link. Co-authored-by: Brandon Thomas <[email protected]>
This commit is contained in:
1 parent
37803c8176
commit
0b69d6856c
2 files changed
+21
-1
No files matched your search
@@ -1259,7 +1259,13 @@ impl Exporter<'_> {
|
||||
_ => lossless(&data, fmt, mode),
|
||||
};
|
||||
if img.is_none() {
|
||||
self.warn(format!("image `{}` could not be decoded and was skipped", asset.name));
|
||||
if data.is_empty() {
|
||||
// A linked file that wasn't found when the document was opened: nothing to decode.
|
||||
let at = asset.link.as_deref().map(|l| format!(" ({l})")).unwrap_or_default();
|
||||
self.warn(format!("image `{}` is missing{at} and was skipped", asset.name));
|
||||
} else {
|
||||
self.warn(format!("image `{}` could not be decoded and was skipped", asset.name));
|
||||
}
|
||||
}
|
||||
if let Some(image) = &img {
|
||||
// Share the original encoded payload. HashMap checks exact bytes after hashing,
|
||||
|
||||
@@ -240,6 +240,20 @@ fn place(d: &mut Document, data: Vec<u8>, px: (u32, u32)) {
|
||||
d.insert_item(SpreadRef::Doc(0), it, None).unwrap();
|
||||
}
|
||||
|
||||
/// A placed image whose linked file wasn't found has no data: the warning says it is missing,
|
||||
/// not that it could not be decoded.
|
||||
#[test]
|
||||
fn a_missing_linked_image_is_reported_as_missing() {
|
||||
let mut d = doc_with_text("still here");
|
||||
place(&mut d, Vec::new(), (64, 64));
|
||||
if let Some(a) = d.assets.values_mut().next() {
|
||||
std::sync::Arc::make_mut(a).link = Some("/gone/curtains.jpeg".into());
|
||||
}
|
||||
let r = export_pdf_with_report(&d, &Cache::new(), &PdfOptions::default()).unwrap();
|
||||
assert!(r.warnings.iter().any(|w| w.contains("is missing (/gone/curtains.jpeg) and was skipped")), "{:?}", r.warnings);
|
||||
assert!(!r.warnings.iter().any(|w| w.contains("could not be decoded")), "{:?}", r.warnings);
|
||||
}
|
||||
|
||||
/// krilla reads PNG, GIF and WebP lazily, so a damaged one passed the exporter's "does it decode"
|
||||
/// check and failed the whole export when the PDF was written ("PDF writer error: … unexpected
|
||||
/// end of file"). A cut-off download must be skipped with a warning, as a damaged TIFF is.
|
||||
|
||||
Reference in new issue
Block a user