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 actionUnknown // anything else
38 virtual ~LinkAction() {}
40 // Was the LinkAction created successfully?
41 virtual GBool isOk() = 0;
43 // Check link action type.
44 virtual LinkActionKind getKind() = 0;
47 //------------------------------------------------------------------------
49 //------------------------------------------------------------------------
65 // Build a LinkDest from the array. If <pageIsRef> is true, the
66 // page is specified by an object reference; otherwise the page is
67 // specified by a (zero-relative) page number.
68 LinkDest(Array *a, GBool pageIsRef1);
71 LinkDest *copy() { return new LinkDest(this); }
73 // Was the LinkDest created successfully?
74 GBool isOk() { return ok; }
77 LinkDestKind getKind() { return kind; }
78 GBool isPageRef() { return pageIsRef; }
79 int getPageNum() { return pageNum; }
80 Ref getPageRef() { return pageRef; }
81 double getLeft() { return left; }
82 double getBottom() { return bottom; }
83 double getRight() { return right; }
84 double getTop() { return top; }
85 double getZoom() { return zoom; }
86 GBool getChangeLeft() { return changeLeft; }
87 GBool getChangeTop() { return changeTop; }
88 GBool getChangeZoom() { return changeZoom; }
92 LinkDestKind kind; // destination type
93 GBool pageIsRef; // is the page a reference or number?
95 Ref pageRef; // reference to page
96 int pageNum; // one-relative page number
98 double left, bottom; // position
100 double zoom; // zoom factor
101 GBool changeLeft, changeTop; // for destXYZ links, which position
102 GBool changeZoom; // components to change
103 GBool ok; // set if created successfully
105 LinkDest(LinkDest *dest);
108 //------------------------------------------------------------------------
110 //------------------------------------------------------------------------
112 class LinkGoTo: public LinkAction {
115 // Build a LinkGoTo from a destination (dictionary, name, or string).
116 LinkGoTo(Object *destObj);
121 // Was the LinkGoTo created successfully?
122 virtual GBool isOk() { return dest || namedDest; }
125 virtual LinkActionKind getKind() { return actionGoTo; }
126 LinkDest *getDest() { return dest; }
127 GString *getNamedDest() { return namedDest; }
131 LinkDest *dest; // regular destination (NULL for remote
132 // link with bad destination)
133 GString *namedDest; // named destination (only one of dest and
134 // and namedDest may be non-NULL)
137 //------------------------------------------------------------------------
139 //------------------------------------------------------------------------
141 class LinkGoToR: public LinkAction {
144 // Build a LinkGoToR from a file spec (dictionary) and destination
145 // (dictionary, name, or string).
146 LinkGoToR(Object *fileSpecObj, Object *destObj);
149 virtual ~LinkGoToR();
151 // Was the LinkGoToR created successfully?
152 virtual GBool isOk() { return fileName && (dest || namedDest); }
155 virtual LinkActionKind getKind() { return actionGoToR; }
156 GString *getFileName() { return fileName; }
157 LinkDest *getDest() { return dest; }
158 GString *getNamedDest() { return namedDest; }
162 GString *fileName; // file name
163 LinkDest *dest; // regular destination (NULL for remote
164 // link with bad destination)
165 GString *namedDest; // named destination (only one of dest and
166 // and namedDest may be non-NULL)
169 //------------------------------------------------------------------------
171 //------------------------------------------------------------------------
173 class LinkLaunch: public LinkAction {
176 // Build a LinkLaunch from an action dictionary.
177 LinkLaunch(Object *actionObj);
180 virtual ~LinkLaunch();
182 // Was the LinkLaunch created successfully?
183 virtual GBool isOk() { return fileName != NULL; }
186 virtual LinkActionKind getKind() { return actionLaunch; }
187 GString *getFileName() { return fileName; }
188 GString *getParams() { return params; }
192 GString *fileName; // file name
193 GString *params; // parameters
196 //------------------------------------------------------------------------
198 //------------------------------------------------------------------------
200 class LinkURI: public LinkAction {
203 // Build a LinkURI given the URI (string) and base URI.
204 LinkURI(Object *uriObj, GString *baseURI);
209 // Was the LinkURI created successfully?
210 virtual GBool isOk() { return uri != NULL; }
213 virtual LinkActionKind getKind() { return actionURI; }
214 GString *getURI() { return uri; }
218 GString *uri; // the URI
221 //------------------------------------------------------------------------
223 //------------------------------------------------------------------------
225 class LinkUnknown: public LinkAction {
228 // Build a LinkUnknown with the specified action type.
229 LinkUnknown(char *action1);
232 virtual ~LinkUnknown();
234 // Was the LinkUnknown create successfully?
235 virtual GBool isOk() { return action != NULL; }
238 virtual LinkActionKind getKind() { return actionUnknown; }
239 GString *getAction() { return action; }
243 GString *action; // action subtype
246 //------------------------------------------------------------------------
248 //------------------------------------------------------------------------
253 // Construct a link, given its dictionary.
254 Link(Dict *dict, GString *baseURI);
259 // Was the link created successfully?
260 GBool isOk() { return ok; }
262 // Check if point is inside the link rectangle.
263 GBool inRect(double x, double y)
264 { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
267 LinkAction *getAction() { return action; }
269 // Get border corners and width.
270 void getBorder(double *xa1, double *ya1, double *xa2, double *ya2,
272 { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; *wa = borderW; }
276 double x1, y1; // lower left corner
277 double x2, y2; // upper right corner
278 double borderW; // border width
279 LinkAction *action; // action
280 GBool ok; // is link valid?
283 //------------------------------------------------------------------------
285 //------------------------------------------------------------------------
290 // Extract links from array of annotations.
291 Links(Object *annots, GString *baseURI);
296 // Iterate through list of links.
297 int getNumLinks() { return numLinks; }
298 Link *getLink(int i) { return links[i]; }
300 // If point <x>,<y> is in a link, return the associated action;
302 LinkAction *find(double x, double y);
304 // Return true if <x>,<y> is in a link.
305 GBool onLink(double x, double y);