Render XeLaTeX shared page resources and scoped graphics

This commit is contained in:
gloamxun committed 2026-11-28 18:58:49 +08:00
1 parent e20acc3eb9
commit 009fde04f7
13 files changed
+445 -12

No files matched your search

@@ -953,3 +953,59 @@ fn xdv_page_dictionaries_and_rectangular_destinations_keep_real_references() {
assert_eq!(resolve(&area[2]).as_i64().unwrap(), 10);
assert_eq!(resolve(&area[5]).as_i64().unwrap(), 400);
}
#[test]
fn xdv_scoped_code_uses_shared_resource_categories_and_page_defaults() {
use lopdf::{Document, Object, content::Content};
use texrra_tex_core::pdf::shipout_lists_to_native_pdf_document;
let state = State::initex().with_etex().with_input_profile(InputProfile::XeTeX);
let result = Executor::new(state, Limits::default())
.with_native_pages()
.run(
source(
r"\catcode123=1 \catcode125=2
\shipout\hbox{%
\special{pdf:obj @shared << >>}%
\special{pdf:obj @soft << /ca 0.25 >>}%
\special{pdf:put @resources << /ExtGState << /Half << /ca 0.5 >> >> >>}%
\special{pdf:put @resources << /ExtGState @shared >>}%
\special{pdf:pageresources << /ExtGState << /Soft @soft >> >>}%
\special{pdf:bcontent}%
\special{pdf:code q /Half gs}%
\kern10pt\special{pdf:code 0 0 10 10 re f Q}%
\special{pdf:econtent}%
\vrule width15pt height1pt}
\shipout\hbox{%
\special{pdf:put @resources << /ExtGState @shared >>}%
\special{pdf:put @shared << /Late << /ca 0.75 >> >>}%
\vrule width20pt height1pt}
\shipout\hbox{%
\special{pdf:pageresources << >>}%
\vrule width25pt height1pt}
\end",
),
&mut TestDevice,
)
.unwrap();
let pages = result.shipout_display_lists().unwrap();
assert!(pages[0].has_embedded_pdf());
assert!(pages[1].has_embedded_pdf());
assert!(!pages[2].has_embedded_pdf());
let output = shipout_lists_to_native_pdf_document(&pages, result.state.pdf_final_options()).unwrap();
let pdf = Document::load_mem(&output.bytes).unwrap();
let ids = pdf.get_pages();
let resources = |id| pdf.get_object(id).unwrap().as_dict().unwrap()
.get(b"Resources").unwrap().as_dict().unwrap();
let shared = resources(ids[&1]).get(b"ExtGState").unwrap().as_reference().unwrap();
assert_eq!(resources(ids[&2]).get(b"ExtGState").unwrap().as_reference().unwrap(), shared);
assert!(!resources(ids[&3]).has(b"ExtGState"));
let fields = pdf.get_object(shared).unwrap().as_dict().unwrap();
assert!(fields.has(b"Half") && fields.has(b"Soft") && fields.has(b"Late"));
let operations = Content::decode(&pdf.get_page_content(ids[&1]).unwrap()).unwrap().operations;
let style = operations.iter().position(|op| op.operator == "gs").unwrap();
assert!(matches!(&operations[style].operands[..], [Object::Name(name)] if name == b"Half"));
assert_eq!(operations[style + 1].operator, "re");
assert_eq!(operations[style + 2].operator, "f");
}