Annot.h 50.9 KB
Newer Older
Kristian Høgsberg's avatar
Kristian Høgsberg committed
1 2 3 4 5 6 7 8
//========================================================================
//
// Annot.h
//
// Copyright 2000-2003 Glyph & Cog, LLC
//
//========================================================================

9 10 11 12
//========================================================================
//
// Modified under the Poppler project - http://poppler.freedesktop.org
//
13 14 15
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
16 17
// Copyright (C) 2006 Scott Turner <scotty1024@mac.com>
// Copyright (C) 2007, 2008 Julien Rebetez <julienr@svn.gnome.org>
Albert Astals Cid's avatar
Albert Astals Cid committed
18
// Copyright (C) 2007-2011, 2013, 2015 Carlos Garcia Campos <carlosgc@gnome.org>
19 20 21 22
// Copyright (C) 2007, 2008 Iñigo Martínez <inigomartinez@gmail.com>
// Copyright (C) 2008 Michael Vrable <mvrable@cs.ucsd.edu>
// Copyright (C) 2008 Hugo Mercier <hmercier31@gmail.com>
// 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-2018 Albert Astals Cid <aacid@kde.org>
25
// Copyright (C) 2012, 2013 Fabio D'Urso <fabiodurso@hotmail.it>
Albert Astals Cid's avatar
Albert Astals Cid committed
26
// Copyright (C) 2012, 2015 Tobias Koenig <tokoe@kdab.com>
Thomas Freitag's avatar
Thomas Freitag committed
27
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
28
// Copyright (C) 2013, 2017 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
Albert Astals Cid's avatar
Albert Astals Cid committed
30 31
// Copyright (C) 2018 Dileep Sankhla <sankhla.dileep96@gmail.com>
// Copyright (C) 2018 Tobias Deiminger <haxtibal@posteo.de>
32 33 34 35 36 37
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
//
//========================================================================

Kristian Høgsberg's avatar
Kristian Høgsberg committed
38 39 40 41 42 43 44
#ifndef ANNOT_H
#define ANNOT_H

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

Tobias Deiminger's avatar
Tobias Deiminger committed
45
#include <memory>
46 47 48
#include <atomic>
#include <mutex>

49 50
#include "Object.h"

Kristian Høgsberg's avatar
Kristian Høgsberg committed
51 52
class XRef;
class Gfx;
53 54
class CharCodeToUnicode;
class GfxFont;
55
class GfxResources;
56
class Page;
57
class PDFDoc;
58
class Form;
59
class FormWidget;
60
class FormField;
61 62
class FormFieldButton;
class FormFieldText;
63
class FormFieldChoice;
64
class PDFRectangle;
Hugo Mercier's avatar
Hugo Mercier committed
65
class Movie;
66
class LinkAction;
67
class Sound;
68
class FileSpec;
69

Inigo Martínez's avatar
Inigo Martínez committed
70 71 72 73 74 75 76 77 78 79 80 81 82
enum AnnotLineEndingStyle {
  annotLineEndingSquare,        // Square
  annotLineEndingCircle,        // Circle
  annotLineEndingDiamond,       // Diamond
  annotLineEndingOpenArrow,     // OpenArrow
  annotLineEndingClosedArrow,   // ClosedArrow
  annotLineEndingNone,          // None
  annotLineEndingButt,          // Butt
  annotLineEndingROpenArrow,    // ROpenArrow
  annotLineEndingRClosedArrow,  // RClosedArrow
  annotLineEndingSlash          // Slash
};

Inigo Martínez's avatar
Inigo Martínez committed
83 84 85 86 87
enum AnnotExternalDataType {
  annotExternalDataMarkupUnknown,
  annotExternalDataMarkup3D       // Markup3D
};

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
//------------------------------------------------------------------------
// AnnotCoord
//------------------------------------------------------------------------

class AnnotCoord {
public:

  AnnotCoord() : x(0), y(0) { }
  AnnotCoord(double _x, double _y) : x(_x), y(_y) { }

  double getX() const { return x; }
  double getY() const { return y; }
  
protected:

  double x, y;
};

Inigo Martínez's avatar
Inigo Martínez committed
106 107 108 109 110 111
//------------------------------------------------------------------------
// AnnotPath
//------------------------------------------------------------------------

class AnnotPath {
public:
112
  AnnotPath();
113
  AnnotPath(Array *array);
Inigo Martínez's avatar
Inigo Martínez committed
114
  AnnotPath(AnnotCoord **coords, int coordLength);
115
  ~AnnotPath();
Inigo Martínez's avatar
Inigo Martínez committed
116

117 118 119
  AnnotPath(const AnnotPath &) = delete;
  AnnotPath& operator=(const AnnotPath &other) = delete;

120 121 122
  double getX(int coord) const;
  double getY(int coord) const;
  AnnotCoord *getCoord(int coord) const;
Pino Toscano's avatar
Pino Toscano committed
123
  int getCoordsLength() const { return coordsLength; }
Inigo Martínez's avatar
Inigo Martínez committed
124 125 126
protected:
  AnnotCoord **coords;
  int coordsLength;
127 128

  void parsePathArray(Array *array);
Inigo Martínez's avatar
Inigo Martínez committed
129 130
};
  
Inigo Martínez's avatar
Inigo Martínez committed
131 132 133 134 135 136 137 138 139 140
//------------------------------------------------------------------------
// AnnotCalloutLine
//------------------------------------------------------------------------

class AnnotCalloutLine {
public:

  AnnotCalloutLine(double x1, double y1, double x2, double y2);
  virtual ~AnnotCalloutLine() { }

141 142 143
  AnnotCalloutLine(const AnnotCalloutLine &) = delete;
  AnnotCalloutLine& operator=(const AnnotCalloutLine &other) = delete;

144 145 146 147
  double getX1() const { return coord1.getX(); }
  double getY1() const { return coord1.getY(); }
  double getX2() const { return coord2.getX(); }
  double getY2() const { return coord2.getY(); }
Inigo Martínez's avatar
Inigo Martínez committed
148 149 150
  
protected:

151
  AnnotCoord coord1, coord2;
Inigo Martínez's avatar
Inigo Martínez committed
152 153 154 155 156 157 158 159 160 161 162 163
};

//------------------------------------------------------------------------
// AnnotCalloutMultiLine
//------------------------------------------------------------------------

class AnnotCalloutMultiLine: public AnnotCalloutLine {
public:

  AnnotCalloutMultiLine(double x1, double y1, double x2, double y2,
    double x3, double y3);

164 165
  double getX3() const { return coord3.getX(); }
  double getY3() const { return coord3.getY(); }
Inigo Martínez's avatar
Inigo Martínez committed
166 167 168

protected:

169
  AnnotCoord coord3;
Inigo Martínez's avatar
Inigo Martínez committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
};

//------------------------------------------------------------------------
// AnnotBorderEffect
//------------------------------------------------------------------------

class AnnotBorderEffect {
public:

  enum AnnotBorderEffectType {
    borderEffectNoEffect, // S
    borderEffectCloudy    // C
  };

  AnnotBorderEffect(Dict *dict);

  AnnotBorderEffectType getEffectType() const { return effectType; }
  double getIntensity() const { return intensity; }

private:

