Ship native PDF annotations with reserved object numbers
This commit is contained in:
1 parent
975dbc8060
commit
de4bd1fa76
14 files changed
+299
-67
No files matched your search
@@ -797,3 +797,66 @@ fn running_links_use_the_current_matrix_and_last_device_rectangle() {
|
||||
assert_eq!(expected.iter().map(Vec::len).collect::<Vec<_>>(), [1, 1, 2, 0, 1]);
|
||||
assert_eq!(page_rectangles(&native), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn direct_annotations_keep_reserved_references_and_copy_geometry() {
|
||||
let (reference, native, diagnostics) = pair(
|
||||
r"\pdfpagewidth=200pt \pdfpageheight=200pt
|
||||
\def\space{ }
|
||||
\pdfobj reserveobjnum \edef\general{\the\pdflastobj}
|
||||
\pdfannot reserveobjnum \edef\parent{\the\pdflastannot}
|
||||
\pdfannot reserveobjnum \edef\popup{\the\pdflastannot}
|
||||
\ifnum\pdflastobj=\general\relax\else\errmessage{annotation changed last generic object}\fi
|
||||
\setbox0=\hbox{
|
||||
\pdfstartlink width6pt height3pt depth1pt user{/Subtype /Link /Border [0 0 0]}
|
||||
\vrule width6pt height3pt\pdfendlink
|
||||
\pdfsave\pdfsetmatrix{0 1 -1 0}
|
||||
\pdfannot useobjnum\parent width9pt height5pt depth1pt
|
||||
{/Subtype /Text /Contents (old^^e9) /Popup \popup\space 0 R}
|
||||
\pdfannot useobjnum\parent width8pt height4pt depth2pt
|
||||
{/Subtype /Text /Contents (duplicate) /IRT \parent\space 0 R}
|
||||
\pdfrestore
|
||||
\pdfannot useobjnum\popup width7pt height3pt depth1pt
|
||||
{/Subtype /Popup /Parent \parent\space 0 R}
|
||||
\pdfannot useobjnum\general width5pt height2pt depth1pt
|
||||
{/Subtype /Text /Contents (generic)}
|
||||
\vrule width10pt height5pt}
|
||||
\shipout\copy0\shipout\box0
|
||||
\ifnum\pdflastannot=\general\relax\else\errmessage{shipout changed last annotation}\fi",
|
||||
);
|
||||
assert!(diagnostics.is_empty(), "{diagnostics:?}");
|
||||
let inspect = |pdf: &Document| {
|
||||
let mut previous = Vec::new();
|
||||
let mut rectangles = Vec::new();
|
||||
for page in pdf.get_pages().into_values() {
|
||||
let page = pdf.get_dictionary(page).unwrap();
|
||||
let annots = get(pdf, page, b"Annots").as_array().unwrap();
|
||||
assert_eq!(annots.len(), 5);
|
||||
let ids: Vec<_> = annots.iter().map(|value| value.as_reference().unwrap()).collect();
|
||||
assert!(ids.iter().all(|id| !previous.contains(id)));
|
||||
assert_eq!(ids.iter().copied().collect::<std::collections::BTreeSet<_>>().len(), 5);
|
||||
let parent = previous.first().copied().unwrap_or(ids[0]);
|
||||
let popup = previous.get(2).copied().unwrap_or(ids[2]);
|
||||
let attrs: Vec<_> = ids.iter().map(|id| pdf.get_dictionary(*id).unwrap()).collect();
|
||||
for (dict, subtype) in attrs.iter().zip([b"Text".as_slice(), b"Text", b"Popup", b"Text", b"Link"]) {
|
||||
assert_eq!(dict.get(b"Subtype").unwrap().as_name().unwrap(), subtype);
|
||||
let rectangle = get(pdf, dict, b"Rect").as_array().unwrap().iter().map(|coordinate| {
|
||||
match coordinate {
|
||||
Object::Integer(value) => *value as f64,
|
||||
Object::Real(value) => f64::from(*value),
|
||||
other => panic!("expected a numeric coordinate, found {other:?}"),
|
||||
}
|
||||
}).collect::<Vec<_>>();
|
||||
rectangles.push(rectangle);
|
||||
}
|
||||
assert_eq!(attrs[0].get(b"Contents").unwrap().as_str().unwrap(), b"old\xe9");
|
||||
assert_eq!(attrs[0].get(b"Popup").unwrap().as_reference().unwrap(), popup);
|
||||
assert_eq!(attrs[1].get(b"IRT").unwrap().as_reference().unwrap(), parent);
|
||||
assert_eq!(attrs[2].get(b"Parent").unwrap().as_reference().unwrap(), parent);
|
||||
previous = ids;
|
||||
}
|
||||
assert_eq!(rectangles.len(), 10);
|
||||
rectangles
|
||||
};
|
||||
assert_eq!(inspect(&native), inspect(&reference));
|
||||
}
|
||||
Reference in new issue
Block a user