2
//========================================================================
6
// Copyright 1996-2002 Glyph & Cog, LLC
8
//========================================================================
15
#ifdef USE_GCC_PRAGMAS
25
//------------------------------------------------------------------------
27
//------------------------------------------------------------------------
30
actionGoTo, // go to destination
31
actionGoToR, // go to destination in new file
32
actionLaunch, // launch app (or open document)
34
actionNamed, // named action
35
actionMovie, // movie action
36
actionUnknown // anything else
43
virtual ~LinkAction() {}
45
// Was the LinkAction created successfully?
46
virtual GBool isOk() = 0;
48
// Check link action type.
49
virtual LinkActionKind getKind() = 0;
51
// Parse a destination (old-style action) name, string, or array.
52
static LinkAction *parseDest(Object *obj);
54
// Parse an action dictionary.
55
static LinkAction *parseAction(Object *obj, GString *baseURI = NULL);
57
// Extract a file name from a file specification (string or
59
static GString *getFileSpecName(Object *fileSpecObj);
62
//------------------------------------------------------------------------
64
//------------------------------------------------------------------------
80
// Build a LinkDest from the array.
84
LinkDest *copy() { return new LinkDest(this); }
86
// Was the LinkDest created successfully?
87
GBool isOk() { return ok; }
90
LinkDestKind getKind() { return kind; }
91
GBool isPageRef() { return pageIsRef; }
92
int getPageNum() { return pageNum; }
93
Ref getPageRef() { return pageRef; }
94
double getLeft() { return left; }
95
double getBottom() { return bottom; }
96
double getRight() { return right; }
97
double getTop() { return top; }
98
double getZoom() { return zoom; }
99
GBool getChangeLeft() { return changeLeft; }
100
GBool getChangeTop() { return changeTop; }
101
GBool getChangeZoom() { return changeZoom; }
105
LinkDestKind kind; // destination type
106
GBool pageIsRef; // is the page a reference or number?
108
Ref pageRef; // reference to page
109
int pageNum; // one-relative page number
111
double left, bottom; // position
113
double zoom; // zoom factor
114
GBool changeLeft, changeTop; // for destXYZ links, which position
115
GBool changeZoom; // components to change
116
GBool ok; // set if created successfully
118
LinkDest(LinkDest *dest);
121
//------------------------------------------------------------------------
123
//------------------------------------------------------------------------
125
class LinkGoTo: public LinkAction {
128
// Build a LinkGoTo from a destination (dictionary, name, or string).
129
LinkGoTo(Object *destObj);
134
// Was the LinkGoTo created successfully?
135
virtual GBool isOk() { return dest || namedDest; }
138
virtual LinkActionKind getKind() { return actionGoTo; }
139
LinkDest *getDest() { return dest; }
140
GString *getNamedDest() { return namedDest; }
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)
150
//------------------------------------------------------------------------
152
//------------------------------------------------------------------------
154
class LinkGoToR: public LinkAction {
157
// Build a LinkGoToR from a file spec (dictionary) and destination
158
// (dictionary, name, or string).
159
LinkGoToR(Object *fileSpecObj, Object *destObj);
162
virtual ~LinkGoToR();
164
// Was the LinkGoToR created successfully?
165
virtual GBool isOk() { return fileName && (dest || namedDest); }
168
virtual LinkActionKind getKind() { return actionGoToR; }
169
GString *getFileName() { return fileName; }
170
LinkDest *getDest() { return dest; }
171
GString *getNamedDest() { return namedDest; }
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)
182
//------------------------------------------------------------------------
184
//------------------------------------------------------------------------
186
class LinkLaunch: public LinkAction {
189
// Build a LinkLaunch from an action dictionary.
190
LinkLaunch(Object *actionObj);
193
virtual ~LinkLaunch();
195
// Was the LinkLaunch created successfully?
196
virtual GBool isOk() { return fileName != NULL; }
199
virtual LinkActionKind getKind() { return actionLaunch; }
200
GString *getFileName() { return fileName; }
201
GString *getParams() { return params; }
205
GString *fileName; // file name
206
GString *params; // parameters
209
//------------------------------------------------------------------------
211
//------------------------------------------------------------------------
213
class LinkURI: public LinkAction {
216
// Build a LinkURI given the URI (string) and base URI.
217
LinkURI(Object *uriObj, GString *baseURI);
222
// Was the LinkURI created successfully?
223
virtual GBool isOk() { return uri != NULL; }
226
virtual LinkActionKind getKind() { return actionURI; }
227
GString *getURI() { return uri; }
231
GString *uri; // the URI
234
//------------------------------------------------------------------------
236
//------------------------------------------------------------------------
238
class LinkNamed: public LinkAction {
241
// Build a LinkNamed given the action name.
242
LinkNamed(Object *nameObj);
244
virtual ~LinkNamed();
246
virtual GBool isOk() { return name != NULL; }
248
virtual LinkActionKind getKind() { return actionNamed; }
249
GString *getName() { return name; }
256
//------------------------------------------------------------------------
258
//------------------------------------------------------------------------
260
class LinkMovie: public LinkAction {
263
LinkMovie(Object *annotObj, Object *titleObj);
265
virtual ~LinkMovie();
267
virtual GBool isOk() { return annotRef.num >= 0 || title != NULL; }
269
virtual LinkActionKind getKind() { return actionMovie; }
270
GBool hasAnnotRef() { return annotRef.num >= 0; }
271
Ref *getAnnotRef() { return &annotRef; }
272
GString *getTitle() { return title; }
280
//------------------------------------------------------------------------
282
//------------------------------------------------------------------------
284
class LinkUnknown: public LinkAction {
287
// Build a LinkUnknown with the specified action type.
288
LinkUnknown(char *actionA);
291
virtual ~LinkUnknown();
293
// Was the LinkUnknown create successfully?
294
virtual GBool isOk() { return action != NULL; }
297
virtual LinkActionKind getKind() { return actionUnknown; }
298
GString *getAction() { return action; }
302
GString *action; // action subtype
305
//------------------------------------------------------------------------
307
//------------------------------------------------------------------------
312
// Construct a link, given its dictionary.
313
Link(Dict *dict, GString *baseURI);
318
// Was the link created successfully?
319
GBool isOk() { return ok; }
321
// Check if point is inside the link rectangle.
322
GBool inRect(double x, double y)
323
{ return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
326
LinkAction *getAction() { return action; }
328
// Get border corners and width.
329
void getBorder(double *xa1, double *ya1, double *xa2, double *ya2,
331
{ *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; *wa = borderW; }
335
double x1, y1; // lower left corner
336
double x2, y2; // upper right corner
337
double borderW; // border width
338
LinkAction *action; // action
339
GBool ok; // is link valid?
342
//------------------------------------------------------------------------
344
//------------------------------------------------------------------------
349
// Extract links from array of annotations.
350
Links(Object *annots, GString *baseURI);
355
// Iterate through list of links.
356
int getNumLinks() { return numLinks; }
357
Link *getLink(int i) { return links[i]; }
359
// If point <x>,<y> is in a link, return the associated action;
361
LinkAction *find(double x, double y);
363
// Return true if <x>,<y> is in a link.
364
GBool onLink(double x, double y);