  AnnotBorderEffectType effectType; // S  (Default S)
  double intensity;                 // I  (Default 0)
};

195
//------------------------------------------------------------------------
196
// AnnotQuadrilateral
197 198
//------------------------------------------------------------------------

199
class AnnotQuadrilaterals {
200
public:
201 202 203
  class AnnotQuadrilateral {
  public:
    AnnotQuadrilateral(double x1, double y1, double x2, double y2, double x3,
204 205
      double y3, double x4, double y4);

206
    AnnotCoord coord1, coord2, coord3, coord4;
207
  };
208

209
  AnnotQuadrilaterals(Array *array, PDFRectangle *rect);
210
  AnnotQuadrilaterals(AnnotQuadrilateral **quads, int quadsLength);
211
  ~AnnotQuadrilaterals();
212

213 214 215
  AnnotQuadrilaterals(const AnnotQuadrilaterals &) = delete;
  AnnotQuadrilaterals& operator=(const AnnotQuadrilaterals &other) = delete;

216 217 218 219 220 221 222 223 224
  double getX1(int quadrilateral);
  double getY1(int quadrilateral);
  double getX2(int quadrilateral);
  double getY2(int quadrilateral);
  double getX3(int quadrilateral);
  double getY3(int quadrilateral);
  double getX4(int quadrilateral);
  double getY4(int quadrilateral);
  int getQuadrilateralsLength() const { return quadrilateralsLength; }
225
protected:
226 227 228

  AnnotQuadrilateral** quadrilaterals;
  int quadrilateralsLength;
229 230
};

231 232 233 234 235 236
//------------------------------------------------------------------------
// AnnotBorder
//------------------------------------------------------------------------

class AnnotBorder {
public:
237 238
  enum AnnotBorderType {
    typeArray,
239
    typeBS
240 241
  };

242 243 244 245 246
  enum AnnotBorderStyle {
    borderSolid,      // Solid
    borderDashed,     // Dashed
    borderBeveled,    // Beveled
    borderInset,      // Inset
247
    borderUnderlined  // Underlined
248
  };
Inigo Martínez's avatar
Inigo Martínez committed
249

250 251
  virtual ~AnnotBorder();

252 253 254
  AnnotBorder(const AnnotBorder &) = delete;
  AnnotBorder& operator=(const AnnotBorder &other) = delete;

255 256
  virtual void setWidth(double new_width) { width = new_width; }

257
  virtual AnnotBorderType getType() const = 0;
258 259 260 261
  virtual double getWidth() const { return width; }
  virtual int getDashLength() const { return dashLength; }
  virtual double *getDash() const { return dash; }
  virtual AnnotBorderStyle getStyle() const { return style; }
262

Albert Astals Cid's avatar
Albert Astals Cid committed
263
  virtual Object writeToObject(XRef *xref) const = 0;
264

265
protected:
266 267
  AnnotBorder();

268
  GBool parseDashArray(Object *dashObj);
269

270
  AnnotBorderType type;
271
  double width;
272
  static const int DASH_LIMIT = 10; // implementation note 82 in Appendix H.
273 274 275 276 277 278 279 280 281 282 283 284 285 286
  int dashLength;
  double *dash;
  AnnotBorderStyle style;
};

//------------------------------------------------------------------------
// AnnotBorderArray
//------------------------------------------------------------------------

class AnnotBorderArray: public AnnotBorder {
public:
  AnnotBorderArray();
  AnnotBorderArray(Array *array);

287 288 289
  void setHorizontalCorner(double hc) { horizontalCorner = hc; }
  void setVerticalCorner(double vc) { verticalCorner = vc; }

290 291
  double getHorizontalCorner() const { return horizontalCorner; }
  double getVerticalCorner() const { return verticalCorner; }
292

293
private:
Albert Astals Cid's avatar
Albert Astals Cid committed
294
  AnnotBorderType getType() const override { return typeArray; }
Albert Astals Cid's avatar
Albert Astals Cid committed
295
  Object writeToObject(XRef *xref) const override;
296

297 298 299 300 301 302 303 304 305 306 307
  double horizontalCorner;          // (Default 0)
  double verticalCorner;            // (Default 0)
  // double width;                  // (Default 1)  (inherited from AnnotBorder)
};

//------------------------------------------------------------------------
// AnnotBorderBS
//------------------------------------------------------------------------

class AnnotBorderBS: public AnnotBorder {
public:
Inigo Martínez's avatar
Inigo Martínez committed
308

309 310 311 312
  AnnotBorderBS();
  AnnotBorderBS(Dict *dict);

private:
Albert Astals Cid's avatar
Albert Astals Cid committed
313
  AnnotBorderType getType() const override { return typeBS; }
Albert Astals Cid's avatar
Albert Astals Cid committed
314
  Object writeToObject(XRef *xref) const override;
315 316

  const char *getStyleName() const;
317

318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
  // double width;           // W  (Default 1)   (inherited from AnnotBorder)
  // AnnotBorderStyle style; // S  (Default S)   (inherited from AnnotBorder)
  // double *dash;           // D  (Default [3]) (inherited from AnnotBorder)
};

//------------------------------------------------------------------------
// AnnotColor
//------------------------------------------------------------------------

class AnnotColor {
public:

  enum AnnotColorSpace {
    colorTransparent = 0,
    colorGray        = 1,
    colorRGB         = 3,
    colorCMYK        = 4
  };
Inigo Martínez's avatar
Inigo Martínez committed
336

337
  AnnotColor();
338 339 340
  AnnotColor(double gray);
  AnnotColor(double r, double g, double b);
  AnnotColor(double c, double m, double y, double k);
341
  AnnotColor(Array *array, int adjust = 0);
342

343 344
  void adjustColor(int adjust);

345
  AnnotColorSpace getSpace() const { return (AnnotColorSpace) length; }
346
  const double *getValues() const { return values; }
347

Albert Astals Cid's avatar
Albert Astals Cid committed
348
  Object writeToObject(XRef *xref) const;
349

350 351
private:

352
  double values[4];
353 354
  int length;
};
355

356 357 358 359 360 361 362
//------------------------------------------------------------------------
// DefaultAppearance
//------------------------------------------------------------------------

class DefaultAppearance {
public:

Albert Astals Cid's avatar
Albert Astals Cid committed
363
  DefaultAppearance(Object &&fontNameA, double fontPtSizeA, std::unique_ptr<AnnotColor> fontColorA);
Tobias Deiminger's avatar
Tobias Deiminger committed
364 365 366 367 368 369 370 371 372
  DefaultAppearance(GooString *da);
  void setFontName(Object &&fontNameA);
  const Object &getFontName() const { return fontName; }
  void setFontPtSize(double fontPtSizeA);
  double getFontPtSize() const { return fontPtSize; }
  void setFontColor(std::unique_ptr<AnnotColor> fontColorA);
  const AnnotColor *getFontColor() const { return fontColor.get(); }
  GooString *toAppearanceString() const;

Albert Astals Cid's avatar
Albert Astals Cid committed
373
  DefaultAppearance(const DefaultAppearance &) = delete;
374
  DefaultAppearance& operator=(const DefaultAppearance&) = delete;
Tobias Deiminger's avatar
Tobias Deiminger committed
375

376 377
private:

Tobias Deiminger's avatar
Tobias Deiminger committed
378 379 380
  Object fontName;
  double fontPtSize;
  std::unique_ptr<AnnotColor> fontColor;
381 382
};

