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