#ifndef LINK_H
#define LINK_H
#include <config.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include "Object.h"
class GString;
class Array;
class Dict;
enum LinkActionKind {
actionGoTo, actionGoToR, actionLaunch, actionURI, actionNamed, actionMovie, actionUnknown };
class LinkAction {
public:
virtual ~LinkAction() {}
virtual GBool isOk() = 0;
virtual LinkActionKind getKind() = 0;
static LinkAction *parseDest(Object *obj);
static LinkAction *parseAction(Object *obj, GString *baseURI = NULL);
static GString *getFileSpecName(Object *fileSpecObj);
};
enum LinkDestKind {
destXYZ,
destFit,
destFitH,
destFitV,
destFitR,
destFitB,
destFitBH,
destFitBV
};
class LinkDest {
public:
LinkDest(Array *a);
LinkDest *copy() { return new LinkDest(this); }
GBool isOk() { return ok; }
LinkDestKind getKind() { return kind; }
GBool isPageRef() { return pageIsRef; }
int getPageNum() { return pageNum; }
Ref getPageRef() { return pageRef; }
double getLeft() { return left; }
double getBottom() { return bottom; }
double getRight() { return right; }
double getTop() { return top; }
double getZoom() { return zoom; }
GBool getChangeLeft() { return changeLeft; }
GBool getChangeTop() { return changeTop; }
GBool getChangeZoom() { return changeZoom; }
private:
LinkDestKind kind; GBool pageIsRef; union {
Ref pageRef; int pageNum; };
double left, bottom; double right, top;
double zoom; GBool changeLeft, changeTop; GBool changeZoom; GBool ok;
LinkDest(LinkDest *dest);
};
class LinkGoTo: public LinkAction {
public:
LinkGoTo(Object *destObj);
virtual ~LinkGoTo();
virtual GBool isOk() { return dest || namedDest; }
virtual LinkActionKind getKind() { return actionGoTo; }
LinkDest *getDest() { return dest; }
GString *getNamedDest() { return namedDest; }
private:
LinkDest *dest; GString *namedDest; };
class LinkGoToR: public LinkAction {
public:
LinkGoToR(Object *fileSpecObj, Object *destObj);
virtual ~LinkGoToR();
virtual GBool isOk() { return fileName && (dest || namedDest); }
virtual LinkActionKind getKind() { return actionGoToR; }
GString *getFileName() { return fileName; }
LinkDest *getDest() { return dest; }
GString *getNamedDest() { return namedDest; }
private:
GString *fileName; LinkDest *dest; GString *namedDest; };
class LinkLaunch: public LinkAction {
public:
LinkLaunch(Object *actionObj);
virtual ~LinkLaunch();
virtual GBool isOk() { return fileName != NULL; }
virtual LinkActionKind getKind() { return actionLaunch; }
GString *getFileName() { return fileName; }
GString *getParams() { return params; }
private:
GString *fileName; GString *params; };
class LinkURI: public LinkAction {
public:
LinkURI(Object *uriObj, GString *baseURI);
virtual ~LinkURI();
virtual GBool isOk() { return uri != NULL; }
virtual LinkActionKind getKind() { return actionURI; }
GString *getURI() { return uri; }
private:
GString *uri; };
class LinkNamed: public LinkAction {
public:
LinkNamed(Object *nameObj);
virtual ~LinkNamed();
virtual GBool isOk() { return name != NULL; }
virtual LinkActionKind getKind() { return actionNamed; }
GString *getName() { return name; }
private:
GString *name;
};
class LinkMovie: public LinkAction {
public:
LinkMovie(Object *annotObj, Object *titleObj);
virtual ~LinkMovie();
virtual GBool isOk() { return annotRef.num >= 0 || title != NULL; }
virtual LinkActionKind getKind() { return actionMovie; }
GBool hasAnnotRef() { return annotRef.num >= 0; }
Ref *getAnnotRef() { return &annotRef; }
GString *getTitle() { return title; }
private:
Ref annotRef;
GString *title;
};
class LinkUnknown: public LinkAction {
public:
LinkUnknown(char *actionA);
virtual ~LinkUnknown();
virtual GBool isOk() { return action != NULL; }
virtual LinkActionKind getKind() { return actionUnknown; }
GString *getAction() { return action; }
private:
GString *action; };
enum LinkBorderType {
linkBorderSolid,
linkBorderDashed,
linkBorderEmbossed,
linkBorderEngraved,
linkBorderUnderlined
};
class LinkBorderStyle {
public:
LinkBorderStyle(LinkBorderType typeA, double widthA,
double *dashA, int dashLengthA,
double rA, double gA, double bA);
~LinkBorderStyle();
LinkBorderType getType() { return type; }
double getWidth() { return width; }
void getDash(double **dashA, int *dashLengthA)
{ *dashA = dash; *dashLengthA = dashLength; }
void getColor(double *rA, double *gA, double *bA)
{ *rA = r; *gA = g; *bA = b; }
private:
LinkBorderType type;
double width;
double *dash;
int dashLength;
double r, g, b;
};
class Link {
public:
Link(Dict *dict, GString *baseURI);
~Link();
GBool isOk() { return ok; }
GBool inRect(double x, double y)
{ return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
LinkAction *getAction() { return action; }
void getRect(double *xa1, double *ya1, double *xa2, double *ya2)
{ *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; }
LinkBorderStyle *getBorderStyle() { return borderStyle; }
private:
double x1, y1; double x2, y2; LinkBorderStyle *borderStyle; LinkAction *action; GBool ok; };
class Links {
public:
Links(Object *annots, GString *baseURI);
~Links();
int getNumLinks() { return numLinks; }
Link *getLink(int i) { return links[i]; }
LinkAction *find(double x, double y);
GBool onLink(double x, double y);
private:
Link **links;
int numLinks;
};
#endif