Restore PDF Forms from native formats
This commit is contained in:
1 parent
c2d3312e5a
commit
57a7097857
12 files changed
+300
-87
No files matched your search
@@ -806,3 +806,103 @@ fn native_form_edit_updates_the_page_that_references_it() {
|
||||
);
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restored_form_reads_the_current_pdf_object_and_updates_only_its_page() {
|
||||
use texrra_engine::native::dump_format;
|
||||
use texrra_tex_core::execution::Cancellation;
|
||||
|
||||
let root = std::env::temp_dir().join(format!("texrra-form-format-{}", std::process::id()));
|
||||
fs::create_dir(&root).unwrap();
|
||||
let root = root.canonicalize().unwrap();
|
||||
let seed = root.join("seed.tex");
|
||||
let format = root.join("seed.tfx");
|
||||
let entry = root.join("entry.tex");
|
||||
let paint = root.join("paint.obj");
|
||||
let effects = root.join("effects.aux");
|
||||
fs::write(&effects, b"OLD\n").unwrap();
|
||||
fs::write(
|
||||
&seed,
|
||||
r"\catcode123=1 \catcode125=2
|
||||
\pdfoutput=1 \pdfminorversion=5 \pdfcompresslevel=0
|
||||
\def\space{ }
|
||||
\pdfobj file{paint.obj}
|
||||
\edef\paintid{\the\pdflastobj}
|
||||
\setbox0=\hbox{\pdfrefobj\paintid\pdfliteral direct{/Alpha gs}%
|
||||
\write1{\phase}\vrule width36pt height9pt depth2pt}
|
||||
\pdfxform resources{/ExtGState << /Alpha \paintid\space 0 R >>} 0
|
||||
\setbox1=\hbox{\pdfrefxform\pdflastxform}
|
||||
\dump
|
||||
",
|
||||
)
|
||||
.unwrap();
|
||||
let time = JobTime::new(2026, 11, 27, 0).unwrap();
|
||||
let world = WorldConfig::new(&root);
|
||||
let mut dump = CompileRequest::new(world.clone(), &seed, &format, time);
|
||||
dump.entry = Entry::Initex;
|
||||
dump.etex = true;
|
||||
// The deferred object file does not exist during the format dump.
|
||||
dump_format(dump, Cancellation::default()).unwrap();
|
||||
let prefix = r"\pdfpagewidth=150pt \pdfpageheight=150pt
|
||||
\shipout\hbox{\vrule width8pt height4pt}
|
||||
";
|
||||
let padding = format!("{}\n", "\\relax ".repeat(32)).repeat(48);
|
||||
let entry_text = format!(
|
||||
"{prefix}{padding}\
|
||||
\\immediate\\openout1=effects.aux\n\
|
||||
\\def\\phase{{RELOAD}}\\shipout\\copy1\n\
|
||||
\\immediate\\closeout1\n\\end\n"
|
||||
);
|
||||
let snapshot = ProjectSnapshot::new(ProjectDefinition {
|
||||
configuration: world.clone(),
|
||||
revision: 1,
|
||||
roots: [root.clone()].into(),
|
||||
files: [
|
||||
(seed.clone(), fs::read(&seed).unwrap().into()),
|
||||
(format.clone(), fs::read(&format).unwrap().into()),
|
||||
(entry.clone(), entry_text.into_bytes().into()),
|
||||
(paint.clone(), Arc::from(b"<< /Type /ExtGState /ca 0.25 >>".as_slice())),
|
||||
]
|
||||
.into(),
|
||||
directories: Default::default(),
|
||||
aliases: Default::default(),
|
||||
generated_roots: [root.clone()].into(),
|
||||
generated: [effects.clone()].into(),
|
||||
})
|
||||
.unwrap();
|
||||
let mut request = CompileRequest::new(world, entry, "entry.pdf", time).observe_generated_initial();
|
||||
request.entry = Entry::Format(format);
|
||||
request.etex = true;
|
||||
let compiler = NativeCompiler::default().with_entry_checkpoints(prefix.len() + 60);
|
||||
let first = compiler
|
||||
.compile(request.clone().with_project(snapshot.clone()))
|
||||
.unwrap();
|
||||
assert_eq!(fs::read(&effects).unwrap(), b"RELOAD\n");
|
||||
let next_snapshot = snapshot
|
||||
.with_file_edits(
|
||||
2,
|
||||
[(paint, Arc::from(b"<< /Type /ExtGState /ca 0.75 >>".as_slice()))].into(),
|
||||
)
|
||||
.unwrap();
|
||||
let revised = request.with_project(next_snapshot);
|
||||
let next = compiler.compile(revised.clone()).unwrap();
|
||||
assert!(
|
||||
next.entry_checkpoint_work.reused_steps > 0,
|
||||
"first: {:?}, revised: {:?}",
|
||||
first.entry_checkpoint_work,
|
||||
next.entry_checkpoint_work
|
||||
);
|
||||
let delta = next.preview_since(Some(first.revision())).unwrap();
|
||||
assert_eq!(delta.pages.iter().map(|page| page.index).collect::<Vec<_>>(), [1]);
|
||||
assert_ne!(next.pdf, first.pdf);
|
||||
assert_eq!(fs::read(&effects).unwrap(), b"RELOAD\n");
|
||||
let full = NativeCompiler::default().compile(revised).unwrap();
|
||||
assert_eq!(next.pdf, full.pdf);
|
||||
assert_eq!(next.execution.execution.io, full.execution.execution.io);
|
||||
assert_eq!(next.source_map.pages, full.source_map.pages);
|
||||
assert_eq!(
|
||||
next.preview_since(None).unwrap().pages,
|
||||
full.preview_since(None).unwrap().pages
|
||||
);
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
Reference in new issue
Block a user