mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-02 22:41:47 -06:00
M14: Reuse form enumeration during document open (#1011)
Co-authored-by: Brandon Thomas <echelon@gmail.com>
This commit is contained in:
co-authored by
Brandon Thomas
parent
3b7a01eac5
commit
db26eb266d
@@ -2390,12 +2390,14 @@ impl Session {
|
||||
};
|
||||
let display = display_bytes(editor.as_ref(), &bytes);
|
||||
let renderer = RenderPool::new(display.clone(), render_threads(), config.clone());
|
||||
let mut form = editor.as_ref().map(|e| pdfcraft_forms::fields(&e.cos)).unwrap_or_default();
|
||||
let mut adopted = 0;
|
||||
if let Some(e) = editor.as_ref() {
|
||||
xfa::mark_script_buttons(&e.cos, &mut form);
|
||||
adopted = pdfcraft_forms::adopted_page_fields(&e.cos);
|
||||
}
|
||||
let (form, adopted) = editor
|
||||
.as_ref()
|
||||
.map(|e| {
|
||||
let mut fields = pdfcraft_forms::fields_with_adopted(&e.cos);
|
||||
xfa::mark_script_buttons(&e.cos, &mut fields.items);
|
||||
(fields.items, fields.adopted_page_fields)
|
||||
})
|
||||
.unwrap_or_default();
|
||||
// Fields the file lists only as page widgets are adopted leniently; the file says so.
|
||||
if adopted > 0
|
||||
&& let Some(e) = &mut editor
|
||||
|
||||
@@ -2400,6 +2400,8 @@ fn xfa_scripts_initialize_calculate_validate_toggle_and_add_rows() {
|
||||
let bytes = Arc::new(pdfcraft_xfa::fixtures::shell(&pdfcraft_xfa::fixtures::scripted_template()));
|
||||
let mut s = Session::new().with_clock(|| 1_700_000_000);
|
||||
let id = s.open("scripted.pdf", None, bytes, None).expect("opens");
|
||||
let add_row = s.get(id).unwrap().form.iter().find(|f| f.name == "addRow").expect("the XFA button is in the form snapshot");
|
||||
assert!(matches!(add_row.button.as_ref(), Some(pdfcraft_forms::af::ButtonAction::Script(_))));
|
||||
let value = |s: &Session, n: &str| {
|
||||
s.get(id).unwrap().form.iter().find(|f| f.name == n).map(|f| f.value.clone()).unwrap_or_else(|| panic!("no field {n}"))
|
||||
};
|
||||
@@ -2828,7 +2830,7 @@ fn adopting_page_only_fields_is_noted_as_a_repair() {
|
||||
let doc = s.get(id).unwrap();
|
||||
let names: Vec<&str> = doc.form.iter().map(|f| f.name.as_str()).collect();
|
||||
assert_eq!(names, ["alpha", "beta"]);
|
||||
assert!(doc.repair_log().iter().any(|l| l.contains("2 fields") && l.contains("page annotations")), "{:?}", doc.repair_log());
|
||||
assert_eq!(doc.repair_log(), vec!["the form's /Fields list omits 2 fields; they were read from the page annotations".to_string()]);
|
||||
}
|
||||
|
||||
/// A page too large for the renderer at the asked resolution exports at the most it allows (and
|
||||
|
||||
Reference in New Issue
Block a user