383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
//------------------------------------------------------------------------
// AnnotIconFit
//------------------------------------------------------------------------

class AnnotIconFit {
public:

  enum AnnotIconFitScaleWhen {
    scaleAlways,  // A
    scaleBigger,  // B
    scaleSmaller, // S
    scaleNever    // N
  };

  enum AnnotIconFitScale {
    scaleAnamorphic,  // A
    scaleProportional // P
  };

  AnnotIconFit(Dict *dict);

  AnnotIconFitScaleWhen getScaleWhen() { return scaleWhen; }
  AnnotIconFitScale getScale() { return scale; }
  double getLeft() { return left; }
  double getBottom() { return bottom; }
  bool getFullyBounds() { return fullyBounds; }

protected:

  AnnotIconFitScaleWhen scaleWhen;  // SW (Default A)
  AnnotIconFitScale scale;          // S  (Default P)
  double left;                      // A  (Default [0.5 0.5]
  double bottom;                    // Only if scale is P
  bool fullyBounds;                 // FB (Default false)
};

//------------------------------------------------------------------------
// AnnotAppearance
//------------------------------------------------------------------------

class AnnotAppearance {
public:

  enum AnnotAppearanceType {
    appearNormal,
    appearRollover,
    appearDown
  };

432 433 434 435
  AnnotAppearance(PDFDoc *docA, Object *dict);
  ~AnnotAppearance();

  // State is ignored if no subdictionary is present
Albert Astals Cid's avatar
Albert Astals Cid committed
436
  Object getAppearanceStream(AnnotAppearanceType type, const char *state);
437 438 439 440 441 442 443 444 445

  // Access keys in normal appearance subdictionary (N)
  GooString * getStateKey(int i);
  int getNumStates();

  // Removes all associated streams in the xref table. Caller is required to
  // reset parent annotation's AP and AS after this call.
  void removeAllStreams();

446 447 448
  // Test if this AnnotAppearance references the specified stream
  GBool referencesStream(Ref targetStreamRef);

449
private:
450 451
  static GBool referencesStream(Object *stateObj, Ref targetStreamRef);
  void removeStream(Ref refToStream);
452 453 454
  void removeStateStreams(Object *state);

protected:
455
  PDFDoc *doc;
456 457
  XRef *xref;                   // the xref table for this PDF file
  Object appearDict;            // Annotation's AP
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
};

//------------------------------------------------------------------------
// AnnotAppearanceCharacs
//------------------------------------------------------------------------

class AnnotAppearanceCharacs {
public:

  enum AnnotAppearanceCharacsTextPos {
    captionNoIcon,    // 0
    captionNoCaption, // 1
    captionBelow,     // 2
    captionAbove,     // 3
    captionRight,     // 4
    captionLeft,      // 5
    captionOverlaid   // 6
  };

  AnnotAppearanceCharacs(Dict *dict);
  ~AnnotAppearanceCharacs();

480 481 482
  AnnotAppearanceCharacs(const AnnotAppearanceCharacs &) = delete;
  AnnotAppearanceCharacs& operator=(const AnnotAppearanceCharacs &) = delete;

Albert Astals Cid's avatar
Albert Astals Cid committed
483 484 485 486 487 488 489 490
  int getRotation() const { return rotation; }
  const AnnotColor *getBorderColor() const { return borderColor; }
  const AnnotColor *getBackColor() const { return backColor; }
  const GooString *getNormalCaption() const { return normalCaption; }
  const GooString *getRolloverCaption() const { return rolloverCaption; }
  const GooString *getAlternateCaption() const { return alternateCaption; }
  const AnnotIconFit *getIconFit() const { return iconFit; }
  AnnotAppearanceCharacsTextPos getPosition() const { return position; }
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506

protected:

  int rotation;                           // R  (Default 0)
  AnnotColor *borderColor;                // BC
  AnnotColor *backColor;                  // BG
  GooString *normalCaption;               // CA
  GooString *rolloverCaption;             // RC
  GooString *alternateCaption;            // AC
  // I
  // RI
  // IX
  AnnotIconFit *iconFit;                  // IF
  AnnotAppearanceCharacsTextPos position; // TP (Default 0)
};

507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
//------------------------------------------------------------------------
// AnnotAppearanceBBox
//------------------------------------------------------------------------

class AnnotAppearanceBBox
{
public:
  AnnotAppearanceBBox(PDFRectangle *init);

  void setBorderWidth(double w) { borderWidth = w; }

  // The following functions operate on coords relative to [origX origY]
  void extendTo(double x, double y);
  void getBBoxRect(double bbox[4]) const;

  // Get boundaries in page coordinates
  double getPageXMin() const;
  double getPageYMin() const;
  double getPageXMax() const;
  double getPageYMax() const;

private:
  double origX, origY, borderWidth;
  double minX, minY, maxX, maxY;
};

533 534 535 536 537 538 539 540 541 542 543 544 545 546
//------------------------------------------------------------------------
// AnnotAppearanceBuilder
//------------------------------------------------------------------------

class AnnotAppearanceBuilder {
public:
  AnnotAppearanceBuilder();
  ~AnnotAppearanceBuilder();

  AnnotAppearanceBuilder(const AnnotAppearanceBuilder &) = delete;
  AnnotAppearanceBuilder& operator=(const AnnotAppearanceBuilder &) = delete;

  void setDrawColor(const AnnotColor *color, GBool fill);
  void setLineStyleForBorder(const AnnotBorder *border);
Tobias Deiminger's avatar
Tobias Deiminger committed
547
  void setTextFont(const Object &fontName, double fontSize);
548 549 550 551
  void drawCircle(double cx, double cy, double r, GBool fill);
  void drawCircleTopLeft(double cx, double cy, double r);
  void drawCircleBottomRight(double cx, double cy, double r);
  void drawFieldBorder(const FormField *field, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect);
552
  bool drawFormField(const FormField *field, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const GooString *appearState, XRef *xref, bool *addedDingbatsResource);
553 554 555 556 557 558 559 560 561

  void writeString(const GooString &str);

  void append(const char *text);
  void appendf(const char *fmt, ...) GOOSTRING_FORMAT;

  const GooString *buffer() const;

private:
562 563 564 565 566 567 568 569 570 571 572 573
  bool drawListBox(const FormFieldChoice *fieldChoice, const AnnotBorder *border, const PDFRectangle *rect,
		   const GooString *da, const GfxResources *resources, int quadding);
  bool drawFormFieldButton(const FormFieldButton *field, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, const GooString *appearState, XRef *xref, bool *addedDingbatsResource);
  bool drawFormFieldText(const FormFieldText *fieldText, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect);
  bool drawFormFieldChoice(const FormFieldChoice *fieldChoice, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect);
  bool drawText(const GooString *text, const GooString *da, const GfxResources *resources,
		const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
		GBool multiline, int comb, int quadding,
		GBool txField, GBool forceZapfDingbats,
		XRef *xref, bool *addedDingbatsResource, // xref and addedDingbatsResource both must not be null if forceZapfDingbats is passed
		GBool password);

574 575 576
  GooString *appearBuf;
};

