Apply XDV color state and page backgrounds at shipout
This commit is contained in:
1 parent
cc147e93d8
commit
8be7867b37
10 files changed
+590
-19
No files matched your search
@@ -548,3 +548,51 @@ fn xdv_destinations_use_shipped_page_ids_and_pdf_string_keys() {
|
||||
assert_eq!(xyz[4].as_f64().unwrap(), 1.5);
|
||||
assert!(output.diagnostics.iter().any(|text| text.contains("Object @A already defined")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xdv_color_is_shipped_in_order_and_replayed_on_the_next_page() {
|
||||
use lopdf::Document;
|
||||
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
|
||||
\def\block{\vrule width8pt height6pt depth0pt}
|
||||
\setbox0=\hbox{\special{color push Blue}\special{background Black}}
|
||||
\shipout\hbox{\block\special{color push rgb 1 0 0}
|
||||
\special{x:gsave}\special{pdf:bc fill [0 1 0]}\block
|
||||
\special{x:grestore}\block\special{background gray .875}}
|
||||
\shipout\hbox{\block\special{pdf:ec}\block\special{color pop}\block}
|
||||
\shipout\hbox{\block\special{background White}}
|
||||
\end",
|
||||
),
|
||||
&mut TestDevice,
|
||||
)
|
||||
.unwrap();
|
||||
let pages = result.shipout_display_lists().unwrap();
|
||||
let output = shipout_lists_to_native_pdf_document(&pages, result.state.pdf_final_options())
|
||||
.unwrap();
|
||||
let pdf = Document::load_mem(&output.bytes).unwrap();
|
||||
let page_contents: Vec<_> = pdf.get_pages().values().map(|&id| {
|
||||
String::from_utf8(pdf.get_page_content(id).unwrap()).unwrap()
|
||||
}).collect();
|
||||
assert_eq!(page_contents.len(), 3);
|
||||
let first = &page_contents[0];
|
||||
assert!(first.find("0.875 g").unwrap() < first.find(" re f").unwrap());
|
||||
let green_fill = "1.000 0.000 0.000 RG 0.000 1.000 0.000 rg";
|
||||
assert!(first.contains(&format!("Q\n{green_fill}\n")));
|
||||
let second = &page_contents[1];
|
||||
let red = "1.000 0.000 0.000 RG 1.000 0.000 0.000 rg";
|
||||
assert!(second.find("0.875 g").unwrap() < second.find(green_fill).unwrap());
|
||||
assert!(second.find(green_fill).unwrap() < second.find(red).unwrap());
|
||||
assert!(!page_contents[2].contains("0.875 g"));
|
||||
let svg = pages[1].try_to_svg().unwrap();
|
||||
assert!(svg.contains("fill=\"#dfdfdf\""));
|
||||
assert!(svg.contains("fill=\"#00ff00\""));
|
||||
let mut without_background = pages[1].clone();
|
||||
without_background.pdf_background = None;
|
||||
assert!(!pages[1].same_svg_paint(&without_background));
|
||||
}
|
||||
Reference in new issue
Block a user