[poppler] 11 commits - poppler/Annot.cc poppler/Annot.h poppler/Catalog.cc poppler/Page.cc poppler/Page.h test/pdf-inspector.cc

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Tue Jun 16 07:37:07 PDT 2009


 poppler/Annot.cc      |  441 +++++++++++++++++++++++++++++++++++++++++++++++---
 poppler/Annot.h       |   47 ++++-
 poppler/Catalog.cc    |    2 
 poppler/Page.cc       |   34 +++
 poppler/Page.h        |    6 
 test/pdf-inspector.cc |   11 +
 6 files changed, 516 insertions(+), 25 deletions(-)

New commits:
commit d30b1013ea3ce45b5ea942fe7357c0fd07ff47f4
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Tue Jun 2 11:44:08 2009 +0200

    Add setOpen() and setIcon() in AnnotText

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index b8f9b18..b3dd9a1 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -1584,6 +1584,31 @@ void AnnotText::initialize(XRef *xrefA, Catalog *catalog, Dict *dict) {
   obj1.free();
 }
 
+void AnnotText::setOpen(GBool openA) {
+  Object obj1;
+
+  open = openA;
+  obj1.initBool(open);
+  update ("Open", &obj1);
+}
+
+void AnnotText::setIcon(GooString *new_icon) {
+  if (new_icon && icon->cmp(new_icon) == 0)
+    return;
+
+  delete icon;
+
+  if (new_icon) {
+    icon = new GooString (new_icon);
+  } else {
+    icon = new GooString("Note");
+  }
+
+  Object obj1;
+  obj1.initName (icon->getCString());
+  update("Name", &obj1);
+}
+
 //------------------------------------------------------------------------
 // AnnotLink
 //------------------------------------------------------------------------
diff --git a/poppler/Annot.h b/poppler/Annot.h
index ab45daf..b83c1db 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -675,6 +675,9 @@ public:
   GooString *getIcon() const { return icon; }
   AnnotTextState getState() const { return state; }
 
+  void setOpen(GBool openA);
+  void setIcon(GooString *new_icon);
+
 private:
 
   void initialize(XRef *xrefA, Catalog *catalog, Dict *dict);
commit 287feffc1c1c0aa42a398fc071b489acef9ef22e
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Tue Jun 2 11:26:40 2009 +0200

    Add setLabel() and setPopup() to AnnotMarkup

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 78b4f11..b8f9b18 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -1440,6 +1440,42 @@ void AnnotMarkup::initialize(XRef *xrefA, Dict *dict, Catalog *catalog, Object *
   obj1.free();
 }
 
+void AnnotMarkup::setLabel(GooString *new_label) {
+  delete label;
+
+  if (new_label) {
+    label = new GooString(new_label);
+    //append the unicode marker <FE FF> if needed
+    if (!label->hasUnicodeMarker()) {
+      label->insert(0, 0xff);
+      label->insert(0, 0xfe);
+    }
+  } else {
+    label = new GooString();
+  }
+
+  Object obj1;
+  obj1.initString(label->copy());
+  update ("T", &obj1);
+}
+
+void AnnotMarkup::setPopup(AnnotPopup *new_popup) {
+  delete popup;
+
+  if (new_popup) {
+    Object obj1;
+    Ref popupRef = new_popup->getRef();
+
+    obj1.initRef (popupRef.num, popupRef.gen);
+    update ("Popup", &obj1);
+
+    new_popup->setParent(this);
+    popup = new_popup;
+  } else {
+    popup = NULL;
+  }
+}
+
 //------------------------------------------------------------------------
 // AnnotText
 //------------------------------------------------------------------------
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 9c55aee..ab45daf 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -625,6 +625,10 @@ public:
   AnnotMarkupReplyType getReplyTo() const { return replyTo; }
   AnnotExternalDataType getExData() const { return exData; }
 
+  // The annotation takes the ownership of new_popup
+  void setPopup(AnnotPopup *new_popup);
+  void setLabel(GooString *new_label);
+
 protected:
   GooString *label;             // T            (Default autor)
   AnnotPopup *popup;            // Popup
commit 2a938af5624fbc79316dd6bee5e550f2b4270a76
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Tue Jun 2 10:59:44 2009 +0200

    Add setParent() and setOpen() to AnnotPopup

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index e2f4e3e..78b4f11 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -1324,6 +1324,25 @@ void AnnotPopup::initialize(XRef *xrefA, Dict *dict, Catalog *catalog) {
   obj1.free();
 }
 
