beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / poppler / Link.h
blobfc2abe60052a2a30fb7c46dfc0ebd54bbebd0fd5
1 //========================================================================
2 //
3 // Link.h
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2006, 2008 Pino Toscano <pino@kde.org>
17 // Copyright (C) 2008 Hugo Mercier <hmercier31@gmail.com>
18 // Copyright (C) 2010, 2011 Carlos Garcia Campos <carlosgc@gnome.org>
19 // Copyright (C) 2012 Tobias Koening <tobias.koenig@kdab.com>
21 // To see a description of the changes please see the Changelog file that
22 // came with your tarball or type make ChangeLog if you are building from git
24 //========================================================================
26 #ifndef LINK_H
27 #define LINK_H
29 #ifdef USE_GCC_PRAGMAS
30 #pragma interface
31 #endif
33 #include "Object.h"
35 class GooString;
36 class GooList;
37 class Array;
38 class Dict;
39 class Sound;
40 class MediaRendition;
41 class AnnotLink;
42 class Annots;
44 //------------------------------------------------------------------------
45 // LinkAction
46 //------------------------------------------------------------------------
48 enum LinkActionKind {
49 actionGoTo, // go to destination
50 actionGoToR, // go to destination in new file
51 actionLaunch, // launch app (or open document)
52 actionURI, // URI
53 actionNamed, // named action
54 actionMovie, // movie action
55 actionRendition, // rendition action
56 actionSound, // sound action
57 actionJavaScript, // JavaScript action
58 actionOCGState, // Set-OCG-State action
59 actionUnknown // anything else
62 class LinkAction {
63 public:
65 // Destructor.
66 virtual ~LinkAction() {}
68 // Was the LinkAction created successfully?
69 virtual GBool isOk() = 0;
71 // Check link action type.
72 virtual LinkActionKind getKind() = 0;
74 // Parse a destination (old-style action) name, string, or array.
75 static LinkAction *parseDest(Object *obj);
77 // Parse an action dictionary.
78 static LinkAction *parseAction(Object *obj, GooString *baseURI = NULL);
81 //------------------------------------------------------------------------
82 // LinkDest
83 //------------------------------------------------------------------------
85 enum LinkDestKind {
86 destXYZ,
87 destFit,
88 destFitH,
89 destFitV,
90 destFitR,
91 destFitB,
92 destFitBH,
93 destFitBV
96 class LinkDest {
97 public:
99 // Build a LinkDest from the array.
100 LinkDest(Array *a);
102 // Copy a LinkDest.
103 LinkDest *copy() { return new LinkDest(this); }
105 // Was the LinkDest created successfully?
106 GBool isOk() { return ok; }
108 // Accessors.
109 LinkDestKind getKind() { return kind; }
110 GBool isPageRef() { return pageIsRef; }
111 int getPageNum() { return pageNum; }
112 Ref getPageRef() { return pageRef; }
113 double getLeft() { return left; }
114 double getBottom() { return bottom; }
115 double getRight() { return right; }
116 double getTop() { return top; }
117 double getZoom() { return zoom; }
118 GBool getChangeLeft() { return changeLeft; }
119 GBool getChangeTop() { return changeTop; }
120 GBool getChangeZoom() { return changeZoom; }
122 private:
124 LinkDestKind kind; // destination type
125 GBool pageIsRef; // is the page a reference or number?
126 union {
127 Ref pageRef; // reference to page
128 int pageNum; // one-relative page number
130 double left, bottom; // position
131 double right, top;
132 double zoom; // zoom factor
133 GBool changeLeft, changeTop; // which position components to change:
134 GBool changeZoom; // destXYZ uses all three;
135 // destFitH/BH use changeTop;
136 // destFitV/BV use changeLeft
137 GBool ok; // set if created successfully
139 LinkDest(LinkDest *dest);
142 //------------------------------------------------------------------------
143 // LinkGoTo
144 //------------------------------------------------------------------------
146 class LinkGoTo: public LinkAction {
147 public:
149 // Build a LinkGoTo from a destination (dictionary, name, or string).
150 LinkGoTo(Object *destObj);
152 // Destructor.
153 virtual ~LinkGoTo();
155 // Was the LinkGoTo created successfully?
156 virtual GBool isOk() { return dest || namedDest; }
158 // Accessors.
159 virtual LinkActionKind getKind() { return actionGoTo; }
160 LinkDest *getDest() { return dest; }
161 GooString *getNamedDest() { return namedDest; }
163 private:
165 LinkDest *dest; // regular destination (NULL for remote
166 // link with bad destination)
167 GooString *namedDest; // named destination (only one of dest and
168 // and namedDest may be non-NULL)
171 //------------------------------------------------------------------------
172 // LinkGoToR
173 //------------------------------------------------------------------------
175 class LinkGoToR: public LinkAction {
176 public:
178 // Build a LinkGoToR from a file spec (dictionary) and destination
179 // (dictionary, name, or string).
180 LinkGoToR(Object *fileSpecObj, Object *destObj);
182 // Destructor.
183 virtual ~LinkGoToR();
185 // Was the LinkGoToR created successfully?
186 virtual GBool isOk() { return fileName && (dest || namedDest); }
188 // Accessors.
189 virtual LinkActionKind getKind() { return actionGoToR; }
190 GooString *getFileName() { return fileName; }
191 LinkDest *getDest() { return dest; }
192 GooString *getNamedDest() { return namedDest; }
194 private:
196 GooString *fileName; // file name
197 LinkDest *dest; // regular destination (NULL for remote
198 // link with bad destination)
199 GooString *namedDest; // named destination (only one of dest and
200 // and namedDest may be non-NULL)
203 //------------------------------------------------------------------------
204 // LinkLaunch
205 //------------------------------------------------------------------------
207 class LinkLaunch: public LinkAction {
208 public:
210 // Build a LinkLaunch from an action dictionary.
211 LinkLaunch(Object *actionObj);
213 // Destructor.
214 virtual ~LinkLaunch();
216 // Was the LinkLaunch created successfully?
217 virtual GBool isOk() { return fileName != NULL; }
219 // Accessors.
220 virtual LinkActionKind getKind() { return actionLaunch; }
221 GooString *getFileName() { return fileName; }
222 GooString *getParams() { return params; }
224 private:
226 GooString *fileName; // file name
227 GooString *params; // parameters
230 //------------------------------------------------------------------------
231 // LinkURI
232 //------------------------------------------------------------------------
234 class LinkURI: public LinkAction {
235 public:
237 // Build a LinkURI given the URI (string) and base URI.
238 LinkURI(Object *uriObj, GooString *baseURI);
240 // Destructor.
241 virtual ~LinkURI();
243 // Was the LinkURI created successfully?
244 virtual GBool isOk() { return uri != NULL; }
246 // Accessors.
247 virtual LinkActionKind getKind() { return actionURI; }
248 GooString *getURI() { return uri; }
250 private:
252 GooString *uri; // the URI
255 //------------------------------------------------------------------------
256 // LinkNamed
257 //------------------------------------------------------------------------
259 class LinkNamed: public LinkAction {
260 public:
262 // Build a LinkNamed given the action name.
263 LinkNamed(Object *nameObj);
265 virtual ~LinkNamed();
267 virtual GBool isOk() { return name != NULL; }
269 virtual LinkActionKind getKind() { return actionNamed; }
270 GooString *getName() { return name; }
272 private:
274 GooString *name;
278 //------------------------------------------------------------------------
279 // LinkMovie
280 //------------------------------------------------------------------------
282 class LinkMovie: public LinkAction {
283 public:
285 enum OperationType {
286 operationTypePlay,
287 operationTypePause,
288 operationTypeResume,
289 operationTypeStop
292 LinkMovie(Object *obj);
293 virtual ~LinkMovie();
295 virtual GBool isOk() { return annotRef.num >= 0 || annotTitle != NULL; }
296 virtual LinkActionKind getKind() { return actionMovie; }
298 // a movie action stores either an indirect reference to a movie annotation
299 // or the movie annotation title
301 GBool hasAnnotRef() { return annotRef.num >= 0; }
302 GBool hasAnnotTitle() { return annotTitle != NULL; }
303 Ref *getAnnotRef() { return &annotRef; }
304 GooString *getAnnotTitle() { return annotTitle; }
306 OperationType getOperation() { return operation; }
308 private:
310 Ref annotRef; // Annotation
311 GooString *annotTitle; // T
313 OperationType operation; // Operation
317 //------------------------------------------------------------------------
318 // LinkRendition
319 //------------------------------------------------------------------------
321 class LinkRendition: public LinkAction {
322 public:
324 * Describes the possible rendition operations.
326 enum RenditionOperation {
327 NoRendition,
328 PlayRendition,
329 StopRendition,
330 PauseRendition,
331 ResumeRendition
334 LinkRendition(Object *Obj);
336 virtual ~LinkRendition();
338 virtual GBool isOk() { return true; }
340 virtual LinkActionKind getKind() { return actionRendition; }
342 GBool hasRenditionObject() { return renditionObj.isDict(); }
343 Object* getRenditionObject() { return &renditionObj; }
345 GBool hasScreenAnnot() { return screenRef.isRef(); }
346 Ref getScreenAnnot() { return screenRef.getRef(); }
348 RenditionOperation getOperation() { return operation; }
350 MediaRendition* getMedia() { return media; }
352 GooString *getScript() { return js; }
354 private:
356 Object screenRef;
357 Object renditionObj;
358 RenditionOperation operation;
360 MediaRendition* media;
362 GooString *js;
365 //------------------------------------------------------------------------
366 // LinkSound
367 //------------------------------------------------------------------------
369 class LinkSound: public LinkAction {
370 public:
372 LinkSound(Object *soundObj);
374 virtual ~LinkSound();
376 virtual GBool isOk() { return sound != NULL; }
378 virtual LinkActionKind getKind() { return actionSound; }
380 double getVolume() { return volume; }
381 GBool getSynchronous() { return sync; }
382 GBool getRepeat() { return repeat; }
383 GBool getMix() { return mix; }
384 Sound *getSound() { return sound; }
386 private:
388 double volume;
389 GBool sync;
390 GBool repeat;
391 GBool mix;
392 Sound *sound;
395 //------------------------------------------------------------------------
396 // LinkJavaScript
397 //------------------------------------------------------------------------
399 class LinkJavaScript: public LinkAction {
400 public:
402 // Build a LinkJavaScript given the action name.
403 LinkJavaScript(Object *jsObj);
405 virtual ~LinkJavaScript();
407 virtual GBool isOk() { return js != NULL; }
409 virtual LinkActionKind getKind() { return actionJavaScript; }
410 GooString *getScript() { return js; }
412 private:
414 GooString *js;
417 //------------------------------------------------------------------------
418 // LinkOCGState
419 //------------------------------------------------------------------------
420 class LinkOCGState: public LinkAction {
421 public:
422 LinkOCGState(Object *obj);
424 virtual ~LinkOCGState();
426 virtual GBool isOk() { return stateList != NULL; }
428 virtual LinkActionKind getKind() { return actionOCGState; }
430 enum State { On, Off, Toggle};
431 struct StateList {
432 StateList() { list = NULL; }
433 ~StateList();
434 State st;
435 GooList *list;
438 GooList *getStateList() { return stateList; }
439 GBool getPreserveRB() { return preserveRB; }
441 private:
442 GooList *stateList;
443 GBool preserveRB;
446 //------------------------------------------------------------------------
447 // LinkUnknown
448 //------------------------------------------------------------------------
450 class LinkUnknown: public LinkAction {
451 public:
453 // Build a LinkUnknown with the specified action type.
454 LinkUnknown(char *actionA);
456 // Destructor.
457 virtual ~LinkUnknown();
459 // Was the LinkUnknown create successfully?
460 virtual GBool isOk() { return action != NULL; }
462 // Accessors.
463 virtual LinkActionKind getKind() { return actionUnknown; }
464 GooString *getAction() { return action; }
466 private:
468 GooString *action; // action subtype
471 //------------------------------------------------------------------------
472 // Links
473 //------------------------------------------------------------------------
475 class Links {
476 public:
478 // Extract links from array of annotations.
479 Links(Annots *annots);
481 // Destructor.
482 ~Links();
484 // Iterate through list of links.
485 int getNumLinks() const { return numLinks; }
486 AnnotLink *getLink(int i) const { return links[i]; }
488 // If point <x>,<y> is in a link, return the associated action;
489 // else return NULL.
490 LinkAction *find(double x, double y) const;
492 // Return true if <x>,<y> is in a link.
493 GBool onLink(double x, double y) const;
495 private:
497 AnnotLink **links;
498 int numLinks;
501 #endif