Skip to main content

pdfium_render/pdf/document/page/field/
unknown.rs

1//! Defines the [PdfFormUnknownField] struct, exposing functionality related to a single
2//! form field of type [PdfFormFieldType::Unknown].
3//!
4
5use crate::bindgen::{FPDF_ANNOTATION, FPDF_FORMHANDLE};
6use crate::pdf::document::page::field::private::internal::PdfFormFieldPrivate;
7use crate::pdfium::PdfiumLibraryBindingsAccessor;
8use std::marker::PhantomData;
9
10#[cfg(doc)]
11use {
12    crate::pdf::document::form::PdfForm,
13    crate::pdf::document::page::annotation::PdfPageAnnotationType,
14    crate::pdf::document::page::field::{PdfFormField, PdfFormFieldType},
15};
16
17/// A single [PdfFormField] of type [PdfFormFieldType::Unknown].
18///
19/// Form fields in Pdfium are wrapped inside page annotations of type [PdfPageAnnotationType::Widget]
20/// or [PdfPageAnnotationType::XfaWidget]. User-specified values can be retrieved directly from
21/// each form field object by unwrapping the form field from the annotation, or in bulk from the
22/// [PdfForm::field_values()] function.
23pub struct PdfFormUnknownField<'a> {
24    form_handle: FPDF_FORMHANDLE,
25    annotation_handle: FPDF_ANNOTATION,
26    lifetime: PhantomData<&'a FPDF_ANNOTATION>,
27}
28
29impl<'a> PdfFormUnknownField<'a> {
30    pub(crate) fn from_pdfium(
31        form_handle: FPDF_FORMHANDLE,
32        annotation_handle: FPDF_ANNOTATION,
33    ) -> Self {
34        PdfFormUnknownField {
35            form_handle,
36            annotation_handle,
37            lifetime: PhantomData,
38        }
39    }
40}
41
42impl<'a> PdfFormFieldPrivate<'a> for PdfFormUnknownField<'a> {
43    #[inline]
44    fn form_handle(&self) -> FPDF_FORMHANDLE {
45        self.form_handle
46    }
47
48    #[inline]
49    fn annotation_handle(&self) -> FPDF_ANNOTATION {
50        self.annotation_handle
51    }
52}
53
54impl<'a> PdfiumLibraryBindingsAccessor<'a> for PdfFormUnknownField<'a> {}
55
56#[cfg(feature = "thread_safe")]
57unsafe impl<'a> Send for PdfFormUnknownField<'a> {}
58
59#[cfg(feature = "thread_safe")]
60unsafe impl<'a> Sync for PdfFormUnknownField<'a> {}