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

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

PDF plugin: Poppler library updated to version 0.10.0

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