mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-31 21:27:00 -06:00
.ai import: a PDF part cropped to the art no longer hides the layers
A PDF-compatible .ai whose PDF part's pages are cropped to its art (each page the box of all the art, the editing data's bounding box) rather than to its artboards came in as that PDF part: the editing data's artboard wasn't the page's size, so its layers were refused. With several artboards every page held all the art, so the document had a copy of everything per page. When the artboard isn't the page's size but the editing data's bounding box is, the layers are compared with the page on that box and keep their artboards. The comparison of their art with the page still decides whether they are used.
This commit is contained in:
@@ -535,6 +535,27 @@ fn an_ai_file_whose_pdf_part_is_only_text_still_opens_from_editing_data_that_rea
|
||||
check_sample(&s);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_ai_file_whose_pdf_part_is_cropped_to_its_art_opens_from_its_layers() {
|
||||
// A 400 × 200 pt artboard with two red bars across (100, 50)–(300, 150). The PDF part's page
|
||||
// is that art's box, 200 × 100 pt (the editing data's bounding box), not the artboard.
|
||||
let red = "0 1 1 0 1 0 0 Xa\n";
|
||||
let art = ai::layer("Art", &format!("{red}{}f\n{red}{}f\n", ai::rect(100.0, 50.0, 180.0, 150.0), ai::rect(220.0, 50.0, 300.0, 150.0)));
|
||||
let data = ai::editing_data_in([100.0, 50.0, 300.0, 150.0], [0.0, 0.0, 400.0, 200.0], &art);
|
||||
let page = "1 0 0 rg 0 0 80 100 re f 120 0 80 100 re f";
|
||||
let mut s = Session::new();
|
||||
let r = open(&mut s, "cropped.ai", &ai::ai(&compressed(data.as_bytes()), page), json!({})).unwrap();
|
||||
assert!(!r["warnings"].to_string().contains("weren't read"), "{r}");
|
||||
let doc = &s.doc().unwrap().doc;
|
||||
assert_eq!(names(&doc.layers), ["Art"]);
|
||||
assert_eq!(doc.artboards.len(), 1);
|
||||
assert_eq!(doc.artboards[0].rect, vectorcraft_geom::Rect::new(0.0, 0.0, 400.0, 200.0), "the file's artboard, not its page");
|
||||
let bars = doc.layers[0].children().unwrap();
|
||||
assert_eq!(bars.len(), 2);
|
||||
let b = bars[0].geometric_bounds().unwrap();
|
||||
assert!((b.x0 - 100.0).abs() < 0.01 && (b.y0 - 50.0).abs() < 0.01, "where the artboard has it: {b:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editing_data_false_opens_only_what_the_page_prints() {
|
||||
let mut s = Session::new();
|
||||
|
||||
Reference in New Issue
Block a user