Kristian Høgsberg's avatar
Kristian Høgsberg committed
577 578 579 580 581
//------------------------------------------------------------------------
// Annot
//------------------------------------------------------------------------

class Annot {
582 583
  friend class Annots;
  friend class Page;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
584
public:
585 586 587 588 589 590 591 592 593 594 595 596 597
  enum AnnotFlag {
    flagUnknown        = 0x0000,
    flagInvisible      = 0x0001,
    flagHidden         = 0x0002,
    flagPrint          = 0x0004,
    flagNoZoom         = 0x0008,
    flagNoRotate       = 0x0010,
    flagNoView         = 0x0020,
    flagReadOnly       = 0x0040,
    flagLocked         = 0x0080,
    flagToggleNoView   = 0x0100,
    flagLockedContents = 0x0200
  };
Kristian Høgsberg's avatar
Kristian Høgsberg committed
598

599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
  enum AnnotSubtype {
    typeUnknown,        //                 0
    typeText,           // Text            1
    typeLink,           // Link            2
    typeFreeText,       // FreeText        3
    typeLine,           // Line            4
    typeSquare,         // Square          5
    typeCircle,         // Circle          6
    typePolygon,        // Polygon         7
    typePolyLine,       // PolyLine        8
    typeHighlight,      // Highlight       9
    typeUnderline,      // Underline      10
    typeSquiggly,       // Squiggly       11
    typeStrikeOut,      // StrikeOut      12
    typeStamp,          // Stamp          13
    typeCaret,          // Caret          14
    typeInk,            // Ink            15
    typePopup,          // Popup          16
    typeFileAttachment, // FileAttachment 17
    typeSound,          // Sound          18
    typeMovie,          // Movie          19
    typeWidget,         // Widget         20
    typeScreen,         // Screen         21
    typePrinterMark,    // PrinterMark    22
    typeTrapNet,        // TrapNet        23
    typeWatermark,      // Watermark      24
625 626
    type3D,             // 3D             25
    typeRichMedia       // RichMedia      26
627 628
  };

629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
  /**
   * Describes the additional actions of a screen or widget annotation.
   */
  enum AdditionalActionsType {
    actionCursorEntering, ///< Performed when the cursor enters the annotation's active area
    actionCursorLeaving,  ///< Performed when the cursor exists the annotation's active area
    actionMousePressed,   ///< Performed when the mouse button is pressed inside the annotation's active area
    actionMouseReleased,  ///< Performed when the mouse button is released inside the annotation's active area
    actionFocusIn,        ///< Performed when the annotation receives the input focus
    actionFocusOut,       ///< Performed when the annotation loses the input focus
    actionPageOpening,    ///< Performed when the page containing the annotation is opened
    actionPageClosing,    ///< Performed when the page containing the annotation is closed
    actionPageVisible,    ///< Performed when the page containing the annotation becomes visible
    actionPageInvisible   ///< Performed when the page containing the annotation becomes invisible
  };

645 646 647 648 649 650 651
  enum FormAdditionalActionsType {
    actionFieldModified,   ///< Performed when the when the user modifies the field
    actionFormatField,     ///< Performed before the field is formatted to display its value
    actionValidateField,   ///< Performed when the field value changes
    actionCalculateField,  ///< Performed when the field needs to be recalculated
  };

652
  Annot(PDFDoc *docA, PDFRectangle *rectA);
653 654
  Annot(PDFDoc *docA, Object *dictObject);
  Annot(PDFDoc *docA, Object *dictObject, Object *obj);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
655 656
  GBool isOk() { return ok; }

657 658 659
  void incRefCnt();
  void decRefCnt();

660
  virtual void draw(Gfx *gfx, GBool printing);
661
  // Get the resource dict of the appearance stream
Albert Astals Cid's avatar
Albert Astals Cid committed
662
  virtual Object getAppearanceResDict();
Kristian Høgsberg's avatar
Kristian Høgsberg committed
663

664 665 666
  GBool match(Ref *refA)
    { return ref.num == refA->num && ref.gen == refA->gen; }

667 668
  double getXMin();
  double getYMin();
669 670
  double getXMax();
  double getYMax();
671

672 673 674
  void setRect(PDFRectangle *rect);
  void setRect(double x1, double y1, double x2, double y2);

675
  // Sets the annot contents to new_content
676
  // new_content should never be NULL
677
  virtual void setContents(GooString *new_content);
678 679 680
  void setName(GooString *new_name);
  void setModified(GooString *new_date);
  void setFlags(Guint new_flags);
681

682
  void setBorder(AnnotBorder *new_border); // Takes ownership
683

684 685 686 687
  // The annotation takes the ownership of
  // new_color. 
  void setColor(AnnotColor *new_color);

688
  void setAppearanceState(const char *state);
689

690
  // getters
691
  PDFDoc *getDoc() const { return doc; }
692
  XRef *getXRef() const { return xref; }
693
  GBool getHasRef() const { return hasRef; }
694
  Ref getRef() const { return ref; }
695 696
  AnnotSubtype getType() const { return type; }
  PDFRectangle *getRect() const { return rect; }
697
  void getRect(double *x1, double *y1, double *x2, double *y2) const;
Albert Astals Cid's avatar
Albert Astals Cid committed
698
  const GooString *getContents() const { return contents; }
699
  int getPageNum() const { return page; }
Albert Astals Cid's avatar
Albert Astals Cid committed
700 701
  const GooString *getName() const { return name; }
  const GooString *getModified() const { return modified; }
702
  Guint getFlags() const { return flags; }
703
  AnnotAppearance *getAppearStreams() const { return appearStreams; }
Albert Astals Cid's avatar
Albert Astals Cid committed
704
  const GooString *getAppearState() const { return appearState; }
705 706 707
  AnnotBorder *getBorder() const { return border; }
  AnnotColor *getColor() const { return color; }
  int getTreeKey() const { return treeKey; }
708

Hugo Mercier's avatar
Hugo Mercier committed
709 710
  int getId() { return ref.num; }

711 712 713
  // Check if point is inside the annot rectangle.
  GBool inRect(double x, double y) const;

714 715 716 717
  static void layoutText(const GooString *text, GooString *outBuf, int *i, const GfxFont *font,
		  double *width, double widthLimit, int *charCount,
		  GBool noReencode);

718
private:
Albert Astals Cid's avatar
Albert Astals Cid committed
719
  void readArrayNum(Object *pdfArray, int key, double *value);
720
  // write vStr[i:j[ in appearBuf
721

722
  void initialize (PDFDoc *docA, Dict *dict);
723
  void setPage (int new_page, GBool updateP); // Called by Page::addAnnot and Annots ctor
724

Hugo Mercier's avatar
Hugo Mercier committed
725

Inigo Martínez's avatar
Inigo Martínez committed
726
protected:
727
  virtual ~Annot();
728
  virtual void removeReferencedObjects(); // Called by Page::removeAnnot
729
  Object createForm(const GooString *appearBuf, double *bbox, GBool transparencyGroup, Dict *resDict);
Albert Astals Cid's avatar
Albert Astals Cid committed
730 731
  Dict *createResourcesDict(const char *formName, Object &&formStream, const char *stateName,
			   double opacity, const char *blendMode);
732
  GBool isVisible(GBool printing);
733
  int getRotation() const;
734

735 736
  // Updates the field key of the annotation dictionary
  // and sets M to the current time
Albert Astals Cid's avatar
Albert Astals Cid committed
737
  void update(const char *key, Object &&value);
738

739 740 741
  // Delete appearance streams and reset appearance state
  void invalidateAppearance();

742
  Object annotObj;
743

744
  std::atomic_int refCnt;
745
  
746
  // required data
747 748
  AnnotSubtype type;                // Annotation type
  PDFRectangle *rect;               // Rect
749 750 751 752 753

