|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef LINK_H |
|
#define LINK_H |
|
|
|
#include "Object.h" |
|
#include "poppler_private_export.h" |
|
#include <memory> |
|
#include <optional> |
|
#include <set> |
|
|
|
class GooString; |
|
class Array; |
|
class Dict; |
|
class Sound; |
|
class MediaRendition; |
|
class AnnotLink; |
|
class Annots; |
|
|
|
|
|
|
|
|
|
|
|
enum LinkActionKind |
|
{ |
|
actionGoTo, |
|
actionGoToR, |
|
actionLaunch, |
|
actionURI, |
|
actionNamed, |
|
actionMovie, |
|
actionRendition, |
|
actionSound, |
|
actionJavaScript, |
|
actionOCGState, |
|
actionHide, |
|
actionResetForm, |
|
actionUnknown |
|
}; |
|
|
|
class POPPLER_PRIVATE_EXPORT LinkAction |
|
{ |
|
public: |
|
LinkAction(); |
|
LinkAction(const LinkAction &) = delete; |
|
LinkAction &operator=(const LinkAction &other) = delete; |
|
|
|
|
|
virtual ~LinkAction(); |
|
|
|
|
|
virtual bool isOk() const = 0; |
|
|
|
|
|
virtual LinkActionKind getKind() const = 0; |
|
|
|
|
|
static std::unique_ptr<LinkAction> parseDest(const Object *obj); |
|
|
|
|
|
static std::unique_ptr<LinkAction> parseAction(const Object *obj, const std::optional<std::string> &baseURI = {}); |
|
|
|
|
|
const std::vector<std::unique_ptr<LinkAction>> &nextActions() const; |
|
|
|
private: |
|
static std::unique_ptr<LinkAction> parseAction(const Object *obj, const std::optional<std::string> &baseURI, std::set<int> *seenNextActions); |
|
|
|
std::vector<std::unique_ptr<LinkAction>> nextActionList; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
enum LinkDestKind |
|
{ |
|
destXYZ, |
|
destFit, |
|
destFitH, |
|
destFitV, |
|
destFitR, |
|
destFitB, |
|
destFitBH, |
|
destFitBV |
|
}; |
|
|
|
class POPPLER_PRIVATE_EXPORT LinkDest |
|
{ |
|
public: |
|
|
|
explicit LinkDest(const Array *a); |
|
|
|
|
|
bool isOk() const { return ok; } |
|
|
|
|
|
LinkDestKind getKind() const { return kind; } |
|
bool isPageRef() const { return pageIsRef; } |
|
int getPageNum() const { return pageNum; } |
|
Ref getPageRef() const { return pageRef; } |
|
double getLeft() const { return left; } |
|
double getBottom() const { return bottom; } |
|
double getRight() const { return right; } |
|
double getTop() const { return top; } |
|
double getZoom() const { return zoom; } |
|
bool getChangeLeft() const { return changeLeft; } |
|
bool getChangeTop() const { return changeTop; } |
|
bool getChangeZoom() const { return changeZoom; } |
|
|
|
private: |
|
LinkDestKind kind; |
|
bool pageIsRef; |
|
union { |
|
Ref pageRef; |
|
int pageNum; |
|
}; |
|
double left, bottom; |
|
double right, top; |
|
double zoom; |
|
bool changeLeft, changeTop; |
|
bool changeZoom; |
|
|
|
|
|
bool ok; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class POPPLER_PRIVATE_EXPORT LinkGoTo : public LinkAction |
|
{ |
|
public: |
|
|
|
explicit LinkGoTo(const Object *destObj); |
|
|
|
~LinkGoTo() override; |
|
|
|
|
|
bool isOk() const override { return dest || namedDest; } |
|
|
|
|
|
LinkActionKind getKind() const override { return actionGoTo; } |
|
const LinkDest *getDest() const { return dest.get(); } |
|
const GooString *getNamedDest() const { return namedDest.get(); } |
|
|
|
private: |
|
std::unique_ptr<LinkDest> dest; |
|
|
|
std::unique_ptr<GooString> namedDest; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class LinkGoToR : public LinkAction |
|
{ |
|
public: |
|
|
|
|
|
LinkGoToR(Object *fileSpecObj, Object *destObj); |
|
|
|
~LinkGoToR() override; |
|
|
|
|
|
bool isOk() const override { return fileName && (dest || namedDest); } |
|
|
|
|
|
LinkActionKind getKind() const override { return actionGoToR; } |
|
const GooString *getFileName() const { return fileName.get(); } |
|
const LinkDest *getDest() const { return dest.get(); } |
|
const GooString *getNamedDest() const { return namedDest.get(); } |
|
|
|
private: |
|
std::unique_ptr<GooString> fileName; |
|
std::unique_ptr<LinkDest> dest; |
|
|
|
std::unique_ptr<GooString> namedDest; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class LinkLaunch : public LinkAction |
|
{ |
|
public: |
|
|
|
explicit LinkLaunch(const Object *actionObj); |
|
~LinkLaunch() override; |
|
|
|
|
|
bool isOk() const override { return fileName != nullptr; } |
|
|
|
|
|
LinkActionKind getKind() const override { return actionLaunch; } |
|
const GooString *getFileName() const { return fileName.get(); } |
|
const GooString *getParams() const { return params.get(); } |
|
|
|
private: |
|
std::unique_ptr<GooString> fileName; |
|
std::unique_ptr<GooString> params; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class POPPLER_PRIVATE_EXPORT LinkURI : public LinkAction |
|
{ |
|
public: |
|
|
|
LinkURI(const Object *uriObj, const std::optional<std::string> &baseURI); |
|
|
|
~LinkURI() override; |
|
|
|
|
|
bool isOk() const override { return hasURIFlag; } |
|
|
|
|
|
LinkActionKind getKind() const override { return actionURI; } |
|
const std::string &getURI() const { return uri; } |
|
|
|
private: |
|
std::string uri; |
|
bool hasURIFlag; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class LinkNamed : public LinkAction |
|
{ |
|
public: |
|
|
|
explicit LinkNamed(const Object *nameObj); |
|
|
|
~LinkNamed() override; |
|
|
|
bool isOk() const override { return hasNameFlag; } |
|
|
|
LinkActionKind getKind() const override { return actionNamed; } |
|
const std::string &getName() const { return name; } |
|
|
|
private: |
|
std::string name; |
|
bool hasNameFlag; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class LinkMovie : public LinkAction |
|
{ |
|
public: |
|
enum OperationType |
|
{ |
|
operationTypePlay, |
|
operationTypePause, |
|
operationTypeResume, |
|
operationTypeStop |
|
}; |
|
|
|
explicit LinkMovie(const Object *obj); |
|
|
|
~LinkMovie() override; |
|
|
|
bool isOk() const override { return hasAnnotRef() || hasAnnotTitleFlag; } |
|
LinkActionKind getKind() const override { return actionMovie; } |
|
|
|
|
|
|
|
|
|
bool hasAnnotRef() const { return annotRef != Ref::INVALID(); } |
|
bool hasAnnotTitle() const { return hasAnnotTitleFlag; } |
|
const Ref *getAnnotRef() const { return &annotRef; } |
|
const std::string &getAnnotTitle() const { return annotTitle; } |
|
|
|
OperationType getOperation() const { return operation; } |
|
|
|
private: |
|
Ref annotRef; |
|
std::string annotTitle; |
|
bool hasAnnotTitleFlag; |
|
|
|
OperationType operation; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class LinkRendition : public LinkAction |
|
{ |
|
public: |
|
|
|
|
|
|
|
enum RenditionOperation |
|
{ |
|
NoRendition, |
|
PlayRendition, |
|
StopRendition, |
|
PauseRendition, |
|
ResumeRendition |
|
}; |
|
|
|
explicit LinkRendition(const Object *Obj); |
|
|
|
~LinkRendition() override; |
|
|
|
bool isOk() const override { return true; } |
|
|
|
LinkActionKind getKind() const override { return actionRendition; } |
|
|
|
bool hasScreenAnnot() const { return screenRef != Ref::INVALID(); } |
|
Ref getScreenAnnot() const { return screenRef; } |
|
|
|
RenditionOperation getOperation() const { return operation; } |
|
|
|
const MediaRendition *getMedia() const { return media; } |
|
|
|
const std::string &getScript() const { return js; } |
|
|
|
private: |
|
Ref screenRef; |
|
RenditionOperation operation; |
|
|
|
MediaRendition *media; |
|
|
|
std::string js; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class LinkSound : public LinkAction |
|
{ |
|
public: |
|
explicit LinkSound(const Object *soundObj); |
|
|
|
~LinkSound() override; |
|
|
|
bool isOk() const override { return sound != nullptr; } |
|
|
|
LinkActionKind getKind() const override { return actionSound; } |
|
|
|
double getVolume() const { return volume; } |
|
bool getSynchronous() const { return sync; } |
|
bool getRepeat() const { return repeat; } |
|
bool getMix() const { return mix; } |
|
Sound *getSound() const { return sound.get(); } |
|
|
|
private: |
|
double volume; |
|
bool sync; |
|
bool repeat; |
|
bool mix; |
|
std::unique_ptr<Sound> sound; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class LinkJavaScript : public LinkAction |
|
{ |
|
public: |
|
|
|
explicit LinkJavaScript(Object *jsObj); |
|
|
|
~LinkJavaScript() override; |
|
|
|
bool isOk() const override { return isValid; } |
|
|
|
LinkActionKind getKind() const override { return actionJavaScript; } |
|
const std::string &getScript() const { return js; } |
|
|
|
static Object createObject(XRef *xref, const std::string &js); |
|
|
|
private: |
|
std::string js; |
|
bool isValid; |
|
}; |
|
|
|
|
|
|
|
|
|
class LinkOCGState : public LinkAction |
|
{ |
|
public: |
|
explicit LinkOCGState(const Object *obj); |
|
|
|
~LinkOCGState() override; |
|
|
|
bool isOk() const override { return isValid; } |
|
|
|
LinkActionKind getKind() const override { return actionOCGState; } |
|
|
|
enum State |
|
{ |
|
On, |
|
Off, |
|
Toggle |
|
}; |
|
struct StateList |
|
{ |
|
StateList() = default; |
|
~StateList() = default; |
|
State st; |
|
std::vector<Ref> list; |
|
}; |
|
|
|
const std::vector<StateList> &getStateList() const { return stateList; } |
|
bool getPreserveRB() const { return preserveRB; } |
|
|
|
private: |
|
std::vector<StateList> stateList; |
|
bool isValid; |
|
bool preserveRB; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class LinkHide : public LinkAction |
|
{ |
|
public: |
|
explicit LinkHide(const Object *hideObj); |
|
|
|
~LinkHide() override; |
|
|
|
bool isOk() const override { return hasTargetNameFlag; } |
|
LinkActionKind getKind() const override { return actionHide; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool hasTargetName() const { return hasTargetNameFlag; } |
|
const std::string &getTargetName() const { return targetName; } |
|
|
|
|
|
bool isShowAction() const { return show; } |
|
|
|
private: |
|
bool hasTargetNameFlag; |
|
std::string targetName; |
|
bool show; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class POPPLER_PRIVATE_EXPORT LinkResetForm : public LinkAction |
|
{ |
|
public: |
|
|
|
explicit LinkResetForm(const Object *nameObj); |
|
|
|
~LinkResetForm() override; |
|
|
|
bool isOk() const override { return true; } |
|
|
|
LinkActionKind getKind() const override { return actionResetForm; } |
|
|
|
const std::vector<std::string> &getFields() const { return fields; } |
|
bool getExclude() const { return exclude; } |
|
|
|
private: |
|
std::vector<std::string> fields; |
|
bool exclude; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class LinkUnknown : public LinkAction |
|
{ |
|
public: |
|
|
|
explicit LinkUnknown(const char *actionA); |
|
|
|
~LinkUnknown() override; |
|
|
|
|
|
|
|
bool isOk() const override { return true; } |
|
|
|
|
|
LinkActionKind getKind() const override { return actionUnknown; } |
|
const std::string &getAction() const { return action; } |
|
|
|
private: |
|
std::string action; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class POPPLER_PRIVATE_EXPORT Links |
|
{ |
|
public: |
|
|
|
explicit Links(Annots *annots); |
|
|
|
|
|
~Links(); |
|
|
|
Links(const Links &) = delete; |
|
Links &operator=(const Links &) = delete; |
|
|
|
const std::vector<AnnotLink *> &getLinks() const { return links; } |
|
|
|
private: |
|
std::vector<AnnotLink *> links; |
|
}; |
|
|
|
#endif |
|
|