[poppler] 2 commits - glib/poppler-annot.cc glib/poppler-annot.h poppler/Annot.cc poppler/Annot.h

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Tue Apr 21 09:10:08 PDT 2009


 glib/poppler-annot.cc |   25 +++++++++++++++++++++++++
 glib/poppler-annot.h  |    2 ++
 poppler/Annot.cc      |   26 +++++++++++++++++++++++++-
 poppler/Annot.h       |    4 ++++
 4 files changed, 56 insertions(+), 1 deletion(-)

New commits:
commit 9c2714a3e1c02f445661618e24bcd27f1392b2b7
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Tue Apr 21 18:08:06 2009 +0200

    [glib] Implement poppler_annot_set_contents()

diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index a2c51e4..5e5a4aa 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -252,6 +252,31 @@ poppler_annot_get_contents (PopplerAnnot *poppler_annot)
 }
 
 /**
+ * poppler_annot_set_contents:
+ * @poppler_annot: a #PopplerAnnot
+ * @contents: a text string containing the new contents
+ *
+ * Sets the contents of @poppler_annot to the given value,
+ * replacing the current contents.
+ **/
+void
+poppler_annot_set_contents (PopplerAnnot *poppler_annot,
+			    const gchar  *contents)
+{
+  GooString *goo_tmp;
+  gchar *tmp;
+  gsize length = 0;
+  
+  g_return_if_fail (POPPLER_IS_ANNOT (poppler_annot));
+
+  tmp = contents ? g_convert (contents, -1, "UTF16BE", "UTF8", NULL, &length, NULL) : NULL;
+  goo_tmp = new GooString (tmp, length);
+  g_free (tmp);
+  poppler_annot->annot->setContents (goo_tmp);
+  delete (goo_tmp);
+}
+
+/**
  * poppler_annot_get_name:
  * @poppler_annot: a #PopplerAnnot
  *
diff --git a/glib/poppler-annot.h b/glib/poppler-annot.h
index 3e38975..714e87b 100644
--- a/glib/poppler-annot.h
+++ b/glib/poppler-annot.h
@@ -133,6 +133,8 @@ struct _PopplerAnnotCalloutLine
 GType                         poppler_annot_get_type                           (void) G_GNUC_CONST;
 PopplerAnnotType              poppler_annot_get_annot_type                     (PopplerAnnot *poppler_annot);
 gchar                        *poppler_annot_get_contents                       (PopplerAnnot *poppler_annot);
+void                          poppler_annot_set_contents                       (PopplerAnnot *poppler_annot,
+										const gchar  *contents);
 gchar                        *poppler_annot_get_name                           (PopplerAnnot *poppler_annot);
 gchar                        *poppler_annot_get_modified                       (PopplerAnnot *poppler_annot);
 PopplerAnnotFlag              poppler_annot_get_flags                          (PopplerAnnot *poppler_annot);
commit eec550e8b3cf96aefed9b03a78d365c2848fb8f2
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Tue Apr 21 18:06:34 2009 +0200

    Add setContents() to modify the annot contents

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index fbf8b47..b6bb7d9 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -841,6 +841,7 @@ void Annot::initialize(XRef *xrefA, Dict *dict, Catalog *catalog) {
   xref = xrefA;
   appearBuf = NULL;
   fontSize = 0;
+  annotObj.initDict (dict);
 
   //----- parse the rectangle
   rect = new PDFRectangle();
@@ -984,6 +985,27 @@ void Annot::initialize(XRef *xrefA, Dict *dict, Catalog *catalog) {
   }
 }
 
+void Annot::setContents(GooString *new_content) {
+  delete contents;
+
+  if (new_content) {
+    contents = new GooString(new_content);
+    //append the unicode marker <FE FF> if needed	
+    if (!contents->hasUnicodeMarker()) {
+      contents->insert(0, 0xff);
+      contents->insert(0, 0xfe);
+    }
+  } else {
+    contents = new GooString();
+  }
+  
+  Object obj1;
+  obj1.initString(contents->copy());
+
+  annotObj.dictSet("Contents", &obj1);
+  xref->setModifiedObject(&annotObj, ref);
+}
+	
 double Annot::getXMin() {
   return rect->x1;
 }
@@ -1006,8 +1028,10 @@ void Annot::readArrayNum(Object *pdfArray, int key, double *value) {
 }
 
 Annot::~Annot() {
+  annotObj.free();
+  
   delete rect;
-
+  
   if (contents)
     delete contents;
 
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 0b8ad2a..45e4ebe 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -497,6 +497,8 @@ public:
 
   double getFontSize() { return fontSize; }
 
+  void setContents(GooString *new_content);
+  
   // getters
   AnnotSubtype getType() const { return type; }
   PDFRectangle *getRect() const { return rect; }
@@ -525,6 +527,8 @@ protected:
   void drawCircle(double cx, double cy, double r, GBool fill);
   void drawCircleTopLeft(double cx, double cy, double r);
   void drawCircleBottomRight(double cx, double cy, double r);
+
+  Object annotObj;
   
   // required data
   AnnotSubtype type;                // Annotation type


More information about the poppler mailing list