  // optional data
  GooString *contents;              // Contents
  GooString *name;                  // NM
  GooString *modified;              // M
754
  int       page;                   // P
755
  Guint flags;                      // F (must be a 32 bit unsigned int)
756
  AnnotAppearance *appearStreams;   // AP
757 758
  Object appearance;     // a reference to the Form XObject stream
                         //   for the normal appearance
759
  AnnotAppearanceBBox *appearBBox;  // BBox of generated appearance
760 761
  GooString *appearState;           // AS
  int treeKey;                      // Struct Parent;
762
  Object oc;                        // OC
763

764
  PDFDoc *doc;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
765
  XRef *xref;			// the xref table for this PDF file
766
  Ref ref;                      // object ref identifying this annotation
767 768
  AnnotBorder *border;          // Border, BS
  AnnotColor *color;            // C
Kristian Høgsberg's avatar
Kristian Høgsberg committed
769
  GBool ok;
Inigo Martínez's avatar
Inigo Martínez committed
770

771
  bool hasRef;
772
  mutable std::recursive_mutex mutex;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
773 774
};

Inigo Martínez's avatar
Inigo Martínez committed
775 776 777 778 779 780
//------------------------------------------------------------------------
// AnnotPopup
//------------------------------------------------------------------------

class AnnotPopup: public Annot {
public:
781
  AnnotPopup(PDFDoc *docA, PDFRectangle *rect);
782
  AnnotPopup(PDFDoc *docA, Object *dictObject, Object *obj);
783
  ~AnnotPopup();
Inigo Martínez's avatar
Inigo Martínez committed
784

785
  Object *getParentNF() { return &parent; }
786 787
  void setParent(Object *parentA);
  void setParent(Annot *parentA);
788
  GBool getOpen() const { return open; }
789
  void setOpen(GBool openA);
Inigo Martínez's avatar
Inigo Martínez committed
790 791

protected:
792
  void initialize(PDFDoc *docA, Dict *dict);
Inigo Martínez's avatar
Inigo Martínez committed
793

794
  Object parent; // Parent
795
  GBool open;   // Open
Inigo Martínez's avatar
Inigo Martínez committed
796 797
};

Inigo Martínez's avatar
Inigo Martínez committed
798 799 800 801
//------------------------------------------------------------------------
// AnnotMarkup
//------------------------------------------------------------------------

802
class AnnotMarkup: public Annot {
Inigo Martínez's avatar
Inigo Martínez committed
803 804 805 806 807 808
public:
  enum  AnnotMarkupReplyType {
    replyTypeR,     // R
    replyTypeGroup  // Group
  };

809
  AnnotMarkup(PDFDoc *docA, PDFRectangle *rect);
810
  AnnotMarkup(PDFDoc *docA, Object *dictObject, Object *obj);
Albert Astals Cid's avatar
Albert Astals Cid committed
811
  ~AnnotMarkup();
Inigo Martínez's avatar
Inigo Martínez committed
812 813

  // getters
Albert Astals Cid's avatar
Albert Astals Cid committed
814
  const GooString *getLabel() const { return label; }
815 816
  AnnotPopup *getPopup() const { return popup; }
  double getOpacity() const { return opacity; }
Inigo Martínez's avatar
Inigo Martínez committed
817
  // getRC
Albert Astals Cid's avatar
Albert Astals Cid committed
818
  const GooString *getDate() const { return date; }
819
  int getInReplyToID() const { return inReplyTo.num; }
Albert Astals Cid's avatar
Albert Astals Cid committed
820
  const GooString *getSubject() const { return subject; }
821 822
  AnnotMarkupReplyType getReplyTo() const { return replyTo; }
  AnnotExternalDataType getExData() const { return exData; }
Inigo Martínez's avatar
Inigo Martínez committed
823

824 825 826
  // The annotation takes the ownership of new_popup
  void setPopup(AnnotPopup *new_popup);
  void setLabel(GooString *new_label);
827
  void setOpacity(double opacityA);
828
  void setDate(GooString *new_date);
829

Inigo Martínez's avatar
Inigo Martínez committed
830
protected:
Albert Astals Cid's avatar
Albert Astals Cid committed
831
  void removeReferencedObjects() override;
832

Inigo Martínez's avatar
Inigo Martínez committed
833 834 835 836 837
  GooString *label;             // T            (Default autor)
  AnnotPopup *popup;            // Popup
  double opacity;               // CA           (Default 1.0)
  // RC
  GooString *date;              // CreationDate
838
  Ref inReplyTo;                // IRT
Inigo Martínez's avatar
Inigo Martínez committed
839 840 841 842 843 844 845 846
  GooString *subject;           // Subj
  AnnotMarkupReplyType replyTo; // RT           (Default R)
  // this object is overrided by the custom intent fields defined in some
  // annotation types.
  //GooString *intent;          // IT
  AnnotExternalDataType exData; // ExData

private:
847
  void initialize(PDFDoc *docA, Dict *dict, Object *obj);
Inigo Martínez's avatar
Inigo Martínez committed
848 849
};

Inigo Martínez's avatar
Inigo Martínez committed
850 851 852 853
//------------------------------------------------------------------------
// AnnotText
//------------------------------------------------------------------------

854
class AnnotText: public AnnotMarkup {
Inigo Martínez's avatar
Inigo Martínez committed
855 856 857 858 859 860 861 862 863 864 865 866 867 868
public:
  enum AnnotTextState {
    stateUnknown,
    // Marked state model
    stateMarked,    // Marked
    stateUnmarked,  // Unmarked
    // Review state model
    stateAccepted,  // Accepted
    stateRejected,  // Rejected
    stateCancelled, // Cancelled
    stateCompleted, // Completed
    stateNone       // None
  };

869
  AnnotText(PDFDoc *docA, PDFRectangle *rect);
870
  AnnotText(PDFDoc *docA, Object *dictObject, Object *obj);
871
  ~AnnotText();
Inigo Martínez's avatar
Inigo Martínez committed
872

Albert Astals Cid's avatar
Albert Astals Cid committed
873
  void draw(Gfx *gfx, GBool printing) override;
874

Inigo Martínez's avatar
Inigo Martínez committed
875
  // getters
876
  GBool getOpen() const { return open; }
Albert Astals Cid's avatar
Albert Astals Cid committed
877
  const GooString *getIcon() const { return icon; }
878
  AnnotTextState getState() const { return state; }
Inigo Martínez's avatar
Inigo Martínez committed
879

880 881 882
  void setOpen(GBool openA);
  void setIcon(GooString *new_icon);

Inigo Martínez's avatar
Inigo Martínez committed
883 884
private:

885
  void initialize(PDFDoc *docA, Dict *dict);
Inigo Martínez's avatar
Inigo Martínez committed
886

887
  GBool open;                       // Open       (Default false)
888
  GooString *icon;                  // Name       (Default Note)
Inigo Martínez's avatar
Inigo Martínez committed
889 890 891 892 893
  AnnotTextState state;             // State      (Default Umarked if
                                    //             StateModel Marked
                                    //             None if StareModel Review)
};

