From 0d0acf9da76a9e3e1d5993c9d6bf870797d98676 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?I=C3=B1igo=20Mart=C3=ADnez?= <inigomartinez@gmail.com>
Date: Sun, 9 Dec 2007 19:20:55 +0100
Subject: [PATCH] AnnotMarkup support.
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Iñigo Martínez <inigomartinez@gmail.com>
---
 poppler/Annot.cc |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 poppler/Annot.h  |   51 ++++++++++++++++++++++++
 2 files changed, 166 insertions(+), 0 deletions(-)

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index b623baf..1c712c0 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -60,6 +60,27 @@
 // = (4 * (sqrt(2) - 1) / 3) * r
 #define bezierCircle 0.55228475
 
+AnnotExternalDataType parseAnnotExternalData(Dict* dict) {
+  Object obj1;
+  AnnotExternalDataType type;
+  
+  if (dict->lookup("Subtype", &obj1)->isName()) {
+    GooString *typeName = new GooString(obj1.getName());
+
+    if(!typeName->cmp("Markup3D")) {
+      type = annotExternalDataMarkup3D;
+    } else {
+      type = annotExternalDataMarkupUnknown;
+    }
+    delete typeName;
+  } else {
+    type = annotExternalDataMarkupUnknown;
+  }
+  obj1.free();
+  
+  return type;
+}
+
 //------------------------------------------------------------------------
 // AnnotBorder
 //------------------------------------------------------------------------
@@ -1718,6 +1739,100 @@ void AnnotPopup::initialize(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *ca
 }
 
 //------------------------------------------------------------------------
+// AnnotMarkup
+//------------------------------------------------------------------------
+ 
+AnnotMarkup::AnnotMarkup(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj) {
+  initialize(xrefA, acroForm, dict, catalog, obj);
+}
+
+AnnotMarkup::~AnnotMarkup() {
+  if (label)
+    delete label;
+
+  if (popup)
+    delete popup;
+
+  if (date)
+    delete date;
+
+  if (inReplyTo)
+    delete inReplyTo;
+
+  if (subject)
+    delete subject;
+}
+
+void AnnotMarkup::initialize(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj) {
+  Object obj1;
+
+  if (dict->lookup("T", &obj1)->isString()) {
+    label = obj1.getString()->copy();
+  } else {
+    label = NULL;
+  }
+  obj1.free();
+
+  if (dict->lookup("Popup", &obj1)->isDict()) {
+    popup = new AnnotPopup(xrefA, acroForm, obj1.getDict(), catalog, obj);
+  } else {
+    popup = NULL;
+  }
+  obj1.free();
+
+  if (dict->lookup("CA", &obj1)->isNum()) {
+    opacity = obj1.getNum();
+  } else {
+    opacity = 1.0;
+  }
+  obj1.free();
+
+  if (dict->lookup("CreationDate", &obj1)->isString()) {
+    date = obj1.getString()->copy();
+  } else {
+    date = NULL;
+  }
+  obj1.free();
+
+  if (dict->lookup("IRT", &obj1)->isDict()) {
+    inReplyTo = obj1.getDict();
+  } else {
+    inReplyTo = NULL;
+  }
+  obj1.free();
+
+  if (dict->lookup("Subj", &obj1)->isString()) {
+    subject = obj1.getString()->copy();
+  } else {
+    subject = NULL;
+  }
+  obj1.free();
+
+  if (dict->lookup("RT", &obj1)->isName()) {
+    GooString *replyName = new GooString(obj1.getName());
+
+    if(!replyName->cmp("R")) {
+      replyTo = replyTypeR;
+    } else if(!replyName->cmp("Group")) {
+      replyTo = replyTypeGroup;
+    } else {
+      replyTo = replyTypeR;
+    }
+    delete replyName;
+  } else {
+    replyTo = replyTypeR;
+  }
+  obj1.free();
+
+  if (dict->lookup("ExData", &obj1)->isDict()) {
+    exData = parseAnnotExternalData(obj1.getDict());
+  } else {
+    exData = annotExternalDataMarkupUnknown;
+  }
+  obj1.free();
+}
+
+//------------------------------------------------------------------------
 // Annots
 //------------------------------------------------------------------------
 
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 61c0c09..22d1cf3 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -22,6 +22,11 @@ class GfxFontDict;
 class FormWidget;
 class PDFRectangle;
 
+enum AnnotExternalDataType {
+  annotExternalDataMarkupUnknown,
+  annotExternalDataMarkup3D       // Markup3D
+};
+
 //------------------------------------------------------------------------
 // AnnotBorder
 //------------------------------------------------------------------------
@@ -307,6 +312,52 @@ protected:
 };
 
 //------------------------------------------------------------------------
+// AnnotMarkup
+//------------------------------------------------------------------------
+
+class AnnotMarkup {
+public:
+
+  enum  AnnotMarkupReplyType {
+    replyTypeR,     // R
+    replyTypeGroup  // Group
+  };
+  
+  AnnotMarkup(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj);
+  virtual ~AnnotMarkup();
+  
+  // getters
+  GooString *getLabel() { return label; }
+  AnnotPopup *getPopup() { return popup; }
+  double getOpacity() { return opacity; }
+  // getRC
+  GooString *getDate() { return date; }
+  Dict *getInReplyTo() { return inReplyTo; }
+  GooString *getSubject() { return subject; }
+  AnnotMarkupReplyType getReplyTo() { return replyTo; }
+  AnnotExternalDataType getExData() { return exData; }
+  
+protected:
+
+  GooString *label;             // T            (Default autor)
+  AnnotPopup *popup;            // Popup
+  double opacity;               // CA           (Default 1.0)
+  // RC
+  GooString *date;              // CreationDate
+  Dict *inReplyTo;              // IRT
+  GooString *subject;           // Subj
+  AnnotMarkupReplyType replyTo; // RT           (Default R)
+  // this object is overrided by the custom intent fields defined in some
+  // annotation types.
+  //GooString *intent;          // IT
+  AnnotExternalDataType exData; // ExData
+  
+private:
+
+  void initialize(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj);
+};
+
+//------------------------------------------------------------------------
 // Annots
 //------------------------------------------------------------------------
 
-- 
1.5.2.5

