Merge PR #2840: M6: detected form fields get no border or fill

crates/engine/src/js.rs: auto_detect_fields keeps main's comb and turn handling, builds props with no border and no fill for every field, and pushes SetFieldProps unconditionally (the review's fix)
parity/acrobat-features.toml: form.detect-fields keeps main's comb evidence and notes and adds the no-border test and sentence
This commit is contained in:
aiongg
2026-10-22 01:47:29 +00:00
3 changed files with 31 additions and 6 deletions
+7 -4
View File
@@ -349,7 +349,12 @@ impl Session {
pdfcraft_forms::detect::Kind::CheckBox => (pdfcraft_forms::NewField::CheckBox, None),
pdfcraft_forms::detect::Kind::Comb { cells } => (pdfcraft_forms::NewField::Text { multiline: false }, Some(cells)),
};
let mut props = FieldProps::default();
// The page already draws the line or box the field sits on, so the field gets no
// border or fill of its own: an opaque fill would hide the printed form (#294, #2831).
let mut props = FieldProps {
appearance: Some(pdfcraft_forms::LookPatch { border: Some(None), fill: Some(None), ..Default::default() }),
..Default::default()
};
if turn != 0 {
// A turned field keeps its place: the rectangle is already the one on the page.
props.rotation = Some((0, turn));
@@ -360,9 +365,7 @@ impl Session {
props.flags = vec![(pdfcraft_forms::flags::COMB, true)];
}
edits.push(Edit::AddField { page, rect: c.rect, kind, name: Some(c.name.clone()) });
if turn != 0 || comb.is_some() {
edits.push(Edit::SetFieldProps { name: c.name, props: Box::new(props) });
}
edits.push(Edit::SetFieldProps { name: c.name, props: Box::new(props) });
}
self.apply(id, Edit::Batch { label: "Detect form fields".into(), edits })?;
Ok(names)
+22
View File
@@ -3722,6 +3722,28 @@ fn detecting_fields_on_a_printed_form() {
assert!(s.detect_fields(id, &[]).is_empty(), "nothing left to detect");
}
/// #294, #2831: a detected field sits on a line or box the page already draws, so it gets no border
/// and no fill that would cover the printed form. A field drawn by hand keeps the defaults.
#[test]
fn detected_fields_have_no_border_or_fill() {
let mut s = Session::new().with_clock(|| 1_700_000_000);
let id = s.open("paper.pdf", None, Arc::new(paper_form()), None).unwrap();
let added = s.auto_detect_fields(id, &[]).unwrap();
let d = s.get(id).unwrap();
let kinds: Vec<pdfcraft_forms::FieldKind> = d.form.iter().map(|f| f.kind).collect();
assert!(kinds.contains(&pdfcraft_forms::FieldKind::Text) && kinds.contains(&pdfcraft_forms::FieldKind::CheckBox), "{kinds:?}");
for name in &added {
let look = d.field_look(name).unwrap();
assert_eq!((look.border, look.fill), (None, None), "{name}");
}
assert_eq!(d.can_undo(), Some("Detect form fields"), "still one step");
s.apply(id, Edit::AddField { page: 0, rect: [200.0, 10.0, 300.0, 30.0], kind: NewField::Text { multiline: false }, name: Some("drawn".into()) })
.unwrap();
let look = s.get(id).unwrap().field_look("drawn").unwrap();
assert!(look.border.is_some() && look.fill.is_some(), "{look:?}");
}
/// A printed form, 420 × 300 pt: a title, a label with a rule to write on, a box with a small
/// label in its corner, an empty box with its label above, and two check boxes.
fn paper_form() -> Vec<u8> {