pdfium_render/pdf/document/page/annotation/
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;
10
11pub struct PdfPageWidgetAnnotation<'a> {
16 annotation_handle: FPDF_ANNOTATION,
17 objects: PdfPageAnnotationObjects<'a>,
18 attachment_points: PdfPageAnnotationAttachmentPoints<'a>,
19 form_field: Option<PdfFormField<'a>>,
20 bindings: &'a dyn PdfiumLibraryBindings,
21}
22
23impl<'a> PdfPageWidgetAnnotation<'a> {
24 pub(crate) fn from_pdfium(
25 document_handle: FPDF_DOCUMENT,
26 page_handle: FPDF_PAGE,
27 annotation_handle: FPDF_ANNOTATION,
28 form_handle: Option<FPDF_FORMHANDLE>,
29 bindings: &'a dyn PdfiumLibraryBindings,
30 ) -> Self {
31 PdfPageWidgetAnnotation {
32 annotation_handle,
33 objects: PdfPageAnnotationObjects::from_pdfium(
34 document_handle,
35 page_handle,
36 annotation_handle,
37 bindings,
38 ),
39 attachment_points: PdfPageAnnotationAttachmentPoints::from_pdfium(
40 annotation_handle,
41 bindings,
42 ),
43 form_field: form_handle.and_then(|form_handle| {
44 PdfFormField::from_pdfium(form_handle, annotation_handle, bindings)
45 }),
46 bindings,
47 }
48 }
49
50 #[inline]
53 pub fn form_field(&self) -> Option<&PdfFormField> {
54 self.form_field.as_ref()
55 }
56
57 #[inline]
60 pub fn form_field_mut(&mut self) -> Option<&mut PdfFormField<'a>> {
61 self.form_field.as_mut()
62 }
63}
64
65impl<'a> PdfPageAnnotationPrivate<'a> for PdfPageWidgetAnnotation<'a> {
66 #[inline]
67 fn handle(&self) -> FPDF_ANNOTATION {
68 self.annotation_handle
69 }
70
71 #[inline]
72 fn bindings(&self) -> &dyn PdfiumLibraryBindings {
73 self.bindings
74 }
75
76 #[inline]
77 fn objects_impl(&self) -> &PdfPageAnnotationObjects {
78 &self.objects
79 }
80
81 #[inline]
82 fn objects_mut_impl(&mut self) -> &mut PdfPageAnnotationObjects<'a> {
83 &mut self.objects
84 }
85
86 #[inline]
87 fn attachment_points_impl(&self) -> &PdfPageAnnotationAttachmentPoints {
88 &self.attachment_points
89 }
90
91 #[inline]
92 fn attachment_points_mut_impl(&mut self) -> &mut PdfPageAnnotationAttachmentPoints<'a> {
93 &mut self.attachment_points
94 }
95}