mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-10 04:51:37 +00:00
fix(print): a printed page's form shares the page's Resources when it adds no appearance (#6089)
This commit is contained in:
1 parent
01c132a6bf
commit
14ae96a2ac
2 files changed
+24
-4
No files matched your search
@@ -219,14 +219,22 @@ pub(crate) fn page_form(
|
||||
body.extend(format!("q {} {} {} {} {} {} cm /{name} Do Q\n", n(a0), n(b0), n(c0), n(d0), n(e0), n(f0)).bytes());
|
||||
xobjects.set(name.into_bytes(), Object::Ref(ap));
|
||||
}
|
||||
if !xobjects.is_empty() {
|
||||
res.set(b"XObject".to_vec(), Object::Dict(xobjects));
|
||||
}
|
||||
// With no appearance added the form keeps the page's own Resources, shared by reference,
|
||||
// rather than a deep copy per printed page.
|
||||
let resources = match page.dict.get(b"Resources") {
|
||||
Some(r) if k == 0 && doc.resolve(r).as_dict().is_some() => r.clone(),
|
||||
_ => {
|
||||
if !xobjects.is_empty() {
|
||||
res.set(b"XObject".to_vec(), Object::Dict(xobjects));
|
||||
}
|
||||
Object::Dict(res)
|
||||
}
|
||||
};
|
||||
let mut d = Dict::new();
|
||||
d.set(b"Type".to_vec(), Object::name("XObject"));
|
||||
d.set(b"Subtype".to_vec(), Object::name("Form"));
|
||||
d.set(b"BBox".to_vec(), Object::Array(crop.iter().map(|v| Object::Real(*v)).collect()));
|
||||
d.set(b"Resources".to_vec(), Object::Dict(res));
|
||||
d.set(b"Resources".to_vec(), resources);
|
||||
if let Some(g) = page.dict.get(b"Group") {
|
||||
d.set(b"Group".to_vec(), g.clone());
|
||||
}
|
||||
|
||||
@@ -1285,3 +1285,15 @@ fn contents_pieces_join_with_a_space_across_a_trailing_comment() {
|
||||
let printed_ctrl = impose(&with_newline, &settings(vec![0], Layout::Size(SizeMode::Actual))).unwrap();
|
||||
assert_eq!(form_strings(printed_ctrl), [b"HIDDEN".to_vec(), b"SHOWN".to_vec()]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_page_form_without_annotations_shares_the_pages_indirect_resources() {
|
||||
let mut doc = fixture(2);
|
||||
let pages = pdfcraft_model::pages(&doc);
|
||||
let res = doc.add(Object::Dict([(b"Font".to_vec(), Object::Dict(Dict::new()))].into_iter().collect()));
|
||||
doc.update_dict(pages[1].obj, |d| d.set(b"Resources".to_vec(), Object::Ref(res))).unwrap();
|
||||
let pages = pdfcraft_model::pages(&doc);
|
||||
let form = imposition::page_form(&mut doc, &pages, 1, Content::default(), &mut Default::default()).unwrap();
|
||||
let Object::Stream(s) = &*doc.get(form) else { panic!("form stream") };
|
||||
assert_eq!(s.dict.get(b"Resources"), Some(&Object::Ref(res)));
|
||||
}
|
||||
Reference in new issue
Block a user