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

Last change on this file since 2 was 2, checked in by Eugene Romanenko, 15 years ago

First import

File size: 10.1 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 UGooString;
20class Array;
21class Dict;
22
23//------------------------------------------------------------------------
24// LinkAction
25//------------------------------------------------------------------------
26
27enum LinkActionKind {
28  actionGoTo,                   // go to destination
29  actionGoToR,                  // go to destination in new file
30  actionLaunch,                 // launch app (or open document)
31  actionURI,                    // URI
32  actionNamed,                  // named action
33  actionMovie,                  // movie action
34  actionUnknown                 // anything else
35};
36
37class LinkAction {
38public:
39
40  // Destructor.
41  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, GooString *baseURI = NULL);
54
55  // Extract a file name from a file specification (string or
56  // dictionary).
57  static GooString *getFileSpecName(Object *fileSpecObj);
58};
59
60//------------------------------------------------------------------------
61// LinkDest
62//------------------------------------------------------------------------
63
64enum LinkDestKind {
65  destXYZ,
66  destFit,
67  destFitH,
68  destFitV,
69  destFitR,
70  destFitB,
71  destFitBH,
72  destFitBV
73};
74
75class LinkDest {
76public:
77
78  // Build a LinkDest from the array.
79  LinkDest(Array *a);
80
81  // Copy a LinkDest.
82  LinkDest *copy() { return new LinkDest(this); }
83
84  // Was the LinkDest created successfully?
85  GBool isOk() { return ok; }
86
87  // Accessors.
88  LinkDestKind getKind() { return kind; }
89  GBool isPageRef() { return pageIsRef; }
90  int getPageNum() { return pageNum; }
91  Ref getPageRef() { return pageRef; }
92  double getLeft() { return left; }
93  double getBottom() { return bottom; }
94  double getRight() { return right; }
95  double getTop() { return top; }
96  double getZoom() { return zoom; }
97  GBool getChangeLeft() { return changeLeft; }
98  GBool getChangeTop() { return changeTop; }
99  GBool getChangeZoom() { return changeZoom; }
100
101private:
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;  // for destXYZ links, which position
113  GBool changeZoom;             //   components to change
114  GBool ok;                     // set if created successfully
115
116  LinkDest(LinkDest *dest);
117};
118
119//------------------------------------------------------------------------
120// LinkGoTo
121//------------------------------------------------------------------------
122
123class LinkGoTo: public LinkAction {
124public:
125
126  // Build a LinkGoTo from a destination (dictionary, name, or string).
127  LinkGoTo(Object *destObj);
128
129  // Destructor.
130  virtual ~LinkGoTo();
131
132  // Was the LinkGoTo created successfully?
133  virtual GBool isOk() { return dest || namedDest; }
134
135  // Accessors.
136  virtual LinkActionKind getKind() { return actionGoTo; }
137  LinkDest *getDest() { return dest; }
138  UGooString *getNamedDest() { return namedDest; }
139
140private:
141
142  LinkDest *dest;               // regular destination (NULL for remote
143                                //   link with bad destination)
144  UGooString *namedDest;        // named destination (only one of dest and
145                                //   and namedDest may be non-NULL)
146};
147
148//------------------------------------------------------------------------
149// LinkGoToR
150//------------------------------------------------------------------------
151
152class LinkGoToR: public LinkAction {
153public:
154
155  // Build a LinkGoToR from a file spec (dictionary) and destination
156  // (dictionary, name, or string).
157  LinkGoToR(Object *fileSpecObj, Object *destObj);
158
159  // Destructor.
160  virtual ~LinkGoToR();
161
162  // Was the LinkGoToR created successfully?
163  virtual GBool isOk() { return fileName && (dest || namedDest); }
164
165  // Accessors.
166  virtual LinkActionKind getKind() { return actionGoToR; }
167  GooString *getFileName() { return fileName; }
168  LinkDest *getDest() { return dest; }
169  UGooString *getNamedDest() { return namedDest; }
170
171private:
172
173  GooString *fileName;          // file name
174  LinkDest *dest;               // regular destination (NULL for remote
175                                //   link with bad destination)
176  UGooString *namedDest;        // named destination (only one of dest and
177                                //   and namedDest may be non-NULL)
178};
179
180//------------------------------------------------------------------------
181// LinkLaunch
182//------------------------------------------------------------------------
183
184class LinkLaunch: public LinkAction {
185public:
186
187  // Build a LinkLaunch from an action dictionary.
188  LinkLaunch(Object *actionObj);
189
190  // Destructor.
191  virtual ~LinkLaunch();
192
193  // Was the LinkLaunch created successfully?
194  virtual GBool isOk() { return fileName != NULL; }
195
196  // Accessors.
197  virtual LinkActionKind getKind() { return actionLaunch; }
198  GooString *getFileName() { return fileName; }
199  GooString *getParams() { return params; }
200
201private:
202
203  GooString *fileName;          // file name
204  GooString *params;            // parameters
205};
206
207//------------------------------------------------------------------------
208// LinkURI
209//------------------------------------------------------------------------
210
211class LinkURI: public LinkAction {
212public:
213
214  // Build a LinkURI given the URI (string) and base URI.
215  LinkURI(Object *uriObj, GooString *baseURI);
216
217  // Destructor.
218  virtual ~LinkURI();
219
220  // Was the LinkURI created successfully?
221  virtual GBool isOk() { return uri != NULL; }
222
223  // Accessors.
224  virtual LinkActionKind getKind() { return actionURI; }
225  GooString *getURI() { return uri; }
226
227private:
228
229  GooString *uri;                       // the URI
230};
231
232//------------------------------------------------------------------------
233// LinkNamed
234//------------------------------------------------------------------------
235
236class LinkNamed: public LinkAction {
237public:
238
239  // Build a LinkNamed given the action name.
240  LinkNamed(Object *nameObj);
241
242  virtual ~LinkNamed();
243
244  virtual GBool isOk() { return name != NULL; }
245
246  virtual LinkActionKind getKind() { return actionNamed; }
247  GooString *getName() { return name; }
248
249private:
250
251  GooString *name;
252};
253
254//------------------------------------------------------------------------
255// LinkMovie
256//------------------------------------------------------------------------
257
258class LinkMovie: public LinkAction {
259public:
260
261  LinkMovie(Object *annotObj, Object *titleObj);
262
263  virtual ~LinkMovie();
264
265  virtual GBool isOk() { return annotRef.num >= 0 || title != NULL; }
266
267  virtual LinkActionKind getKind() { return actionMovie; }
268  GBool hasAnnotRef() { return annotRef.num >= 0; }
269  Ref *getAnnotRef() { return &annotRef; }
270  GooString *getTitle() { return title; }
271
272private:
273
274  Ref annotRef;
275  GooString *title;
276};
277
278//------------------------------------------------------------------------
279// LinkUnknown
280//------------------------------------------------------------------------
281
282class LinkUnknown: public LinkAction {
283public:
284
285  // Build a LinkUnknown with the specified action type.
286  LinkUnknown(char *actionA);
287
288  // Destructor.
289  virtual ~LinkUnknown();
290
291  // Was the LinkUnknown create successfully?
292  virtual GBool isOk() { return action != NULL; }
293
294  // Accessors.
295  virtual LinkActionKind getKind() { return actionUnknown; }
296  GooString *getAction() { return action; }
297
298private:
299
300  GooString *action;            // action subtype
301};
302
303//------------------------------------------------------------------------
304// LinkBorderStyle
305//------------------------------------------------------------------------
306
307enum LinkBorderType {
308  linkBorderSolid,
309  linkBorderDashed,
310  linkBorderEmbossed,
311  linkBorderEngraved,
312  linkBorderUnderlined
313};
314
315class LinkBorderStyle {
316public:
317
318  LinkBorderStyle(LinkBorderType typeA, double widthA,
319                  double *dashA, int dashLengthA,
320                  double rA, double gA, double bA);
321  ~LinkBorderStyle();
322
323  LinkBorderType getType() { return type; }
324  double getWidth() { return width; }
325  void getDash(double **dashA, int *dashLengthA)
326    { *dashA = dash; *dashLengthA = dashLength; }
327  void getColor(double *rA, double *gA, double *bA)
328    { *rA = r; *gA = g; *bA = b; }
329
330private:
331
332  LinkBorderType type;
333  double width;
334  double *dash;
335  int dashLength;
336  double r, g, b;
337};
338
339//------------------------------------------------------------------------
340// Link
341//------------------------------------------------------------------------
342
343class Link {
344public:
345
346  // Construct a link, given its dictionary.
347  Link(Dict *dict, GooString *baseURI);
348
349  // Destructor.
350  ~Link();
351
352  // Was the link created successfully?
353  GBool isOk() { return ok; }
354
355  // Check if point is inside the link rectangle.
356  GBool inRect(double x, double y)
357    { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
358
359  // Get action.
360  LinkAction *getAction() { return action; }
361
362  // Get the link rectangle.
363  void getRect(double *xa1, double *ya1, double *xa2, double *ya2)
364    { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; }
365
366  // Get the border style info.
367  LinkBorderStyle *getBorderStyle() { return borderStyle; }
368
369private:
370
371  double x1, y1;                // lower left corner
372  double x2, y2;                // upper right corner
373  LinkBorderStyle *borderStyle; // border style
374  LinkAction *action;           // action
375  GBool ok;                     // is link valid?
376};
377
378//------------------------------------------------------------------------
379// Links
380//------------------------------------------------------------------------
381
382class Links {
383public:
384
385  // Extract links from array of annotations.
386  Links(Object *annots, GooString *baseURI);
387
388  // Destructor.
389  ~Links();
390
391  // Iterate through list of links.
392  int getNumLinks() const { return numLinks; }
393  Link *getLink(int i) const { return links[i]; }
394
395  // If point <x>,<y> is in a link, return the associated action;
396  // else return NULL.
397  LinkAction *find(double x, double y) const;
398
399  // Return true if <x>,<y> is in a link.
400  GBool onLink(double x, double y) const;
401
402private:
403
404  Link **links;
405  int numLinks;
406};
407
408#endif
Note: See TracBrowser for help on using the repository browser.