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::document::page::object::ownership::PdfPageObjectOwnership;
57use crate::pdf::points::PdfPoints;
58use crate::pdf::rect::PdfRect;
59use chrono::prelude::*;
60
61#[cfg(doc)]
62use crate::pdf::document::page::PdfPage;
63
64/// The type of a single [PdfPageAnnotation], as defined in table 8.20 of the PDF Reference,
65/// version 1.7, on page 615.
66///
67/// Not all PDF annotation types are supported by Pdfium. For example, Pdfium does not
68/// currently support embedded sound or movie file annotations, embedded 3D animations, or
69/// annotations containing embedded file attachments.
70///
71/// Pdfium currently supports creating, editing, and rendering the following types of annotations:
72///
73/// * [PdfPageAnnotationType::Circle]
74/// * [PdfPageAnnotationType::FreeText]
75/// * [PdfPageAnnotationType::Highlight]
76/// * [PdfPageAnnotationType::Ink]
77/// * [PdfPageAnnotationType::Link]
78/// * [PdfPageAnnotationType::Popup]
79/// * [PdfPageAnnotationType::Redacted]
80/// * [PdfPageAnnotationType::Square]
81/// * [PdfPageAnnotationType::Squiggly]
82/// * [PdfPageAnnotationType::Stamp]
83/// * [PdfPageAnnotationType::Strikeout]
84/// * [PdfPageAnnotationType::Text]
85/// * [PdfPageAnnotationType::Underline]
86/// * [PdfPageAnnotationType::Widget]
87/// * [PdfPageAnnotationType::XfaWidget]
88///
89/// Note that a `FreeText` annotation is rendered directly on the page, whereas a `Text` annotation
90/// floats over the page inside its own enclosed area. Adobe often uses the term "sticky note"
91/// in reference to `Text` annotations to distinguish them from `FreeText` annotations.
92#[derive(Debug, Copy, Clone, PartialOrd, PartialEq)]
93pub enum PdfPageAnnotationType {
94    Unknown = FPDF_ANNOT_UNKNOWN as isize,
95    Text = FPDF_ANNOT_TEXT as isize,
96    Link = FPDF_ANNOT_LINK as isize,
97    FreeText = FPDF_ANNOT_FREETEXT as isize,
98    Line = FPDF_ANNOT_LINE as isize,
99    Square = FPDF_ANNOT_SQUARE as isize,
100    Circle = FPDF_ANNOT_CIRCLE as isize,
101    Polygon = FPDF_ANNOT_POLYGON as isize,
102    Polyline = FPDF_ANNOT_POLYLINE as isize,
103    Highlight = FPDF_ANNOT_HIGHLIGHT as isize,
104    Underline = FPDF_ANNOT_UNDERLINE as isize,
105    Squiggly = FPDF_ANNOT_SQUIGGLY as isize,
106    Strikeout = FPDF_ANNOT_STRIKEOUT as isize,
107    Stamp = FPDF_ANNOT_STAMP as isize,
108    Caret = FPDF_ANNOT_CARET as isize,
109    Ink = FPDF_ANNOT_INK as isize,
110    Popup = FPDF_ANNOT_POPUP as isize,
111    FileAttachment = FPDF_ANNOT_FILEATTACHMENT as isize,
112    Sound = FPDF_ANNOT_SOUND as isize,
113    Movie = FPDF_ANNOT_MOVIE as isize,
114    Widget = FPDF_ANNOT_WIDGET as isize,
115    Screen = FPDF_ANNOT_SCREEN as isize,
116    PrinterMark = FPDF_ANNOT_PRINTERMARK as isize,
117    TrapNet = FPDF_ANNOT_TRAPNET as isize,
118    Watermark = FPDF_ANNOT_WATERMARK as isize,
119    ThreeD = FPDF_ANNOT_THREED as isize,
120    RichMedia = FPDF_ANNOT_RICHMEDIA as isize,
121    XfaWidget = FPDF_ANNOT_XFAWIDGET as isize,
122    Redacted = FPDF_ANNOT_REDACT as isize,
123}
124
125impl PdfPageAnnotationType {
126    pub(crate) fn from_pdfium(
127        value: FPDF_ANNOTATION_SUBTYPE,
128    ) -> Result<PdfPageAnnotationType, PdfiumError> {
129        match value as u32 {
130            FPDF_ANNOT_UNKNOWN => Ok(PdfPageAnnotationType::Unknown),
131            FPDF_ANNOT_TEXT => Ok(PdfPageAnnotationType::Text),
132            FPDF_ANNOT_LINK => Ok(PdfPageAnnotationType::Link),
133            FPDF_ANNOT_FREETEXT => Ok(PdfPageAnnotationType::FreeText),
134            FPDF_ANNOT_LINE => Ok(PdfPageAnnotationType::Line),
135            FPDF_ANNOT_SQUARE => Ok(PdfPageAnnotationType::Square),
136            FPDF_ANNOT_CIRCLE => Ok(PdfPageAnnotationType::Circle),
137            FPDF_ANNOT_POLYGON => Ok(PdfPageAnnotationType::Polygon),
138            FPDF_ANNOT_POLYLINE => Ok(PdfPageAnnotationType::Polyline),
139            FPDF_ANNOT_HIGHLIGHT => Ok(PdfPageAnnotationType::Highlight),
140            FPDF_ANNOT_UNDERLINE => Ok(PdfPageAnnotationType::Underline),
141            FPDF_ANNOT_SQUIGGLY => Ok(PdfPageAnnotationType::Squiggly),
142            FPDF_ANNOT_STRIKEOUT => Ok(PdfPageAnnotationType::Strikeout),
143            FPDF_ANNOT_STAMP => Ok(PdfPageAnnotationType::Stamp),
144            FPDF_ANNOT_CARET => Ok(PdfPageAnnotationType::Caret),
145            FPDF_ANNOT_INK => Ok(PdfPageAnnotationType::Ink),
146            FPDF_ANNOT_POPUP => Ok(PdfPageAnnotationType::Popup),
147            FPDF_ANNOT_FILEATTACHMENT => Ok(PdfPageAnnotationType::FileAttachment),
148            FPDF_ANNOT_SOUND => Ok(PdfPageAnnotationType::Sound),
149            FPDF_ANNOT_MOVIE => Ok(PdfPageAnnotationType::Movie),
150            FPDF_ANNOT_WIDGET => Ok(PdfPageAnnotationType::Widget),
151            FPDF_ANNOT_SCREEN => Ok(PdfPageAnnotationType::Screen),
152            FPDF_ANNOT_PRINTERMARK => Ok(PdfPageAnnotationType::PrinterMark),
153            FPDF_ANNOT_TRAPNET => Ok(PdfPageAnnotationType::TrapNet),
154            FPDF_ANNOT_WATERMARK => Ok(PdfPageAnnotationType::Watermark),
155            FPDF_ANNOT_THREED => Ok(PdfPageAnnotationType::ThreeD),
156            FPDF_ANNOT_RICHMEDIA => Ok(PdfPageAnnotationType::RichMedia),
157            FPDF_ANNOT_XFAWIDGET => Ok(PdfPageAnnotationType::XfaWidget),
158            FPDF_ANNOT_REDACT => Ok(PdfPageAnnotationType::Redacted),
159            _ => Err(PdfiumError::UnknownPdfAnnotationType),
160        }
161    }
162
163    #[allow(dead_code)]
164    // The as_pdfium() function is not currently used, but we expect it to be in future
165    pub(crate) fn as_pdfium(&self) -> FPDF_ANNOTATION_SUBTYPE {
166        (match self {
167            PdfPageAnnotationType::Unknown => FPDF_ANNOT_UNKNOWN,
168            PdfPageAnnotationType::Text => FPDF_ANNOT_TEXT,
169            PdfPageAnnotationType::Link => FPDF_ANNOT_LINK,
170            PdfPageAnnotationType::FreeText => FPDF_ANNOT_FREETEXT,
171            PdfPageAnnotationType::Line => FPDF_ANNOT_LINE,
172            PdfPageAnnotationType::Square => FPDF_ANNOT_SQUARE,
173            PdfPageAnnotationType::Circle => FPDF_ANNOT_CIRCLE,
174            PdfPageAnnotationType::Polygon => FPDF_ANNOT_POLYGON,
175            PdfPageAnnotationType::Polyline => FPDF_ANNOT_POLYLINE,
176            PdfPageAnnotationType::Highlight => FPDF_ANNOT_HIGHLIGHT,
177            PdfPageAnnotationType::Underline => FPDF_ANNOT_UNDERLINE,
178            PdfPageAnnotationType::Squiggly => FPDF_ANNOT_SQUIGGLY,
179            PdfPageAnnotationType::Strikeout => FPDF_ANNOT_STRIKEOUT,
180            PdfPageAnnotationType::Stamp => FPDF_ANNOT_STAMP,
181            PdfPageAnnotationType::Caret => FPDF_ANNOT_CARET,
182            PdfPageAnnotationType::Ink => FPDF_ANNOT_INK,
183            PdfPageAnnotationType::Popup => FPDF_ANNOT_POPUP,
184            PdfPageAnnotationType::FileAttachment => FPDF_ANNOT_FILEATTACHMENT,
185            PdfPageAnnotationType::Sound => FPDF_ANNOT_SOUND,
186            PdfPageAnnotationType::Movie => FPDF_ANNOT_MOVIE,
187            PdfPageAnnotationType::Widget => FPDF_ANNOT_WIDGET,
188            PdfPageAnnotationType::Screen => FPDF_ANNOT_SCREEN,
189            PdfPageAnnotationType::PrinterMark => FPDF_ANNOT_PRINTERMARK,
190            PdfPageAnnotationType::TrapNet => FPDF_ANNOT_TRAPNET,
191            PdfPageAnnotationType::Watermark => FPDF_ANNOT_WATERMARK,
192            PdfPageAnnotationType::ThreeD => FPDF_ANNOT_THREED,
193            PdfPageAnnotationType::RichMedia => FPDF_ANNOT_RICHMEDIA,
194            PdfPageAnnotationType::XfaWidget => FPDF_ANNOT_XFAWIDGET,
195            PdfPageAnnotationType::Redacted => FPDF_ANNOT_REDACT,
196        }) as FPDF_ANNOTATION_SUBTYPE
197    }
198}
199
200/// A single user annotation on a [PdfPage].
201pub enum PdfPageAnnotation<'a> {
202    Circle(PdfPageCircleAnnotation<'a>),
203    FreeText(PdfPageFreeTextAnnotation<'a>),
204    Highlight(PdfPageHighlightAnnotation<'a>),
205    Ink(PdfPageInkAnnotation<'a>),
206    Link(PdfPageLinkAnnotation<'a>),
207    Popup(PdfPagePopupAnnotation<'a>),
208    Square(PdfPageSquareAnnotation<'a>),
209    Squiggly(PdfPageSquigglyAnnotation<'a>),
210    Stamp(PdfPageStampAnnotation<'a>),
211    Strikeout(PdfPageStrikeoutAnnotation<'a>),
212    Text(PdfPageTextAnnotation<'a>),
213    Underline(PdfPageUnderlineAnnotation<'a>),
214    Widget(PdfPageWidgetAnnotation<'a>),
215    XfaWidget(PdfPageXfaWidgetAnnotation<'a>),
216    Redacted(PdfPageRedactedAnnotation<'a>),
217
218    /// Common properties shared by all [PdfPageAnnotation] types can still be accessed for
219    /// annotations not supported by Pdfium, but annotation-specific functionality
220    /// will be unavailable.
221    Unsupported(PdfPageUnsupportedAnnotation<'a>),
222}
223
224impl<'a> PdfPageAnnotation<'a> {
225    pub(crate) fn from_pdfium(
226        document_handle: FPDF_DOCUMENT,
227        page_handle: FPDF_PAGE,
228        annotation_handle: FPDF_ANNOTATION,
229        form_handle: Option<FPDF_FORMHANDLE>,
230        bindings: &'a dyn PdfiumLibraryBindings,
231    ) -> Self {
232        let annotation_type =
233            PdfPageAnnotationType::from_pdfium(bindings.FPDFAnnot_GetSubtype(annotation_handle))
234                .unwrap_or(PdfPageAnnotationType::Unknown);
235
236        match annotation_type {
237            PdfPageAnnotationType::Circle => {
238                PdfPageAnnotation::Circle(PdfPageCircleAnnotation::from_pdfium(
239                    document_handle,
240                    page_handle,
241                    annotation_handle,
242                    bindings,
243                ))
244            }
245            PdfPageAnnotationType::FreeText => {
246                PdfPageAnnotation::FreeText(PdfPageFreeTextAnnotation::from_pdfium(
247                    document_handle,
248                    page_handle,
249                    annotation_handle,
250                    bindings,
251                ))
252            }
253            PdfPageAnnotationType::Highlight => {
254                PdfPageAnnotation::Highlight(PdfPageHighlightAnnotation::from_pdfium(
255                    document_handle,
256                    page_handle,
257                    annotation_handle,
258                    bindings,
259                ))
260            }
261            PdfPageAnnotationType::Ink => {
262                PdfPageAnnotation::Ink(PdfPageInkAnnotation::from_pdfium(
263                    document_handle,
264                    page_handle,
265                    annotation_handle,
266                    bindings,
267                ))
268            }
269            PdfPageAnnotationType::Link => {
270                PdfPageAnnotation::Link(PdfPageLinkAnnotation::from_pdfium(
271                    document_handle,
272                    page_handle,
273                    annotation_handle,
274                    bindings,
275                ))
276            }
277            PdfPageAnnotationType::Popup => {
278                PdfPageAnnotation::Popup(PdfPagePopupAnnotation::from_pdfium(
279                    document_handle,
280                    page_handle,
281                    annotation_handle,
282                    bindings,
283                ))
284            }
285            PdfPageAnnotationType::Square => {
286                PdfPageAnnotation::Square(PdfPageSquareAnnotation::from_pdfium(
287                    document_handle,
288                    page_handle,
289                    annotation_handle,
290                    bindings,
291                ))
292            }
293            PdfPageAnnotationType::Squiggly => {
294                PdfPageAnnotation::Squiggly(PdfPageSquigglyAnnotation::from_pdfium(
295                    document_handle,
296                    page_handle,
297                    annotation_handle,
298                    bindings,
299                ))
300            }
301            PdfPageAnnotationType::Stamp => {
302                PdfPageAnnotation::Stamp(PdfPageStampAnnotation::from_pdfium(
303                    document_handle,
304                    page_handle,
305                    annotation_handle,
306                    bindings,
307                ))
308            }
309            PdfPageAnnotationType::Strikeout => {
310                PdfPageAnnotation::Strikeout(PdfPageStrikeoutAnnotation::from_pdfium(
311                    document_handle,
312                    page_handle,
313                    annotation_handle,
314                    bindings,
315                ))
316            }
317            PdfPageAnnotationType::Text => {
318                PdfPageAnnotation::Text(PdfPageTextAnnotation::from_pdfium(
319                    document_handle,
320                    page_handle,
321                    annotation_handle,
322                    bindings,
323                ))
324            }
325            PdfPageAnnotationType::Underline => {
326                PdfPageAnnotation::Underline(PdfPageUnderlineAnnotation::from_pdfium(
327                    document_handle,
328                    page_handle,
329                    annotation_handle,
330                    bindings,
331                ))
332            }
333            PdfPageAnnotationType::Widget => {
334                PdfPageAnnotation::Widget(PdfPageWidgetAnnotation::from_pdfium(
335                    document_handle,
336                    page_handle,
337                    annotation_handle,
338                    form_handle,
339                    bindings,
340                ))
341            }
342            PdfPageAnnotationType::XfaWidget => {
343                PdfPageAnnotation::XfaWidget(PdfPageXfaWidgetAnnotation::from_pdfium(
344                    document_handle,
345                    page_handle,
346                    annotation_handle,
347                    form_handle,
348                    bindings,
349                ))
350            }
351            PdfPageAnnotationType::Redacted => {
352                PdfPageAnnotation::Redacted(PdfPageRedactedAnnotation::from_pdfium(
353                    document_handle,
354                    page_handle,
355                    annotation_handle,
356                    bindings,
357                ))
358            }
359            _ => PdfPageAnnotation::Unsupported(PdfPageUnsupportedAnnotation::from_pdfium(
360                document_handle,
361                page_handle,
362                annotation_handle,
363                annotation_type,
364                bindings,
365            )),
366        }
367    }
368
369    #[inline]
370    pub(crate) fn unwrap_as_trait(&self) -> &dyn PdfPageAnnotationPrivate<'a> {
371        match self {
372            PdfPageAnnotation::Circle(annotation) => annotation,
373            PdfPageAnnotation::FreeText(annotation) => annotation,
374            PdfPageAnnotation::Highlight(annotation) => annotation,
375            PdfPageAnnotation::Ink(annotation) => annotation,
376            PdfPageAnnotation::Link(annotation) => annotation,
377            PdfPageAnnotation::Popup(annotation) => annotation,
378            PdfPageAnnotation::Square(annotation) => annotation,
379            PdfPageAnnotation::Squiggly(annotation) => annotation,
380            PdfPageAnnotation::Stamp(annotation) => annotation,
381            PdfPageAnnotation::Strikeout(annotation) => annotation,
382            PdfPageAnnotation::Text(annotation) => annotation,
383            PdfPageAnnotation::Underline(annotation) => annotation,
384            PdfPageAnnotation::Widget(annotation) => annotation,
385            PdfPageAnnotation::XfaWidget(annotation) => annotation,
386            PdfPageAnnotation::Redacted(annotation) => annotation,
387            PdfPageAnnotation::Unsupported(annotation) => annotation,
388        }
389    }
390
391    #[inline]
392    #[allow(dead_code)] // We don't currently use unwrap_as_trait_mut(), but we expect to in the future
393    pub(crate) fn unwrap_as_trait_mut(&mut self) -> &mut dyn PdfPageAnnotationPrivate<'a> {
394        match self {
395            PdfPageAnnotation::Circle(annotation) => annotation,
396            PdfPageAnnotation::FreeText(annotation) => annotation,
397            PdfPageAnnotation::Highlight(annotation) => annotation,
398            PdfPageAnnotation::Ink(annotation) => annotation,
399            PdfPageAnnotation::Link(annotation) => annotation,
400            PdfPageAnnotation::Popup(annotation) => annotation,
401            PdfPageAnnotation::Square(annotation) => annotation,
402            PdfPageAnnotation::Squiggly(annotation) => annotation,
403            PdfPageAnnotation::Stamp(annotation) => annotation,
404            PdfPageAnnotation::Strikeout(annotation) => annotation,
405            PdfPageAnnotation::Text(annotation) => annotation,
406            PdfPageAnnotation::Underline(annotation) => annotation,
407            PdfPageAnnotation::Widget(annotation) => annotation,
408            PdfPageAnnotation::XfaWidget(annotation) => annotation,
409            PdfPageAnnotation::Redacted(annotation) => annotation,
410            PdfPageAnnotation::Unsupported(annotation) => annotation,
411        }
412    }
413
414    /// The type of this [PdfPageAnnotation].
415    ///
416    /// Not all PDF annotation types are supported by Pdfium. For example, Pdfium does not
417    /// currently support embedded sound or movie file annotations, embedded 3D animations, or
418    /// annotations containing embedded file attachments.
419    ///
420    /// Pdfium currently supports creating, editing, and rendering the following types of annotations:
421    ///
422    /// * [PdfPageAnnotationType::Circle]
423    /// * [PdfPageAnnotationType::FreeText]
424    /// * [PdfPageAnnotationType::Highlight]
425    /// * [PdfPageAnnotationType::Ink]
426    /// * [PdfPageAnnotationType::Link]
427    /// * [PdfPageAnnotationType::Popup]
428    /// * [PdfPageAnnotationType::Redacted]
429    /// * [PdfPageAnnotationType::Square]
430    /// * [PdfPageAnnotationType::Squiggly]
431    /// * [PdfPageAnnotationType::Stamp]
432    /// * [PdfPageAnnotationType::Strikeout]
433    /// * [PdfPageAnnotationType::Text]
434    /// * [PdfPageAnnotationType::Underline]
435    /// * [PdfPageAnnotationType::Widget]
436    /// * [PdfPageAnnotationType::XfaWidget]
437    #[inline]
438    pub fn annotation_type(&self) -> PdfPageAnnotationType {
439        match self {
440            PdfPageAnnotation::Circle(_) => PdfPageAnnotationType::Circle,
441            PdfPageAnnotation::FreeText(_) => PdfPageAnnotationType::FreeText,
442            PdfPageAnnotation::Highlight(_) => PdfPageAnnotationType::Highlight,
443            PdfPageAnnotation::Ink(_) => PdfPageAnnotationType::Ink,
444            PdfPageAnnotation::Link(_) => PdfPageAnnotationType::Link,
445            PdfPageAnnotation::Popup(_) => PdfPageAnnotationType::Popup,
446            PdfPageAnnotation::Square(_) => PdfPageAnnotationType::Square,
447            PdfPageAnnotation::Squiggly(_) => PdfPageAnnotationType::Squiggly,
448            PdfPageAnnotation::Stamp(_) => PdfPageAnnotationType::Stamp,
449            PdfPageAnnotation::Strikeout(_) => PdfPageAnnotationType::Strikeout,
450            PdfPageAnnotation::Text(_) => PdfPageAnnotationType::Text,
451            PdfPageAnnotation::Underline(_) => PdfPageAnnotationType::Underline,
452            PdfPageAnnotation::Widget(_) => PdfPageAnnotationType::Widget,
453            PdfPageAnnotation::XfaWidget(_) => PdfPageAnnotationType::XfaWidget,
454            PdfPageAnnotation::Redacted(_) => PdfPageAnnotationType::Redacted,
455            PdfPageAnnotation::Unsupported(annotation) => annotation.get_type(),
456        }
457    }
458
459    /// Returns `true` if Pdfium supports creating, editing, and rendering this type of
460    /// [PdfPageAnnotation].
461    ///
462    /// Not all PDF annotation types are supported by Pdfium. For example, Pdfium does not
463    /// currently support embedded sound or movie file annotations, embedded 3D animations, or
464    /// annotations containing embedded file attachments.
465    ///
466    /// Pdfium currently supports creating, editing, and rendering the following types of annotations:
467    ///
468    /// * [PdfPageAnnotationType::Circle]
469    /// * [PdfPageAnnotationType::FreeText]
470    /// * [PdfPageAnnotationType::Highlight]
471    /// * [PdfPageAnnotationType::Ink]
472    /// * [PdfPageAnnotationType::Link]
473    /// * [PdfPageAnnotationType::Popup]
474    /// * [PdfPageAnnotationType::Redacted]
475    /// * [PdfPageAnnotationType::Square]
476    /// * [PdfPageAnnotationType::Squiggly]
477    /// * [PdfPageAnnotationType::Stamp]
478    /// * [PdfPageAnnotationType::Strikeout]
479    /// * [PdfPageAnnotationType::Text]
480    /// * [PdfPageAnnotationType::Underline]
481    /// * [PdfPageAnnotationType::Widget]
482    /// * [PdfPageAnnotationType::XfaWidget]
483    #[inline]
484    pub fn is_supported(&self) -> bool {
485        !self.is_unsupported()
486    }
487
488    /// Returns `true` if Pdfium does _not_ support creating, editing, and rendering this type of
489    /// [PdfPageAnnotation].
490    ///
491    /// Not all PDF annotation types are supported by Pdfium. For example, Pdfium does not
492    /// currently support embedded sound or movie file annotations, embedded 3D animations, or
493    /// annotations containing embedded file attachments.
494    ///
495    /// Pdfium currently supports creating, editing, and rendering the following types of annotations:
496    ///
497    /// * [PdfPageAnnotationType::Circle]
498    /// * [PdfPageAnnotationType::FreeText]
499    /// * [PdfPageAnnotationType::Highlight]
500    /// * [PdfPageAnnotationType::Ink]
501    /// * [PdfPageAnnotationType::Link]
502    /// * [PdfPageAnnotationType::Popup]
503    /// * [PdfPageAnnotationType::Redacted]
504    /// * [PdfPageAnnotationType::Square]
505    /// * [PdfPageAnnotationType::Squiggly]
506    /// * [PdfPageAnnotationType::Stamp]
507    /// * [PdfPageAnnotationType::Strikeout]
508    /// * [PdfPageAnnotationType::Text]
509    /// * [PdfPageAnnotationType::Underline]
510    /// * [PdfPageAnnotationType::Widget]
511    /// * [PdfPageAnnotationType::XfaWidget]
512    #[inline]
513    pub fn is_unsupported(&self) -> bool {
514        matches!(self, PdfPageAnnotation::Unsupported(_))
515    }
516
517    /// Returns an immutable reference to the underlying [PdfPageCircleAnnotation]
518    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
519    /// [PdfPageAnnotationType::Circle].
520    #[inline]
521    pub fn as_circle_annotation(&self) -> Option<&PdfPageCircleAnnotation> {
522        match self {
523            PdfPageAnnotation::Circle(annotation) => Some(annotation),
524            _ => None,
525        }
526    }
527
528    /// Returns a mutable reference to the underlying [PdfPageCircleAnnotation]
529    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
530    /// [PdfPageAnnotationType::Circle].
531    #[inline]
532    pub fn as_circle_annotation_mut(&mut self) -> Option<&mut PdfPageCircleAnnotation<'a>> {
533        match self {
534            PdfPageAnnotation::Circle(annotation) => Some(annotation),
535            _ => None,
536        }
537    }
538
539    /// Returns an immutable reference to the underlying [PdfPageFreeTextAnnotation]
540    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
541    /// [PdfPageAnnotationType::FreeText].
542    #[inline]
543    pub fn as_free_text_annotation(&self) -> Option<&PdfPageFreeTextAnnotation> {
544        match self {
545            PdfPageAnnotation::FreeText(annotation) => Some(annotation),
546            _ => None,
547        }
548    }
549
550    /// Returns a mutable reference to the underlying [PdfPageFreeTextAnnotation]
551    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
552    /// [PdfPageAnnotationType::FreeText].
553    #[inline]
554    pub fn as_free_text_annotation_mut(&mut self) -> Option<&mut PdfPageFreeTextAnnotation<'a>> {
555        match self {
556            PdfPageAnnotation::FreeText(annotation) => Some(annotation),
557            _ => None,
558        }
559    }
560
561    /// Returns an immutable reference to the underlying [PdfPageHighlightAnnotation]
562    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
563    /// [PdfPageAnnotationType::Highlight].
564    #[inline]
565    pub fn as_highlight_annotation(&self) -> Option<&PdfPageHighlightAnnotation> {
566        match self {
567            PdfPageAnnotation::Highlight(annotation) => Some(annotation),
568            _ => None,
569        }
570    }
571
572    /// Returns a mutable reference to the underlying [PdfPageHighlightAnnotation]
573    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
574    /// [PdfPageAnnotationType::Highlight].
575    #[inline]
576    pub fn as_highlight_annotation_mut(&mut self) -> Option<&mut PdfPageHighlightAnnotation<'a>> {
577        match self {
578            PdfPageAnnotation::Highlight(annotation) => Some(annotation),
579            _ => None,
580        }
581    }
582
583    /// Returns an immutable reference to the underlying [PdfPageInkAnnotation]
584    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
585    /// [PdfPageAnnotationType::Ink].
586    #[inline]
587    pub fn as_ink_annotation(&self) -> Option<&PdfPageInkAnnotation> {
588        match self {
589            PdfPageAnnotation::Ink(annotation) => Some(annotation),
590            _ => None,
591        }
592    }
593
594    /// Returns a mutable reference to the underlying [PdfPageInkAnnotation]
595    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
596    /// [PdfPageAnnotationType::Ink].
597    #[inline]
598    pub fn as_ink_annotation_mut(&mut self) -> Option<&mut PdfPageInkAnnotation<'a>> {
599        match self {
600            PdfPageAnnotation::Ink(annotation) => Some(annotation),
601            _ => None,
602        }
603    }
604
605    /// Returns an immutable reference to the underlying [PdfPageLinkAnnotation]
606    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
607    /// [PdfPageAnnotationType::Link].
608    #[inline]
609    pub fn as_link_annotation(&self) -> Option<&PdfPageLinkAnnotation> {
610        match self {
611            PdfPageAnnotation::Link(annotation) => Some(annotation),
612            _ => None,
613        }
614    }
615
616    /// Returns a mutable reference to the underlying [PdfPageLinkAnnotation]
617    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
618    /// [PdfPageAnnotationType::Link].
619    #[inline]
620    pub fn as_link_annotation_mut(&mut self) -> Option<&mut PdfPageLinkAnnotation<'a>> {
621        match self {
622            PdfPageAnnotation::Link(annotation) => Some(annotation),
623            _ => None,
624        }
625    }
626
627    /// Returns an immutable reference to the underlying [PdfPagePopupAnnotation]
628    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
629    /// [PdfPageAnnotationType::Popup].
630    #[inline]
631    pub fn as_popup_annotation(&self) -> Option<&PdfPagePopupAnnotation> {
632        match self {
633            PdfPageAnnotation::Popup(annotation) => Some(annotation),
634            _ => None,
635        }
636    }
637
638    /// Returns a mutable reference to the underlying [PdfPagePopupAnnotation]
639    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
640    /// [PdfPageAnnotationType::Popup].
641    #[inline]
642    pub fn as_popup_annotation_mut(&mut self) -> Option<&mut PdfPagePopupAnnotation<'a>> {
643        match self {
644            PdfPageAnnotation::Popup(annotation) => Some(annotation),
645            _ => None,
646        }
647    }
648
649    /// Returns an immutable reference to the underlying [PdfPageSquareAnnotation]
650    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
651    /// [PdfPageAnnotationType::Square].
652    #[inline]
653    pub fn as_square_annotation(&self) -> Option<&PdfPageSquareAnnotation> {
654        match self {
655            PdfPageAnnotation::Square(annotation) => Some(annotation),
656            _ => None,
657        }
658    }
659
660    /// Returns a mutable reference to the underlying [PdfPageSquareAnnotation]
661    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
662    /// [PdfPageAnnotationType::Square].
663    #[inline]
664    pub fn as_square_annotation_mut(&mut self) -> Option<&mut PdfPageSquareAnnotation<'a>> {
665        match self {
666            PdfPageAnnotation::Square(annotation) => Some(annotation),
667            _ => None,
668        }
669    }
670
671    /// Returns an immutable reference to the underlying [PdfPageSquigglyAnnotation]
672    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
673    /// [PdfPageAnnotationType::Squiggly].
674    #[inline]
675    pub fn as_squiggly_annotation(&self) -> Option<&PdfPageSquigglyAnnotation> {
676        match self {
677            PdfPageAnnotation::Squiggly(annotation) => Some(annotation),
678            _ => None,
679        }
680    }
681
682    /// Returns a mutable reference to the underlying [PdfPageSquigglyAnnotation]
683    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
684    /// [PdfPageAnnotationType::Squiggly].
685    #[inline]
686    pub fn as_squiggly_annotation_mut(&mut self) -> Option<&mut PdfPageSquigglyAnnotation<'a>> {
687        match self {
688            PdfPageAnnotation::Squiggly(annotation) => Some(annotation),
689            _ => None,
690        }
691    }
692
693    /// Returns an immutable reference to the underlying [PdfPageStampAnnotation]
694    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
695    /// [PdfPageAnnotationType::Stamp].
696    #[inline]
697    pub fn as_stamp_annotation(&self) -> Option<&PdfPageStampAnnotation> {
698        match self {
699            PdfPageAnnotation::Stamp(annotation) => Some(annotation),
700            _ => None,
701        }
702    }
703
704    /// Returns a mutable reference to the underlying [PdfPageStampAnnotation]
705    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
706    /// [PdfPageAnnotationType::Stamp].
707    #[inline]
708    pub fn as_stamp_annotation_mut(&mut self) -> Option<&mut PdfPageStampAnnotation<'a>> {
709        match self {
710            PdfPageAnnotation::Stamp(annotation) => Some(annotation),
711            _ => None,
712        }
713    }
714
715    /// Returns an immutable reference to the underlying [PdfPageStrikeoutAnnotation]
716    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
717    /// [PdfPageAnnotationType::Strikeout].
718    #[inline]
719    pub fn as_strikeout_annotation(&self) -> Option<&PdfPageStrikeoutAnnotation> {
720        match self {
721            PdfPageAnnotation::Strikeout(annotation) => Some(annotation),
722            _ => None,
723        }
724    }
725
726    /// Returns a mutable reference to the underlying [PdfPageStrikeoutAnnotation]
727    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
728    /// [PdfPageAnnotationType::Strikeout].
729    #[inline]
730    pub fn as_strikeout_annotation_mut(&mut self) -> Option<&mut PdfPageStrikeoutAnnotation<'a>> {
731        match self {
732            PdfPageAnnotation::Strikeout(annotation) => Some(annotation),
733            _ => None,
734        }
735    }
736
737    /// Returns an immutable reference to the underlying [PdfPageTextAnnotation]
738    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
739    /// [PdfPageAnnotationType::Text].
740    #[inline]
741    pub fn as_text_annotation(&self) -> Option<&PdfPageTextAnnotation> {
742        match self {
743            PdfPageAnnotation::Text(annotation) => Some(annotation),
744            _ => None,
745        }
746    }
747
748    /// Returns a mutable reference to the underlying [PdfPageTextAnnotation]
749    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
750    /// [PdfPageAnnotationType::Text].
751    #[inline]
752    pub fn as_text_annotation_mut(&mut self) -> Option<&mut PdfPageTextAnnotation<'a>> {
753        match self {
754            PdfPageAnnotation::Text(annotation) => Some(annotation),
755            _ => None,
756        }
757    }
758
759    /// Returns an immutable reference to the underlying [PdfPageUnderlineAnnotation]
760    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
761    /// [PdfPageAnnotationType::Underline].
762    #[inline]
763    pub fn as_underline_annotation(&self) -> Option<&PdfPageUnderlineAnnotation> {
764        match self {
765            PdfPageAnnotation::Underline(annotation) => Some(annotation),
766            _ => None,
767        }
768    }
769
770    /// Returns a mutable reference to the underlying [PdfPageUnderlineAnnotation]
771    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
772    /// [PdfPageAnnotationType::Underline].
773    #[inline]
774    pub fn as_underline_annotation_mut(&mut self) -> Option<&mut PdfPageUnderlineAnnotation<'a>> {
775        match self {
776            PdfPageAnnotation::Underline(annotation) => Some(annotation),
777            _ => None,
778        }
779    }
780
781    /// Returns an immutable reference to the underlying [PdfPageWidgetAnnotation]
782    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
783    /// [PdfPageAnnotationType::Widget].
784    #[inline]
785    pub fn as_widget_annotation(&self) -> Option<&PdfPageWidgetAnnotation> {
786        match self {
787            PdfPageAnnotation::Widget(annotation) => Some(annotation),
788            _ => None,
789        }
790    }
791
792    /// Returns a mutable reference to the underlying [PdfPageWidgetAnnotation]
793    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
794    /// [PdfPageAnnotationType::Widget].
795    #[inline]
796    pub fn as_widget_annotation_mut(&mut self) -> Option<&mut PdfPageWidgetAnnotation<'a>> {
797        match self {
798            PdfPageAnnotation::Widget(annotation) => Some(annotation),
799            _ => None,
800        }
801    }
802
803    /// Returns an immutable reference to the underlying [PdfPageXfaWidgetAnnotation]
804    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
805    /// [PdfPageAnnotationType::XfaWidget].
806    #[inline]
807    pub fn as_xfa_widget_annotation(&self) -> Option<&PdfPageXfaWidgetAnnotation> {
808        match self {
809            PdfPageAnnotation::XfaWidget(annotation) => Some(annotation),
810            _ => None,
811        }
812    }
813
814    /// Returns a mutable reference to the underlying [PdfPageXfaWidgetAnnotation]
815    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
816    /// [PdfPageAnnotationType::XfaWidget].
817    #[inline]
818    pub fn as_xfa_widget_annotation_mut(&mut self) -> Option<&mut PdfPageXfaWidgetAnnotation<'a>> {
819        match self {
820            PdfPageAnnotation::XfaWidget(annotation) => Some(annotation),
821            _ => None,
822        }
823    }
824
825    /// Returns an immutable reference to the underlying [PdfPageRedactedAnnotation]
826    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
827    /// [PdfPageAnnotationType::Redacted].
828    #[inline]
829    pub fn as_redacted_annotation(&self) -> Option<&PdfPageRedactedAnnotation> {
830        match self {
831            PdfPageAnnotation::Redacted(annotation) => Some(annotation),
832            _ => None,
833        }
834    }
835
836    /// Returns a mutable reference to the underlying [PdfPageRedactedAnnotation]
837    /// for this [PdfPageAnnotation], if this annotation has an annotation type of
838    /// [PdfPageAnnotationType::Redacted].
839    #[inline]
840    pub fn as_redacted_annotation_mut(&mut self) -> Option<&mut PdfPageRedactedAnnotation<'a>> {
841        match self {
842            PdfPageAnnotation::Redacted(annotation) => Some(annotation),
843            _ => None,
844        }
845    }
846
847    /// Returns an immutable reference to the [PdfFormField] wrapped by this [PdfPageAnnotation],
848    /// if any.
849    ///
850    /// Only annotations of type [PdfPageAnnotationType::Widget] and [PdfPageAnnotationType::XfaWidget]
851    /// wrap form fields.
852    #[inline]
853    pub fn as_form_field(&self) -> Option<&PdfFormField> {
854        match self {
855            PdfPageAnnotation::Widget(annotation) => annotation.form_field(),
856            PdfPageAnnotation::XfaWidget(annotation) => annotation.form_field(),
857            _ => None,
858        }
859    }
860
861    /// Returns a mutable reference to the [PdfFormField] wrapped by this [PdfPageAnnotation],
862    /// if any.
863    ///
864    /// Only annotations of type [PdfPageAnnotationType::Widget] and [PdfPageAnnotationType::XfaWidget]
865    /// wrap form fields.
866    #[inline]
867    pub fn as_form_field_mut(&mut self) -> Option<&mut PdfFormField<'a>> {
868        match self {
869            PdfPageAnnotation::Widget(annotation) => annotation.form_field_mut(),
870            PdfPageAnnotation::XfaWidget(annotation) => annotation.form_field_mut(),
871            _ => None,
872        }
873    }
874}
875
876/// Functionality common to all [PdfPageAnnotation] objects, regardless of their [PdfPageAnnotationType].
877pub trait PdfPageAnnotationCommon {
878    /// Returns the name of this [PdfPageAnnotation], if any. This is a text string uniquely identifying
879    /// this annotation among all the annotations attached to the containing page.
880    fn name(&self) -> Option<String>;
881
882    /// Returns `true` if this [PdfPageAnnotation] supports applying text markup to the page
883    /// by setting the annotation contents using the [PdfPageAnnotationCommon::set_contents()]
884    /// function.
885    fn is_markup_annotation(&self) -> bool;
886
887    /// Returns `true` if this [PdfPageAnnotation] supports setting attachment points that
888    /// visually associate it with a `PdfPageObject`.
889    fn has_attachment_points(&self) -> bool;
890
891    /// Returns the bounding box of this [PdfPageAnnotation].
892    fn bounds(&self) -> Result<PdfRect, PdfiumError>;
893
894    /// Sets the bounding box of this [PdfPageAnnotation].
895    ///
896    /// This sets the position, the width, and the height of the annotation in a single operation.
897    /// To set these properties separately, use the [PdfPageAnnotationCommon::set_position()],
898    /// [PdfPageAnnotationCommon::set_width()], and [PdfPageAnnotationCommon::set_height()] functions.
899    fn set_bounds(&mut self, bounds: PdfRect) -> Result<(), PdfiumError>;
900
901    /// Sets the bottom right corner of this [PdfPageAnnotation] to the given values.
902    ///
903    /// To set the position, the width, and the height of the annotation in a single operation,
904    /// use the [PdfPageAnnotationCommon::set_bounds()] function.
905    fn set_position(&mut self, x: PdfPoints, y: PdfPoints) -> Result<(), PdfiumError>;
906
907    /// Sets the width of this [PdfPageAnnotation] to the given value.
908    ///
909    /// To set the position, the width, and the height of the annotation in a single operation,
910    /// use the [PdfPageAnnotationCommon::set_bounds()] function.
911    fn set_width(&mut self, width: PdfPoints) -> Result<(), PdfiumError>;
912
913    /// Sets the height of this [PdfPageAnnotation] to the given value.
914    ///
915    /// To set the position, the width, and the height of the annotation in a single operation,
916    /// use the [PdfPageAnnotationCommon::set_bounds()] function.
917    fn set_height(&mut self, width: PdfPoints) -> Result<(), PdfiumError>;
918
919    /// Returns the text to be displayed for this [PdfPageAnnotation], or, if this type of annotation
920    /// does not display text, an alternate description of the annotation's contents in human-readable
921    /// form. In either case this text is useful when extracting the document's contents in support
922    /// of accessibility to users with disabilities or for other purposes.
923    fn contents(&self) -> Option<String>;
924
925    /// Sets the text to be displayed for this [PdfPageAnnotation], or, if this type of annotation
926    /// does not display text, an alternate description of the annotation's contents in human-readable
927    /// form for providing accessibility to users with disabilities or for other purposes.
928    fn set_contents(&mut self, contents: &str) -> Result<(), PdfiumError>;
929
930    /// Returns the name of the creator of this [PdfPageAnnotation], if any.
931    fn creator(&self) -> Option<String>;
932
933    /// Sets the name of the creator of this [PdfPageAnnotation].
934    fn set_creator(&mut self, creator: &str) -> Result<(), PdfiumError>;
935
936    /// Returns the date and time when this [PdfPageAnnotation] was originally created, if any.
937    fn creation_date(&self) -> Option<String>;
938
939    /// Sets the date and time when this [PdfPageAnnotation] was originally created.
940    fn set_creation_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError>;
941
942    /// Returns the date and time when this [PdfPageAnnotation] was last modified, if any.
943    fn modification_date(&self) -> Option<String>;
944
945    /// Sets the date and time when this [PdfPageAnnotation] was last modified.
946    fn set_modification_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError>;
947
948    /// Returns the color of any filled paths in this [PdfPageAnnotation].
949    fn fill_color(&self) -> Result<PdfColor, PdfiumError>;
950
951    /// Sets the color of any filled paths in this [PdfPageAnnotation].
952    fn set_fill_color(&mut self, fill_color: PdfColor) -> Result<(), PdfiumError>;
953
954    /// Returns the color of any stroked paths in this [PdfPageAnnotation].
955    fn stroke_color(&self) -> Result<PdfColor, PdfiumError>;
956
957    /// Sets the color of any stroked paths in this [PdfPageAnnotation].
958    fn set_stroke_color(&mut self, stroke_color: PdfColor) -> Result<(), PdfiumError>;
959
960    /// Returns an immutable collection of all the page objects in this [PdfPageAnnotation].
961    ///
962    /// Page objects can be retrieved from any type of [PdfPageAnnotation], but Pdfium currently
963    /// only permits adding new page objects to, or removing existing page objects from, annotations
964    /// of types [PdfPageAnnotationType::Ink] and [PdfPageAnnotationType::Stamp]. All other annotation
965    /// types are read-only.
966    ///
967    /// To gain access to the mutable collection of page objects inside an ink or stamp annotation,
968    /// you must first unwrap the annotation, like so:
969    /// ```
970    /// annotation.as_stamp_annotation_mut().unwrap().objects_mut();
971    /// ```
972    fn objects(&self) -> &PdfPageAnnotationObjects;
973
974    /// Returns an immutable collection of the attachment points that visually associate
975    /// this [PdfPageAnnotation] with one or more `PdfPageObject` objects on this `PdfPage`.
976    ///
977    /// This collection is provided for all annotation types, but it will always be empty
978    /// if the annotation does not support attachment points. Pdfium supports attachment points
979    /// for all markup annotations and the Link annotation, but not for any other annotation type.
980    /// The [PdfPageAnnotationCommon::has_attachment_points()] function will return `true`
981    /// if the annotation supports attachment points.
982    ///
983    /// To gain access to the mutable collection of attachment points inside a supported
984    /// annotation, you must first unwrap the annotation, like so:
985    /// ```
986    /// annotation.as_link_annotation_mut().unwrap().attachment_points_mut();
987    /// ```
988    fn attachment_points(&self) -> &PdfPageAnnotationAttachmentPoints;
989}
990
991// Blanket implementation for all PdfPageAnnotation types.
992
993impl<'a, T> PdfPageAnnotationCommon for T
994where
995    T: PdfPageAnnotationPrivate<'a>,
996{
997    #[inline]
998    fn name(&self) -> Option<String> {
999        self.name_impl()
1000    }
1001
1002    #[inline]
1003    fn is_markup_annotation(&self) -> bool {
1004        self.is_markup_annotation_impl()
1005    }
1006
1007    #[inline]
1008    fn has_attachment_points(&self) -> bool {
1009        self.has_attachment_points_impl()
1010    }
1011
1012    #[inline]
1013    fn bounds(&self) -> Result<PdfRect, PdfiumError> {
1014        self.bounds_impl()
1015    }
1016
1017    #[inline]
1018    fn set_bounds(&mut self, bounds: PdfRect) -> Result<(), PdfiumError> {
1019        self.set_bounds_impl(bounds)
1020    }
1021
1022    #[inline]
1023    fn set_position(&mut self, x: PdfPoints, y: PdfPoints) -> Result<(), PdfiumError> {
1024        self.set_position_impl(x, y)
1025    }
1026
1027    #[inline]
1028    fn set_width(&mut self, width: PdfPoints) -> Result<(), PdfiumError> {
1029        self.set_width_impl(width)
1030    }
1031
1032    #[inline]
1033    fn set_height(&mut self, height: PdfPoints) -> Result<(), PdfiumError> {
1034        self.set_height_impl(height)
1035    }
1036
1037    #[inline]
1038    fn contents(&self) -> Option<String> {
1039        self.contents_impl()
1040    }
1041
1042    #[inline]
1043    fn set_contents(&mut self, contents: &str) -> Result<(), PdfiumError> {
1044        self.set_contents_impl(contents)
1045    }
1046
1047    #[inline]
1048    fn creator(&self) -> Option<String> {
1049        self.creator_impl()
1050    }
1051
1052    #[inline]
1053    fn set_creator(&mut self, creator: &str) -> Result<(), PdfiumError> {
1054        self.set_creator_impl(creator)
1055    }
1056
1057    #[inline]
1058    fn creation_date(&self) -> Option<String> {
1059        self.creation_date_impl()
1060    }
1061
1062    #[inline]
1063    fn set_creation_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError> {
1064        self.set_creation_date_impl(date)
1065    }
1066
1067    #[inline]
1068    fn modification_date(&self) -> Option<String> {
1069        self.modification_date_impl()
1070    }
1071
1072    #[inline]
1073    fn set_modification_date(&mut self, date: DateTime<Utc>) -> Result<(), PdfiumError> {
1074        self.set_modification_date_impl(date)
1075    }
1076
1077    #[inline]
1078    fn fill_color(&self) -> Result<PdfColor, PdfiumError> {
1079        self.fill_color_impl()
1080    }
1081
1082    #[inline]
1083    fn set_fill_color(&mut self, fill_color: PdfColor) -> Result<(), PdfiumError> {
1084        self.set_fill_color_impl(fill_color)
1085    }
1086
1087    #[inline]
1088    fn stroke_color(&self) -> Result<PdfColor, PdfiumError> {
1089        self.stroke_color_impl()
1090    }
1091
1092    #[inline]
1093    fn set_stroke_color(&mut self, stroke_color: PdfColor) -> Result<(), PdfiumError> {
1094        self.set_stroke_color_impl(stroke_color)
1095    }
1096
1097    #[inline]
1098    fn objects(&self) -> &PdfPageAnnotationObjects {
1099        self.objects_impl()
1100    }
1101
1102    #[inline]
1103    fn attachment_points(&self) -> &PdfPageAnnotationAttachmentPoints {
1104        self.attachment_points_impl()
1105    }
1106}
1107
1108impl<'a> PdfPageAnnotationPrivate<'a> for PdfPageAnnotation<'a> {
1109    #[inline]
1110    fn handle(&self) -> FPDF_ANNOTATION {
1111        self.unwrap_as_trait().handle()
1112    }
1113
1114    #[inline]
1115    fn bindings(&self) -> &dyn PdfiumLibraryBindings {
1116        self.unwrap_as_trait().bindings()
1117    }
1118
1119    #[inline]
1120    fn ownership(&self) -> &PdfPageObjectOwnership {
1121        self.unwrap_as_trait().ownership()
1122    }
1123
1124    #[inline]
1125    fn objects_impl(&self) -> &PdfPageAnnotationObjects {
1126        self.unwrap_as_trait().objects_impl()
1127    }
1128
1129    #[inline]
1130    fn attachment_points_impl(&self) -> &PdfPageAnnotationAttachmentPoints {
1131        self.unwrap_as_trait().attachment_points_impl()
1132    }
1133}
1134
1135impl<'a> Drop for PdfPageAnnotation<'a> {
1136    /// Closes this [PdfPageAnnotation], releasing held memory.
1137    #[inline]
1138    fn drop(&mut self) {
1139        self.bindings().FPDFPage_CloseAnnot(self.handle());
1140    }
1141}