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