7#ifndef PDF_ANNOTATION_H
8#define PDF_ANNOTATION_H
10#include "PdfElement.h"
11#include <podofo/auxiliary/Rect.h>
18class PdfAnnotationText;
19class PdfAnnotationLink;
20class PdfAnnotationFreeText;
21class PdfAnnotationLine;
22class PdfAnnotationSquare;
23class PdfAnnotationCircle;
24class PdfAnnotationPolygon;
25class PdfAnnotationPolyLine;
26class PdfAnnotationHighlight;
27class PdfAnnotationUnderline;
28class PdfAnnotationSquiggly;
29class PdfAnnotationStrikeOut;
30class PdfAnnotationStamp;
31class PdfAnnotationCaret;
32class PdfAnnotationInk;
33class PdfAnnotationPopup;
34class PdfAnnotationFileAttachment;
35class PdfAnnotationSound;
36class PdfAnnotationMovie;
37class PdfAnnotationWidget;
38class PdfAnnotationScreen;
39class PdfAnnotationPrinterMark;
40class PdfAnnotationTrapNet;
41class PdfAnnotationWatermark;
42class PdfAnnotationModel3D;
43class PdfAnnotationRichMedia;
44class PdfAnnotationWebMedia;
45class PdfAnnotationRedact;
46class PdfAnnotationProjection;
64 friend class PdfAnnotationCollection;
65 friend class PdfAnnotationTextMarkupBase;
66 friend class PdfAnnotationPopup;
67 friend class PdfAnnotationText;
68 friend class PdfAnnotationCaret;
69 friend class PdfAnnotationFileAttachment;
70 friend class PdfAnnotationFreeText;
71 friend class PdfAnnotationHighlight;
72 friend class PdfAnnotationInk;
73 friend class PdfAnnotationLine;
74 friend class PdfAnnotationModel3D;
75 friend class PdfAnnotationMovie;
76 friend class PdfAnnotationPolygon;
77 friend class PdfAnnotationPolyLine;
78 friend class PdfAnnotationPrinterMark;
79 friend class PdfAnnotationRichMedia;
80 friend class PdfAnnotationScreen;
81 friend class PdfAnnotationSquiggly;
82 friend class PdfAnnotationStrikeOut;
83 friend class PdfAnnotationSound;
84 friend class PdfAnnotationSquare;
85 friend class PdfAnnotationCircle;
86 friend class PdfAnnotationStamp;
87 friend class PdfAnnotationTrapNet;
88 friend class PdfAnnotationUnderline;
89 friend class PdfAnnotationWatermark;
90 friend class PdfAnnotationWebMedia;
91 friend class PdfAnnotationRedact;
92 friend class PdfAnnotationProjection;
93 friend class PdfAnnotationActionBase;
94 friend class PdfToggleButton;
102 static bool TryCreateFromObject(
PdfObject&
obj, std::unique_ptr<PdfAnnotation>&
xobj);
104 static bool TryCreateFromObject(
const PdfObject&
obj, std::unique_ptr<const PdfAnnotation>&
xobj);
106 template <
typename TAnnotation>
107 static bool TryCreateFromObject(
PdfObject&
obj, std::unique_ptr<TAnnotation>&
xobj);
109 template <
typename TAnnotation>
110 static bool TryCreateFromObject(
const PdfObject&
obj, std::unique_ptr<const TAnnotation>&
xobj);
135 void GetAppearanceStreams(std::vector<PdfAppearanceStream>&
states)
const;
137 void ClearAppearances();
142 PdfObject* GetAppearanceDictionaryObject();
143 const PdfObject* GetAppearanceDictionaryObject()
const;
156 Rect GetRect()
const;
161 void SetRect(
const Rect& rect);
163 Corners GetRectRaw()
const;
165 void SetRectRaw(
const Corners& rect);
170 void SetFlags(PdfAnnotationFlags flags);
178 PdfAnnotationFlags GetFlags()
const;
185 void SetBorderStyle(
double hCorner,
double vCorner,
double width);
193 void SetBorderStyle(
double hCorner,
double vCorner,
double width,
const PdfArray& strokeStyle);
200 void SetTitle(nullable<const PdfString&> title);
208 nullable<const PdfString&> GetTitle()
const;
216 void SetContents(nullable<const PdfString&> contents);
224 nullable<const PdfString&> GetContents()
const;
231 PdfColor GetColor()
const;
236 void SetColor(nullable<const PdfColor&> color);
249 inline const PdfPage* GetPage()
const {
return m_Page; }
250 PdfPage& MustGetPage();
251 const PdfPage& MustGetPage()
const;
254 template <
typename TAnnot>
255 static constexpr PdfAnnotationType GetAnnotationType();
257 static std::unique_ptr<PdfAnnotation> Create(PdfPage& page, PdfAnnotationType annotType,
const Rect& rect);
259 void SetPage(PdfPage& page) { m_Page = &page; }
261 void PushAppearanceStream(
const PdfXObject& xobj, PdfAppearanceType appearance,
const PdfName& state,
bool raw);
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_))
281 xobj.reset((TAnnotation*)xobj_);
285template<
typename TAnnotation>
286bool PdfAnnotation::TryCreateFromObject(
const PdfObject& obj, std::unique_ptr<const TAnnotation>& xobj)
288 PdfAnnotation* xobj_;
289 if (!tryCreateFromObject(obj, GetAnnotationType<TAnnotation>(), xobj_))
292 xobj.reset((
const TAnnotation*)xobj_);
296template<
typename TAnnot>
299 if (std::is_same_v<TAnnot, PdfAnnotationText>)
300 return PdfAnnotationType::Text;
301 else if (std::is_same_v<TAnnot, PdfAnnotationLink>)
302 return PdfAnnotationType::Link;
303 else if (std::is_same_v<TAnnot, PdfAnnotationFreeText>)
304 return PdfAnnotationType::FreeText;
305 else if (std::is_same_v<TAnnot, PdfAnnotationLine>)
306 return PdfAnnotationType::Line;
307 else if (std::is_same_v<TAnnot, PdfAnnotationSquare>)
308 return PdfAnnotationType::Square;
309 else if (std::is_same_v<TAnnot, PdfAnnotationCircle>)
310 return PdfAnnotationType::Circle;
311 else if (std::is_same_v<TAnnot, PdfAnnotationPolygon>)
312 return PdfAnnotationType::Polygon;
313 else if (std::is_same_v<TAnnot, PdfAnnotationPolyLine>)
314 return PdfAnnotationType::PolyLine;
315 else if (std::is_same_v<TAnnot, PdfAnnotationHighlight>)
316 return PdfAnnotationType::Highlight;
317 else if (std::is_same_v<TAnnot, PdfAnnotationUnderline>)
318 return PdfAnnotationType::Underline;
319 else if (std::is_same_v<TAnnot, PdfAnnotationSquiggly>)
320 return PdfAnnotationType::Squiggly;
321 else if (std::is_same_v<TAnnot, PdfAnnotationStrikeOut>)
322 return PdfAnnotationType::StrikeOut;
323 else if (std::is_same_v<TAnnot, PdfAnnotationStamp>)
324 return PdfAnnotationType::Stamp;
325 else if (std::is_same_v<TAnnot, PdfAnnotationCaret>)
326 return PdfAnnotationType::Caret;
327 else if (std::is_same_v<TAnnot, PdfAnnotationInk>)
328 return PdfAnnotationType::Ink;
329 else if (std::is_same_v<TAnnot, PdfAnnotationPopup>)
330 return PdfAnnotationType::Popup;
331 else if (std::is_same_v<TAnnot, PdfAnnotationFileAttachment>)
332 return PdfAnnotationType::FileAttachement;
333 else if (std::is_same_v<TAnnot, PdfAnnotationSound>)
334 return PdfAnnotationType::Sound;
335 else if (std::is_same_v<TAnnot, PdfAnnotationMovie>)
336 return PdfAnnotationType::Movie;
337 else if (std::is_same_v<TAnnot, PdfAnnotationWidget>)
338 return PdfAnnotationType::Widget;
339 else if (std::is_same_v<TAnnot, PdfAnnotationScreen>)
340 return PdfAnnotationType::Screen;
341 else if (std::is_same_v<TAnnot, PdfAnnotationPrinterMark>)
342 return PdfAnnotationType::PrinterMark;
343 else if (std::is_same_v<TAnnot, PdfAnnotationTrapNet>)
344 return PdfAnnotationType::TrapNet;
345 else if (std::is_same_v<TAnnot, PdfAnnotationWatermark>)
346 return PdfAnnotationType::Watermark;
347 else if (std::is_same_v<TAnnot, PdfAnnotationModel3D>)
348 return PdfAnnotationType::Model3D;
349 else if (std::is_same_v<TAnnot, PdfAnnotationRichMedia>)
350 return PdfAnnotationType::RichMedia;
351 else if (std::is_same_v<TAnnot, PdfAnnotationWebMedia>)
352 return PdfAnnotationType::WebMedia;
353 else if (std::is_same_v<TAnnot, PdfAnnotationRedact>)
354 return PdfAnnotationType::Redact;
355 else if (std::is_same_v<TAnnot, PdfAnnotationProjection>)
356 return PdfAnnotationType::Projection;
358 return PdfAnnotationType::Unknown;
An annotation to a PdfPage To create an annotation use PdfPage::CreateAnnotation.
Definition PdfAnnotation.h:63
PdfAnnotationType GetType() const
Get the type of this annotation.
Definition PdfAnnotation.h:242
PdfObject * GetAppearanceStream(PdfAppearanceType appearance=PdfAppearanceType::Normal, const std::string_view &state={ })
PdfPage * GetPage()
Get the page of this PdfField.
Definition PdfAnnotation.h:248
This class represents a PdfName.
Definition PdfName.h:24
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:35
PdfPage is one page in the pdf document.
Definition PdfPage.h:129
A XObject is a content stream with several drawing commands and data which can be used throughout a P...
Definition PdfXObject.h:31
An normalized rectangle defined by position (left-bottom) and size.
Definition Rect.h:20
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:38
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition basetypes.h:16
PdfAnnotationType
The type of the annotation.
Definition PdfDeclarations.h:595
PdfAppearanceType
Type of the annotation appearance.
Definition PdfDeclarations.h:689
Templatized object type getter helper.
Definition PdfObject.h:609
A qualified appearance stream, with type and state name.
Definition PdfAnnotation.h:51