forked from tsdgeos/poppler_mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnnot.h
1787 lines (1443 loc) · 59.2 KB
/
Annot.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
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
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
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
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//========================================================================
//
// Annot.h
//
// Copyright 2000-2003 Glyph & Cog, LLC
//
//========================================================================
//========================================================================
//
// Modified under the Poppler project - http://poppler.freedesktop.org
//
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
// Copyright (C) 2006 Scott Turner <[email protected]>
// Copyright (C) 2007, 2008 Julien Rebetez <[email protected]>
// Copyright (C) 2007-2011, 2013, 2015, 2018 Carlos Garcia Campos <[email protected]>
// Copyright (C) 2007, 2008 Iñigo Martínez <[email protected]>
// Copyright (C) 2008 Michael Vrable <[email protected]>
// Copyright (C) 2008 Hugo Mercier <[email protected]>
// Copyright (C) 2008 Pino Toscano <[email protected]>
// Copyright (C) 2008 Tomas Are Haavet <[email protected]>
// Copyright (C) 2009-2011, 2013, 2016-2024 Albert Astals Cid <[email protected]>
// Copyright (C) 2012, 2013 Fabio D'Urso <[email protected]>
// Copyright (C) 2012, 2015 Tobias Koenig <[email protected]>
// Copyright (C) 2013 Thomas Freitag <[email protected]>
// Copyright (C) 2013, 2017, 2023 Adrian Johnson <[email protected]>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by the LiMux project of the city of Munich
// Copyright (C) 2018 Dileep Sankhla <[email protected]>
// Copyright (C) 2018-2020 Tobias Deiminger <[email protected]>
// Copyright (C) 2018, 2020, 2022 Oliver Sander <[email protected]>
// Copyright (C) 2018 Adam Reichold <[email protected]>
// Copyright (C) 2019 Umang Malik <[email protected]>
// Copyright (C) 2019 João Netto <[email protected]>
// Copyright (C) 2020 Nelson Benítez León <[email protected]>
// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by Technische Universität Dresden
// Copyright (C) 2020 Katarina Behrens <[email protected]>
// Copyright (C) 2020 Thorsten Behrens <[email protected]>
// Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>.
// Copyright (C) 2021 Zachary Travis <[email protected]>
// Copyright (C) 2021 Mahmoud Ahmed Khalil <[email protected]>
// Copyright (C) 2021 Georgiy Sgibnev <[email protected]>. Work sponsored by lab50.net.
// Copyright (C) 2022 Martin <[email protected]>
// Copyright (C) 2024 Erich E. Hoover <[email protected]>
// Copyright (C) 2024 Carsten Emde <[email protected]>
// Copyright (C) 2024 Lucas Baudin <[email protected]>
// Copyright (C) 2024 g10 Code GmbH, Author: Sune Stolborg Vuorela <[email protected]>
//
// 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
//
//========================================================================
#ifndef ANNOT_H
#define ANNOT_H
#include <memory>
#include <atomic>
#include <mutex>
#include <vector>
#include "AnnotStampImageHelper.h"
#include "Object.h"
#include "poppler_private_export.h"
class XRef;
class Gfx;
class CharCodeToUnicode;
class GfxFont;
class GfxResources;
class Page;
class PDFDoc;
class Form;
class FormWidget;
class FormField;
class FormFieldButton;
class FormFieldText;
class FormFieldChoice;
class FormFieldSignature;
class PDFRectangle;
class Movie;
class LinkAction;
class Sound;
class FileSpec;
enum AnnotLineEndingStyle
{
annotLineEndingSquare, // Square
annotLineEndingCircle, // Circle
annotLineEndingDiamond, // Diamond
annotLineEndingOpenArrow, // OpenArrow
annotLineEndingClosedArrow, // ClosedArrow
annotLineEndingNone, // None
annotLineEndingButt, // Butt
annotLineEndingROpenArrow, // ROpenArrow
annotLineEndingRClosedArrow, // RClosedArrow
annotLineEndingSlash // Slash
};
enum AnnotExternalDataType
{
annotExternalDataMarkupUnknown,
annotExternalDataMarkup3D // Markup3D
};
enum class VariableTextQuadding
{
leftJustified,
centered,
rightJustified
};
//------------------------------------------------------------------------
// 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;
};
//------------------------------------------------------------------------
// AnnotPath
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT AnnotPath
{
public:
AnnotPath();
explicit AnnotPath(Array *array);
explicit AnnotPath(std::vector<AnnotCoord> &&coords);
~AnnotPath();
AnnotPath(const AnnotPath &) = delete;
AnnotPath &operator=(const AnnotPath &other) = delete;
double getX(int coord) const;
double getY(int coord) const;
int getCoordsLength() const { return coords.size(); }
protected:
std::vector<AnnotCoord> coords;
void parsePathArray(Array *array);
};
//------------------------------------------------------------------------
// AnnotCalloutLine
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT AnnotCalloutLine
{
public:
AnnotCalloutLine(double x1, double y1, double x2, double y2);
virtual ~AnnotCalloutLine();
AnnotCalloutLine(const AnnotCalloutLine &) = delete;
AnnotCalloutLine &operator=(const AnnotCalloutLine &other) = delete;
double getX1() const { return coord1.getX(); }
double getY1() const { return coord1.getY(); }
double getX2() const { return coord2.getX(); }
double getY2() const { return coord2.getY(); }
protected:
AnnotCoord coord1, coord2;
};
//------------------------------------------------------------------------
// AnnotCalloutMultiLine
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT AnnotCalloutMultiLine : public AnnotCalloutLine
{
public:
AnnotCalloutMultiLine(double x1, double y1, double x2, double y2, double x3, double y3);
~AnnotCalloutMultiLine() override;
double getX3() const { return coord3.getX(); }
double getY3() const { return coord3.getY(); }
protected:
AnnotCoord coord3;
};
//------------------------------------------------------------------------
// AnnotBorderEffect
//------------------------------------------------------------------------
class AnnotBorderEffect
{
public:
enum AnnotBorderEffectType
{
borderEffectNoEffect, // S
borderEffectCloudy // C
};
explicit AnnotBorderEffect(Dict *dict);
AnnotBorderEffectType getEffectType() const { return effectType; }
double getIntensity() const { return intensity; }
private:
AnnotBorderEffectType effectType; // S (Default S)
double intensity; // I (Default 0)
};
//------------------------------------------------------------------------
// AnnotQuadrilateral
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT AnnotQuadrilaterals
{
public:
class POPPLER_PRIVATE_EXPORT AnnotQuadrilateral
{
public:
AnnotQuadrilateral();
AnnotQuadrilateral(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
AnnotCoord coord1, coord2, coord3, coord4;
};
AnnotQuadrilaterals(Array *array, PDFRectangle *rect);
AnnotQuadrilaterals(std::unique_ptr<AnnotQuadrilateral[]> &&quads, int quadsLength);
~AnnotQuadrilaterals();
AnnotQuadrilaterals(const AnnotQuadrilaterals &) = delete;
AnnotQuadrilaterals &operator=(const AnnotQuadrilaterals &other) = delete;
double getX1(int quadrilateral) const;
double getY1(int quadrilateral) const;
double getX2(int quadrilateral) const;
double getY2(int quadrilateral) const;
double getX3(int quadrilateral) const;
double getY3(int quadrilateral) const;
double getX4(int quadrilateral) const;
double getY4(int quadrilateral) const;
int getQuadrilateralsLength() const { return quadrilateralsLength; }
protected:
std::unique_ptr<AnnotQuadrilateral[]> quadrilaterals;
int quadrilateralsLength;
};
//------------------------------------------------------------------------
// AnnotBorder
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT AnnotBorder
{
public:
enum AnnotBorderType
{
typeArray,
typeBS
};
enum AnnotBorderStyle
{
borderSolid, // Solid
borderDashed, // Dashed
borderBeveled, // Beveled
borderInset, // Inset
borderUnderlined // Underlined
};
virtual ~AnnotBorder();
AnnotBorder(const AnnotBorder &) = delete;
AnnotBorder &operator=(const AnnotBorder &other) = delete;
virtual void setWidth(double new_width) { width = new_width; }
virtual AnnotBorderType getType() const = 0;
virtual double getWidth() const { return width; }
virtual const std::vector<double> &getDash() const { return dash; }
virtual AnnotBorderStyle getStyle() const { return style; }
virtual Object writeToObject(XRef *xref) const = 0;
virtual std::unique_ptr<AnnotBorder> copy() const = 0;
protected:
AnnotBorder();
bool parseDashArray(Object *dashObj);
AnnotBorderType type;
double width;
static const int DASH_LIMIT = 10; // implementation note 82 in Appendix H.
std::vector<double> dash;
AnnotBorderStyle style;
};
//------------------------------------------------------------------------
// AnnotBorderArray
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT AnnotBorderArray : public AnnotBorder
{
public:
AnnotBorderArray();
explicit AnnotBorderArray(Array *array);
void setHorizontalCorner(double hc) { horizontalCorner = hc; }
void setVerticalCorner(double vc) { verticalCorner = vc; }
double getHorizontalCorner() const { return horizontalCorner; }
double getVerticalCorner() const { return verticalCorner; }
std::unique_ptr<AnnotBorder> copy() const override;
private:
AnnotBorderType getType() const override { return typeArray; }
Object writeToObject(XRef *xref) const override;
double horizontalCorner; // (Default 0)
double verticalCorner; // (Default 0)
// double width; // (Default 1) (inherited from AnnotBorder)
};
//------------------------------------------------------------------------
// AnnotBorderBS
//------------------------------------------------------------------------
class AnnotBorderBS : public AnnotBorder
{
public:
AnnotBorderBS();
explicit AnnotBorderBS(Dict *dict);
private:
AnnotBorderType getType() const override { return typeBS; }
Object writeToObject(XRef *xref) const override;
const char *getStyleName() const;
std::unique_ptr<AnnotBorder> copy() const override;
// 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 POPPLER_PRIVATE_EXPORT AnnotColor
{
public:
enum AnnotColorSpace
{
colorTransparent = 0,
colorGray = 1,
colorRGB = 3,
colorCMYK = 4
};
AnnotColor();
explicit AnnotColor(double gray);
AnnotColor(double r, double g, double b);
AnnotColor(double c, double m, double y, double k);
explicit AnnotColor(Array *array, int adjust = 0);
void adjustColor(int adjust);
AnnotColorSpace getSpace() const { return (AnnotColorSpace)length; }
const double *getValues() const { return values; }
Object writeToObject(XRef *xref) const;
private:
double values[4];
int length;
};
//------------------------------------------------------------------------
// DefaultAppearance
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT DefaultAppearance
{
public:
DefaultAppearance(Object &&fontNameA, double fontPtSizeA, std::unique_ptr<AnnotColor> &&fontColorA);
explicit DefaultAppearance(const 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(); }
std::string toAppearanceString() const;
DefaultAppearance(const DefaultAppearance &) = delete;
DefaultAppearance &operator=(const DefaultAppearance &) = delete;
private:
Object fontName;
double fontPtSize;
std::unique_ptr<AnnotColor> fontColor;
};
//------------------------------------------------------------------------
// AnnotIconFit
//------------------------------------------------------------------------
class AnnotIconFit
{
public:
enum AnnotIconFitScaleWhen
{
scaleAlways, // A
scaleBigger, // B
scaleSmaller, // S
scaleNever // N
};
enum AnnotIconFitScale
{
scaleAnamorphic, // A
scaleProportional // P
};
explicit 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
};
AnnotAppearance(PDFDoc *docA, Object *dict);
~AnnotAppearance();
// State is ignored if no subdictionary is present
Object getAppearanceStream(AnnotAppearanceType type, const char *state);
// Access keys in normal appearance subdictionary (N)
std::unique_ptr<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();
// Test if this AnnotAppearance references the specified stream
bool referencesStream(Ref refToStream);
private:
static bool referencesStream(const Object *stateObj, Ref refToStream);
void removeStream(Ref refToStream);
void removeStateStreams(const Object *state);
protected:
PDFDoc *doc;
Object appearDict; // Annotation's AP
};
//------------------------------------------------------------------------
// AnnotAppearanceCharacs
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT AnnotAppearanceCharacs
{
public:
enum AnnotAppearanceCharacsTextPos
{
captionNoIcon, // 0
captionNoCaption, // 1
captionBelow, // 2
captionAbove, // 3
captionRight, // 4
captionLeft, // 5
captionOverlaid // 6
};
explicit AnnotAppearanceCharacs(Dict *dict);
~AnnotAppearanceCharacs();
AnnotAppearanceCharacs(const AnnotAppearanceCharacs &) = delete;
AnnotAppearanceCharacs &operator=(const AnnotAppearanceCharacs &) = delete;
int getRotation() const { return rotation; }
const AnnotColor *getBorderColor() const { return borderColor.get(); }
void setBorderColor(std::unique_ptr<AnnotColor> &&color) { borderColor = std::move(color); }
const AnnotColor *getBackColor() const { return backColor.get(); }
void setBackColor(std::unique_ptr<AnnotColor> &&color) { backColor = std::move(color); }
const GooString *getNormalCaption() const { return normalCaption.get(); }
const GooString *getRolloverCaption() { return rolloverCaption.get(); }
const GooString *getAlternateCaption() { return alternateCaption.get(); }
const AnnotIconFit *getIconFit() { return iconFit.get(); }
AnnotAppearanceCharacsTextPos getPosition() const { return position; }
std::unique_ptr<AnnotAppearanceCharacs> copy() const;
protected:
int rotation; // R (Default 0)
std::unique_ptr<AnnotColor> borderColor; // BC
std::unique_ptr<AnnotColor> backColor; // BG
std::unique_ptr<GooString> normalCaption; // CA
std::unique_ptr<GooString> rolloverCaption; // RC
std::unique_ptr<GooString> alternateCaption; // AC
// I
// RI
// IX
std::unique_ptr<AnnotIconFit> iconFit; // IF
AnnotAppearanceCharacsTextPos position; // TP (Default 0)
};
//------------------------------------------------------------------------
// AnnotAppearanceBBox
//------------------------------------------------------------------------
class AnnotAppearanceBBox
{
public:
explicit AnnotAppearanceBBox(PDFRectangle *rect);
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;
};
//------------------------------------------------------------------------
// AnnotAppearanceBuilder
//------------------------------------------------------------------------
class Matrix;
class AnnotAppearanceBuilder
{
public:
AnnotAppearanceBuilder();
~AnnotAppearanceBuilder();
AnnotAppearanceBuilder(const AnnotAppearanceBuilder &) = delete;
AnnotAppearanceBuilder &operator=(const AnnotAppearanceBuilder &) = delete;
void setDrawColor(const AnnotColor &color, bool fill);
void setLineStyleForBorder(const AnnotBorder &border);
void setTextFont(const Object &fontName, double fontSize);
void drawCircle(double cx, double cy, double r, bool fill);
void drawEllipse(double cx, double cy, double rx, double ry, bool fill, bool stroke);
void drawCircleTopLeft(double cx, double cy, double r);
void drawCircleBottomRight(double cx, double cy, double r);
void drawLineEnding(AnnotLineEndingStyle endingStyle, double x, double y, double size, bool fill, const Matrix &m);
void drawLineEndSquare(double x, double y, double size, bool fill, const Matrix &m);
void drawLineEndCircle(double x, double y, double size, bool fill, const Matrix &m);
void drawLineEndDiamond(double x, double y, double size, bool fill, const Matrix &m);
void drawLineEndArrow(double x, double y, double size, int orientation, bool isOpen, bool fill, const Matrix &m);
void drawLineEndSlash(double x, double y, double size, const Matrix &m);
void drawFieldBorder(const FormField *field, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect);
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, Dict *resourcesDict);
static double lineEndingXShorten(AnnotLineEndingStyle endingStyle, double size);
static double lineEndingXExtendBBox(AnnotLineEndingStyle endingStyle, double size);
void writeString(const std::string &str);
void append(const char *text);
void appendf(const char *fmt, ...) GOOSTRING_FORMAT;
const GooString *buffer() const;
private:
enum DrawTextFlags
{
NoDrawTextFlags = 0,
MultilineDrawTextFlag = 1,
EmitMarkedContentDrawTextFlag = 2,
ForceZapfDingbatsDrawTextFlag = 4,
TurnTextToStarsDrawTextFlag = 8
};
bool drawListBox(const FormFieldChoice *fieldChoice, const AnnotBorder *border, const PDFRectangle *rect, const GooString *da, const GfxResources *resources, VariableTextQuadding quadding, XRef *xref, Dict *resourcesDict);
bool drawFormFieldButton(const FormFieldButton *field, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
const GooString *appearState, XRef *xref, Dict *resourcesDict);
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,
Dict *resourcesDict);
bool drawFormFieldChoice(const FormFieldChoice *fieldChoice, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
XRef *xref, Dict *resourcesDict);
bool drawSignatureFieldText(const FormFieldSignature *field, const Form *form, const GfxResources *resources, const GooString *da, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
XRef *xref, Dict *resourcesDict);
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,
bool centerHorizontally);
bool drawText(const GooString *text, const Form *form, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect,
const VariableTextQuadding quadding, XRef *xref, Dict *resourcesDict, const int flags = NoDrawTextFlags, const int nCombs = 0);
void drawArrowPath(double x, double y, const Matrix &m, int orientation = 1);
GooString *appearBuf;
};
//------------------------------------------------------------------------
// Annot
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT Annot
{
friend class Annots;
friend class Page;
public:
enum AnnotFlag
{
flagUnknown = 0x0000,
flagInvisible = 0x0001,
flagHidden = 0x0002,
flagPrint = 0x0004,
flagNoZoom = 0x0008,
flagNoRotate = 0x0010,
flagNoView = 0x0020,
flagReadOnly = 0x0040,
flagLocked = 0x0080,
flagToggleNoView = 0x0100,
flagLockedContents = 0x0200
};
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
type3D, // 3D 25
typeRichMedia // RichMedia 26
};
/**
* 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
};
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
};
Annot(PDFDoc *docA, PDFRectangle *rectA);
Annot(PDFDoc *docA, Object &&dictObject);
Annot(PDFDoc *docA, Object &&dictObject, const Object *obj);
bool isOk() { return ok; }
static double calculateFontSize(const Form *form, const GfxFont *font, const GooString *text, const double wMax, const double hMax, const bool forceZapfDingbats = {});
void incRefCnt();
void decRefCnt();
virtual void draw(Gfx *gfx, bool printing);
// Get the resource dict of the appearance stream
virtual Object getAppearanceResDict();
bool match(const Ref *refA) const { return ref == *refA; }
double getXMin();
double getYMin();
double getXMax();
double getYMax();
void setRect(const PDFRectangle &rect);
void setRect(double x1, double y1, double x2, double y2);
// Sets the annot contents to new_content
// new_content should never be NULL
virtual void setContents(std::unique_ptr<GooString> &&new_content);
void setName(GooString *new_name);
void setModified(GooString *new_modified);
void setFlags(unsigned int new_flags);
void setBorder(std::unique_ptr<AnnotBorder> &&new_border);
void setColor(std::unique_ptr<AnnotColor> &&new_color);
void setAppearanceState(const char *state);
// getters
PDFDoc *getDoc() const { return doc; }
bool getHasRef() const { return hasRef; }
Ref getRef() const { return ref; }
const Object &getAnnotObj() const { return annotObj; }
AnnotSubtype getType() const { return type; }
const PDFRectangle &getRect() const { return *rect; }
void getRect(double *x1, double *y1, double *x2, double *y2) const;
const GooString *getContents() const { return contents.get(); }
int getPageNum() const { return page; }
const GooString *getName() const { return name.get(); }
const GooString *getModified() const { return modified.get(); }
unsigned int getFlags() const { return flags; }
Object getAppearance() const;
void setNewAppearance(Object &&newAppearance);
void setNewAppearance(Object &&newAppearance, bool keepAppearState);
AnnotAppearance *getAppearStreams() const { return appearStreams.get(); }
const GooString *getAppearState() const { return appearState.get(); }
AnnotBorder *getBorder() const { return border.get(); }
AnnotColor *getColor() const { return color.get(); }
int getTreeKey() const { return treeKey; }
int getId() { return ref.num; }
// Check if point is inside the annot rectangle.
bool inRect(double x, double y) const;
// If newFontNeeded is not null, it will contain whether the given font has glyphs to represent the needed text
static void layoutText(const GooString *text, GooString *outBuf, int *i, const GfxFont &font, double *width, double widthLimit, int *charCount, bool noReencode, bool *newFontNeeded = nullptr);
private:
void readArrayNum(Object *pdfArray, int key, double *value);
// write vStr[i:j[ in appearBuf
void initialize(PDFDoc *docA, Dict *dict);
void setPage(int pageIndex, bool updateP); // Called by Page::addAnnot and Annots ctor
protected:
virtual ~Annot();
virtual void removeReferencedObjects(); // Called by Page::removeAnnot
Object createForm(const GooString *appearBuf, const double *bbox, bool transparencyGroup, Dict *resDict);
Object createForm(const GooString *appearBuf, const double *bbox, bool transparencyGroup, Object &&resDictObject); // overload to support incRef/decRef
Dict *createResourcesDict(const char *formName, Object &&formStream, const char *stateName, double opacity, const char *blendMode);
bool isVisible(bool printing);
int getRotation() const;
// Updates the field key of the annotation dictionary
// and sets M to the current time
void update(const char *key, Object &&value);
// Delete appearance streams and reset appearance state
virtual void invalidateAppearance();
Object annotObj;
std::atomic_int refCnt;
// required data
AnnotSubtype type; // Annotation type
std::unique_ptr<PDFRectangle> rect; // Rect
// optional data
std::unique_ptr<GooString> contents; // Contents
std::unique_ptr<GooString> name; // NM
std::unique_ptr<GooString> modified; // M
int page; // P
unsigned int flags; // F (must be a 32 bit unsigned int)
std::unique_ptr<AnnotAppearance> appearStreams; // AP
Object appearance; // a reference to the Form XObject stream
// for the normal appearance
std::unique_ptr<AnnotAppearanceBBox> appearBBox; // BBox of generated appearance
std::unique_ptr<GooString> appearState; // AS
int treeKey; // Struct Parent;
Object oc; // OC
PDFDoc *doc;
Ref ref; // object ref identifying this annotation
std::unique_ptr<AnnotBorder> border; // Border, BS
std::unique_ptr<AnnotColor> color; // C
bool ok;
bool hasRef;
mutable std::recursive_mutex mutex;
bool hasBeenUpdated = false;
};
//------------------------------------------------------------------------
// AnnotPopup
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT AnnotPopup : public Annot
{
public:
AnnotPopup(PDFDoc *docA, PDFRectangle *rect);
AnnotPopup(PDFDoc *docA, Object &&dictObject, const Object *obj);
~AnnotPopup() override;
bool hasParent() const { return parentRef != Ref::INVALID(); }
void setParent(Annot *parentA);
bool getOpen() const { return open; }
void setOpen(bool openA);
protected:
void initialize(PDFDoc *docA, Dict *dict);
Ref parentRef; // Parent
bool open; // Open
};
//------------------------------------------------------------------------
// AnnotMarkup
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT AnnotMarkup : public Annot
{
public:
enum AnnotMarkupReplyType
{
replyTypeR, // R
replyTypeGroup // Group
};
AnnotMarkup(PDFDoc *docA, PDFRectangle *rect);
AnnotMarkup(PDFDoc *docA, Object &&dictObject, const Object *obj);
~AnnotMarkup() override;
// getters
const GooString *getLabel() const { return label.get(); }
AnnotPopup *getPopup() const { return popup.get(); }
double getOpacity() const { return opacity; }
// getRC
const GooString *getDate() const { return date.get(); }
bool isInReplyTo() const { return inReplyTo != Ref::INVALID(); }
int getInReplyToID() const { return inReplyTo.num; }
const GooString *getSubject() const { return subject.get(); }
AnnotMarkupReplyType getReplyTo() const { return replyTo; }
AnnotExternalDataType getExData() const { return exData; }
// The annotation takes the ownership of new_popup
void setPopup(std::unique_ptr<AnnotPopup> &&new_popup);
void setLabel(std::unique_ptr<GooString> &&new_label);
void setOpacity(double opacityA);
void setDate(GooString *new_date);
protected:
void removeReferencedObjects() override;
std::unique_ptr<GooString> label; // T (Default author)
std::unique_ptr<AnnotPopup> popup; // Popup
double opacity; // CA (Default 1.0)
// RC
std::unique_ptr<GooString> date; // CreationDate
Ref inReplyTo; // IRT
std::unique_ptr<GooString> subject; // Subj
AnnotMarkupReplyType replyTo; // RT (Default R)
// this object is overridden by the custom intent fields defined in some
// annotation types.
// GooString *intent; // IT
AnnotExternalDataType exData; // ExData
private:
void initialize(PDFDoc *docA, Dict *dict);
};
//------------------------------------------------------------------------
// AnnotText
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT AnnotText : public AnnotMarkup
{
public:
enum AnnotTextState
{
stateUnknown,
// Marked state model
stateMarked, // Marked
stateUnmarked, // Unmarked
// Review state model
stateAccepted, // Accepted
stateRejected, // Rejected
stateCancelled, // Cancelled
stateCompleted, // Completed
stateNone // None
};
AnnotText(PDFDoc *docA, PDFRectangle *rect);
AnnotText(PDFDoc *docA, Object &&dictObject, const Object *obj);
~AnnotText() override;
void draw(Gfx *gfx, bool printing) override;
// getters
bool getOpen() const { return open; }
const GooString *getIcon() const { return icon.get(); }
AnnotTextState getState() const { return state; }
void setOpen(bool openA);
void setIcon(GooString *new_icon);
private:
void initialize(PDFDoc *docA, Dict *dict);
bool open; // Open (Default false)
std::unique_ptr<GooString> icon; // Name (Default Note)
AnnotTextState state; // State (Default Umarked if
// StateModel Marked
// None if StareModel Review)
};
//------------------------------------------------------------------------
// AnnotMovie
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT AnnotMovie : public Annot
{
public:
AnnotMovie(PDFDoc *docA, PDFRectangle *rect, Movie *movieA);
AnnotMovie(PDFDoc *docA, Object &&dictObject, const Object *obj);
~AnnotMovie() override;
void draw(Gfx *gfx, bool printing) override;
const GooString *getTitle() const { return title.get(); }
Movie *getMovie() { return movie.get(); }
private:
void initialize(PDFDoc *docA, Dict *dict);
std::unique_ptr<GooString> title; // T
std::unique_ptr<Movie> movie; // Movie + A
};
//------------------------------------------------------------------------
// AnnotScreen
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT AnnotScreen : public Annot
{
public:
AnnotScreen(PDFDoc *docA, PDFRectangle *rect);
AnnotScreen(PDFDoc *docA, Object &&dictObject, const Object *obj);
~AnnotScreen() override;
const GooString *getTitle() const { return title.get(); }
AnnotAppearanceCharacs *getAppearCharacs() { return appearCharacs.get(); }
LinkAction *getAction() { return action.get(); } // The caller should not delete the result