Skip to main content

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