From 1f24099dd99ac67f1ce6c62f80aefd9d320c3e61 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 1 Nov 2026 06:22:13 -0800 Subject: [PATCH] .ai save: test that a file opens from its VectorCraft document when the editing copy differs A .ai whose editing copy for other apps holds no transparency, while the VectorCraft document it carries holds 50% opacity, opens in VectorCraft with the opacity of the VectorCraft document. Read with native: false, the same file gives the editing copy. --- crates/engine/src/cmd/fileio/tests_pdfedit.rs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/engine/src/cmd/fileio/tests_pdfedit.rs b/crates/engine/src/cmd/fileio/tests_pdfedit.rs index 358c9840c..7b9f9774f 100644 --- a/crates/engine/src/cmd/fileio/tests_pdfedit.rs +++ b/crates/engine/src/cmd/fileio/tests_pdfedit.rs @@ -451,3 +451,29 @@ fn ai_files_carry_an_editing_copy_for_other_apps() { assert_eq!(vectorcraft_pdf::illustrator_data(&b64(&r), None), None); assert!(s.execute("document.export", &json!({"format": "ai", "editingData": "no"})).is_err()); } + +/// A `.ai` whose editing copy for other apps differs from the VectorCraft document it carries (the +/// copy has no transparency) opens in VectorCraft from the VectorCraft document. +#[test] +fn an_ai_file_opens_from_its_vectorcraft_document_when_the_editing_copy_differs() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 200, "height": 100})).unwrap(); + s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 40, "height": 30})).unwrap(); + s.execute("transparency.set", &json!({"opacity": 50})).unwrap(); + let bytes = b64(&s.execute("document.export", &json!({"format": "ai"})).unwrap()); + let opacities = |doc: &vectorcraft_doc::Document| { + let mut out = vec![]; + doc.walk(|n| { + if matches!(n.kind, vectorcraft_doc::NodeKind::Path { .. }) { + out.push(n.opacity); + } + }); + out + }; + let copy = load::load_with("art.ai", &bytes, &LoadOptions { native: false, trust_editing_data: true, ..Default::default() }).unwrap(); + assert!(copy.editing_data && !copy.restored); + assert_eq!(opacities(©.doc), [1.0]); + let opened = load::load_with("art.ai", &bytes, &LoadOptions::default()).unwrap(); + assert!(opened.restored); + assert_eq!(opacities(&opened.doc), [0.5]); +}