Hugo Mercier's avatar
Hugo Mercier committed
894 895 896 897 898 899 900 901
//------------------------------------------------------------------------
// AnnotMovie
//------------------------------------------------------------------------



class AnnotMovie: public Annot {
 public:
902
  AnnotMovie(PDFDoc *docA, PDFRectangle *rect, Movie *movieA);
903
  AnnotMovie(PDFDoc *docA, Object *dictObject, Object *obj);
Hugo Mercier's avatar
Hugo Mercier committed
904 905
  ~AnnotMovie();

Albert Astals Cid's avatar
Albert Astals Cid committed
906
  void draw(Gfx *gfx, GBool printing) override;
907

Albert Astals Cid's avatar
Albert Astals Cid committed
908
  const GooString* getTitle() const { return title; }
Hugo Mercier's avatar
Hugo Mercier committed
909 910 911
  Movie* getMovie() { return movie; }

 private:
912
  void initialize(PDFDoc *docA, Dict *dict);
Hugo Mercier's avatar
Hugo Mercier committed
913 914

  GooString* title;      // T
915
  Movie* movie;          // Movie + A
Hugo Mercier's avatar
Hugo Mercier committed
916 917 918 919 920 921 922 923 924 925
};


//------------------------------------------------------------------------
// AnnotScreen
//------------------------------------------------------------------------

class AnnotScreen: public Annot {
 public:

926
  AnnotScreen(PDFDoc *docA, PDFRectangle *rect);
927
  AnnotScreen(PDFDoc *docA, Object *dictObject, Object *obj);
Hugo Mercier's avatar
Hugo Mercier committed
928 929
  ~AnnotScreen();

Albert Astals Cid's avatar
Albert Astals Cid committed
930
  const GooString* getTitle() const { return title; }
Hugo Mercier's avatar
Hugo Mercier committed
931 932

  AnnotAppearanceCharacs *getAppearCharacs() { return appearCharacs; }
933 934
  LinkAction* getAction() { return action; } // The caller should now delete the result
  LinkAction *getAdditionalAction(AdditionalActionsType type); // The caller should delete the result
Hugo Mercier's avatar
Hugo Mercier committed
935 936

 private:
937
  void initialize(PDFDoc *docA, Dict *dict);
Hugo Mercier's avatar
Hugo Mercier committed
938 939 940 941 942 943


  GooString* title;                      // T

  AnnotAppearanceCharacs* appearCharacs; // MK

944
  LinkAction *action;                    // A
945
  Object additionalActions;              // AA
Hugo Mercier's avatar
Hugo Mercier committed
946 947
};

948 949 950 951 952 953 954
//------------------------------------------------------------------------
// AnnotLink
//------------------------------------------------------------------------

class AnnotLink: public Annot {
public:

955 956 957 958 959 960 961
  enum AnnotLinkEffect {
    effectNone,     // N
    effectInvert,   // I
    effectOutline,  // O
    effectPush      // P
  };

962
  AnnotLink(PDFDoc *docA, PDFRectangle *rect);
963
  AnnotLink(PDFDoc *docA, Object *dictObject, Object *obj);
Albert Astals Cid's avatar
Albert Astals Cid committed
964
  ~AnnotLink();
965

Albert Astals Cid's avatar
Albert Astals Cid committed
966
  void draw(Gfx *gfx, GBool printing) override;
967

968
  // getters
969
  LinkAction *getAction() const { return action; }
970 971
  AnnotLinkEffect getLinkEffect() const { return linkEffect; }
  Dict *getUriAction() const { return uriAction; }
972
  AnnotQuadrilaterals *getQuadrilaterals() const { return quadrilaterals; }
973 974 975

protected:

976
  void initialize(PDFDoc *docA, Dict *dict);
977

978
  LinkAction *action;                  // A, Dest
979 980
  AnnotLinkEffect linkEffect;          // H          (Default I)
  Dict *uriAction;                     // PA
981

982
  AnnotQuadrilaterals *quadrilaterals; // QuadPoints
983 984
};

Inigo Martínez's avatar
Inigo Martínez committed
985 986 987 988
//------------------------------------------------------------------------
// AnnotFreeText
//------------------------------------------------------------------------

989
class AnnotFreeText: public AnnotMarkup {
Inigo Martínez's avatar
Inigo Martínez committed
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
public:

  enum AnnotFreeTextQuadding {
    quaddingLeftJustified,  // 0
    quaddingCentered,       // 1
    quaddingRightJustified  // 2
  };

  enum AnnotFreeTextIntent {
    intentFreeText,           // FreeText
    intentFreeTextCallout,    // FreeTextCallout
    intentFreeTextTypeWriter  // FreeTextTypeWriter
  };

1004
  AnnotFreeText(PDFDoc *docA, PDFRectangle *rect, const DefaultAppearance &da);
1005
  AnnotFreeText(PDFDoc *docA, Object *dictObject, Object *obj);
1006
  ~AnnotFreeText();
Inigo Martínez's avatar
Inigo Martínez committed
1007

Albert Astals Cid's avatar
Albert Astals Cid committed
1008
  void draw(Gfx *gfx, GBool printing) override;
Albert Astals Cid's avatar
Albert Astals Cid committed
1009
  Object getAppearanceResDict() override;
Albert Astals Cid's avatar
Albert Astals Cid committed
1010
  void setContents(GooString *new_content) override;
1011

1012
  void setDefaultAppearance(const DefaultAppearance &da);
1013 1014
  void setQuadding(AnnotFreeTextQuadding new_quadding);
  void setStyleString(GooString *new_string);
1015
  void setCalloutLine(AnnotCalloutLine *line);
1016 1017
  void setIntent(AnnotFreeTextIntent new_intent);

Inigo Martínez's avatar
Inigo Martínez committed
1018
  // getters
Tobias Deiminger's avatar
Tobias Deiminger committed
1019
  std::unique_ptr<DefaultAppearance> getDefaultAppearance() const;
Inigo Martínez's avatar
Inigo Martínez committed
1020 1021
  AnnotFreeTextQuadding getQuadding() const { return quadding; }
  // return rc
Albert Astals Cid's avatar
Albert Astals Cid committed
1022
  const GooString *getStyleString() const { return styleString; }
Inigo Martínez's avatar
Inigo Martínez committed
1023 1024 1025 1026 1027 1028 1029 1030
  AnnotCalloutLine *getCalloutLine() const {  return calloutLine; }
  AnnotFreeTextIntent getIntent() const { return intent; }
  AnnotBorderEffect *getBorderEffect() const { return borderEffect; }
  PDFRectangle *getRectangle() const { return rectangle; }
  AnnotLineEndingStyle getEndStyle() const { return endStyle; }

protected:

1031
  void initialize(PDFDoc *docA, Dict *dict);
1032
  void generateFreeTextAppearance();
Inigo Martínez's avatar
Inigo Martínez committed
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049

