Scope XDV PDF content at the driver page origin

This commit is contained in:
gloamxun committed 2026-11-28 07:25:57 +08:00
1 parent ab6b1093ec
commit 526ec9b3b0
9 files changed
+176 -46

No files matched your search

+65
View File
@@ -822,6 +822,71 @@ fn xetex_opentype_font_switch_uses_the_current_text_line_origin() {
fs::remove_dir_all(root).unwrap();
}
#[test]
fn xetex_content_special_scopes_graphics_and_emits_marked_content() {
use lopdf::{Document, content::Content};
use texrra_tex_core::{
execution::InputProfile,
pdf_device::{PdfGraphics, PdfLiteralMode},
render::DisplayItem,
source_map::PaintKind,
};
let root = directory("xetex-content");
let mut job = request(&root);
job.input_profile = InputProfile::XeTeX;
fs::write(
root.join("main.tex"),
br"\catcode123=1 \catcode125=2
\font\face=cmr10
\shipout\hbox{\kern10pt%
\special{pdf:content 2 0 0 2 3 4 cm 5 Tw 1 0 0 rg 0 0 8 8 re f}%
\special{pdf:content /Span << /ActualText (Accessible) >> BDC}%
\face X\special{pdf:content EMC}\kern3pt\vrule width5pt height2pt depth0pt}
\end",
)
.unwrap();
let result = NativeCompiler::default().compile(job).unwrap();
let page = &result.pages[0];
let payloads = page
.items
.iter()
.filter_map(|item| match item {
DisplayItem::PdfGraphics {
operation: PdfGraphics::Literal { mode, bytes },
..
} => Some((*mode, bytes.as_ref())),
_ => None,
})
.collect::<Vec<_>>();
assert_eq!(payloads.len(), 3);
assert!(payloads.iter().all(|(mode, _)| *mode == PdfLiteralMode::XdvContent));
assert_eq!(payloads[2].1, b"EMC");
assert!(page.has_embedded_pdf());
assert!(result.preview_since(None).unwrap().pages[0].svg.contains("<svg"));
let pdf = Document::load_mem(result.pdf.as_deref().unwrap()).unwrap();
let bytes = pdf.get_page_content(pdf.get_pages()[&1]).unwrap();
let content = Content::decode(&bytes).unwrap();
let ops = content
.operations
.iter()
.map(|op| op.operator.as_str())
.collect::<Vec<_>>();
assert!(ops.starts_with(&["q", "rg", "cm"]));
assert!(matches!(
content.operations[2].operands[4],
lopdf::Object::Real(value) if value == 72.
));
assert!(ops.windows(8).any(|ops| ops == ["q", "cm", "cm", "Tw", "rg", "re", "f", "Q"]));
assert!(ops.windows(5).any(|ops| ops == ["q", "cm", "BDC", "Q", "BT"]));
assert!(ops.windows(5).any(|ops| ops == ["ET", "q", "cm", "EMC", "Q"]));
let sources = &result.source_map.pages[0];
assert!(sources.entries.iter().any(|entry| matches!(entry.kind, PaintKind::Glyph { slot: b'X', .. })));
fs::remove_dir_all(root).unwrap();
}
#[test]
fn xetex_unclaimed_special_warns_at_shipout_and_retains_the_whatsit() {
use texrra_tex_core::execution::{Event, InputProfile};