pdfium_render/pdf/document/page/annotation/
xfa_widget.rs1use crate::bindgen::{FPDF_ANNOTATION, FPDF_DOCUMENT, FPDF_FORMHANDLE, FPDF_PAGE};
5use crate::bindings::PdfiumLibraryBindings;
6use crate::pdf::document::page::annotation::attachment_points::PdfPageAnnotationAttachmentPoints;
7use crate::pdf::document::page::annotation::objects::PdfPageAnnotationObjects;
8use crate::pdf::document::page::annotation::private::internal::PdfPageAnnotationPrivate;
9use crate::pdf::document::page::field::PdfFormField;
10use crate::pdf::document::page::object::ownership::PdfPageObjectOwnership;
11use crate::pdf::document::page::objects::private::internal::PdfPageObjectsPrivate;
12use crate::pdfium::PdfiumLibraryBindingsAccessor;
13use std::marker::PhantomData;
14
15#[cfg(doc)]
16use {
17 crate::pdf::document::page::annotation::PdfPageAnnotation,
18 crate::pdf::document::page::annotation::PdfPageAnnotationType,
19};
20
21pub struct PdfPageXfaWidgetAnnotation<'a> {
26 annotation_handle: FPDF_ANNOTATION,
27 objects: PdfPageAnnotationObjects<'a>,
28 attachment_points: PdfPageAnnotationAttachmentPoints<'a>,
29 form_field: Option<PdfFormField<'a>>,
30 lifetime: PhantomData<&'a FPDF_ANNOTATION>,
31}
32
33impl<'a> PdfPageXfaWidgetAnnotation<'a> {
34 pub(crate) fn from_pdfium(
35 document_handle: FPDF_DOCUMENT,
36 page_handle: FPDF_PAGE,
37 annotation_handle: FPDF_ANNOTATION,
38 form_handle: Option<FPDF_FORMHANDLE>,
39 bindings: &'a dyn PdfiumLibraryBindings,
40 ) -> Self {
41 PdfPageXfaWidgetAnnotation {
42 annotation_handle,
43 objects: PdfPageAnnotationObjects::from_pdfium(
44 document_handle,
45 page_handle,
46 annotation_handle,
47 ),
48 attachment_points: PdfPageAnnotationAttachmentPoints::from_pdfium(annotation_handle),
49 form_field: form_handle.and_then(|form_handle| {
50 PdfFormField::from_pdfium(form_handle, annotation_handle, bindings)
51 }),
52 lifetime: PhantomData,
53 }
54 }
55
56 #[inline]
59 pub fn form_field(&self) -> Option<&PdfFormField<'_>> {
60 self.form_field.as_ref()
61 }
62
63 #[inline]
66 pub fn form_field_mut(&mut self) -> Option<&mut PdfFormField<'a>> {
67 self.form_field.as_mut()
68 }
69}
70
71impl<'a> PdfPageAnnotationPrivate<'a> for PdfPageXfaWidgetAnnotation<'a> {
72 #[inline]
73 fn handle(&self) -> FPDF_ANNOTATION {
74 self.annotation_handle
75 }
76
77 #[inline]
78 fn ownership(&self) -> &PdfPageObjectOwnership {
79 self.objects_impl().ownership()
80 }
81
82 #[inline]
83 fn objects_impl(&self) -> &PdfPageAnnotationObjects<'_> {
84 &self.objects
85 }
86
87 #[inline]
88 fn attachment_points_impl(&self) -> &PdfPageAnnotationAttachmentPoints<'_> {
89 &self.attachment_points
90 }
91}
92
93impl<'a> PdfiumLibraryBindingsAccessor<'a> for PdfPageXfaWidgetAnnotation<'a> {}
94
95#[cfg(feature = "thread_safe")]
96unsafe impl<'a> Send for PdfPageXfaWidgetAnnotation<'a> {}
97
98#[cfg(feature = "thread_safe")]
99unsafe impl<'a> Sync for PdfPageXfaWidgetAnnotation<'a> {}