  // required
  GooString *appearanceString;      // DA

  // optional
  AnnotFreeTextQuadding quadding;   // Q  (Default 0)
  // RC
  GooString *styleString;           // DS
  AnnotCalloutLine *calloutLine;    // CL
  AnnotFreeTextIntent intent;       // IT
  AnnotBorderEffect *borderEffect;  // BE
  PDFRectangle *rectangle;          // RD
  // inherited  from Annot
  // AnnotBorderBS border;          // BS
  AnnotLineEndingStyle endStyle;    // LE (Default None)
};

1050 1051 1052 1053
//------------------------------------------------------------------------
// AnnotLine
//------------------------------------------------------------------------

1054
class AnnotLine: public AnnotMarkup {
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
public:

  enum AnnotLineIntent {
    intentLineArrow,    // LineArrow
    intentLineDimension // LineDimension
  };

  enum AnnotLineCaptionPos {
    captionPosInline, // Inline
    captionPosTop     // Top
  };

1067
  AnnotLine(PDFDoc *docA, PDFRectangle *rect);
1068
  AnnotLine(PDFDoc *docA, Object *dictObject, Object *obj);
1069
  ~AnnotLine();
1070

Albert Astals Cid's avatar
Albert Astals Cid committed
1071
  void draw(Gfx *gfx, GBool printing) override;
Albert Astals Cid's avatar
Albert Astals Cid committed
1072
  Object getAppearanceResDict() override;
Albert Astals Cid's avatar
Albert Astals Cid committed
1073
  void setContents(GooString *new_content) override;
1074

1075 1076 1077 1078 1079 1080 1081 1082
  void setVertices(double x1, double y1, double x2, double y2);
  void setStartEndStyle(AnnotLineEndingStyle start, AnnotLineEndingStyle end);
  void setInteriorColor(AnnotColor *new_color);
  void setLeaderLineLength(double len);
  void setLeaderLineExtension(double len);
  void setCaption(bool new_cap);
  void setIntent(AnnotLineIntent new_intent);

1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
  // getters
  AnnotLineEndingStyle getStartStyle() const { return startStyle; }
  AnnotLineEndingStyle getEndStyle() const { return endStyle; }
  AnnotColor *getInteriorColor() const { return interiorColor; }
  double getLeaderLineLength() const { return leaderLineLength; }
  double getLeaderLineExtension() const { return leaderLineExtension; }
  bool getCaption() const { return caption; }
  AnnotLineIntent getIntent() const { return intent; }
  double  getLeaderLineOffset() const { return leaderLineOffset; }
  AnnotLineCaptionPos getCaptionPos() const { return captionPos; }
  Dict *getMeasure() const { return measure; }
  double getCaptionTextHorizontal() const { return captionTextHorizontal; }
  double getCaptionTextVertical() const { return captionTextVertical; }
1096 1097 1098 1099
  double getX1() const { return coord1->getX(); }
  double getY1() const { return coord1->getY(); }
  double getX2() const { return coord2->getX(); }
  double getY2() const { return coord2->getY(); }
1100 1101 1102

protected:

1103
  void initialize(PDFDoc *docA, Dict *dict);
1104
  void generateLineAppearance();
1105 1106

  // required
1107
  AnnotCoord *coord1, *coord2;
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
  
  // optional
  // inherited  from Annot
  // AnnotBorderBS border;          // BS
  AnnotLineEndingStyle startStyle;  // LE       (Default [/None /None])
  AnnotLineEndingStyle endStyle;    //
  AnnotColor *interiorColor;        // IC
  double leaderLineLength;          // LL       (Default 0)
  double leaderLineExtension;       // LLE      (Default 0)
  bool caption;                     // Cap      (Default false)
  AnnotLineIntent intent;           // IT
  double leaderLineOffset;          // LLO
  AnnotLineCaptionPos captionPos;   // CP       (Default Inline)
  Dict *measure;                    // Measure
  double captionTextHorizontal;     // CO       (Default [0, 0])
  double captionTextVertical;       //
};

//------------------------------------------------------------------------
// AnnotTextMarkup
//------------------------------------------------------------------------

1130
class AnnotTextMarkup: public AnnotMarkup {
1131 1132
public:

1133
  AnnotTextMarkup(PDFDoc *docA, PDFRectangle *rect, AnnotSubtype subType);
1134
  AnnotTextMarkup(PDFDoc *docA, Object *dictObject, Object *obj);
Albert Astals Cid's avatar
Albert Astals Cid committed
1135
  ~AnnotTextMarkup();
1136

Albert Astals Cid's avatar
Albert Astals Cid committed
1137
  void draw(Gfx *gfx, GBool printing) override;
1138

1139 1140 1141 1142 1143
  // typeHighlight, typeUnderline, typeSquiggly or typeStrikeOut
  void setType(AnnotSubtype new_type);

  void setQuadrilaterals(AnnotQuadrilaterals *quadPoints);

1144 1145 1146 1147
  AnnotQuadrilaterals *getQuadrilaterals() const { return quadrilaterals; }

protected:

1148
  void initialize(PDFDoc *docA, Dict *dict);
1149 1150 1151 1152
  
  AnnotQuadrilaterals *quadrilaterals; // QuadPoints
};

1153 1154 1155 1156 1157 1158 1159
//------------------------------------------------------------------------
// AnnotStamp
//------------------------------------------------------------------------

class AnnotStamp: public AnnotMarkup {
public:

1160
  AnnotStamp(PDFDoc *docA, PDFRectangle *rect);
1161
  AnnotStamp(PDFDoc *docA, Object *dictObject, Object *obj);
1162 1163
  ~AnnotStamp();

1164 1165
  void setIcon(GooString *new_icon);

1166
  // getters
Albert Astals Cid's avatar
Albert Astals Cid committed
1167
  const GooString *getIcon() const { return icon; }
1168 1169 1170

private:

1171
  void initialize(PDFDoc *docA, Dict *dict);
1172 1173 1174 1175

  GooString *icon;                  // Name       (Default Draft)
};

1176 1177 1178 1179 1180 1181 1182
//------------------------------------------------------------------------
// AnnotGeometry
//------------------------------------------------------------------------

class AnnotGeometry: public AnnotMarkup {
public:

1183
  AnnotGeometry(PDFDoc *docA, PDFRectangle *rect, AnnotSubtype subType);
1184
  AnnotGeometry(PDFDoc *docA, Object *dictObject, Object *obj);
1185 1186
  ~AnnotGeometry();

Albert Astals Cid's avatar
Albert Astals Cid committed
1187
  void draw(Gfx *gfx, GBool printing) override;
1188

1189 1190 1191
  void setType(AnnotSubtype new_type); // typeSquare or typeCircle
  void setInteriorColor(AnnotColor *new_color);

1192 1193 1194 1195 1196 1197 1198
  // getters
  AnnotColor *getInteriorColor() const { return interiorColor; }
  AnnotBorderEffect *getBorderEffect() const { return borderEffect; }
  PDFRectangle *getGeometryRect() const { return geometryRect; }

private:

1199
  void initialize(PDFDoc *docA, Dict *dict);
1200 1201 1202 1203 1204 1205

