source: trunk/poppler/mypoppler/poppler/Link.h @ 250

Last change on this file since 250 was 250, checked in by Eugene Romanenko, 13 years ago

PDF plugin: poppler library updated to version 0.8.3

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