Match pdfTeX link rectangles in repeated leaders
This commit is contained in:
1 parent
aed7010cba
commit
5b9eca1d60
6 files changed
+178
-10
No files matched your search
@@ -1,4 +1,4 @@
|
||||
//! Reference material copied from the independent pdfTeX DVI run.
|
||||
//! Leader placement and repeated shipout effects against pdfTeX fixtures.
|
||||
use serde_json::Value;
|
||||
use std::{fs, io::Write, path::PathBuf};
|
||||
use texrra_tex_core::{execution::*, math_engine_tex::MathItem};
|
||||
@@ -176,3 +176,67 @@ fn repeated_device_effects_follow_the_paint_order_and_obey_placement_budget() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repeated_pdf_link_nodes_keep_their_final_rectangle() {
|
||||
let execution = Executor::new(
|
||||
State::initex()
|
||||
.with_etex()
|
||||
.with_input_profile(InputProfile::TeX8Bit),
|
||||
Limits::default(),
|
||||
)
|
||||
.with_native_pages()
|
||||
.run(
|
||||
SourceFile {
|
||||
name: "links.tex".into(),
|
||||
data: include_bytes!("fixtures/leaders/links.tex").to_vec(),
|
||||
},
|
||||
&mut NoFiles,
|
||||
)
|
||||
.unwrap();
|
||||
let pdf = texrra_tex_core::pdf::shipout_lists_to_native_pdf(
|
||||
&execution.shipout_display_lists().unwrap(),
|
||||
execution.state.pdf_final_options(),
|
||||
)
|
||||
.unwrap();
|
||||
let document = lopdf::Document::load_mem(&pdf).unwrap();
|
||||
|
||||
// PDF /Rect arrays from pdfTeX 1.40.29, in thousandths of a PDF point.
|
||||
let expected: Vec<Vec<[i64; 4]>> = serde_json::from_str(include_str!(
|
||||
"fixtures/leaders/reference-link-rectangles.json"
|
||||
))
|
||||
.unwrap();
|
||||
let pages = document.get_pages();
|
||||
assert_eq!(pages.len(), expected.len());
|
||||
let mut objects = std::collections::BTreeSet::new();
|
||||
for ((page, id), expected) in pages.into_iter().zip(expected) {
|
||||
let annotations = document
|
||||
.get_dictionary(id)
|
||||
.unwrap()
|
||||
.get(b"Annots")
|
||||
.unwrap()
|
||||
.as_array()
|
||||
.unwrap();
|
||||
let actual = annotations
|
||||
.iter()
|
||||
.map(|object| {
|
||||
let id = object.as_reference().unwrap();
|
||||
assert!(objects.insert(id), "duplicate annotation object on page {page}");
|
||||
let rect = document
|
||||
.get_dictionary(id)
|
||||
.unwrap()
|
||||
.get(b"Rect")
|
||||
.unwrap()
|
||||
.as_array()
|
||||
.unwrap();
|
||||
assert_eq!(rect.len(), 4);
|
||||
std::array::from_fn(|i| match rect[i] {
|
||||
lopdf::Object::Integer(value) => value * 1000,
|
||||
lopdf::Object::Real(value) => (value * 1000.0).round() as i64,
|
||||
ref value => panic!("unexpected rectangle coordinate {value:?}"),
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(actual, expected, "page {page}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user