/src/xpdf-4.05/xpdf/Link.h
Line | Count | Source (jump to first uncovered line) |
1 | | //======================================================================== |
2 | | // |
3 | | // Link.h |
4 | | // |
5 | | // Copyright 1996-2003 Glyph & Cog, LLC |
6 | | // |
7 | | //======================================================================== |
8 | | |
9 | | #ifndef LINK_H |
10 | | #define LINK_H |
11 | | |
12 | | #include <aconf.h> |
13 | | |
14 | | #include "Object.h" |
15 | | |
16 | | class GString; |
17 | | class Array; |
18 | | class Dict; |
19 | | |
20 | | //------------------------------------------------------------------------ |
21 | | // LinkAction |
22 | | //------------------------------------------------------------------------ |
23 | | |
24 | | enum LinkActionKind { |
25 | | actionGoTo, // go to destination |
26 | | actionGoToR, // go to destination in new file |
27 | | actionLaunch, // launch app (or open document) |
28 | | actionURI, // URI |
29 | | actionNamed, // named action |
30 | | actionMovie, // movie action |
31 | | actionJavaScript, // run JavaScript |
32 | | actionSubmitForm, // submit form |
33 | | actionHide, // hide annotation |
34 | | actionUnknown // anything else |
35 | | }; |
36 | | |
37 | | class LinkAction { |
38 | | public: |
39 | | |
40 | | // Destructor. |
41 | 88 | virtual ~LinkAction() {} |
42 | | |
43 | | // Was the LinkAction created successfully? |
44 | | virtual GBool isOk() = 0; |
45 | | |
46 | | // Check link action type. |
47 | | virtual LinkActionKind getKind() = 0; |
48 | | |
49 | | // Parse a destination (old-style action) name, string, or array. |
50 | | static LinkAction *parseDest(Object *obj); |
51 | | |
52 | | // Parse an action dictionary. |
53 | | static LinkAction *parseAction(Object *obj, GString *baseURI = NULL); |
54 | | |
55 | | // Extract a file name from a file specification (string or |
56 | | // dictionary). |
57 | | static GString *getFileSpecName(Object *fileSpecObj); |
58 | | }; |
59 | | |
60 | | //------------------------------------------------------------------------ |
61 | | // LinkDest |
62 | | //------------------------------------------------------------------------ |
63 | | |
64 | | enum LinkDestKind { |
65 | | destXYZ, |
66 | | destFit, |
67 | | destFitH, |
68 | | destFitV, |
69 | | destFitR, |
70 | | destFitB, |
71 | | destFitBH, |
72 | | destFitBV |
73 | | }; |
74 | | |
75 | | class LinkDest { |
76 | | public: |
77 | | |
78 | | // Build a LinkDest from the array. |
79 | | LinkDest(Array *a); |
80 | | |
81 | | // Copy a LinkDest. |
82 | 0 | LinkDest *copy() { return new LinkDest(this); } |
83 | | |
84 | | // Was the LinkDest created successfully? |
85 | 61 | GBool isOk() { return ok; } |
86 | | |
87 | | // Accessors. |
88 | 0 | LinkDestKind getKind() { return kind; } |
89 | 0 | GBool isPageRef() { return pageIsRef; } |
90 | 0 | int getPageNum() { return pageNum; } |
91 | 0 | Ref getPageRef() { return pageRef; } |
92 | 0 | double getLeft() { return left; } |
93 | 0 | double getBottom() { return bottom; } |
94 | 0 | double getRight() { return right; } |
95 | 0 | double getTop() { return top; } |
96 | 0 | double getZoom() { return zoom; } |
97 | 0 | GBool getChangeLeft() { return changeLeft; } |
98 | 0 | GBool getChangeTop() { return changeTop; } |
99 | 0 | GBool getChangeZoom() { return changeZoom; } |
100 | | |
101 | | private: |
102 | | |
103 | | LinkDestKind kind; // destination type |
104 | | GBool pageIsRef; // is the page a reference or number? |
105 | | union { |
106 | | Ref pageRef; // reference to page |
107 | | int pageNum; // one-relative page number |
108 | | }; |
109 | | double left, bottom; // position |
110 | | double right, top; |
111 | | double zoom; // zoom factor |
112 | | GBool changeLeft, changeTop; // which position components to change: |
113 | | GBool changeZoom; // destXYZ uses all three; |
114 | | // destFitH/BH use changeTop; |
115 | | // destFitV/BV use changeLeft |
116 | | GBool ok; // set if created successfully |
117 | | |
118 | | LinkDest(LinkDest *dest); |
119 | | }; |
120 | | |
121 | | //------------------------------------------------------------------------ |
122 | | // LinkGoTo |
123 | | //------------------------------------------------------------------------ |
124 | | |
125 | | class LinkGoTo: public LinkAction { |
126 | | public: |
127 | | |
128 | | // Build a LinkGoTo from a destination (dictionary, name, or string). |
129 | | LinkGoTo(Object *destObj); |
130 | | |
131 | | // Destructor. |
132 | | virtual ~LinkGoTo(); |
133 | | |
134 | | // Was the LinkGoTo created successfully? |
135 | 65 | virtual GBool isOk() { return dest || namedDest; } |
136 | | |
137 | | // Accessors. |
138 | 0 | virtual LinkActionKind getKind() { return actionGoTo; } |
139 | 0 | LinkDest *getDest() { return dest; } |
140 | 0 | GString *getNamedDest() { return namedDest; } |
141 | | |
142 | | private: |
143 | | |
144 | | LinkDest *dest; // regular destination (NULL for remote |
145 | | // link with bad destination) |
146 | | GString *namedDest; // named destination (only one of dest and |
147 | | // and namedDest may be non-NULL) |
148 | | }; |
149 | | |
150 | | //------------------------------------------------------------------------ |
151 | | // LinkGoToR |
152 | | //------------------------------------------------------------------------ |
153 | | |
154 | | class LinkGoToR: public LinkAction { |
155 | | public: |
156 | | |
157 | | // Build a LinkGoToR from a file spec (dictionary) and destination |
158 | | // (dictionary, name, or string). |
159 | | LinkGoToR(Object *fileSpecObj, Object *destObj); |
160 | | |
161 | | // Destructor. |
162 | | virtual ~LinkGoToR(); |
163 | | |
164 | | // Was the LinkGoToR created successfully? |
165 | 0 | virtual GBool isOk() { return fileName && (dest || namedDest); } |
166 | | |
167 | | // Accessors. |
168 | 0 | virtual LinkActionKind getKind() { return actionGoToR; } |
169 | 0 | GString *getFileName() { return fileName; } |
170 | 0 | LinkDest *getDest() { return dest; } |
171 | 0 | GString *getNamedDest() { return namedDest; } |
172 | | |
173 | | private: |
174 | | |
175 | | GString *fileName; // file name |
176 | | LinkDest *dest; // regular destination (NULL for remote |
177 | | // link with bad destination) |
178 | | GString *namedDest; // named destination (only one of dest and |
179 | | // and namedDest may be non-NULL) |
180 | | }; |
181 | | |
182 | | //------------------------------------------------------------------------ |
183 | | // LinkLaunch |
184 | | //------------------------------------------------------------------------ |
185 | | |
186 | | class LinkLaunch: public LinkAction { |
187 | | public: |
188 | | |
189 | | // Build a LinkLaunch from an action dictionary. |
190 | | LinkLaunch(Object *actionObj); |
191 | | |
192 | | // Destructor. |
193 | | virtual ~LinkLaunch(); |
194 | | |
195 | | // Was the LinkLaunch created successfully? |
196 | 0 | virtual GBool isOk() { return fileName != NULL; } |
197 | | |
198 | | // Accessors. |
199 | 0 | virtual LinkActionKind getKind() { return actionLaunch; } |
200 | 0 | GString *getFileName() { return fileName; } |
201 | 0 | GString *getParams() { return params; } |
202 | | |
203 | | private: |
204 | | |
205 | | GString *fileName; // file name |
206 | | GString *params; // parameters |
207 | | }; |
208 | | |
209 | | //------------------------------------------------------------------------ |
210 | | // LinkURI |
211 | | //------------------------------------------------------------------------ |
212 | | |
213 | | class LinkURI: public LinkAction { |
214 | | public: |
215 | | |
216 | | // Build a LinkURI given the URI (string) and base URI. |
217 | | LinkURI(Object *uriObj, GString *baseURI); |
218 | | |
219 | | // Destructor. |
220 | | virtual ~LinkURI(); |
221 | | |
222 | | // Was the LinkURI created successfully? |
223 | 21 | virtual GBool isOk() { return uri != NULL; } |
224 | | |
225 | | // Accessors. |
226 | 0 | virtual LinkActionKind getKind() { return actionURI; } |
227 | 0 | GString *getURI() { return uri; } |
228 | | |
229 | | private: |
230 | | |
231 | | GString *uri; // the URI |
232 | | }; |
233 | | |
234 | | //------------------------------------------------------------------------ |
235 | | // LinkNamed |
236 | | //------------------------------------------------------------------------ |
237 | | |
238 | | class LinkNamed: public LinkAction { |
239 | | public: |
240 | | |
241 | | // Build a LinkNamed given the action name. |
242 | | LinkNamed(Object *nameObj); |
243 | | |
244 | | virtual ~LinkNamed(); |
245 | | |
246 | | // Was the LinkNamed created successfully? |
247 | 0 | virtual GBool isOk() { return name != NULL; } |
248 | | |
249 | | // Accessors. |
250 | 0 | virtual LinkActionKind getKind() { return actionNamed; } |
251 | 0 | GString *getName() { return name; } |
252 | | |
253 | | private: |
254 | | |
255 | | GString *name; |
256 | | }; |
257 | | |
258 | | //------------------------------------------------------------------------ |
259 | | // LinkMovie |
260 | | //------------------------------------------------------------------------ |
261 | | |
262 | | class LinkMovie: public LinkAction { |
263 | | public: |
264 | | |
265 | | LinkMovie(Object *annotObj, Object *titleObj); |
266 | | |
267 | | virtual ~LinkMovie(); |
268 | | |
269 | | // Was the LinkMovie created successfully? |
270 | 0 | virtual GBool isOk() { return annotRef.num >= 0 || title != NULL; } |
271 | | |
272 | | // Accessors. |
273 | 0 | virtual LinkActionKind getKind() { return actionMovie; } |
274 | 0 | GBool hasAnnotRef() { return annotRef.num >= 0; } |
275 | 0 | Ref *getAnnotRef() { return &annotRef; } |
276 | 0 | GString *getTitle() { return title; } |
277 | | |
278 | | private: |
279 | | |
280 | | Ref annotRef; |
281 | | GString *title; |
282 | | }; |
283 | | |
284 | | //------------------------------------------------------------------------ |
285 | | // LinkJavaScript |
286 | | //------------------------------------------------------------------------ |
287 | | |
288 | | class LinkJavaScript: public LinkAction { |
289 | | public: |
290 | | |
291 | | LinkJavaScript(Object *jsObj); |
292 | | |
293 | | virtual ~LinkJavaScript(); |
294 | | |
295 | | // Was the LinkJavaScript created successfully? |
296 | 0 | virtual GBool isOk() { return js != NULL; } |
297 | | |
298 | | // Accessors. |
299 | 0 | virtual LinkActionKind getKind() { return actionJavaScript; } |
300 | 0 | GString *getJS() { return js; } |
301 | | |
302 | | private: |
303 | | |
304 | | GString *js; |
305 | | }; |
306 | | |
307 | | //------------------------------------------------------------------------ |
308 | | // LinkSubmitForm |
309 | | //------------------------------------------------------------------------ |
310 | | |
311 | | class LinkSubmitForm: public LinkAction { |
312 | | public: |
313 | | |
314 | | LinkSubmitForm(Object *urlObj, Object *fieldsObj, Object *flagsObj); |
315 | | |
316 | | virtual ~LinkSubmitForm(); |
317 | | |
318 | | // Was the LinkSubmitForm created successfully? |
319 | 0 | virtual GBool isOk() { return url != NULL; } |
320 | | |
321 | | // Accessors. |
322 | 0 | virtual LinkActionKind getKind() { return actionSubmitForm; } |
323 | 0 | GString *getURL() { return url; } |
324 | 0 | Object *getFields() { return &fields; } |
325 | 0 | int getFlags() { return flags; } |
326 | | |
327 | | private: |
328 | | |
329 | | GString *url; |
330 | | Object fields; |
331 | | int flags; |
332 | | }; |
333 | | |
334 | | //------------------------------------------------------------------------ |
335 | | // LinkHide |
336 | | //------------------------------------------------------------------------ |
337 | | |
338 | | class LinkHide: public LinkAction { |
339 | | public: |
340 | | |
341 | | LinkHide(Object *fieldsObj, Object *hideFlagObj); |
342 | | |
343 | | virtual ~LinkHide(); |
344 | | |
345 | | // Was the LinkHide created successfully? |
346 | 0 | virtual GBool isOk() { return !fields.isNull(); } |
347 | | |
348 | | // Accessors. |
349 | 0 | virtual LinkActionKind getKind() { return actionHide; } |
350 | 0 | Object *getFields() { return &fields; } |
351 | 0 | GBool getHideFlag() { return hideFlag; } |
352 | | |
353 | | private: |
354 | | |
355 | | Object fields; |
356 | | GBool hideFlag; |
357 | | }; |
358 | | |
359 | | //------------------------------------------------------------------------ |
360 | | // LinkUnknown |
361 | | //------------------------------------------------------------------------ |
362 | | |
363 | | class LinkUnknown: public LinkAction { |
364 | | public: |
365 | | |
366 | | // Build a LinkUnknown with the specified action type. |
367 | | LinkUnknown(char *actionA); |
368 | | |
369 | | // Destructor. |
370 | | virtual ~LinkUnknown(); |
371 | | |
372 | | // Was the LinkUnknown create successfully? |
373 | 2 | virtual GBool isOk() { return action != NULL; } |
374 | | |
375 | | // Accessors. |
376 | 0 | virtual LinkActionKind getKind() { return actionUnknown; } |
377 | 0 | GString *getAction() { return action; } |
378 | | |
379 | | private: |
380 | | |
381 | | GString *action; // action subtype |
382 | | }; |
383 | | |
384 | | //------------------------------------------------------------------------ |
385 | | // Link |
386 | | //------------------------------------------------------------------------ |
387 | | |
388 | | class Link { |
389 | | public: |
390 | | |
391 | | // Construct a link, given its dictionary. |
392 | | Link(Dict *dict, GString *baseURI); |
393 | | |
394 | | // Destructor. |
395 | | ~Link(); |
396 | | |
397 | | // Was the link created successfully? |
398 | 0 | GBool isOk() { return ok; } |
399 | | |
400 | | // Check if point is inside the link rectangle. |
401 | | GBool inRect(double x, double y) |
402 | 0 | { return x1 <= x && x <= x2 && y1 <= y && y <= y2; } |
403 | | |
404 | | // Get action. |
405 | 0 | LinkAction *getAction() { return action; } |
406 | | |
407 | | // Get the link rectangle. |
408 | | void getRect(double *xa1, double *ya1, double *xa2, double *ya2) |
409 | 0 | { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; } |
410 | | |
411 | | private: |
412 | | |
413 | | double x1, y1; // lower left corner |
414 | | double x2, y2; // upper right corner |
415 | | LinkAction *action; // action |
416 | | GBool ok; // is link valid? |
417 | | }; |
418 | | |
419 | | //------------------------------------------------------------------------ |
420 | | // Links |
421 | | //------------------------------------------------------------------------ |
422 | | |
423 | | class Links { |
424 | | public: |
425 | | |
426 | | // Extract links from array of annotations. |
427 | | Links(Object *annots, GString *baseURI); |
428 | | |
429 | | // Destructor. |
430 | | ~Links(); |
431 | | |
432 | | // Iterate through list of links. |
433 | 0 | int getNumLinks() { return numLinks; } |
434 | 0 | Link *getLink(int i) { return links[i]; } |
435 | | |
436 | | // If point <x>,<y> is in a link, return the associated action; |
437 | | // else return NULL. |
438 | | LinkAction *find(double x, double y); |
439 | | |
440 | | // Return true if <x>,<y> is in a link. |
441 | | GBool onLink(double x, double y); |
442 | | |
443 | | private: |
444 | | |
445 | | Link **links; |
446 | | int numLinks; |
447 | | }; |
448 | | |
449 | | #endif |