5#ifndef PDF_ANNOTATION_H
6#define PDF_ANNOTATION_H
9#include <podofo/auxiliary/Rect.h>
16class PdfAnnotationText;
17class PdfAnnotationLink;
18class PdfAnnotationFreeText;
19class PdfAnnotationLine;
20class PdfAnnotationSquare;
21class PdfAnnotationCircle;
22class PdfAnnotationPolygon;
23class PdfAnnotationPolyLine;
24class PdfAnnotationHighlight;
25class PdfAnnotationUnderline;
26class PdfAnnotationSquiggly;
27class PdfAnnotationStrikeOut;
28class PdfAnnotationStamp;
29class PdfAnnotationCaret;
30class PdfAnnotationInk;
31class PdfAnnotationPopup;
32class PdfAnnotationFileAttachment;
33class PdfAnnotationSound;
34class PdfAnnotationMovie;
35class PdfAnnotationWidget;
36class PdfAnnotationScreen;
37class PdfAnnotationPrinterMark;
38class PdfAnnotationTrapNet;
39class PdfAnnotationWatermark;
40class PdfAnnotationModel3D;
41class PdfAnnotationRichMedia;
42class PdfAnnotationWebMedia;
43class PdfAnnotationRedact;
44class PdfAnnotationProjection;
60 friend class PdfAnnotationCollection;
61 friend class PdfAnnotationTextMarkupBase;
62 friend class PdfAnnotationPopup;
63 friend class PdfAnnotationText;
64 friend class PdfAnnotationCaret;
65 friend class PdfAnnotationFileAttachment;
66 friend class PdfAnnotationFreeText;
67 friend class PdfAnnotationHighlight;
68 friend class PdfAnnotationInk;
69 friend class PdfAnnotationLine;
70 friend class PdfAnnotationModel3D;
71 friend class PdfAnnotationMovie;
72 friend class PdfAnnotationPolygon;
73 friend class PdfAnnotationPolyLine;
74 friend class PdfAnnotationPrinterMark;
75 friend class PdfAnnotationRichMedia;
76 friend class PdfAnnotationScreen;
77 friend class PdfAnnotationSquiggly;
78 friend class PdfAnnotationStrikeOut;
79 friend class PdfAnnotationSound;
80 friend class PdfAnnotationSquare;
81 friend class PdfAnnotationCircle;
82 friend class PdfAnnotationStamp;
83 friend class PdfAnnotationTrapNet;
84 friend class PdfAnnotationUnderline;
85 friend class PdfAnnotationWatermark;
86 friend class PdfAnnotationWebMedia;
87 friend class PdfAnnotationRedact;
88 friend class PdfAnnotationProjection;
89 friend class PdfAnnotationActionBase;
90 friend class PdfToggleButton;
98 static bool TryCreateFromObject(
PdfObject&
obj, std::unique_ptr<PdfAnnotation>&
xobj);
100 static bool TryCreateFromObject(
const PdfObject&
obj, std::unique_ptr<const PdfAnnotation>&
xobj);
102 template <
typename TAnnotation>
103 static bool TryCreateFromObject(
PdfObject&
obj, std::unique_ptr<TAnnotation>&
xobj);
105 template <
typename TAnnotation>
106 static bool TryCreateFromObject(
const PdfObject&
obj, std::unique_ptr<const TAnnotation>&
xobj);
129 void GetAppearanceStreams(std::vector<PdfAppearanceStream>&
states)
const;
131 void ClearAppearances();
134 PdfObject* GetAppearanceDictionaryObject();
135 const PdfObject* GetAppearanceDictionaryObject()
const;
145 Rect GetRect()
const;
149 void SetRect(
const Rect& rect);
151 Corners GetRectRaw()
const;
153 void SetRectRaw(
const Corners& rect);
157 void SetFlags(PdfAnnotationFlags flags);
164 PdfAnnotationFlags GetFlags()
const;
170 void SetBorderStyle(
double hCorner,
double vCorner,
double width);
177 void SetBorderStyle(
double hCorner,
double vCorner,
double width,
const PdfArray& strokeStyle);
183 void SetTitle(nullable<const PdfString&> title);
190 nullable<const PdfString&> GetTitle()
const;
197 void SetContents(nullable<const PdfString&> contents);
204 nullable<const PdfString&> GetContents()
const;
211 PdfColor GetColor()
const;
216 void SetColor(nullable<const PdfColor&> color);
227 inline const PdfPage* GetPage()
const {
return m_Page; }
228 PdfPage& MustGetPage();
229 const PdfPage& MustGetPage()
const;
232 template <
typename TAnnot>
233 static constexpr PdfAnnotationType GetAnnotationType();
235 static std::unique_ptr<PdfAnnotation> Create(PdfPage& page, PdfAnnotationType annotType,
const Rect& rect);
237 void SetPage(PdfPage& page) { m_Page = &page; }
239 void PushAppearanceStream(
const PdfXObject& xobj, PdfAppearanceType appearance,
const PdfName& state,
bool raw);
242 static bool tryCreateFromObject(
const PdfObject& obj, PdfAnnotationType targetType, PdfAnnotation*& xobj);
244 PdfObject* getAppearanceStream(PdfAppearanceType appearance,
const std::string_view& state)
const;
245 PdfDictionary* getAppearanceDictionary()
const;
252template<
typename TAnnotation>
253bool PdfAnnotation::TryCreateFromObject(PdfObject& obj, std::unique_ptr<TAnnotation>& xobj)
255 PdfAnnotation* xobj_;
256 if (!tryCreateFromObject(obj, GetAnnotationType<TAnnotation>(), xobj_))
259 xobj.reset((TAnnotation*)xobj_);
263template<
typename TAnnotation>
264bool PdfAnnotation::TryCreateFromObject(
const PdfObject& obj, std::unique_ptr<const TAnnotation>& xobj)
266 PdfAnnotation* xobj_;
267 if (!tryCreateFromObject(obj, GetAnnotationType<TAnnotation>(), xobj_))
270 xobj.reset((
const TAnnotation*)xobj_);
274template<
typename TAnnot>
277 if (std::is_same_v<TAnnot, PdfAnnotationText>)
278 return PdfAnnotationType::Text;
279 else if (std::is_same_v<TAnnot, PdfAnnotationLink>)
280 return PdfAnnotationType::Link;
281 else if (std::is_same_v<TAnnot, PdfAnnotationFreeText>)
282 return PdfAnnotationType::FreeText;
283 else if (std::is_same_v<TAnnot, PdfAnnotationLine>)
284 return PdfAnnotationType::Line;
285 else if (std::is_same_v<TAnnot, PdfAnnotationSquare>)
286 return PdfAnnotationType::Square;
287 else if (std::is_same_v<TAnnot, PdfAnnotationCircle>)
288 return PdfAnnotationType::Circle;
289 else if (std::is_same_v<TAnnot, PdfAnnotationPolygon>)
290 return PdfAnnotationType::Polygon;
291 else if (std::is_same_v<TAnnot, PdfAnnotationPolyLine>)
292 return PdfAnnotationType::PolyLine;
293 else if (std::is_same_v<TAnnot, PdfAnnotationHighlight>)
294 return PdfAnnotationType::Highlight;
295 else if (std::is_same_v<TAnnot, PdfAnnotationUnderline>)
296 return PdfAnnotationType::Underline;
297 else if (std::is_same_v<TAnnot, PdfAnnotationSquiggly>)
298 return PdfAnnotationType::Squiggly;
299 else if (std::is_same_v<TAnnot, PdfAnnotationStrikeOut>)
300 return PdfAnnotationType::StrikeOut;
301 else if (std::is_same_v<TAnnot, PdfAnnotationStamp>)
302 return PdfAnnotationType::Stamp;
303 else if (std::is_same_v<TAnnot, PdfAnnotationCaret>)
304 return PdfAnnotationType::Caret;
305 else if (std::is_same_v<TAnnot, PdfAnnotationInk>)
306 return PdfAnnotationType::Ink;
307 else if (std::is_same_v<TAnnot, PdfAnnotationPopup>)
308 return PdfAnnotationType::Popup;
309 else if (std::is_same_v<TAnnot, PdfAnnotationFileAttachment>)
310 return PdfAnnotationType::FileAttachement;
311 else if (std::is_same_v<TAnnot, PdfAnnotationSound>)
312 return PdfAnnotationType::Sound;
313 else if (std::is_same_v<TAnnot, PdfAnnotationMovie>)
314 return PdfAnnotationType::Movie;
315 else if (std::is_same_v<TAnnot, PdfAnnotationWidget>)
316 return PdfAnnotationType::Widget;
317 else if (std::is_same_v<TAnnot, PdfAnnotationScreen>)
318 return PdfAnnotationType::Screen;
319 else if (std::is_same_v<TAnnot, PdfAnnotationPrinterMark>)
320 return PdfAnnotationType::PrinterMark;
321 else if (std::is_same_v<TAnnot, PdfAnnotationTrapNet>)
322 return PdfAnnotationType::TrapNet;
323 else if (std::is_same_v<TAnnot, PdfAnnotationWatermark>)
324 return PdfAnnotationType::Watermark;
325 else if (std::is_same_v<TAnnot, PdfAnnotationModel3D>)
326 return PdfAnnotationType::Model3D;
327 else if (std::is_same_v<TAnnot, PdfAnnotationRichMedia>)
328 return PdfAnnotationType::RichMedia;
329 else if (std::is_same_v<TAnnot, PdfAnnotationWebMedia>)
330 return PdfAnnotationType::WebMedia;
331 else if (std::is_same_v<TAnnot, PdfAnnotationRedact>)
332 return PdfAnnotationType::Redact;
333 else if (std::is_same_v<TAnnot, PdfAnnotationProjection>)
334 return PdfAnnotationType::Projection;
336 return PdfAnnotationType::Unknown;
An annotation to a PdfPage To create an annotation use PdfPage::CreateAnnotation.
Definition PdfAnnotation.h:59
PdfAnnotationType GetType() const
Get the type of this annotation.
Definition PdfAnnotation.h:221
PdfObject * GetAppearanceStream(PdfAppearanceType appearance=PdfAppearanceType::Normal, const std::string_view &state={ })
PdfPage * GetPage()
Get the page of this PdfField.
Definition PdfAnnotation.h:226
This class represents a PdfName.
Definition PdfName.h:21
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:31
PdfPage is one page in the pdf document.
Definition PdfPage.h:133
A XObject is a content stream with several drawing commands and data which can be used throughout a P...
Definition PdfXObject.h:28
An normalized rectangle defined by position (left-bottom) and size.
Definition Rect.h:17
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:30
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13
PdfAnnotationType
The type of the annotation.
Definition PdfDeclarations.h:557
PdfAppearanceType
Type of the annotation appearance.
Definition PdfDeclarations.h:646
A qualified appearance stream, with type and state name.
Definition PdfAnnotation.h:48