1//========================================================================
2//
3// Annot.h
4//
5// Copyright 2000-2003 Glyph & Cog, LLC
6//
7//========================================================================
8
9//========================================================================
10//
11// Modified under the Poppler project - http://poppler.freedesktop.org
12//
13// All changes made under the Poppler project to this file are licensed
14// under GPL version 2 or later
15//
16// Copyright (C) 2006 Scott Turner <scotty1024@mac.com>
17// Copyright (C) 2007, 2008 Julien Rebetez <julienr@svn.gnome.org>
18// Copyright (C) 2007-2011, 2013, 2015, 2018 Carlos Garcia Campos <carlosgc@gnome.org>
19// Copyright (C) 2007, 2008 Iñigo Martínez <inigomartinez@gmail.com>
20// Copyright (C) 2008 Michael Vrable <mvrable@cs.ucsd.edu>
21// Copyright (C) 2008 Hugo Mercier <hmercier31@gmail.com>
22// Copyright (C) 2008 Pino Toscano <pino@kde.org>
23// Copyright (C) 2008 Tomas Are Haavet <tomasare@gmail.com>
24// Copyright (C) 2009-2011, 2013, 2016-2023 Albert Astals Cid <aacid@kde.org>
25// Copyright (C) 2012, 2013 Fabio D'Urso <fabiodurso@hotmail.it>
26// Copyright (C) 2012, 2015 Tobias Koenig <tokoe@kdab.com>
27// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
28// Copyright (C) 2013, 2017, 2023 Adrian Johnson <ajohnson@redneon.com>
29// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
30// Copyright (C) 2018 Dileep Sankhla <sankhla.dileep96@gmail.com>
31// Copyright (C) 2018-2020 Tobias Deiminger <haxtibal@posteo.de>
32// Copyright (C) 2018, 2020, 2022 Oliver Sander <oliver.sander@tu-dresden.de>
33// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
34// Copyright (C) 2019 Umang Malik <umang99m@gmail.com>
35// Copyright (C) 2019 João Netto <joaonetto901@gmail.com>
36// Copyright (C) 2020 Nelson Benítez León <nbenitezl@gmail.com>
37// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by Technische Universität Dresden
38// Copyright (C) 2020 Katarina Behrens <Katarina.Behrens@cib.de>
39// Copyright (C) 2020 Thorsten Behrens <Thorsten.Behrens@CIB.de>
40// Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>.
41// Copyright (C) 2021 Zachary Travis <ztravis@everlaw.com>
42// Copyright (C) 2021 Mahmoud Ahmed Khalil <mahmoudkhalil11@gmail.com>
43// Copyright (C) 2021 Georgiy Sgibnev <georgiy@sgibnev.com>. Work sponsored by lab50.net.
44// Copyright (C) 2022 Martin <martinbts@gmx.net>
45// Copyright (C) 2024 Erich E. Hoover <erich.e.hoover@gmail.com>
46//
47// To see a description of the changes please see the Changelog file that
48// came with your tarball or type make ChangeLog if you are building from git
49//
50//========================================================================
51
52#ifndef ANNOT_H
53#define ANNOT_H
54
55#include <memory>
56#include <atomic>
57#include <mutex>
58#include <vector>
59
60#include "AnnotStampImageHelper.h"
61#include "Object.h"
62#include "poppler_private_export.h"
63
64class XRef;
65class Gfx;
66class CharCodeToUnicode;
67class GfxFont;
68class GfxResources;
69class Page;
70class PDFDoc;
71class Form;
72class FormWidget;
73class FormField;
74class FormFieldButton;
75class FormFieldText;
76class FormFieldChoice;
77class FormFieldSignature;
78class PDFRectangle;
79class Movie;
80class LinkAction;
81class Sound;
82class FileSpec;
83
84enum AnnotLineEndingStyle
85{
86 annotLineEndingSquare, // Square
87 annotLineEndingCircle, // Circle
88 annotLineEndingDiamond, // Diamond
89 annotLineEndingOpenArrow, // OpenArrow
90 annotLineEndingClosedArrow, // ClosedArrow
91 annotLineEndingNone, // None
92 annotLineEndingButt, // Butt
93 annotLineEndingROpenArrow, // ROpenArrow
94 annotLineEndingRClosedArrow, // RClosedArrow
95 annotLineEndingSlash // Slash
96};
97
98enum AnnotExternalDataType
99{
100 annotExternalDataMarkupUnknown,
101 annotExternalDataMarkup3D // Markup3D
102};
103
104enum class VariableTextQuadding
105{
106 leftJustified,
107 centered,
108 rightJustified
109};
110
111//------------------------------------------------------------------------
112// AnnotCoord
113//------------------------------------------------------------------------
114
115class AnnotCoord
116{
117public:
118 AnnotCoord() : x(0), y(0) { }
119 AnnotCoord(double _x, double _y) : x(_x), y(_y) { }
120
121 double getX() const { return x; }
122 double getY() const { return y; }
123
124protected:
125 double x, y;
126};
127
128//------------------------------------------------------------------------
129// AnnotPath
130//------------------------------------------------------------------------
131
132class POPPLER_PRIVATE_EXPORT AnnotPath
133{
134public:
135 AnnotPath();
136 explicit AnnotPath(Array *array);
137 explicit AnnotPath(std::vector<AnnotCoord> &&coords);
138 ~AnnotPath();
139
140 AnnotPath(const AnnotPath &) = delete;
141 AnnotPath &operator=(const AnnotPath &other) = delete;
142
143 double getX(int coord) const;
144 double getY(int coord) const;
145 AnnotCoord *getCoord(int coord);
146 int getCoordsLength() const { return coords.size(); }
147
148protected:
149 std::vector<AnnotCoord> coords;
150
151 void parsePathArray(Array *array);
152};
153
154//------------------------------------------------------------------------
155// AnnotCalloutLine
156//------------------------------------------------------------------------
157
158class POPPLER_PRIVATE_EXPORT AnnotCalloutLine
159{
160public:
161 AnnotCalloutLine(double x1, double y1, double x2, double y2);
162 virtual ~AnnotCalloutLine();
163
164 AnnotCalloutLine(const AnnotCalloutLine &) = delete;
165 AnnotCalloutLine &operator=(const AnnotCalloutLine &other) = delete;
166
167 double getX1() const { return coord1.getX(); }
168 double getY1() const { return coord1.getY(); }
169 double getX2() const { return coord2.getX(); }
170 double getY2() const { return coord2.getY(); }
171
172protected:
173 AnnotCoord coord1, coord2;
174};
175
176//------------------------------------------------------------------------
177// AnnotCalloutMultiLine
178//------------------------------------------------------------------------
179
180class POPPLER_PRIVATE_EXPORT AnnotCalloutMultiLine : public AnnotCalloutLine
181{
182public:
183 AnnotCalloutMultiLine(double x1, double y1, double x2, double y2, double x3, double y3);
184 ~AnnotCalloutMultiLine() override;
185
186 double getX3() const { return coord3.getX(); }
187 double getY3() const { return coord3.getY(); }
188
189protected:
190 AnnotCoord coord3;
191};
192
193//------------------------------------------------------------------------
194// AnnotBorderEffect
195//------------------------------------------------------------------------
196
197class AnnotBorderEffect
198{
199public:
200 enum AnnotBorderEffectType
201 {
202 borderEffectNoEffect, // S
203 borderEffectCloudy // C
204 };
205
206 explicit AnnotBorderEffect(Dict *dict);
207
208 AnnotBorderEffectType getEffectType() const { return effectType; }
209 double getIntensity() const { return intensity; }
210
211private:
212 AnnotBorderEffectType effectType; // S (Default S)
213 double intensity; // I (Default 0)
214};
215
216//------------------------------------------------------------------------
217// AnnotQuadrilateral
218//------------------------------------------------------------------------
219
220class POPPLER_PRIVATE_EXPORT AnnotQuadrilaterals
221{
222public:
223 class POPPLER_PRIVATE_EXPORT AnnotQuadrilateral
224 {
225 public:
226 AnnotQuadrilateral();
227 AnnotQuadrilateral(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
228
229 AnnotCoord coord1, coord2, coord3, coord4;
230 };
231
232 AnnotQuadrilaterals(Array *array, PDFRectangle *rect);
233 AnnotQuadrilaterals(std::unique_ptr<AnnotQuadrilateral[]> &&quads, int quadsLength);
234 ~AnnotQuadrilaterals();
235
236 AnnotQuadrilaterals(const AnnotQuadrilaterals &) = delete;
237 AnnotQuadrilaterals &operator=(const AnnotQuadrilaterals &other) = delete;
238
239 double getX1(int quadrilateral);
240 double getY1(int quadrilateral);
241 double getX2(int quadrilateral);
242 double getY2(int quadrilateral);
243 double getX3(int quadrilateral);
244 double getY3(int quadrilateral);
245 double getX4(int quadrilateral);
246 double getY4(int quadrilateral);
247 int getQuadrilateralsLength() const { return quadrilateralsLength; }
248
249protected:
250 std::unique_ptr<AnnotQuadrilateral[]> quadrilaterals;
251 int quadrilateralsLength;
252};
253
254//------------------------------------------------------------------------
255// AnnotBorder
256//------------------------------------------------------------------------
257
258class POPPLER_PRIVATE_EXPORT AnnotBorder
259{
260public:
261 enum AnnotBorderType
262 {
263 typeArray,
264 typeBS
265 };
266
267 enum AnnotBorderStyle
268 {
269 borderSolid, // Solid
270 borderDashed, // Dashed
271 borderBeveled, // Beveled
272 borderInset, // Inset
273 borderUnderlined // Underlined
274 };
275
276 virtual ~AnnotBorder();
277
278 AnnotBorder(const AnnotBorder &) = delete;
279 AnnotBorder &operator=(const AnnotBorder &other) = delete;
280
281 virtual void setWidth(double new_width) { width = new_width; }
282
283 virtual AnnotBorderType getType() const = 0;
284 virtual double getWidth() const { return width; }
285 virtual const std::vector<double> &getDash() const { return dash; }
286 virtual AnnotBorderStyle getStyle() const { return style; }
287
288 virtual Object writeToObject(XRef *xref) const = 0;
289 virtual std::unique_ptr<AnnotBorder> copy() const = 0;
290
291protected:
292 AnnotBorder();
293
294 bool parseDashArray(Object *dashObj);
295
296 AnnotBorderType type;
297 double width;
298 static const int DASH_LIMIT = 10; // implementation note 82 in Appendix H.
299 std::vector<double> dash;
300 AnnotBorderStyle style;
301};
302
303//------------------------------------------------------------------------
304// AnnotBorderArray
305//------------------------------------------------------------------------
306
307class POPPLER_PRIVATE_EXPORT AnnotBorderArray : public AnnotBorder
308{
309public:
310 AnnotBorderArray();
311 explicit AnnotBorderArray(Array *array);
312
313 void setHorizontalCorner(double hc) { horizontalCorner = hc; }
314 void setVerticalCorner(double vc) { verticalCorner = vc; }
315
316 double getHorizontalCorner() const { return horizontalCorner; }
317 double getVerticalCorner() const { return verticalCorner; }
318
319 std::unique_ptr<AnnotBorder> copy() const override;
320
321private:
322 AnnotBorderType getType() const override { return typeArray; }
323 Object writeToObject(XRef *xref) const override;
324
325 double horizontalCorner; // (Default 0)
326 double verticalCorner; // (Default 0)
327 // double width; // (Default 1) (inherited from AnnotBorder)
328};
329
330//------------------------------------------------------------------------
331// AnnotBorderBS
332//------------------------------------------------------------------------
333
334class AnnotBorderBS : public AnnotBorder
335{
336public:
337 AnnotBorderBS();
338 explicit AnnotBorderBS(Dict *dict);
339
340private:
341 AnnotBorderType getType() const override { return typeBS; }
342 Object writeToObject(XRef *xref) const override;
343
344 const char *getStyleName() const;
345
346 std::unique_ptr<AnnotBorder> copy() const override;
347
348 // double width; // W (Default 1) (inherited from AnnotBorder)
349 // AnnotBorderStyle style; // S (Default S) (inherited from AnnotBorder)
350 // double *dash; // D (Default [3]) (inherited from AnnotBorder)
351};
352
353//------------------------------------------------------------------------
354// AnnotColor
355//------------------------------------------------------------------------
356
357class POPPLER_PRIVATE_EXPORT AnnotColor
358{
359public:
360 enum AnnotColorSpace
361 {
362 colorTransparent = 0,
363 colorGray = 1,
364 colorRGB = 3,
365 colorCMYK = 4
366 };
367
368 AnnotColor();
369 explicit AnnotColor(double gray);
370 AnnotColor(double r, double g, double b);
371 AnnotColor(double c, double m, double y, double k);
372 explicit AnnotColor(Array *array, int adjust = 0);
373
374 void adjustColor(int adjust);
375
376 AnnotColorSpace getSpace() const { return (AnnotColorSpace)length; }
377 const double *getValues() const { return values; }
378
379 Object writeToObject(XRef *xref) const;
380
381private:
382 double values[4];
383 int length;
384};
385
386//------------------------------------------------------------------------
387// DefaultAppearance
388//------------------------------------------------------------------------
389
390class POPPLER_PRIVATE_EXPORT DefaultAppearance
391{
392public:
393 DefaultAppearance(Object &&fontNameA, double fontPtSizeA, std::unique_ptr<AnnotColor> &&fontColorA);
394 explicit DefaultAppearance(const GooString *da);
395 void setFontName(Object &&fontNameA);
396 const Object &getFontName() const { return fontName; }
397 void setFontPtSize(double fontPtSizeA);
398 double getFontPtSize() const { return fontPtSize; }
399 void setFontColor(std::unique_ptr<AnnotColor> fontColorA);
400 const AnnotColor *getFontColor() const { return fontColor.get(); }
401 std::string toAppearanceString() const;
402
403 DefaultAppearance(const DefaultAppearance &) = delete;
404 DefaultAppearance &operator=(const DefaultAppearance &) = delete;
405
406private:
407 Object fontName;
408 double fontPtSize;
409 std::unique_ptr<AnnotColor> fontColor;
410};
411
412//------------------------------------------------------------------------
413// AnnotIconFit
414//------------------------------------------------------------------------
415
416class AnnotIconFit
417{
418public:
419 enum AnnotIconFitScaleWhen
420 {
421 scaleAlways, // A
422 scaleBigger, // B
423 scaleSmaller, // S
424 scaleNever // N
425 };
426
427 enum AnnotIconFitScale
428 {
429 scaleAnamorphic, // A
430 scaleProportional // P
431 };
432
433 explicit AnnotIconFit(Dict *dict);
434
435 AnnotIconFitScaleWhen getScaleWhen() { return scaleWhen; }
436 AnnotIconFitScale getScale() { return scale; }
437 double getLeft() { return left; }
438 double getBottom() { return bottom; }
439 bool getFullyBounds() { return fullyBounds; }
440
441protected:
442 AnnotIconFitScaleWhen scaleWhen; // SW (Default A)
443 AnnotIconFitScale scale; // S (Default P)
444 double left; // A (Default [0.5 0.5]
445 double bottom; // Only if scale is P
446 bool fullyBounds; // FB (Default false)
447};
448
449//------------------------------------------------------------------------
450// AnnotAppearance
451//------------------------------------------------------------------------
452
453class AnnotAppearance
454{
455public:
456 enum AnnotAppearanceType
457 {
458 appearNormal,
459 appearRollover,
460 appearDown
461 };
462
463 AnnotAppearance(PDFDoc *docA, Object *dict);
464 ~AnnotAppearance();
465
466 // State is ignored if no subdictionary is present
467 Object getAppearanceStream(AnnotAppearanceType type, const char *state);
468
469 // Access keys in normal appearance subdictionary (N)
470 std::unique_ptr<GooString> getStateKey(int i);
471 int getNumStates();
472
473 // Removes all associated streams in the xref table. Caller is required to
474 // reset parent annotation's AP and AS after this call.
475 void removeAllStreams();
476
477 // Test if this AnnotAppearance references the specified stream
478 bool referencesStream(Ref refToStream);
479
480private:
481 static bool referencesStream(const Object *stateObj, Ref refToStream);
482 void removeStream(Ref refToStream);
483 void removeStateStreams(const Object *state);
484
485protected:
486 PDFDoc *doc;
487 Object appearDict; // Annotation's AP
488};
489
490//------------------------------------------------------------------------
491// AnnotAppearanceCharacs
492//------------------------------------------------------------------------
493
494class POPPLER_PRIVATE_EXPORT AnnotAppearanceCharacs
495{
496public:
497 enum AnnotAppearanceCharacsTextPos
498 {
499 captionNoIcon, // 0
500 captionNoCaption, // 1
501 captionBelow, // 2
502 captionAbove, // 3
503 captionRight, // 4
504 captionLeft, // 5
505 captionOverlaid // 6
506 };
507
508 explicit AnnotAppearanceCharacs(Dict *dict);
509 ~AnnotAppearanceCharacs();
510
511 AnnotAppearanceCharacs(const AnnotAppearanceCharacs &) = delete;
512 AnnotAppearanceCharacs &operator=(const AnnotAppearanceCharacs &) = delete;
513
514 int getRotation() const { return rotation; }
515 const AnnotColor *getBorderColor() const { return borderColor.get(); }
516 void setBorderColor(std::unique_ptr<AnnotColor> &&color) { borderColor = std::move(color); }
517 const AnnotColor *getBackColor() const { return backColor.get(); }
518 void setBackColor(std::unique_ptr<AnnotColor> &&color) { backColor = std::move(color); }
519 const GooString *getNormalCaption() const { return normalCaption.get(); }
520 const GooString *getRolloverCaption() { return rolloverCaption.get(); }
521 const GooString *getAlternateCaption() { return alternateCaption.get(); }
522 const AnnotIconFit *getIconFit() { return iconFit.get(); }
523 AnnotAppearanceCharacsTextPos getPosition() const { return position; }
524
525 std::unique_ptr<AnnotAppearanceCharacs> copy() const;
526
527protected:
528 int rotation; // R (Default 0)
529 std::unique_ptr<AnnotColor> borderColor; // BC
530 std::unique_ptr<AnnotColor> backColor; // BG
531 std::unique_ptr<GooString> normalCaption; // CA
532 std::unique_ptr<GooString> rolloverCaption; // RC
533 std::unique_ptr<GooString> alternateCaption; // AC
534 // I
535 // RI
536 // IX
537 std::unique_ptr<AnnotIconFit> iconFit; // IF
538 AnnotAppearanceCharacsTextPos position; // TP (Default 0)
539};
540
541//------------------------------------------------------------------------
542// AnnotAppearanceBBox
543//------------------------------------------------------------------------
544
545class AnnotAppearanceBBox
546{
547public:
548 explicit AnnotAppearanceBBox(PDFRectangle *rect);
549
550 void setBorderWidth(double w) { borderWidth = w; }
551
552 // The following functions operate on coords relative to [origX origY]
553 void extendTo(double x, double y);
554 void getBBoxRect(double bbox[4]) const;
555
556 // Get boundaries in page coordinates
557 double getPageXMin() const;
558 double getPageYMin() const;
559 double getPageXMax() const;
560 double getPageYMax() const;
561
562private:
563 double origX, origY, borderWidth;
564 double minX, minY, maxX, maxY;
565};
566
567//------------------------------------------------------------------------
568// AnnotAppearanceBuilder
569//------------------------------------------------------------------------
570class Matrix;
571
572class AnnotAppearanceBuilder
573{
574public:
575 AnnotAppearanceBuilder();
576 ~AnnotAppearanceBuilder();
577
578 AnnotAppearanceBuilder(const AnnotAppearanceBuilder &) = delete;
579 AnnotAppearanceBuilder &operator=(const AnnotAppearanceBuilder &) = delete;
580
581 void setDrawColor(const AnnotColor *color, bool fill);
582 void setLineStyleForBorder(const AnnotBorder *border);
583 void setTextFont(const Object &fontName, double fontSize);
584 void drawCircle(double cx, double cy, double r, bool fill);
585 void drawEllipse(double cx, double cy, double rx, double ry, bool fill, bool stroke);
586 void drawCircleTopLeft(double cx, double cy, double r);
587 void drawCircleBottomRight(double cx, double cy, double r);
588 void drawLineEnding(AnnotLineEndingStyle endingStyle, double x, double y, double size, bool fill, const Matrix &m);
589 void drawLineEndSquare(double x, double y, double size, bool fill, const Matrix &m);
590 void drawLineEndCircle(double x, double y, double size, bool fill, const Matrix &m);
591 void drawLineEndDiamond(double x, double y, double size, bool fill, const Matrix &m);
592 void drawLineEndArrow(double x, double y, double size, int orientation, bool isOpen, bool fill, const Matrix &m);
593 void drawLineEndSlash(double x, double y, double size, const Matrix &m);
594 void drawFieldBorder(const FormField *field, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect);
595 bool drawFormField(const FormField *field, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
596 const GooString *appearState, XRef *xref, Dict *resourcesDict);
597 static double lineEndingXShorten(AnnotLineEndingStyle endingStyle, double size);
598 static double lineEndingXExtendBBox(AnnotLineEndingStyle endingStyle, double size);
599 void writeString(const std::string &str);
600
601 void append(const char *text);
602 void appendf(const char *fmt, ...) GOOSTRING_FORMAT;
603
604 const GooString *buffer() const;
605
606private:
607 enum DrawTextFlags
608 {
609 NoDrawTextFlags = 0,
610 MultilineDrawTextFlag = 1,
611 EmitMarkedContentDrawTextFlag = 2,
612 ForceZapfDingbatsDrawTextFlag = 4,
613 TurnTextToStarsDrawTextFlag = 8
614 };
615
616 bool drawListBox(const FormFieldChoice *fieldChoice, const AnnotBorder *border, const PDFRectangle *rect, const GooString *da, const GfxResources *resources, VariableTextQuadding quadding, XRef *xref, Dict *resourcesDict);
617 bool drawFormFieldButton(const FormFieldButton *field, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
618 const GooString *appearState, XRef *xref, Dict *resourcesDict);
619 bool drawFormFieldText(const FormFieldText *fieldText, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, XRef *xref,
620 Dict *resourcesDict);
621 bool drawFormFieldChoice(const FormFieldChoice *fieldChoice, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
622 XRef *xref, Dict *resourcesDict);
623 bool drawSignatureFieldText(const FormFieldSignature *field, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
624 XRef *xref, Dict *resourcesDict);
625 void drawSignatureFieldText(const GooString &text, const Form *form, const DefaultAppearance &da, const AnnotBorder *border, const PDFRectangle *rect, XRef *xref, Dict *resourcesDict, double leftMargin, bool centerVertically,
626 bool centerHorizontally);
627 bool drawText(const GooString *text, const Form *form, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
628 const VariableTextQuadding quadding, XRef *xref, Dict *resourcesDict, const int flags = NoDrawTextFlags, const int nCombs = 0);
629 void drawArrowPath(double x, double y, const Matrix &m, int orientation = 1);
630
631 GooString *appearBuf;
632};
633
634//------------------------------------------------------------------------
635// Annot
636//------------------------------------------------------------------------
637
638class POPPLER_PRIVATE_EXPORT Annot
639{
640 friend class Annots;
641 friend class Page;
642
643public:
644 enum AnnotFlag
645 {
646 flagUnknown = 0x0000,
647 flagInvisible = 0x0001,
648 flagHidden = 0x0002,
649 flagPrint = 0x0004,
650 flagNoZoom = 0x0008,
651 flagNoRotate = 0x0010,
652 flagNoView = 0x0020,
653 flagReadOnly = 0x0040,
654 flagLocked = 0x0080,
655 flagToggleNoView = 0x0100,
656 flagLockedContents = 0x0200
657 };
658
659 enum AnnotSubtype
660 {
661 typeUnknown, // 0
662 typeText, // Text 1
663 typeLink, // Link 2
664 typeFreeText, // FreeText 3
665 typeLine, // Line 4
666 typeSquare, // Square 5
667 typeCircle, // Circle 6
668 typePolygon, // Polygon 7
669 typePolyLine, // PolyLine 8
670 typeHighlight, // Highlight 9
671 typeUnderline, // Underline 10
672 typeSquiggly, // Squiggly 11
673 typeStrikeOut, // StrikeOut 12
674 typeStamp, // Stamp 13
675 typeCaret, // Caret 14
676 typeInk, // Ink 15
677 typePopup, // Popup 16
678 typeFileAttachment, // FileAttachment 17
679 typeSound, // Sound 18
680 typeMovie, // Movie 19
681 typeWidget, // Widget 20
682 typeScreen, // Screen 21
683 typePrinterMark, // PrinterMark 22
684 typeTrapNet, // TrapNet 23
685 typeWatermark, // Watermark 24
686 type3D, // 3D 25
687 typeRichMedia // RichMedia 26
688 };
689
690 /**
691 * Describes the additional actions of a screen or widget annotation.
692 */
693 enum AdditionalActionsType
694 {
695 actionCursorEntering, ///< Performed when the cursor enters the annotation's active area
696 actionCursorLeaving, ///< Performed when the cursor exists the annotation's active area
697 actionMousePressed, ///< Performed when the mouse button is pressed inside the annotation's active area
698 actionMouseReleased, ///< Performed when the mouse button is released inside the annotation's active area
699 actionFocusIn, ///< Performed when the annotation receives the input focus
700 actionFocusOut, ///< Performed when the annotation loses the input focus
701 actionPageOpening, ///< Performed when the page containing the annotation is opened
702 actionPageClosing, ///< Performed when the page containing the annotation is closed
703 actionPageVisible, ///< Performed when the page containing the annotation becomes visible
704 actionPageInvisible ///< Performed when the page containing the annotation becomes invisible
705 };
706
707 enum FormAdditionalActionsType
708 {
709 actionFieldModified, ///< Performed when the when the user modifies the field
710 actionFormatField, ///< Performed before the field is formatted to display its value
711 actionValidateField, ///< Performed when the field value changes
712 actionCalculateField, ///< Performed when the field needs to be recalculated
713 };
714
715 Annot(PDFDoc *docA, PDFRectangle *rectA);
716 Annot(PDFDoc *docA, Object &&dictObject);
717 Annot(PDFDoc *docA, Object &&dictObject, const Object *obj);
718 bool isOk() { return ok; }
719
720 static double calculateFontSize(const Form *form, const GfxFont *font, const GooString *text, const double wMax, const double hMax, const bool forceZapfDingbats = {});
721
722 void incRefCnt();
723 void decRefCnt();
724
725 virtual void draw(Gfx *gfx, bool printing);
726 // Get the resource dict of the appearance stream
727 virtual Object getAppearanceResDict();
728
729 bool match(const Ref *refA) const { return ref == *refA; }
730
731 double getXMin();
732 double getYMin();
733 double getXMax();
734 double getYMax();
735
736 void setRect(const PDFRectangle *rect);
737 void setRect(double x1, double y1, double x2, double y2);
738
739 // Sets the annot contents to new_content
740 // new_content should never be NULL
741 virtual void setContents(std::unique_ptr<GooString> &&new_content);
742 void setName(GooString *new_name);
743 void setModified(GooString *new_modified);
744 void setFlags(unsigned int new_flags);
745
746 void setBorder(std::unique_ptr<AnnotBorder> &&new_border);
747 void setColor(std::unique_ptr<AnnotColor> &&new_color);
748
749 void setAppearanceState(const char *state);
750
751 // getters
752 PDFDoc *getDoc() const { return doc; }
753 bool getHasRef() const { return hasRef; }
754 Ref getRef() const { return ref; }
755 const Object &getAnnotObj() const { return annotObj; }
756 AnnotSubtype getType() const { return type; }
757 const PDFRectangle &getRect() const { return *rect; }
758 void getRect(double *x1, double *y1, double *x2, double *y2) const;
759 const GooString *getContents() const { return contents.get(); }
760 int getPageNum() const { return page; }
761 const GooString *getName() const { return name.get(); }
762 const GooString *getModified() const { return modified.get(); }
763 unsigned int getFlags() const { return flags; }
764 Object getAppearance() const;
765 void setNewAppearance(Object &&newAppearance);
766 AnnotAppearance *getAppearStreams() const { return appearStreams.get(); }
767 const GooString *getAppearState() const { return appearState.get(); }
768 AnnotBorder *getBorder() const { return border.get(); }
769 AnnotColor *getColor() const { return color.get(); }
770 int getTreeKey() const { return treeKey; }
771
772 int getId() { return ref.num; }
773
774 // Check if point is inside the annot rectangle.
775 bool inRect(double x, double y) const;
776
777 // If newFontNeeded is not null, it will contain whether the given font has glyphs to represent the needed text
778 static void layoutText(const GooString *text, GooString *outBuf, int *i, const GfxFont &font, double *width, double widthLimit, int *charCount, bool noReencode, bool *newFontNeeded = nullptr);
779
780private:
781 void readArrayNum(Object *pdfArray, int key, double *value);
782 // write vStr[i:j[ in appearBuf
783
784 void initialize(PDFDoc *docA, Dict *dict);
785 void setPage(int pageIndex, bool updateP); // Called by Page::addAnnot and Annots ctor
786
787protected:
788 virtual ~Annot();
789 virtual void removeReferencedObjects(); // Called by Page::removeAnnot
790 Object createForm(const GooString *appearBuf, const double *bbox, bool transparencyGroup, Dict *resDict);
791 Object createForm(const GooString *appearBuf, const double *bbox, bool transparencyGroup, Object &&resDictObject); // overload to support incRef/decRef
792 Dict *createResourcesDict(const char *formName, Object &&formStream, const char *stateName, double opacity, const char *blendMode);
793 bool isVisible(bool printing);
794 int getRotation() const;
795
796 // Updates the field key of the annotation dictionary
797 // and sets M to the current time
798 void update(const char *key, Object &&value);
799
800 // Delete appearance streams and reset appearance state
801 virtual void invalidateAppearance();
802
803 Object annotObj;
804
805 std::atomic_int refCnt;
806
807 // required data
808 AnnotSubtype type; // Annotation type
809 std::unique_ptr<PDFRectangle> rect; // Rect
810
811 // optional data
812 std::unique_ptr<GooString> contents; // Contents
813 std::unique_ptr<GooString> name; // NM
814 std::unique_ptr<GooString> modified; // M
815 int page; // P
816 unsigned int flags; // F (must be a 32 bit unsigned int)
817 std::unique_ptr<AnnotAppearance> appearStreams; // AP
818 Object appearance; // a reference to the Form XObject stream
819 // for the normal appearance
820 std::unique_ptr<AnnotAppearanceBBox> appearBBox; // BBox of generated appearance
821 std::unique_ptr<GooString> appearState; // AS
822 int treeKey; // Struct Parent;
823 Object oc; // OC
824
825 PDFDoc *doc;
826 Ref ref; // object ref identifying this annotation
827 std::unique_ptr<AnnotBorder> border; // Border, BS
828 std::unique_ptr<AnnotColor> color; // C
829 bool ok;
830
831 bool hasRef;
832 mutable std::recursive_mutex mutex;
833
834 bool hasBeenUpdated = false;
835};
836
837//------------------------------------------------------------------------
838// AnnotPopup
839//------------------------------------------------------------------------
840
841class POPPLER_PRIVATE_EXPORT AnnotPopup : public Annot
842{
843public:
844 AnnotPopup(PDFDoc *docA, PDFRectangle *rect);
845 AnnotPopup(PDFDoc *docA, Object &&dictObject, const Object *obj);
846 ~AnnotPopup() override;
847
848 bool hasParent() const { return parentRef != Ref::INVALID(); }
849 void setParent(Annot *parentA);
850 bool getOpen() const { return open; }
851 void setOpen(bool openA);
852
853protected:
854 void initialize(PDFDoc *docA, Dict *dict);
855
856 Ref parentRef; // Parent
857 bool open; // Open
858};
859
860//------------------------------------------------------------------------
861// AnnotMarkup
862//------------------------------------------------------------------------
863
864class POPPLER_PRIVATE_EXPORT AnnotMarkup : public Annot
865{
866public:
867 enum AnnotMarkupReplyType
868 {
869 replyTypeR, // R
870 replyTypeGroup // Group
871 };
872
873 AnnotMarkup(PDFDoc *docA, PDFRectangle *rect);
874 AnnotMarkup(PDFDoc *docA, Object &&dictObject, const Object *obj);
875 ~AnnotMarkup() override;
876
877 // getters
878 const GooString *getLabel() const { return label.get(); }
879 AnnotPopup *getPopup() const { return popup.get(); }
880 double getOpacity() const { return opacity; }
881 // getRC
882 const GooString *getDate() const { return date.get(); }
883 bool isInReplyTo() const { return inReplyTo != Ref::INVALID(); }
884 int getInReplyToID() const { return inReplyTo.num; }
885 const GooString *getSubject() const { return subject.get(); }
886 AnnotMarkupReplyType getReplyTo() const { return replyTo; }
887 AnnotExternalDataType getExData() const { return exData; }
888
889 // The annotation takes the ownership of new_popup
890 void setPopup(std::unique_ptr<AnnotPopup> &&new_popup);
891 void setLabel(std::unique_ptr<GooString> &&new_label);
892 void setOpacity(double opacityA);
893 void setDate(GooString *new_date);
894
895protected:
896 void removeReferencedObjects() override;
897
898 std::unique_ptr<GooString> label; // T (Default author)
899 std::unique_ptr<AnnotPopup> popup; // Popup
900 double opacity; // CA (Default 1.0)
901 // RC
902 std::unique_ptr<GooString> date; // CreationDate
903 Ref inReplyTo; // IRT
904 std::unique_ptr<GooString> subject; // Subj
905 AnnotMarkupReplyType replyTo; // RT (Default R)
906 // this object is overridden by the custom intent fields defined in some
907 // annotation types.
908 // GooString *intent; // IT
909 AnnotExternalDataType exData; // ExData
910
911private:
912 void initialize(PDFDoc *docA, Dict *dict);
913};
914
915//------------------------------------------------------------------------
916// AnnotText
917//------------------------------------------------------------------------
918
919class POPPLER_PRIVATE_EXPORT AnnotText : public AnnotMarkup
920{
921public:
922 enum AnnotTextState
923 {
924 stateUnknown,
925 // Marked state model
926 stateMarked, // Marked
927 stateUnmarked, // Unmarked
928 // Review state model
929 stateAccepted, // Accepted
930 stateRejected, // Rejected
931 stateCancelled, // Cancelled
932 stateCompleted, // Completed
933 stateNone // None
934 };
935
936 AnnotText(PDFDoc *docA, PDFRectangle *rect);
937 AnnotText(PDFDoc *docA, Object &&dictObject, const Object *obj);
938 ~AnnotText() override;
939
940 void draw(Gfx *gfx, bool printing) override;
941
942 // getters
943 bool getOpen() const { return open; }
944 const GooString *getIcon() const { return icon.get(); }
945 AnnotTextState getState() const { return state; }
946
947 void setOpen(bool openA);
948 void setIcon(GooString *new_icon);
949
950private:
951 void initialize(PDFDoc *docA, Dict *dict);
952
953 bool open; // Open (Default false)
954 std::unique_ptr<GooString> icon; // Name (Default Note)
955 AnnotTextState state; // State (Default Umarked if
956 // StateModel Marked
957 // None if StareModel Review)
958};
959
960//------------------------------------------------------------------------
961// AnnotMovie
962//------------------------------------------------------------------------
963
964class POPPLER_PRIVATE_EXPORT AnnotMovie : public Annot
965{
966public:
967 AnnotMovie(PDFDoc *docA, PDFRectangle *rect, Movie *movieA);
968 AnnotMovie(PDFDoc *docA, Object &&dictObject, const Object *obj);
969 ~AnnotMovie() override;
970
971 void draw(Gfx *gfx, bool printing) override;
972
973 const GooString *getTitle() const { return title.get(); }
974 Movie *getMovie() { return movie.get(); }
975
976private:
977 void initialize(PDFDoc *docA, Dict *dict);
978
979 std::unique_ptr<GooString> title; // T
980 std::unique_ptr<Movie> movie; // Movie + A
981};
982
983//------------------------------------------------------------------------
984// AnnotScreen
985//------------------------------------------------------------------------
986
987class POPPLER_PRIVATE_EXPORT AnnotScreen : public Annot
988{
989public:
990 AnnotScreen(PDFDoc *docA, PDFRectangle *rect);
991 AnnotScreen(PDFDoc *docA, Object &&dictObject, const Object *obj);
992 ~AnnotScreen() override;
993
994 const GooString *getTitle() const { return title.get(); }
995
996 AnnotAppearanceCharacs *getAppearCharacs() { return appearCharacs.get(); }
997 LinkAction *getAction() { return action.get(); } // The caller should not delete the result
998 std::unique_ptr<LinkAction> getAdditionalAction(AdditionalActionsType type);
999
1000private:
1001 void initialize(PDFDoc *docA, Dict *dict);
1002
1003 std::unique_ptr<GooString> title; // T
1004
1005 std::unique_ptr<AnnotAppearanceCharacs> appearCharacs; // MK
1006
1007 std::unique_ptr<LinkAction> action; // A
1008 Object additionalActions; // AA
1009};
1010
1011//------------------------------------------------------------------------
1012// AnnotLink
1013//------------------------------------------------------------------------
1014
1015class AnnotLink : public Annot
1016{
1017public:
1018 enum AnnotLinkEffect
1019 {
1020 effectNone, // N
1021 effectInvert, // I
1022 effectOutline, // O
1023 effectPush // P
1024 };
1025
1026 AnnotLink(PDFDoc *docA, PDFRectangle *rect);
1027 AnnotLink(PDFDoc *docA, Object &&dictObject, const Object *obj);
1028 ~AnnotLink() override;
1029
1030 void draw(Gfx *gfx, bool printing) override;
1031
1032 // getters
1033 LinkAction *getAction() const { return action.get(); }
1034 AnnotLinkEffect getLinkEffect() const { return linkEffect; }
1035 AnnotQuadrilaterals *getQuadrilaterals() const { return quadrilaterals.get(); }
1036
1037protected:
1038 void initialize(PDFDoc *docA, Dict *dict);
1039
1040 std::unique_ptr<LinkAction> action; // A, Dest
1041 AnnotLinkEffect linkEffect; // H (Default I)
1042 // Dict *uriAction; // PA
1043
1044 std::unique_ptr<AnnotQuadrilaterals> quadrilaterals; // QuadPoints
1045};
1046
1047//------------------------------------------------------------------------
1048// AnnotFreeText
1049//------------------------------------------------------------------------
1050
1051class POPPLER_PRIVATE_EXPORT AnnotFreeText : public AnnotMarkup
1052{
1053public:
1054 enum AnnotFreeTextIntent
1055 {
1056 intentFreeText, // FreeText
1057 intentFreeTextCallout, // FreeTextCallout
1058 intentFreeTextTypeWriter // FreeTextTypeWriter
1059 };
1060
1061 static const double undefinedFontPtSize;
1062
1063 AnnotFreeText(PDFDoc *docA, PDFRectangle *rect);
1064 AnnotFreeText(PDFDoc *docA, Object &&dictObject, const Object *obj);
1065 ~AnnotFreeText() override;
1066
1067 void draw(Gfx *gfx, bool printing) override;
1068 Object getAppearanceResDict() override;
1069 void setContents(std::unique_ptr<GooString> &&new_content) override;
1070
1071 void setDefaultAppearance(const DefaultAppearance &da);
1072 void setQuadding(VariableTextQuadding new_quadding);
1073 void setStyleString(GooString *new_string);
1074 void setCalloutLine(AnnotCalloutLine *line);
1075 void setIntent(AnnotFreeTextIntent new_intent);
1076
1077 // getters
1078 std::unique_ptr<DefaultAppearance> getDefaultAppearance() const;
1079 VariableTextQuadding getQuadding() const { return quadding; }
1080 // return rc
1081 const GooString *getStyleString() const { return styleString.get(); }
1082 AnnotCalloutLine *getCalloutLine() const { return calloutLine.get(); }
1083 AnnotFreeTextIntent getIntent() const { return intent; }
1084 AnnotBorderEffect *getBorderEffect() const { return borderEffect.get(); }
1085 PDFRectangle *getRectangle() const { return rectangle.get(); }
1086 AnnotLineEndingStyle getEndStyle() const { return endStyle; }
1087
1088protected:
1089 void initialize(PDFDoc *docA, Dict *dict);
1090 void generateFreeTextAppearance();
1091
1092 // required
1093 std::unique_ptr<GooString> appearanceString; // DA
1094
1095 // optional
1096 VariableTextQuadding quadding; // Q (Default 0)
1097 // RC
1098 std::unique_ptr<GooString> styleString; // DS
1099 std::unique_ptr<AnnotCalloutLine> calloutLine; // CL
1100 AnnotFreeTextIntent intent; // IT
1101 std::unique_ptr<AnnotBorderEffect> borderEffect; // BE
1102 std::unique_ptr<PDFRectangle> rectangle; // RD
1103 // inherited from Annot
1104 // AnnotBorderBS border; // BS
1105 AnnotLineEndingStyle endStyle; // LE (Default None)
1106};
1107
1108//------------------------------------------------------------------------
1109// AnnotLine
1110//------------------------------------------------------------------------
1111
1112class POPPLER_PRIVATE_EXPORT AnnotLine : public AnnotMarkup
1113{
1114public:
1115 enum AnnotLineIntent
1116 {
1117 intentLineArrow, // LineArrow
1118 intentLineDimension // LineDimension
1119 };
1120
1121 enum AnnotLineCaptionPos
1122 {
1123 captionPosInline, // Inline
1124 captionPosTop // Top
1125 };
1126
1127 AnnotLine(PDFDoc *docA, PDFRectangle *rect);
1128 AnnotLine(PDFDoc *docA, Object &&dictObject, const Object *obj);
1129 ~AnnotLine() override;
1130
1131 void draw(Gfx *gfx, bool printing) override;
1132 Object getAppearanceResDict() override;
1133 void setContents(std::unique_ptr<GooString> &&new_content) override;
1134
1135 void setVertices(double x1, double y1, double x2, double y2);
1136 void setStartEndStyle(AnnotLineEndingStyle start, AnnotLineEndingStyle end);
1137 void setInteriorColor(std::unique_ptr<AnnotColor> &&new_color);
1138 void setLeaderLineLength(double len);
1139 void setLeaderLineExtension(double len);
1140 void setCaption(bool new_cap);
1141 void setIntent(AnnotLineIntent new_intent);
1142
1143 // getters
1144 AnnotLineEndingStyle getStartStyle() const { return startStyle; }
1145 AnnotLineEndingStyle getEndStyle() const { return endStyle; }
1146 AnnotColor *getInteriorColor() const { return interiorColor.get(); }
1147 double getLeaderLineLength() const { return leaderLineLength; }
1148 double getLeaderLineExtension() const { return leaderLineExtension; }
1149 bool getCaption() const { return caption; }
1150 AnnotLineIntent getIntent() const { return intent; }
1151 double getLeaderLineOffset() const { return leaderLineOffset; }
1152 AnnotLineCaptionPos getCaptionPos() const { return captionPos; }
1153 Dict *getMeasure() const { return measure; }
1154 double getCaptionTextHorizontal() const { return captionTextHorizontal; }
1155 double getCaptionTextVertical() const { return captionTextVertical; }
1156 double getX1() const { return coord1->getX(); }
1157 double getY1() const { return coord1->getY(); }
1158 double getX2() const { return coord2->getX(); }
1159 double getY2() const { return coord2->getY(); }
1160
1161protected:
1162 void initialize(PDFDoc *docA, Dict *dict);
1163 void generateLineAppearance();
1164
1165 // required
1166 std::unique_ptr<AnnotCoord> coord1;
1167 std::unique_ptr<AnnotCoord> coord2;
1168
1169 // optional
1170 // inherited from Annot
1171 // AnnotBorderBS border; // BS
1172 AnnotLineEndingStyle startStyle; // LE (Default [/None /None])
1173 AnnotLineEndingStyle endStyle; //
1174 std::unique_ptr<AnnotColor> interiorColor; // IC
1175 double leaderLineLength; // LL (Default 0)
1176 double leaderLineExtension; // LLE (Default 0)
1177 bool caption; // Cap (Default false)
1178 AnnotLineIntent intent; // IT
1179 double leaderLineOffset; // LLO
1180 AnnotLineCaptionPos captionPos; // CP (Default Inline)
1181 Dict *measure; // Measure
1182 double captionTextHorizontal; // CO (Default [0, 0])
1183 double captionTextVertical; //
1184};
1185
1186//------------------------------------------------------------------------
1187// AnnotTextMarkup
1188//------------------------------------------------------------------------
1189
1190class POPPLER_PRIVATE_EXPORT AnnotTextMarkup : public AnnotMarkup
1191{
1192public:
1193 AnnotTextMarkup(PDFDoc *docA, PDFRectangle *rect, AnnotSubtype subType);
1194 AnnotTextMarkup(PDFDoc *docA, Object &&dictObject, const Object *obj);
1195 ~AnnotTextMarkup() override;
1196
1197 void draw(Gfx *gfx, bool printing) override;
1198
1199 // typeHighlight, typeUnderline, typeSquiggly or typeStrikeOut
1200 void setType(AnnotSubtype new_type);
1201
1202 void setQuadrilaterals(AnnotQuadrilaterals *quadPoints);
1203
1204 AnnotQuadrilaterals *getQuadrilaterals() const { return quadrilaterals.get(); }
1205
1206protected:
1207 void initialize(PDFDoc *docA, Dict *dict);
1208
1209 std::unique_ptr<AnnotQuadrilaterals> quadrilaterals; // QuadPoints
1210
1211private:
1212 bool shouldCreateApperance(Gfx *gfx) const;
1213};
1214
1215//------------------------------------------------------------------------
1216// AnnotStamp
1217//------------------------------------------------------------------------
1218
1219class POPPLER_PRIVATE_EXPORT AnnotStamp : public AnnotMarkup
1220{
1221public:
1222 AnnotStamp(PDFDoc *docA, PDFRectangle *rect);
1223 AnnotStamp(PDFDoc *docA, Object &&dictObject, const Object *obj);
1224 ~AnnotStamp() override;
1225
1226 void draw(Gfx *gfx, bool printing) override;
1227
1228 void setIcon(GooString *new_icon);
1229
1230 void setCustomImage(AnnotStampImageHelper *stampImageHelperA);
1231
1232 void clearCustomImage();
1233
1234 // getters
1235 const GooString *getIcon() const { return icon.get(); }
1236
1237private:
1238 void initialize(PDFDoc *docA, Dict *dict);
1239 void generateStampDefaultAppearance();
1240 void generateStampCustomAppearance();
1241
1242 std::unique_ptr<GooString> icon; // Name (Default Draft)
1243 AnnotStampImageHelper *stampImageHelper;
1244 Ref updatedAppearanceStream;
1245};
1246
1247//------------------------------------------------------------------------
1248// AnnotGeometry
1249//------------------------------------------------------------------------
1250
1251class POPPLER_PRIVATE_EXPORT AnnotGeometry : public AnnotMarkup
1252{
1253public:
1254 AnnotGeometry(PDFDoc *docA, PDFRectangle *rect, AnnotSubtype subType);
1255 AnnotGeometry(PDFDoc *docA, Object &&dictObject, const Object *obj);
1256 ~AnnotGeometry() override;
1257
1258 void draw(Gfx *gfx, bool printing) override;
1259
1260 void setType(AnnotSubtype new_type); // typeSquare or typeCircle
1261 void setInteriorColor(std::unique_ptr<AnnotColor> &&new_color);
1262
1263 // getters
1264 AnnotColor *getInteriorColor() const { return interiorColor.get(); }
1265 AnnotBorderEffect *getBorderEffect() const { return borderEffect.get(); }
1266 PDFRectangle *getGeometryRect() const { return geometryRect.get(); }
1267
1268private:
1269 void initialize(PDFDoc *docA, Dict *dict);
1270
1271 std::unique_ptr<AnnotColor> interiorColor; // IC
1272 std::unique_ptr<AnnotBorderEffect> borderEffect; // BE
1273 std::unique_ptr<PDFRectangle> geometryRect; // RD (combined with Rect)
1274};
1275
1276//------------------------------------------------------------------------
1277// AnnotPolygon
1278//------------------------------------------------------------------------
1279
1280class POPPLER_PRIVATE_EXPORT AnnotPolygon : public AnnotMarkup
1281{
1282public:
1283 enum AnnotPolygonIntent
1284 {
1285 polygonCloud, // PolygonCloud
1286 polylineDimension, // PolyLineDimension
1287 polygonDimension // PolygonDimension
1288 };
1289
1290 AnnotPolygon(PDFDoc *docA, PDFRectangle *rect, AnnotSubtype subType);
1291 AnnotPolygon(PDFDoc *docA, Object &&dictObject, const Object *obj);
1292 ~AnnotPolygon() override;
1293
1294 void draw(Gfx *gfx, bool printing) override;
1295 void generatePolyLineAppearance(AnnotAppearanceBuilder *appearBuilder);
1296 void setType(AnnotSubtype new_type); // typePolygon or typePolyLine
1297 void setVertices(AnnotPath *path);
1298 void setStartEndStyle(AnnotLineEndingStyle start, AnnotLineEndingStyle end);
1299 void setInteriorColor(std::unique_ptr<AnnotColor> &&new_color);
1300 void setIntent(AnnotPolygonIntent new_intent);
1301
1302 // getters
1303 AnnotPath *getVertices() const { return vertices.get(); }
1304 AnnotLineEndingStyle getStartStyle() const { return startStyle; }
1305 AnnotLineEndingStyle getEndStyle() const { return endStyle; }
1306 AnnotColor *getInteriorColor() const { return interiorColor.get(); }
1307 AnnotBorderEffect *getBorderEffect() const { return borderEffect.get(); }
1308 AnnotPolygonIntent getIntent() const { return intent; }
1309
1310private:
1311 void initialize(PDFDoc *docA, Dict *dict);
1312
1313 // required
1314 std::unique_ptr<AnnotPath> vertices; // Vertices
1315
1316 // optional
1317 AnnotLineEndingStyle startStyle; // LE (Default [/None /None])
1318 AnnotLineEndingStyle endStyle; //
1319 // inherited from Annot
1320 // AnnotBorderBS border; // BS
1321 std::unique_ptr<AnnotColor> interiorColor; // IC
1322 std::unique_ptr<AnnotBorderEffect> borderEffect; // BE
1323 AnnotPolygonIntent intent; // IT
1324 // Measure
1325};
1326
1327//------------------------------------------------------------------------
1328// AnnotCaret
1329//------------------------------------------------------------------------
1330
1331class POPPLER_PRIVATE_EXPORT AnnotCaret : public AnnotMarkup
1332{
1333public:
1334 enum AnnotCaretSymbol
1335 {
1336 symbolNone, // None
1337 symbolP // P
1338 };
1339
1340 AnnotCaret(PDFDoc *docA, PDFRectangle *rect);
1341 AnnotCaret(PDFDoc *docA, Object &&dictObject, const Object *obj);
1342 ~AnnotCaret() override;
1343
1344 void setSymbol(AnnotCaretSymbol new_symbol);
1345
1346 // getters
1347 AnnotCaretSymbol getSymbol() const { return symbol; }
1348 PDFRectangle *getCaretRect() const { return caretRect.get(); }
1349
1350private:
1351 void initialize(PDFDoc *docA, Dict *dict);
1352
1353 AnnotCaretSymbol symbol; // Sy (Default None)
1354 std::unique_ptr<PDFRectangle> caretRect; // RD (combined with Rect)
1355};
1356
1357//------------------------------------------------------------------------
1358// AnnotInk
1359//------------------------------------------------------------------------
1360
1361class POPPLER_PRIVATE_EXPORT AnnotInk : public AnnotMarkup
1362{
1363public:
1364 AnnotInk(PDFDoc *docA, PDFRectangle *rect);
1365 AnnotInk(PDFDoc *docA, Object &&dictObject, const Object *obj);
1366 ~AnnotInk() override;
1367
1368 void draw(Gfx *gfx, bool printing) override;
1369
1370 void setInkList(AnnotPath **paths, int n_paths);
1371
1372 // getters
1373 AnnotPath **getInkList() const { return inkList; }
1374 int getInkListLength() const { return inkListLength; }
1375
1376private:
1377 void initialize(PDFDoc *docA, Dict *dict);
1378 void writeInkList(AnnotPath **paths, int n_paths, Array *dest_array);
1379 void parseInkList(Array *src_array);
1380 void freeInkList();
1381
1382 // required
1383 AnnotPath **inkList; // InkList
1384 int inkListLength;
1385
1386 // optional
1387 // inherited from Annot
1388 // AnnotBorderBS border; // BS
1389};
1390
1391//------------------------------------------------------------------------
1392// AnnotFileAttachment
1393//------------------------------------------------------------------------
1394
1395class AnnotFileAttachment : public AnnotMarkup
1396{
1397public:
1398 AnnotFileAttachment(PDFDoc *docA, PDFRectangle *rect, GooString *filename);
1399 AnnotFileAttachment(PDFDoc *docA, Object &&dictObject, const Object *obj);
1400 ~AnnotFileAttachment() override;
1401
1402 void draw(Gfx *gfx, bool printing) override;
1403
1404 // getters
1405 Object *getFile() { return &file; }
1406 const GooString *getName() const { return name.get(); }
1407
1408private:
1409 void initialize(PDFDoc *docA, Dict *dict);
1410
1411 // required
1412 Object file; // FS
1413
1414 // optional
1415 std::unique_ptr<GooString> name; // Name
1416};
1417
1418//------------------------------------------------------------------------
1419// AnnotSound
1420//------------------------------------------------------------------------
1421
1422class AnnotSound : public AnnotMarkup
1423{
1424public:
1425 AnnotSound(PDFDoc *docA, PDFRectangle *rect, Sound *soundA);
1426 AnnotSound(PDFDoc *docA, Object &&dictObject, const Object *obj);
1427 ~AnnotSound() override;
1428
1429 void draw(Gfx *gfx, bool printing) override;
1430
1431 // getters
1432 Sound *getSound() { return sound.get(); }
1433 const GooString *getName() const { return name.get(); }
1434
1435private:
1436 void initialize(PDFDoc *docA, Dict *dict);
1437
1438 // required
1439 std::unique_ptr<Sound> sound; // Sound
1440
1441 // optional
1442 std::unique_ptr<GooString> name; // Name
1443};
1444
1445//------------------------------------------------------------------------
1446// AnnotWidget
1447//------------------------------------------------------------------------
1448
1449class POPPLER_PRIVATE_EXPORT AnnotWidget : public Annot
1450{
1451public:
1452 enum AnnotWidgetHighlightMode
1453 {
1454 highlightModeNone, // N
1455 highlightModeInvert, // I
1456 highlightModeOutline, // O
1457 highlightModePush // P,T
1458 };
1459
1460 AnnotWidget(PDFDoc *docA, Object &&dictObject, const Object *obj);
1461 AnnotWidget(PDFDoc *docA, Object *dictObject, Object *obj, FormField *fieldA);
1462 ~AnnotWidget() override;
1463
1464 void draw(Gfx *gfx, bool printing) override;
1465 void invalidateAppearance() override;
1466
1467 void generateFieldAppearance();
1468 void updateAppearanceStream();
1469
1470 AnnotWidgetHighlightMode getMode() { return mode; }
1471 AnnotAppearanceCharacs *getAppearCharacs() { return appearCharacs.get(); }
1472 void setAppearCharacs(std::unique_ptr<AnnotAppearanceCharacs> &&appearCharacsA) { appearCharacs = std::move(appearCharacsA); }
1473 LinkAction *getAction() { return action.get(); } // The caller should not delete the result
1474 std::unique_ptr<LinkAction> getAdditionalAction(AdditionalActionsType type);
1475 std::unique_ptr<LinkAction> getFormAdditionalAction(FormAdditionalActionsType type);
1476 Dict *getParent() { return parent; }
1477
1478 bool setFormAdditionalAction(FormAdditionalActionsType type, const std::string &js);
1479
1480 void setField(FormField *f) { field = f; };
1481
1482private:
1483 void initialize(PDFDoc *docA, Dict *dict);
1484
1485 Form *form;
1486 FormField *field; // FormField object for this annotation
1487 AnnotWidgetHighlightMode mode; // H (Default I)
1488 std::unique_ptr<AnnotAppearanceCharacs> appearCharacs; // MK
1489 std::unique_ptr<LinkAction> action; // A
1490 Object additionalActions; // AA
1491 // inherited from Annot
1492 // AnnotBorderBS border; // BS
1493 Dict *parent; // Parent
1494 Ref updatedAppearanceStream; // {-1,-1} if updateAppearanceStream has never been called
1495};
1496
1497//------------------------------------------------------------------------
1498// Annot3D
1499//------------------------------------------------------------------------
1500
1501class Annot3D : public Annot
1502{
1503 class Activation
1504 {
1505 public:
1506 enum ActivationATrigger
1507 {
1508 aTriggerUnknown,
1509 aTriggerPageOpened, // PO
1510 aTriggerPageVisible, // PV
1511 aTriggerUserAction // XA
1512 };
1513
1514 enum ActivationAState
1515 {
1516 aStateUnknown,
1517 aStateEnabled, // I
1518 aStateDisabled // L
1519 };
1520
1521 enum ActivationDTrigger
1522 {
1523 dTriggerUnknown,
1524 dTriggerPageClosed, // PC
1525 dTriggerPageInvisible, // PI
1526 dTriggerUserAction // XD
1527 };
1528
1529 enum ActivationDState
1530 {
1531 dStateUnknown,
1532 dStateUninstantiaded, // U
1533 dStateInstantiated, // I
1534 dStateLive // L
1535 };
1536
1537 explicit Activation(Dict *dict);
1538
1539 private:
1540 ActivationATrigger aTrigger; // A (Default XA)
1541 ActivationAState aState; // AIS (Default L)
1542 ActivationDTrigger dTrigger; // D (Default PI)
1543 ActivationDState dState; // DIS (Default U)
1544 bool displayToolbar; // TB (Default true)
1545 bool displayNavigation; // NP (Default false);
1546 };
1547
1548public:
1549 Annot3D(PDFDoc *docA, PDFRectangle *rect);
1550 Annot3D(PDFDoc *docA, Object &&dictObject, const Object *obj);
1551 ~Annot3D() override;
1552
1553 // getters
1554
1555private:
1556 void initialize(PDFDoc *docA, Dict *dict);
1557
1558 std::unique_ptr<Activation> activation; // 3DA
1559};
1560
1561//------------------------------------------------------------------------
1562// AnnotRichMedia
1563//------------------------------------------------------------------------
1564
1565class POPPLER_PRIVATE_EXPORT AnnotRichMedia : public Annot
1566{
1567public:
1568 class POPPLER_PRIVATE_EXPORT Params
1569 {
1570 public:
1571 explicit Params(Dict *dict);
1572 ~Params();
1573
1574 Params(const Params &) = delete;
1575 Params &operator=(const Params &) = delete;
1576
1577 const GooString *getFlashVars() const;
1578
1579 private:
1580 // optional
1581 std::unique_ptr<GooString> flashVars; // FlashVars
1582 };
1583
1584 class POPPLER_PRIVATE_EXPORT Instance
1585 {
1586 public:
1587 enum Type
1588 {
1589 type3D, // 3D
1590 typeFlash, // Flash
1591 typeSound, // Sound
1592 typeVideo // Video
1593 };
1594
1595 explicit Instance(Dict *dict);
1596 ~Instance();
1597
1598 Instance(const Instance &) = delete;
1599 Instance &operator=(const Instance &) = delete;
1600
1601 Type getType() const;
1602 Params *getParams() const;
1603
1604 private:
1605 // optional
1606 Type type; // Subtype
1607 std::unique_ptr<Params> params; // Params
1608 };
1609
1610 class POPPLER_PRIVATE_EXPORT Configuration
1611 {
1612 public:
1613 enum Type
1614 {
1615 type3D, // 3D
1616 typeFlash, // Flash
1617 typeSound, // Sound
1618 typeVideo // Video
1619 };
1620
1621 explicit Configuration(Dict *dict);
1622 ~Configuration();
1623
1624 Configuration(const Configuration &) = delete;
1625 Configuration &operator=(const Configuration &) = delete;
1626
1627 Type getType() const;
1628 const GooString *getName() const;
1629 int getInstancesCount() const;
1630 Instance *getInstance(int index) const;
1631
1632 private:
1633 // optional
1634 Type type; // Subtype
1635 std::unique_ptr<GooString> name; // Name
1636 Instance **instances; // Instances
1637 int nInstances;
1638 };
1639
1640 class Content;
1641
1642 class POPPLER_PRIVATE_EXPORT Asset
1643 {
1644 public:
1645 Asset();
1646 ~Asset();
1647
1648 Asset(const Asset &) = delete;
1649 Asset &operator=(const Asset &) = delete;
1650
1651 const GooString *getName() const;
1652 Object *getFileSpec() const;
1653
1654 private:
1655 friend class AnnotRichMedia::Content;
1656
1657 std::unique_ptr<GooString> name;
1658 Object fileSpec;
1659 };
1660
1661 class POPPLER_PRIVATE_EXPORT Content
1662 {
1663 public:
1664 explicit Content(Dict *dict);
1665 ~Content();
1666
1667 Content(const Content &) = delete;
1668 Content &operator=(const Content &) = delete;
1669
1670 int getConfigurationsCount() const;
1671 Configuration *getConfiguration(int index) const;
1672
1673 int getAssetsCount() const;
1674 Asset *getAsset(int index) const;
1675
1676 private:
1677 // optional
1678 Configuration **configurations; // Configurations
1679 int nConfigurations;
1680
1681 Asset **assets; // Assets
1682 int nAssets;
1683 };
1684
1685 class POPPLER_PRIVATE_EXPORT Activation
1686 {
1687 public:
1688 enum Condition
1689 {
1690 conditionPageOpened, // PO
1691 conditionPageVisible, // PV
1692 conditionUserAction // XA
1693 };
1694
1695 explicit Activation(Dict *dict);
1696
1697 Condition getCondition() const;
1698
1699 private:
1700 // optional
1701 Condition condition;
1702 };
1703
1704 class POPPLER_PRIVATE_EXPORT Deactivation
1705 {
1706 public:
1707 enum Condition
1708 {
1709 conditionPageClosed, // PC
1710 conditionPageInvisible, // PI
1711 conditionUserAction // XD
1712 };
1713
1714 explicit Deactivation(Dict *dict);
1715
1716 Condition getCondition() const;
1717
1718 private:
1719 // optional
1720 Condition condition;
1721 };
1722
1723 class POPPLER_PRIVATE_EXPORT Settings
1724 {
1725 public:
1726 explicit Settings(Dict *dict);
1727 ~Settings();
1728
1729 Settings(const Settings &) = delete;
1730 Settings &operator=(const Settings &) = delete;
1731
1732 Activation *getActivation() const;
1733 Deactivation *getDeactivation() const;
1734
1735 private:
1736 // optional
1737 std::unique_ptr<Activation> activation;
1738 std::unique_ptr<Deactivation> deactivation;
1739 };
1740
1741 AnnotRichMedia(PDFDoc *docA, PDFRectangle *rect);
1742 AnnotRichMedia(PDFDoc *docA, Object &&dictObject, const Object *obj);
1743 ~AnnotRichMedia() override;
1744
1745 Content *getContent() const;
1746
1747 Settings *getSettings() const;
1748
1749private:
1750 void initialize(PDFDoc *docA, Dict *dict);
1751
1752 // required
1753 std::unique_ptr<Content> content; // RichMediaContent
1754
1755 // optional
1756 std::unique_ptr<Settings> settings; // RichMediaSettings
1757};
1758
1759//------------------------------------------------------------------------
1760// Annots
1761//------------------------------------------------------------------------
1762
1763class POPPLER_PRIVATE_EXPORT Annots
1764{
1765public:
1766 // Build a list of Annot objects and call setPage on them
1767 Annots(PDFDoc *docA, int page, Object *annotsObj);
1768
1769 ~Annots();
1770
1771 Annots(const Annots &) = delete;
1772 Annots &operator=(const Annots &) = delete;
1773
1774 const std::vector<Annot *> &getAnnots() { return annots; }
1775
1776 void appendAnnot(Annot *annot);
1777 bool removeAnnot(Annot *annot);
1778
1779private:
1780 Annot *createAnnot(Object &&dictObject, const Object *obj);
1781 Annot *findAnnot(Ref *ref);
1782
1783 PDFDoc *doc;
1784 std::vector<Annot *> annots;
1785};
1786
1787#endif
1788

source code of poppler/poppler/Annot.h