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}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
\pdfoutput=1\pdfcompresslevel=0\pdfobjcompresslevel=0\pdfpkresolution=600
|
||||
\catcode123=1\catcode125=2\pdflinkmargin=0pt
|
||||
\def\tile{\hbox to2pt{\pdfstartlink width1pt height2pt depth0pt user{/Subtype /Link /A << /S /URI /URI (https://example.invalid/) >>}\vrule width1pt height2pt\pdfendlink\hss}}
|
||||
\setbox5=\tile
|
||||
\shipout\hbox{\cleaders\copy5\hskip6pt}
|
||||
\shipout\hbox{\copy5\kern2pt\copy5}
|
||||
\shipout\hbox{\cleaders\hbox to18pt{\copy5\kern1pt\leaders\copy5\hskip1pt\copy5%
|
||||
\kern1pt\leaders\copy5\hskip4pt\kern1pt\leaders\copy5\hskip4pt\hss}\hskip37pt}
|
||||
\def\runtile{\hbox to2pt{\pdfstartlink height2pt depth0pt user{/Subtype /Link /A << /S /URI /URI (https://example.invalid/) >>}\vrule width1pt height2pt\pdfendlink\hss}}
|
||||
\shipout\vbox{\cleaders\vbox{\hbox{\cleaders\runtile\hskip6pt}}\vskip4pt}
|
||||
\end
|
||||
@@ -0,0 +1,31 @@
|
||||
[
|
||||
[
|
||||
[75985, -73993, 149978, 73993],
|
||||
[75985, -73993, 149978, 73993],
|
||||
[75985, -73993, 149978, 73993]
|
||||
],
|
||||
[
|
||||
[72000, 72000, 72996, 73993],
|
||||
[75985, 72000, 76981, 73993]
|
||||
],
|
||||
[
|
||||
[90431, -1494, 162929, 144000],
|
||||
[94416, -5480, 170899, 144000],
|
||||
[98401, -9465, 178869, 144000],
|
||||
[104379, -116832, 206765, 144000],
|
||||
[104379, -116832, 206765, 144000],
|
||||
[90431, -1494, 162929, 144000],
|
||||
[94416, -5480, 170899, 144000],
|
||||
[98401, -9465, 178869, 144000],
|
||||
[104379, -116832, 206765, 144000],
|
||||
[104379, -116832, 206765, 144000]
|
||||
],
|
||||
[
|
||||
[75985, -73993, 149978, 144000],
|
||||
[75985, -73993, 149978, 144000],
|
||||
[75985, -73993, 149978, 144000],
|
||||
[75985, -73993, 149978, 144000],
|
||||
[75985, -73993, 149978, 144000],
|
||||
[75985, -73993, 149978, 144000]
|
||||
]
|
||||
]
|
||||
Reference in new issue
Block a user