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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
pub(crate) mod internal {
// We want to make the PdfFormFieldPrivate trait private while providing a blanket
// implementation of PdfFormFieldCommon for any type T where T: PdfFormFieldPrivate.
// Rust complains, however, that by doing so we are leaking the private trait outside
// the crate.
// Instead of making the PdfFormFieldPrivate trait private, we leave it public but place it
// inside this pub(crate) module in order to prevent it from being visible outside the crate.
use crate::bindgen::{
FPDF_ANNOTATION, FPDF_FORMFLAG_CHOICE_COMBO, FPDF_FORMFLAG_CHOICE_EDIT,
FPDF_FORMFLAG_CHOICE_MULTI_SELECT, FPDF_FORMFLAG_NOEXPORT, FPDF_FORMFLAG_NONE,
FPDF_FORMFLAG_READONLY, FPDF_FORMFLAG_REQUIRED, FPDF_FORMFLAG_TEXT_MULTILINE,
FPDF_FORMFLAG_TEXT_PASSWORD, FPDF_FORMHANDLE, FPDF_OBJECT_NAME, FPDF_OBJECT_STREAM,
FPDF_OBJECT_STRING, FPDF_WCHAR,
};
use crate::error::{PdfiumError, PdfiumInternalError};
use crate::pdf::appearance_mode::PdfAppearanceMode;
use crate::pdf::document::page::field::PdfFormFieldCommon;
use crate::pdfium::PdfiumLibraryBindingsAccessor;
use crate::utils::dates::date_time_to_pdf_string;
use crate::utils::mem::create_byte_buffer;
use crate::utils::utf16le::get_string_from_pdfium_utf16le_bytes;
use bitflags::bitflags;
use chrono::Utc;
#[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
use std::os::raw::c_int;
bitflags! {
/// Flags specifying various characteristics of one form field. For more details,
/// refer to Section 8.6.2 of The PDF Reference (Sixth Edition, PDF Format 1.7),
/// starting on page 674.
pub struct PdfFormFieldFlags: u32 {
/// No flags are set for this form field.
const None = FPDF_FORMFLAG_NONE;
/// If set, the user may not change the value of the field. Any associated widget
/// annotations will not interact with the user; that is, they will not respond
/// to mouse clicks or change their appearance in response to mouse motions.
/// This flag is useful for fields whose values are computed or imported from
/// a database.
const ReadOnly = FPDF_FORMFLAG_READONLY;
/// If set, the field must have a value at the time it is exported by a
/// "submit form" action.
///
/// For more information on "submit form" actions, refer to Section 8.6.4 of
/// The PDF Reference (Sixth Edition, PDF Format 1.7), starting on page 702.
const Required = FPDF_FORMFLAG_REQUIRED;
/// If set, the field must not be exported by any "submit form" action.
///
/// For more information on "submit form" actions, refer to Section 8.6.4 of
/// The PDF Reference (Sixth Edition, PDF Format 1.7), starting on page 702.
const NoExport = FPDF_FORMFLAG_NOEXPORT;
/// If set, the field can contain multiple lines of text; if clear,
/// the field's text is restricted to a single line.
const TextMultiline = FPDF_FORMFLAG_TEXT_MULTILINE;
/// If set, the field is intended for entering a secure password that should not
/// be echoed visibly to the screen. Characters typed from the keyboard
/// should instead be echoed in some unreadable form, such as asterisks or
/// bullet characters.
///
/// To protect password confidentiality, viewer applications should never
/// store the value of the text field in the PDF file if this flag is set.
const TextPassword = FPDF_FORMFLAG_TEXT_PASSWORD;
/// If set, the text entered in the field represents the path name of a
/// file whose contents are to be submitted as the value of the field.
///
/// This flag was added in PDF version 1.4.
const TextFileSelect = 1 << 21; // Not directly exposed by Pdfium, but we can support it inline.
/// If set, the text entered in the field is not spell-checked.
///
/// This flag was added in PDF version 1.4.
const TextDoNotSpellCheck = 1 << 23; // Not directly exposed by Pdfium, but we can support it inline.
/// If set, the field does not scroll (horizontally for single-line fields,
/// vertically for multiple-line fields) to accommodate more text than fits
/// within its annotation rectangle. Once the field is full, no further text
/// is accepted.
///
/// This flag was added in PDF version 1.4.
const TextDoNotScroll = 1 << 24; // Not directly exposed by Pdfium, but we can support it inline.
/// Meaningful only if the `MaxLen` entry is present in the text field
/// dictionary (see Table 8.78) _and_ if the Multiline, Password, and FileSelect
/// flags are clear. If set, the field is automatically divided into as many
/// equally-spaced positions ("combs") as the value of `MaxLen`, and the text
/// is laid out into those combs.
///
/// For more information on this setting, refer to Table 8.77 of
/// The PDF Reference (Sixth Edition, PDF Format 1.7), on page 691.
///
/// This flag was added in PDF version 1.5.
const TextComb = 1 << 25; // Not directly exposed by Pdfium, but we can support it inline.
/// If set, the value of this field should be represented as a rich text
/// string. If the field has a value, the `RV` entry of the field dictionary
/// specifies the rich text string.
///
/// This flag was added in PDF version 1.5.
const TextRichText = 1 << 26; // Not directly exposed by Pdfium, but we can support it inline.
/// If set, the field is a combo box; if clear, the field is a list box.
const ChoiceCombo = FPDF_FORMFLAG_CHOICE_COMBO;
/// If set, the combo box includes an editable text box as well as a drop-
/// down list; if clear, it includes only a drop-down list. This flag is
/// meaningful only if the `ChoiceCombo` flag is set.
const ChoiceEdit = FPDF_FORMFLAG_CHOICE_EDIT;
/// If set, the option items of the combo box or list box should be sorted
/// alphabetically.
///
/// This flag is intended for use by form authoring tools, not by PDF viewer
/// applications. Viewers should simply display the options in the order in which
/// they occur in the `Opt` array.
const ChoiceSort = 1 << 20; // Not directly exposed by Pdfium, but we can support it inline.
/// If set, more than one of the option items of the combo box or list box
/// may be selected simultaneously; if clear, no more than one item at a time
/// may be selected.
///
/// This flag was added in PDF version 1.4.
const ChoiceMultiSelect = FPDF_FORMFLAG_CHOICE_MULTI_SELECT;
/// If set, text entered in the combo box field is not spell-checked.
///
/// This flag is meaningful only if the `ChoiceCombo` and `ChoiceEdit` flags
/// are both set.
///
/// This flag was added in PDF version 1.4.
const ChoiceDoNotSpellCheck = 1 << 23;
/// If set, the new value for the combo box or list box is committed as soon
/// as a selection is made with the pointing device. This option enables
/// applications to perform an action once a selection is made, without requiring
/// the user to exit the field. If clear, the new value is not committed until
/// the user exits the field.
const ChoiceCommitOnSelectionChange = 1 << 27;
/// If set, exactly one radio button must be selected at all
/// times; clicking the currently selected button has no effect. If clear,
/// clicking the selected button deselects it, leaving no button selected.
///
/// This flag is only applicable to radio buttons.
const ButtonNoToggleToOff = 1 << 15; // Not directly exposed by Pdfium, but we can support it inline.
/// If set, the field is a set of radio buttons; if clear, the field is a check box.
/// This flag is meaningful only if the `ButtonIsPushbutton` flag is clear.
const ButtonIsRadio = 1 << 16; // Not directly exposed by Pdfium, but we can support it inline.
/// If set, the field is a push button that does not retain a permanent value.
const ButtonIsPushButton = 1 << 17; // Not directly exposed by Pdfium, but we can support it inline.
/// If set, a group of radio buttons within a radio button field that
/// use the same value for the on state will turn on and off in unison; that is if
/// one is checked, they are all checked. If clear, the buttons are mutually
/// exclusive, i.e. the same behavior as HTML radio buttons.
///
/// This flag was added in PDF version 1.5.
const ButtonIsRadiosInUnison = 1 << 26; // Not directly exposed by Pdfium, but we can support it inline.
}
}
/// Internal crate-specific functionality common to all [PdfFormField] objects.
pub(crate) trait PdfFormFieldPrivate<'a>:
PdfFormFieldCommon + PdfiumLibraryBindingsAccessor<'a>
{
/// Returns the internal `FPDF_FORMHANDLE` handle for this [PdfFormField].
fn form_handle(&self) -> FPDF_FORMHANDLE;
/// Returns the internal `FPDF_ANNOTATION` handle for this [PdfFormField].
fn annotation_handle(&self) -> FPDF_ANNOTATION;
/// Internal implementation of [PdfFormFieldCommon::name()].
fn name_impl(&self) -> Option<String> {
// Retrieving the field name from Pdfium is a two-step operation. First, we call
// FPDFAnnot_GetFormFieldName() with a null buffer; this will retrieve the length of
// the field name text in bytes. If the length is zero, then the field name is not set.
// If the length is non-zero, then we reserve a byte buffer of the given
// length and call FPDFAnnot_GetFormFieldName() again with a pointer to the buffer;
// this will write the field name to the buffer in UTF16LE format.
let buffer_length = unsafe {
self.bindings().FPDFAnnot_GetFormFieldName(
self.form_handle(),
self.annotation_handle(),
std::ptr::null_mut(),
0,
)
};
if buffer_length == 0 {
// The field name is not present.
None
} else {
let mut buffer = create_byte_buffer(buffer_length as usize);
let result = unsafe {
self.bindings().FPDFAnnot_GetFormFieldName(
self.form_handle(),
self.annotation_handle(),
buffer.as_mut_ptr() as *mut FPDF_WCHAR,
buffer_length,
)
};
debug_assert_eq!(result, buffer_length);
get_string_from_pdfium_utf16le_bytes(buffer)
}
}
/// Internal implementation of `value()` function shared by value-carrying form field widgets
/// such as text fields. Not exposed directly by [PdfFormFieldCommon].
fn value_impl(&self) -> Option<String> {
// Retrieving the field value from Pdfium is a two-step operation. First, we call
// FPDFAnnot_GetFormFieldValue() with a null buffer; this will retrieve the length of
// the form value text in bytes. If the length is zero, then the form value is not set.
// If the length is non-zero, then we reserve a byte buffer of the given
// length and call FPDFAnnot_GetFormFieldValue() again with a pointer to the buffer;
// this will write the field value to the buffer in UTF16LE format.
let buffer_length = unsafe {
self.bindings().FPDFAnnot_GetFormFieldValue(
self.form_handle(),
self.annotation_handle(),
std::ptr::null_mut(),
0,
)
};
if buffer_length == 0 {
// The field value is not present.
None
} else {
let mut buffer = create_byte_buffer(buffer_length as usize);
let result = unsafe {
self.bindings().FPDFAnnot_GetFormFieldValue(
self.form_handle(),
self.annotation_handle(),
buffer.as_mut_ptr() as *mut FPDF_WCHAR,
buffer_length,
)
};
debug_assert_eq!(result, buffer_length);
get_string_from_pdfium_utf16le_bytes(buffer)
}
}
/// Internal implementation of `set_value()` function shared by value-carrying form
/// field widgets such as text fields. Not exposed directly by [PdfFormFieldCommon].
#[inline]
fn set_value_impl(&mut self, value: &str) -> Result<(), PdfiumError> {
self.bindings()
.to_result(unsafe {
self.bindings().FPDFAnnot_SetStringValue_str(
self.annotation_handle(),
"M",
&date_time_to_pdf_string(Utc::now()),
)
})
.and_then(|_| {
self.bindings().to_result(unsafe {
self.bindings().FPDFAnnot_SetStringValue_str(
self.annotation_handle(),
"V",
value,
)
})
})
}
/// Internal implementation of `export_value()` function shared by on/off form field widgets
/// such as checkbox and radio button fields. Not exposed directly by [PdfFormFieldCommon].
#[allow(dead_code)] // TODO: AJRC - 30/3/26 - will be removed if not required by PdfFormRadioButtonField
fn export_value_impl(&self) -> Option<String> {
// Retrieving the export value from Pdfium is a two-step operation. First, we call
// FPDFAnnot_GetFormFieldExportValue() with a null buffer; this will retrieve the length of
// the export value text in bytes. If the length is zero, then the export value is not set.
// If the length is non-zero, then we reserve a byte buffer of the given
// length and call FPDFAnnot_GetFormFieldExportValue() again with a pointer to the buffer;
// this will write the export value to the buffer in UTF16LE format.
let buffer_length = unsafe {
self.bindings().FPDFAnnot_GetFormFieldExportValue(
self.form_handle(),
self.annotation_handle(),
std::ptr::null_mut(),
0,
)
};
if buffer_length == 0 {
// The field value is not present.
None
} else {
let mut buffer = create_byte_buffer(buffer_length as usize);
let result = unsafe {
self.bindings().FPDFAnnot_GetFormFieldExportValue(
self.form_handle(),
self.annotation_handle(),
buffer.as_mut_ptr() as *mut FPDF_WCHAR,
buffer_length,
)
};
debug_assert_eq!(result, buffer_length);
get_string_from_pdfium_utf16le_bytes(buffer)
}
}
/// Internal implementation of `is_checked()` function shared by checkable form field widgets
/// such as radio buttons and checkboxes. Not exposed directly by [PdfFormFieldCommon].
///
/// Note Pdfium does not consider appearance streams when determining if a checkable form
/// field is currently selected. As a result, this function may not return the expected
/// result for fields with custom appearance streams.
fn is_checked_impl(&self) -> Result<bool, PdfiumError> {
Ok(self.bindings().is_true(unsafe {
self.bindings()
.FPDFAnnot_IsChecked(self.form_handle(), self.annotation_handle())
}))
}
/// Internal implementation of `index_in_group()` function shared by checkable form field
/// widgets such as radio buttons and checkboxes. Not exposed directly by [PdfFormFieldCommon].
fn index_in_group_impl(&self) -> u32 {
let result = unsafe {
self.bindings()
.FPDFAnnot_GetFormControlIndex(self.form_handle(), self.annotation_handle())
};
if result < 0 {
// Pdfium uses a -1 value to signal an error.
0
} else {
result as u32
}
}
/// Returns the string value associated with the given key in the annotation dictionary
/// of the [PdfPageAnnotation] containing this [PdfFormField], if any.
fn get_string_value(&self, key: &str) -> Option<String> {
if !self.bindings().is_true(unsafe {
self.bindings()
.FPDFAnnot_HasKey(self.annotation_handle(), key)
}) {
// The key does not exist.
return None;
}
let t = unsafe {
self.bindings()
.FPDFAnnot_GetValueType(self.annotation_handle(), key)
} as u32;
if t != FPDF_OBJECT_STRING && t != FPDF_OBJECT_NAME && t != FPDF_OBJECT_STREAM {
// The key exists, but the value associated with the key is not a string
// or a type with an underlying string representation.
return None;
}
// Retrieving the string value from Pdfium is a two-step operation. First, we call
// FPDFAnot_GetStringValue() with a null buffer; this will retrieve the length of
// the value in bytes, assuming the key exists. If the length is zero, then there
// is no such key, or the key's value is not a string.
// If the length is non-zero, then we reserve a byte buffer of the given
// length and call FPDFAnot_GetStringValue() again with a pointer to the buffer;
// this will write the string value into the buffer.
let buffer_length = unsafe {
self.bindings().FPDFAnnot_GetStringValue(
self.annotation_handle(),
key,
std::ptr::null_mut(),
0,
)
};
if buffer_length <= 2 {
// A buffer length of 2 indicates that the string value for the given key is
// an empty UTF16-LE string, so there is no point in retrieving it.
return None;
}
let mut buffer = create_byte_buffer(buffer_length as usize);
let result = unsafe {
self.bindings().FPDFAnnot_GetStringValue(
self.annotation_handle(),
key,
buffer.as_mut_ptr() as *mut FPDF_WCHAR,
buffer_length,
)
};
assert_eq!(result, buffer_length);
Some(get_string_from_pdfium_utf16le_bytes(buffer).unwrap_or_default())
}
/// Sets the string value associated with the given key in the annotation dictionary
/// of the [PdfPageAnnotation] containing this [PdfFormField].
fn set_string_value(&mut self, key: &str, value: &str) -> Result<(), PdfiumError> {
// Attempt to update the modification date first, before we apply the given value update.
// That way, if updating the date fails, we can fail early.
#[allow(clippy::collapsible_if)] // Prefer to keep the intent clear
if key != "M"
// Don't update the modification date if the key we have been given to update
// is itself the modification date!
{
self.set_string_value("M", &date_time_to_pdf_string(Utc::now()))?;
}
// With the modification date updated, we can now update the key and value
// we were given.
if self.bindings().is_true(unsafe {
self.bindings()
.FPDFAnnot_SetStringValue_str(self.annotation_handle(), key, value)
}) {
Ok(())
} else {
Err(PdfiumError::PdfiumLibraryInternalError(
PdfiumInternalError::Unknown,
))
}
}
/// Internal implementation of [PdfFormFieldCommon::appearance_mode_value()].
fn appearance_mode_value_impl(&self, appearance_mode: PdfAppearanceMode) -> Option<String> {
// Retrieving the appearance mode value from Pdfium is a two-step operation.
// First, we call FPDFAnnot_GetAP() with a null buffer; this will retrieve the length of
// the appearance mode value text in bytes. If the length is zero, then the
// appearance mode value is not set.
// If the length is non-zero, then we reserve a byte buffer of the given
// length and call FPDFAnnot_GetAP() again with a pointer to the buffer;
// this will write the appearance mode value to the buffer in UTF16LE format.
let buffer_length = unsafe {
self.bindings().FPDFAnnot_GetAP(
self.annotation_handle(),
appearance_mode.as_pdfium(),
std::ptr::null_mut(),
0,
)
};
if buffer_length == 0 {
// The appearance mode value is not present.
None
} else {
let mut buffer = create_byte_buffer(buffer_length as usize);
let result = unsafe {
self.bindings().FPDFAnnot_GetAP(
self.annotation_handle(),
appearance_mode.as_pdfium(),
buffer.as_mut_ptr() as *mut FPDF_WCHAR,
buffer_length,
)
};
debug_assert_eq!(result, buffer_length);
get_string_from_pdfium_utf16le_bytes(buffer)
}
}
/// Returns the currently set appearance stream for this form field, if any.
fn appearance_stream_impl(&self) -> Option<String> {
self.get_string_value("AS")
}
/// Returns all the flags currently set on this form field.
#[inline]
fn get_flags_impl(&self) -> PdfFormFieldFlags {
PdfFormFieldFlags::from_bits_truncate(unsafe {
self.bindings()
.FPDFAnnot_GetFormFieldFlags(self.form_handle(), self.annotation_handle())
} as u32)
}
#[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
/// Sets all the flags on this form field.
#[inline]
fn set_flags_impl(&self, flags: PdfFormFieldFlags) -> bool {
unsafe {
self.bindings()
.is_true(self.bindings().FPDFAnnot_SetFormFieldFlags(
self.form_handle(),
self.annotation_handle(),
flags.bits() as c_int,
))
}
}
#[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
/// Sets or clears a single flag on this form field.
fn update_one_flag_impl(
&self,
flag: PdfFormFieldFlags,
value: bool,
) -> Result<(), PdfiumError> {
let mut flags = self.get_flags_impl();
flags.set(flag, value);
if self.set_flags_impl(flags) {
Ok(())
} else {
Err(PdfiumError::PdfiumLibraryInternalError(
crate::error::PdfiumInternalError::Unknown,
))
}
}
}
}
#[cfg(test)]
mod tests {
use crate::pdf::document::page::field::private::internal::{
PdfFormFieldFlags, PdfFormFieldPrivate,
};
use crate::prelude::*;
use crate::utils::test::test_bind_to_pdfium;
#[test]
fn test_get_form_field_flags() -> Result<(), PdfiumError> {
let pdfium = test_bind_to_pdfium();
let document = pdfium.load_pdf_from_file("test/form-test.pdf", None)?;
let page = document.pages().first()?;
let annotation = page
.annotations()
.iter()
.find(|annotation| annotation.as_form_field().is_some())
.unwrap();
let field = annotation.as_form_field().unwrap();
let text = field.as_text_field().unwrap();
let flags = text.get_flags_impl();
assert!(!flags.contains(PdfFormFieldFlags::ReadOnly));
assert_eq!(text.is_read_only(), false);
assert!(!flags.contains(PdfFormFieldFlags::Required));
assert_eq!(text.is_required(), false);
assert!(!flags.contains(PdfFormFieldFlags::NoExport));
assert_eq!(text.is_exported_on_submit(), true);
assert!(!flags.contains(PdfFormFieldFlags::TextMultiline));
assert_eq!(text.is_multiline(), false);
assert!(!flags.contains(PdfFormFieldFlags::TextPassword));
assert_eq!(text.is_password(), false);
assert!(flags.contains(PdfFormFieldFlags::TextDoNotSpellCheck));
assert_eq!(text.is_spell_checked(), false);
Ok(())
}
#[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
#[test]
fn test_set_form_field_flags() -> Result<(), PdfiumError> {
let pdfium = test_bind_to_pdfium();
let mut document = pdfium.load_pdf_from_file("test/form-test.pdf", None)?;
let mut page = document.pages_mut().first()?;
let mut annotation = page
.annotations_mut()
.iter()
.find(|annotation| annotation.as_form_field().is_some())
.unwrap();
let field = annotation.as_form_field_mut().unwrap();
let text = field.as_text_field_mut().unwrap();
assert_eq!(text.is_read_only(), false);
assert_eq!(text.is_required(), false);
assert_eq!(text.is_exported_on_submit(), true);
assert_eq!(text.is_multiline(), false);
assert_eq!(text.is_password(), false);
assert_eq!(text.is_spell_checked(), false);
let mut flags = text.get_flags_impl();
flags.set(PdfFormFieldFlags::ReadOnly, true);
flags.set(PdfFormFieldFlags::Required, true);
flags.set(PdfFormFieldFlags::NoExport, true);
flags.set(PdfFormFieldFlags::TextMultiline, true);
flags.set(PdfFormFieldFlags::TextPassword, true);
flags.set(PdfFormFieldFlags::TextDoNotSpellCheck, false);
assert!(text.set_flags_impl(flags));
assert_eq!(text.is_read_only(), true);
assert_eq!(text.is_required(), true);
assert_eq!(text.is_exported_on_submit(), false);
assert_eq!(text.is_multiline(), true);
assert_eq!(text.is_password(), true);
assert_eq!(text.is_spell_checked(), true);
Ok(())
}
#[cfg(any(feature = "pdfium_future", feature = "pdfium_7350"))]
#[test]
fn test_update_one_form_field_flag() -> Result<(), PdfiumError> {
let pdfium = test_bind_to_pdfium();
let mut document = pdfium.load_pdf_from_file("test/form-test.pdf", None)?;
let mut page = document.pages_mut().first()?;
let mut annotation = page
.annotations_mut()
.iter()
.find(|annotation| annotation.as_form_field().is_some())
.unwrap();
let field = annotation.as_form_field_mut().unwrap();
let text = field.as_text_field_mut().unwrap();
assert_eq!(text.is_read_only(), false);
assert_eq!(text.is_required(), false);
assert_eq!(text.is_exported_on_submit(), true);
assert_eq!(text.is_multiline(), false);
assert_eq!(text.is_password(), false);
assert_eq!(text.is_spell_checked(), false);
text.set_is_read_only(true)?;
assert_eq!(text.is_read_only(), true);
text.set_is_required(true)?;
assert_eq!(text.is_required(), true);
text.set_is_exported_on_submit(false)?;
assert_eq!(text.is_exported_on_submit(), false);
text.set_is_multiline(true)?;
assert_eq!(text.is_multiline(), true);
text.set_is_password(true)?;
assert_eq!(text.is_password(), true);
text.set_is_spell_checked(true)?;
assert_eq!(text.is_spell_checked(), true);
assert_eq!(text.is_read_only(), true);
assert_eq!(text.is_required(), true);
assert_eq!(text.is_exported_on_submit(), false);
assert_eq!(text.is_multiline(), true);
assert_eq!(text.is_password(), true);
assert_eq!(text.is_spell_checked(), true);
Ok(())
}
}