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;
69 friend class PdfAnnotationCollection;
70 friend class PdfAnnotationTextMarkupBase;
71 friend class PdfAnnotationPopup;
72 friend class PdfAnnotationText;
73 friend class PdfAnnotationCaret;
74 friend class PdfAnnotationFileAttachment;
75 friend class PdfAnnotationFreeText;
76 friend class PdfAnnotationHighlight;
77 friend class PdfAnnotationInk;
78 friend class PdfAnnotationLine;
79 friend class PdfAnnotationModel3D;
80 friend class PdfAnnotationMovie;
81 friend class PdfAnnotationPolygon;
82 friend class PdfAnnotationPolyLine;
83 friend class PdfAnnotationPrinterMark;
84 friend class PdfAnnotationRichMedia;
85 friend class PdfAnnotationScreen;
86 friend class PdfAnnotationSquiggly;
87 friend class PdfAnnotationStrikeOut;
88 friend class PdfAnnotationSound;
89 friend class PdfAnnotationSquare;
90 friend class PdfAnnotationCircle;
91 friend class PdfAnnotationStamp;
92 friend class PdfAnnotationTrapNet;
93 friend class PdfAnnotationUnderline;
94 friend class PdfAnnotationWatermark;
95 friend class PdfAnnotationWebMedia;
96 friend class PdfAnnotationRedact;
97 friend class PdfAnnotationProjection;
98 friend class PdfAnnotationActionBase;
99 friend class PdfToggleButton;
107 static bool TryCreateFromObject(
PdfObject&
obj, std::unique_ptr<PdfAnnotation>&
xobj);
109 static bool TryCreateFromObject(
const PdfObject&
obj, std::unique_ptr<const PdfAnnotation>&
xobj);
111 template <
typename TAnnotation>
112 static bool TryCreateFromObject(
PdfObject&
obj, std::unique_ptr<TAnnotation>&
xobj);
114 template <
typename TAnnotation>
115 static bool TryCreateFromObject(
const PdfObject&
obj, std::unique_ptr<const TAnnotation>&
xobj);
136 [[deprecated(
"Use the SetAppearanceStream methods with flags instead")]]
146 [[deprecated(
"Use the SetAppearanceStream methods with flags instead")]]
152 void GetAppearanceStreams(std::vector<PdfAppearanceStream>&
states)
const;
154 void ClearAppearances();
157 PdfObject* GetAppearanceDictionaryObject();
158 const PdfObject* GetAppearanceDictionaryObject()
const;
168 Rect GetRect()
const;
172 void SetRect(
const Rect& rect);
174 Corners GetRectRaw()
const;
176 void SetRectRaw(
const Corners& rect);
180 void SetFlags(PdfAnnotationFlags flags);
187 PdfAnnotationFlags GetFlags()
const;
193 void SetBorderStyle(
double hCorner,
double vCorner,
double width);
200 void SetBorderStyle(
double hCorner,
double vCorner,
double width,
const PdfArray& strokeStyle);
206 void SetTitle(nullable<const PdfString&> title);
213 nullable<const PdfString&> GetTitle()
const;
220 void SetContents(nullable<const PdfString&> contents);
227 nullable<const PdfString&> GetContents()
const;
234 PdfColor GetColor()
const;
239 void SetColor(nullable<const PdfColor&> color);
250 inline const PdfPage* GetPage()
const {
return m_Page; }
251 PdfPage& MustGetPage();
252 const PdfPage& MustGetPage()
const;
255 template <
typename TAnnot>
256 static constexpr PdfAnnotationType GetAnnotationType();
258 static std::unique_ptr<PdfAnnotation> Create(PdfPage& page, PdfAnnotationType annotType,
const Rect& rect);
260 void SetPage(PdfPage& page) { m_Page = &page; }
263 void setAppearanceStream(PdfXObject& xobj, PdfSetAppearanceFlags flags, PdfAppearanceType appearance,
const PdfName& state);
264 static bool tryCreateFromObject(
const PdfObject& obj, PdfAnnotationType targetType, PdfAnnotation*& xobj);
266 PdfObject* getAppearanceStream(PdfAppearanceType appearance,
const std::string_view& state)
const;
267 PdfDictionary* getAppearanceDictionary()
const;
274template<
typename TAnnotation>
275bool PdfAnnotation::TryCreateFromObject(PdfObject& obj, std::unique_ptr<TAnnotation>& xobj)
277 PdfAnnotation* xobj_;
278 if (!tryCreateFromObject(obj, GetAnnotationType<TAnnotation>(), xobj_))
282 std::unique_ptr<PdfAnnotation> created(xobj_);
283 if (
dynamic_cast<TAnnotation*
>(created.get()) ==
nullptr)
286 xobj.reset(
static_cast<TAnnotation*
>(created.release()));
290template<
typename TAnnotation>
291bool PdfAnnotation::TryCreateFromObject(
const PdfObject& obj, std::unique_ptr<const TAnnotation>& xobj)
293 PdfAnnotation* xobj_;
294 if (!tryCreateFromObject(obj, GetAnnotationType<TAnnotation>(), xobj_))
297 std::unique_ptr<const PdfAnnotation> created(xobj_);
298 if (
dynamic_cast<const TAnnotation*
>(created.get()) ==
nullptr)
301 xobj.reset(
static_cast<const TAnnotation*
>(created.release()));
305template<
typename TAnnot>
308 if (std::is_same_v<TAnnot, PdfAnnotationText>)
309 return PdfAnnotationType::Text;
310 else if (std::is_same_v<TAnnot, PdfAnnotationLink>)
311 return PdfAnnotationType::Link;
312 else if (std::is_same_v<TAnnot, PdfAnnotationFreeText>)
313 return PdfAnnotationType::FreeText;
314 else if (std::is_same_v<TAnnot, PdfAnnotationLine>)
315 return PdfAnnotationType::Line;
316 else if (std::is_same_v<TAnnot, PdfAnnotationSquare>)
317 return PdfAnnotationType::Square;
318 else if (std::is_same_v<TAnnot, PdfAnnotationCircle>)
319 return PdfAnnotationType::Circle;
320 else if (std::is_same_v<TAnnot, PdfAnnotationPolygon>)
321 return PdfAnnotationType::Polygon;
322 else if (std::is_same_v<TAnnot, PdfAnnotationPolyLine>)
323 return PdfAnnotationType::PolyLine;
324 else if (std::is_same_v<TAnnot, PdfAnnotationHighlight>)
325 return PdfAnnotationType::Highlight;
326 else if (std::is_same_v<TAnnot, PdfAnnotationUnderline>)
327 return PdfAnnotationType::Underline;
328 else if (std::is_same_v<TAnnot, PdfAnnotationSquiggly>)
329 return PdfAnnotationType::Squiggly;
330 else if (std::is_same_v<TAnnot, PdfAnnotationStrikeOut>)
331 return PdfAnnotationType::StrikeOut;
332 else if (std::is_same_v<TAnnot, PdfAnnotationStamp>)
333 return PdfAnnotationType::Stamp;
334 else if (std::is_same_v<TAnnot, PdfAnnotationCaret>)
335 return PdfAnnotationType::Caret;
336 else if (std::is_same_v<TAnnot, PdfAnnotationInk>)
337 return PdfAnnotationType::Ink;
338 else if (std::is_same_v<TAnnot, PdfAnnotationPopup>)
339 return PdfAnnotationType::Popup;
340 else if (std::is_same_v<TAnnot, PdfAnnotationFileAttachment>)
341 return PdfAnnotationType::FileAttachement;
342 else if (std::is_same_v<TAnnot, PdfAnnotationSound>)
343 return PdfAnnotationType::Sound;
344 else if (std::is_same_v<TAnnot, PdfAnnotationMovie>)
345 return PdfAnnotationType::Movie;
346 else if (std::is_same_v<TAnnot, PdfAnnotationWidget>)
347 return PdfAnnotationType::Widget;
348 else if (std::is_same_v<TAnnot, PdfAnnotationScreen>)
349 return PdfAnnotationType::Screen;
350 else if (std::is_same_v<TAnnot, PdfAnnotationPrinterMark>)
351 return PdfAnnotationType::PrinterMark;
352 else if (std::is_same_v<TAnnot, PdfAnnotationTrapNet>)
353 return PdfAnnotationType::TrapNet;
354 else if (std::is_same_v<TAnnot, PdfAnnotationWatermark>)
355 return PdfAnnotationType::Watermark;
356 else if (std::is_same_v<TAnnot, PdfAnnotationModel3D>)
357 return PdfAnnotationType::Model3D;
358 else if (std::is_same_v<TAnnot, PdfAnnotationRichMedia>)
359 return PdfAnnotationType::RichMedia;
360 else if (std::is_same_v<TAnnot, PdfAnnotationWebMedia>)
361 return PdfAnnotationType::WebMedia;
362 else if (std::is_same_v<TAnnot, PdfAnnotationRedact>)
363 return PdfAnnotationType::Redact;
364 else if (std::is_same_v<TAnnot, PdfAnnotationProjection>)
365 return PdfAnnotationType::Projection;
367 return PdfAnnotationType::Unknown;
An annotation to a PdfPage To create an annotation use PdfPage::CreateAnnotation.
Definition PdfAnnotation.h:68
PdfAnnotationType GetType() const
Get the type of this annotation.
Definition PdfAnnotation.h:244
PdfObject * GetAppearanceStream(PdfAppearanceType appearance=PdfAppearanceType::Normal, const std::string_view &state={ })
PdfPage * GetPage()
Get the page of this PdfField.
Definition PdfAnnotation.h:249
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:566
PdfSetAppearanceFlags
Definition PdfAnnotation.h:55
@ Raw
Insert the appearance stream without handling page rotations.
@ SkipSelectedState
Skip setting the selected state.
@ InplaceRotation
Try skip inserting a XObject trampoline for the appearance stream in case of page rotations.
@ None
Do not add a default appearance.
PdfAppearanceType
Type of the annotation appearance.
Definition PdfDeclarations.h:655
A qualified appearance stream, with type and state name.
Definition PdfAnnotation.h:48