+void AnnotPopup::setParent(Object *parentA) {
+  parentA->copy(&parent);
+  update ("Parent", &parent);
+}
+
+void AnnotPopup::setParent(Annot *parentA) {
+  Ref parentRef = parentA->getRef();
+  parent.initRef(parentRef.num, parentRef.gen);
+  update ("Parent", &parent);
+}
+
+void AnnotPopup::setOpen(GBool openA) {
+  Object obj1;
+
+  open = openA;
+  obj1.initBool(open);
+  update ("Open", &obj1);
+}
+
 //------------------------------------------------------------------------
 // AnnotMarkup
 //------------------------------------------------------------------------
diff --git a/poppler/Annot.h b/poppler/Annot.h
index f1b53cd..9c55aee 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -586,7 +586,11 @@ public:
   ~AnnotPopup();
 
   Object *getParent(Object *obj) { return parent.fetch (xref, obj); }
+  Object *getParentNF(Object *obj) { return &parent; }
+  void setParent(Object *parentA);
+  void setParent(Annot *parentA);
   GBool getOpen() const { return open; }
+  void setOpen(GBool openA);
 
 protected:
   void initialize(XRef *xrefA, Dict *dict, Catalog *catalog);
commit 0af5464352dfa51f0458c57a3590c847a45964c7
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Tue Jun 2 10:37:49 2009 +0200

    Save parent reference of popup annotations

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 0f0267b..e2f4e3e 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -1306,22 +1306,16 @@ AnnotPopup::AnnotPopup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
 }
 
 AnnotPopup::~AnnotPopup() {
-  /*
-  if (parent)
-    delete parent;
-  */
+  parent.free();
 }
 
 void AnnotPopup::initialize(XRef *xrefA, Dict *dict, Catalog *catalog) {
   Object obj1;
-  /*
-  if (dict->lookup("Parent", &obj1)->isDict()) {
-    parent = NULL;
-  } else {
-    parent = NULL;
+
+  if (!dict->lookupNF("Parent", &parent)->isRef()) {
+    parent.initNull();
   }
-  obj1.free();
-  */
+
   if (dict->lookup("Open", &obj1)->isBool()) {
     open = obj1.getBool();
   } else {
diff --git a/poppler/Annot.h b/poppler/Annot.h
index b4d8794..f1b53cd 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -585,13 +585,13 @@ public:
   AnnotPopup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotPopup();
 
-  Dict *getParent() const { return parent; }
+  Object *getParent(Object *obj) { return parent.fetch (xref, obj); }
   GBool getOpen() const { return open; }
 
 protected:
   void initialize(XRef *xrefA, Dict *dict, Catalog *catalog);
 
-  Dict *parent; // Parent
+  Object parent; // Parent
   GBool open;   // Open
 };
 
commit fc4bc43dcd6f6871a47b9198e8c2571a5d448c3e
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Mon Jun 1 14:52:21 2009 +0200

    Fix a crash in pdf-inspector

diff --git a/test/pdf-inspector.cc b/test/pdf-inspector.cc
index aba4a71..ce09757 100644
--- a/test/pdf-inspector.cc
+++ b/test/pdf-inspector.cc
@@ -214,6 +214,8 @@ PdfInspector::analyze_page (int page)
   void *p;
   GtkWidget *label;
   char *text;
+  cairo_t *cr;
+  cairo_surface_t *surface;
 
   label = glade_xml_get_widget (xml, "pdf_total_label");
 
@@ -221,7 +223,15 @@ PdfInspector::analyze_page (int page)
   gtk_list_store_clear (GTK_LIST_STORE (model));
 
   GooTimer timer;
+  surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
+					doc->getPageCropWidth(page + 1),
+					doc->getPageCropHeight(page + 1));
+  cr = cairo_create (surface);
+  cairo_surface_destroy (surface);
+  output->setCairo (cr);
+  cairo_destroy (cr);
   doc->displayPage (output, page + 1, 72, 72, 0, gFalse, gTrue, gTrue);
+  output->setCairo (NULL);
 
   // Total time;
   text = g_strdup_printf ("%g", timer.getElapsed ());
@@ -331,6 +341,7 @@ main (int argc, char *argv [])
   
   globalParams = new GlobalParams();
   globalParams->setProfileCommands (true);
+  globalParams->setPrintCommands (true);
 
   if (argc == 2)
     file_name = argv[1];
commit 3da7a2657892fde52b62e1f73476cb33d6c75e96
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Fri May 29 13:35:39 2009 +0200

    Add Annot::setColor()

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 3d6f250..0f0267b 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -1070,7 +1070,24 @@ void Annot::setContents(GooString *new_content) {
   obj1.initString(contents->copy());
   update ("Contents", &obj1);
 }
-	
+
+void Annot::setColor(AnnotColor *new_color) {
+  delete color;
+
+  if (new_color) {
+    Object obj1, obj2;
+    double *values = new_color->getValues();
+
+    obj1.initArray(xref);
+    for (int i = 0; i < (int)new_color->getSpace(); i++)
+      obj1.arrayAdd(obj2.initReal (values[i]));
+    update ("C", &obj1);
+    color = new_color;
+  } else {
+    color = NULL;
+  }
+}
+
 double Annot::getXMin() {
   return rect->x1;
 }
