1pub mod attachment_points;
4pub mod circle;
5pub mod free_text;
6pub mod highlight;
7pub mod ink;
8pub mod link;
9pub mod objects;
10pub mod popup;
11pub(crate) mod private; pub mod redacted;
13pub mod square;
14pub mod squiggly;
15pub mod stamp;
16pub mod strikeout;
17pub mod text;
18pub mod underline;
19pub mod unsupported;
20pub mod widget;
21pub mod xfa_widget;
22
23use crate::bindgen::{
24 FPDF_ANNOTATION, FPDF_ANNOTATION_SUBTYPE, FPDF_ANNOT_CARET, FPDF_ANNOT_CIRCLE,
25 FPDF_ANNOT_FILEATTACHMENT, FPDF_ANNOT_FREETEXT, FPDF_ANNOT_HIGHLIGHT, FPDF_ANNOT_INK,
26 FPDF_ANNOT_LINE, FPDF_ANNOT_LINK, FPDF_ANNOT_MOVIE, FPDF_ANNOT_POLYGON, FPDF_ANNOT_POLYLINE,
27 FPDF_ANNOT_POPUP, FPDF_ANNOT_PRINTERMARK, FPDF_ANNOT_REDACT, FPDF_ANNOT_RICHMEDIA,
28 FPDF_ANNOT_SCREEN, FPDF_ANNOT_SOUND, FPDF_ANNOT_SQUARE, FPDF_ANNOT_SQUIGGLY, FPDF_ANNOT_STAMP,
29 FPDF_ANNOT_STRIKEOUT, FPDF_ANNOT_TEXT, FPDF_ANNOT_THREED, FPDF_ANNOT_TRAPNET,
30 FPDF_ANNOT_UNDERLINE, FPDF_ANNOT_UNKNOWN, FPDF_ANNOT_WATERMARK, FPDF_ANNOT_WIDGET,
31 FPDF_ANNOT_XFAWIDGET, FPDF_DOCUMENT, FPDF_FORMHANDLE, FPDF_PAGE,
32};
33use crate::bindings::PdfiumLibraryBindings;
34use crate::error::PdfiumError;
35use crate::pdf::color::PdfColor;
36use crate::pdf::document::page::annotation::attachment_points::PdfPageAnnotationAttachmentPoints;
37use crate::pdf::document::page::annotation::circle::PdfPageCircleAnnotation;
38use crate::pdf::document::page::annotation::free_text::PdfPageFreeTextAnnotation;
39use crate::pdf::document::page::annotation::highlight::PdfPageHighlightAnnotation;
40use crate::pdf::document::page::annotation::ink::PdfPageInkAnnotation;
41use crate::pdf::document::page::annotation::link::PdfPageLinkAnnotation;
42use crate::pdf::document::page::annotation::objects::PdfPageAnnotationObjects;
43use crate::pdf::document::page::annotation::popup::PdfPagePopupAnnotation;
44use crate::pdf::document::page::annotation::private::internal::PdfPageAnnotationPrivate;
45use crate::pdf::document::page::annotation::redacted::PdfPageRedactedAnnotation;
46use crate::pdf::document::page::annotation::square::PdfPageSquareAnnotation;
47use crate::pdf::document::page::annotation::squiggly::PdfPageSquigglyAnnotation;
48use crate::pdf::document::page::annotation::stamp::PdfPageStampAnnotation;
49use crate::pdf::document::page::annotation::strikeout::PdfPageStrikeoutAnnotation;
50use crate::pdf::document::page::annotation::text::PdfPageTextAnnotation;
51use crate::pdf::document::page::annotation::underline::PdfPageUnderlineAnnotation;
52use crate::pdf::document::page::annotation::unsupported::PdfPageUnsupportedAnnotation;
53use crate::pdf::document::page::annotation::widget::PdfPageWidgetAnnotation;
54use crate::pdf::document::page::annotation::xfa_widget::PdfPageXfaWidgetAnnotation;
55use crate::pdf::document::page::field::PdfFormField;
56use crate::pdf::document::page::object::ownership::PdfPageObjectOwnership;
57use crate::pdf::points::PdfPoints;
58use crate::pdf::rect::PdfRect;
59use chrono::prelude::*;
60
61#[cfg(doc)]
62use crate::pdf::document::page::PdfPage;
63
64#[derive(Debug, Copy, Clone, PartialOrd, PartialEq)]
93pub enum PdfPageAnnotationType {
94 Unknown = FPDF_ANNOT_UNKNOWN as isize,
95 Text = FPDF_ANNOT_TEXT as isize,
96 Link = FPDF_ANNOT_LINK as isize,
97 FreeText = FPDF_ANNOT_FREETEXT as isize,
98 Line = FPDF_ANNOT_LINE as isize,
99 Square = FPDF_ANNOT_SQUARE as isize,
100 Circle = FPDF_ANNOT_CIRCLE as isize,
101 Polygon = FPDF_ANNOT_POLYGON as isize,
102 Polyline = FPDF_ANNOT_POLYLINE as isize,
103 Highlight = FPDF_ANNOT_HIGHLIGHT as isize,
104 Underline = FPDF_ANNOT_UNDERLINE as isize,
105 Squiggly = FPDF_ANNOT_SQUIGGLY as isize,
106 Strikeout = FPDF_ANNOT_STRIKEOUT as isize,
107 Stamp = FPDF_ANNOT_STAMP as isize,
108 Caret = FPDF_ANNOT_CARET as isize,
109 Ink = FPDF_ANNOT_INK as isize,
110 Popup = FPDF_ANNOT_POPUP as isize,
111 FileAttachment = FPDF_ANNOT_FILEATTACHMENT as isize,
112 Sound = FPDF_ANNOT_SOUND as isize,
113 Movie = FPDF_ANNOT_MOVIE as isize,
114 Widget = FPDF_ANNOT_WIDGET as isize,
115 Screen = FPDF_ANNOT_SCREEN as isize,
116 PrinterMark = FPDF_ANNOT_PRINTERMARK as isize,
117 TrapNet = FPDF_ANNOT_TRAPNET as isize,
118 Watermark = FPDF_ANNOT_WATERMARK as isize,
119 ThreeD = FPDF_ANNOT_THREED as isize,
120 RichMedia = FPDF_ANNOT_RICHMEDIA as isize,
121 XfaWidget = FPDF_ANNOT_XFAWIDGET as isize,
122 Redacted = FPDF_ANNOT_REDACT as isize,
123}
124
125impl PdfPageAnnotationType {
126 pub(crate) fn from_pdfium(
127 value: FPDF_ANNOTATION_SUBTYPE,
128 ) -> Result<PdfPageAnnotationType, PdfiumError> {
129 match value as u32 {
130 FPDF_ANNOT_UNKNOWN => Ok(PdfPageAnnotationType::Unknown),
131 FPDF_ANNOT_TEXT => Ok(PdfPageAnnotationType::Text),
132 FPDF_ANNOT_LINK => Ok(PdfPageAnnotationType::Link),
133 FPDF_ANNOT_FREETEXT => Ok(PdfPageAnnotationType::FreeText),
134 FPDF_ANNOT_LINE => Ok(PdfPageAnnotationType::Line),
135 FPDF_ANNOT_SQUARE => Ok(PdfPageAnnotationType::Square),
136 FPDF_ANNOT_CIRCLE => Ok(PdfPageAnnotationType::Circle),
137 FPDF_ANNOT_POLYGON => Ok(PdfPageAnnotationType::Polygon),
138 FPDF_ANNOT_POLYLINE => Ok(PdfPageAnnotationType::Polyline),
139 FPDF_ANNOT_HIGHLIGHT => Ok(PdfPageAnnotationType::Highlight),
140 FPDF_ANNOT_UNDERLINE => Ok(PdfPageAnnotationType::Underline),
141 FPDF_ANNOT_SQUIGGLY => Ok(PdfPageAnnotationType::Squiggly),
142 FPDF_ANNOT_STRIKEOUT => Ok(PdfPageAnnotationType::Strikeout),
143 FPDF_ANNOT_STAMP => Ok(PdfPageAnnotationType::Stamp),
144 FPDF_ANNOT_CARET => Ok(PdfPageAnnotationType::Caret),
145 FPDF_ANNOT_INK => Ok(PdfPageAnnotationType::Ink),
146 FPDF_ANNOT_POPUP => Ok(PdfPageAnnotationType::Popup),
147 FPDF_ANNOT_FILEATTACHMENT => Ok(PdfPageAnnotationType::FileAttachment),
148 FPDF_ANNOT_SOUND => Ok(PdfPageAnnotationType::Sound),
149 FPDF_ANNOT_MOVIE => Ok(PdfPageAnnotationType::Movie),
150 FPDF_ANNOT_WIDGET => Ok(PdfPageAnnotationType::Widget),
151 FPDF_ANNOT_SCREEN => Ok(PdfPageAnnotationType::Screen),
152 FPDF_ANNOT_PRINTERMARK => Ok(PdfPageAnnotationType::PrinterMark),
153 FPDF_ANNOT_TRAPNET => Ok(PdfPageAnnotationType::TrapNet),
154 FPDF_ANNOT_WATERMARK => Ok(PdfPageAnnotationType::Watermark),
155 FPDF_ANNOT_THREED => Ok(PdfPageAnnotationType::ThreeD),
156 FPDF_ANNOT_RICHMEDIA => Ok(PdfPageAnnotationType::RichMedia),
157 FPDF_ANNOT_XFAWIDGET => Ok(PdfPageAnnotationType::XfaWidget),
158 FPDF_ANNOT_REDACT => Ok(PdfPageAnnotationType::Redacted),
159 _ => Err(PdfiumError::UnknownPdfAnnotationType),
160 }
161 }
162
163 #[allow(dead_code)]
164 pub(crate) fn as_pdfium(&self) -> FPDF_ANNOTATION_SUBTYPE {
166 (match self {
167 PdfPageAnnotationType::Unknown => FPDF_ANNOT_UNKNOWN,
168 PdfPageAnnotationType::Text => FPDF_ANNOT_TEXT,
169 PdfPageAnnotationType::Link => FPDF_ANNOT_LINK,
170 PdfPageAnnotationType::FreeText => FPDF_ANNOT_FREETEXT,
171 PdfPageAnnotationType::Line => FPDF_ANNOT_LINE,
172 PdfPageAnnotationType::Square => FPDF_ANNOT_SQUARE,
173 PdfPageAnnotationType::Circle => FPDF_ANNOT_CIRCLE,
174 PdfPageAnnotationType::Polygon => FPDF_ANNOT_POLYGON,
175 PdfPageAnnotationType::Polyline => FPDF_ANNOT_POLYLINE,
176 PdfPageAnnotationType::Highlight => FPDF_ANNOT_HIGHLIGHT,
177 PdfPageAnnotationType::Underline => FPDF_ANNOT_UNDERLINE,
178 PdfPageAnnotationType::Squiggly => FPDF_ANNOT_SQUIGGLY,
179 PdfPageAnnotationType::Strikeout => FPDF_ANNOT_STRIKEOUT,
180 PdfPageAnnotationType::Stamp => FPDF_ANNOT_STAMP,
181 PdfPageAnnotationType::Caret => FPDF_ANNOT_CARET,
182 PdfPageAnnotationType::Ink => FPDF_ANNOT_INK,
183 PdfPageAnnotationType::Popup => FPDF_ANNOT_POPUP,
184 PdfPageAnnotationType::FileAttachment => FPDF_ANNOT_FILEATTACHMENT,
185 PdfPageAnnotationType::Sound => FPDF_ANNOT_SOUND,
186 PdfPageAnnotationType::Movie => FPDF_ANNOT_MOVIE,
187 PdfPageAnnotationType::Widget => FPDF_ANNOT_WIDGET,
188 PdfPageAnnotationType::Screen => FPDF_ANNOT_SCREEN,
189 PdfPageAnnotationType::PrinterMark => FPDF_ANNOT_PRINTERMARK,
190 PdfPageAnnotationType::TrapNet => FPDF_ANNOT_TRAPNET,
191 PdfPageAnnotationType::Watermark => FPDF_ANNOT_WATERMARK,
192 PdfPageAnnotationType::ThreeD => FPDF_ANNOT_THREED,
193 PdfPageAnnotationType::RichMedia => FPDF_ANNOT_RICHMEDIA,
194 PdfPageAnnotationType::XfaWidget => FPDF_ANNOT_XFAWIDGET,
195 PdfPageAnnotationType::Redacted => FPDF_ANNOT_REDACT,
196 }) as FPDF_ANNOTATION_SUBTYPE
197 }
198}
199
200pub enum PdfPageAnnotation<'a> {
202 Circle(PdfPageCircleAnnotation<'a>),
203 FreeText(PdfPageFreeTextAnnotation<'a>),
204 Highlight(PdfPageHighlightAnnotation<'a>),
205 Ink(PdfPageInkAnnotation<'a>),
206 Link(PdfPageLinkAnnotation<'a>),
207 Popup(PdfPagePopupAnnotation<'a>),
208 Square(PdfPageSquareAnnotation<'a>),
209 Squiggly(PdfPageSquigglyAnnotation<'a>),
210 Stamp(PdfPageStampAnnotation<'a>),
211 Strikeout(PdfPageStrikeoutAnnotation<'a>),
212 Text(PdfPageTextAnnotation<'a>),
213 Underline(PdfPageUnderlineAnnotation<'a>),
214 Widget(PdfPageWidgetAnnotation<'a>),
215 XfaWidget(PdfPageXfaWidgetAnnotation<'a>),
216 Redacted(PdfPageRedactedAnnotation<'a>),
217
218 Unsupported(PdfPageUnsupportedAnnotation<'a>),
222}
223
224impl<'a> PdfPageAnnotation<'a> {
225 pub(crate) fn from_pdfium(
226 document_handle: FPDF_DOCUMENT,
227 page_handle: FPDF_PAGE,
228 annotation_handle: FPDF_ANNOTATION,
229 form_handle: Option<FPDF_FORMHANDLE>,
230 bindings: &'a dyn PdfiumLibraryBindings,
231 ) -> Self {
232 let annotation_type =
233 PdfPageAnnotationType::from_pdfium(bindings.FPDFAnnot_GetSubtype(annotation_handle))
234 .unwrap_or(PdfPageAnnotationType::Unknown);
235
236 match annotation_type {
237 PdfPageAnnotationType::Circle => {
238 PdfPageAnnotation::Circle(PdfPageCircleAnnotation::from_pdfium(
239 document_handle,
240 page_handle,
241 annotation_handle,
242 bindings,
243 ))
244 }
245 PdfPageAnnotationType::FreeText => {
246 PdfPageAnnotation::FreeText(PdfPageFreeTextAnnotation::from_pdfium(
247 document_handle,
248 page_handle,
249 annotation_handle,
250 bindings,
251 ))
252 }
253 PdfPageAnnotationType::Highlight => {
254 PdfPageAnnotation::Highlight(PdfPageHighlightAnnotation::from_pdfium(
255 document_handle,
256 page_handle,
257 annotation_handle,
258 bindings,
259 ))
260 }
261 PdfPageAnnotationType::Ink => {
262 PdfPageAnnotation::Ink(PdfPageInkAnnotation::from_pdfium(
263 document_handle,
264 page_handle,
265 annotation_handle,
266 bindings,
267 ))
268 }
269 PdfPageAnnotationType::Link => {
270 PdfPageAnnotation::Link(PdfPageLinkAnnotation::from_pdfium(
271 document_handle,
272 page_handle,
273 annotation_handle,
274 bindings,
275 ))
276 }
277 PdfPageAnnotationType::Popup => {
278 PdfPageAnnotation::Popup(PdfPagePopupAnnotation::from_pdfium(
279 document_handle,
280 page_handle,
281 annotation_handle,
282 bindings,
283 ))
284 }
285 PdfPageAnnotationType::Square => {
286 PdfPageAnnotation::Square(PdfPageSquareAnnotation::from_pdfium(
287 document_handle,
288 page_handle,
289 annotation_handle,
290 bindings,
291 ))
292 }
293 PdfPageAnnotationType::Squiggly => {
294 PdfPageAnnotation::Squiggly(PdfPageSquigglyAnnotation::from_pdfium(
295 document_handle,
296 page_handle,
297 annotation_handle,
298 bindings,
299 ))
300 }
301 PdfPageAnnotationType::Stamp => {
302 PdfPageAnnotation::Stamp(PdfPageStampAnnotation::from_pdfium(
303 document_handle,
304 page_handle,
305 annotation_handle,
306 bindings,
307 ))
308 }
309 PdfPageAnnotationType::Strikeout => {
310 PdfPageAnnotation::Strikeout(PdfPageStrikeoutAnnotation::from_pdfium(
311 document_handle,
312 page_handle,
313 annotation_handle,
314 bindings,
315 ))
316 }
317 PdfPageAnnotationType::Text => {
318 PdfPageAnnotation::Text(PdfPageTextAnnotation::from_pdfium(
319 document_handle,
320 page_handle,
321 annotation_handle,
322 bindings,
323 ))
324 }
325 PdfPageAnnotationType::Underline => {
326 PdfPageAnnotation::Underline(PdfPageUnderlineAnnotation::from_pdfium(
327 document_handle,
328 page_handle,
329 annotation_handle,
330 bindings,
331 ))
332 }
333 PdfPageAnnotationType::Widget => {
334 PdfPageAnnotation::Widget(PdfPageWidgetAnnotation::from_pdfium(
335 document_handle,
336 page_handle,
337 annotation_handle,
338 form_handle,
339 bindings,
340 ))
341 }
342 PdfPageAnnotationType::XfaWidget => {
343 PdfPageAnnotation::XfaWidget(PdfPageXfaWidgetAnnotation::from_pdfium(
344 document_handle,
345 page_handle,
346 annotation_handle,
347 form_handle,
348 bindings,
349 ))
350 }
351 PdfPageAnnotationType::Redacted => {
352 PdfPageAnnotation::Redacted(PdfPageRedactedAnnotation::from_pdfium(
353 document_handle,
354 page_handle,
355 annotation_handle,
356 bindings,
357 ))
358 }
359 _ => PdfPageAnnotation::Unsupported(PdfPageUnsupportedAnnotation::from_pdfium(
360 document_handle,
361 page_handle,
362 annotation_handle,
363 annotation_type,
364 bindings,
365 )),
366 }
367 }
368
369 #[inline]
370 pub(crate) fn unwrap_as_trait(&self) -> &dyn PdfPageAnnotationPrivate<'a> {
371 match self {
372 PdfPageAnnotation::Circle(annotation) => annotation,
373 PdfPageAnnotation::FreeText(annotation) => annotation,
374 PdfPageAnnotation::Highlight(annotation) => annotation,
375 PdfPageAnnotation::Ink(annotation) => annotation,
376 PdfPageAnnotation::Link(annotation) => annotation,
377 PdfPageAnnotation::Popup(annotation) => annotation,
378 PdfPageAnnotation::Square(annotation) => annotation,
379 PdfPageAnnotation::Squiggly(annotation) => annotation,
380 PdfPageAnnotation::Stamp(annotation) => annotation,
381 PdfPageAnnotation::Strikeout(annotation) => annotation,
382 PdfPageAnnotation::Text(annotation) => annotation,
383 PdfPageAnnotation::Underline(annotation) => annotation,
384 PdfPageAnnotation::Widget(annotation) => annotation,
385 PdfPageAnnotation::XfaWidget(annotation) => annotation,
386 PdfPageAnnotation::Redacted(annotation) => annotation,
387 PdfPageAnnotation::Unsupported(annotation) => annotation,
388 }
389 }
390
391 #[inline]
392 #[allow(dead_code)] pub(crate) fn unwrap_as_trait_mut(&mut self) -> &mut dyn PdfPageAnnotationPrivate<'a> {
394 match self {
395 PdfPageAnnotation::Circle(annotation) => annotation,
396 PdfPageAnnotation::FreeText(annotation) => annotation,
397 PdfPageAnnotation::Highlight(annotation) => annotation,
398 PdfPageAnnotation::Ink(annotation) => annotation,
399 PdfPageAnnotation::Link(annotation) => annotation,
400 PdfPageAnnotation::Popup(annotation) => annotation,
401 PdfPageAnnotation::Square(annotation) => annotation,
402 PdfPageAnnotation::Squiggly(annotation) => annotation,
403 PdfPageAnnotation::Stamp(annotation) => annotation,
404 PdfPageAnnotation::Strikeout(annotation) => annotation,
405 PdfPageAnnotation::Text(annotation) => annotation,
406 PdfPageAnnotation::Underline(annotation) => annotation,
407 PdfPageAnnotation::Widget(annotation) => annotation,
408 PdfPageAnnotation::XfaWidget(annotation) => annotation,
409 PdfPageAnnotation::Redacted(annotation) => annotation,
410 PdfPageAnnotation::Unsupported(annotation) => annotation,
411 }
412 }
413
414 #[inline]
438 pub fn annotation_type(&self) -> PdfPageAnnotationType {
439 match self {
440 PdfPageAnnotation::Circle(_) => PdfPageAnnotationType::Circle,
441 PdfPageAnnotation::FreeText(_) => PdfPageAnnotationType::FreeText,
442 PdfPageAnnotation::Highlight(_) => PdfPageAnnotationType::Highlight,
443 PdfPageAnnotation::Ink(_) => PdfPageAnnotationType::Ink,
444 PdfPageAnnotation::Link(_) => PdfPageAnnotationType::Link,
445 PdfPageAnnotation::Popup(_) => PdfPageAnnotationType::Popup,
446 PdfPageAnnotation::Square(_) => PdfPageAnnotationType::Square,
447 PdfPageAnnotation::Squiggly(_) => PdfPageAnnotationType::Squiggly,
448 PdfPageAnnotation::Stamp(_) => PdfPageAnnotationType::Stamp,
449 PdfPageAnnotation::Strikeout(_) => PdfPageAnnotationType::Strikeout,
450 PdfPageAnnotation::Text(_) => PdfPageAnnotationType::Text,
451 PdfPageAnnotation::Underline(_) => PdfPageAnnotationType::Underline,
452 PdfPageAnnotation::Widget(_) => PdfPageAnnotationType::Widget,
453 PdfPageAnnotation::XfaWidget(_) => PdfPageAnnotationType::XfaWidget,
454 PdfPageAnnotation::Redacted(_) => PdfPageAnnotationType::Redacted,
455 PdfPageAnnotation::Unsupported(annotation) => annotation.get_type(),
456 }
457 }
458
459 #[inline]
484 pub fn is_supported(&self) -> bool {
485 !self.is_unsupported()
486 }
487
488 #[inline]
513 pub fn is_unsupported(&self) -> bool {
514 matches!(self, PdfPageAnnotation::Unsupported(_))
515 }
516
517 #[inline]
521 pub fn as_circle_annotation(&self) -> Option<&PdfPageCircleAnnotation> {
522 match self {
523 PdfPageAnnotation::Circle(annotation) => Some(annotation),
524 _ => None,
525 }
526 }
527
528 #[inline]
532 pub fn as_circle_annotation_mut(&mut self) -> Option<&mut PdfPageCircleAnnotation<'a>> {
533 match self {
534 PdfPageAnnotation::Circle(annotation) => Some(annotation),
535 _ => None,
536 }
537 }
538
539 #[inline]
543 pub fn as_free_text_annotation(&self) -> Option<&PdfPageFreeTextAnnotation> {
544 match self {
545 PdfPageAnnotation::FreeText(annotation) => Some(annotation),
546 _ => None,
547 }
548 }
549
550 #[inline]
554 pub fn as_free_text_annotation_mut(&mut self) -> Option<&mut PdfPageFreeTextAnnotation<'a>> {
555 match self {
556 PdfPageAnnotation::FreeText(annotation) => Some(annotation),
557 _ => None,
558 }
559 }
560
561 #[inline]
565 pub fn as_highlight_annotation(&self) -> Option<&PdfPageHighlightAnnotation> {
566 match self {
567 PdfPageAnnotation::Highlight(annotation) => Some(annotation),
568 _ => None,
569 }
570 }
571
572 #[inline]
576 pub fn as_highlight_annotation_mut(&mut self) -> Option<&mut PdfPageHighlightAnnotation<'a>> {
577 match self {
578 PdfPageAnnotation::Highlight(annotation) => Some(annotation),
579 _ => None,
580 }
581 }
582
583 #[inline]
587 pub fn as_ink_annotation(&self) -> Option<&PdfPageInkAnnotation> {
588 match self {
589 PdfPageAnnotation::Ink(annotation) => Some(annotation),
590 _ => None,
591 }
592 }
593
594 #[inline]
598 pub fn as_ink_annotation_mut(&mut self) -> Option<&mut PdfPageInkAnnotation<'a>> {
599 match self {
600 PdfPageAnnotation::Ink(annotation) => Some(annotation),
601 _ => None,
602 }
603 }
604
605 #[inline]
609 pub fn as_link_annotation(&self) -> Option<&PdfPageLinkAnnotation> {
610 match self {
611 PdfPageAnnotation::Link(annotation) => Some(annotation),
612 _ => None,
613 }
614 }
615
616 #[inline]
620 pub fn as_link_annotation_mut(&mut self) -> Option<&mut PdfPageLinkAnnotation<'a>> {
621 match self {
622 PdfPageAnnotation::Link(annotation) => Some(annotation),
623 _ => None,
624 }
625 }
626
627 #[inline]
631 pub fn as_popup_annotation(&self) -> Option<&PdfPagePopupAnnotation> {
632 match self {
633 PdfPageAnnotation::Popup(annotation) => Some(annotation),
634 _ => None,
635 }
636 }
637
638 #[inline]
642 pub fn as_popup_annotation_mut(&mut self) -> Option<&mut PdfPagePopupAnnotation<'a>> {
643 match self {
644 PdfPageAnnotation::Popup(annotation) => Some(annotation),
645 _ => None,
646 }
647 }
648
649 #[inline]
653 pub fn as_square_annotation(&self) -> Option<&PdfPageSquareAnnotation> {
654 match self {
655 PdfPageAnnotation::Square(annotation) => Some(annotation),
656 _ => None,
657 }
658 }
659
660 #[inline]
664 pub fn as_square_annotation_mut(&mut self) -> Option<&mut PdfPageSquareAnnotation<'a>> {
665 match self {
666 PdfPageAnnotation::Square(annotation) => Some(annotation),
667 _ => None,
668 }
669 }
670
671 #[inline]
675 pub fn as_squiggly_annotation(&self) -> Option<&PdfPageSquigglyAnnotation> {
676 match self {
677 PdfPageAnnotation::Squiggly(annotation) => Some(annotation),
678 _ => None,
679 }
680 }
681
682 #[inline]
686 pub fn as_squiggly_annotation_mut(&mut self) -> Option<&mut PdfPageSquigglyAnnotation<'a>> {
687 match self {
688 PdfPageAnnotation::Squiggly(annotation) => Some(annotation),
689 _ => None,
690 }
691 }
692
693 #[inline]
697 pub fn as_stamp_annotation(&self) -> Option<&PdfPageStampAnnotation> {
698 match self {
699 PdfPageAnnotation::Stamp(annotation) => Some(annotation),
700 _ => None,
701 }
702 }
703
704 #[inline]
708 pub fn as_stamp_annotation_mut(&mut self) -> Option<&mut PdfPageStampAnnotation<'a>> {
709 match self {
710 PdfPageAnnotation::Stamp(annotation) => Some(annotation),
711 _ => None,
712 }
713 }
714
715 #[inline]
719 pub fn as_strikeout_annotation(&self) -> Option<&PdfPageStrikeoutAnnotation> {
720 match self {
721 PdfPageAnnotation::Strikeout(annotation) => Some(annotation),
722 _ => None,
723 }
724 }
725
726 #[inline]
730 pub fn as_strikeout_annotation_mut(&mut self) -> Option<&mut PdfPageStrikeoutAnnotation<'a>> {
731 match self {
732 PdfPageAnnotation::Strikeout(annotation) => Some(annotation),
733 _ => None,
734 }
735 }
736
737 #[inline]
741 pub fn as_text_annotation(&self) -> Option<&PdfPageTextAnnotation> {
742 match self {
743 PdfPageAnnotation::Text(annotation) => Some(annotation),
744 _ => None,
745 }
746 }
747
748 #[inline]
752 pub fn as_text_annotation_mut(&mut self) -> Option<&mut PdfPageTextAnnotation<'a>> {
753 match self {
754 PdfPageAnnotation::Text(annotation) => Some(annotation),
755 _ => None,
756 }
757 }
758
759 #[inline]
763 pub fn as_underline_annotation(&self) -> Option<&PdfPageUnderlineAnnotation> {
764 match self {
765 PdfPageAnnotation::Underline(annotation) => Some(annotation),
766 _ => None,
767 }
768 }
769
770 #[inline]
774 pub fn as_underline_annotation_mut(&mut self) -> Option<&mut PdfPageUnderlineAnnotation<'a>> {
775 match self {
776 PdfPageAnnotation::Underline(annotation) => Some(annotation),
777 _ => None,
778 }
779 }
780
781 #[inline]
785 pub fn as_widget_annotation(&self) -> Option<&PdfPageWidgetAnnotation> {
786 match self {
787 PdfPageAnnotation::Widget(annotation) => Some(annotation),
788 _ => None,
789 }
790 }
791
792 #[inline]
796 pub fn as_widget_annotation_mut(&mut self) -> Option<&mut PdfPageWidgetAnnotation<'a>> {
797 match self {
798 PdfPageAnnotation::Widget(annotation) => Some(annotation),
799 _ => None,
800 }
801 }
802
803 #[inline]
807 pub fn as_xfa_widget_annotation(&self) -> Option<&PdfPageXfaWidgetAnnotation> {
808 match self {
809 PdfPageAnnotation::XfaWidget(annotation) => Some(annotation),
810 _ => None,
811 }
812 }
813
814 #[inline]
818 pub fn as_xfa_widget_annotation_mut(&mut self) -> Option<&mut PdfPageXfaWidgetAnnotation<'a>> {
819 match self {
820 PdfPageAnnotation::XfaWidget(annotation) => Some(annotation),
821 _ => None,
822 }
823 }
824
825 #[inline]
829 pub fn as_redacted_annotation(&self) -> Option<&PdfPageRedactedAnnotation> {
830 match self {
831 PdfPageAnnotation::Redacted(annotation) => Some(annotation),
832 _ => None,
833 }
834 }
835
836 #[inline]
840 pub fn as_redacted_annotation_mut(&mut self) -> Option<&mut PdfPageRedactedAnnotation<'a>> {
841 match self {
842 PdfPageAnnotation::Redacted(annotation) => Some(annotation),
843 _ => None,
844 }
845 }
846
847 #[inline]
853 pub fn as_form_field(&self) -> Option<&PdfFormField> {
854 match self {
855 PdfPageAnnotation::Widget(annotation) => annotation.form_field(),
856 PdfPageAnnotation::XfaWidget(annotation) => annotation.form_field(),
857 _ => None,
858 }
859 }
860
861 #[inline]
867 pub fn as_form_field_mut(&mut self) -> Option<&mut PdfFormField<'a>> {
868 match self {
869 PdfPageAnnotation::Widget(annotation) => annotation.form_field_mut(),
870 PdfPageAnnotation::XfaWidget(annotation) => annotation.form_field_mut(),
871 _ => None,
872 }
873 }
874}
875
876pub trait PdfPageAnnotationCommon {
878 fn name(&self) -> Option<String>;
881
882 fn is_markup_annotation(&self) -> bool;
886
887 fn has_attachment_points(&self) -> bool;
890
891 fn bounds(&self) -> Result<PdfRect, PdfiumError>;
893
894 fn set_bounds(&mut self, bounds: PdfRect) -> Result<(), PdfiumError>;
900
901 fn set_position(&mut self, x: PdfPoints, y: PdfPoints) -> Result<(), PdfiumError>;
906
907 fn set_width(&mut self, width: PdfPoints) -> Result<(), PdfiumError>;
912
913 fn set_height(&mut self, width: PdfPoints) -> Result<(), PdfiumError>;
918
919 fn contents(&self) -> Option<String>;
924
925 fn set_contents(&mut self, contents: &str) -> Result<(), PdfiumError>;
929
930 fn creator(&self) -> Option<String>;
932
933 fn set_creator(&mut self, creator: &str) -> Result<(), PdfiumError>;
935
936 fn creation_date(&self) -> Option<String>;
938
939 fn set_creation_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError>;
941
942 fn modification_date(&self) -> Option<String>;
944
945 fn set_modification_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError>;
947
948 fn fill_color(&self) -> Result<PdfColor, PdfiumError>;
950
951 fn set_fill_color(&mut self, fill_color: PdfColor) -> Result<(), PdfiumError>;
953
954 fn stroke_color(&self) -> Result<PdfColor, PdfiumError>;
956
957 fn set_stroke_color(&mut self, stroke_color: PdfColor) -> Result<(), PdfiumError>;
959
960 fn objects(&self) -> &PdfPageAnnotationObjects;
973
974 fn attachment_points(&self) -> &PdfPageAnnotationAttachmentPoints;
989}
990
991impl<'a, T> PdfPageAnnotationCommon for T
994where
995 T: PdfPageAnnotationPrivate<'a>,
996{
997 #[inline]
998 fn name(&self) -> Option<String> {
999 self.name_impl()
1000 }
1001
1002 #[inline]
1003 fn is_markup_annotation(&self) -> bool {
1004 self.is_markup_annotation_impl()
1005 }
1006
1007 #[inline]
1008 fn has_attachment_points(&self) -> bool {
1009 self.has_attachment_points_impl()
1010 }
1011
1012 #[inline]
1013 fn bounds(&self) -> Result<PdfRect, PdfiumError> {
1014 self.bounds_impl()
1015 }
1016
1017 #[inline]
1018 fn set_bounds(&mut self, bounds: PdfRect) -> Result<(), PdfiumError> {
1019 self.set_bounds_impl(bounds)
1020 }
1021
1022 #[inline]
1023 fn set_position(&mut self, x: PdfPoints, y: PdfPoints) -> Result<(), PdfiumError> {
1024 self.set_position_impl(x, y)
1025 }
1026
1027 #[inline]
1028 fn set_width(&mut self, width: PdfPoints) -> Result<(), PdfiumError> {
1029 self.set_width_impl(width)
1030 }
1031
1032 #[inline]
1033 fn set_height(&mut self, height: PdfPoints) -> Result<(), PdfiumError> {
1034 self.set_height_impl(height)
1035 }
1036
1037 #[inline]
1038 fn contents(&self) -> Option<String> {
1039 self.contents_impl()
1040 }
1041
1042 #[inline]
1043 fn set_contents(&mut self, contents: &str) -> Result<(), PdfiumError> {
1044 self.set_contents_impl(contents)
1045 }
1046
1047 #[inline]
1048 fn creator(&self) -> Option<String> {
1049 self.creator_impl()
1050 }
1051
1052 #[inline]
1053 fn set_creator(&mut self, creator: &str) -> Result<(), PdfiumError> {
1054 self.set_creator_impl(creator)
1055 }
1056
1057 #[inline]
1058 fn creation_date(&self) -> Option<String> {
1059 self.creation_date_impl()
1060 }
1061
1062 #[inline]
1063 fn set_creation_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError> {
1064 self.set_creation_date_impl(date)
1065 }
1066
1067 #[inline]
1068 fn modification_date(&self) -> Option<String> {
1069 self.modification_date_impl()
1070 }
1071
1072 #[inline]
1073 fn set_modification_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError> {
1074 self.set_modification_date_impl(date)
1075 }
1076
1077 #[inline]
1078 fn fill_color(&self) -> Result<PdfColor, PdfiumError> {
1079 self.fill_color_impl()
1080 }
1081
1082 #[inline]
1083 fn set_fill_color(&mut self, fill_color: PdfColor) -> Result<(), PdfiumError> {
1084 self.set_fill_color_impl(fill_color)
1085 }
1086
1087 #[inline]
1088 fn stroke_color(&self) -> Result<PdfColor, PdfiumError> {
1089 self.stroke_color_impl()
1090 }
1091
1092 #[inline]
1093 fn set_stroke_color(&mut self, stroke_color: PdfColor) -> Result<(), PdfiumError> {
1094 self.set_stroke_color_impl(stroke_color)
1095 }
1096
1097 #[inline]
1098 fn objects(&self) -> &PdfPageAnnotationObjects {
1099 self.objects_impl()
1100 }
1101
1102 #[inline]
1103 fn attachment_points(&self) -> &PdfPageAnnotationAttachmentPoints {
1104 self.attachment_points_impl()
1105 }
1106}
1107
1108impl<'a> PdfPageAnnotationPrivate<'a> for PdfPageAnnotation<'a> {
1109 #[inline]
1110 fn handle(&self) -> FPDF_ANNOTATION {
1111 self.unwrap_as_trait().handle()
1112 }
1113
1114 #[inline]
1115 fn bindings(&self) -> &dyn PdfiumLibraryBindings {
1116 self.unwrap_as_trait().bindings()
1117 }
1118
1119 #[inline]
1120 fn ownership(&self) -> &PdfPageObjectOwnership {
1121 self.unwrap_as_trait().ownership()
1122 }
1123
1124 #[inline]
1125 fn objects_impl(&self) -> &PdfPageAnnotationObjects {
1126 self.unwrap_as_trait().objects_impl()
1127 }
1128
1129 #[inline]
1130 fn attachment_points_impl(&self) -> &PdfPageAnnotationAttachmentPoints {
1131 self.unwrap_as_trait().attachment_points_impl()
1132 }
1133}
1134
1135impl<'a> Drop for PdfPageAnnotation<'a> {
1136 #[inline]
1138 fn drop(&mut self) {
1139 self.bindings().FPDFPage_CloseAnnot(self.handle());
1140 }
1141}