Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-10 10:23:45

0001 //========================================================================
0002 //
0003 // Annot.h
0004 //
0005 // Copyright 2000-2003 Glyph & Cog, LLC
0006 //
0007 //========================================================================
0008 
0009 //========================================================================
0010 //
0011 // Modified under the Poppler project - http://poppler.freedesktop.org
0012 //
0013 // All changes made under the Poppler project to this file are licensed
0014 // under GPL version 2 or later
0015 //
0016 // Copyright (C) 2006 Scott Turner <scotty1024@mac.com>
0017 // Copyright (C) 2007, 2008 Julien Rebetez <julienr@svn.gnome.org>
0018 // Copyright (C) 2007-2011, 2013, 2015, 2018 Carlos Garcia Campos <carlosgc@gnome.org>
0019 // Copyright (C) 2007, 2008 Iñigo Martínez <inigomartinez@gmail.com>
0020 // Copyright (C) 2008 Michael Vrable <mvrable@cs.ucsd.edu>
0021 // Copyright (C) 2008 Hugo Mercier <hmercier31@gmail.com>
0022 // Copyright (C) 2008 Pino Toscano <pino@kde.org>
0023 // Copyright (C) 2008 Tomas Are Haavet <tomasare@gmail.com>
0024 // Copyright (C) 2009-2011, 2013, 2016-2022 Albert Astals Cid <aacid@kde.org>
0025 // Copyright (C) 2012, 2013 Fabio D'Urso <fabiodurso@hotmail.it>
0026 // Copyright (C) 2012, 2015 Tobias Koenig <tokoe@kdab.com>
0027 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
0028 // Copyright (C) 2013, 2017 Adrian Johnson <ajohnson@redneon.com>
0029 // 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
0030 // Copyright (C) 2018 Dileep Sankhla <sankhla.dileep96@gmail.com>
0031 // Copyright (C) 2018-2020 Tobias Deiminger <haxtibal@posteo.de>
0032 // Copyright (C) 2018, 2020, 2022 Oliver Sander <oliver.sander@tu-dresden.de>
0033 // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
0034 // Copyright (C) 2019 Umang Malik <umang99m@gmail.com>
0035 // Copyright (C) 2019 João Netto <joaonetto901@gmail.com>
0036 // Copyright (C) 2020 Nelson Benítez León <nbenitezl@gmail.com>
0037 // Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by Technische Universität Dresden
0038 // Copyright (C) 2020 Katarina Behrens <Katarina.Behrens@cib.de>
0039 // Copyright (C) 2020 Thorsten Behrens <Thorsten.Behrens@CIB.de>
0040 // Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>.
0041 // Copyright (C) 2021 Zachary Travis <ztravis@everlaw.com>
0042 // Copyright (C) 2021 Mahmoud Ahmed Khalil <mahmoudkhalil11@gmail.com>
0043 // Copyright (C) 2021 Georgiy Sgibnev <georgiy@sgibnev.com>. Work sponsored by lab50.net.
0044 // Copyright (C) 2022 Martin <martinbts@gmx.net>
0045 //
0046 // To see a description of the changes please see the Changelog file that
0047 // came with your tarball or type make ChangeLog if you are building from git
0048 //
0049 //========================================================================
0050 
0051 #ifndef ANNOT_H
0052 #define ANNOT_H
0053 
0054 #include <memory>
0055 #include <atomic>
0056 #include <mutex>
0057 #include <vector>
0058 
0059 #include "AnnotStampImageHelper.h"
0060 #include "Object.h"
0061 #include "poppler_private_export.h"
0062 
0063 class XRef;
0064 class Gfx;
0065 class CharCodeToUnicode;
0066 class GfxFont;
0067 class GfxResources;
0068 class Page;
0069 class PDFDoc;
0070 class Form;
0071 class FormWidget;
0072 class FormField;
0073 class FormFieldButton;
0074 class FormFieldText;
0075 class FormFieldChoice;
0076 class FormFieldSignature;
0077 class PDFRectangle;
0078 class Movie;
0079 class LinkAction;
0080 class Sound;
0081 class FileSpec;
0082 
0083 enum AnnotLineEndingStyle
0084 {
0085     annotLineEndingSquare, // Square
0086     annotLineEndingCircle, // Circle
0087     annotLineEndingDiamond, // Diamond
0088     annotLineEndingOpenArrow, // OpenArrow
0089     annotLineEndingClosedArrow, // ClosedArrow
0090     annotLineEndingNone, // None
0091     annotLineEndingButt, // Butt
0092     annotLineEndingROpenArrow, // ROpenArrow
0093     annotLineEndingRClosedArrow, // RClosedArrow
0094     annotLineEndingSlash // Slash
0095 };
0096 
0097 enum AnnotExternalDataType
0098 {
0099     annotExternalDataMarkupUnknown,
0100     annotExternalDataMarkup3D // Markup3D
0101 };
0102 
0103 enum class VariableTextQuadding
0104 {
0105     leftJustified,
0106     centered,
0107     rightJustified
0108 };
0109 
0110 //------------------------------------------------------------------------
0111 // AnnotCoord
0112 //------------------------------------------------------------------------
0113 
0114 class AnnotCoord
0115 {
0116 public:
0117     AnnotCoord() : x(0), y(0) { }
0118     AnnotCoord(double _x, double _y) : x(_x), y(_y) { }
0119 
0120     double getX() const { return x; }
0121     double getY() const { return y; }
0122 
0123 protected:
0124     double x, y;
0125 };
0126 
0127 //------------------------------------------------------------------------
0128 // AnnotPath
0129 //------------------------------------------------------------------------
0130 
0131 class POPPLER_PRIVATE_EXPORT AnnotPath
0132 {
0133 public:
0134     AnnotPath();
0135     explicit AnnotPath(Array *array);
0136     explicit AnnotPath(std::vector<AnnotCoord> &&coords);
0137     ~AnnotPath();
0138 
0139     AnnotPath(const AnnotPath &) = delete;
0140     AnnotPath &operator=(const AnnotPath &other) = delete;
0141 
0142     double getX(int coord) const;
0143     double getY(int coord) const;
0144     AnnotCoord *getCoord(int coord);
0145     int getCoordsLength() const { return coords.size(); }
0146 
0147 protected:
0148     std::vector<AnnotCoord> coords;
0149 
0150     void parsePathArray(Array *array);
0151 };
0152 
0153 //------------------------------------------------------------------------
0154 // AnnotCalloutLine
0155 //------------------------------------------------------------------------
0156 
0157 class POPPLER_PRIVATE_EXPORT AnnotCalloutLine
0158 {
0159 public:
0160     AnnotCalloutLine(double x1, double y1, double x2, double y2);
0161     virtual ~AnnotCalloutLine();
0162 
0163     AnnotCalloutLine(const AnnotCalloutLine &) = delete;
0164     AnnotCalloutLine &operator=(const AnnotCalloutLine &other) = delete;
0165 
0166     double getX1() const { return coord1.getX(); }
0167     double getY1() const { return coord1.getY(); }
0168     double getX2() const { return coord2.getX(); }
0169     double getY2() const { return coord2.getY(); }
0170 
0171 protected:
0172     AnnotCoord coord1, coord2;
0173 };
0174 
0175 //------------------------------------------------------------------------
0176 // AnnotCalloutMultiLine
0177 //------------------------------------------------------------------------
0178 
0179 class POPPLER_PRIVATE_EXPORT AnnotCalloutMultiLine : public AnnotCalloutLine
0180 {
0181 public:
0182     AnnotCalloutMultiLine(double x1, double y1, double x2, double y2, double x3, double y3);
0183     ~AnnotCalloutMultiLine() override;
0184 
0185     double getX3() const { return coord3.getX(); }
0186     double getY3() const { return coord3.getY(); }
0187 
0188 protected:
0189     AnnotCoord coord3;
0190 };
0191 
0192 //------------------------------------------------------------------------
0193 // AnnotBorderEffect
0194 //------------------------------------------------------------------------
0195 
0196 class AnnotBorderEffect
0197 {
0198 public:
0199     enum AnnotBorderEffectType
0200     {
0201         borderEffectNoEffect, // S
0202         borderEffectCloudy // C
0203     };
0204 
0205     explicit AnnotBorderEffect(Dict *dict);
0206 
0207     AnnotBorderEffectType getEffectType() const { return effectType; }
0208     double getIntensity() const { return intensity; }
0209 
0210 private:
0211     AnnotBorderEffectType effectType; // S  (Default S)
0212     double intensity; // I  (Default 0)
0213 };
0214 
0215 //------------------------------------------------------------------------
0216 // AnnotQuadrilateral
0217 //------------------------------------------------------------------------
0218 
0219 class POPPLER_PRIVATE_EXPORT AnnotQuadrilaterals
0220 {
0221 public:
0222     class POPPLER_PRIVATE_EXPORT AnnotQuadrilateral
0223     {
0224     public:
0225         AnnotQuadrilateral();
0226         AnnotQuadrilateral(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
0227 
0228         AnnotCoord coord1, coord2, coord3, coord4;
0229     };
0230 
0231     AnnotQuadrilaterals(Array *array, PDFRectangle *rect);
0232     AnnotQuadrilaterals(std::unique_ptr<AnnotQuadrilateral[]> &&quads, int quadsLength);
0233     ~AnnotQuadrilaterals();
0234 
0235     AnnotQuadrilaterals(const AnnotQuadrilaterals &) = delete;
0236     AnnotQuadrilaterals &operator=(const AnnotQuadrilaterals &other) = delete;
0237 
0238     double getX1(int quadrilateral);
0239     double getY1(int quadrilateral);
0240     double getX2(int quadrilateral);
0241     double getY2(int quadrilateral);
0242     double getX3(int quadrilateral);
0243     double getY3(int quadrilateral);
0244     double getX4(int quadrilateral);
0245     double getY4(int quadrilateral);
0246     int getQuadrilateralsLength() const { return quadrilateralsLength; }
0247 
0248 protected:
0249     std::unique_ptr<AnnotQuadrilateral[]> quadrilaterals;
0250     int quadrilateralsLength;
0251 };
0252 
0253 //------------------------------------------------------------------------
0254 // AnnotBorder
0255 //------------------------------------------------------------------------
0256 
0257 class POPPLER_PRIVATE_EXPORT AnnotBorder
0258 {
0259 public:
0260     enum AnnotBorderType
0261     {
0262         typeArray,
0263         typeBS
0264     };
0265 
0266     enum AnnotBorderStyle
0267     {
0268         borderSolid, // Solid
0269         borderDashed, // Dashed
0270         borderBeveled, // Beveled
0271         borderInset, // Inset
0272         borderUnderlined // Underlined
0273     };
0274 
0275     virtual ~AnnotBorder();
0276 
0277     AnnotBorder(const AnnotBorder &) = delete;
0278     AnnotBorder &operator=(const AnnotBorder &other) = delete;
0279 
0280     virtual void setWidth(double new_width) { width = new_width; }
0281 
0282     virtual AnnotBorderType getType() const = 0;
0283     virtual double getWidth() const { return width; }
0284     virtual const std::vector<double> &getDash() const { return dash; }
0285     virtual AnnotBorderStyle getStyle() const { return style; }
0286 
0287     virtual Object writeToObject(XRef *xref) const = 0;
0288     virtual std::unique_ptr<AnnotBorder> copy() const = 0;
0289 
0290 protected:
0291     AnnotBorder();
0292 
0293     bool parseDashArray(Object *dashObj);
0294 
0295     AnnotBorderType type;
0296     double width;
0297     static const int DASH_LIMIT = 10; // implementation note 82 in Appendix H.
0298     std::vector<double> dash;
0299     AnnotBorderStyle style;
0300 };
0301 
0302 //------------------------------------------------------------------------
0303 // AnnotBorderArray
0304 //------------------------------------------------------------------------
0305 
0306 class POPPLER_PRIVATE_EXPORT AnnotBorderArray : public AnnotBorder
0307 {
0308 public:
0309     AnnotBorderArray();
0310     explicit AnnotBorderArray(Array *array);
0311 
0312     void setHorizontalCorner(double hc) { horizontalCorner = hc; }
0313     void setVerticalCorner(double vc) { verticalCorner = vc; }
0314 
0315     double getHorizontalCorner() const { return horizontalCorner; }
0316     double getVerticalCorner() const { return verticalCorner; }
0317 
0318     std::unique_ptr<AnnotBorder> copy() const override;
0319 
0320 private:
0321     AnnotBorderType getType() const override { return typeArray; }
0322     Object writeToObject(XRef *xref) const override;
0323 
0324     double horizontalCorner; // (Default 0)
0325     double verticalCorner; // (Default 0)
0326     // double width;                  // (Default 1)  (inherited from AnnotBorder)
0327 };
0328 
0329 //------------------------------------------------------------------------
0330 // AnnotBorderBS
0331 //------------------------------------------------------------------------
0332 
0333 class AnnotBorderBS : public AnnotBorder
0334 {
0335 public:
0336     AnnotBorderBS();
0337     explicit AnnotBorderBS(Dict *dict);
0338 
0339 private:
0340     AnnotBorderType getType() const override { return typeBS; }
0341     Object writeToObject(XRef *xref) const override;
0342 
0343     const char *getStyleName() const;
0344 
0345     std::unique_ptr<AnnotBorder> copy() const override;
0346 
0347     // double width;           // W  (Default 1)   (inherited from AnnotBorder)
0348     // AnnotBorderStyle style; // S  (Default S)   (inherited from AnnotBorder)
0349     // double *dash;           // D  (Default [3]) (inherited from AnnotBorder)
0350 };
0351 
0352 //------------------------------------------------------------------------
0353 // AnnotColor
0354 //------------------------------------------------------------------------
0355 
0356 class POPPLER_PRIVATE_EXPORT AnnotColor
0357 {
0358 public:
0359     enum AnnotColorSpace
0360     {
0361         colorTransparent = 0,
0362         colorGray = 1,
0363         colorRGB = 3,
0364         colorCMYK = 4
0365     };
0366 
0367     AnnotColor();
0368     explicit AnnotColor(double gray);
0369     AnnotColor(double r, double g, double b);
0370     AnnotColor(double c, double m, double y, double k);
0371     explicit AnnotColor(Array *array, int adjust = 0);
0372 
0373     void adjustColor(int adjust);
0374 
0375     AnnotColorSpace getSpace() const { return (AnnotColorSpace)length; }
0376     const double *getValues() const { return values; }
0377 
0378     Object writeToObject(XRef *xref) const;
0379 
0380 private:
0381     double values[4];
0382     int length;
0383 };
0384 
0385 //------------------------------------------------------------------------
0386 // DefaultAppearance
0387 //------------------------------------------------------------------------
0388 
0389 class POPPLER_PRIVATE_EXPORT DefaultAppearance
0390 {
0391 public:
0392     DefaultAppearance(Object &&fontNameA, double fontPtSizeA, std::unique_ptr<AnnotColor> &&fontColorA);
0393     explicit DefaultAppearance(const GooString *da);
0394     void setFontName(Object &&fontNameA);
0395     const Object &getFontName() const { return fontName; }
0396     void setFontPtSize(double fontPtSizeA);
0397     double getFontPtSize() const { return fontPtSize; }
0398     void setFontColor(std::unique_ptr<AnnotColor> fontColorA);
0399     const AnnotColor *getFontColor() const { return fontColor.get(); }
0400     std::string toAppearanceString() const;
0401 
0402     DefaultAppearance(const DefaultAppearance &) = delete;
0403     DefaultAppearance &operator=(const DefaultAppearance &) = delete;
0404 
0405 private:
0406     Object fontName;
0407     double fontPtSize;
0408     std::unique_ptr<AnnotColor> fontColor;
0409 };
0410 
0411 //------------------------------------------------------------------------
0412 // AnnotIconFit
0413 //------------------------------------------------------------------------
0414 
0415 class AnnotIconFit
0416 {
0417 public:
0418     enum AnnotIconFitScaleWhen
0419     {
0420         scaleAlways, // A
0421         scaleBigger, // B
0422         scaleSmaller, // S
0423         scaleNever // N
0424     };
0425 
0426     enum AnnotIconFitScale
0427     {
0428         scaleAnamorphic, // A
0429         scaleProportional // P
0430     };
0431 
0432     explicit AnnotIconFit(Dict *dict);
0433 
0434     AnnotIconFitScaleWhen getScaleWhen() { return scaleWhen; }
0435     AnnotIconFitScale getScale() { return scale; }
0436     double getLeft() { return left; }
0437     double getBottom() { return bottom; }
0438     bool getFullyBounds() { return fullyBounds; }
0439 
0440 protected:
0441     AnnotIconFitScaleWhen scaleWhen; // SW (Default A)
0442     AnnotIconFitScale scale; // S  (Default P)
0443     double left; // A  (Default [0.5 0.5]
0444     double bottom; // Only if scale is P
0445     bool fullyBounds; // FB (Default false)
0446 };
0447 
0448 //------------------------------------------------------------------------
0449 // AnnotAppearance
0450 //------------------------------------------------------------------------
0451 
0452 class AnnotAppearance
0453 {
0454 public:
0455     enum AnnotAppearanceType
0456     {
0457         appearNormal,
0458         appearRollover,
0459         appearDown
0460     };
0461 
0462     AnnotAppearance(PDFDoc *docA, Object *dict);
0463     ~AnnotAppearance();
0464 
0465     // State is ignored if no subdictionary is present
0466     Object getAppearanceStream(AnnotAppearanceType type, const char *state);
0467 
0468     // Access keys in normal appearance subdictionary (N)
0469     std::unique_ptr<GooString> getStateKey(int i);
0470     int getNumStates();
0471 
0472     // Removes all associated streams in the xref table. Caller is required to
0473     // reset parent annotation's AP and AS after this call.
0474     void removeAllStreams();
0475 
0476     // Test if this AnnotAppearance references the specified stream
0477     bool referencesStream(Ref refToStream);
0478 
0479 private:
0480     static bool referencesStream(const Object *stateObj, Ref refToStream);
0481     void removeStream(Ref refToStream);
0482     void removeStateStreams(const Object *state);
0483 
0484 protected:
0485     PDFDoc *doc;
0486     Object appearDict; // Annotation's AP
0487 };
0488 
0489 //------------------------------------------------------------------------
0490 // AnnotAppearanceCharacs
0491 //------------------------------------------------------------------------
0492 
0493 class POPPLER_PRIVATE_EXPORT AnnotAppearanceCharacs
0494 {
0495 public:
0496     enum AnnotAppearanceCharacsTextPos
0497     {
0498         captionNoIcon, // 0
0499         captionNoCaption, // 1
0500         captionBelow, // 2
0501         captionAbove, // 3
0502         captionRight, // 4
0503         captionLeft, // 5
0504         captionOverlaid // 6
0505     };
0506 
0507     explicit AnnotAppearanceCharacs(Dict *dict);
0508     ~AnnotAppearanceCharacs();
0509 
0510     AnnotAppearanceCharacs(const AnnotAppearanceCharacs &) = delete;
0511     AnnotAppearanceCharacs &operator=(const AnnotAppearanceCharacs &) = delete;
0512 
0513     int getRotation() const { return rotation; }
0514     const AnnotColor *getBorderColor() const { return borderColor.get(); }
0515     void setBorderColor(std::unique_ptr<AnnotColor> &&color) { borderColor = std::move(color); }
0516     const AnnotColor *getBackColor() const { return backColor.get(); }
0517     void setBackColor(std::unique_ptr<AnnotColor> &&color) { backColor = std::move(color); }
0518     const GooString *getNormalCaption() const { return normalCaption.get(); }
0519     const GooString *getRolloverCaption() { return rolloverCaption.get(); }
0520     const GooString *getAlternateCaption() { return alternateCaption.get(); }
0521     const AnnotIconFit *getIconFit() { return iconFit.get(); }
0522     AnnotAppearanceCharacsTextPos getPosition() const { return position; }
0523 
0524     std::unique_ptr<AnnotAppearanceCharacs> copy() const;
0525 
0526 protected:
0527     int rotation; // R  (Default 0)
0528     std::unique_ptr<AnnotColor> borderColor; // BC
0529     std::unique_ptr<AnnotColor> backColor; // BG
0530     std::unique_ptr<GooString> normalCaption; // CA
0531     std::unique_ptr<GooString> rolloverCaption; // RC
0532     std::unique_ptr<GooString> alternateCaption; // AC
0533     // I
0534     // RI
0535     // IX
0536     std::unique_ptr<AnnotIconFit> iconFit; // IF
0537     AnnotAppearanceCharacsTextPos position; // TP (Default 0)
0538 };
0539 
0540 //------------------------------------------------------------------------
0541 // AnnotAppearanceBBox
0542 //------------------------------------------------------------------------
0543 
0544 class AnnotAppearanceBBox
0545 {
0546 public:
0547     explicit AnnotAppearanceBBox(PDFRectangle *rect);
0548 
0549     void setBorderWidth(double w) { borderWidth = w; }
0550 
0551     // The following functions operate on coords relative to [origX origY]
0552     void extendTo(double x, double y);
0553     void getBBoxRect(double bbox[4]) const;
0554 
0555     // Get boundaries in page coordinates
0556     double getPageXMin() const;
0557     double getPageYMin() const;
0558     double getPageXMax() const;
0559     double getPageYMax() const;
0560 
0561 private:
0562     double origX, origY, borderWidth;
0563     double minX, minY, maxX, maxY;
0564 };
0565 
0566 //------------------------------------------------------------------------
0567 // AnnotAppearanceBuilder
0568 //------------------------------------------------------------------------
0569 class Matrix;
0570 
0571 class AnnotAppearanceBuilder
0572 {
0573 public:
0574     AnnotAppearanceBuilder();
0575     ~AnnotAppearanceBuilder();
0576 
0577     AnnotAppearanceBuilder(const AnnotAppearanceBuilder &) = delete;
0578     AnnotAppearanceBuilder &operator=(const AnnotAppearanceBuilder &) = delete;
0579 
0580     void setDrawColor(const AnnotColor *color, bool fill);
0581     void setLineStyleForBorder(const AnnotBorder *border);
0582     void setTextFont(const Object &fontName, double fontSize);
0583     void drawCircle(double cx, double cy, double r, bool fill);
0584     void drawEllipse(double cx, double cy, double rx, double ry, bool fill, bool stroke);
0585     void drawCircleTopLeft(double cx, double cy, double r);
0586     void drawCircleBottomRight(double cx, double cy, double r);
0587     void drawLineEnding(AnnotLineEndingStyle endingStyle, double x, double y, double size, bool fill, const Matrix &m);
0588     void drawLineEndSquare(double x, double y, double size, bool fill, const Matrix &m);
0589     void drawLineEndCircle(double x, double y, double size, bool fill, const Matrix &m);
0590     void drawLineEndDiamond(double x, double y, double size, bool fill, const Matrix &m);
0591     void drawLineEndArrow(double x, double y, double size, int orientation, bool isOpen, bool fill, const Matrix &m);
0592     void drawLineEndSlash(double x, double y, double size, const Matrix &m);
0593     void drawFieldBorder(const FormField *field, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect);
0594     bool drawFormField(const FormField *field, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
0595                        const GooString *appearState, XRef *xref, Dict *resourcesDict);
0596     static double lineEndingXShorten(AnnotLineEndingStyle endingStyle, double size);
0597     static double lineEndingXExtendBBox(AnnotLineEndingStyle endingStyle, double size);
0598     void writeString(const std::string &str);
0599 
0600     void append(const char *text);
0601     void appendf(const char *fmt, ...) GOOSTRING_FORMAT;
0602 
0603     const GooString *buffer() const;
0604 
0605 private:
0606     enum DrawTextFlags
0607     {
0608         NoDrawTextFlags = 0,
0609         MultilineDrawTextFlag = 1,
0610         EmitMarkedContentDrawTextFlag = 2,
0611         ForceZapfDingbatsDrawTextFlag = 4,
0612         TurnTextToStarsDrawTextFlag = 8
0613     };
0614 
0615     bool drawListBox(const FormFieldChoice *fieldChoice, const AnnotBorder *border, const PDFRectangle *rect, const GooString *da, const GfxResources *resources, VariableTextQuadding quadding, XRef *xref, Dict *resourcesDict);
0616     bool drawFormFieldButton(const FormFieldButton *field, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
0617                              const GooString *appearState, XRef *xref, Dict *resourcesDict);
0618     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,
0619                            Dict *resourcesDict);
0620     bool drawFormFieldChoice(const FormFieldChoice *fieldChoice, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
0621                              XRef *xref, Dict *resourcesDict);
0622     bool drawSignatureFieldText(const FormFieldSignature *field, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
0623                                 XRef *xref, Dict *resourcesDict);
0624     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,
0625                                 bool centerHorizontally);
0626     bool drawText(const GooString *text, const Form *form, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
0627                   const VariableTextQuadding quadding, XRef *xref, Dict *resourcesDict, const int flags = NoDrawTextFlags, const int nCombs = 0);
0628     void drawArrowPath(double x, double y, const Matrix &m, int orientation = 1);
0629 
0630     GooString *appearBuf;
0631 };
0632 
0633 //------------------------------------------------------------------------
0634 // Annot
0635 //------------------------------------------------------------------------
0636 
0637 class POPPLER_PRIVATE_EXPORT Annot
0638 {
0639     friend class Annots;
0640     friend class Page;
0641 
0642 public:
0643     enum AnnotFlag
0644     {
0645         flagUnknown = 0x0000,
0646         flagInvisible = 0x0001,
0647         flagHidden = 0x0002,
0648         flagPrint = 0x0004,
0649         flagNoZoom = 0x0008,
0650         flagNoRotate = 0x0010,
0651         flagNoView = 0x0020,
0652         flagReadOnly = 0x0040,
0653         flagLocked = 0x0080,
0654         flagToggleNoView = 0x0100,
0655         flagLockedContents = 0x0200
0656     };
0657 
0658     enum AnnotSubtype
0659     {
0660         typeUnknown, //                 0
0661         typeText, // Text            1
0662         typeLink, // Link            2
0663         typeFreeText, // FreeText        3
0664         typeLine, // Line            4
0665         typeSquare, // Square          5
0666         typeCircle, // Circle          6
0667         typePolygon, // Polygon         7
0668         typePolyLine, // PolyLine        8
0669         typeHighlight, // Highlight       9
0670         typeUnderline, // Underline      10
0671         typeSquiggly, // Squiggly       11
0672         typeStrikeOut, // StrikeOut      12
0673         typeStamp, // Stamp          13
0674         typeCaret, // Caret          14
0675         typeInk, // Ink            15
0676         typePopup, // Popup          16
0677         typeFileAttachment, // FileAttachment 17
0678         typeSound, // Sound          18
0679         typeMovie, // Movie          19
0680         typeWidget, // Widget         20
0681         typeScreen, // Screen         21
0682         typePrinterMark, // PrinterMark    22
0683         typeTrapNet, // TrapNet        23
0684         typeWatermark, // Watermark      24
0685         type3D, // 3D             25
0686         typeRichMedia // RichMedia      26
0687     };
0688 
0689     /**
0690      * Describes the additional actions of a screen or widget annotation.
0691      */
0692     enum AdditionalActionsType
0693     {
0694         actionCursorEntering, ///< Performed when the cursor enters the annotation's active area
0695         actionCursorLeaving, ///< Performed when the cursor exists the annotation's active area
0696         actionMousePressed, ///< Performed when the mouse button is pressed inside the annotation's active area
0697         actionMouseReleased, ///< Performed when the mouse button is released inside the annotation's active area
0698         actionFocusIn, ///< Performed when the annotation receives the input focus
0699         actionFocusOut, ///< Performed when the annotation loses the input focus
0700         actionPageOpening, ///< Performed when the page containing the annotation is opened
0701         actionPageClosing, ///< Performed when the page containing the annotation is closed
0702         actionPageVisible, ///< Performed when the page containing the annotation becomes visible
0703         actionPageInvisible ///< Performed when the page containing the annotation becomes invisible
0704     };
0705 
0706     enum FormAdditionalActionsType
0707     {
0708         actionFieldModified, ///< Performed when the when the user modifies the field
0709         actionFormatField, ///< Performed before the field is formatted to display its value
0710         actionValidateField, ///< Performed when the field value changes
0711         actionCalculateField, ///< Performed when the field needs to be recalculated
0712     };
0713 
0714     Annot(PDFDoc *docA, PDFRectangle *rectA);
0715     Annot(PDFDoc *docA, Object &&dictObject);
0716     Annot(PDFDoc *docA, Object &&dictObject, const Object *obj);
0717     bool isOk() { return ok; }
0718 
0719     void incRefCnt();
0720     void decRefCnt();
0721 
0722     virtual void draw(Gfx *gfx, bool printing);
0723     // Get the resource dict of the appearance stream
0724     virtual Object getAppearanceResDict();
0725 
0726     bool match(const Ref *refA) const { return ref == *refA; }
0727 
0728     double getXMin();
0729     double getYMin();
0730     double getXMax();
0731     double getYMax();
0732 
0733     void setRect(const PDFRectangle *rect);
0734     void setRect(double x1, double y1, double x2, double y2);
0735 
0736     // Sets the annot contents to new_content
0737     // new_content should never be NULL
0738     virtual void setContents(std::unique_ptr<GooString> &&new_content);
0739     void setName(GooString *new_name);
0740     void setModified(GooString *new_modified);
0741     void setFlags(unsigned int new_flags);
0742 
0743     void setBorder(std::unique_ptr<AnnotBorder> &&new_border);
0744     void setColor(std::unique_ptr<AnnotColor> &&new_color);
0745 
0746     void setAppearanceState(const char *state);
0747 
0748     // getters
0749     PDFDoc *getDoc() const { return doc; }
0750     bool getHasRef() const { return hasRef; }
0751     Ref getRef() const { return ref; }
0752     const Object &getAnnotObj() const { return annotObj; }
0753     AnnotSubtype getType() const { return type; }
0754     const PDFRectangle &getRect() const { return *rect; }
0755     void getRect(double *x1, double *y1, double *x2, double *y2) const;
0756     const GooString *getContents() const { return contents.get(); }
0757     int getPageNum() const { return page; }
0758     const GooString *getName() const { return name.get(); }
0759     const GooString *getModified() const { return modified.get(); }
0760     unsigned int getFlags() const { return flags; }
0761     Object getAppearance() const;
0762     void setNewAppearance(Object &&newAppearance);
0763     AnnotAppearance *getAppearStreams() const { return appearStreams.get(); }
0764     const GooString *getAppearState() const { return appearState.get(); }
0765     AnnotBorder *getBorder() const { return border.get(); }
0766     AnnotColor *getColor() const { return color.get(); }
0767     int getTreeKey() const { return treeKey; }
0768 
0769     int getId() { return ref.num; }
0770 
0771     // Check if point is inside the annot rectangle.
0772     bool inRect(double x, double y) const;
0773 
0774     // If newFontNeeded is not null, it will contain whether the given font has glyphs to represent the needed text
0775     static void layoutText(const GooString *text, GooString *outBuf, int *i, const GfxFont &font, double *width, double widthLimit, int *charCount, bool noReencode, bool *newFontNeeded = nullptr);
0776 
0777 private:
0778     void readArrayNum(Object *pdfArray, int key, double *value);
0779     // write vStr[i:j[ in appearBuf
0780 
0781     void initialize(PDFDoc *docA, Dict *dict);
0782     void setPage(int pageIndex, bool updateP); // Called by Page::addAnnot and Annots ctor
0783 
0784 protected:
0785     virtual ~Annot();
0786     virtual void removeReferencedObjects(); // Called by Page::removeAnnot
0787     Object createForm(const GooString *appearBuf, const double *bbox, bool transparencyGroup, Dict *resDict);
0788     Object createForm(const GooString *appearBuf, const double *bbox, bool transparencyGroup, Object &&resDictObject); // overload to support incRef/decRef
0789     Dict *createResourcesDict(const char *formName, Object &&formStream, const char *stateName, double opacity, const char *blendMode);
0790     bool isVisible(bool printing);
0791     int getRotation() const;
0792 
0793     // Updates the field key of the annotation dictionary
0794     // and sets M to the current time
0795     void update(const char *key, Object &&value);
0796 
0797     // Delete appearance streams and reset appearance state
0798     virtual void invalidateAppearance();
0799 
0800     Object annotObj;
0801 
0802     std::atomic_int refCnt;
0803 
0804     // required data
0805     AnnotSubtype type; // Annotation type
0806     std::unique_ptr<PDFRectangle> rect; // Rect
0807 
0808     // optional data
0809     std::unique_ptr<GooString> contents; // Contents
0810     std::unique_ptr<GooString> name; // NM
0811     std::unique_ptr<GooString> modified; // M
0812     int page; // P
0813     unsigned int flags; // F (must be a 32 bit unsigned int)
0814     std::unique_ptr<AnnotAppearance> appearStreams; // AP
0815     Object appearance; // a reference to the Form XObject stream
0816                        //   for the normal appearance
0817     std::unique_ptr<AnnotAppearanceBBox> appearBBox; // BBox of generated appearance
0818     std::unique_ptr<GooString> appearState; // AS
0819     int treeKey; // Struct Parent;
0820     Object oc; // OC
0821 
0822     PDFDoc *doc;
0823     Ref ref; // object ref identifying this annotation
0824     std::unique_ptr<AnnotBorder> border; // Border, BS
0825     std::unique_ptr<AnnotColor> color; // C
0826     bool ok;
0827 
0828     bool hasRef;
0829     mutable std::recursive_mutex mutex;
0830 
0831     bool hasBeenUpdated = false;
0832 };
0833 
0834 //------------------------------------------------------------------------
0835 // AnnotPopup
0836 //------------------------------------------------------------------------
0837 
0838 class POPPLER_PRIVATE_EXPORT AnnotPopup : public Annot
0839 {
0840 public:
0841     AnnotPopup(PDFDoc *docA, PDFRectangle *rect);
0842     AnnotPopup(PDFDoc *docA, Object &&dictObject, const Object *obj);
0843     ~AnnotPopup() override;
0844 
0845     bool hasParent() const { return parentRef != Ref::INVALID(); }
0846     void setParent(Annot *parentA);
0847     bool getOpen() const { return open; }
0848     void setOpen(bool openA);
0849 
0850 protected:
0851     void initialize(PDFDoc *docA, Dict *dict);
0852 
0853     Ref parentRef; // Parent
0854     bool open; // Open
0855 };
0856 
0857 //------------------------------------------------------------------------
0858 // AnnotMarkup
0859 //------------------------------------------------------------------------
0860 
0861 class POPPLER_PRIVATE_EXPORT AnnotMarkup : public Annot
0862 {
0863 public:
0864     enum AnnotMarkupReplyType
0865     {
0866         replyTypeR, // R
0867         replyTypeGroup // Group
0868     };
0869 
0870     AnnotMarkup(PDFDoc *docA, PDFRectangle *rect);
0871     AnnotMarkup(PDFDoc *docA, Object &&dictObject, const Object *obj);
0872     ~AnnotMarkup() override;
0873 
0874     // getters
0875     const GooString *getLabel() const { return label.get(); }
0876     AnnotPopup *getPopup() const { return popup.get(); }
0877     double getOpacity() const { return opacity; }
0878     // getRC
0879     const GooString *getDate() const { return date.get(); }
0880     bool isInReplyTo() const { return inReplyTo != Ref::INVALID(); }
0881     int getInReplyToID() const { return inReplyTo.num; }
0882     const GooString *getSubject() const { return subject.get(); }
0883     AnnotMarkupReplyType getReplyTo() const { return replyTo; }
0884     AnnotExternalDataType getExData() const { return exData; }
0885 
0886     // The annotation takes the ownership of new_popup
0887     void setPopup(std::unique_ptr<AnnotPopup> &&new_popup);
0888     void setLabel(std::unique_ptr<GooString> &&new_label);
0889     void setOpacity(double opacityA);
0890     void setDate(GooString *new_date);
0891 
0892 protected:
0893     void removeReferencedObjects() override;
0894 
0895     std::unique_ptr<GooString> label; // T            (Default author)
0896     std::unique_ptr<AnnotPopup> popup; // Popup
0897     double opacity; // CA           (Default 1.0)
0898     // RC
0899     std::unique_ptr<GooString> date; // CreationDate
0900     Ref inReplyTo; // IRT
0901     std::unique_ptr<GooString> subject; // Subj
0902     AnnotMarkupReplyType replyTo; // RT           (Default R)
0903     // this object is overridden by the custom intent fields defined in some
0904     // annotation types.
0905     // GooString *intent;                // IT
0906     AnnotExternalDataType exData; // ExData
0907 
0908 private:
0909     void initialize(PDFDoc *docA, Dict *dict);
0910 };
0911 
0912 //------------------------------------------------------------------------
0913 // AnnotText
0914 //------------------------------------------------------------------------
0915 
0916 class POPPLER_PRIVATE_EXPORT AnnotText : public AnnotMarkup
0917 {
0918 public:
0919     enum AnnotTextState
0920     {
0921         stateUnknown,
0922         // Marked state model
0923         stateMarked, // Marked
0924         stateUnmarked, // Unmarked
0925         // Review state model
0926         stateAccepted, // Accepted
0927         stateRejected, // Rejected
0928         stateCancelled, // Cancelled
0929         stateCompleted, // Completed
0930         stateNone // None
0931     };
0932 
0933     AnnotText(PDFDoc *docA, PDFRectangle *rect);
0934     AnnotText(PDFDoc *docA, Object &&dictObject, const Object *obj);
0935     ~AnnotText() override;
0936 
0937     void draw(Gfx *gfx, bool printing) override;
0938 
0939     // getters
0940     bool getOpen() const { return open; }
0941     const GooString *getIcon() const { return icon.get(); }
0942     AnnotTextState getState() const { return state; }
0943 
0944     void setOpen(bool openA);
0945     void setIcon(GooString *new_icon);
0946 
0947 private:
0948     void initialize(PDFDoc *docA, Dict *dict);
0949 
0950     bool open; // Open       (Default false)
0951     std::unique_ptr<GooString> icon; // Name       (Default Note)
0952     AnnotTextState state; // State      (Default Umarked if
0953                           //             StateModel Marked
0954                           //             None if StareModel Review)
0955 };
0956 
0957 //------------------------------------------------------------------------
0958 // AnnotMovie
0959 //------------------------------------------------------------------------
0960 
0961 class POPPLER_PRIVATE_EXPORT AnnotMovie : public Annot
0962 {
0963 public:
0964     AnnotMovie(PDFDoc *docA, PDFRectangle *rect, Movie *movieA);
0965     AnnotMovie(PDFDoc *docA, Object &&dictObject, const Object *obj);
0966     ~AnnotMovie() override;
0967 
0968     void draw(Gfx *gfx, bool printing) override;
0969 
0970     const GooString *getTitle() const { return title.get(); }
0971     Movie *getMovie() { return movie.get(); }
0972 
0973 private:
0974     void initialize(PDFDoc *docA, Dict *dict);
0975 
0976     std::unique_ptr<GooString> title; // T
0977     std::unique_ptr<Movie> movie; // Movie + A
0978 };
0979 
0980 //------------------------------------------------------------------------
0981 // AnnotScreen
0982 //------------------------------------------------------------------------
0983 
0984 class POPPLER_PRIVATE_EXPORT AnnotScreen : public Annot
0985 {
0986 public:
0987     AnnotScreen(PDFDoc *docA, PDFRectangle *rect);
0988     AnnotScreen(PDFDoc *docA, Object &&dictObject, const Object *obj);
0989     ~AnnotScreen() override;
0990 
0991     const GooString *getTitle() const { return title.get(); }
0992 
0993     AnnotAppearanceCharacs *getAppearCharacs() { return appearCharacs.get(); }
0994     LinkAction *getAction() { return action.get(); } // The caller should not delete the result
0995     std::unique_ptr<LinkAction> getAdditionalAction(AdditionalActionsType type);
0996 
0997 private:
0998     void initialize(PDFDoc *docA, Dict *dict);
0999 
1000     std::unique_ptr<GooString> title; // T
1001 
1002     std::unique_ptr<AnnotAppearanceCharacs> appearCharacs; // MK
1003 
1004     std::unique_ptr<LinkAction> action; // A
1005     Object additionalActions; // AA
1006 };
1007 
1008 //------------------------------------------------------------------------
1009 // AnnotLink
1010 //------------------------------------------------------------------------
1011 
1012 class AnnotLink : public Annot
1013 {
1014 public:
1015     enum AnnotLinkEffect
1016     {
1017         effectNone, // N
1018         effectInvert, // I
1019         effectOutline, // O
1020         effectPush // P
1021     };
1022 
1023     AnnotLink(PDFDoc *docA, PDFRectangle *rect);
1024     AnnotLink(PDFDoc *docA, Object &&dictObject, const Object *obj);
1025     ~AnnotLink() override;
1026 
1027     void draw(Gfx *gfx, bool printing) override;
1028 
1029     // getters
1030     LinkAction *getAction() const { return action.get(); }
1031     AnnotLinkEffect getLinkEffect() const { return linkEffect; }
1032     AnnotQuadrilaterals *getQuadrilaterals() const { return quadrilaterals.get(); }
1033 
1034 protected:
1035     void initialize(PDFDoc *docA, Dict *dict);
1036 
1037     std::unique_ptr<LinkAction> action; // A, Dest
1038     AnnotLinkEffect linkEffect; // H          (Default I)
1039     // Dict *uriAction;                                   // PA
1040 
1041     std::unique_ptr<AnnotQuadrilaterals> quadrilaterals; // QuadPoints
1042 };
1043 
1044 //------------------------------------------------------------------------
1045 // AnnotFreeText
1046 //------------------------------------------------------------------------
1047 
1048 class POPPLER_PRIVATE_EXPORT AnnotFreeText : public AnnotMarkup
1049 {
1050 public:
1051     enum AnnotFreeTextIntent
1052     {
1053         intentFreeText, // FreeText
1054         intentFreeTextCallout, // FreeTextCallout
1055         intentFreeTextTypeWriter // FreeTextTypeWriter
1056     };
1057 
1058     static const double undefinedFontPtSize;
1059 
1060     AnnotFreeText(PDFDoc *docA, PDFRectangle *rect);
1061     AnnotFreeText(PDFDoc *docA, Object &&dictObject, const Object *obj);
1062     ~AnnotFreeText() override;
1063 
1064     void draw(Gfx *gfx, bool printing) override;
1065     Object getAppearanceResDict() override;
1066     void setContents(std::unique_ptr<GooString> &&new_content) override;
1067 
1068     void setDefaultAppearance(const DefaultAppearance &da);
1069     void setQuadding(VariableTextQuadding new_quadding);
1070     void setStyleString(GooString *new_string);
1071     void setCalloutLine(AnnotCalloutLine *line);
1072     void setIntent(AnnotFreeTextIntent new_intent);
1073 
1074     // getters
1075     std::unique_ptr<DefaultAppearance> getDefaultAppearance() const;
1076     VariableTextQuadding getQuadding() const { return quadding; }
1077     // return rc
1078     const GooString *getStyleString() const { return styleString.get(); }
1079     AnnotCalloutLine *getCalloutLine() const { return calloutLine.get(); }
1080     AnnotFreeTextIntent getIntent() const { return intent; }
1081     AnnotBorderEffect *getBorderEffect() const { return borderEffect.get(); }
1082     PDFRectangle *getRectangle() const { return rectangle.get(); }
1083     AnnotLineEndingStyle getEndStyle() const { return endStyle; }
1084 
1085 protected:
1086     void initialize(PDFDoc *docA, Dict *dict);
1087     void generateFreeTextAppearance();
1088 
1089     // required
1090     std::unique_ptr<GooString> appearanceString; // DA
1091 
1092     // optional
1093     VariableTextQuadding quadding; // Q  (Default 0)
1094     // RC
1095     std::unique_ptr<GooString> styleString; // DS
1096     std::unique_ptr<AnnotCalloutLine> calloutLine; // CL
1097     AnnotFreeTextIntent intent; // IT
1098     std::unique_ptr<AnnotBorderEffect> borderEffect; // BE
1099     std::unique_ptr<PDFRectangle> rectangle; // RD
1100     // inherited  from Annot
1101     // AnnotBorderBS border;                          // BS
1102     AnnotLineEndingStyle endStyle; // LE (Default None)
1103 };
1104 
1105 //------------------------------------------------------------------------
1106 // AnnotLine
1107 //------------------------------------------------------------------------
1108 
1109 class POPPLER_PRIVATE_EXPORT AnnotLine : public AnnotMarkup
1110 {
1111 public:
1112     enum AnnotLineIntent
1113     {
1114         intentLineArrow, // LineArrow
1115         intentLineDimension // LineDimension
1116     };
1117 
1118     enum AnnotLineCaptionPos
1119     {
1120         captionPosInline, // Inline
1121         captionPosTop // Top
1122     };
1123 
1124     AnnotLine(PDFDoc *docA, PDFRectangle *rect);
1125     AnnotLine(PDFDoc *docA, Object &&dictObject, const Object *obj);
1126     ~AnnotLine() override;
1127 
1128     void draw(Gfx *gfx, bool printing) override;
1129     Object getAppearanceResDict() override;
1130     void setContents(std::unique_ptr<GooString> &&new_content) override;
1131 
1132     void setVertices(double x1, double y1, double x2, double y2);
1133     void setStartEndStyle(AnnotLineEndingStyle start, AnnotLineEndingStyle end);
1134     void setInteriorColor(std::unique_ptr<AnnotColor> &&new_color);
1135     void setLeaderLineLength(double len);
1136     void setLeaderLineExtension(double len);
1137     void setCaption(bool new_cap);
1138     void setIntent(AnnotLineIntent new_intent);
1139 
1140     // getters
1141     AnnotLineEndingStyle getStartStyle() const { return startStyle; }
1142     AnnotLineEndingStyle getEndStyle() const { return endStyle; }
1143     AnnotColor *getInteriorColor() const { return interiorColor.get(); }
1144     double getLeaderLineLength() const { return leaderLineLength; }
1145     double getLeaderLineExtension() const { return leaderLineExtension; }
1146     bool getCaption() const { return caption; }
1147     AnnotLineIntent getIntent() const { return intent; }
1148     double getLeaderLineOffset() const { return leaderLineOffset; }
1149     AnnotLineCaptionPos getCaptionPos() const { return captionPos; }
1150     Dict *getMeasure() const { return measure; }
1151     double getCaptionTextHorizontal() const { return captionTextHorizontal; }
1152     double getCaptionTextVertical() const { return captionTextVertical; }
1153     double getX1() const { return coord1->getX(); }
1154     double getY1() const { return coord1->getY(); }
1155     double getX2() const { return coord2->getX(); }
1156     double getY2() const { return coord2->getY(); }
1157 
1158 protected:
1159     void initialize(PDFDoc *docA, Dict *dict);
1160     void generateLineAppearance();
1161 
1162     // required
1163     std::unique_ptr<AnnotCoord> coord1;
1164     std::unique_ptr<AnnotCoord> coord2;
1165 
1166     // optional
1167     // inherited  from Annot
1168     // AnnotBorderBS border;                   // BS
1169     AnnotLineEndingStyle startStyle; // LE       (Default [/None /None])
1170     AnnotLineEndingStyle endStyle; //
1171     std::unique_ptr<AnnotColor> interiorColor; // IC
1172     double leaderLineLength; // LL       (Default 0)
1173     double leaderLineExtension; // LLE      (Default 0)
1174     bool caption; // Cap      (Default false)
1175     AnnotLineIntent intent; // IT
1176     double leaderLineOffset; // LLO
1177     AnnotLineCaptionPos captionPos; // CP       (Default Inline)
1178     Dict *measure; // Measure
1179     double captionTextHorizontal; // CO       (Default [0, 0])
1180     double captionTextVertical; //
1181 };
1182 
1183 //------------------------------------------------------------------------
1184 // AnnotTextMarkup
1185 //------------------------------------------------------------------------
1186 
1187 class POPPLER_PRIVATE_EXPORT AnnotTextMarkup : public AnnotMarkup
1188 {
1189 public:
1190     AnnotTextMarkup(PDFDoc *docA, PDFRectangle *rect, AnnotSubtype subType);
1191     AnnotTextMarkup(PDFDoc *docA, Object &&dictObject, const Object *obj);
1192     ~AnnotTextMarkup() override;
1193 
1194     void draw(Gfx *gfx, bool printing) override;
1195 
1196     // typeHighlight, typeUnderline, typeSquiggly or typeStrikeOut
1197     void setType(AnnotSubtype new_type);
1198 
1199     void setQuadrilaterals(AnnotQuadrilaterals *quadPoints);
1200 
1201     AnnotQuadrilaterals *getQuadrilaterals() const { return quadrilaterals.get(); }
1202 
1203 protected:
1204     void initialize(PDFDoc *docA, Dict *dict);
1205 
1206     std::unique_ptr<AnnotQuadrilaterals> quadrilaterals; // QuadPoints
1207 
1208 private:
1209     bool shouldCreateApperance(Gfx *gfx) const;
1210 };
1211 
1212 //------------------------------------------------------------------------
1213 // AnnotStamp
1214 //------------------------------------------------------------------------
1215 
1216 class POPPLER_PRIVATE_EXPORT AnnotStamp : public AnnotMarkup
1217 {
1218 public:
1219     AnnotStamp(PDFDoc *docA, PDFRectangle *rect);
1220     AnnotStamp(PDFDoc *docA, Object &&dictObject, const Object *obj);
1221     ~AnnotStamp() override;
1222 
1223     void draw(Gfx *gfx, bool printing) override;
1224 
1225     void setIcon(GooString *new_icon);
1226 
1227     void setCustomImage(AnnotStampImageHelper *stampImageHelperA);
1228 
1229     void clearCustomImage();
1230 
1231     // getters
1232     const GooString *getIcon() const { return icon.get(); }
1233 
1234 private:
1235     void initialize(PDFDoc *docA, Dict *dict);
1236     void generateStampDefaultAppearance();
1237     void generateStampCustomAppearance();
1238 
1239     std::unique_ptr<GooString> icon; // Name       (Default Draft)
1240     AnnotStampImageHelper *stampImageHelper;
1241     Ref updatedAppearanceStream;
1242 };
1243 
1244 //------------------------------------------------------------------------
1245 // AnnotGeometry
1246 //------------------------------------------------------------------------
1247 
1248 class POPPLER_PRIVATE_EXPORT AnnotGeometry : public AnnotMarkup
1249 {
1250 public:
1251     AnnotGeometry(PDFDoc *docA, PDFRectangle *rect, AnnotSubtype subType);
1252     AnnotGeometry(PDFDoc *docA, Object &&dictObject, const Object *obj);
1253     ~AnnotGeometry() override;
1254 
1255     void draw(Gfx *gfx, bool printing) override;
1256 
1257     void setType(AnnotSubtype new_type); // typeSquare or typeCircle
1258     void setInteriorColor(std::unique_ptr<AnnotColor> &&new_color);
1259 
1260     // getters
1261     AnnotColor *getInteriorColor() const { return interiorColor.get(); }
1262     AnnotBorderEffect *getBorderEffect() const { return borderEffect.get(); }
1263     PDFRectangle *getGeometryRect() const { return geometryRect.get(); }
1264 
1265 private:
1266     void initialize(PDFDoc *docA, Dict *dict);
1267 
1268     std::unique_ptr<AnnotColor> interiorColor; // IC
1269     std::unique_ptr<AnnotBorderEffect> borderEffect; // BE
1270     std::unique_ptr<PDFRectangle> geometryRect; // RD (combined with Rect)
1271 };
1272 
1273 //------------------------------------------------------------------------
1274 // AnnotPolygon
1275 //------------------------------------------------------------------------
1276 
1277 class POPPLER_PRIVATE_EXPORT AnnotPolygon : public AnnotMarkup
1278 {
1279 public:
1280     enum AnnotPolygonIntent
1281     {
1282         polygonCloud, // PolygonCloud
1283         polylineDimension, // PolyLineDimension
1284         polygonDimension // PolygonDimension
1285     };
1286 
1287     AnnotPolygon(PDFDoc *docA, PDFRectangle *rect, AnnotSubtype subType);
1288     AnnotPolygon(PDFDoc *docA, Object &&dictObject, const Object *obj);
1289     ~AnnotPolygon() override;
1290 
1291     void draw(Gfx *gfx, bool printing) override;
1292     void generatePolyLineAppearance(AnnotAppearanceBuilder *appearBuilder);
1293     void setType(AnnotSubtype new_type); // typePolygon or typePolyLine
1294     void setVertices(AnnotPath *path);
1295     void setStartEndStyle(AnnotLineEndingStyle start, AnnotLineEndingStyle end);
1296     void setInteriorColor(std::unique_ptr<AnnotColor> &&new_color);
1297     void setIntent(AnnotPolygonIntent new_intent);
1298 
1299     // getters
1300     AnnotPath *getVertices() const { return vertices.get(); }
1301     AnnotLineEndingStyle getStartStyle() const { return startStyle; }
1302     AnnotLineEndingStyle getEndStyle() const { return endStyle; }
1303     AnnotColor *getInteriorColor() const { return interiorColor.get(); }
1304     AnnotBorderEffect *getBorderEffect() const { return borderEffect.get(); }
1305     AnnotPolygonIntent getIntent() const { return intent; }
1306 
1307 private:
1308     void initialize(PDFDoc *docA, Dict *dict);
1309 
1310     // required
1311     std::unique_ptr<AnnotPath> vertices; // Vertices
1312 
1313     // optional
1314     AnnotLineEndingStyle startStyle; // LE       (Default [/None /None])
1315     AnnotLineEndingStyle endStyle; //
1316     // inherited  from Annot
1317     // AnnotBorderBS border;                          // BS
1318     std::unique_ptr<AnnotColor> interiorColor; // IC
1319     std::unique_ptr<AnnotBorderEffect> borderEffect; // BE
1320     AnnotPolygonIntent intent; // IT
1321     // Measure
1322 };
1323 
1324 //------------------------------------------------------------------------
1325 // AnnotCaret
1326 //------------------------------------------------------------------------
1327 
1328 class POPPLER_PRIVATE_EXPORT AnnotCaret : public AnnotMarkup
1329 {
1330 public:
1331     enum AnnotCaretSymbol
1332     {
1333         symbolNone, // None
1334         symbolP // P
1335     };
1336 
1337     AnnotCaret(PDFDoc *docA, PDFRectangle *rect);
1338     AnnotCaret(PDFDoc *docA, Object &&dictObject, const Object *obj);
1339     ~AnnotCaret() override;
1340 
1341     void setSymbol(AnnotCaretSymbol new_symbol);
1342 
1343     // getters
1344     AnnotCaretSymbol getSymbol() const { return symbol; }
1345     PDFRectangle *getCaretRect() const { return caretRect.get(); }
1346 
1347 private:
1348     void initialize(PDFDoc *docA, Dict *dict);
1349 
1350     AnnotCaretSymbol symbol; // Sy         (Default None)
1351     std::unique_ptr<PDFRectangle> caretRect; // RD (combined with Rect)
1352 };
1353 
1354 //------------------------------------------------------------------------
1355 // AnnotInk
1356 //------------------------------------------------------------------------
1357 
1358 class POPPLER_PRIVATE_EXPORT AnnotInk : public AnnotMarkup
1359 {
1360 public:
1361     AnnotInk(PDFDoc *docA, PDFRectangle *rect);
1362     AnnotInk(PDFDoc *docA, Object &&dictObject, const Object *obj);
1363     ~AnnotInk() override;
1364 
1365     void draw(Gfx *gfx, bool printing) override;
1366 
1367     void setInkList(AnnotPath **paths, int n_paths);
1368 
1369     // getters
1370     AnnotPath **getInkList() const { return inkList; }
1371     int getInkListLength() const { return inkListLength; }
1372 
1373 private:
1374     void initialize(PDFDoc *docA, Dict *dict);
1375     void writeInkList(AnnotPath **paths, int n_paths, Array *dest_array);
1376     void parseInkList(Array *src_array);
1377     void freeInkList();
1378 
1379     // required
1380     AnnotPath **inkList; // InkList
1381     int inkListLength;
1382 
1383     // optional
1384     // inherited from Annot
1385     // AnnotBorderBS border;  // BS
1386 };
1387 
1388 //------------------------------------------------------------------------
1389 // AnnotFileAttachment
1390 //------------------------------------------------------------------------
1391 
1392 class AnnotFileAttachment : public AnnotMarkup
1393 {
1394 public:
1395     AnnotFileAttachment(PDFDoc *docA, PDFRectangle *rect, GooString *filename);
1396     AnnotFileAttachment(PDFDoc *docA, Object &&dictObject, const Object *obj);
1397     ~AnnotFileAttachment() override;
1398 
1399     void draw(Gfx *gfx, bool printing) override;
1400 
1401     // getters
1402     Object *getFile() { return &file; }
1403     const GooString *getName() const { return name.get(); }
1404 
1405 private:
1406     void initialize(PDFDoc *docA, Dict *dict);
1407 
1408     // required
1409     Object file; // FS
1410 
1411     // optional
1412     std::unique_ptr<GooString> name; // Name
1413 };
1414 
1415 //------------------------------------------------------------------------
1416 // AnnotSound
1417 //------------------------------------------------------------------------
1418 
1419 class AnnotSound : public AnnotMarkup
1420 {
1421 public:
1422     AnnotSound(PDFDoc *docA, PDFRectangle *rect, Sound *soundA);
1423     AnnotSound(PDFDoc *docA, Object &&dictObject, const Object *obj);
1424     ~AnnotSound() override;
1425 
1426     void draw(Gfx *gfx, bool printing) override;
1427 
1428     // getters
1429     Sound *getSound() { return sound.get(); }
1430     const GooString *getName() const { return name.get(); }
1431 
1432 private:
1433     void initialize(PDFDoc *docA, Dict *dict);
1434 
1435     // required
1436     std::unique_ptr<Sound> sound; // Sound
1437 
1438     // optional
1439     std::unique_ptr<GooString> name; // Name
1440 };
1441 
1442 //------------------------------------------------------------------------
1443 // AnnotWidget
1444 //------------------------------------------------------------------------
1445 
1446 class POPPLER_PRIVATE_EXPORT AnnotWidget : public Annot
1447 {
1448 public:
1449     enum AnnotWidgetHighlightMode
1450     {
1451         highlightModeNone, // N
1452         highlightModeInvert, // I
1453         highlightModeOutline, // O
1454         highlightModePush // P,T
1455     };
1456 
1457     AnnotWidget(PDFDoc *docA, Object &&dictObject, const Object *obj);
1458     AnnotWidget(PDFDoc *docA, Object *dictObject, Object *obj, FormField *fieldA);
1459     ~AnnotWidget() override;
1460 
1461     void draw(Gfx *gfx, bool printing) override;
1462     void invalidateAppearance() override;
1463 
1464     void generateFieldAppearance();
1465     void updateAppearanceStream();
1466 
1467     AnnotWidgetHighlightMode getMode() { return mode; }
1468     AnnotAppearanceCharacs *getAppearCharacs() { return appearCharacs.get(); }
1469     void setAppearCharacs(std::unique_ptr<AnnotAppearanceCharacs> &&appearCharacsA) { appearCharacs = std::move(appearCharacsA); }
1470     LinkAction *getAction() { return action.get(); } // The caller should not delete the result
1471     std::unique_ptr<LinkAction> getAdditionalAction(AdditionalActionsType type);
1472     std::unique_ptr<LinkAction> getFormAdditionalAction(FormAdditionalActionsType type);
1473     Dict *getParent() { return parent; }
1474 
1475     bool setFormAdditionalAction(FormAdditionalActionsType type, const GooString &js);
1476 
1477     void setField(FormField *f) { field = f; };
1478 
1479 private:
1480     void initialize(PDFDoc *docA, Dict *dict);
1481 
1482     Form *form;
1483     FormField *field; // FormField object for this annotation
1484     AnnotWidgetHighlightMode mode; // H  (Default I)
1485     std::unique_ptr<AnnotAppearanceCharacs> appearCharacs; // MK
1486     std::unique_ptr<LinkAction> action; // A
1487     Object additionalActions; // AA
1488     // inherited  from Annot
1489     // AnnotBorderBS border;                // BS
1490     Dict *parent; // Parent
1491     Ref updatedAppearanceStream; // {-1,-1} if updateAppearanceStream has never been called
1492 };
1493 
1494 //------------------------------------------------------------------------
1495 // Annot3D
1496 //------------------------------------------------------------------------
1497 
1498 class Annot3D : public Annot
1499 {
1500     class Activation
1501     {
1502     public:
1503         enum ActivationATrigger
1504         {
1505             aTriggerUnknown,
1506             aTriggerPageOpened, // PO
1507             aTriggerPageVisible, // PV
1508             aTriggerUserAction // XA
1509         };
1510 
1511         enum ActivationAState
1512         {
1513             aStateUnknown,
1514             aStateEnabled, // I
1515             aStateDisabled // L
1516         };
1517 
1518         enum ActivationDTrigger
1519         {
1520             dTriggerUnknown,
1521             dTriggerPageClosed, // PC
1522             dTriggerPageInvisible, // PI
1523             dTriggerUserAction // XD
1524         };
1525 
1526         enum ActivationDState
1527         {
1528             dStateUnknown,
1529             dStateUninstantiaded, // U
1530             dStateInstantiated, // I
1531             dStateLive // L
1532         };
1533 
1534         explicit Activation(Dict *dict);
1535 
1536     private:
1537         ActivationATrigger aTrigger; // A   (Default XA)
1538         ActivationAState aState; // AIS (Default L)
1539         ActivationDTrigger dTrigger; // D   (Default PI)
1540         ActivationDState dState; // DIS (Default U)
1541         bool displayToolbar; // TB  (Default true)
1542         bool displayNavigation; // NP  (Default false);
1543     };
1544 
1545 public:
1546     Annot3D(PDFDoc *docA, PDFRectangle *rect);
1547     Annot3D(PDFDoc *docA, Object &&dictObject, const Object *obj);
1548     ~Annot3D() override;
1549 
1550     // getters
1551 
1552 private:
1553     void initialize(PDFDoc *docA, Dict *dict);
1554 
1555     std::unique_ptr<Activation> activation; // 3DA
1556 };
1557 
1558 //------------------------------------------------------------------------
1559 // AnnotRichMedia
1560 //------------------------------------------------------------------------
1561 
1562 class POPPLER_PRIVATE_EXPORT AnnotRichMedia : public Annot
1563 {
1564 public:
1565     class POPPLER_PRIVATE_EXPORT Params
1566     {
1567     public:
1568         explicit Params(Dict *dict);
1569         ~Params();
1570 
1571         Params(const Params &) = delete;
1572         Params &operator=(const Params &) = delete;
1573 
1574         const GooString *getFlashVars() const;
1575 
1576     private:
1577         // optional
1578         std::unique_ptr<GooString> flashVars; // FlashVars
1579     };
1580 
1581     class POPPLER_PRIVATE_EXPORT Instance
1582     {
1583     public:
1584         enum Type
1585         {
1586             type3D, // 3D
1587             typeFlash, // Flash
1588             typeSound, // Sound
1589             typeVideo // Video
1590         };
1591 
1592         explicit Instance(Dict *dict);
1593         ~Instance();
1594 
1595         Instance(const Instance &) = delete;
1596         Instance &operator=(const Instance &) = delete;
1597 
1598         Type getType() const;
1599         Params *getParams() const;
1600 
1601     private:
1602         // optional
1603         Type type; // Subtype
1604         std::unique_ptr<Params> params; // Params
1605     };
1606 
1607     class POPPLER_PRIVATE_EXPORT Configuration
1608     {
1609     public:
1610         enum Type
1611         {
1612             type3D, // 3D
1613             typeFlash, // Flash
1614             typeSound, // Sound
1615             typeVideo // Video
1616         };
1617 
1618         explicit Configuration(Dict *dict);
1619         ~Configuration();
1620 
1621         Configuration(const Configuration &) = delete;
1622         Configuration &operator=(const Configuration &) = delete;
1623 
1624         Type getType() const;
1625         const GooString *getName() const;
1626         int getInstancesCount() const;
1627         Instance *getInstance(int index) const;
1628 
1629     private:
1630         // optional
1631         Type type; // Subtype
1632         std::unique_ptr<GooString> name; // Name
1633         Instance **instances; // Instances
1634         int nInstances;
1635     };
1636 
1637     class Content;
1638 
1639     class POPPLER_PRIVATE_EXPORT Asset
1640     {
1641     public:
1642         Asset();
1643         ~Asset();
1644 
1645         Asset(const Asset &) = delete;
1646         Asset &operator=(const Asset &) = delete;
1647 
1648         const GooString *getName() const;
1649         Object *getFileSpec() const;
1650 
1651     private:
1652         friend class AnnotRichMedia::Content;
1653 
1654         std::unique_ptr<GooString> name;
1655         Object fileSpec;
1656     };
1657 
1658     class POPPLER_PRIVATE_EXPORT Content
1659     {
1660     public:
1661         explicit Content(Dict *dict);
1662         ~Content();
1663 
1664         Content(const Content &) = delete;
1665         Content &operator=(const Content &) = delete;
1666 
1667         int getConfigurationsCount() const;
1668         Configuration *getConfiguration(int index) const;
1669 
1670         int getAssetsCount() const;
1671         Asset *getAsset(int index) const;
1672 
1673     private:
1674         // optional
1675         Configuration **configurations; // Configurations
1676         int nConfigurations;
1677 
1678         Asset **assets; // Assets
1679         int nAssets;
1680     };
1681 
1682     class POPPLER_PRIVATE_EXPORT Activation
1683     {
1684     public:
1685         enum Condition
1686         {
1687             conditionPageOpened, // PO
1688             conditionPageVisible, // PV
1689             conditionUserAction // XA
1690         };
1691 
1692         explicit Activation(Dict *dict);
1693 
1694         Condition getCondition() const;
1695 
1696     private:
1697         // optional
1698         Condition condition;
1699     };
1700 
1701     class POPPLER_PRIVATE_EXPORT Deactivation
1702     {
1703     public:
1704         enum Condition
1705         {
1706             conditionPageClosed, // PC
1707             conditionPageInvisible, // PI
1708             conditionUserAction // XD
1709         };
1710 
1711         explicit Deactivation(Dict *dict);
1712 
1713         Condition getCondition() const;
1714 
1715     private:
1716         // optional
1717         Condition condition;
1718     };
1719 
1720     class POPPLER_PRIVATE_EXPORT Settings
1721     {
1722     public:
1723         explicit Settings(Dict *dict);
1724         ~Settings();
1725 
1726         Settings(const Settings &) = delete;
1727         Settings &operator=(const Settings &) = delete;
1728 
1729         Activation *getActivation() const;
1730         Deactivation *getDeactivation() const;
1731 
1732     private:
1733         // optional
1734         std::unique_ptr<Activation> activation;
1735         std::unique_ptr<Deactivation> deactivation;
1736     };
1737 
1738     AnnotRichMedia(PDFDoc *docA, PDFRectangle *rect);
1739     AnnotRichMedia(PDFDoc *docA, Object &&dictObject, const Object *obj);
1740     ~AnnotRichMedia() override;
1741 
1742     Content *getContent() const;
1743 
1744     Settings *getSettings() const;
1745 
1746 private:
1747     void initialize(PDFDoc *docA, Dict *dict);
1748 
1749     // required
1750     std::unique_ptr<Content> content; // RichMediaContent
1751 
1752     // optional
1753     std::unique_ptr<Settings> settings; // RichMediaSettings
1754 };
1755 
1756 //------------------------------------------------------------------------
1757 // Annots
1758 //------------------------------------------------------------------------
1759 
1760 class Annots
1761 {
1762 public:
1763     // Build a list of Annot objects and call setPage on them
1764     Annots(PDFDoc *docA, int page, Object *annotsObj);
1765 
1766     ~Annots();
1767 
1768     Annots(const Annots &) = delete;
1769     Annots &operator=(const Annots &) = delete;
1770 
1771     const std::vector<Annot *> &getAnnots() { return annots; }
1772 
1773     void appendAnnot(Annot *annot);
1774     bool removeAnnot(Annot *annot);
1775 
1776 private:
1777     Annot *createAnnot(Object &&dictObject, const Object *obj);
1778     Annot *findAnnot(Ref *ref);
1779 
1780     PDFDoc *doc;
1781     std::vector<Annot *> annots;
1782 };
1783 
1784 #endif