Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

M5: doc comments for the functions around this change

Eric Kadenad453129f0a4
diff --git a/crates/forms/src/appearance.rs b/crates/forms/src/appearance.rs
index 35bb9146a..6d7275470 100644
--- a/crates/forms/src/appearance.rs
+++ b/crates/forms/src/appearance.rs
@@ -240,6 +240,8 @@ pub(crate) fn button_caption(doc: &Document, da: &str, caption: &str, width: f64
(out, name, font, missing)
}
+/// A non-embedded Helvetica font dictionary in WinAnsi encoding, the fallback when the form's
+/// `/DR` has no font that can show the text.
fn helvetica() -> Object {
let mut f = Dict::new();
f.set(b"Type".to_vec(), Object::name("Font"));
diff --git a/crates/forms/src/tests.rs b/crates/forms/src/tests.rs
index 40d44677f..41aa52a53 100644
--- a/crates/forms/src/tests.rs
+++ b/crates/forms/src/tests.rs
@@ -80,6 +80,7 @@ fn field<'a>(all: &'a [Field], name: &str) -> &'a Field {
all.iter().find(|f| f.name == name).unwrap_or_else(|| panic!("no field {name}"))
}
+/// The decoded text of widget `w`'s normal (`/N`) appearance stream.
fn ap(doc: &Document, w: &Widget) -> String {
let wd = doc.get(w.obj).as_dict().cloned().unwrap();
let n = wd.get(b"AP").unwrap().as_dict().unwrap().reference(b"N").expect("normal appearance stream");
@@ -136,6 +137,9 @@ fn a_button_caption_its_fonts_encoding_cant_hold_is_reported() {
assert_eq!(undrawn_fields(&doc), [("go".to_string(), '\u{2000B}')]);
}
+/// Changing one widget's caption on a push button with two widgets leaves the other widget, the
+/// shared `/MK` and the parent's action untouched, keeps the other `/MK` and `/AP` entries, and
+/// drops the stale rollover and down appearances, with a direct or indirect caption and either save.
#[test]
fn button_caption_preserves_other_widgets_and_shared_dictionaries() {
for indirect_caption in [false, true] {