mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 21:27:00 +00:00
Merge pull request #8173 from dotCooCoo/fix/editing-data-fallback-says-why
.ai import: a refused PDF part's error says why the editing data couldn't be read
This commit is contained in:
@@ -286,16 +286,24 @@ fn editing_copy(opened: &vectorcraft_pdf::Opened, opts: &LoadOptions) -> Option<
|
||||
|
||||
/// A `.ai`, or a PDF saved with the editing data, whose PDF part can't be read (`e`, the import's
|
||||
/// error) from the editor's own copy of its art alone, as a file saved without PDF compatibility
|
||||
/// is read, its first note saying why: `None` when pages are picked, layers or the editing data
|
||||
/// are off, or the file has no editing data that reads. Its type is outlines when `opts` asks.
|
||||
fn without_pdf_part(bytes: &[u8], opts: &LoadOptions, e: &EngineError) -> Option<(Document, Vec<String>)> {
|
||||
/// is read, its first note saying why. Else `e`: as it is when pages are picked, layers or the
|
||||
/// editing data are off, or the file has no editing data, and followed by why when the file has
|
||||
/// editing data that can't be read. Its type is outlines when `opts` asks.
|
||||
fn without_pdf_part(bytes: &[u8], opts: &LoadOptions, e: EngineError) -> Result<(Document, Vec<String>)> {
|
||||
if opts.pages.is_some() || !opts.layers || !opts.editing_data {
|
||||
return None;
|
||||
return Err(e);
|
||||
}
|
||||
let read = vectorcraft_pdf::read_illustrator_data_without_pdf_part(bytes, opts.password.as_deref())
|
||||
.and_then(|private| private.map(|p| vectorcraft_eps::ai_alone_on_page(&p.data, p.trim, p.user_unit, opts.legacy_names)).transpose());
|
||||
match read {
|
||||
Ok(Some((doc, warnings))) => {
|
||||
let notes =
|
||||
std::iter::once(format!("the PDF part couldn't be read ({e}): the file opened from its editing data")).chain(warnings).collect();
|
||||
Ok(outlined_if_asked(doc, notes, opts))
|
||||
}
|
||||
Ok(None) => Err(e),
|
||||
Err(why) => Err(err(format!("{e}; its editing data couldn't be read either ({why})"))),
|
||||
}
|
||||
let private = vectorcraft_pdf::illustrator_data_without_pdf_part(bytes, opts.password.as_deref())?;
|
||||
let (doc, warnings) = vectorcraft_eps::ai_alone_on_page(&private.data, private.trim, private.user_unit, opts.legacy_names).ok()?;
|
||||
let notes = std::iter::once(format!("the PDF part couldn't be read ({e}): the file opened from its editing data")).chain(warnings).collect();
|
||||
Some(outlined_if_asked(doc, notes, opts))
|
||||
}
|
||||
|
||||
/// Is `w` a note on the PDF part as a page, which says nothing was skipped: that the art off the
|
||||
@@ -497,7 +505,7 @@ pub fn load_with(name: &str, bytes: &[u8], opts: &LoadOptions) -> Result<Loaded>
|
||||
.inspect(|_| editing_data = true),
|
||||
// A PDF part that can't be read (a stream the import refuses): the editing copy
|
||||
// alone where it reads, else the error.
|
||||
Err(e) => without_pdf_part(bytes, opts, &e).inspect(|_| editing_data = true).ok_or(e),
|
||||
Err(e) => without_pdf_part(bytes, opts, e).inspect(|_| editing_data = true),
|
||||
}
|
||||
})?;
|
||||
// The File Info of a file read from its pages or its editing copy.
|
||||
|
||||
@@ -799,7 +799,7 @@ fn unread_pdf_part(e: &str) -> String {
|
||||
|
||||
/// #4366: a `.ai`, or a PDF saved with the editing data, whose PDF part can't be read opens from
|
||||
/// its editing data, with a first note saying why. Pages picked, layers off or the editing data
|
||||
/// off keep the error, and so does editing data that can't be read.
|
||||
/// off keep the error. Editing data that can't be read keeps it too, followed by why.
|
||||
#[test]
|
||||
fn a_file_whose_pdf_part_cant_be_read_opens_from_its_editing_data() {
|
||||
let mut s = Session::new();
|
||||
@@ -817,10 +817,25 @@ fn a_file_whose_pdf_part_cant_be_read_opens_from_its_editing_data() {
|
||||
}
|
||||
for (name, file) in refused_files(b"%AI12_CompressedData not zlib", ai::page_pdf()) {
|
||||
let plain = open(&mut s, name, &file, json!({"editingData": false})).unwrap_err().to_string();
|
||||
assert_eq!(open(&mut s, name, &file, json!({})).unwrap_err().to_string(), plain, "{name}");
|
||||
let both = format!("{plain}; its editing data couldn't be read either (its zlib compression is damaged)");
|
||||
assert_eq!(open(&mut s, name, &file, json!({})).unwrap_err().to_string(), both, "{name}");
|
||||
for p in [json!({"pages": "1"}), json!({"layers": false})] {
|
||||
assert_eq!(open(&mut s, name, &file, p.clone()).unwrap_err().to_string(), plain, "{name}: {p}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// #4366: editing data stored in a form the reader doesn't take, beside a PDF part that can't be
|
||||
/// read, is named in the error.
|
||||
#[test]
|
||||
fn the_error_says_why_the_editing_data_couldnt_be_read() {
|
||||
let mut s = Session::new();
|
||||
let file = ai::ai_with_private_streams(&compressed(&ai::sample_data()), ai::page_pdf(), REFUSED_CONTENT, "/Filter /Bogus ");
|
||||
let plain = open(&mut s, "art.ai", &file, json!({"editingData": false})).unwrap_err().to_string();
|
||||
let e = open(&mut s, "art.ai", &file, json!({})).unwrap_err().to_string();
|
||||
assert_eq!(e, format!("{plain}; its editing data couldn't be read either (it is stored in a form that isn't read)"));
|
||||
}
|
||||
|
||||
/// A file saved in units of 10 points (`/UserUnit 10`, as in
|
||||
/// `an_ai_file_with_a_user_unit_opens_at_its_size_in_points`) whose PDF part can't be read opens
|
||||
/// from its editing data at its size in points.
|
||||
|
||||
Reference in New Issue
Block a user