diff --git a/poppler/Annot.h b/poppler/Annot.h
index cd73068..b4d8794 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -504,7 +504,11 @@ public:
   // Sets the annot contents to new_content
   // new_content should never be NULL
   void setContents(GooString *new_content);
-  
+
+  // The annotation takes the ownership of
+  // new_color. 
+  void setColor(AnnotColor *new_color);
+
   // getters
   Ref getRef() const { return ref; }
   AnnotSubtype getType() const { return type; }
commit 3eabdf57729852205855cf74ff2d2f9d7bc03f73
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Fri May 29 13:23:26 2009 +0200

    Add construtors to create AnnotColor objects directly from color values

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 18eff1a..3d6f250 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -613,6 +613,32 @@ AnnotColor::AnnotColor() {
   values = NULL;
 }
 
+AnnotColor::AnnotColor(double gray) {
+  length = 1;
+  values = (double *) gmallocn (length, sizeof(double));
+
+  values[0] = gray;
+}
+
+AnnotColor::AnnotColor(double r, double g, double b) {
+  length = 3;
+  values = (double *) gmallocn (length, sizeof(double));
+
+  values[0] = r;
+  values[1] = g;
+  values[2] = b;
+}
+
+AnnotColor::AnnotColor(double c, double m, double y, double k) {
+  length = 4;
+  values = (double *) gmallocn (length, sizeof(double));
+
+  values[0] = c;
+  values[1] = m;
+  values[2] = y;
+  values[3] = k;
+}
+
 AnnotColor::AnnotColor(Array *array) {
   // TODO: check what Acrobat does in the case of having more than 5 numbers.
   if (array->getLength() < 5) {
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 5a845ae..cd73068 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -287,6 +287,9 @@ public:
   };
 
   AnnotColor();
+  AnnotColor(double gray);
+  AnnotColor(double r, double g, double b);
+  AnnotColor(double c, double m, double y, double k);
   AnnotColor(Array *array);
   ~AnnotColor();
 
commit 8045e7a1a84a3d54a1c9415ac63b5b9df5ecc349
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Fri May 29 13:06:40 2009 +0200

    Add Page::addAnnot() to add a new annotation to the page

diff --git a/poppler/Page.cc b/poppler/Page.cc
index 67d93e0..3bbfdde 100644
--- a/poppler/Page.cc
+++ b/poppler/Page.cc
@@ -354,6 +354,34 @@ Annots *Page::getAnnots(Catalog *catalog) {
   return annots;
 }
 
+void Page::addAnnot(Annot *annot) {
+  Object obj1;
+  Object tmp;
+  Ref annotRef = annot->getRef ();
+
+  if (annots.isNull()) {
+    Ref annotsRef;
+    // page doesn't have annots array,
+    // we have to create it
+
+    obj1.initArray(xref);
+    obj1.arrayAdd(tmp.initRef (annotRef.num, annotRef.gen));
+    tmp.free();
+
+    annotsRef = xref->addIndirectObject (&obj1);
+    annots.initRef(annotsRef.num, annotsRef.gen);
+    pageObj.dictSet ("Annots", &annots);
+    xref->setModifiedObject (&pageObj, pageRef);
+  } else {
+    getAnnots(&obj1);
+    if (obj1.isArray()) {
+      obj1.arrayAdd (tmp.initRef (annotRef.num, annotRef.gen));
+      xref->setModifiedObject (&obj1, annots.getRef());
+    }
+    obj1.free();
+  }
+}
+
 Links *Page::getLinks(Catalog *catalog) {
   Links *links;
   Object obj;
diff --git a/poppler/Page.h b/poppler/Page.h
index 103a544..9d892b1 100644
--- a/poppler/Page.h
+++ b/poppler/Page.h
@@ -163,6 +163,8 @@ public:
 
   // Get annotations array.
   Object *getAnnots(Object *obj) { return annots.fetch(xref, obj); }
+  // Add a new annotation to the page
+  void addAnnot(Annot *annot);
 
   // Return a list of links.
   Links *getLinks(Catalog *catalog);
commit fe80eb84ec711b7400cef95e791a74c8fd259af7
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Fri May 29 13:00:19 2009 +0200

    Add getRef() to get the annotation reference

diff --git a/poppler/Annot.h b/poppler/Annot.h
index 52f1940..5a845ae 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -503,6 +503,7 @@ public:
   void setContents(GooString *new_content);
   
   // getters
+  Ref getRef() const { return ref; }
   AnnotSubtype getType() const { return type; }
   PDFRectangle *getRect() const { return rect; }
   GooString *getContents() const { return contents; }
commit 1c92657be72c44dba7185808ffb00dd85c5ab289
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Fri May 29 12:14:02 2009 +0200

    Save page object and ref in Page class
    
    This is needed to be able to modify the page object.

diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc
index a48639f..9a18e24 100644
--- a/poppler/Catalog.cc
+++ b/poppler/Catalog.cc
@@ -309,7 +309,7 @@ int Catalog::readPageTree(Dict *pagesDict, PageAttrs *attrs, int start,
     kids.arrayGet(i, &kid);
     if (kid.isDict("Page")) {
       attrs2 = new PageAttrs(attrs1, kid.getDict());
-      page = new Page(xref, start+1, kid.getDict(), attrs2, form);
+      page = new Page(xref, start+1, kid.getDict(), kidRef.getRef(), attrs2, form);
       if (!page->isOk()) {
 	++start;
 	goto err3;
diff --git a/poppler/Page.cc b/poppler/Page.cc
index 40cb6d9..67d93e0 100644
--- a/poppler/Page.cc
+++ b/poppler/Page.cc
@@ -252,7 +252,7 @@ GBool PageAttrs::readBox(Dict *dict, char *key, PDFRectangle *box) {
 // Page
 //------------------------------------------------------------------------
 
-Page::Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA, Form *form) {
+Page::Page(XRef *xrefA, int numA, Dict *pageDict, Ref pageRefA, PageAttrs *attrsA, Form *form) {
   Object tmp;
 	
   ok = gTrue;
@@ -261,6 +261,9 @@ Page::Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA, Form *form)
   duration = -1;
   pageWidgets = NULL;
 
+  pageObj.initDict(pageDict);
+  pageRef = pageRefA;
+
   // get attributes
   attrs = attrsA;
 
@@ -334,6 +337,7 @@ Page::Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA, Form *form)
 Page::~Page() {
   delete pageWidgets;
   delete attrs;
+  pageObj.free();
   annots.free();
   contents.free();
   trans.free();
diff --git a/poppler/Page.h b/poppler/Page.h
index 6116083..103a544 100644
--- a/poppler/Page.h
+++ b/poppler/Page.h
@@ -126,7 +126,7 @@ class Page {
 public:
 
   // Constructor.
-  Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA, Form *form);
+  Page(XRef *xrefA, int numA, Dict *pageDict, Ref pageRefA, PageAttrs *attrsA, Form *form);
 
   // Destructor.
   ~Page();
@@ -235,6 +235,8 @@ public:
 private:
 
   XRef *xref;			// the xref table for this PDF file
+  Object pageObj;               // page dictionary
+  Ref pageRef;                  // page reference
   int num;			// page number
   PageAttrs *attrs;		// page attributes
   Object annots;		// annotations array
commit 4ad2d663262008e4b97342c4ed67c686ff5abd13
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Fri May 29 11:43:30 2009 +0200

    Add annot constructors to create annot objects without a dict
    
    This allows to create annotation objects to be added to the document.
    Required fields on the annotation dictionary are constructor arguments,
    setters will be added for the other fields.

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 8654f70..18eff1a 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -37,6 +37,7 @@
 
 #include <stdlib.h>
 #include <math.h>
+#include <assert.h>
 #include "goo/gmem.h"
 #include "GooList.h"
 #include "Error.h"
@@ -814,10 +815,35 @@ AnnotAppearanceCharacs::~AnnotAppearanceCharacs() {
 // Annot
 //------------------------------------------------------------------------
 
+Annot::Annot(XRef *xrefA, PDFRectangle *rectA, Catalog *catalog) {
+  Object obj1;
+
+  flags = flagUnknown;
+  type = typeUnknown;
+
+  obj1.initArray (xrefA);
+  Object obj2;
+  obj1.arrayAdd (obj2.initReal (rectA->x1));
+  obj1.arrayAdd (obj2.initReal (rectA->y1));
+  obj1.arrayAdd (obj2.initReal (rectA->x2));
+  obj1.arrayAdd (obj2.initReal (rectA->y2));
+  obj2.free ();
+
+  annotObj.initDict (xrefA);
+  annotObj.dictSet ("Type", obj2.initName ("Annot"));
+  annotObj.dictSet ("Rect", &obj1);
+  // obj1 is owned by the dict
+
+  ref = xrefA->addIndirectObject (&annotObj);
+
+  initialize (xrefA, annotObj.getDict(), catalog);
+}
+
 Annot::Annot(XRef *xrefA, Dict *dict, Catalog* catalog) {
   hasRef = false;
   flags = flagUnknown;
   type = typeUnknown;
+  annotObj.initDict (dict);
   initialize (xrefA, dict, catalog);
 }
 
@@ -830,6 +856,7 @@ Annot::Annot(XRef *xrefA, Dict *dict, Catalog* catalog, Object *obj) {
   }
   flags = flagUnknown;
   type = typeUnknown;
+  annotObj.initDict (dict);
   initialize (xrefA, dict, catalog);
 }
 
@@ -842,7 +869,6 @@ void Annot::initialize(XRef *xrefA, Dict *dict, Catalog *catalog) {
   xref = xrefA;
   appearBuf = NULL;
   fontSize = 0;
-  annotObj.initDict (dict);
 
   //----- parse the rectangle
   rect = new PDFRectangle();
@@ -1220,6 +1246,16 @@ void Annot::draw(Gfx *gfx, GBool printing) {
 // AnnotPopup
 //------------------------------------------------------------------------
 
+AnnotPopup::AnnotPopup(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+    Annot(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typePopup;
+
+  annotObj.dictSet ("Subtype", obj1.initName ("Popup"));
+  initialize (xrefA, annotObj.getDict(), catalog);
+}
+
 AnnotPopup::AnnotPopup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
     Annot(xrefA, dict, catalog, obj) {
   type = typePopup;
@@ -1254,7 +1290,11 @@ void AnnotPopup::initialize(XRef *xrefA, Dict *dict, Catalog *catalog) {
 //------------------------------------------------------------------------
 // AnnotMarkup
 //------------------------------------------------------------------------
- 
+AnnotMarkup::AnnotMarkup(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+    Annot(xrefA, rect, catalog) {
+  initialize(xrefA, annotObj.getDict(), catalog, &annotObj);
+}
+
 AnnotMarkup::AnnotMarkup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
     Annot(xrefA, dict, catalog, obj) {
   initialize(xrefA, dict, catalog, obj);
@@ -1348,6 +1388,17 @@ void AnnotMarkup::initialize(XRef *xrefA, Dict *dict, Catalog *catalog, Object *
 // AnnotText
 //------------------------------------------------------------------------
 
+AnnotText::AnnotText(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeText;
+  flags |= flagNoZoom | flagNoRotate;
+
+  annotObj.dictSet ("Subtype", obj1.initName ("Text"));
+  initialize (xrefA, catalog, annotObj.getDict());
+}
+
 AnnotText::AnnotText(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
     AnnotMarkup(xrefA, dict, catalog, obj) {
 
@@ -1444,6 +1495,14 @@ void AnnotText::initialize(XRef *xrefA, Catalog *catalog, Dict *dict) {
 //------------------------------------------------------------------------
 // AnnotLink
 //------------------------------------------------------------------------
+AnnotLink::AnnotLink(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+    Annot(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeLink;
+  annotObj.dictSet ("Subtype", obj1.initName ("Link"));
+  initialize (xrefA, catalog, annotObj.getDict());
+}
 
 AnnotLink::AnnotLink(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
     Annot(xrefA, dict, catalog, obj) {
@@ -1532,6 +1591,20 @@ void AnnotLink::draw(Gfx *gfx, GBool printing) {
 //------------------------------------------------------------------------
 // AnnotFreeText
 //------------------------------------------------------------------------
+AnnotFreeText::AnnotFreeText(XRef *xrefA, PDFRectangle *rect, GooString *da, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeFreeText;
+
+  annotObj.dictSet ("Subtype", obj1.initName ("FreeText"));
+
+  Object obj2;
+  obj2.initString (da->copy());
+  annotObj.dictSet("DA", &obj2);
+
+  initialize (xrefA, catalog, annotObj.getDict());
+}
 
 AnnotFreeText::AnnotFreeText(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
     AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -1655,6 +1728,24 @@ void AnnotFreeText::initialize(XRef *xrefA, Catalog *catalog, Dict *dict) {
 // AnnotLine
 //------------------------------------------------------------------------
 
+AnnotLine::AnnotLine(XRef *xrefA, PDFRectangle *rect, PDFRectangle *lRect, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeLine;
+  annotObj.dictSet ("Subtype", obj1.initName ("Line"));
+
+  Object obj2, obj3;
+  obj2.initArray (xrefA);
+  obj2.arrayAdd (obj3.initReal (lRect->x1));
+  obj2.arrayAdd (obj3.initReal (lRect->y1));
+  obj2.arrayAdd (obj3.initReal (lRect->x2));
+  obj2.arrayAdd (obj3.initReal (lRect->y2));
+  annotObj.dictSet ("L", &obj2);
+
+  initialize (xrefA, catalog, annotObj.getDict());
+}
+
 AnnotLine::AnnotLine(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
     AnnotMarkup(xrefA, dict, catalog, obj) {
   type = typeLine;
@@ -1814,6 +1905,48 @@ void AnnotLine::initialize(XRef *xrefA, Catalog *catalog, Dict *dict) {
 //------------------------------------------------------------------------
 // AnnotTextMarkup
 //------------------------------------------------------------------------
+AnnotTextMarkup::AnnotTextMarkup(XRef *xrefA, PDFRectangle *rect, AnnotSubtype subType,
+				 AnnotQuadrilaterals *quadPoints, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  switch (subType) {
+    case typeHighlight:
+      annotObj.dictSet ("Subtype", obj1.initName ("Highlight"));
+      break;
+    case typeUnderline:
+      annotObj.dictSet ("Subtype", obj1.initName ("Underline"));
+      break;
+    case typeSquiggly:
+      annotObj.dictSet ("Subtype", obj1.initName ("Squiggly"));
+      break;
+    case typeStrikeOut:
+      annotObj.dictSet ("Subtype", obj1.initName ("StrikeOut"));
+      break;
+    default:
+      assert (0 && "Invalid subtype for AnnotTextMarkup\n");
+  }
+
+  Object obj2;
+  obj2.initArray (xrefA);
+
+  for (int i = 0; i < quadPoints->getQuadrilateralsLength(); ++i) {
+    Object obj3;
+
+    obj2.arrayAdd (obj3.initReal (quadPoints->getX1(i)));
+    obj2.arrayAdd (obj3.initReal (quadPoints->getY1(i)));
+    obj2.arrayAdd (obj3.initReal (quadPoints->getX2(i)));
+    obj2.arrayAdd (obj3.initReal (quadPoints->getY2(i)));
+    obj2.arrayAdd (obj3.initReal (quadPoints->getX3(i)));
+    obj2.arrayAdd (obj3.initReal (quadPoints->getY3(i)));
+    obj2.arrayAdd (obj3.initReal (quadPoints->getX4(i)));
+    obj2.arrayAdd (obj3.initReal (quadPoints->getY4(i)));
+  }
+
+  annotObj.dictSet ("QuadPoints", &obj2);
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 AnnotTextMarkup::AnnotTextMarkup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -3208,7 +3341,19 @@ void AnnotWidget::draw(Gfx *gfx, GBool printing) {
 //------------------------------------------------------------------------
 // AnnotMovie
 //------------------------------------------------------------------------
- 
+AnnotMovie::AnnotMovie(XRef *xrefA, PDFRectangle *rect, Movie *movieA, Catalog *catalog) :
+    Annot(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeMovie;
+  annotObj.dictSet ("Subtype", obj1.initName ("Movie"));
+
+  movie = movieA->copy();
+  // TODO: create movie dict from movieA
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
+
 AnnotMovie::AnnotMovie(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   Annot(xrefA, dict, catalog, obj) {
   type = typeMovie;
@@ -3473,7 +3618,16 @@ void AnnotMovie::getZoomFactor(int& num, int& denum) {
 //------------------------------------------------------------------------
 // AnnotScreen
 //------------------------------------------------------------------------
- 
+AnnotScreen::AnnotScreen(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+    Annot(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeScreen;
+
+  annotObj.dictSet ("Subtype", obj1.initName ("Screen"));
+  initialize(xrefA, catalog, annotObj.getDict());
+}
+
 AnnotScreen::AnnotScreen(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   Annot(xrefA, dict, catalog, obj) {
   type = typeScreen;
@@ -3514,7 +3668,15 @@ void AnnotScreen::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
 //------------------------------------------------------------------------
 // AnnotStamp
 //------------------------------------------------------------------------
- 
+AnnotStamp::AnnotStamp(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+  AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeStamp;
+  annotObj.dictSet ("Subtype", obj1.initName ("Stamp"));
+  initialize(xrefA, catalog, annotObj.getDict());
+}
+
 AnnotStamp::AnnotStamp(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
   type = typeStamp;
@@ -3540,6 +3702,23 @@ void AnnotStamp::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
 //------------------------------------------------------------------------
 // AnnotGeometry
 //------------------------------------------------------------------------
+AnnotGeometry::AnnotGeometry(XRef *xrefA, PDFRectangle *rect, AnnotSubtype subType, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  switch (subType) {
+    case typeSquare:
+      annotObj.dictSet ("Subtype", obj1.initName ("Square"));
+      break;
+    case typeCircle:
+      annotObj.dictSet ("Subtype", obj1.initName ("Circle"));
+      break;
+    default:
+      assert (0 && "Invalid subtype for AnnotGeometry\n");
+  }
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 AnnotGeometry::AnnotGeometry(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -3592,6 +3771,36 @@ void AnnotGeometry::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
 //------------------------------------------------------------------------
 // AnnotPolygon
 //------------------------------------------------------------------------
+AnnotPolygon::AnnotPolygon(XRef *xrefA, PDFRectangle *rect, AnnotSubtype subType,
+			   AnnotPath *path, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  switch (subType) {
+    case typePolygon:
+      annotObj.dictSet ("Subtype", obj1.initName ("Polygon"));
+      break;
+    case typePolyLine:
+      annotObj.dictSet ("Subtype", obj1.initName ("PolyLine"));
+      break;
+    default:
+      assert (0 && "Invalid subtype for AnnotGeometry\n");
+  }
+
+  Object obj2;
+  obj2.initArray (xrefA);
+
+  for (int i = 0; i < path->getCoordsLength(); ++i) {
+    Object obj3;
+
+    obj2.arrayAdd (obj3.initReal (path->getX(i)));
+    obj2.arrayAdd (obj3.initReal (path->getY(i)));
+  }
+
+  annotObj.dictSet ("Vertices", &obj2);
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 AnnotPolygon::AnnotPolygon(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -3686,6 +3895,15 @@ void AnnotPolygon::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
 //------------------------------------------------------------------------
 // AnnotCaret
 //------------------------------------------------------------------------
+AnnotCaret::AnnotCaret(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeCaret;
+
+  annotObj.dictSet ("Subtype", obj1.initName ("Caret"));
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 AnnotCaret::AnnotCaret(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -3723,6 +3941,36 @@ void AnnotCaret::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
 //------------------------------------------------------------------------
 // AnnotInk
 //------------------------------------------------------------------------
+AnnotInk::AnnotInk(XRef *xrefA, PDFRectangle *rect, AnnotPath **paths, int n_paths, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeInk;
+
+  annotObj.dictSet ("Subtype", obj1.initName ("Ink"));
+
+  Object obj2;
+  obj2.initArray (xrefA);
+
+  for (int i = 0; i < n_paths; ++i) {
+    AnnotPath *path = paths[i];
+    Object obj3;
+    obj3.initArray (xrefA);
+
+    for (int j = 0; j < path->getCoordsLength(); ++j) {
+      Object obj4;
+
+      obj3.arrayAdd (obj4.initReal (path->getX(j)));
+      obj3.arrayAdd (obj4.initReal (path->getY(j)));
+    }
+
+    obj2.arrayAdd (&obj3);
+  }
+
+  annotObj.dictSet ("InkList", &obj2);
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 AnnotInk::AnnotInk(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -3764,6 +4012,20 @@ void AnnotInk::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
 //------------------------------------------------------------------------
 // AnnotFileAttachment
 //------------------------------------------------------------------------
+AnnotFileAttachment::AnnotFileAttachment(XRef *xrefA, PDFRectangle *rect, GooString *filename, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeFileAttachment;
+
+  annotObj.dictSet ("Subtype", obj1.initName ("FileAttachment"));
+
+  Object obj2;
+  obj2.initString(filename->copy());
+  annotObj.dictSet ("FS", &obj2);
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 AnnotFileAttachment::AnnotFileAttachment(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -3781,7 +4043,7 @@ AnnotFileAttachment::~AnnotFileAttachment() {
 void AnnotFileAttachment::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
   Object obj1;
 
-  if (dict->lookup("FS", &obj1)->isDict()) {
+  if (dict->lookup("FS", &obj1)->isDict() || dict->lookup("FS", &obj1)->isString()) {
     obj1.copy(&file);
   } else {
     error(-1, "Bad Annot File Attachment");
@@ -3800,6 +4062,22 @@ void AnnotFileAttachment::initialize(XRef *xrefA, Catalog *catalog, Dict* dict)
 //------------------------------------------------------------------------
 // AnnotSound
 //------------------------------------------------------------------------
+AnnotSound::AnnotSound(XRef *xrefA, PDFRectangle *rect, Sound *soundA, Catalog *catalog) :
+    AnnotMarkup(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = typeSound;
+
+  annotObj.dictSet ("Subtype", obj1.initName ("Sound"));
+
+  Object obj2;
+  Stream *str = soundA->getStream();
+  obj2.initStream (str);
+  str->incRef(); //FIXME: initStream should do this?
+  annotObj.dictSet ("Sound", &obj2);
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 AnnotSound::AnnotSound(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   AnnotMarkup(xrefA, dict, catalog, obj) {
@@ -3834,6 +4112,16 @@ void AnnotSound::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
 //------------------------------------------------------------------------
 // Annot3D
 //------------------------------------------------------------------------
+Annot3D::Annot3D(XRef *xrefA, PDFRectangle *rect, Catalog *catalog) :
+    Annot(xrefA, rect, catalog) {
+  Object obj1;
+
+  type = type3D;
+
+  annotObj.dictSet ("Subtype", obj1.initName ("3D"));
+
+  initialize(xrefA, catalog, annotObj.getDict());
+}
 
 Annot3D::Annot3D(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
   Annot(xrefA, dict, catalog, obj) {
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 5d9aad1..52f1940 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -480,7 +480,8 @@ public:
     type3D              // 3D             25
   };
 
-  Annot(XRef *xrefA, Dict *dict, Catalog* catalog);
+  Annot(XRef *xrefA, PDFRectangle *rectA, Catalog *catalog);
+  Annot(XRef *xrefA, Dict *dict, Catalog *catalog);
   Annot(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   virtual ~Annot();
   GBool isOk() { return ok; }
@@ -572,6 +573,7 @@ protected:
 
 class AnnotPopup: public Annot {
 public:
+  AnnotPopup(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   AnnotPopup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotPopup();
 
@@ -596,6 +598,7 @@ public:
     replyTypeGroup  // Group
   };
 
+  AnnotMarkup(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   AnnotMarkup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   virtual ~AnnotMarkup();
 
@@ -647,6 +650,7 @@ public:
     stateNone       // None
   };
 
+  AnnotText(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   AnnotText(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotText();
 
@@ -693,6 +697,7 @@ class AnnotMovie: public Annot {
     int units_per_second; // 0 : defined by movie
   };
 
+  AnnotMovie(XRef *xrefA, PDFRectangle *rect, Movie *movieA, Catalog *catalog);
   AnnotMovie(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotMovie();
 
@@ -766,6 +771,7 @@ class AnnotMovie: public Annot {
 class AnnotScreen: public Annot {
  public:
 
+  AnnotScreen(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   AnnotScreen(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotScreen();
 
@@ -801,6 +807,7 @@ public:
     effectPush      // P
   };
 
+  AnnotLink(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   AnnotLink(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   virtual ~AnnotLink();
 
@@ -844,6 +851,7 @@ public:
     intentFreeTextTypeWriter  // FreeTextTypeWriter
   };
 
+  AnnotFreeText(XRef *xrefA, PDFRectangle *rect, GooString *da, Catalog *catalog);
   AnnotFreeText(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotFreeText();
 
@@ -895,6 +903,7 @@ public:
     captionPosTop     // Top
   };
 
+  AnnotLine(XRef *xrefA, PDFRectangle *rect, PDFRectangle *lRect, Catalog *catalog);
   AnnotLine(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotLine();
 
@@ -947,6 +956,8 @@ protected:
 class AnnotTextMarkup: public AnnotMarkup {
 public:
 
+  AnnotTextMarkup(XRef *xrefA, PDFRectangle *rect, AnnotSubtype subType,
+		  AnnotQuadrilaterals *quadPoints, Catalog *catalog);
   AnnotTextMarkup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   virtual ~AnnotTextMarkup();
 
@@ -966,6 +977,7 @@ protected:
 class AnnotStamp: public AnnotMarkup {
 public:
 
+  AnnotStamp(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   AnnotStamp(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotStamp();
 
@@ -986,6 +998,7 @@ private:
 class AnnotGeometry: public AnnotMarkup {
 public:
 
+  AnnotGeometry(XRef *xrefA, PDFRectangle *rect, AnnotSubtype subType, Catalog *catalog);
   AnnotGeometry(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotGeometry();
 
@@ -1016,6 +1029,8 @@ public:
     polygonDimension   // PolygonDimension
   };
 
+  AnnotPolygon(XRef *xrefA, PDFRectangle *rect, AnnotSubtype subType,
+	       AnnotPath *path, Catalog *catalog);
   AnnotPolygon(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotPolygon();
 
@@ -1057,6 +1072,7 @@ public:
     symbolP         // P
   };
 
+  AnnotCaret(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   AnnotCaret(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotCaret();
 
@@ -1079,6 +1095,7 @@ private:
 class AnnotInk: public AnnotMarkup {
 public:
 
+  AnnotInk(XRef *xrefA, PDFRectangle *rect, AnnotPath **paths, int n_paths, Catalog *catalog);
   AnnotInk(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotInk();
 
@@ -1106,6 +1123,7 @@ private:
 class AnnotFileAttachment: public AnnotMarkup {
 public:
 
+  AnnotFileAttachment(XRef *xrefA, PDFRectangle *rect, GooString *filename, Catalog *catalog);
   AnnotFileAttachment(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotFileAttachment();
 
@@ -1131,6 +1149,7 @@ private:
 class AnnotSound: public AnnotMarkup {
 public:
 
+  AnnotSound(XRef *xrefA, PDFRectangle *rect, Sound *soundA, Catalog *catalog);
   AnnotSound(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~AnnotSound();
 
@@ -1251,6 +1270,7 @@ class Annot3D: public Annot {
   };
 public:
 
+  Annot3D(XRef *xrefA, PDFRectangle *rect, Catalog *catalog);
   Annot3D(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
   ~Annot3D();
 


More information about the poppler mailing list