[poppler] poppler/Annot.cc poppler/Annot.h

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Fri Aug 24 10:15:49 PDT 2012


 poppler/Annot.cc |   58 +++++++++++++++++++++++++++++++++++++++++++------------
 poppler/Annot.h  |   24 ++++++++++++++++++----
 2 files changed, 66 insertions(+), 16 deletions(-)

New commits:
commit 1881486e9817304d0817ce24b177c1bc79587138
Author: Tobias Koenig <tobias.koenig at kdab.com>
Date:   Fri Aug 24 19:12:20 2012 +0200

    annots: Unify parsing of additional actions entries
    
    https://bugs.freedesktop.org/show_bug.cgi?id=53586

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index e55ddde..8b5d630 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -195,6 +195,34 @@ PDFRectangle *parseDiffRectangle(Array *array, PDFRectangle *rect) {
   return newRect;
 }
 
+static LinkAction* getAdditionalAction(Annot::AdditionalActionsType type, Object *additionalActions, PDFDoc *doc) {
+  Object additionalActionsObject;
+  LinkAction *linkAction = NULL;
+
+  if (additionalActions->fetch(doc->getXRef(), &additionalActionsObject)->isDict()) {
+    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" : NULL);
+
+    Object actionObject;
+
+    if (additionalActionsObject.dictLookup(key, &actionObject)->isDict())
+      linkAction = LinkAction::parseAction(&actionObject, doc->getCatalog()->getBaseURI());
+    actionObject.free();
+  }
+
+  additionalActionsObject.free();
+
+  return linkAction;
+}
+
 //------------------------------------------------------------------------
 // AnnotBorderEffect
 //------------------------------------------------------------------------
@@ -3730,10 +3758,9 @@ AnnotWidget::~AnnotWidget() {
   
   if (action)
     delete action;
-    
-  if (additionActions)
-    delete additionActions;
-    
+
+  additionalActions.free();
+
   if (parent)
     delete parent;
 }
@@ -3773,12 +3800,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 +3810,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 +5130,7 @@ AnnotScreen::~AnnotScreen() {
   if (action)
     delete action;
 
-  additionAction.free();
+  additionalActions.free();
 }
 
 void AnnotScreen::initialize(PDFDoc *docA, Dict* dict) {
@@ -5127,14 +5154,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 NULL;
 
+  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


More information about the poppler mailing list