1 //========================================================================
5 // Copyright 1996-2002 Glyph & Cog, LLC
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.
70 LinkDest *copy() { return new LinkDest(this); }
72 // Was the LinkDest created successfully?
73 GBool isOk() { return ok; }
76 LinkDestKind getKind() { return kind; }
77 GBool isPageRef() { return pageIsRef; }
78 int getPageNum() { return pageNum; }
79 Ref getPageRef() { return pageRef; }
80 double getLeft() { return left; }
81 double getBottom() { return bottom; }
82 double getRight() { return right; }
83 double getTop() { return top; }
84 double getZoom() { return zoom; }
85 GBool getChangeLeft() { return changeLeft; }
86 GBool getChangeTop() { return changeTop; }
87 GBool getChangeZoom() { return changeZoom; }
91 LinkDestKind kind; // destination type
92 GBool pageIsRef; // is the page a reference or number?
94 Ref pageRef; // reference to page
95 int pageNum; // one-relative page number
97 double left, bottom; // position
99 double zoom; // zoom factor
100 GBool changeLeft, changeTop; // for destXYZ links, which position
101 GBool changeZoom; // components to change
102 GBool ok; // set if created successfully
104 LinkDest(LinkDest *dest);
107 //------------------------------------------------------------------------
109 //------------------------------------------------------------------------
111 class LinkGoTo: public LinkAction {
114 // Build a LinkGoTo from a destination (dictionary, name, or string).
115 LinkGoTo(Object *destObj);
120 // Was the LinkGoTo created successfully?
121 virtual GBool isOk() { return dest || namedDest; }
124 virtual LinkActionKind getKind() { return actionGoTo; }
125 LinkDest *getDest() { return dest; }
126 GString *getNamedDest() { return namedDest; }
130 LinkDest *dest; // regular destination (NULL for remote
131 // link with bad destination)
132 GString *namedDest; // named destination (only one of dest and
133 // and namedDest may be non-NULL)
136 //------------------------------------------------------------------------
138 //------------------------------------------------------------------------
140 class LinkGoToR: public LinkAction {
143 // Build a LinkGoToR from a file spec (dictionary) and destination
144 // (dictionary, name, or string).
145 LinkGoToR(Object *fileSpecObj, Object *destObj);
148 virtual ~LinkGoToR();
150 // Was the LinkGoToR created successfully?
151 virtual GBool isOk() { return fileName && (dest || namedDest); }
154 virtual LinkActionKind getKind() { return actionGoToR; }
155 GString *getFileName() { return fileName; }
156 LinkDest *getDest() { return dest; }
157 GString *getNamedDest() { return namedDest; }
161 GString *fileName; // file name
162 LinkDest *dest; // regular destination (NULL for remote
163 // link with bad destination)
164 GString *namedDest; // named destination (only one of dest and
165 // and namedDest may be non-NULL)
168 //------------------------------------------------------------------------
170 //------------------------------------------------------------------------
172 class LinkLaunch: public LinkAction {
175 // Build a LinkLaunch from an action dictionary.
176 LinkLaunch(Object *actionObj);
179 virtual ~LinkLaunch();
181 // Was the LinkLaunch created successfully?
182 virtual GBool isOk() { return fileName != NULL; }
185 virtual LinkActionKind getKind() { return actionLaunch; }
186 GString *getFileName() { return fileName; }
187 GString *getParams() { return params; }
191 GString *fileName; // file name
192 GString *params; // parameters
195 //------------------------------------------------------------------------
197 //------------------------------------------------------------------------
199 class LinkURI: public LinkAction {
202 // Build a LinkURI given the URI (string) and base URI.
203 LinkURI(Object *uriObj, GString *baseURI);
208 // Was the LinkURI created successfully?
209 virtual GBool isOk() { return uri != NULL; }
212 virtual LinkActionKind getKind() { return actionURI; }
213 GString *getURI() { return uri; }
217 GString *uri; // the URI
220 //------------------------------------------------------------------------
222 //------------------------------------------------------------------------
224 class LinkNamed: public LinkAction {
227 // Build a LinkNamed given the action name.
228 LinkNamed(Object *nameObj);
230 virtual ~LinkNamed();
232 virtual GBool isOk() { return name != NULL; }
234 virtual LinkActionKind getKind() { return actionNamed; }
235 GString *getName() { return name; }
242 //------------------------------------------------------------------------
244 //------------------------------------------------------------------------
246 class LinkUnknown: public LinkAction {
249 // Build a LinkUnknown with the specified action type.
250 LinkUnknown(char *actionA);
253 virtual ~LinkUnknown();
255 // Was the LinkUnknown create successfully?
256 virtual GBool isOk() { return action != NULL; }
259 virtual LinkActionKind getKind() { return actionUnknown; }
260 GString *getAction() { return action; }
264 GString *action; // action subtype
267 //------------------------------------------------------------------------
269 //------------------------------------------------------------------------
274 // Construct a link, given its dictionary.
275 Link(Dict *dict, GString *baseURI);
280 // Was the link created successfully?
281 GBool isOk() { return ok; }
283 // Check if point is inside the link rectangle.
284 GBool inRect(double x, double y)
285 { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
288 LinkAction *getAction() { return action; }
290 // Get border corners and width.
291 void getBorder(double *xa1, double *ya1, double *xa2, double *ya2,
293 { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; *wa = borderW; }
297 double x1, y1; // lower left corner
298 double x2, y2; // upper right corner
299 double borderW; // border width
300 LinkAction *action; // action
301 GBool ok; // is link valid?
304 //------------------------------------------------------------------------
306 //------------------------------------------------------------------------
311 // Extract links from array of annotations.
312 Links(Object *annots, GString *baseURI);
317 // Iterate through list of links.
318 int getNumLinks() { return numLinks; }
319 Link *getLink(int i) { return links[i]; }
321 // If point <x>,<y> is in a link, return the associated action;
323 LinkAction *find(double x, double y);
325 // Return true if <x>,<y> is in a link.
326 GBool onLink(double x, double y);