Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/Link.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/qpdf/xpdf/Link.h | 336 |
1 files changed, 336 insertions, 0 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/Link.h b/noncore/unsupported/qpdf/xpdf/Link.h new file mode 100644 index 0000000..0ad4581 --- a/dev/null +++ b/noncore/unsupported/qpdf/xpdf/Link.h | |||
@@ -0,0 +1,336 @@ | |||
1 | //======================================================================== | ||
2 | // | ||
3 | // Link.h | ||
4 | // | ||
5 | // Copyright 1996 Derek B. Noonburg | ||
6 | // | ||
7 | //======================================================================== | ||
8 | |||
9 | #ifndef LINK_H | ||
10 | #define LINK_H | ||
11 | |||
12 | #ifdef __GNUC__ | ||
13 | #pragma interface | ||
14 | #endif | ||
15 | |||
16 | #include "Object.h" | ||
17 | |||
18 | class GString; | ||
19 | class Array; | ||
20 | class Dict; | ||
21 | |||
22 | //------------------------------------------------------------------------ | ||
23 | // LinkAction | ||
24 | //------------------------------------------------------------------------ | ||
25 | |||
26 | enum LinkActionKind { | ||
27 | actionGoTo, // go to destination | ||
28 | actionGoToR, // go to destination in new file | ||
29 | actionLaunch, // launch app (or open document) | ||
30 | actionURI, // URI | ||
31 | actionNamed, // named action | ||
32 | actionUnknown // anything else | ||
33 | }; | ||
34 | |||
35 | class LinkAction { | ||
36 | public: | ||
37 | |||
38 | // Destructor. | ||
39 | virtual ~LinkAction() {} | ||
40 | |||
41 | // Was the LinkAction created successfully? | ||
42 | virtual GBool isOk() = 0; | ||
43 | |||
44 | // Check link action type. | ||
45 | virtual LinkActionKind getKind() = 0; | ||
46 | }; | ||
47 | |||
48 | //------------------------------------------------------------------------ | ||
49 | // LinkDest | ||
50 | //------------------------------------------------------------------------ | ||
51 | |||
52 | enum LinkDestKind { | ||
53 | destXYZ, | ||
54 | destFit, | ||
55 | destFitH, | ||
56 | destFitV, | ||
57 | destFitR, | ||
58 | destFitB, | ||
59 | destFitBH, | ||
60 | destFitBV | ||
61 | }; | ||
62 | |||
63 | class LinkDest { | ||
64 | public: | ||
65 | |||
66 | // Build a LinkDest from the array. If <pageIsRef> is true, the | ||
67 | // page is specified by an object reference; otherwise the page is | ||
68 | // specified by a (zero-relative) page number. | ||
69 | LinkDest(Array *a, GBool pageIsRef1); | ||
70 | |||
71 | // Copy a LinkDest. | ||
72 | LinkDest *copy() { return new LinkDest(this); } | ||
73 | |||
74 | // Was the LinkDest created successfully? | ||
75 | GBool isOk() { return ok; } | ||
76 | |||
77 | // Accessors. | ||
78 | LinkDestKind getKind() { return kind; } | ||
79 | GBool isPageRef() { return pageIsRef; } | ||
80 | int getPageNum() { return pageNum; } | ||
81 | Ref getPageRef() { return pageRef; } | ||
82 | fouble getLeft() { return left; } | ||
83 | fouble getBottom() { return bottom; } | ||
84 | fouble getRight() { return right; } | ||
85 | fouble getTop() { return top; } | ||
86 | fouble getZoom() { return zoom; } | ||
87 | GBool getChangeLeft() { return changeLeft; } | ||
88 | GBool getChangeTop() { return changeTop; } | ||
89 | GBool getChangeZoom() { return changeZoom; } | ||
90 | |||
91 | private: | ||
92 | |||
93 | LinkDestKind kind; // destination type | ||
94 | GBool pageIsRef; // is the page a reference or number? | ||
95 | union { | ||
96 | Ref pageRef; // reference to page | ||
97 | int pageNum; // one-relative page number | ||
98 | }; | ||
99 | fouble left, bottom; // position | ||
100 | fouble right, top; | ||
101 | fouble zoom; // zoom factor | ||
102 | GBool changeLeft, changeTop;// for destXYZ links, which position | ||
103 | GBool changeZoom; // components to change | ||
104 | GBool ok; // set if created successfully | ||
105 | |||
106 | LinkDest(LinkDest *dest); | ||
107 | }; | ||
108 | |||
109 | //------------------------------------------------------------------------ | ||
110 | // LinkGoTo | ||
111 | //------------------------------------------------------------------------ | ||
112 | |||
113 | class LinkGoTo: public LinkAction { | ||
114 | public: | ||
115 | |||
116 | // Build a LinkGoTo from a destination (dictionary, name, or string). | ||
117 | LinkGoTo(Object *destObj); | ||
118 | |||
119 | // Destructor. | ||
120 | virtual ~LinkGoTo(); | ||
121 | |||
122 | // Was the LinkGoTo created successfully? | ||
123 | virtual GBool isOk() { return dest || namedDest; } | ||
124 | |||
125 | // Accessors. | ||
126 | virtual LinkActionKind getKind() { return actionGoTo; } | ||
127 | LinkDest *getDest() { return dest; } | ||
128 | GString *getNamedDest() { return namedDest; } | ||
129 | |||
130 | private: | ||
131 | |||
132 | LinkDest *dest; // regular destination (NULL for remote | ||
133 | // link with bad destination) | ||
134 | GString *namedDest; // named destination (only one of dest and | ||
135 | // and namedDest may be non-NULL) | ||
136 | }; | ||
137 | |||
138 | //------------------------------------------------------------------------ | ||
139 | // LinkGoToR | ||
140 | //------------------------------------------------------------------------ | ||
141 | |||
142 | class LinkGoToR: public LinkAction { | ||
143 | public: | ||
144 | |||
145 | // Build a LinkGoToR from a file spec (dictionary) and destination | ||
146 | // (dictionary, name, or string). | ||
147 | LinkGoToR(Object *fileSpecObj, Object *destObj); | ||
148 | |||
149 | // Destructor. | ||
150 | virtual ~LinkGoToR(); | ||
151 | |||
152 | // Was the LinkGoToR created successfully? | ||
153 | virtual GBool isOk() { return fileName && (dest || namedDest); } | ||
154 | |||
155 | // Accessors. | ||
156 | virtual LinkActionKind getKind() { return actionGoToR; } | ||
157 | GString *getFileName() { return fileName; } | ||
158 | LinkDest *getDest() { return dest; } | ||
159 | GString *getNamedDest() { return namedDest; } | ||
160 | |||
161 | private: | ||
162 | |||
163 | GString *fileName; // file name | ||
164 | LinkDest *dest; // regular destination (NULL for remote | ||
165 | // link with bad destination) | ||
166 | GString *namedDest; // named destination (only one of dest and | ||
167 | // and namedDest may be non-NULL) | ||
168 | }; | ||
169 | |||
170 | //------------------------------------------------------------------------ | ||
171 | // LinkLaunch | ||
172 | //------------------------------------------------------------------------ | ||
173 | |||
174 | class LinkLaunch: public LinkAction { | ||
175 | public: | ||
176 | |||
177 | // Build a LinkLaunch from an action dictionary. | ||
178 | LinkLaunch(Object *actionObj); | ||
179 | |||
180 | // Destructor. | ||
181 | virtual ~LinkLaunch(); | ||
182 | |||
183 | // Was the LinkLaunch created successfully? | ||
184 | virtual GBool isOk() { return fileName != NULL; } | ||
185 | |||
186 | // Accessors. | ||
187 | virtual LinkActionKind getKind() { return actionLaunch; } | ||
188 | GString *getFileName() { return fileName; } | ||
189 | GString *getParams() { return params; } | ||
190 | |||
191 | private: | ||
192 | |||
193 | GString *fileName; // file name | ||
194 | GString *params; // parameters | ||
195 | }; | ||
196 | |||
197 | //------------------------------------------------------------------------ | ||
198 | // LinkURI | ||
199 | //------------------------------------------------------------------------ | ||
200 | |||
201 | class LinkURI: public LinkAction { | ||
202 | public: | ||
203 | |||
204 | // Build a LinkURI given the URI (string) and base URI. | ||
205 | LinkURI(Object *uriObj, GString *baseURI); | ||
206 | |||
207 | // Destructor. | ||
208 | virtual ~LinkURI(); | ||
209 | |||
210 | // Was the LinkURI created successfully? | ||
211 | virtual GBool isOk() { return uri != NULL; } | ||
212 | |||
213 | // Accessors. | ||
214 | virtual LinkActionKind getKind() { return actionURI; } | ||
215 | GString *getURI() { return uri; } | ||
216 | |||
217 | private: | ||
218 | |||
219 | GString *uri; // the URI | ||
220 | }; | ||
221 | |||
222 | //------------------------------------------------------------------------ | ||
223 | // LinkNamed | ||
224 | //------------------------------------------------------------------------ | ||
225 | |||
226 | class LinkNamed: public LinkAction { | ||
227 | public: | ||
228 | |||
229 | // Build a LinkNamed given the action name. | ||
230 | LinkNamed(Object *nameObj); | ||
231 | |||
232 | virtual ~LinkNamed(); | ||
233 | |||
234 | virtual GBool isOk() { return name != NULL; } | ||
235 | |||
236 | virtual LinkActionKind getKind() { return actionNamed; } | ||
237 | GString *getName() { return name; } | ||
238 | |||
239 | private: | ||
240 | |||
241 | GString *name; | ||
242 | }; | ||
243 | |||
244 | //------------------------------------------------------------------------ | ||
245 | // LinkUnknown | ||
246 | //------------------------------------------------------------------------ | ||
247 | |||
248 | class LinkUnknown: public LinkAction { | ||
249 | public: | ||
250 | |||
251 | // Build a LinkUnknown with the specified action type. | ||
252 | LinkUnknown(char *actionA); | ||
253 | |||
254 | // Destructor. | ||
255 | virtual ~LinkUnknown(); | ||
256 | |||
257 | // Was the LinkUnknown create successfully? | ||
258 | virtual GBool isOk() { return action != NULL; } | ||
259 | |||
260 | // Accessors. | ||
261 | virtual LinkActionKind getKind() { return actionUnknown; } | ||
262 | GString *getAction() { return action; } | ||
263 | |||
264 | private: | ||
265 | |||
266 | GString *action; // action subtype | ||
267 | }; | ||
268 | |||
269 | //------------------------------------------------------------------------ | ||
270 | // Link | ||
271 | //------------------------------------------------------------------------ | ||
272 | |||
273 | class Link { | ||
274 | public: | ||
275 | |||
276 | // Construct a link, given its dictionary. | ||
277 | Link(Dict *dict, GString *baseURI); | ||
278 | |||
279 | // Destructor. | ||
280 | ~Link(); | ||
281 | |||
282 | // Was the link created successfully? | ||
283 | GBool isOk() { return ok; } | ||
284 | |||
285 | // Check if point is inside the link rectangle. | ||
286 | GBool inRect(fouble x, fouble y) | ||
287 | { return x1 <= x && x <= x2 && y1 <= y && y <= y2; } | ||
288 | |||
289 | // Get action. | ||
290 | LinkAction *getAction() { return action; } | ||
291 | |||
292 | // Get border corners and width. | ||
293 | void getBorder(fouble *xa1, fouble *ya1, fouble *xa2, fouble *ya2, | ||
294 | fouble *wa) | ||
295 | { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; *wa = borderW; } | ||
296 | |||
297 | private: | ||
298 | |||
299 | fouble x1, y1; // lower left corner | ||
300 | fouble x2, y2; // upper right corner | ||
301 | fouble borderW; // border width | ||
302 | LinkAction *action; // action | ||
303 | GBool ok; // is link valid? | ||
304 | }; | ||
305 | |||
306 | //------------------------------------------------------------------------ | ||
307 | // Links | ||
308 | //------------------------------------------------------------------------ | ||
309 | |||
310 | class Links { | ||
311 | public: | ||
312 | |||
313 | // Extract links from array of annotations. | ||
314 | Links(Object *annots, GString *baseURI); | ||
315 | |||
316 | // Destructor. | ||
317 | ~Links(); | ||
318 | |||
319 | // Iterate through list of links. | ||
320 | int getNumLinks() { return numLinks; } | ||
321 | Link *getLink(int i) { return links[i]; } | ||
322 | |||
323 | // If point <x>,<y> is in a link, return the associated action; | ||
324 | // else return NULL. | ||
325 | LinkAction *find(fouble x, fouble y); | ||
326 | |||
327 | // Return true if <x>,<y> is in a link. | ||
328 | GBool onLink(fouble x, fouble y); | ||
329 | |||
330 | private: | ||
331 | |||
332 | Link **links; | ||
333 | int numLinks; | ||
334 | }; | ||
335 | |||
336 | #endif | ||