/src/xpdf-4.06/xpdf/Annot.h
Line | Count | Source |
1 | | //======================================================================== |
2 | | // |
3 | | // Annot.h |
4 | | // |
5 | | // Copyright 2000-2022 Glyph & Cog, LLC |
6 | | // |
7 | | //======================================================================== |
8 | | |
9 | | #ifndef ANNOT_H |
10 | | #define ANNOT_H |
11 | | |
12 | | #include <aconf.h> |
13 | | #if MULTITHREADED |
14 | | #include "GMutex.h" |
15 | | #endif |
16 | | |
17 | | class XRef; |
18 | | class Catalog; |
19 | | class Gfx; |
20 | | class GfxFontDict; |
21 | | class PDFDoc; |
22 | | class PageAnnots; |
23 | | |
24 | | //------------------------------------------------------------------------ |
25 | | // AnnotBorderStyle |
26 | | //------------------------------------------------------------------------ |
27 | | |
28 | | enum AnnotBorderType { |
29 | | annotBorderSolid, |
30 | | annotBorderDashed, |
31 | | annotBorderBeveled, |
32 | | annotBorderInset, |
33 | | annotBorderUnderlined |
34 | | }; |
35 | | |
36 | | class AnnotBorderStyle { |
37 | | public: |
38 | | |
39 | | AnnotBorderStyle(AnnotBorderType typeA, double widthA, |
40 | | double *dashA, int dashLengthA, |
41 | | double *colorA, int nColorCompsA); |
42 | | ~AnnotBorderStyle(); |
43 | | |
44 | 1.43k | AnnotBorderType getType() { return type; } |
45 | 2.07k | double getWidth() { return width; } |
46 | | void getDash(double **dashA, int *dashLengthA) |
47 | 500 | { *dashA = dash; *dashLengthA = dashLength; } |
48 | 1.27k | int getNumColorComps() { return nColorComps; } |
49 | 799 | double *getColor() { return color; } |
50 | | |
51 | | private: |
52 | | |
53 | | AnnotBorderType type; |
54 | | double width; |
55 | | double *dash; |
56 | | int dashLength; |
57 | | double color[4]; |
58 | | int nColorComps; |
59 | | }; |
60 | | |
61 | | //------------------------------------------------------------------------ |
62 | | |
63 | | enum AnnotLineEndType { |
64 | | annotLineEndNone, |
65 | | annotLineEndSquare, |
66 | | annotLineEndCircle, |
67 | | annotLineEndDiamond, |
68 | | annotLineEndOpenArrow, |
69 | | annotLineEndClosedArrow, |
70 | | annotLineEndButt, |
71 | | annotLineEndROpenArrow, |
72 | | annotLineEndRClosedArrow, |
73 | | annotLineEndSlash |
74 | | }; |
75 | | |
76 | | //------------------------------------------------------------------------ |
77 | | // Annot |
78 | | //------------------------------------------------------------------------ |
79 | | |
80 | | class Annot { |
81 | | public: |
82 | | |
83 | | Annot(PDFDoc *docA, Dict *dict, Ref *refA); |
84 | | ~Annot(); |
85 | 29.9k | GBool isOk() { return ok; } |
86 | | |
87 | | void draw(Gfx *gfx, GBool printing); |
88 | | |
89 | 0 | GString *getType() { return type; } |
90 | 0 | double getXMin() { return xMin; } |
91 | 0 | double getYMin() { return yMin; } |
92 | 0 | double getXMax() { return xMax; } |
93 | 0 | double getYMax() { return yMax; } |
94 | | Object *getObject(Object *obj); |
95 | | |
96 | | // Check if point is inside the annotation rectangle. |
97 | | GBool inRect(double x, double y) |
98 | 0 | { return xMin <= x && x <= xMax && yMin <= y && y <= yMax; } |
99 | | |
100 | | // Get appearance object. |
101 | 0 | Object *getAppearance(Object *obj) { return appearance.fetch(xref, obj); } |
102 | | |
103 | 0 | AnnotBorderStyle *getBorderStyle() { return borderStyle; } |
104 | | |
105 | | GBool match(Ref *refA) |
106 | 0 | { return ref.num == refA->num && ref.gen == refA->gen; } |
107 | | |
108 | | void generateAnnotAppearance(Object *annotObj); |
109 | | |
110 | | private: |
111 | | |
112 | | void generateLineAppearance(Object *annotObj); |
113 | | void generatePolyLineAppearance(Object *annotObj); |
114 | | void generatePolygonAppearance(Object *annotObj); |
115 | | void generateFreeTextAppearance(Object *annotObj); |
116 | | void setLineStyle(AnnotBorderStyle *bs, double *lineWidth); |
117 | | void setStrokeColor(double *color, int nComps); |
118 | | GBool setFillColor(Object *colorObj); |
119 | | AnnotLineEndType parseLineEndType(Object *obj); |
120 | | void adjustLineEndpoint(AnnotLineEndType lineEnd, |
121 | | double x, double y, double dx, double dy, |
122 | | double w, double *tx, double *ty); |
123 | | void drawLineArrow(AnnotLineEndType lineEnd, |
124 | | double x, double y, double dx, double dy, |
125 | | double w, GBool fill); |
126 | | void drawCircle(double cx, double cy, double r, const char *cmd); |
127 | | void drawCircleTopLeft(double cx, double cy, double r); |
128 | | void drawCircleBottomRight(double cx, double cy, double r); |
129 | | void drawText(GString *text, GString *da, int quadding, double margin, |
130 | | int rot); |
131 | | |
132 | | PDFDoc *doc; |
133 | | XRef *xref; // the xref table for this PDF file |
134 | | Ref ref; // object ref identifying this annotation |
135 | | GString *type; // annotation type |
136 | | GString *appearanceState; // appearance state name |
137 | | Object appearance; // a reference to the Form XObject stream |
138 | | // for the normal appearance |
139 | | GString *appearBuf; |
140 | | double xMin, yMin, // annotation rectangle |
141 | | xMax, yMax; |
142 | | Guint flags; |
143 | | AnnotBorderStyle *borderStyle; |
144 | | Object ocObj; // optional content entry |
145 | | GBool ok; |
146 | | }; |
147 | | |
148 | | //------------------------------------------------------------------------ |
149 | | // Annots |
150 | | //------------------------------------------------------------------------ |
151 | | |
152 | | class Annots { |
153 | | public: |
154 | | |
155 | | Annots(PDFDoc *docA); |
156 | | |
157 | | ~Annots(); |
158 | | |
159 | | // Iterate over annotations on a specific page. |
160 | | int getNumAnnots(int page); |
161 | | Annot *getAnnot(int page, int idx); |
162 | | |
163 | | // If point (<x>,<y>) is in an annotation, return the associated |
164 | | // annotation (or annotation index); else return NULL (or -1). |
165 | | Annot *find(int page, double x, double y); |
166 | | int findIdx(int page, double x, double y); |
167 | | |
168 | | // Add an annotation [annotObj] on page [page]. |
169 | | void add(int page, Object *annotObj); |
170 | | |
171 | | // Generate an appearance stream for any non-form-field annotation |
172 | | // on the specified page that is missing an appearance. |
173 | | void generateAnnotAppearances(int page); |
174 | | |
175 | | private: |
176 | | |
177 | | void loadAnnots(int page); |
178 | | void loadFormFieldRefs(); |
179 | | |
180 | | PDFDoc *doc; |
181 | | PageAnnots **pageAnnots; // list of annots for each page |
182 | | int formFieldRefsSize; // number of entries in formFieldRefs[] |
183 | | char *formFieldRefs; // set of AcroForm field refs |
184 | | #if MULTITHREADED |
185 | | GMutex mutex; |
186 | | #endif |
187 | | }; |
188 | | |
189 | | #endif |