Order native PDF link continuations with shipout effects
This commit is contained in:
1 parent
e95d1264da
commit
af19a26c23
5 files changed
+274
-140
No files matched your search
@@ -200,6 +200,91 @@ fn checkpoint_retains_a_link_target_reserved_by_an_earlier_page() {
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checkpoint_restores_a_link_running_into_an_edited_page() {
|
||||
use std::sync::Arc;
|
||||
use texrra_engine::native::{
|
||||
CompileRequest, Entry, NativeCompiler, ProjectDefinition, ProjectSnapshot,
|
||||
};
|
||||
use texrra_tex_core::{execution::JobTime, resources::WorldConfig};
|
||||
|
||||
let root = std::env::temp_dir().join(format!("texrra-pdf-running-checkpoint-{}", std::process::id()));
|
||||
fs::create_dir(&root).unwrap();
|
||||
let entry = root.join("probe.tex");
|
||||
let second = root.join("second.tex");
|
||||
let configuration = WorldConfig::new(&root);
|
||||
let mut source = r"\catcode123=1 \catcode125=2
|
||||
\pdfoutput=1 \pdfminorversion=5 \pdfobjcompresslevel=1
|
||||
\pdfpagewidth=80pt \pdfpageheight=80pt \pdfhorigin=6pt \pdfvorigin=6pt
|
||||
\shipout\hbox{\pdfstartlink goto name{anchor}\vrule width4pt height5pt}
|
||||
".to_owned();
|
||||
let line = format!("{}\n", "\\relax ".repeat(26));
|
||||
source.push_str(&line.repeat(40));
|
||||
source.push_str("\\input second.tex\n\\end\n");
|
||||
let original = br"\shipout\hbox{\vrule width4pt height5pt\pdfendlink\pdfdest name{anchor} xyz}";
|
||||
let changed = br"\shipout\hbox{\vrule width8pt height5pt\pdfendlink\pdfdest name{anchor} xyz}";
|
||||
let project = ProjectSnapshot::new(ProjectDefinition {
|
||||
configuration: configuration.clone(),
|
||||
revision: 1,
|
||||
roots: [root.clone()].into(),
|
||||
files: [
|
||||
(entry.clone(), Arc::<[u8]>::from(source.into_bytes())),
|
||||
(second.clone(), Arc::from(original.as_slice())),
|
||||
].into(),
|
||||
directories: Default::default(),
|
||||
aliases: Default::default(),
|
||||
generated_roots: [root.clone()].into(),
|
||||
generated: Default::default(),
|
||||
}).unwrap();
|
||||
let updated = project.with_file_edits(2, [(second, Arc::from(changed.as_slice()))].into()).unwrap();
|
||||
let time = JobTime::new(2026, 11, 27, 600).unwrap().with_pdf_clock(0, 0).unwrap();
|
||||
let mut request = CompileRequest::new(configuration, entry, "probe.pdf", time);
|
||||
request.entry = Entry::Initex;
|
||||
request.etex = true;
|
||||
let live = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let first = live.compile(request.clone().with_project(project)).unwrap();
|
||||
let next = live.compile(request.clone().with_project(updated.clone())).unwrap();
|
||||
let cold = NativeCompiler::default().compile(request.with_project(updated)).unwrap();
|
||||
assert!(next.entry_checkpoint_work.reused_steps > 0);
|
||||
assert_eq!(next.pdf, cold.pdf);
|
||||
assert_eq!(next.source_map.pages, cold.source_map.pages);
|
||||
assert_eq!(next.preview_since(None).unwrap().pages, cold.preview_since(None).unwrap().pages);
|
||||
let patch = next.preview_since(Some(first.revision())).unwrap();
|
||||
assert_eq!(patch.pages.iter().map(|page| page.index).collect::<Vec<_>>(), [1]);
|
||||
let pdf = Document::load_mem(next.pdf.as_deref().unwrap()).unwrap();
|
||||
for page in pdf.get_pages().into_values() {
|
||||
let page = pdf.get_dictionary(page).unwrap();
|
||||
let annotations = resolve(&pdf, page.get(b"Annots").unwrap()).as_array().unwrap();
|
||||
assert_eq!(annotations.len(), 1);
|
||||
}
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn running_link_allocates_the_continuation_before_a_write_on_that_row() {
|
||||
let root = std::env::temp_dir().join(format!("texrra-pdf-continuation-order-{}", std::process::id()));
|
||||
let source = r"\catcode123=1 \catcode125=2
|
||||
\pdfoutput=1 \pdfminorversion=5 \pdfcompresslevel=0 \pdfobjcompresslevel=0
|
||||
\pdfpagewidth=100bp \pdfpageheight=100bp \pdfhorigin=8bp \pdfvorigin=8bp
|
||||
\immediate\openout0=probe.aux
|
||||
\shipout\vbox{\hsize=40pt \baselineskip=16pt \lineskiplimit=0pt
|
||||
\parfillskip=0pt plus1fil \noindent
|
||||
\pdfstartlink attr{/Border [0 0 0]} goto name{target}
|
||||
\vrule width10pt height5pt depth2pt
|
||||
\hfil\penalty-10000\relax
|
||||
\write0{MARK=continuation/\pdfpageref2;}
|
||||
\vrule width10pt height5pt depth2pt\pdfendlink\par}
|
||||
\shipout\hbox{\pdfdest name{target} fit \vrule width10pt height5pt depth2pt}
|
||||
\immediate\closeout0
|
||||
\end";
|
||||
let expected = describe(&compile(&root, source, false));
|
||||
assert_eq!(describe(&compile(&root, source, true)), expected);
|
||||
let aux = fs::read(root.join("reference/probe.aux")).unwrap();
|
||||
assert_eq!(aux, b"MARK=continuation/6;\n");
|
||||
assert_eq!(fs::read(root.join("native/probe.aux")).unwrap(), aux);
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn real_pdf_link_fragments_and_named_destination_match_pdftex() {
|
||||
let root = std::env::temp_dir().join(format!("texrra-pdf-links-{}", std::process::id()));
|
||||
|
||||
Reference in new issue
Block a user