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::points::PdfPoints;
57use crate::pdf::rect::PdfRect;
58use chrono::prelude::*;
59
60#[cfg(doc)]
61use crate::pdf::document::page::PdfPage;
62
63#[derive(Debug, Copy, Clone, PartialOrd, PartialEq)]
92pub enum PdfPageAnnotationType {
93 Unknown = FPDF_ANNOT_UNKNOWN as isize,
94 Text = FPDF_ANNOT_TEXT as isize,
95 Link = FPDF_ANNOT_LINK as isize,
96 FreeText = FPDF_ANNOT_FREETEXT as isize,
97 Line = FPDF_ANNOT_LINE as isize,
98 Square = FPDF_ANNOT_SQUARE as isize,
99 Circle = FPDF_ANNOT_CIRCLE as isize,
100 Polygon = FPDF_ANNOT_POLYGON as isize,
101 Polyline = FPDF_ANNOT_POLYLINE as isize,
102 Highlight = FPDF_ANNOT_HIGHLIGHT as isize,
103 Underline = FPDF_ANNOT_UNDERLINE as isize,
104 Squiggly = FPDF_ANNOT_SQUIGGLY as isize,
105 Strikeout = FPDF_ANNOT_STRIKEOUT as isize,
106 Stamp = FPDF_ANNOT_STAMP as isize,
107 Caret = FPDF_ANNOT_CARET as isize,
108 Ink = FPDF_ANNOT_INK as isize,
109 Popup = FPDF_ANNOT_POPUP as isize,
110 FileAttachment = FPDF_ANNOT_FILEATTACHMENT as isize,
111 Sound = FPDF_ANNOT_SOUND as isize,
112 Movie = FPDF_ANNOT_MOVIE as isize,
113 Widget = FPDF_ANNOT_WIDGET as isize,
114 Screen = FPDF_ANNOT_SCREEN as isize,
115 PrinterMark = FPDF_ANNOT_PRINTERMARK as isize,
116 TrapNet = FPDF_ANNOT_TRAPNET as isize,
117 Watermark = FPDF_ANNOT_WATERMARK as isize,
118 ThreeD = FPDF_ANNOT_THREED as isize,
119 RichMedia = FPDF_ANNOT_RICHMEDIA as isize,
120 XfaWidget = FPDF_ANNOT_XFAWIDGET as isize,
121 Redacted = FPDF_ANNOT_REDACT as isize,
122}
123
124impl PdfPageAnnotationType {
125 pub(crate) fn from_pdfium(
126 value: FPDF_ANNOTATION_SUBTYPE,
127 ) -> Result<PdfPageAnnotationType, PdfiumError> {
128 match value as u32 {
129 FPDF_ANNOT_UNKNOWN => Ok(PdfPageAnnotationType::Unknown),
130 FPDF_ANNOT_TEXT => Ok(PdfPageAnnotationType::Text),
131 FPDF_ANNOT_LINK => Ok(PdfPageAnnotationType::Link),
132 FPDF_ANNOT_FREETEXT => Ok(PdfPageAnnotationType::FreeText),
133 FPDF_ANNOT_LINE => Ok(PdfPageAnnotationType::Line),
134 FPDF_ANNOT_SQUARE => Ok(PdfPageAnnotationType::Square),
135 FPDF_ANNOT_CIRCLE => Ok(PdfPageAnnotationType::Circle),
136 FPDF_ANNOT_POLYGON => Ok(PdfPageAnnotationType::Polygon),
137 FPDF_ANNOT_POLYLINE => Ok(PdfPageAnnotationType::Polyline),
138 FPDF_ANNOT_HIGHLIGHT => Ok(PdfPageAnnotationType::Highlight),
139 FPDF_ANNOT_UNDERLINE => Ok(PdfPageAnnotationType::Underline),
140 FPDF_ANNOT_SQUIGGLY => Ok(PdfPageAnnotationType::Squiggly),
141 FPDF_ANNOT_STRIKEOUT => Ok(PdfPageAnnotationType::Strikeout),
142 FPDF_ANNOT_STAMP => Ok(PdfPageAnnotationType::Stamp),
143 FPDF_ANNOT_CARET => Ok(PdfPageAnnotationType::Caret),
144 FPDF_ANNOT_INK => Ok(PdfPageAnnotationType::Ink),
145 FPDF_ANNOT_POPUP => Ok(PdfPageAnnotationType::Popup),
146 FPDF_ANNOT_FILEATTACHMENT => Ok(PdfPageAnnotationType::FileAttachment),
147 FPDF_ANNOT_SOUND => Ok(PdfPageAnnotationType::Sound),
148 FPDF_ANNOT_MOVIE => Ok(PdfPageAnnotationType::Movie),
149 FPDF_ANNOT_WIDGET => Ok(PdfPageAnnotationType::Widget),
150 FPDF_ANNOT_SCREEN => Ok(PdfPageAnnotationType::Screen),
151 FPDF_ANNOT_PRINTERMARK => Ok(PdfPageAnnotationType::PrinterMark),
152 FPDF_ANNOT_TRAPNET => Ok(PdfPageAnnotationType::TrapNet),
153 FPDF_ANNOT_WATERMARK => Ok(PdfPageAnnotationType::Watermark),
154 FPDF_ANNOT_THREED => Ok(PdfPageAnnotationType::ThreeD),
155 FPDF_ANNOT_RICHMEDIA => Ok(PdfPageAnnotationType::RichMedia),
156 FPDF_ANNOT_XFAWIDGET => Ok(PdfPageAnnotationType::XfaWidget),
157 FPDF_ANNOT_REDACT => Ok(PdfPageAnnotationType::Redacted),
158 _ => Err(PdfiumError::UnknownPdfAnnotationType),
159 }
160 }
161
162 #[allow(dead_code)]
163 pub(crate) fn as_pdfium(&self) -> FPDF_ANNOTATION_SUBTYPE {
165 (match self {
166 PdfPageAnnotationType::Unknown => FPDF_ANNOT_UNKNOWN,
167 PdfPageAnnotationType::Text => FPDF_ANNOT_TEXT,
168 PdfPageAnnotationType::Link => FPDF_ANNOT_LINK,
169 PdfPageAnnotationType::FreeText => FPDF_ANNOT_FREETEXT,
170 PdfPageAnnotationType::Line => FPDF_ANNOT_LINE,
171 PdfPageAnnotationType::Square => FPDF_ANNOT_SQUARE,
172 PdfPageAnnotationType::Circle => FPDF_ANNOT_CIRCLE,
173 PdfPageAnnotationType::Polygon => FPDF_ANNOT_POLYGON,
174 PdfPageAnnotationType::Polyline => FPDF_ANNOT_POLYLINE,
175 PdfPageAnnotationType::Highlight => FPDF_ANNOT_HIGHLIGHT,
176 PdfPageAnnotationType::Underline => FPDF_ANNOT_UNDERLINE,
177 PdfPageAnnotationType::Squiggly => FPDF_ANNOT_SQUIGGLY,
178 PdfPageAnnotationType::Strikeout => FPDF_ANNOT_STRIKEOUT,
179 PdfPageAnnotationType::Stamp => FPDF_ANNOT_STAMP,
180 PdfPageAnnotationType::Caret => FPDF_ANNOT_CARET,
181 PdfPageAnnotationType::Ink => FPDF_ANNOT_INK,
182 PdfPageAnnotationType::Popup => FPDF_ANNOT_POPUP,
183 PdfPageAnnotationType::FileAttachment => FPDF_ANNOT_FILEATTACHMENT,
184 PdfPageAnnotationType::Sound => FPDF_ANNOT_SOUND,
185 PdfPageAnnotationType::Movie => FPDF_ANNOT_MOVIE,
186 PdfPageAnnotationType::Widget => FPDF_ANNOT_WIDGET,
187 PdfPageAnnotationType::Screen => FPDF_ANNOT_SCREEN,
188 PdfPageAnnotationType::PrinterMark => FPDF_ANNOT_PRINTERMARK,
189 PdfPageAnnotationType::TrapNet => FPDF_ANNOT_TRAPNET,
190 PdfPageAnnotationType::Watermark => FPDF_ANNOT_WATERMARK,
191 PdfPageAnnotationType::ThreeD => FPDF_ANNOT_THREED,
192 PdfPageAnnotationType::RichMedia => FPDF_ANNOT_RICHMEDIA,
193 PdfPageAnnotationType::XfaWidget => FPDF_ANNOT_XFAWIDGET,
194 PdfPageAnnotationType::Redacted => FPDF_ANNOT_REDACT,
195 }) as FPDF_ANNOTATION_SUBTYPE
196 }
197}
198
199pub enum PdfPageAnnotation<'a> {
201 Circle(PdfPageCircleAnnotation<'a>),
202 FreeText(PdfPageFreeTextAnnotation<'a>),
203 Highlight(PdfPageHighlightAnnotation<'a>),
204 Ink(PdfPageInkAnnotation<'a>),
205 Link(PdfPageLinkAnnotation<'a>),
206 Popup(PdfPagePopupAnnotation<'a>),
207 Square(PdfPageSquareAnnotation<'a>),
208 Squiggly(PdfPageSquigglyAnnotation<'a>),
209 Stamp(PdfPageStampAnnotation<'a>),
210 Strikeout(PdfPageStrikeoutAnnotation<'a>),
211 Text(PdfPageTextAnnotation<'a>),
212 Underline(PdfPageUnderlineAnnotation<'a>),
213 Widget(PdfPageWidgetAnnotation<'a>),
214 XfaWidget(PdfPageXfaWidgetAnnotation<'a>),
215 Redacted(PdfPageRedactedAnnotation<'a>),
216
217 Unsupported(PdfPageUnsupportedAnnotation<'a>),
221}
222
223impl<'a> PdfPageAnnotation<'a> {
224 pub(crate) fn from_pdfium(
225 document_handle: FPDF_DOCUMENT,
226 page_handle: FPDF_PAGE,
227 annotation_handle: FPDF_ANNOTATION,
228 form_handle: Option<FPDF_FORMHANDLE>,
229 bindings: &'a dyn PdfiumLibraryBindings,
230 ) -> Self {
231 let annotation_type =
232 PdfPageAnnotationType::from_pdfium(bindings.FPDFAnnot_GetSubtype(annotation_handle))
233 .unwrap_or(PdfPageAnnotationType::Unknown);
234
235 match annotation_type {
236 PdfPageAnnotationType::Circle => {
237 PdfPageAnnotation::Circle(PdfPageCircleAnnotation::from_pdfium(
238 document_handle,
239 page_handle,
240 annotation_handle,
241 bindings,
242 ))
243 }
244 PdfPageAnnotationType::FreeText => {
245 PdfPageAnnotation::FreeText(PdfPageFreeTextAnnotation::from_pdfium(
246 document_handle,
247 page_handle,
248 annotation_handle,
249 bindings,
250 ))
251 }
252 PdfPageAnnotationType::Highlight => {
253 PdfPageAnnotation::Highlight(PdfPageHighlightAnnotation::from_pdfium(
254 document_handle,
255 page_handle,
256 annotation_handle,
257 bindings,
258 ))
259 }
260 PdfPageAnnotationType::Ink => {
261 PdfPageAnnotation::Ink(PdfPageInkAnnotation::from_pdfium(
262 document_handle,
263 page_handle,
264 annotation_handle,
265 bindings,
266 ))
267 }
268 PdfPageAnnotationType::Link => {
269 PdfPageAnnotation::Link(PdfPageLinkAnnotation::from_pdfium(
270 document_handle,
271 page_handle,
272 annotation_handle,
273 bindings,
274 ))
275 }
276 PdfPageAnnotationType::Popup => {
277 PdfPageAnnotation::Popup(PdfPagePopupAnnotation::from_pdfium(
278 document_handle,
279 page_handle,
280 annotation_handle,
281 bindings,
282 ))
283 }
284 PdfPageAnnotationType::Square => {
285 PdfPageAnnotation::Square(PdfPageSquareAnnotation::from_pdfium(
286 document_handle,
287 page_handle,
288 annotation_handle,
289 bindings,
290 ))
291 }
292 PdfPageAnnotationType::Squiggly => {
293 PdfPageAnnotation::Squiggly(PdfPageSquigglyAnnotation::from_pdfium(
294 document_handle,
295 page_handle,
296 annotation_handle,
297 bindings,
298 ))
299 }
300 PdfPageAnnotationType::Stamp => {
301 PdfPageAnnotation::Stamp(PdfPageStampAnnotation::from_pdfium(
302 document_handle,
303 page_handle,
304 annotation_handle,
305 bindings,
306 ))
307 }
308 PdfPageAnnotationType::Strikeout => {
309 PdfPageAnnotation::Strikeout(PdfPageStrikeoutAnnotation::from_pdfium(
310 document_handle,
311 page_handle,
312 annotation_handle,
313 bindings,
314 ))
315 }
316 PdfPageAnnotationType::Text => {
317 PdfPageAnnotation::Text(PdfPageTextAnnotation::from_pdfium(
318 document_handle,
319 page_handle,
320 annotation_handle,
321 bindings,
322 ))
323 }
324 PdfPageAnnotationType::Underline => {
325 PdfPageAnnotation::Underline(PdfPageUnderlineAnnotation::from_pdfium(
326 document_handle,
327 page_handle,
328 annotation_handle,
329 bindings,
330 ))
331 }
332 PdfPageAnnotationType::Widget => {
333 PdfPageAnnotation::Widget(PdfPageWidgetAnnotation::from_pdfium(
334 document_handle,
335 page_handle,
336 annotation_handle,
337 form_handle,
338 bindings,
339 ))
340 }
341 PdfPageAnnotationType::XfaWidget => {
342 PdfPageAnnotation::XfaWidget(PdfPageXfaWidgetAnnotation::from_pdfium(
343 document_handle,
344 page_handle,
345 annotation_handle,
346 form_handle,
347 bindings,
348 ))
349 }
350 PdfPageAnnotationType::Redacted => {
351 PdfPageAnnotation::Redacted(PdfPageRedactedAnnotation::from_pdfium(
352 document_handle,
353 page_handle,
354 annotation_handle,
355 bindings,
356 ))
357 }
358 _ => PdfPageAnnotation::Unsupported(PdfPageUnsupportedAnnotation::from_pdfium(
359 document_handle,
360 page_handle,
361 annotation_handle,
362 annotation_type,
363 bindings,
364 )),
365 }
366 }
367
368 #[inline]
369 pub(crate) fn unwrap_as_trait(&self) -> &dyn PdfPageAnnotationPrivate<'a> {
370 match self {
371 PdfPageAnnotation::Circle(annotation) => annotation,
372 PdfPageAnnotation::FreeText(annotation) => annotation,
373 PdfPageAnnotation::Highlight(annotation) => annotation,
374 PdfPageAnnotation::Ink(annotation) => annotation,
375 PdfPageAnnotation::Link(annotation) => annotation,
376 PdfPageAnnotation::Popup(annotation) => annotation,
377 PdfPageAnnotation::Square(annotation) => annotation,
378 PdfPageAnnotation::Squiggly(annotation) => annotation,
379 PdfPageAnnotation::Stamp(annotation) => annotation,
380 PdfPageAnnotation::Strikeout(annotation) => annotation,
381 PdfPageAnnotation::Text(annotation) => annotation,
382 PdfPageAnnotation::Underline(annotation) => annotation,
383 PdfPageAnnotation::Widget(annotation) => annotation,
384 PdfPageAnnotation::XfaWidget(annotation) => annotation,
385 PdfPageAnnotation::Redacted(annotation) => annotation,
386 PdfPageAnnotation::Unsupported(annotation) => annotation,
387 }
388 }
389
390 #[inline]
391 pub(crate) fn unwrap_as_trait_mut(&mut self) -> &mut dyn PdfPageAnnotationPrivate<'a> {
392 match self {
393 PdfPageAnnotation::Circle(annotation) => annotation,
394 PdfPageAnnotation::FreeText(annotation) => annotation,
395 PdfPageAnnotation::Highlight(annotation) => annotation,
396 PdfPageAnnotation::Ink(annotation) => annotation,
397 PdfPageAnnotation::Link(annotation) => annotation,
398 PdfPageAnnotation::Popup(annotation) => annotation,
399 PdfPageAnnotation::Square(annotation) => annotation,
400 PdfPageAnnotation::Squiggly(annotation) => annotation,
401 PdfPageAnnotation::Stamp(annotation) => annotation,
402 PdfPageAnnotation::Strikeout(annotation) => annotation,
403 PdfPageAnnotation::Text(annotation) => annotation,
404 PdfPageAnnotation::Underline(annotation) => annotation,
405 PdfPageAnnotation::Widget(annotation) => annotation,
406 PdfPageAnnotation::XfaWidget(annotation) => annotation,
407 PdfPageAnnotation::Redacted(annotation) => annotation,
408 PdfPageAnnotation::Unsupported(annotation) => annotation,
409 }
410 }
411
412 #[inline]
436 pub fn annotation_type(&self) -> PdfPageAnnotationType {
437 match self {
438 PdfPageAnnotation::Circle(_) => PdfPageAnnotationType::Circle,
439 PdfPageAnnotation::FreeText(_) => PdfPageAnnotationType::FreeText,
440 PdfPageAnnotation::Highlight(_) => PdfPageAnnotationType::Highlight,
441 PdfPageAnnotation::Ink(_) => PdfPageAnnotationType::Ink,
442 PdfPageAnnotation::Link(_) => PdfPageAnnotationType::Link,
443 PdfPageAnnotation::Popup(_) => PdfPageAnnotationType::Popup,
444 PdfPageAnnotation::Square(_) => PdfPageAnnotationType::Square,
445 PdfPageAnnotation::Squiggly(_) => PdfPageAnnotationType::Squiggly,
446 PdfPageAnnotation::Stamp(_) => PdfPageAnnotationType::Stamp,
447 PdfPageAnnotation::Strikeout(_) => PdfPageAnnotationType::Strikeout,
448 PdfPageAnnotation::Text(_) => PdfPageAnnotationType::Text,
449 PdfPageAnnotation::Underline(_) => PdfPageAnnotationType::Underline,
450 PdfPageAnnotation::Widget(_) => PdfPageAnnotationType::Widget,
451 PdfPageAnnotation::XfaWidget(_) => PdfPageAnnotationType::XfaWidget,
452 PdfPageAnnotation::Redacted(_) => PdfPageAnnotationType::Redacted,
453 PdfPageAnnotation::Unsupported(annotation) => annotation.get_type(),
454 }
455 }
456
457 #[inline]
482 pub fn is_supported(&self) -> bool {
483 !self.is_unsupported()
484 }
485
486 #[inline]
511 pub fn is_unsupported(&self) -> bool {
512 matches!(self, PdfPageAnnotation::Unsupported(_))
513 }
514
515 #[inline]
519 pub fn as_circle_annotation(&self) -> Option<&PdfPageCircleAnnotation> {
520 match self {
521 PdfPageAnnotation::Circle(annotation) => Some(annotation),
522 _ => None,
523 }
524 }
525
526 #[inline]
530 pub fn as_circle_annotation_mut(&mut self) -> Option<&mut PdfPageCircleAnnotation<'a>> {
531 match self {
532 PdfPageAnnotation::Circle(annotation) => Some(annotation),
533 _ => None,
534 }
535 }
536
537 #[inline]
541 pub fn as_free_text_annotation(&self) -> Option<&PdfPageFreeTextAnnotation> {
542 match self {
543 PdfPageAnnotation::FreeText(annotation) => Some(annotation),
544 _ => None,
545 }
546 }
547
548 #[inline]
552 pub fn as_free_text_annotation_mut(&mut self) -> Option<&mut PdfPageFreeTextAnnotation<'a>> {
553 match self {
554 PdfPageAnnotation::FreeText(annotation) => Some(annotation),
555 _ => None,
556 }
557 }
558
559 #[inline]
563 pub fn as_highlight_annotation(&self) -> Option<&PdfPageHighlightAnnotation> {
564 match self {
565 PdfPageAnnotation::Highlight(annotation) => Some(annotation),
566 _ => None,
567 }
568 }
569
570 #[inline]
574 pub fn as_highlight_annotation_mut(&mut self) -> Option<&mut PdfPageHighlightAnnotation<'a>> {
575 match self {
576 PdfPageAnnotation::Highlight(annotation) => Some(annotation),
577 _ => None,
578 }
579 }
580
581 #[inline]
585 pub fn as_ink_annotation(&self) -> Option<&PdfPageInkAnnotation> {
586 match self {
587 PdfPageAnnotation::Ink(annotation) => Some(annotation),
588 _ => None,
589 }
590 }
591
592 #[inline]
596 pub fn as_ink_annotation_mut(&mut self) -> Option<&mut PdfPageInkAnnotation<'a>> {
597 match self {
598 PdfPageAnnotation::Ink(annotation) => Some(annotation),
599 _ => None,
600 }
601 }
602
603 #[inline]
607 pub fn as_link_annotation(&self) -> Option<&PdfPageLinkAnnotation> {
608 match self {
609 PdfPageAnnotation::Link(annotation) => Some(annotation),
610 _ => None,
611 }
612 }
613
614 #[inline]
618 pub fn as_link_annotation_mut(&mut self) -> Option<&mut PdfPageLinkAnnotation<'a>> {
619 match self {
620 PdfPageAnnotation::Link(annotation) => Some(annotation),
621 _ => None,
622 }
623 }
624
625 #[inline]
629 pub fn as_popup_annotation(&self) -> Option<&PdfPagePopupAnnotation> {
630 match self {
631 PdfPageAnnotation::Popup(annotation) => Some(annotation),
632 _ => None,
633 }
634 }
635
636 #[inline]
640 pub fn as_popup_annotation_mut(&mut self) -> Option<&mut PdfPagePopupAnnotation<'a>> {
641 match self {
642 PdfPageAnnotation::Popup(annotation) => Some(annotation),
643 _ => None,
644 }
645 }
646
647 #[inline]
651 pub fn as_square_annotation(&self) -> Option<&PdfPageSquareAnnotation> {
652 match self {
653 PdfPageAnnotation::Square(annotation) => Some(annotation),
654 _ => None,
655 }
656 }
657
658 #[inline]
662 pub fn as_square_annotation_mut(&mut self) -> Option<&mut PdfPageSquareAnnotation<'a>> {
663 match self {
664 PdfPageAnnotation::Square(annotation) => Some(annotation),
665 _ => None,
666 }
667 }
668
669 #[inline]
673 pub fn as_squiggly_annotation(&self) -> Option<&PdfPageSquigglyAnnotation> {
674 match self {
675 PdfPageAnnotation::Squiggly(annotation) => Some(annotation),
676 _ => None,
677 }
678 }
679
680 #[inline]
684 pub fn as_squiggly_annotation_mut(&mut self) -> Option<&mut PdfPageSquigglyAnnotation<'a>> {
685 match self {
686 PdfPageAnnotation::Squiggly(annotation) => Some(annotation),
687 _ => None,
688 }
689 }
690
691 #[inline]
695 pub fn as_stamp_annotation(&self) -> Option<&PdfPageStampAnnotation> {
696 match self {
697 PdfPageAnnotation::Stamp(annotation) => Some(annotation),
698 _ => None,
699 }
700 }
701
702 #[inline]
706 pub fn as_stamp_annotation_mut(&mut self) -> Option<&mut PdfPageStampAnnotation<'a>> {
707 match self {
708 PdfPageAnnotation::Stamp(annotation) => Some(annotation),
709 _ => None,
710 }
711 }
712
713 #[inline]
717 pub fn as_strikeout_annotation(&self) -> Option<&PdfPageStrikeoutAnnotation> {
718 match self {
719 PdfPageAnnotation::Strikeout(annotation) => Some(annotation),
720 _ => None,
721 }
722 }
723
724 #[inline]
728 pub fn as_strikeout_annotation_mut(&mut self) -> Option<&mut PdfPageStrikeoutAnnotation<'a>> {
729 match self {
730 PdfPageAnnotation::Strikeout(annotation) => Some(annotation),
731 _ => None,
732 }
733 }
734
735 #[inline]
739 pub fn as_text_annotation(&self) -> Option<&PdfPageTextAnnotation> {
740 match self {
741 PdfPageAnnotation::Text(annotation) => Some(annotation),
742 _ => None,
743 }
744 }
745
746 #[inline]
750 pub fn as_text_annotation_mut(&mut self) -> Option<&mut PdfPageTextAnnotation<'a>> {
751 match self {
752 PdfPageAnnotation::Text(annotation) => Some(annotation),
753 _ => None,
754 }
755 }
756
757 #[inline]
761 pub fn as_underline_annotation(&self) -> Option<&PdfPageUnderlineAnnotation> {
762 match self {
763 PdfPageAnnotation::Underline(annotation) => Some(annotation),
764 _ => None,
765 }
766 }
767
768 #[inline]
772 pub fn as_underline_annotation_mut(&mut self) -> Option<&mut PdfPageUnderlineAnnotation<'a>> {
773 match self {
774 PdfPageAnnotation::Underline(annotation) => Some(annotation),
775 _ => None,
776 }
777 }
778
779 #[inline]
783 pub fn as_widget_annotation(&self) -> Option<&PdfPageWidgetAnnotation> {
784 match self {
785 PdfPageAnnotation::Widget(annotation) => Some(annotation),
786 _ => None,
787 }
788 }
789
790 #[inline]
794 pub fn as_widget_annotation_mut(&mut self) -> Option<&mut PdfPageWidgetAnnotation<'a>> {
795 match self {
796 PdfPageAnnotation::Widget(annotation) => Some(annotation),
797 _ => None,
798 }
799 }
800
801 #[inline]
805 pub fn as_xfa_widget_annotation(&self) -> Option<&PdfPageXfaWidgetAnnotation> {
806 match self {
807 PdfPageAnnotation::XfaWidget(annotation) => Some(annotation),
808 _ => None,
809 }
810 }
811
812 #[inline]
816 pub fn as_xfa_widget_annotation_mut(&mut self) -> Option<&mut PdfPageXfaWidgetAnnotation<'a>> {
817 match self {
818 PdfPageAnnotation::XfaWidget(annotation) => Some(annotation),
819 _ => None,
820 }
821 }
822
823 #[inline]
827 pub fn as_redacted_annotation(&self) -> Option<&PdfPageRedactedAnnotation> {
828 match self {
829 PdfPageAnnotation::Redacted(annotation) => Some(annotation),
830 _ => None,
831 }
832 }
833
834 #[inline]
838 pub fn as_redacted_annotation_mut(&mut self) -> Option<&mut PdfPageRedactedAnnotation<'a>> {
839 match self {
840 PdfPageAnnotation::Redacted(annotation) => Some(annotation),
841 _ => None,
842 }
843 }
844
845 #[inline]
851 pub fn as_form_field(&self) -> Option<&PdfFormField> {
852 match self {
853 PdfPageAnnotation::Widget(annotation) => annotation.form_field(),
854 PdfPageAnnotation::XfaWidget(annotation) => annotation.form_field(),
855 _ => None,
856 }
857 }
858
859 #[inline]
865 pub fn as_form_field_mut(&mut self) -> Option<&mut PdfFormField<'a>> {
866 match self {
867 PdfPageAnnotation::Widget(annotation) => annotation.form_field_mut(),
868 PdfPageAnnotation::XfaWidget(annotation) => annotation.form_field_mut(),
869 _ => None,
870 }
871 }
872}
873
874pub trait PdfPageAnnotationCommon {
876 fn name(&self) -> Option<String>;
879
880 fn is_markup_annotation(&self) -> bool;
884
885 fn has_attachment_points(&self) -> bool;
888
889 fn bounds(&self) -> Result<PdfRect, PdfiumError>;
891
892 fn set_bounds(&mut self, bounds: PdfRect) -> Result<(), PdfiumError>;
898
899 fn set_position(&mut self, x: PdfPoints, y: PdfPoints) -> Result<(), PdfiumError>;
904
905 fn set_width(&mut self, width: PdfPoints) -> Result<(), PdfiumError>;
910
911 fn set_height(&mut self, width: PdfPoints) -> Result<(), PdfiumError>;
916
917 fn contents(&self) -> Option<String>;
922
923 fn set_contents(&mut self, contents: &str) -> Result<(), PdfiumError>;
927
928 fn creator(&self) -> Option<String>;
930
931 fn creation_date(&self) -> Option<String>;
933
934 fn set_creation_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError>;
936
937 fn modification_date(&self) -> Option<String>;
939
940 fn set_modification_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError>;
942
943 fn fill_color(&self) -> Result<PdfColor, PdfiumError>;
945
946 fn set_fill_color(&mut self, fill_color: PdfColor) -> Result<(), PdfiumError>;
948
949 fn stroke_color(&self) -> Result<PdfColor, PdfiumError>;
951
952 fn set_stroke_color(&mut self, stroke_color: PdfColor) -> Result<(), PdfiumError>;
954
955 fn objects(&self) -> &PdfPageAnnotationObjects;
968
969 fn attachment_points(&self) -> &PdfPageAnnotationAttachmentPoints;
984}
985
986impl<'a, T> PdfPageAnnotationCommon for T
989where
990 T: PdfPageAnnotationPrivate<'a>,
991{
992 #[inline]
993 fn name(&self) -> Option<String> {
994 self.name_impl()
995 }
996
997 #[inline]
998 fn is_markup_annotation(&self) -> bool {
999 self.is_markup_annotation_impl()
1000 }
1001
1002 #[inline]
1003 fn has_attachment_points(&self) -> bool {
1004 self.has_attachment_points_impl()
1005 }
1006
1007 #[inline]
1008 fn bounds(&self) -> Result<PdfRect, PdfiumError> {
1009 self.bounds_impl()
1010 }
1011
1012 #[inline]
1013 fn set_bounds(&mut self, bounds: PdfRect) -> Result<(), PdfiumError> {
1014 self.set_bounds_impl(bounds)
1015 }
1016
1017 #[inline]
1018 fn set_position(&mut self, x: PdfPoints, y: PdfPoints) -> Result<(), PdfiumError> {
1019 self.set_position_impl(x, y)
1020 }
1021
1022 #[inline]
1023 fn set_width(&mut self, width: PdfPoints) -> Result<(), PdfiumError> {
1024 self.set_width_impl(width)
1025 }
1026
1027 #[inline]
1028 fn set_height(&mut self, height: PdfPoints) -> Result<(), PdfiumError> {
1029 self.set_height_impl(height)
1030 }
1031
1032 #[inline]
1033 fn contents(&self) -> Option<String> {
1034 self.contents_impl()
1035 }
1036
1037 #[inline]
1038 fn set_contents(&mut self, contents: &str) -> Result<(), PdfiumError> {
1039 self.set_contents_impl(contents)
1040 }
1041
1042 #[inline]
1043 fn creator(&self) -> Option<String> {
1044 self.creator_impl()
1045 }
1046
1047 #[inline]
1048 fn creation_date(&self) -> Option<String> {
1049 self.creation_date_impl()
1050 }
1051
1052 #[inline]
1053 fn set_creation_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError> {
1054 self.set_creation_date_impl(date)
1055 }
1056
1057 #[inline]
1058 fn modification_date(&self) -> Option<String> {
1059 self.modification_date_impl()
1060 }
1061
1062 #[inline]
1063 fn set_modification_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError> {
1064 self.set_modification_date_impl(date)
1065 }
1066
1067 #[inline]
1068 fn fill_color(&self) -> Result<PdfColor, PdfiumError> {
1069 self.fill_color_impl()
1070 }
1071
1072 #[inline]
1073 fn set_fill_color(&mut self, fill_color: PdfColor) -> Result<(), PdfiumError> {
1074 self.set_fill_color_impl(fill_color)
1075 }
1076
1077 #[inline]
1078 fn stroke_color(&self) -> Result<PdfColor, PdfiumError> {
1079 self.stroke_color_impl()
1080 }
1081
1082 #[inline]
1083 fn set_stroke_color(&mut self, stroke_color: PdfColor) -> Result<(), PdfiumError> {
1084 self.set_stroke_color_impl(stroke_color)
1085 }
1086
1087 #[inline]
1088 fn objects(&self) -> &PdfPageAnnotationObjects {
1089 self.objects_impl()
1090 }
1091
1092 #[inline]
1093 fn attachment_points(&self) -> &PdfPageAnnotationAttachmentPoints {
1094 self.attachment_points_impl()
1095 }
1096}
1097
1098impl<'a> PdfPageAnnotationPrivate<'a> for PdfPageAnnotation<'a> {
1099 #[inline]
1100 fn handle(&self) -> FPDF_ANNOTATION {
1101 self.unwrap_as_trait().handle()
1102 }
1103
1104 #[inline]
1105 fn bindings(&self) -> &dyn PdfiumLibraryBindings {
1106 self.unwrap_as_trait().bindings()
1107 }
1108
1109 #[inline]
1110 fn objects_impl(&self) -> &PdfPageAnnotationObjects {
1111 self.unwrap_as_trait().objects_impl()
1112 }
1113
1114 #[inline]
1115 fn objects_mut_impl(&mut self) -> &mut PdfPageAnnotationObjects<'a> {
1116 self.unwrap_as_trait_mut().objects_mut_impl()
1117 }
1118
1119 #[inline]
1120 fn attachment_points_impl(&self) -> &PdfPageAnnotationAttachmentPoints {
1121 self.unwrap_as_trait().attachment_points_impl()
1122 }
1123
1124 #[inline]
1125 fn attachment_points_mut_impl(&mut self) -> &mut PdfPageAnnotationAttachmentPoints<'a> {
1126 self.unwrap_as_trait_mut().attachment_points_mut_impl()
1127 }
1128}
1129
1130impl<'a> Drop for PdfPageAnnotation<'a> {
1131 #[inline]
1133 fn drop(&mut self) {
1134 self.bindings().FPDFPage_CloseAnnot(self.handle());
1135 }
1136}