  AnnotColor *interiorColor;        // IC
  AnnotBorderEffect *borderEffect;  // BE
  PDFRectangle *geometryRect;       // RD (combined with Rect)
};

1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218
//------------------------------------------------------------------------
// AnnotPolygon
//------------------------------------------------------------------------

class AnnotPolygon: public AnnotMarkup {
public:

  enum AnnotPolygonIntent {
    polygonCloud,      // PolygonCloud
    polylineDimension, // PolyLineDimension
    polygonDimension   // PolygonDimension
  };

1219
  AnnotPolygon(PDFDoc *docA, PDFRectangle *rect, AnnotSubtype subType);
1220
  AnnotPolygon(PDFDoc *docA, Object *dictObject, Object *obj);
1221 1222
  ~AnnotPolygon();

Albert Astals Cid's avatar
Albert Astals Cid committed
1223
  void draw(Gfx *gfx, GBool printing) override;
Fabio D'Urso's avatar
Fabio D'Urso committed
1224

1225 1226 1227 1228 1229 1230
  void setType(AnnotSubtype new_type); // typePolygon or typePolyLine
  void setVertices(AnnotPath *path);
  void setStartEndStyle(AnnotLineEndingStyle start, AnnotLineEndingStyle end);
  void setInteriorColor(AnnotColor *new_color);
  void setIntent(AnnotPolygonIntent new_intent);

1231
  // getters
1232 1233 1234 1235 1236 1237
  AnnotPath *getVertices() const { return vertices; }
  AnnotLineEndingStyle getStartStyle() const { return startStyle; }
  AnnotLineEndingStyle getEndStyle() const { return endStyle; }
  AnnotColor *getInteriorColor() const { return interiorColor; }
  AnnotBorderEffect *getBorderEffect() const { return borderEffect; }
  AnnotPolygonIntent getIntent() const { return intent; }
1238 1239 1240

private:

1241
  void initialize(PDFDoc *docA, Dict *dict);
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256

  // required
  AnnotPath *vertices;              // Vertices

  // optional
  AnnotLineEndingStyle startStyle;  // LE       (Default [/None /None])
  AnnotLineEndingStyle endStyle;    //
  // inherited  from Annot
  // AnnotBorderBS border;          // BS
  AnnotColor *interiorColor;        // IC
  AnnotBorderEffect *borderEffect;  // BE
  AnnotPolygonIntent intent;        // IT
  // Measure
};

1257
//------------------------------------------------------------------------
Pino Toscano's avatar
Pino Toscano committed
1258
// AnnotCaret
1259 1260 1261 1262 1263
//------------------------------------------------------------------------

class AnnotCaret: public AnnotMarkup {
public:

1264 1265 1266 1267 1268
  enum AnnotCaretSymbol {
    symbolNone,     // None
    symbolP         // P
  };

1269
  AnnotCaret(PDFDoc *docA, PDFRectangle *rect);
1270
  AnnotCaret(PDFDoc *docA, Object *dictObject, Object *obj);
1271 1272
  ~AnnotCaret();

1273 1274
  void setSymbol(AnnotCaretSymbol new_symbol);

1275
  // getters
1276
  AnnotCaretSymbol getSymbol() const { return symbol; }
1277 1278 1279 1280
  PDFRectangle *getCaretRect() const { return caretRect; }

private:

1281
  void initialize(PDFDoc *docA, Dict *dict);
1282

1283
  AnnotCaretSymbol symbol;       // Sy         (Default None)
1284 1285 1286
  PDFRectangle *caretRect;       // RD (combined with Rect)
};

Inigo Martínez's avatar
Inigo Martínez committed
1287 1288 1289 1290 1291 1292 1293
//------------------------------------------------------------------------
// AnnotInk
//------------------------------------------------------------------------

class AnnotInk: public AnnotMarkup {
public:

1294
  AnnotInk(PDFDoc *docA, PDFRectangle *rect);
1295
  AnnotInk(PDFDoc *docA, Object *dictObject, Object *obj);
Inigo Martínez's avatar
Inigo Martínez committed
1296 1297
  ~AnnotInk();

Albert Astals Cid's avatar
Albert Astals Cid committed
1298
  void draw(Gfx *gfx, GBool printing) override;
Fabio D'Urso's avatar
Fabio D'Urso committed
1299

1300 1301
  void setInkList(AnnotPath **paths, int n_paths);

Inigo Martínez's avatar
Inigo Martínez committed
1302
  // getters
1303 1304
  AnnotPath **getInkList() const { return inkList; }
  int getInkListLength() const { return inkListLength; }
Inigo Martínez's avatar
Inigo Martínez committed
1305 1306 1307

private:

1308
  void initialize(PDFDoc *docA, Dict *dict);
1309 1310 1311
  void writeInkList(AnnotPath **paths, int n_paths, Array *dest_array);
  void parseInkList(Array *src_array);
  void freeInkList();
Inigo Martínez's avatar
Inigo Martínez committed
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321

  // required
  AnnotPath **inkList;       // InkList
  int inkListLength;

  // optional
  // inherited from Annot
  // AnnotBorderBS border;  // BS
};

1322 1323 1324 1325 1326 1327 1328
//------------------------------------------------------------------------
// AnnotFileAttachment
//------------------------------------------------------------------------

class AnnotFileAttachment: public AnnotMarkup {
public:

1329
  AnnotFileAttachment(PDFDoc *docA, PDFRectangle *rect, GooString *filename);
1330
  AnnotFileAttachment(PDFDoc *docA, Object *dictObject, Object *obj);
1331 1332
  ~AnnotFileAttachment();

Albert Astals Cid's avatar
Albert Astals Cid committed
1333
  void draw(Gfx *gfx, GBool printing) override;
1334

1335
  // getters
1336
  Object *getFile() { return &file; }
Albert Astals Cid's avatar
Albert Astals Cid committed
1337
  const GooString *getName() const { return name; }
1338 1339 1340

private:

1341
  void initialize(PDFDoc *docA, Dict *dict);
1342 1343 1344 1345 1346 1347 1348 1349

  // required
  Object file;      // FS

  // optional
  GooString *name;  // Name
};

1350 1351 1352 1353 1354 1355 1356
//------------------------------------------------------------------------
// AnnotSound
//------------------------------------------------------------------------

class AnnotSound: public AnnotMarkup {
public:

1357
  AnnotSound(PDFDoc *docA, PDFRectangle *rect, Sound *soundA);
1358
  AnnotSound(PDFDoc *docA, Object *dictObject, Object *obj);
1359 1360
  ~AnnotSound();

Albert Astals Cid's avatar
Albert Astals Cid committed
1361
  void draw(Gfx *gfx, GBool printing) override;
1362

1363 1364
  // getters
  Sound *getSound() { return sound; }
Albert Astals Cid's avatar
Albert Astals Cid committed
1365
  const GooString *getName() const { return name; }
1366 1367 1368

private:

1369
  void initialize(PDFDoc *docA, Dict *dict);