1 //========================================================================
5 // Copyright 1996 Derek B. Noonburg
7 //========================================================================
22 //------------------------------------------------------------------------
24 //------------------------------------------------------------------------
27 actionGoTo, // go to destination
28 actionGoToR, // go to destination in new file
29 actionLaunch, // launch app (or open document)
31 actionNamed, // named action
32 actionUnknown // anything else
39 virtual ~LinkAction() {}
41 // Was the LinkAction created successfully?
42 virtual GBool isOk() = 0;
44 // Check link action type.
45 virtual LinkActionKind getKind() = 0;
48 //------------------------------------------------------------------------
50 //------------------------------------------------------------------------
66 // Build a LinkDest from the array. If <pageIsRef> is true, the
67 // page is specified by an object reference; otherwise the page is
68 // specified by a (zero-relative) page number.
69 LinkDest(Array *a, GBool pageIsRef1);
72 LinkDest *copy() { return new LinkDest(this); }
74 // Was the LinkDest created successfully?
75 GBool isOk() { return ok; }
78 LinkDestKind getKind() { return kind; }
79 GBool isPageRef() { return pageIsRef; }
80 int getPageNum() { return pageNum; }
81 Ref getPageRef() { return pageRef; }
82 double getLeft() { return left; }
83 double getBottom() { return bottom; }
84 double getRight() { return right; }
85 double getTop() { return top; }
86 double getZoom() { return zoom; }
87 GBool getChangeLeft() { return changeLeft; }
88 GBool getChangeTop() { return changeTop; }
89 GBool getChangeZoom() { return changeZoom; }
93 LinkDestKind kind; // destination type
94 GBool pageIsRef; // is the page a reference or number?
96 Ref pageRef; // reference to page
97 int pageNum; // one-relative page number
99 double left, bottom; // position
101 double zoom; // zoom factor
102 GBool changeLeft, changeTop; // for destXYZ links, which position
103 GBool changeZoom; // components to change
104 GBool ok; // set if created successfully
106 LinkDest(LinkDest *dest);
109 //------------------------------------------------------------------------
111 //------------------------------------------------------------------------
113 class LinkGoTo: public LinkAction {
116 // Build a LinkGoTo from a destination (dictionary, name, or string).
117 LinkGoTo(Object *destObj);
122 // Was the LinkGoTo created successfully?
123 virtual GBool isOk() { return dest || namedDest; }
126 virtual LinkActionKind getKind() { return actionGoTo; }
127 LinkDest *getDest() { return dest; }
128 GString *getNamedDest() { return namedDest; }
132 LinkDest *dest; // regular destination (NULL for remote
133 // link with bad destination)
134 GString *namedDest; // named destination (only one of dest and
135 // and namedDest may be non-NULL)
138 //------------------------------------------------------------------------
140 //------------------------------------------------------------------------
142 class LinkGoToR: public LinkAction {
145 // Build a LinkGoToR from a file spec (dictionary) and destination
146 // (dictionary, name, or string).
147 LinkGoToR(Object *fileSpecObj, Object *destObj);
150 virtual ~LinkGoToR();
152 // Was the LinkGoToR created successfully?
153 virtual GBool isOk() { return fileName && (dest || namedDest); }
156 virtual LinkActionKind getKind() { return actionGoToR; }
157 GString *getFileName() { return fileName; }
158 LinkDest *getDest() { return dest; }
159 GString *getNamedDest() { return namedDest; }
163 GString *fileName; // file name
164 LinkDest *dest; // regular destination (NULL for remote
165 // link with bad destination)
166 GString *namedDest; // named destination (only one of dest and
167 // and namedDest may be non-NULL)
170 //------------------------------------------------------------------------
172 //------------------------------------------------------------------------
174 class LinkLaunch: public LinkAction {
177 // Build a LinkLaunch from an action dictionary.
178 LinkLaunch(Object *actionObj);
181 virtual ~LinkLaunch();
183 // Was the LinkLaunch created successfully?
184 virtual GBool isOk() { return fileName != NULL; }
187 virtual LinkActionKind getKind() { return actionLaunch; }
188 GString *getFileName() { return fileName; }
189 GString *getParams() { return params; }
193 GString *fileName; // file name
194 GString *params; // parameters
197 //------------------------------------------------------------------------
199 //------------------------------------------------------------------------
201 class LinkURI: public LinkAction {
204 // Build a LinkURI given the URI (string) and base URI.
205 LinkURI(Object *uriObj, GString *baseURI);
210 // Was the LinkURI created successfully?
211 virtual GBool isOk() { return uri != NULL; }
214 virtual LinkActionKind getKind() { return actionURI; }
215 GString *getURI() { return uri; }
219 GString *uri; // the URI
222 //------------------------------------------------------------------------
224 //------------------------------------------------------------------------
226 class LinkNamed: public LinkAction {
229 // Build a LinkNamed given the action name.
230 LinkNamed(Object *nameObj);
232 virtual ~LinkNamed();
234 virtual GBool isOk() { return name != NULL; }
236 virtual LinkActionKind getKind() { return actionNamed; }
237 GString *getName() { return name; }
244 //------------------------------------------------------------------------
246 //------------------------------------------------------------------------
248 class LinkUnknown: public LinkAction {
251 // Build a LinkUnknown with the specified action type.
252 LinkUnknown(char *action1);
255 virtual ~LinkUnknown();
257 // Was the LinkUnknown create successfully?
258 virtual GBool isOk() { return action != NULL; }
261 virtual LinkActionKind getKind() { return actionUnknown; }
262 GString *getAction() { return action; }
266 GString *action; // action subtype
269 //------------------------------------------------------------------------
271 //------------------------------------------------------------------------
276 // Construct a link, given its dictionary.
277 Link(Dict *dict, GString *baseURI);
282 // Was the link created successfully?
283 GBool isOk() { return ok; }
285 // Check if point is inside the link rectangle.
286 GBool inRect(double x, double y)
287 { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
290 LinkAction *getAction() { return action; }
292 // Get border corners and width.
293 void getBorder(double *xa1, double *ya1, double *xa2, double *ya2,
295 { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; *wa = borderW; }
299 double x1, y1; // lower left corner
300 double x2, y2; // upper right corner
301 double borderW; // border width
302 LinkAction *action; // action
303 GBool ok; // is link valid?
306 //------------------------------------------------------------------------
308 //------------------------------------------------------------------------
313 // Extract links from array of annotations.
314 Links(Object *annots, GString *baseURI);
319 // Iterate through list of links.
320 int getNumLinks() { return numLinks; }
321 Link *getLink(int i) { return links[i]; }
323 // If point <x>,<y> is in a link, return the associated action;
325 LinkAction *find(double x, double y);
327 // Return true if <x>,<y> is in a link.
328 GBool onLink(double x, double y);