pdfium_render/pdf/document/page/
annotation.rs

1//! Defines the [PdfPageAnnotation] struct, exposing functionality related to a single annotation.
2
3pub 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; // Keep private so that the PdfPageAnnotationPrivate trait is not exposed.
12pub 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/// The type of a single [PdfPageAnnotation], as defined in table 8.20 of the PDF Reference,
64/// version 1.7, on page 615.
65///
66/// Not all PDF annotation types are supported by Pdfium. For example, Pdfium does not
67/// currently support embedded sound or movie file annotations, embedded 3D animations, or
68/// annotations containing embedded file attachments.
69///
70/// Pdfium currently supports creating, editing, and rendering the following types of annotations:
71///
72/// * [PdfPageAnnotationType::Circle]
73/// * [PdfPageAnnotationType::FreeText]
74/// * [PdfPageAnnotationType::Highlight]
75/// * [PdfPageAnnotationType::Ink]
76/// * [PdfPageAnnotationType::Link]
77/// * [PdfPageAnnotationType::Popup]
78/// * [PdfPageAnnotationType::Redacted]
79/// * [PdfPageAnnotationType::Square]
80/// * [PdfPageAnnotationType::Squiggly]
81/// * [PdfPageAnnotationType::Stamp]
82/// * [PdfPageAnnotationType::Strikeout]
83/// * [PdfPageAnnotationType::Text]
84/// * [PdfPageAnnotationType::Underline]
85/// * [PdfPageAnnotationType::Widget]
86/// * [PdfPageAnnotationType::XfaWidget]
87///
88/// Note that a `FreeText` annotation is rendered directly on the page, whereas a `Text` annotation
89/// floats over the page inside its own enclosed area. Adobe often uses the term "sticky note"
90/// in reference to `Text` annotations to distinguish them from `FreeText` annotations.
91#[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    // The as_pdfium() function is not currently used, but we expect it to be in future
164    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
199/// A single user annotation on a [PdfPage].
200pub 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    /// Common properties shared by all [PdfPageAnnotation] types can still be accessed for
218    /// annotations not supported by Pdfium, but annotation-specific functionality
219    /// will be unavailable.
220    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    /// The type of this [PdfPageAnnotation].
413    ///
414    /// Not all PDF annotation types are supported by Pdfium. For example, Pdfium does not
415    /// currently support embedded sound or movie file annotations, embedded 3D animations, or
416    /// annotations containing embedded file attachments.
417    ///
418    /// Pdfium currently supports creating, editing, and rendering the following types of annotations:
419    ///
420    /// * [PdfPageAnnotationType::Circle]
421    /// * [PdfPageAnnotationType::FreeText]
422    /// * [PdfPageAnnotationType::Highlight]
423    /// * [PdfPageAnnotationType::Ink]
424    /// * [PdfPageAnnotationType::Link]
425    /// * [PdfPageAnnotationType::Popup]
426    /// * [PdfPageAnnotationType::Redacted]
427    /// * [PdfPageAnnotationType::Square]
428    /// * [PdfPageAnnotationType::Squiggly]
429    /// * [PdfPageAnnotationType::Stamp]
430    /// * [PdfPageAnnotationType::Strikeout]
431    /// * [PdfPageAnnotationType::Text]
432    /// * [PdfPageAnnotationType::Underline]
433    /// * [PdfPageAnnotationType::Widget]
434    /// * [PdfPageAnnotationType::XfaWidget]
435    #[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    /// Returns `true` if Pdfium supports creating, editing, and rendering this type of
458    /// [PdfPageAnnotation].
459    ///
460    /// Not all PDF annotation types are supported by Pdfium. For example, Pdfium does not
461    /// currently support embedded sound or movie file annotations, embedded 3D animations, or
462    /// annotations containing embedded file attachments.
463    ///
464    /// Pdfium currently supports creating, editing, and rendering the following types of annotations:
465    ///
466    /// * [PdfPageAnnotationType::Circle]
467    /// * [PdfPageAnnotationType::FreeText]
468    /// * [PdfPageAnnotationType::Highlight]
469    /// * [PdfPageAnnotationType::Ink]
470    /// * [PdfPageAnnotationType::Link]
471    /// * [PdfPageAnnotationType::Popup]
472    /// * [PdfPageAnnotationType::Redacted]
473    /// * [PdfPageAnnotationType::Square]
474    /// * [PdfPageAnnotationType::Squiggly]
475    /// * [PdfPageAnnotationType::Stamp]
476    /// * [PdfPageAnnotationType::Strikeout]
477    /// * [PdfPageAnnotationType::Text]
478    /// * [PdfPageAnnotationType::Underline]
479    /// * [PdfPageAnnotationType::Widget]
480    /// * [PdfPageAnnotationType::XfaWidget]
481    #[inline]
482    pub fn is_supported(&self) -> bool {
483        !self.is_unsupported()
484    }
485
486    /// Returns `true` if Pdfium does _not_ support creating, editing, and rendering this type of
487    /// [PdfPageAnnotation].
488    ///
489    /// Not all PDF annotation types are supported by Pdfium. For example, Pdfium does not
490    /// currently support embedded sound or movie file annotations, embedded 3D animations, or
491    /// annotations containing embedded file attachments.
492    ///
493    /// Pdfium currently supports creating, editing, and rendering the following types of annotations:
494    ///
495    /// * [PdfPageAnnotationType::Circle]
496    /// * [PdfPageAnnotationType::FreeText]
497    /// * [PdfPageAnnotationType::Highlight]
498    /// * [PdfPageAnnotationType::Ink]
499    /// * [PdfPageAnnotationType::Link]
500    /// * [PdfPageAnnotationType::Popup]
501    /// * [PdfPageAnnotationType::Redacted]
502    /// * [PdfPageAnnotationType::Square]
503    /// * [PdfPageAnnotationType::Squiggly]
504    /// * [PdfPageAnnotationType::Stamp]
505    /// * [PdfPageAnnotationType::Strikeout]
506    /// * [PdfPageAnnotationType::Text]
507    /// * [PdfPageAnnotationType::Underline]
508    /// * [PdfPageAnnotationType::Widget]
509    /// * [PdfPageAnnotationType::XfaWidget]
510    #[inline]
511    pub fn is_unsupported(&self) -> bool {
512        matches!(self, PdfPageAnnotation::Unsupported(_))
513    }
514
515    /// Returns an immutable reference to the underlying [PdfPageCircleAnnotation]
516    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
517    /// [PdfPageAnnotationType::Circle].
518    #[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    /// Returns a mutable reference to the underlying [PdfPageCircleAnnotation]
527    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
528    /// [PdfPageAnnotationType::Circle].
529    #[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    /// Returns an immutable reference to the underlying [PdfPageFreeTextAnnotation]
538    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
539    /// [PdfPageAnnotationType::FreeText].
540    #[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    /// Returns a mutable reference to the underlying [PdfPageFreeTextAnnotation]
549    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
550    /// [PdfPageAnnotationType::FreeText].
551    #[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    /// Returns an immutable reference to the underlying [PdfPageHighlightAnnotation]
560    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
561    /// [PdfPageAnnotationType::Highlight].
562    #[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    /// Returns a mutable reference to the underlying [PdfPageHighlightAnnotation]
571    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
572    /// [PdfPageAnnotationType::Highlight].
573    #[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    /// Returns an immutable reference to the underlying [PdfPageInkAnnotation]
582    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
583    /// [PdfPageAnnotationType::Ink].
584    #[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    /// Returns a mutable reference to the underlying [PdfPageInkAnnotation]
593    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
594    /// [PdfPageAnnotationType::Ink].
595    #[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    /// Returns an immutable reference to the underlying [PdfPageLinkAnnotation]
604    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
605    /// [PdfPageAnnotationType::Link].
606    #[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    /// Returns a mutable reference to the underlying [PdfPageLinkAnnotation]
615    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
616    /// [PdfPageAnnotationType::Link].
617    #[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    /// Returns an immutable reference to the underlying [PdfPagePopupAnnotation]
626    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
627    /// [PdfPageAnnotationType::Popup].
628    #[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    /// Returns a mutable reference to the underlying [PdfPagePopupAnnotation]
637    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
638    /// [PdfPageAnnotationType::Popup].
639    #[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    /// Returns an immutable reference to the underlying [PdfPageSquareAnnotation]
648    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
649    /// [PdfPageAnnotationType::Square].
650    #[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    /// Returns a mutable reference to the underlying [PdfPageSquareAnnotation]
659    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
660    /// [PdfPageAnnotationType::Square].
661    #[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    /// Returns an immutable reference to the underlying [PdfPageSquigglyAnnotation]
670    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
671    /// [PdfPageAnnotationType::Squiggly].
672    #[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    /// Returns a mutable reference to the underlying [PdfPageSquigglyAnnotation]
681    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
682    /// [PdfPageAnnotationType::Squiggly].
683    #[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    /// Returns an immutable reference to the underlying [PdfPageStampAnnotation]
692    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
693    /// [PdfPageAnnotationType::Stamp].
694    #[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    /// Returns a mutable reference to the underlying [PdfPageStampAnnotation]
703    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
704    /// [PdfPageAnnotationType::Stamp].
705    #[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    /// Returns an immutable reference to the underlying [PdfPageStrikeoutAnnotation]
714    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
715    /// [PdfPageAnnotationType::Strikeout].
716    #[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    /// Returns a mutable reference to the underlying [PdfPageStrikeoutAnnotation]
725    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
726    /// [PdfPageAnnotationType::Strikeout].
727    #[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    /// Returns an immutable reference to the underlying [PdfPageTextAnnotation]
736    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
737    /// [PdfPageAnnotationType::Text].
738    #[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    /// Returns a mutable reference to the underlying [PdfPageTextAnnotation]
747    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
748    /// [PdfPageAnnotationType::Text].
749    #[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    /// Returns an immutable reference to the underlying [PdfPageUnderlineAnnotation]
758    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
759    /// [PdfPageAnnotationType::Underline].
760    #[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    /// Returns a mutable reference to the underlying [PdfPageUnderlineAnnotation]
769    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
770    /// [PdfPageAnnotationType::Underline].
771    #[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    /// Returns an immutable reference to the underlying [PdfPageWidgetAnnotation]
780    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
781    /// [PdfPageAnnotationType::Widget].
782    #[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    /// Returns a mutable reference to the underlying [PdfPageWidgetAnnotation]
791    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
792    /// [PdfPageAnnotationType::Widget].
793    #[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    /// Returns an immutable reference to the underlying [PdfPageXfaWidgetAnnotation]
802    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
803    /// [PdfPageAnnotationType::XfaWidget].
804    #[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    /// Returns a mutable reference to the underlying [PdfPageXfaWidgetAnnotation]
813    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
814    /// [PdfPageAnnotationType::XfaWidget].
815    #[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    /// Returns an immutable reference to the underlying [PdfPageRedactedAnnotation]
824    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
825    /// [PdfPageAnnotationType::Redacted].
826    #[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    /// Returns a mutable reference to the underlying [PdfPageRedactedAnnotation]
835    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
836    /// [PdfPageAnnotationType::Redacted].
837    #[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    /// Returns an immutable reference to the [PdfFormField] wrapped by this [PdfPageAnnotation],
846    /// if any.
847    ///
848    /// Only annotations of type [PdfPageAnnotationType::Widget] and [PdfPageAnnotationType::XfaWidget]
849    /// wrap form fields.
850    #[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    /// Returns a mutable reference to the [PdfFormField] wrapped by this [PdfPageAnnotation],
860    /// if any.
861    ///
862    /// Only annotations of type [PdfPageAnnotationType::Widget] and [PdfPageAnnotationType::XfaWidget]
863    /// wrap form fields.
864    #[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
874/// Functionality common to all [PdfPageAnnotation] objects, regardless of their [PdfPageAnnotationType].
875pub trait PdfPageAnnotationCommon {
876    /// Returns the name of this [PdfPageAnnotation], if any. This is a text string uniquely identifying
877    /// this annotation among all the annotations attached to the containing page.
878    fn name(&self) -> Option<String>;
879
880    /// Returns `true` if this [PdfPageAnnotation] supports applying text markup to the page
881    /// by setting the annotation contents using the [PdfPageAnnotationCommon::set_contents()]
882    /// function.
883    fn is_markup_annotation(&self) -> bool;
884
885    /// Returns `true` if this [PdfPageAnnotation] supports setting attachment points that
886    /// visually associate it with a `PdfPageObject`.
887    fn has_attachment_points(&self) -> bool;
888
889    /// Returns the bounding box of this [PdfPageAnnotation].
890    fn bounds(&self) -> Result<PdfRect, PdfiumError>;
891
892    /// Sets the bounding box of this [PdfPageAnnotation].
893    ///
894    /// This sets the position, the width, and the height of the annotation in a single operation.
895    /// To set these properties separately, use the [PdfPageAnnotationCommon::set_position()],
896    /// [PdfPageAnnotationCommon::set_width()], and [PdfPageAnnotationCommon::set_height()] functions.
897    fn set_bounds(&mut self, bounds: PdfRect) -> Result<(), PdfiumError>;
898
899    /// Sets the bottom right corner of this [PdfPageAnnotation] to the given values.
900    ///
901    /// To set the position, the width, and the height of the annotation in a single operation,
902    /// use the [PdfPageAnnotationCommon::set_bounds()] function.
903    fn set_position(&mut self, x: PdfPoints, y: PdfPoints) -> Result<(), PdfiumError>;
904
905    /// Sets the width of this [PdfPageAnnotation] to the given value.
906    ///
907    /// To set the position, the width, and the height of the annotation in a single operation,
908    /// use the [PdfPageAnnotationCommon::set_bounds()] function.
909    fn set_width(&mut self, width: PdfPoints) -> Result<(), PdfiumError>;
910
911    /// Sets the height of this [PdfPageAnnotation] to the given value.
912    ///
913    /// To set the position, the width, and the height of the annotation in a single operation,
914    /// use the [PdfPageAnnotationCommon::set_bounds()] function.
915    fn set_height(&mut self, width: PdfPoints) -> Result<(), PdfiumError>;
916
917    /// Returns the text to be displayed for this [PdfPageAnnotation], or, if this type of annotation
918    /// does not display text, an alternate description of the annotation's contents in human-readable
919    /// form. In either case this text is useful when extracting the document's contents in support
920    /// of accessibility to users with disabilities or for other purposes.
921    fn contents(&self) -> Option<String>;
922
923    /// Sets the text to be displayed for this [PdfPageAnnotation], or, if this type of annotation
924    /// does not display text, an alternate description of the annotation's contents in human-readable
925    /// form for providing accessibility to users with disabilities or for other purposes.
926    fn set_contents(&mut self, contents: &str) -> Result<(), PdfiumError>;
927
928    /// Returns the name of the creator of this [PdfPageAnnotation], if any.
929    fn creator(&self) -> Option<String>;
930
931    /// Returns the date and time when this [PdfPageAnnotation] was originally created, if any.
932    fn creation_date(&self) -> Option<String>;
933
934    /// Sets the date and time when this [PdfPageAnnotation] was originally created.
935    fn set_creation_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError>;
936
937    /// Returns the date and time when this [PdfPageAnnotation] was last modified, if any.
938    fn modification_date(&self) -> Option<String>;
939
940    /// Sets the date and time when this [PdfPageAnnotation] was last modified.
941    fn set_modification_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError>;
942
943    /// Returns the color of any filled paths in this [PdfPageAnnotation].
944    fn fill_color(&self) -> Result<PdfColor, PdfiumError>;
945
946    /// Sets the color of any filled paths in this [PdfPageAnnotation].
947    fn set_fill_color(&mut self, fill_color: PdfColor) -> Result<(), PdfiumError>;
948
949    /// Returns the color of any stroked paths in this [PdfPageAnnotation].
950    fn stroke_color(&self) -> Result<PdfColor, PdfiumError>;
951
952    /// Sets the color of any stroked paths in this [PdfPageAnnotation].
953    fn set_stroke_color(&mut self, stroke_color: PdfColor) -> Result<(), PdfiumError>;
954
955    /// Returns an immutable collection of all the page objects in this [PdfPageAnnotation].
956    ///
957    /// Page objects can be retrieved from any type of [PdfPageAnnotation], but Pdfium currently
958    /// only permits adding new page objects to, or removing existing page objects from, annotations
959    /// of types [PdfPageAnnotationType::Ink] and [PdfPageAnnotationType::Stamp]. All other annotation
960    /// types are read-only.
961    ///
962    /// To gain access to the mutable collection of page objects inside an ink or stamp annotation,
963    /// you must first unwrap the annotation, like so:
964    /// ```
965    /// annotation.as_stamp_annotation_mut().unwrap().objects_mut();
966    /// ```
967    fn objects(&self) -> &PdfPageAnnotationObjects;
968
969    /// Returns an immutable collection of the attachment points that visually associate
970    /// this [PdfPageAnnotation] with one or more `PdfPageObject` objects on this `PdfPage`.
971    ///
972    /// This collection is provided for all annotation types, but it will always be empty
973    /// if the annotation does not support attachment points. Pdfium supports attachment points
974    /// for all markup annotations and the Link annotation, but not for any other annotation type.
975    /// The [PdfPageAnnotationCommon::has_attachment_points()] function will return `true`
976    /// if the annotation supports attachment points.
977    ///
978    /// To gain access to the mutable collection of attachment points inside a supported
979    /// annotation, you must first unwrap the annotation, like so:
980    /// ```
981    /// annotation.as_link_annotation_mut().unwrap().attachment_points_mut();
982    /// ```
983    fn attachment_points(&self) -> &PdfPageAnnotationAttachmentPoints;
984}
985
986// Blanket implementation for all PdfPageAnnotation types.
987
988impl<'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    /// Closes this [PdfPageAnnotation], releasing held memory.
1132    #[inline]
1133    fn drop(&mut self) {
1134        self.bindings().FPDFPage_CloseAnnot(self.handle());
1135    }
1136}