diff --git a/poppler/Annot.cc b/poppler/Annot.cc index e55ddde..c07b616 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -195,6 +195,40 @@ PDFRectangle *parseDiffRectangle(Array *array, PDFRectangle *rect) { return newRect; } +static LinkAction* getAdditionalAction(Annot::AdditionalActionsType type, Object *additionalActions, PDFDoc *doc) { + + Object additionalActionsObject; + + additionalActions->fetch(doc->getXRef(), &additionalActionsObject); + + if (!additionalActionsObject.isDict()) { + additionalActionsObject.free(); + return 0; + } + + Dict *dict = additionalActionsObject.getDict(); + + const char *key = (type == Annot::actionCursorEntering ? "E" : + type == Annot::actionCursorLeaving ? "X" : + type == Annot::actionMousePressed ? "D" : + type == Annot::actionMouseReleased ? "U" : + type == Annot::actionFocusIn ? "Fo" : + type == Annot::actionFocusOut ? "BI" : + type == Annot::actionPageOpening ? "PO" : + type == Annot::actionPageClosing ? "PC" : + type == Annot::actionPageVisible ? "PV" : + type == Annot::actionPageInvisible ? "PI" : 0); + + Object actionObject; + dict->lookup(key, &actionObject); + LinkAction *linkAction = LinkAction::parseAction(&actionObject, doc->getCatalog()->getBaseURI()); + actionObject.free(); + + additionalActionsObject.free(); + + return linkAction; +} + //------------------------------------------------------------------------ // AnnotBorderEffect //------------------------------------------------------------------------ @@ -3730,10 +3764,9 @@ AnnotWidget::~AnnotWidget() { if (action) delete action; - - if (additionActions) - delete additionActions; - + + additionalActions.free(); + if (parent) delete parent; } @@ -3773,12 +3806,7 @@ void AnnotWidget::initialize(PDFDoc *docA, Dict *dict) { } obj1.free(); - if(dict->lookup("AA", &obj1)->isDict()) { - additionActions = NULL; - } else { - additionActions = NULL; - } - obj1.free(); + dict->lookupNF("AA", &additionalActions); if(dict->lookup("Parent", &obj1)->isDict()) { parent = NULL; @@ -3788,6 +3816,11 @@ void AnnotWidget::initialize(PDFDoc *docA, Dict *dict) { obj1.free(); } +LinkAction* AnnotWidget::getAdditionalAction(AdditionalActionsType type) +{ + return ::getAdditionalAction(type, &additionalActions, doc); +} + // Grand unified handler for preparing text strings to be drawn into form // fields. Takes as input a text string (in PDFDocEncoding or UTF-16). // Converts some or all of this string to the appropriate encoding for the @@ -5103,7 +5136,7 @@ AnnotScreen::~AnnotScreen() { if (action) delete action; - additionAction.free(); + additionalActions.free(); } void AnnotScreen::initialize(PDFDoc *docA, Dict* dict) { @@ -5127,14 +5160,21 @@ void AnnotScreen::initialize(PDFDoc *docA, Dict* dict) { } obj1.free(); - dict->lookup("AA", &additionAction); + dict->lookupNF("AA", &additionalActions); appearCharacs = NULL; if(dict->lookup("MK", &obj1)->isDict()) { appearCharacs = new AnnotAppearanceCharacs(obj1.getDict()); } obj1.free(); +} + +LinkAction* AnnotScreen::getAdditionalAction(AdditionalActionsType type) +{ + if (type == actionFocusIn || type == actionFocusOut) // not defined for screen annotation + return 0; + return ::getAdditionalAction(type, &additionalActions, doc); } //------------------------------------------------------------------------ diff --git a/poppler/Annot.h b/poppler/Annot.h index 0d20cc7..876e70a 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -518,6 +518,22 @@ public: type3D // 3D 25 }; + /** + * Describes the additional actions of a screen or widget annotation. + */ + enum AdditionalActionsType { + actionCursorEntering, ///< Performed when the cursor enters the annotation's active area + actionCursorLeaving, ///< Performed when the cursor exists the annotation's active area + actionMousePressed, ///< Performed when the mouse button is pressed inside the annotation's active area + actionMouseReleased, ///< Performed when the mouse button is released inside the annotation's active area + actionFocusIn, ///< Performed when the annotation receives the input focus + actionFocusOut, ///< Performed when the annotation loses the input focus + actionPageOpening, ///< Performed when the page containing the annotation is opened + actionPageClosing, ///< Performed when the page containing the annotation is closed + actionPageVisible, ///< Performed when the page containing the annotation becomes visible + actionPageInvisible ///< Performed when the page containing the annotation becomes invisible + }; + Annot(PDFDoc *docA, PDFRectangle *rectA); Annot(PDFDoc *docA, Dict *dict); Annot(PDFDoc *docA, Dict *dict, Object *obj); @@ -805,7 +821,7 @@ class AnnotScreen: public Annot { AnnotAppearanceCharacs *getAppearCharacs() { return appearCharacs; } LinkAction* getAction() { return action; } - Object* getAdditionActions() { return &additionAction; } + LinkAction *getAdditionalAction(AdditionalActionsType type); private: void initialize(PDFDoc *docA, Dict *dict); @@ -816,7 +832,7 @@ class AnnotScreen: public Annot { AnnotAppearanceCharacs* appearCharacs; // MK LinkAction *action; // A - Object additionAction; // AA + Object additionalActions; // AA }; //------------------------------------------------------------------------ @@ -1278,7 +1294,7 @@ public: AnnotWidgetHighlightMode getMode() { return mode; } AnnotAppearanceCharacs *getAppearCharacs() { return appearCharacs; } LinkAction *getAction() { return action; } - Dict *getAdditionActions() { return additionActions; } + LinkAction *getAdditionalAction(AdditionalActionsType type); Dict *getParent() { return parent; } private: @@ -1297,7 +1313,7 @@ private: AnnotWidgetHighlightMode mode; // H (Default I) AnnotAppearanceCharacs *appearCharacs; // MK LinkAction *action; // A - Dict *additionActions; // AA + Object additionalActions; // AA // inherited from Annot // AnnotBorderBS border; // BS Dict *parent; // Parent