1 //========================================================================
5 // Copyright 1996-2002 Glyph & Cog, LLC
7 //========================================================================
14 #ifdef USE_GCC_PRAGMAS
24 //------------------------------------------------------------------------
26 //------------------------------------------------------------------------
29 actionGoTo, // go to destination
30 actionGoToR, // go to destination in new file
31 actionLaunch, // launch app (or open document)
33 actionNamed, // named action
34 actionMovie, // movie action
35 actionUnknown // anything else
42 virtual ~LinkAction() {}
44 // Was the LinkAction created successfully?
45 virtual GBool isOk() = 0;
47 // Check link action type.
48 virtual LinkActionKind getKind() = 0;
50 // Parse a destination (old-style action) name, string, or array.
51 static LinkAction *parseDest(Object *obj);
53 // Parse an action dictionary.
54 static LinkAction *parseAction(Object *obj, GString *baseURI = NULL);
56 // Extract a file name from a file specification (string or
58 static GString *getFileSpecName(Object *fileSpecObj);
61 //------------------------------------------------------------------------
63 //------------------------------------------------------------------------
79 // Build a LinkDest from the array.
83 LinkDest *copy() { return new LinkDest(this); }
85 // Was the LinkDest created successfully?
86 GBool isOk() { return ok; }
89 LinkDestKind getKind() { return kind; }
90 GBool isPageRef() { return pageIsRef; }
91 int getPageNum() { return pageNum; }
92 Ref getPageRef() { return pageRef; }
93 double getLeft() { return left; }
94 double getBottom() { return bottom; }
95 double getRight() { return right; }
96 double getTop() { return top; }
97 double getZoom() { return zoom; }
98 GBool getChangeLeft() { return changeLeft; }
99 GBool getChangeTop() { return changeTop; }
100 GBool getChangeZoom() { return changeZoom; }
104 LinkDestKind kind; // destination type
105 GBool pageIsRef; // is the page a reference or number?
107 Ref pageRef; // reference to page
108 int pageNum; // one-relative page number
110 double left, bottom; // position
112 double zoom; // zoom factor
113 GBool changeLeft, changeTop; // for destXYZ links, which position
114 GBool changeZoom; // components to change
115 GBool ok; // set if created successfully
117 LinkDest(LinkDest *dest);
120 //------------------------------------------------------------------------
122 //------------------------------------------------------------------------
124 class LinkGoTo: public LinkAction {
127 // Build a LinkGoTo from a destination (dictionary, name, or string).
128 LinkGoTo(Object *destObj);
133 // Was the LinkGoTo created successfully?
134 virtual GBool isOk() { return dest || namedDest; }
137 virtual LinkActionKind getKind() { return actionGoTo; }
138 LinkDest *getDest() { return dest; }
139 GString *getNamedDest() { return namedDest; }
143 LinkDest *dest; // regular destination (NULL for remote
144 // link with bad destination)
145 GString *namedDest; // named destination (only one of dest and
146 // and namedDest may be non-NULL)
149 //------------------------------------------------------------------------
151 //------------------------------------------------------------------------
153 class LinkGoToR: public LinkAction {
156 // Build a LinkGoToR from a file spec (dictionary) and destination
157 // (dictionary, name, or string).
158 LinkGoToR(Object *fileSpecObj, Object *destObj);
161 virtual ~LinkGoToR();
163 // Was the LinkGoToR created successfully?
164 virtual GBool isOk() { return fileName && (dest || namedDest); }
167 virtual LinkActionKind getKind() { return actionGoToR; }
168 GString *getFileName() { return fileName; }
169 LinkDest *getDest() { return dest; }
170 GString *getNamedDest() { return namedDest; }
174 GString *fileName; // file name
175 LinkDest *dest; // regular destination (NULL for remote
176 // link with bad destination)
177 GString *namedDest; // named destination (only one of dest and
178 // and namedDest may be non-NULL)
181 //------------------------------------------------------------------------
183 //------------------------------------------------------------------------
185 class LinkLaunch: public LinkAction {
188 // Build a LinkLaunch from an action dictionary.
189 LinkLaunch(Object *actionObj);
192 virtual ~LinkLaunch();
194 // Was the LinkLaunch created successfully?
195 virtual GBool isOk() { return fileName != NULL; }
198 virtual LinkActionKind getKind() { return actionLaunch; }
199 GString *getFileName() { return fileName; }
200 GString *getParams() { return params; }
204 GString *fileName; // file name
205 GString *params; // parameters
208 //------------------------------------------------------------------------
210 //------------------------------------------------------------------------
212 class LinkURI: public LinkAction {
215 // Build a LinkURI given the URI (string) and base URI.
216 LinkURI(Object *uriObj, GString *baseURI);
221 // Was the LinkURI created successfully?
222 virtual GBool isOk() { return uri != NULL; }
225 virtual LinkActionKind getKind() { return actionURI; }
226 GString *getURI() { return uri; }
230 GString *uri; // the URI
233 //------------------------------------------------------------------------
235 //------------------------------------------------------------------------
237 class LinkNamed: public LinkAction {
240 // Build a LinkNamed given the action name.
241 LinkNamed(Object *nameObj);
243 virtual ~LinkNamed();
245 virtual GBool isOk() { return name != NULL; }
247 virtual LinkActionKind getKind() { return actionNamed; }
248 GString *getName() { return name; }
255 //------------------------------------------------------------------------
257 //------------------------------------------------------------------------
259 class LinkMovie: public LinkAction {
262 LinkMovie(Object *annotObj, Object *titleObj);
264 virtual ~LinkMovie();
266 virtual GBool isOk() { return annotRef.num >= 0 || title != NULL; }
268 virtual LinkActionKind getKind() { return actionMovie; }
269 GBool hasAnnotRef() { return annotRef.num >= 0; }
270 Ref *getAnnotRef() { return &annotRef; }
271 GString *getTitle() { return title; }
279 //------------------------------------------------------------------------
281 //------------------------------------------------------------------------
283 class LinkUnknown: public LinkAction {
286 // Build a LinkUnknown with the specified action type.
287 LinkUnknown(char *actionA);
290 virtual ~LinkUnknown();
292 // Was the LinkUnknown create successfully?
293 virtual GBool isOk() { return action != NULL; }
296 virtual LinkActionKind getKind() { return actionUnknown; }
297 GString *getAction() { return action; }
301 GString *action; // action subtype
304 //------------------------------------------------------------------------
306 //------------------------------------------------------------------------
311 // Construct a link, given its dictionary.
312 Link(Dict *dict, GString *baseURI);
317 // Was the link created successfully?
318 GBool isOk() const { return ok; }
320 // Check if point is inside the link rectangle.
321 GBool inRect(double x, double y) const
322 { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
325 LinkAction *getAction() const { return action; }
327 // Get border corners and width.
328 void getBorder(double *xa1, double *ya1, double *xa2, double *ya2,
330 { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; *wa = borderW; }
334 double x1, y1; // lower left corner
335 double x2, y2; // upper right corner
336 double borderW; // border width
337 LinkAction *action; // action
338 GBool ok; // is link valid?
341 //------------------------------------------------------------------------
343 //------------------------------------------------------------------------
348 // Extract links from array of annotations.
349 Links(Object *annots, GString *baseURI);
354 // Iterate through list of links.
355 int getNumLinks() const { return numLinks; }
356 Link *getLink(int i) const { return links[i]; }
358 // If point <x>,<y> is in a link, return the associated action;
360 LinkAction *find(double x, double y) const;
362 // Return true if <x>,<y> is in a link.
363 GBool onLink(double x, double y) const;