1pub mod attachment_points;
4pub mod circle;
5pub mod free_text;
6pub mod highlight;
7pub mod ink;
8pub mod link;
9pub mod objects;
10pub(crate) mod private;
11pub mod square;
12pub mod squiggly;
13pub mod stamp;
14pub mod strikeout;
15pub mod text;
16pub mod underline;
17pub mod unsupported;
18
19use crate::bindgen::{
20 FPDF_ANNOT_CARET, FPDF_ANNOT_CIRCLE, FPDF_ANNOT_FILEATTACHMENT, FPDF_ANNOT_FREETEXT, FPDF_ANNOT_HIGHLIGHT,
21 FPDF_ANNOT_INK, FPDF_ANNOT_LINE, FPDF_ANNOT_LINK, FPDF_ANNOT_MOVIE, FPDF_ANNOT_POLYGON, FPDF_ANNOT_POLYLINE,
22 FPDF_ANNOT_POPUP, FPDF_ANNOT_PRINTERMARK, FPDF_ANNOT_REDACT, FPDF_ANNOT_RICHMEDIA, FPDF_ANNOT_SCREEN,
23 FPDF_ANNOT_SOUND, FPDF_ANNOT_SQUARE, FPDF_ANNOT_SQUIGGLY, FPDF_ANNOT_STAMP, FPDF_ANNOT_STRIKEOUT, FPDF_ANNOT_TEXT,
24 FPDF_ANNOT_THREED, FPDF_ANNOT_TRAPNET, FPDF_ANNOT_UNDERLINE, FPDF_ANNOT_UNKNOWN, FPDF_ANNOT_WATERMARK,
25 FPDF_ANNOT_WIDGET, FPDF_ANNOT_XFAWIDGET, FPDF_ANNOTATION, FPDF_ANNOTATION_SUBTYPE, FPDF_DOCUMENT, FPDF_FORMHANDLE,
26 FPDF_PAGE,
27};
28use crate::bindings::PdfiumLibraryBindings;
29use crate::error::PdfiumError;
30use crate::pdf::color::PdfColor;
31use crate::pdf::document::page::annotation::attachment_points::PdfPageAnnotationAttachmentPoints;
32use crate::pdf::document::page::annotation::circle::PdfPageCircleAnnotation;
33use crate::pdf::document::page::annotation::free_text::PdfPageFreeTextAnnotation;
34use crate::pdf::document::page::annotation::highlight::PdfPageHighlightAnnotation;
35use crate::pdf::document::page::annotation::ink::PdfPageInkAnnotation;
36use crate::pdf::document::page::annotation::link::PdfPageLinkAnnotation;
37use crate::pdf::document::page::annotation::objects::PdfPageAnnotationObjects;
38use crate::pdf::document::page::annotation::private::internal::{PdfAnnotationFlags, PdfPageAnnotationPrivate};
39use crate::pdf::document::page::annotation::square::PdfPageSquareAnnotation;
40use crate::pdf::document::page::annotation::squiggly::PdfPageSquigglyAnnotation;
41use crate::pdf::document::page::annotation::stamp::PdfPageStampAnnotation;
42use crate::pdf::document::page::annotation::strikeout::PdfPageStrikeoutAnnotation;
43use crate::pdf::document::page::annotation::text::PdfPageTextAnnotation;
44use crate::pdf::document::page::annotation::underline::PdfPageUnderlineAnnotation;
45use crate::pdf::document::page::annotation::unsupported::PdfPageUnsupportedAnnotation;
46use crate::pdf::document::page::object::ownership::PdfPageObjectOwnership;
47use crate::pdf::points::PdfPoints;
48use crate::pdf::rect::PdfRect;
49use chrono::prelude::*;
50
51#[cfg(doc)]
52use crate::pdf::document::page::PdfPage;
53
54#[derive(Debug, Copy, Clone, PartialOrd, PartialEq)]
83pub enum PdfPageAnnotationType {
84 Unknown = FPDF_ANNOT_UNKNOWN as isize,
85 Text = FPDF_ANNOT_TEXT as isize,
86 Link = FPDF_ANNOT_LINK as isize,
87 FreeText = FPDF_ANNOT_FREETEXT as isize,
88 Line = FPDF_ANNOT_LINE as isize,
89 Square = FPDF_ANNOT_SQUARE as isize,
90 Circle = FPDF_ANNOT_CIRCLE as isize,
91 Polygon = FPDF_ANNOT_POLYGON as isize,
92 Polyline = FPDF_ANNOT_POLYLINE as isize,
93 Highlight = FPDF_ANNOT_HIGHLIGHT as isize,
94 Underline = FPDF_ANNOT_UNDERLINE as isize,
95 Squiggly = FPDF_ANNOT_SQUIGGLY as isize,
96 Strikeout = FPDF_ANNOT_STRIKEOUT as isize,
97 Stamp = FPDF_ANNOT_STAMP as isize,
98 Caret = FPDF_ANNOT_CARET as isize,
99 Ink = FPDF_ANNOT_INK as isize,
100 Popup = FPDF_ANNOT_POPUP as isize,
101 FileAttachment = FPDF_ANNOT_FILEATTACHMENT as isize,
102 Sound = FPDF_ANNOT_SOUND as isize,
103 Movie = FPDF_ANNOT_MOVIE as isize,
104 Widget = FPDF_ANNOT_WIDGET as isize,
105 Screen = FPDF_ANNOT_SCREEN as isize,
106 PrinterMark = FPDF_ANNOT_PRINTERMARK as isize,
107 TrapNet = FPDF_ANNOT_TRAPNET as isize,
108 Watermark = FPDF_ANNOT_WATERMARK as isize,
109 ThreeD = FPDF_ANNOT_THREED as isize,
110 RichMedia = FPDF_ANNOT_RICHMEDIA as isize,
111 XfaWidget = FPDF_ANNOT_XFAWIDGET as isize,
112 Redacted = FPDF_ANNOT_REDACT as isize,
113}
114
115impl PdfPageAnnotationType {
116 pub(crate) fn from_pdfium(value: FPDF_ANNOTATION_SUBTYPE) -> Result<PdfPageAnnotationType, PdfiumError> {
117 match value as u32 {
118 FPDF_ANNOT_UNKNOWN => Ok(PdfPageAnnotationType::Unknown),
119 FPDF_ANNOT_TEXT => Ok(PdfPageAnnotationType::Text),
120 FPDF_ANNOT_LINK => Ok(PdfPageAnnotationType::Link),
121 FPDF_ANNOT_FREETEXT => Ok(PdfPageAnnotationType::FreeText),
122 FPDF_ANNOT_LINE => Ok(PdfPageAnnotationType::Line),
123 FPDF_ANNOT_SQUARE => Ok(PdfPageAnnotationType::Square),
124 FPDF_ANNOT_CIRCLE => Ok(PdfPageAnnotationType::Circle),
125 FPDF_ANNOT_POLYGON => Ok(PdfPageAnnotationType::Polygon),
126 FPDF_ANNOT_POLYLINE => Ok(PdfPageAnnotationType::Polyline),
127 FPDF_ANNOT_HIGHLIGHT => Ok(PdfPageAnnotationType::Highlight),
128 FPDF_ANNOT_UNDERLINE => Ok(PdfPageAnnotationType::Underline),
129 FPDF_ANNOT_SQUIGGLY => Ok(PdfPageAnnotationType::Squiggly),
130 FPDF_ANNOT_STRIKEOUT => Ok(PdfPageAnnotationType::Strikeout),
131 FPDF_ANNOT_STAMP => Ok(PdfPageAnnotationType::Stamp),
132 FPDF_ANNOT_CARET => Ok(PdfPageAnnotationType::Caret),
133 FPDF_ANNOT_INK => Ok(PdfPageAnnotationType::Ink),
134 FPDF_ANNOT_POPUP => Ok(PdfPageAnnotationType::Popup),
135 FPDF_ANNOT_FILEATTACHMENT => Ok(PdfPageAnnotationType::FileAttachment),
136 FPDF_ANNOT_SOUND => Ok(PdfPageAnnotationType::Sound),
137 FPDF_ANNOT_MOVIE => Ok(PdfPageAnnotationType::Movie),
138 FPDF_ANNOT_WIDGET => Ok(PdfPageAnnotationType::Widget),
139 FPDF_ANNOT_SCREEN => Ok(PdfPageAnnotationType::Screen),
140 FPDF_ANNOT_PRINTERMARK => Ok(PdfPageAnnotationType::PrinterMark),
141 FPDF_ANNOT_TRAPNET => Ok(PdfPageAnnotationType::TrapNet),
142 FPDF_ANNOT_WATERMARK => Ok(PdfPageAnnotationType::Watermark),
143 FPDF_ANNOT_THREED => Ok(PdfPageAnnotationType::ThreeD),
144 FPDF_ANNOT_RICHMEDIA => Ok(PdfPageAnnotationType::RichMedia),
145 FPDF_ANNOT_XFAWIDGET => Ok(PdfPageAnnotationType::XfaWidget),
146 FPDF_ANNOT_REDACT => Ok(PdfPageAnnotationType::Redacted),
147 _ => Err(PdfiumError::UnknownPdfAnnotationType),
148 }
149 }
150
151 #[allow(dead_code)]
152 pub(crate) fn as_pdfium(&self) -> FPDF_ANNOTATION_SUBTYPE {
153 (match self {
154 PdfPageAnnotationType::Unknown => FPDF_ANNOT_UNKNOWN,
155 PdfPageAnnotationType::Text => FPDF_ANNOT_TEXT,
156 PdfPageAnnotationType::Link => FPDF_ANNOT_LINK,
157 PdfPageAnnotationType::FreeText => FPDF_ANNOT_FREETEXT,
158 PdfPageAnnotationType::Line => FPDF_ANNOT_LINE,
159 PdfPageAnnotationType::Square => FPDF_ANNOT_SQUARE,
160 PdfPageAnnotationType::Circle => FPDF_ANNOT_CIRCLE,
161 PdfPageAnnotationType::Polygon => FPDF_ANNOT_POLYGON,
162 PdfPageAnnotationType::Polyline => FPDF_ANNOT_POLYLINE,
163 PdfPageAnnotationType::Highlight => FPDF_ANNOT_HIGHLIGHT,
164 PdfPageAnnotationType::Underline => FPDF_ANNOT_UNDERLINE,
165 PdfPageAnnotationType::Squiggly => FPDF_ANNOT_SQUIGGLY,
166 PdfPageAnnotationType::Strikeout => FPDF_ANNOT_STRIKEOUT,
167 PdfPageAnnotationType::Stamp => FPDF_ANNOT_STAMP,
168 PdfPageAnnotationType::Caret => FPDF_ANNOT_CARET,
169 PdfPageAnnotationType::Ink => FPDF_ANNOT_INK,
170 PdfPageAnnotationType::Popup => FPDF_ANNOT_POPUP,
171 PdfPageAnnotationType::FileAttachment => FPDF_ANNOT_FILEATTACHMENT,
172 PdfPageAnnotationType::Sound => FPDF_ANNOT_SOUND,
173 PdfPageAnnotationType::Movie => FPDF_ANNOT_MOVIE,
174 PdfPageAnnotationType::Widget => FPDF_ANNOT_WIDGET,
175 PdfPageAnnotationType::Screen => FPDF_ANNOT_SCREEN,
176 PdfPageAnnotationType::PrinterMark => FPDF_ANNOT_PRINTERMARK,
177 PdfPageAnnotationType::TrapNet => FPDF_ANNOT_TRAPNET,
178 PdfPageAnnotationType::Watermark => FPDF_ANNOT_WATERMARK,
179 PdfPageAnnotationType::ThreeD => FPDF_ANNOT_THREED,
180 PdfPageAnnotationType::RichMedia => FPDF_ANNOT_RICHMEDIA,
181 PdfPageAnnotationType::XfaWidget => FPDF_ANNOT_XFAWIDGET,
182 PdfPageAnnotationType::Redacted => FPDF_ANNOT_REDACT,
183 }) as FPDF_ANNOTATION_SUBTYPE
184 }
185}
186
187pub enum PdfPageAnnotation<'a> {
189 Circle(PdfPageCircleAnnotation<'a>),
190 FreeText(PdfPageFreeTextAnnotation<'a>),
191 Highlight(PdfPageHighlightAnnotation<'a>),
192 Ink(PdfPageInkAnnotation<'a>),
193 Link(PdfPageLinkAnnotation<'a>),
194 Square(PdfPageSquareAnnotation<'a>),
195 Squiggly(PdfPageSquigglyAnnotation<'a>),
196 Stamp(PdfPageStampAnnotation<'a>),
197 Strikeout(PdfPageStrikeoutAnnotation<'a>),
198 Text(PdfPageTextAnnotation<'a>),
199 Underline(PdfPageUnderlineAnnotation<'a>),
200
201 Unsupported(PdfPageUnsupportedAnnotation<'a>),
205}
206
207impl<'a> PdfPageAnnotation<'a> {
208 pub(crate) fn from_pdfium(
209 document_handle: FPDF_DOCUMENT,
210 page_handle: FPDF_PAGE,
211 annotation_handle: FPDF_ANNOTATION,
212 _form_handle: Option<FPDF_FORMHANDLE>,
213 bindings: &'a dyn PdfiumLibraryBindings,
214 ) -> Self {
215 let annotation_type = PdfPageAnnotationType::from_pdfium(bindings.FPDFAnnot_GetSubtype(annotation_handle))
216 .unwrap_or(PdfPageAnnotationType::Unknown);
217
218 match annotation_type {
219 PdfPageAnnotationType::Circle => PdfPageAnnotation::Circle(PdfPageCircleAnnotation::from_pdfium(
220 document_handle,
221 page_handle,
222 annotation_handle,
223 bindings,
224 )),
225 PdfPageAnnotationType::FreeText => PdfPageAnnotation::FreeText(PdfPageFreeTextAnnotation::from_pdfium(
226 document_handle,
227 page_handle,
228 annotation_handle,
229 bindings,
230 )),
231 PdfPageAnnotationType::Highlight => PdfPageAnnotation::Highlight(PdfPageHighlightAnnotation::from_pdfium(
232 document_handle,
233 page_handle,
234 annotation_handle,
235 bindings,
236 )),
237 PdfPageAnnotationType::Ink => PdfPageAnnotation::Ink(PdfPageInkAnnotation::from_pdfium(
238 document_handle,
239 page_handle,
240 annotation_handle,
241 bindings,
242 )),
243 PdfPageAnnotationType::Link => PdfPageAnnotation::Link(PdfPageLinkAnnotation::from_pdfium(
244 document_handle,
245 page_handle,
246 annotation_handle,
247 bindings,
248 )),
249 PdfPageAnnotationType::Square => PdfPageAnnotation::Square(PdfPageSquareAnnotation::from_pdfium(
250 document_handle,
251 page_handle,
252 annotation_handle,
253 bindings,
254 )),
255 PdfPageAnnotationType::Squiggly => PdfPageAnnotation::Squiggly(PdfPageSquigglyAnnotation::from_pdfium(
256 document_handle,
257 page_handle,
258 annotation_handle,
259 bindings,
260 )),
261 PdfPageAnnotationType::Stamp => PdfPageAnnotation::Stamp(PdfPageStampAnnotation::from_pdfium(
262 document_handle,
263 page_handle,
264 annotation_handle,
265 bindings,
266 )),
267 PdfPageAnnotationType::Strikeout => PdfPageAnnotation::Strikeout(PdfPageStrikeoutAnnotation::from_pdfium(
268 document_handle,
269 page_handle,
270 annotation_handle,
271 bindings,
272 )),
273 PdfPageAnnotationType::Text => PdfPageAnnotation::Text(PdfPageTextAnnotation::from_pdfium(
274 document_handle,
275 page_handle,
276 annotation_handle,
277 bindings,
278 )),
279 PdfPageAnnotationType::Underline => PdfPageAnnotation::Underline(PdfPageUnderlineAnnotation::from_pdfium(
280 document_handle,
281 page_handle,
282 annotation_handle,
283 bindings,
284 )),
285 _ => PdfPageAnnotation::Unsupported(PdfPageUnsupportedAnnotation::from_pdfium(
286 document_handle,
287 page_handle,
288 annotation_handle,
289 annotation_type,
290 bindings,
291 )),
292 }
293 }
294
295 #[inline]
296 pub(crate) fn unwrap_as_trait(&self) -> &dyn PdfPageAnnotationPrivate<'a> {
297 match self {
298 PdfPageAnnotation::Circle(annotation) => annotation,
299 PdfPageAnnotation::FreeText(annotation) => annotation,
300 PdfPageAnnotation::Highlight(annotation) => annotation,
301 PdfPageAnnotation::Ink(annotation) => annotation,
302 PdfPageAnnotation::Link(annotation) => annotation,
303 PdfPageAnnotation::Square(annotation) => annotation,
304 PdfPageAnnotation::Squiggly(annotation) => annotation,
305 PdfPageAnnotation::Stamp(annotation) => annotation,
306 PdfPageAnnotation::Strikeout(annotation) => annotation,
307 PdfPageAnnotation::Text(annotation) => annotation,
308 PdfPageAnnotation::Underline(annotation) => annotation,
309 PdfPageAnnotation::Unsupported(annotation) => annotation,
310 }
311 }
312
313 #[inline]
314 #[allow(dead_code)]
315 pub(crate) fn unwrap_as_trait_mut(&mut self) -> &mut dyn PdfPageAnnotationPrivate<'a> {
316 match self {
317 PdfPageAnnotation::Circle(annotation) => annotation,
318 PdfPageAnnotation::FreeText(annotation) => annotation,
319 PdfPageAnnotation::Highlight(annotation) => annotation,
320 PdfPageAnnotation::Ink(annotation) => annotation,
321 PdfPageAnnotation::Link(annotation) => annotation,
322 PdfPageAnnotation::Square(annotation) => annotation,
323 PdfPageAnnotation::Squiggly(annotation) => annotation,
324 PdfPageAnnotation::Stamp(annotation) => annotation,
325 PdfPageAnnotation::Strikeout(annotation) => annotation,
326 PdfPageAnnotation::Text(annotation) => annotation,
327 PdfPageAnnotation::Underline(annotation) => annotation,
328 PdfPageAnnotation::Unsupported(annotation) => annotation,
329 }
330 }
331
332 #[inline]
356 pub fn annotation_type(&self) -> PdfPageAnnotationType {
357 match self {
358 PdfPageAnnotation::Circle(_) => PdfPageAnnotationType::Circle,
359 PdfPageAnnotation::FreeText(_) => PdfPageAnnotationType::FreeText,
360 PdfPageAnnotation::Highlight(_) => PdfPageAnnotationType::Highlight,
361 PdfPageAnnotation::Ink(_) => PdfPageAnnotationType::Ink,
362 PdfPageAnnotation::Link(_) => PdfPageAnnotationType::Link,
363 PdfPageAnnotation::Square(_) => PdfPageAnnotationType::Square,
364 PdfPageAnnotation::Squiggly(_) => PdfPageAnnotationType::Squiggly,
365 PdfPageAnnotation::Stamp(_) => PdfPageAnnotationType::Stamp,
366 PdfPageAnnotation::Strikeout(_) => PdfPageAnnotationType::Strikeout,
367 PdfPageAnnotation::Text(_) => PdfPageAnnotationType::Text,
368 PdfPageAnnotation::Underline(_) => PdfPageAnnotationType::Underline,
369 PdfPageAnnotation::Unsupported(annotation) => annotation.get_type(),
370 }
371 }
372
373 #[inline]
398 pub fn is_supported(&self) -> bool {
399 !self.is_unsupported()
400 }
401
402 #[inline]
427 pub fn is_unsupported(&self) -> bool {
428 matches!(self, PdfPageAnnotation::Unsupported(_))
429 }
430
431 #[inline]
435 pub fn as_circle_annotation(&self) -> Option<&PdfPageCircleAnnotation<'_>> {
436 match self {
437 PdfPageAnnotation::Circle(annotation) => Some(annotation),
438 _ => None,
439 }
440 }
441
442 #[inline]
446 pub fn as_circle_annotation_mut(&mut self) -> Option<&mut PdfPageCircleAnnotation<'a>> {
447 match self {
448 PdfPageAnnotation::Circle(annotation) => Some(annotation),
449 _ => None,
450 }
451 }
452
453 #[inline]
457 pub fn as_free_text_annotation(&self) -> Option<&PdfPageFreeTextAnnotation<'_>> {
458 match self {
459 PdfPageAnnotation::FreeText(annotation) => Some(annotation),
460 _ => None,
461 }
462 }
463
464 #[inline]
468 pub fn as_free_text_annotation_mut(&mut self) -> Option<&mut PdfPageFreeTextAnnotation<'a>> {
469 match self {
470 PdfPageAnnotation::FreeText(annotation) => Some(annotation),
471 _ => None,
472 }
473 }
474
475 #[inline]
479 pub fn as_highlight_annotation(&self) -> Option<&PdfPageHighlightAnnotation<'_>> {
480 match self {
481 PdfPageAnnotation::Highlight(annotation) => Some(annotation),
482 _ => None,
483 }
484 }
485
486 #[inline]
490 pub fn as_highlight_annotation_mut(&mut self) -> Option<&mut PdfPageHighlightAnnotation<'a>> {
491 match self {
492 PdfPageAnnotation::Highlight(annotation) => Some(annotation),
493 _ => None,
494 }
495 }
496
497 #[inline]
501 pub fn as_ink_annotation(&self) -> Option<&PdfPageInkAnnotation<'_>> {
502 match self {
503 PdfPageAnnotation::Ink(annotation) => Some(annotation),
504 _ => None,
505 }
506 }
507
508 #[inline]
512 pub fn as_ink_annotation_mut(&mut self) -> Option<&mut PdfPageInkAnnotation<'a>> {
513 match self {
514 PdfPageAnnotation::Ink(annotation) => Some(annotation),
515 _ => None,
516 }
517 }
518
519 #[inline]
523 pub fn as_link_annotation(&self) -> Option<&PdfPageLinkAnnotation<'_>> {
524 match self {
525 PdfPageAnnotation::Link(annotation) => Some(annotation),
526 _ => None,
527 }
528 }
529
530 #[inline]
534 pub fn as_link_annotation_mut(&mut self) -> Option<&mut PdfPageLinkAnnotation<'a>> {
535 match self {
536 PdfPageAnnotation::Link(annotation) => Some(annotation),
537 _ => None,
538 }
539 }
540
541 #[inline]
545 pub fn as_square_annotation(&self) -> Option<&PdfPageSquareAnnotation<'_>> {
546 match self {
547 PdfPageAnnotation::Square(annotation) => Some(annotation),
548 _ => None,
549 }
550 }
551
552 #[inline]
556 pub fn as_square_annotation_mut(&mut self) -> Option<&mut PdfPageSquareAnnotation<'a>> {
557 match self {
558 PdfPageAnnotation::Square(annotation) => Some(annotation),
559 _ => None,
560 }
561 }
562
563 #[inline]
567 pub fn as_squiggly_annotation(&self) -> Option<&PdfPageSquigglyAnnotation<'_>> {
568 match self {
569 PdfPageAnnotation::Squiggly(annotation) => Some(annotation),
570 _ => None,
571 }
572 }
573
574 #[inline]
578 pub fn as_squiggly_annotation_mut(&mut self) -> Option<&mut PdfPageSquigglyAnnotation<'a>> {
579 match self {
580 PdfPageAnnotation::Squiggly(annotation) => Some(annotation),
581 _ => None,
582 }
583 }
584
585 #[inline]
589 pub fn as_stamp_annotation(&self) -> Option<&PdfPageStampAnnotation<'_>> {
590 match self {
591 PdfPageAnnotation::Stamp(annotation) => Some(annotation),
592 _ => None,
593 }
594 }
595
596 #[inline]
600 pub fn as_stamp_annotation_mut(&mut self) -> Option<&mut PdfPageStampAnnotation<'a>> {
601 match self {
602 PdfPageAnnotation::Stamp(annotation) => Some(annotation),
603 _ => None,
604 }
605 }
606
607 #[inline]
611 pub fn as_strikeout_annotation(&self) -> Option<&PdfPageStrikeoutAnnotation<'_>> {
612 match self {
613 PdfPageAnnotation::Strikeout(annotation) => Some(annotation),
614 _ => None,
615 }
616 }
617
618 #[inline]
622 pub fn as_strikeout_annotation_mut(&mut self) -> Option<&mut PdfPageStrikeoutAnnotation<'a>> {
623 match self {
624 PdfPageAnnotation::Strikeout(annotation) => Some(annotation),
625 _ => None,
626 }
627 }
628
629 #[inline]
633 pub fn as_text_annotation(&self) -> Option<&PdfPageTextAnnotation<'_>> {
634 match self {
635 PdfPageAnnotation::Text(annotation) => Some(annotation),
636 _ => None,
637 }
638 }
639
640 #[inline]
644 pub fn as_text_annotation_mut(&mut self) -> Option<&mut PdfPageTextAnnotation<'a>> {
645 match self {
646 PdfPageAnnotation::Text(annotation) => Some(annotation),
647 _ => None,
648 }
649 }
650
651 #[inline]
655 pub fn as_underline_annotation(&self) -> Option<&PdfPageUnderlineAnnotation<'_>> {
656 match self {
657 PdfPageAnnotation::Underline(annotation) => Some(annotation),
658 _ => None,
659 }
660 }
661
662 #[inline]
666 pub fn as_underline_annotation_mut(&mut self) -> Option<&mut PdfPageUnderlineAnnotation<'a>> {
667 match self {
668 PdfPageAnnotation::Underline(annotation) => Some(annotation),
669 _ => None,
670 }
671 }
672}
673
674pub trait PdfPageAnnotationCommon {
676 fn name(&self) -> Option<String>;
679
680 fn is_markup_annotation(&self) -> bool;
684
685 fn has_attachment_points(&self) -> bool;
688
689 fn bounds(&self) -> Result<PdfRect, PdfiumError>;
691
692 fn set_bounds(&mut self, bounds: PdfRect) -> Result<(), PdfiumError>;
698
699 fn set_position(&mut self, x: PdfPoints, y: PdfPoints) -> Result<(), PdfiumError>;
704
705 fn set_width(&mut self, width: PdfPoints) -> Result<(), PdfiumError>;
710
711 fn set_height(&mut self, width: PdfPoints) -> Result<(), PdfiumError>;
716
717 fn contents(&self) -> Option<String>;
722
723 fn set_contents(&mut self, contents: &str) -> Result<(), PdfiumError>;
727
728 fn creator(&self) -> Option<String>;
730
731 fn set_creator(&mut self, creator: &str) -> Result<(), PdfiumError>;
733
734 fn creation_date(&self) -> Option<String>;
736
737 fn set_creation_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError>;
739
740 fn modification_date(&self) -> Option<String>;
742
743 fn set_modification_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError>;
745
746 fn fill_color(&self) -> Result<PdfColor, PdfiumError>;
748
749 fn set_fill_color(&mut self, fill_color: PdfColor) -> Result<(), PdfiumError>;
751
752 fn stroke_color(&self) -> Result<PdfColor, PdfiumError>;
754
755 fn set_stroke_color(&mut self, stroke_color: PdfColor) -> Result<(), PdfiumError>;
757
758 fn is_invisible_if_unsupported(&self) -> bool;
762
763 fn set_is_invisible_if_unsupported(&mut self, is_invisible: bool) -> Result<(), PdfiumError>;
767
768 fn is_hidden(&self) -> bool;
774
775 fn set_is_hidden(&mut self, is_hidden: bool) -> Result<(), PdfiumError>;
781
782 fn is_printed(&self) -> bool;
790
791 fn set_is_printed(&mut self, is_printed: bool) -> Result<(), PdfiumError>;
799
800 fn is_zoomable(&self) -> bool;
807
808 fn set_is_zoomable(&mut self, is_zoomable: bool) -> Result<(), PdfiumError>;
813
814 fn is_rotatable(&self) -> bool;
820
821 fn set_is_rotatable(&mut self, is_rotatable: bool) -> Result<(), PdfiumError>;
826
827 fn is_printable_but_not_viewable(&self) -> bool;
834
835 fn set_is_printable_but_not_viewable(&mut self, is_printable_but_not_viewable: bool) -> Result<(), PdfiumError>;
841
842 fn is_read_only(&self) -> bool;
853
854 fn set_is_read_only(&mut self, is_read_only: bool) -> Result<(), PdfiumError>;
862
863 fn is_locked(&self) -> bool;
868
869 fn set_is_locked(&mut self, is_locked: bool) -> Result<(), PdfiumError>;
874
875 fn is_editable(&self) -> bool;
880
881 fn set_is_editable(&mut self, is_editable: bool) -> Result<(), PdfiumError>;
886
887 fn objects(&self) -> &PdfPageAnnotationObjects<'_>;
900
901 fn attachment_points(&self) -> &PdfPageAnnotationAttachmentPoints<'_>;
916}
917
918impl<'a, T> PdfPageAnnotationCommon for T
919where
920 T: PdfPageAnnotationPrivate<'a>,
921{
922 #[inline]
923 fn name(&self) -> Option<String> {
924 self.name_impl()
925 }
926
927 #[inline]
928 fn is_markup_annotation(&self) -> bool {
929 self.is_markup_annotation_impl()
930 }
931
932 #[inline]
933 fn has_attachment_points(&self) -> bool {
934 self.has_attachment_points_impl()
935 }
936
937 #[inline]
938 fn bounds(&self) -> Result<PdfRect, PdfiumError> {
939 self.bounds_impl()
940 }
941
942 #[inline]
943 fn set_bounds(&mut self, bounds: PdfRect) -> Result<(), PdfiumError> {
944 self.set_bounds_impl(bounds)
945 }
946
947 #[inline]
948 fn set_position(&mut self, x: PdfPoints, y: PdfPoints) -> Result<(), PdfiumError> {
949 self.set_position_impl(x, y)
950 }
951
952 #[inline]
953 fn set_width(&mut self, width: PdfPoints) -> Result<(), PdfiumError> {
954 self.set_width_impl(width)
955 }
956
957 #[inline]
958 fn set_height(&mut self, height: PdfPoints) -> Result<(), PdfiumError> {
959 self.set_height_impl(height)
960 }
961
962 #[inline]
963 fn contents(&self) -> Option<String> {
964 self.contents_impl()
965 }
966
967 #[inline]
968 fn set_contents(&mut self, contents: &str) -> Result<(), PdfiumError> {
969 self.set_contents_impl(contents)
970 }
971
972 #[inline]
973 fn creator(&self) -> Option<String> {
974 self.creator_impl()
975 }
976
977 #[inline]
978 fn set_creator(&mut self, creator: &str) -> Result<(), PdfiumError> {
979 self.set_creator_impl(creator)
980 }
981
982 #[inline]
983 fn creation_date(&self) -> Option<String> {
984 self.creation_date_impl()
985 }
986
987 #[inline]
988 fn set_creation_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError> {
989 self.set_creation_date_impl(date)
990 }
991
992 #[inline]
993 fn modification_date(&self) -> Option<String> {
994 self.modification_date_impl()
995 }
996
997 #[inline]
998 fn set_modification_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError> {
999 self.set_modification_date_impl(date)
1000 }
1001
1002 #[inline]
1003 fn fill_color(&self) -> Result<PdfColor, PdfiumError> {
1004 self.fill_color_impl()
1005 }
1006
1007 #[inline]
1008 fn set_fill_color(&mut self, fill_color: PdfColor) -> Result<(), PdfiumError> {
1009 self.set_fill_color_impl(fill_color)
1010 }
1011
1012 #[inline]
1013 fn stroke_color(&self) -> Result<PdfColor, PdfiumError> {
1014 self.stroke_color_impl()
1015 }
1016
1017 #[inline]
1018 fn set_stroke_color(&mut self, stroke_color: PdfColor) -> Result<(), PdfiumError> {
1019 self.set_stroke_color_impl(stroke_color)
1020 }
1021
1022 #[inline]
1023 fn objects(&self) -> &PdfPageAnnotationObjects<'_> {
1024 self.objects_impl()
1025 }
1026
1027 #[inline]
1028 fn attachment_points(&self) -> &PdfPageAnnotationAttachmentPoints<'_> {
1029 self.attachment_points_impl()
1030 }
1031
1032 #[inline]
1033 fn is_invisible_if_unsupported(&self) -> bool {
1034 self.get_flags_impl().contains(PdfAnnotationFlags::Invisible)
1035 }
1036
1037 #[inline]
1038 fn set_is_invisible_if_unsupported(&mut self, is_invisible: bool) -> Result<(), PdfiumError> {
1039 self.update_one_flag_impl(PdfAnnotationFlags::Invisible, is_invisible)
1040 }
1041
1042 #[inline]
1043 fn is_hidden(&self) -> bool {
1044 self.get_flags_impl().contains(PdfAnnotationFlags::Hidden)
1045 }
1046
1047 #[inline]
1048 fn set_is_hidden(&mut self, is_hidden: bool) -> Result<(), PdfiumError> {
1049 self.update_one_flag_impl(PdfAnnotationFlags::Hidden, is_hidden)
1050 }
1051
1052 #[inline]
1053 fn is_printed(&self) -> bool {
1054 self.get_flags_impl().contains(PdfAnnotationFlags::Print)
1055 }
1056
1057 #[inline]
1058 fn set_is_printed(&mut self, is_printed: bool) -> Result<(), PdfiumError> {
1059 self.update_one_flag_impl(PdfAnnotationFlags::Print, is_printed)
1060 }
1061
1062 #[inline]
1063 fn is_zoomable(&self) -> bool {
1064 !self.get_flags_impl().contains(PdfAnnotationFlags::NoZoom)
1065 }
1066
1067 #[inline]
1068 fn set_is_zoomable(&mut self, is_zoomable: bool) -> Result<(), PdfiumError> {
1069 self.update_one_flag_impl(PdfAnnotationFlags::NoZoom, !is_zoomable)
1070 }
1071
1072 #[inline]
1073 fn is_rotatable(&self) -> bool {
1074 !self.get_flags_impl().contains(PdfAnnotationFlags::NoRotate)
1075 }
1076
1077 #[inline]
1078 fn set_is_rotatable(&mut self, is_rotatable: bool) -> Result<(), PdfiumError> {
1079 self.update_one_flag_impl(PdfAnnotationFlags::NoRotate, !is_rotatable)
1080 }
1081
1082 #[inline]
1083 fn is_printable_but_not_viewable(&self) -> bool {
1084 self.get_flags_impl().contains(PdfAnnotationFlags::NoView)
1085 }
1086
1087 #[inline]
1088 fn set_is_printable_but_not_viewable(&mut self, is_printable_but_not_viewable: bool) -> Result<(), PdfiumError> {
1089 self.update_one_flag_impl(PdfAnnotationFlags::NoView, is_printable_but_not_viewable)
1090 }
1091
1092 #[inline]
1093 fn is_read_only(&self) -> bool {
1094 self.get_flags_impl().contains(PdfAnnotationFlags::ReadOnly)
1095 }
1096
1097 #[inline]
1098 fn set_is_read_only(&mut self, is_read_only: bool) -> Result<(), PdfiumError> {
1099 self.update_one_flag_impl(PdfAnnotationFlags::ReadOnly, is_read_only)
1100 }
1101
1102 #[inline]
1103 fn is_locked(&self) -> bool {
1104 self.get_flags_impl().contains(PdfAnnotationFlags::Locked)
1105 }
1106
1107 #[inline]
1108 fn set_is_locked(&mut self, is_locked: bool) -> Result<(), PdfiumError> {
1109 self.update_one_flag_impl(PdfAnnotationFlags::Locked, is_locked)
1110 }
1111
1112 #[inline]
1113 fn is_editable(&self) -> bool {
1114 !self.get_flags_impl().contains(PdfAnnotationFlags::LockedContents)
1115 }
1116
1117 #[inline]
1118 fn set_is_editable(&mut self, is_editable: bool) -> Result<(), PdfiumError> {
1119 self.update_one_flag_impl(PdfAnnotationFlags::LockedContents, !is_editable)
1120 }
1121}
1122
1123impl<'a> PdfPageAnnotationPrivate<'a> for PdfPageAnnotation<'a> {
1124 #[inline]
1125 fn handle(&self) -> FPDF_ANNOTATION {
1126 self.unwrap_as_trait().handle()
1127 }
1128
1129 #[inline]
1130 fn bindings(&self) -> &dyn PdfiumLibraryBindings {
1131 self.unwrap_as_trait().bindings()
1132 }
1133
1134 #[inline]
1135 fn ownership(&self) -> &PdfPageObjectOwnership {
1136 self.unwrap_as_trait().ownership()
1137 }
1138
1139 #[inline]
1140 fn objects_impl(&self) -> &PdfPageAnnotationObjects<'_> {
1141 self.unwrap_as_trait().objects_impl()
1142 }
1143
1144 #[inline]
1145 fn attachment_points_impl(&self) -> &PdfPageAnnotationAttachmentPoints<'_> {
1146 self.unwrap_as_trait().attachment_points_impl()
1147 }
1148}
1149
1150impl<'a> Drop for PdfPageAnnotation<'a> {
1151 #[inline]
1153 fn drop(&mut self) {
1154 self.bindings().FPDFPage_CloseAnnot(self.handle());
1155 }
1156}