Back to index

tetex-bin  3.0
Link.h
Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // Link.h
00004 //
00005 // Copyright 1996-2003 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #ifndef LINK_H
00010 #define LINK_H
00011 
00012 #include <aconf.h>
00013 
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017 
00018 #include "Object.h"
00019 
00020 class GString;
00021 class Array;
00022 class Dict;
00023 
00024 //------------------------------------------------------------------------
00025 // LinkAction
00026 //------------------------------------------------------------------------
00027 
00028 enum LinkActionKind {
00029   actionGoTo,               // go to destination
00030   actionGoToR,                     // go to destination in new file
00031   actionLaunch,                    // launch app (or open document)
00032   actionURI,                // URI
00033   actionNamed,                     // named action
00034   actionMovie,                     // movie action
00035   actionUnknown                    // anything else
00036 };
00037 
00038 class LinkAction {
00039 public:
00040 
00041   // Destructor.
00042   virtual ~LinkAction() {}
00043 
00044   // Was the LinkAction created successfully?
00045   virtual GBool isOk() = 0;
00046 
00047   // Check link action type.
00048   virtual LinkActionKind getKind() = 0;
00049 
00050   // Parse a destination (old-style action) name, string, or array.
00051   static LinkAction *parseDest(Object *obj);
00052 
00053   // Parse an action dictionary.
00054   static LinkAction *parseAction(Object *obj, GString *baseURI = NULL);
00055 
00056   // Extract a file name from a file specification (string or
00057   // dictionary).
00058   static GString *getFileSpecName(Object *fileSpecObj);
00059 };
00060 
00061 //------------------------------------------------------------------------
00062 // LinkDest
00063 //------------------------------------------------------------------------
00064 
00065 enum LinkDestKind {
00066   destXYZ,
00067   destFit,
00068   destFitH,
00069   destFitV,
00070   destFitR,
00071   destFitB,
00072   destFitBH,
00073   destFitBV
00074 };
00075 
00076 class LinkDest {
00077 public:
00078 
00079   // Build a LinkDest from the array.
00080   LinkDest(Array *a);
00081 
00082   // Copy a LinkDest.
00083   LinkDest *copy() { return new LinkDest(this); }
00084 
00085   // Was the LinkDest created successfully?
00086   GBool isOk() { return ok; }
00087 
00088   // Accessors.
00089   LinkDestKind getKind() { return kind; }
00090   GBool isPageRef() { return pageIsRef; }
00091   int getPageNum() { return pageNum; }
00092   Ref getPageRef() { return pageRef; }
00093   double getLeft() { return left; }
00094   double getBottom() { return bottom; }
00095   double getRight() { return right; }
00096   double getTop() { return top; }
00097   double getZoom() { return zoom; }
00098   GBool getChangeLeft() { return changeLeft; }
00099   GBool getChangeTop() { return changeTop; }
00100   GBool getChangeZoom() { return changeZoom; }
00101 
00102 private:
00103 
00104   LinkDestKind kind;        // destination type
00105   GBool pageIsRef;          // is the page a reference or number?
00106   union {
00107     Ref pageRef;            // reference to page
00108     int pageNum;            // one-relative page number
00109   };
00110   double left, bottom;             // position
00111   double right, top;
00112   double zoom;                     // zoom factor
00113   GBool changeLeft, changeTop;     // for destXYZ links, which position
00114   GBool changeZoom;         //   components to change
00115   GBool ok;                 // set if created successfully
00116 
00117   LinkDest(LinkDest *dest);
00118 };
00119 
00120 //------------------------------------------------------------------------
00121 // LinkGoTo
00122 //------------------------------------------------------------------------
00123 
00124 class LinkGoTo: public LinkAction {
00125 public:
00126 
00127   // Build a LinkGoTo from a destination (dictionary, name, or string).
00128   LinkGoTo(Object *destObj);
00129 
00130   // Destructor.
00131   virtual ~LinkGoTo();
00132 
00133   // Was the LinkGoTo created successfully?
00134   virtual GBool isOk() { return dest || namedDest; }
00135 
00136   // Accessors.
00137   virtual LinkActionKind getKind() { return actionGoTo; }
00138   LinkDest *getDest() { return dest; }
00139   GString *getNamedDest() { return namedDest; }
00140 
00141 private:
00142 
00143   LinkDest *dest;           // regular destination (NULL for remote
00144                             //   link with bad destination)
00145   GString *namedDest;              // named destination (only one of dest and
00146                             //   and namedDest may be non-NULL)
00147 };
00148 
00149 //------------------------------------------------------------------------
00150 // LinkGoToR
00151 //------------------------------------------------------------------------
00152 
00153 class LinkGoToR: public LinkAction {
00154 public:
00155 
00156   // Build a LinkGoToR from a file spec (dictionary) and destination
00157   // (dictionary, name, or string).
00158   LinkGoToR(Object *fileSpecObj, Object *destObj);
00159 
00160   // Destructor.
00161   virtual ~LinkGoToR();
00162 
00163   // Was the LinkGoToR created successfully?
00164   virtual GBool isOk() { return fileName && (dest || namedDest); }
00165 
00166   // Accessors.
00167   virtual LinkActionKind getKind() { return actionGoToR; }
00168   GString *getFileName() { return fileName; }
00169   LinkDest *getDest() { return dest; }
00170   GString *getNamedDest() { return namedDest; }
00171 
00172 private:
00173 
00174   GString *fileName;        // file name
00175   LinkDest *dest;           // regular destination (NULL for remote
00176                             //   link with bad destination)
00177   GString *namedDest;              // named destination (only one of dest and
00178                             //   and namedDest may be non-NULL)
00179 };
00180 
00181 //------------------------------------------------------------------------
00182 // LinkLaunch
00183 //------------------------------------------------------------------------
00184 
00185 class LinkLaunch: public LinkAction {
00186 public:
00187 
00188   // Build a LinkLaunch from an action dictionary.
00189   LinkLaunch(Object *actionObj);
00190 
00191   // Destructor.
00192   virtual ~LinkLaunch();
00193 
00194   // Was the LinkLaunch created successfully?
00195   virtual GBool isOk() { return fileName != NULL; }
00196 
00197   // Accessors.
00198   virtual LinkActionKind getKind() { return actionLaunch; }
00199   GString *getFileName() { return fileName; }
00200   GString *getParams() { return params; }
00201 
00202 private:
00203 
00204   GString *fileName;        // file name
00205   GString *params;          // parameters
00206 };
00207 
00208 //------------------------------------------------------------------------
00209 // LinkURI
00210 //------------------------------------------------------------------------
00211 
00212 class LinkURI: public LinkAction {
00213 public:
00214 
00215   // Build a LinkURI given the URI (string) and base URI.
00216   LinkURI(Object *uriObj, GString *baseURI);
00217 
00218   // Destructor.
00219   virtual ~LinkURI();
00220 
00221   // Was the LinkURI created successfully?
00222   virtual GBool isOk() { return uri != NULL; }
00223 
00224   // Accessors.
00225   virtual LinkActionKind getKind() { return actionURI; }
00226   GString *getURI() { return uri; }
00227 
00228 private:
00229 
00230   GString *uri;                    // the URI
00231 };
00232 
00233 //------------------------------------------------------------------------
00234 // LinkNamed
00235 //------------------------------------------------------------------------
00236 
00237 class LinkNamed: public LinkAction {
00238 public:
00239 
00240   // Build a LinkNamed given the action name.
00241   LinkNamed(Object *nameObj);
00242 
00243   virtual ~LinkNamed();
00244 
00245   virtual GBool isOk() { return name != NULL; }
00246 
00247   virtual LinkActionKind getKind() { return actionNamed; }
00248   GString *getName() { return name; }
00249 
00250 private:
00251 
00252   GString *name;
00253 };
00254 
00255 //------------------------------------------------------------------------
00256 // LinkMovie
00257 //------------------------------------------------------------------------
00258 
00259 class LinkMovie: public LinkAction {
00260 public:
00261 
00262   LinkMovie(Object *annotObj, Object *titleObj);
00263 
00264   virtual ~LinkMovie();
00265 
00266   virtual GBool isOk() { return annotRef.num >= 0 || title != NULL; }
00267 
00268   virtual LinkActionKind getKind() { return actionMovie; }
00269   GBool hasAnnotRef() { return annotRef.num >= 0; }
00270   Ref *getAnnotRef() { return &annotRef; }
00271   GString *getTitle() { return title; }
00272 
00273 private:
00274 
00275   Ref annotRef;
00276   GString *title;
00277 };
00278 
00279 //------------------------------------------------------------------------
00280 // LinkUnknown
00281 //------------------------------------------------------------------------
00282 
00283 class LinkUnknown: public LinkAction {
00284 public:
00285 
00286   // Build a LinkUnknown with the specified action type.
00287   LinkUnknown(char *actionA);
00288 
00289   // Destructor.
00290   virtual ~LinkUnknown();
00291 
00292   // Was the LinkUnknown create successfully?
00293   virtual GBool isOk() { return action != NULL; }
00294 
00295   // Accessors.
00296   virtual LinkActionKind getKind() { return actionUnknown; }
00297   GString *getAction() { return action; }
00298 
00299 private:
00300 
00301   GString *action;          // action subtype
00302 };
00303 
00304 //------------------------------------------------------------------------
00305 // LinkBorderStyle
00306 //------------------------------------------------------------------------
00307 
00308 enum LinkBorderType {
00309   linkBorderSolid,
00310   linkBorderDashed,
00311   linkBorderEmbossed,
00312   linkBorderEngraved,
00313   linkBorderUnderlined
00314 };
00315 
00316 class LinkBorderStyle {
00317 public:
00318 
00319   LinkBorderStyle(LinkBorderType typeA, double widthA,
00320                 double *dashA, int dashLengthA,
00321                 double rA, double gA, double bA);
00322   ~LinkBorderStyle();
00323 
00324   LinkBorderType getType() { return type; }
00325   double getWidth() { return width; }
00326   void getDash(double **dashA, int *dashLengthA)
00327     { *dashA = dash; *dashLengthA = dashLength; }
00328   void getColor(double *rA, double *gA, double *bA)
00329     { *rA = r; *gA = g; *bA = b; }
00330 
00331 private:
00332 
00333   LinkBorderType type;
00334   double width;
00335   double *dash;
00336   int dashLength;
00337   double r, g, b;
00338 };
00339 
00340 //------------------------------------------------------------------------
00341 // Link
00342 //------------------------------------------------------------------------
00343 
00344 class Link {
00345 public:
00346 
00347   // Construct a link, given its dictionary.
00348   Link(Dict *dict, GString *baseURI);
00349 
00350   // Destructor.
00351   ~Link();
00352 
00353   // Was the link created successfully?
00354   GBool isOk() { return ok; }
00355 
00356   // Check if point is inside the link rectangle.
00357   GBool inRect(double x, double y)
00358     { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
00359 
00360   // Get action.
00361   LinkAction *getAction() { return action; }
00362 
00363   // Get the link rectangle.
00364   void getRect(double *xa1, double *ya1, double *xa2, double *ya2)
00365     { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; }
00366 
00367   // Get the border style info.
00368   LinkBorderStyle *getBorderStyle() { return borderStyle; }
00369 
00370 private:
00371 
00372   double x1, y1;            // lower left corner
00373   double x2, y2;            // upper right corner
00374   LinkBorderStyle *borderStyle;    // border style
00375   LinkAction *action;              // action
00376   GBool ok;                 // is link valid?
00377 };
00378 
00379 //------------------------------------------------------------------------
00380 // Links
00381 //------------------------------------------------------------------------
00382 
00383 class Links {
00384 public:
00385 
00386   // Extract links from array of annotations.
00387   Links(Object *annots, GString *baseURI);
00388 
00389   // Destructor.
00390   ~Links();
00391 
00392   // Iterate through list of links.
00393   int getNumLinks() { return numLinks; }
00394   Link *getLink(int i) { return links[i]; }
00395 
00396   // If point <x>,<y> is in a link, return the associated action;
00397   // else return NULL.
00398   LinkAction *find(double x, double y);
00399 
00400   // Return true if <x>,<y> is in a link.
00401   GBool onLink(double x, double y);
00402 
00403 private:
00404 
00405   Link **links;
00406   int numLinks;
00407 };
00408 
00409 #endif