Execute positioned TeX specials through native PDF devices
This commit is contained in:
1 parent
05e633bb14
commit
ce8a780031
21 files changed
+519
-29
No files matched your search
@@ -0,0 +1,98 @@
|
||||
use texrra_tex_core::{
|
||||
execution::{Event, Executor, InputProfile, Limits, NativeShipout, NoFiles, SourceFile, State},
|
||||
pdf_device::{PdfGraphics, PdfLiteralMode},
|
||||
render::DisplayItem,
|
||||
};
|
||||
|
||||
fn ship(source: &str, pdf: bool) -> NativeShipout {
|
||||
let mut state = State::initex()
|
||||
.with_etex()
|
||||
.with_input_profile(InputProfile::UnicodeScalar);
|
||||
if pdf {
|
||||
state = state.with_pdf_output();
|
||||
}
|
||||
let result = Executor::new(state, Limits::default())
|
||||
.with_native_pages()
|
||||
.run(
|
||||
SourceFile {
|
||||
name: "specials.tex".into(),
|
||||
data: format!(
|
||||
r"\catcode123=1 \catcode125=2 \catcode35=6 \pdfpkresolution=72 {source}"
|
||||
)
|
||||
.into_bytes(),
|
||||
},
|
||||
&mut NoFiles,
|
||||
)
|
||||
.unwrap();
|
||||
result
|
||||
.events
|
||||
.into_iter()
|
||||
.find_map(|event| match event {
|
||||
Event::Shipout(page) => Some(*page),
|
||||
_ => None,
|
||||
})
|
||||
.expect("the source ships one page")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn special_expansion_and_positions_follow_shipped_box_copies() {
|
||||
let page = ship(
|
||||
r"\def\payload{early}
|
||||
\setbox0=\hbox{\kern10pt\special{test:\payload Café}
|
||||
\special shipout{test:\payload}\vrule width4pt height2pt depth0pt}
|
||||
\setbox1=\hbox{\special{discarded}}
|
||||
\def\payload{late}\shipout\vbox{\kern20pt\copy0\box0}\end",
|
||||
false,
|
||||
);
|
||||
let specials: Vec<_> = page
|
||||
.specials
|
||||
.iter()
|
||||
.map(|special| (special.bytes.as_ref(), special.position))
|
||||
.collect();
|
||||
assert_eq!(
|
||||
specials,
|
||||
[
|
||||
("test:earlyCafé".as_bytes(), [655360, -131072]),
|
||||
(b"test:late", [655360, -131072]),
|
||||
("test:earlyCafé".as_bytes(), [655360, 0]),
|
||||
(b"test:late", [655360, 0]),
|
||||
]
|
||||
);
|
||||
let restored: NativeShipout =
|
||||
serde_json::from_str(&serde_json::to_string(&page).unwrap()).unwrap();
|
||||
assert_eq!(restored, page);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unicode_pdf_device_keeps_literal_modes_and_order_with_rules() {
|
||||
let page = ship(
|
||||
r"\def\paint#1{1 0 0 rg}
|
||||
\setbox0=\hbox{\kern10pt\special{pdf:literal \paint{} 0 0 10 10 re f}
|
||||
\kern5pt\special shipout{pdf:literal direct \paint{} 100 -60 7 9 re f}
|
||||
\vrule width4pt height2pt depth0pt}
|
||||
\def\paint#1{0 0 1 rg}\shipout\box0\end",
|
||||
true,
|
||||
);
|
||||
let display = page.display_list().unwrap();
|
||||
assert!(matches!(
|
||||
display.items.as_slice(),
|
||||
[
|
||||
DisplayItem::PdfGraphics {
|
||||
operation: PdfGraphics::Literal {
|
||||
mode: PdfLiteralMode::XdvOrigin,
|
||||
bytes: early,
|
||||
},
|
||||
..
|
||||
},
|
||||
DisplayItem::PdfGraphics {
|
||||
operation: PdfGraphics::Literal {
|
||||
mode: PdfLiteralMode::XdvDirect,
|
||||
bytes: late,
|
||||
},
|
||||
..
|
||||
},
|
||||
DisplayItem::Rule { .. },
|
||||
] if early.as_ref() == b"1 0 0 rg 0 0 10 10 re f"
|
||||
&& late.as_ref() == b"0 0 1 rg 100 -60 7 9 re f"
|
||||
));
|
||||
}
|
||||
Reference in new issue
Block a user