7 #ifndef PDF_ANNOTATION_H
8 #define PDF_ANNOTATION_H
10 #include "PdfElement.h"
11 #include <podofo/auxiliary/Rect.h>
18 class PdfAnnotationText;
19 class PdfAnnotationLink;
20 class PdfAnnotationFreeText;
21 class PdfAnnotationLine;
22 class PdfAnnotationSquare;
23 class PdfAnnotationCircle;
24 class PdfAnnotationPolygon;
25 class PdfAnnotationPolyLine;
26 class PdfAnnotationHighlight;
27 class PdfAnnotationUnderline;
28 class PdfAnnotationSquiggly;
29 class PdfAnnotationStrikeOut;
30 class PdfAnnotationStamp;
31 class PdfAnnotationCaret;
32 class PdfAnnotationInk;
33 class PdfAnnotationPopup;
34 class PdfAnnotationFileAttachment;
35 class PdfAnnotationSound;
36 class PdfAnnotationMovie;
37 class PdfAnnotationWidget;
38 class PdfAnnotationScreen;
39 class PdfAnnotationPrinterMark;
40 class PdfAnnotationTrapNet;
41 class PdfAnnotationWatermark;
42 class PdfAnnotationModel3D;
43 class PdfAnnotationRichMedia;
44 class PdfAnnotationWebMedia;
45 class PdfAnnotationRedact;
46 class 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;
100 static bool TryCreateFromObject(
PdfObject& obj, std::unique_ptr<PdfAnnotation>& xobj);
102 static bool TryCreateFromObject(
const PdfObject& obj, std::unique_ptr<const PdfAnnotation>& xobj);
104 template <
typename TAnnotation>
105 static bool TryCreateFromObject(
PdfObject& obj, std::unique_ptr<TAnnotation>& xobj);
107 template <
typename TAnnotation>
108 static bool TryCreateFromObject(
const PdfObject& obj, std::unique_ptr<const TAnnotation>& xobj);
129 void GetAppearanceStreams(std::vector<PdfAppearanceStream>& states)
const;
131 void ClearAppearances();
136 PdfObject* GetAppearanceDictionaryObject();
137 const PdfObject* GetAppearanceDictionaryObject()
const;
150 Rect GetRect()
const;
151 Rect GetRectRaw()
const;
156 void SetRect(
const Rect& rect);
157 void SetRectRaw(
const Rect& rect);
177 void SetBorderStyle(
double hCorner,
double vCorner,
double width);
185 void SetBorderStyle(
double hCorner,
double vCorner,
double width,
const PdfArray& strokeStyle);
192 void SetTitle(nullable<const PdfString&> title);
200 nullable<const PdfString&> GetTitle()
const;
208 void SetContents(nullable<const PdfString&> contents);
216 nullable<const PdfString&> GetContents()
const;
223 PdfColor GetColor()
const;
228 void SetColor(nullable<const PdfColor&> color);
241 inline const PdfPage* GetPage()
const {
return m_Page; }
242 PdfPage& MustGetPage();
243 const PdfPage& MustGetPage()
const;
246 template <
typename TAnnot>
249 static std::unique_ptr<PdfAnnotation> Create(PdfPage& page,
PdfAnnotationType annotType,
const Rect& rect);
251 void SetPage(PdfPage& page) { m_Page = &page; }
254 static bool tryCreateFromObject(
const PdfObject& obj,
PdfAnnotationType targetType, PdfAnnotation*& xobj);
256 PdfObject* getAppearanceStream(
PdfAppearanceType appearance,
const std::string_view& state)
const;
257 PdfDictionary* getAppearanceDictionary()
const;
264 template<
typename TAnnotation>
265 bool PdfAnnotation::TryCreateFromObject(PdfObject& obj, std::unique_ptr<TAnnotation>& xobj)
267 PdfAnnotation* xobj_;
268 if (!tryCreateFromObject(obj, GetAnnotationType<TAnnotation>(), xobj_))
271 xobj.reset((TAnnotation*)xobj_);
275 template<
typename TAnnotation>
276 bool PdfAnnotation::TryCreateFromObject(
const PdfObject& obj, std::unique_ptr<const TAnnotation>& xobj)
278 PdfAnnotation* xobj_;
279 if (!tryCreateFromObject(obj, GetAnnotationType<TAnnotation>(), xobj_))
282 xobj.reset((
const TAnnotation*)xobj_);
286 template<
typename TAnnot>
289 if (std::is_same_v<TAnnot, PdfAnnotationText>)
290 return PdfAnnotationType::Text;
291 else if (std::is_same_v<TAnnot, PdfAnnotationLink>)
292 return PdfAnnotationType::Link;
293 else if (std::is_same_v<TAnnot, PdfAnnotationFreeText>)
294 return PdfAnnotationType::FreeText;
295 else if (std::is_same_v<TAnnot, PdfAnnotationLine>)
296 return PdfAnnotationType::Line;
297 else if (std::is_same_v<TAnnot, PdfAnnotationSquare>)
298 return PdfAnnotationType::Square;
299 else if (std::is_same_v<TAnnot, PdfAnnotationCircle>)
300 return PdfAnnotationType::Circle;
301 else if (std::is_same_v<TAnnot, PdfAnnotationPolygon>)
302 return PdfAnnotationType::Polygon;
303 else if (std::is_same_v<TAnnot, PdfAnnotationPolyLine>)
304 return PdfAnnotationType::PolyLine;
305 else if (std::is_same_v<TAnnot, PdfAnnotationHighlight>)
306 return PdfAnnotationType::Highlight;
307 else if (std::is_same_v<TAnnot, PdfAnnotationUnderline>)
308 return PdfAnnotationType::Underline;
309 else if (std::is_same_v<TAnnot, PdfAnnotationSquiggly>)
310 return PdfAnnotationType::Squiggly;
311 else if (std::is_same_v<TAnnot, PdfAnnotationStrikeOut>)
312 return PdfAnnotationType::StrikeOut;
313 else if (std::is_same_v<TAnnot, PdfAnnotationStamp>)
314 return PdfAnnotationType::Stamp;
315 else if (std::is_same_v<TAnnot, PdfAnnotationCaret>)
316 return PdfAnnotationType::Caret;
317 else if (std::is_same_v<TAnnot, PdfAnnotationInk>)
318 return PdfAnnotationType::Ink;
319 else if (std::is_same_v<TAnnot, PdfAnnotationPopup>)
320 return PdfAnnotationType::Popup;
321 else if (std::is_same_v<TAnnot, PdfAnnotationFileAttachment>)
322 return PdfAnnotationType::FileAttachement;
323 else if (std::is_same_v<TAnnot, PdfAnnotationSound>)
324 return PdfAnnotationType::Sound;
325 else if (std::is_same_v<TAnnot, PdfAnnotationMovie>)
326 return PdfAnnotationType::Movie;
327 else if (std::is_same_v<TAnnot, PdfAnnotationWidget>)
328 return PdfAnnotationType::Widget;
329 else if (std::is_same_v<TAnnot, PdfAnnotationScreen>)
330 return PdfAnnotationType::Screen;
331 else if (std::is_same_v<TAnnot, PdfAnnotationPrinterMark>)
332 return PdfAnnotationType::PrinterMark;
333 else if (std::is_same_v<TAnnot, PdfAnnotationTrapNet>)
334 return PdfAnnotationType::TrapNet;
335 else if (std::is_same_v<TAnnot, PdfAnnotationWatermark>)
336 return PdfAnnotationType::Watermark;
337 else if (std::is_same_v<TAnnot, PdfAnnotationModel3D>)
338 return PdfAnnotationType::Model3D;
339 else if (std::is_same_v<TAnnot, PdfAnnotationRichMedia>)
340 return PdfAnnotationType::RichMedia;
341 else if (std::is_same_v<TAnnot, PdfAnnotationWebMedia>)
342 return PdfAnnotationType::WebMedia;
343 else if (std::is_same_v<TAnnot, PdfAnnotationRedact>)
344 return PdfAnnotationType::Redact;
345 else if (std::is_same_v<TAnnot, PdfAnnotationProjection>)
346 return PdfAnnotationType::Projection;
348 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:234
PdfPage * GetPage()
Get the page of this PdfField.
Definition: PdfAnnotation.h:240
PdfObject * GetAppearanceStream(PdfAppearanceType appearance=PdfAppearanceType::Normal, const std::string_view &state={ })
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:127
A rectangle defined by position and size.
Definition: Rect.h:20
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:559
PdfAppearanceType
Type of the annotation appearance.
Definition: PdfDeclarations.h:653
@ Normal
Normal appearance.
PdfAnnotationFlags
Flags that control the appearance of a PdfAnnotation.
Definition: PdfDeclarations.h:597
Templatized object type getter helper.
Definition: PdfObject.h:607
A qualified appearance stream, with type and state name.
Definition: PdfAnnotation.h:51