1 //========================================================================
5 // Copyright 1996-2003 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 //------------------------------------------------------------------------
308 enum LinkBorderType {
316 class LinkBorderStyle {
319 LinkBorderStyle(LinkBorderType typeA, double widthA,
320 double *dashA, int dashLengthA,
321 double rA, double gA, double bA);
324 LinkBorderType getType() { return type; }
325 double getWidth() { return width; }
326 void getDash(double **dashA, int *dashLengthA)
327 { *dashA = dash; *dashLengthA = dashLength; }
328 void getColor(double *rA, double *gA, double *bA)
329 { *rA = r; *gA = g; *bA = b; }
340 //------------------------------------------------------------------------
342 //------------------------------------------------------------------------
347 // Construct a link, given its dictionary.
348 Link(Dict *dict, GString *baseURI);
353 // Was the link created successfully?
354 GBool isOk() { return ok; }
356 // Check if point is inside the link rectangle.
357 GBool inRect(double x, double y)
358 { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
361 LinkAction *getAction() { return action; }
363 // Get the link rectangle.
364 void getRect(double *xa1, double *ya1, double *xa2, double *ya2)
365 { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; }
367 // Get the border style info.
368 LinkBorderStyle *getBorderStyle() { return borderStyle; }
372 double x1, y1; // lower left corner
373 double x2, y2; // upper right corner
374 LinkBorderStyle *borderStyle; // border style
375 LinkAction *action; // action
376 GBool ok; // is link valid?
379 //------------------------------------------------------------------------
381 //------------------------------------------------------------------------
386 // Extract links from array of annotations.
387 Links(Object *annots, GString *baseURI);
392 // Iterate through list of links.
393 int getNumLinks() { return numLinks; }
394 Link *getLink(int i) { return links[i]; }
396 // If point <x>,<y> is in a link, return the associated action;
398 LinkAction *find(double x, double y);
400 // Return true if <x>,<y> is in a link.
401 GBool onLink(double x, double y);