[PATCH] Annot will save their generated appearance in their AP dict.

Julien Rebetez julien at fhtagn.net
Fri Oct 26 05:23:22 PDT 2007


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

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 850b729..a1bb227 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -26,6 +26,7 @@
 #include "CharCodeToUnicode.h"
 #include "Form.h"
 #include "Error.h"
+#include "XRef.h"
 
 #define annotFlagHidden    0x0002
 #define annotFlagPrint     0x0004
@@ -106,6 +107,8 @@ void Annot::initialize(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog
   double borderR, borderG, borderB;
   double t;
 
+  appRef.num = 0;
+  appRef.gen = 65535;
   ok = gTrue;
   xref = xrefA;
   appearBuf = NULL;
@@ -711,6 +714,40 @@ void Annot::generateFieldAppearance(Dict *field, Dict *annot, Dict *acroForm) {
   appearance.free();
   appearance.initStream(appearStream);
 
+
+  appearStream->setNeedFree(gTrue);
+
+  if (widget->isModified()) {
+    //create a new object that will contains the new appearance
+    
+    //if we already have a N entry in our AP dict, reuse it
+    if (annot->lookup("AP", &obj1)->isDict() &&
+        obj1.dictLookupNF("N", &obj2)->isRef()) {
+      appRef = obj2.getRef();
+    }
+
+    // this annot doesn't have an AP yet, create one
+    if (appRef.num == 0)
+      appRef = xref->addIndirectObject(&appearance);
+    else // since we reuse the already existing AP, we have to notify the xref about this update
+      xref->setModifiedObject(&appearance, appRef);
+
+    // update object's AP and AS
+    Object apObj;
+    apObj.initDict(xref);
+
+    Object oaRef;
+    oaRef.initRef(appRef.num, appRef.gen);
+
+    apObj.dictSet("N", &oaRef);
+    annot->set("AP", &apObj);
+    Dict* d = new Dict(annot);
+    Object dictObj;
+    dictObj.initDict(d);
+
+    xref->setModifiedObject(&dictObj, ref);
+  }
+
   if (fontDict) {
     delete fontDict;
   }
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 50f5bfb..56af2f5 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -115,7 +115,9 @@ private:
   FormWidget *widget;           // FormWidget object for this annotation
   GooString *type;              // annotation type
   Object appearance;		// a reference to the Form XObject stream
-				//   for the normal appearance
+  Ref appRef; //the reference to the indirect appearance object in XRef 
+
+	// for the normal appearance
   GooString *appearBuf;
   Guint flags;
   double xMin, yMin,		// annotation rectangle
-- 
1.5.2.5


--------------030500050101040903030608
Content-Type: text/x-patch;
 name="0006-FormWidget-s-modified-field-is-now-correctly-updated.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename*0="0006-FormWidget-s-modified-field-is-now-correctly-updated.pa";
 filename*1="tch"



More information about the poppler mailing list