Hi all, 

we are still lacking write support in annotations. This patch, to be
able to modify the contents of an annotation, it's just a first step. 

ok to commit?
-- 
Carlos Garcia Campos
   [email protected]
   [email protected]
   http://carlosgc.linups.org
PGP key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x523E6462
From c05546618db4157fd00925041ede94b2707a70c8 Mon Sep 17 00:00:00 2001
From: Carlos Garcia Campos <[email protected]>
Date: Sat, 18 Apr 2009 18:49:09 +0200
Subject: [PATCH] Add setContents() to modify the annot contents

---
 poppler/Annot.cc |   22 +++++++++++++++++++++-
 poppler/Annot.h  |    4 ++++
 2 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index fbf8b47..10e3911 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,23 @@ void Annot::initialize(XRef *xrefA, Dict *dict, Catalog *catalog) {
   }
 }
 
+void Annot::setContents(GooString *new_content) {
+  delete contents;
+  contents = new GooString(new_content);
+  
+  //append the unicode marker <FE FF> if needed
+  if (new_content && !contents->hasUnicodeMarker()) {
+    contents->insert(0, 0xff);
+    contents->insert(0, 0xfe);
+  }
+  
+  Object obj1;
+  obj1.initString(contents->copy());
+
+  annotObj.dictSet("Contents", &obj1);
+  xref->setModifiedObject(&annotObj, ref);
+}
+	
 double Annot::getXMin() {
   return rect->x1;
 }
@@ -1006,8 +1024,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
-- 
1.6.0.4

Attachment: signature.asc
Description: Esta parte del mensaje está firmada digitalmente

_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to