pub enum FieldKind {
Text,
Check,
Radio,
Button,
Combo,
List,
Signature,
}Expand description
What kind of control a form field is (ISO 32000-1 §12.7.4).
The variants are the /FT values crossed with the two /Ff bits that
split them: a /Btn is a push button, a radio button or a check box
depending on bits 17 and 16, and a /Ch is a combo box or a list box
depending on bit 18.
Variants§
Text
A text field (/Tx).
Check
A check box (/Btn with neither the push-button nor the radio bit).
Radio
A radio button (/Btn with bit 16 set).
Button
A push button (/Btn with bit 17 set) — it holds no value.
Combo
A drop-down (/Ch with bit 18 set).
List
A list box (/Ch without bit 18).
Signature
A signature field (/Sig).
Implementations§
Source§impl FieldKind
impl FieldKind
Sourcepub fn classify(field_type: &[u8], flags: FieldFlags) -> Option<FieldKind>
pub fn classify(field_type: &[u8], flags: FieldFlags) -> Option<FieldKind>
Classifies a field from its /FT and /Ff.
Returns None for a node with no field type at all, which is how the
walk tells a naming-only interior node from a terminal field.
use pdfrum_doc::form::{FieldFlags, FieldKind};
assert_eq!(FieldKind::classify(b"Tx", FieldFlags::default()), Some(FieldKind::Text));
// A `/Btn` splits three ways on its flags.
let radio = FieldFlags::from_bits(1 << 15);
assert_eq!(FieldKind::classify(b"Btn", radio), Some(FieldKind::Radio));
assert_eq!(FieldKind::classify(b"Btn", FieldFlags::default()), Some(FieldKind::Check));
// No field type at all: an interior naming node, not a field.
assert_eq!(FieldKind::classify(b"", FieldFlags::default()), None);Sourcepub fn is_writable(self) -> bool
pub fn is_writable(self) -> bool
Whether the field holds a value a caller can write.
False only for FieldKind::Button, which fires an action rather
than storing anything, and FieldKind::Signature, whose value is a
signature dictionary this crate does not synthesize.
use pdfrum_doc::form::FieldKind;
assert!(FieldKind::Text.is_writable());
assert!(!FieldKind::Button.is_writable());
assert!(!FieldKind::Signature.is_writable());Sourcepub fn is_toggle(self) -> bool
pub fn is_toggle(self) -> bool
Whether the field is one of the two on/off controls, whose value is a state name rather than free text.
use pdfrum_doc::form::FieldKind;
assert!(FieldKind::Check.is_toggle());
assert!(FieldKind::Radio.is_toggle());
assert!(!FieldKind::Combo.is_toggle());Sourcepub fn is_choice(self) -> bool
pub fn is_choice(self) -> bool
Whether the kind picks from /Opt — a drop-down or a list box.
These are the two that carry /I alongside /V, which is why a write
has to keep the pair agreeing.
use pdfrum_doc::form::FieldKind;
assert!(FieldKind::Combo.is_choice());
assert!(FieldKind::List.is_choice());
assert!(!FieldKind::Text.is_choice());