1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//! Field flags (/Ff) bitfield wrapper (B.1).
/// Wrapper around a PDF field-flags integer (/Ff).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct FieldFlags(u32);
impl FieldFlags {
/// Create from raw bits.
pub fn from_bits(bits: u32) -> Self {
Self(bits)
}
/// Empty (no flags set).
pub fn empty() -> Self {
Self(0)
}
/// Raw bits.
pub fn bits(self) -> u32 {
self.0
}
fn has(self, bit: u32) -> bool {
self.0 & (1 << bit) != 0
}
// Common flags
/// Bit 1: read-only.
pub fn read_only(self) -> bool {
self.has(0)
}
/// Bit 2: required.
pub fn required(self) -> bool {
self.has(1)
}
/// Bit 3: no-export.
pub fn no_export(self) -> bool {
self.has(2)
}
// Text field flags
/// Bit 13: multiline.
pub fn multiline(self) -> bool {
self.has(12)
}
/// Bit 14: password.
pub fn password(self) -> bool {
self.has(13)
}
/// Bit 21: file-select.
pub fn file_select(self) -> bool {
self.has(20)
}
/// Bit 23: do-not-spell-check.
pub fn do_not_spell_check(self) -> bool {
self.has(22)
}
/// Bit 24: do-not-scroll.
pub fn do_not_scroll(self) -> bool {
self.has(23)
}
/// Bit 25: comb.
pub fn comb(self) -> bool {
self.has(24)
}
/// Bit 26: rich-text.
pub fn rich_text(self) -> bool {
self.has(25)
}
// Button flags
/// Bit 15: no-toggle-to-off (radio buttons).
pub fn no_toggle_to_off(self) -> bool {
self.has(14)
}
/// Bit 16: radio.
pub fn radio(self) -> bool {
self.has(15)
}
/// Bit 17: push-button.
pub fn push_button(self) -> bool {
self.has(16)
}
/// Bit 26: radios-in-unison.
pub fn radios_in_unison(self) -> bool {
self.has(25)
}
// Choice flags
/// Bit 18: combo.
pub fn combo(self) -> bool {
self.has(17)
}
/// Bit 19: edit (editable combo).
pub fn edit(self) -> bool {
self.has(18)
}
/// Bit 20: sort.
pub fn sort(self) -> bool {
self.has(19)
}
/// Bit 22: multi-select.
pub fn multi_select(self) -> bool {
self.has(21)
}
/// Bit 27: commit-on-sel-change.
pub fn commit_on_sel_change(self) -> bool {
self.has(26)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn empty_flags() {
assert!(!FieldFlags::empty().read_only());
}
#[test]
fn read_only() {
assert!(FieldFlags::from_bits(1).read_only());
}
#[test]
fn multiline() {
assert!(FieldFlags::from_bits(1 << 12).multiline());
}
#[test]
fn combo() {
assert!(FieldFlags::from_bits(1 << 17).combo());
}
#[test]
fn push_button() {
assert!(FieldFlags::from_bits(1 << 16).push_button());
}
#[test]
fn radio() {
assert!(FieldFlags::from_bits(1 << 15).radio());
}
}