[poppler] Branch 'xpdf303merge' - poppler/Form.cc poppler/Form.h

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Sun Sep 4 02:54:17 PDT 2011


 poppler/Form.cc |   79 ++++++++++++++++++++++++++++----------------------------
 poppler/Form.h  |   28 ++++++++++---------
 2 files changed, 55 insertions(+), 52 deletions(-)

New commits:
commit ca7d77a27e2f3a692842968f08dcb9fa5379bf0f
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Sun Sep 4 11:53:40 2011 +0200

    Create forms with a PDFDoc instead of XRef too

diff --git a/poppler/Form.cc b/poppler/Form.cc
index f2b6604..00c8cc1 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -38,7 +38,6 @@
 #include "XRef.h"
 #include "PDFDocEncoding.h"
 #include "Annot.h"
-#include "Catalog.h"
 #include "Link.h"
 
 //return a newly allocated char* containing an UTF16BE string of size length
@@ -62,12 +61,13 @@ char* pdfDocEncodingToUTF16 (GooString* orig, int* length)
 
 
 
-FormWidget::FormWidget(XRef *xrefA, Object *aobj, unsigned num, Ref aref, FormField *fieldA) 
+FormWidget::FormWidget(PDFDoc *docA, Object *aobj, unsigned num, Ref aref, FormField *fieldA)
 {
   ref = aref;
   ID = 0;
   childNum = num;
-  xref = xrefA;
+  doc = docA;
+  xref = doc->getXRef();
   aobj->copy(&obj);
   type = formUndef;
   field = fieldA;
@@ -87,13 +87,13 @@ void FormWidget::print(int indent) {
 }
 #endif
 
-void FormWidget::createWidgetAnnotation(PDFDoc *docA) {
+void FormWidget::createWidgetAnnotation() {
   if (widget)
     return;
 
   Object obj1;
   obj1.initRef(ref.num, ref.gen);
-  widget = new AnnotWidget(docA, obj.getDict(), &obj1, field);
+  widget = new AnnotWidget(doc, obj.getDict(), &obj1, field);
   obj1.free();
 }
 
@@ -150,8 +150,8 @@ LinkAction *FormWidget::getActivationAction() {
   return widget ? widget->getAction() : NULL;
 }
 
-FormWidgetButton::FormWidgetButton (XRef *xrefA, Object *aobj, unsigned num, Ref ref, FormField *p) :
-	FormWidget(xrefA, aobj, num, ref, p)
+FormWidgetButton::FormWidgetButton (PDFDoc *docA, Object *aobj, unsigned num, Ref ref, FormField *p) :
+	FormWidget(docA, aobj, num, ref, p)
 {
   type = formButton;
   parent = static_cast<FormFieldButton*>(field);
@@ -232,8 +232,8 @@ void FormWidgetButton::setNumSiblingsID (int i)
 }
 
 
-FormWidgetText::FormWidgetText (XRef *xrefA, Object *aobj, unsigned num, Ref ref, FormField *p) :
-	FormWidget(xrefA, aobj, num, ref, p)
+FormWidgetText::FormWidgetText (PDFDoc *docA, Object *aobj, unsigned num, Ref ref, FormField *p) :
+	FormWidget(docA, aobj, num, ref, p)
 {
   type = formText;
   parent = static_cast<FormFieldText*>(field);
@@ -299,8 +299,8 @@ void FormWidgetText::setContent(GooString* new_content)
   parent->setContentCopy(new_content);
 }
 
-FormWidgetChoice::FormWidgetChoice(XRef *xrefA, Object *aobj, unsigned num, Ref ref, FormField *p) :
-	FormWidget(xrefA, aobj, num, ref, p)
+FormWidgetChoice::FormWidgetChoice(PDFDoc *docA, Object *aobj, unsigned num, Ref ref, FormField *p) :
+	FormWidget(docA, aobj, num, ref, p)
 {
   type = formChoice;
   parent = static_cast<FormFieldChoice*>(field);
@@ -417,8 +417,8 @@ bool FormWidgetChoice::isListBox () const
   return parent->isListBox();
 }
 
-FormWidgetSignature::FormWidgetSignature(XRef *xrefA, Object *aobj, unsigned num, Ref ref, FormField *p) :
-	FormWidget(xrefA, aobj, num, ref, p)
+FormWidgetSignature::FormWidgetSignature(PDFDoc *docA, Object *aobj, unsigned num, Ref ref, FormField *p) :
+	FormWidget(docA, aobj, num, ref, p)
 {
   type = formSignature;
   parent = static_cast<FormFieldSignature*>(field);
@@ -429,9 +429,10 @@ FormWidgetSignature::FormWidgetSignature(XRef *xrefA, Object *aobj, unsigned num
 // FormField
 //========================================================================
 
-FormField::FormField(XRef* xrefA, Object *aobj, const Ref& aref, FormField *parentA, std::set<int> *usedParents, FormFieldType ty)
+FormField::FormField(PDFDoc *docA, Object *aobj, const Ref& aref, FormField *parentA, std::set<int> *usedParents, FormFieldType ty)
 {
-  xref = xrefA;
+  doc = docA;
+  xref = doc->getXRef();
   aobj->copy(&obj);
   Dict* dict = obj.getDict();
   ref.num = ref.gen = 0;
@@ -489,7 +490,7 @@ FormField::FormField(XRef* xrefA, Object *aobj, const Ref& aref, FormField *pare
 
           numChildren++;
           children = (FormField**)greallocn(children, numChildren, sizeof(FormField*));
-          children[numChildren - 1] = Form::createFieldFromDict(&childObj, xref, ref, this, &usedParentsAux);
+          children[numChildren - 1] = Form::createFieldFromDict(&childObj, doc, ref, this, &usedParentsAux);
         } else if (childObj.dictLookup("Subtype", &obj2)->isName("Widget")) {
           // Child is a widget annotation
           if (!terminal && numChildren > 0) {
@@ -613,13 +614,13 @@ void FormField::fillChildrenSiblingsID()
   }
 }
 
-void FormField::createWidgetAnnotations(PDFDoc *docA) {
+void FormField::createWidgetAnnotations() {
   if (terminal) {
     for (int i = 0; i < numChildren; i++)
-      widgets[i]->createWidgetAnnotation(docA);
+      widgets[i]->createWidgetAnnotation();
   } else {
     for (int i = 0; i < numChildren; i++)
-      children[i]->createWidgetAnnotations(docA);
+      children[i]->createWidgetAnnotations();
   }
 }
 
@@ -635,16 +636,16 @@ void FormField::_createWidget (Object *obj, Ref aref)
   //ID = index in "widgets" table
   switch (type) {
   case formButton:
-    widgets[numChildren-1] = new FormWidgetButton(xref, obj, numChildren-1, aref, this);
+    widgets[numChildren-1] = new FormWidgetButton(doc, obj, numChildren-1, aref, this);
     break;
   case formText:
-    widgets[numChildren-1] = new FormWidgetText(xref, obj, numChildren-1, aref, this);
+    widgets[numChildren-1] = new FormWidgetText(doc, obj, numChildren-1, aref, this);
     break;
   case formChoice:
-    widgets[numChildren-1] = new FormWidgetChoice(xref, obj, numChildren-1, aref, this);
+    widgets[numChildren-1] = new FormWidgetChoice(doc, obj, numChildren-1, aref, this);
     break;
   case formSignature:
-    widgets[numChildren-1] = new FormWidgetSignature(xref, obj, numChildren-1, aref, this);
+    widgets[numChildren-1] = new FormWidgetSignature(doc, obj, numChildren-1, aref, this);
     break;
   default:
     error(errSyntaxWarning, -1, "SubType on non-terminal field, invalid document?");
@@ -719,8 +720,8 @@ GooString* FormField::getFullyQualifiedName() {
 //------------------------------------------------------------------------
 // FormFieldButton
 //------------------------------------------------------------------------
-FormFieldButton::FormFieldButton(XRef *xrefA, Object *aobj, const Ref& ref, FormField *parent, std::set<int> *usedParents)
-  : FormField(xrefA, aobj, ref, parent, usedParents, formButton)
+FormFieldButton::FormFieldButton(PDFDoc *docA, Object *aobj, const Ref& ref, FormField *parent, std::set<int> *usedParents)
+  : FormField(docA, aobj, ref, parent, usedParents, formButton)
 {
   Dict* dict = obj.getDict();
   active_child = -1;
@@ -886,8 +887,8 @@ FormFieldButton::~FormFieldButton()
 //------------------------------------------------------------------------
 // FormFieldText
 //------------------------------------------------------------------------
-FormFieldText::FormFieldText(XRef *xrefA, Object *aobj, const Ref& ref, FormField *parent, std::set<int> *usedParents)
-  : FormField(xrefA, aobj, ref, parent, usedParents, formText)
+FormFieldText::FormFieldText(PDFDoc *docA, Object *aobj, const Ref& ref, FormField *parent, std::set<int> *usedParents)
+  : FormField(docA, aobj, ref, parent, usedParents, formText)
 {
   Dict* dict = obj.getDict();
   Object obj1;
@@ -979,8 +980,8 @@ FormFieldText::~FormFieldText()
 //------------------------------------------------------------------------
 // FormFieldChoice
 //------------------------------------------------------------------------
-FormFieldChoice::FormFieldChoice(XRef *xrefA, Object *aobj, const Ref& ref, FormField *parent, std::set<int> *usedParents)
-  : FormField(xrefA, aobj, ref, parent, usedParents, formChoice)
+FormFieldChoice::FormFieldChoice(PDFDoc *docA, Object *aobj, const Ref& ref, FormField *parent, std::set<int> *usedParents)
+  : FormField(docA, aobj, ref, parent, usedParents, formChoice)
 {
   numChoices = 0;
   choices = NULL;
@@ -1220,8 +1221,8 @@ GooString *FormFieldChoice::getSelectedChoice() {
 //------------------------------------------------------------------------
 // FormFieldSignature
 //------------------------------------------------------------------------
-FormFieldSignature::FormFieldSignature(XRef *xrefA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents)
-  : FormField(xrefA, dict, ref, parent, usedParents, formSignature)
+FormFieldSignature::FormFieldSignature(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents)
+  : FormField(docA, dict, ref, parent, usedParents, formSignature)
 {
 }
 
@@ -1310,7 +1311,7 @@ Form::Form(PDFDoc *docA, Object* acroFormA)
       }
 
       std::set<int> usedParents;
-      rootFields[numFields++] = createFieldFromDict (&obj2, xref, oref.getRef(), NULL, &usedParents);
+      rootFields[numFields++] = createFieldFromDict (&obj2, doc, oref.getRef(), NULL, &usedParents);
 
       obj2.free();
       oref.free();
@@ -1375,21 +1376,21 @@ Object *Form::fieldLookup(Dict *field, const char *key, Object *obj) {
   return ::fieldLookup(field, key, obj, &usedParents);
 }
 
-FormField *Form::createFieldFromDict (Object* obj, XRef *xrefA, const Ref& pref, FormField *parent, std::set<int> *usedParents)
+FormField *Form::createFieldFromDict (Object* obj, PDFDoc *docA, const Ref& pref, FormField *parent, std::set<int> *usedParents)
 {
     Object obj2;
     FormField *field;
 
     if (Form::fieldLookup(obj->getDict (), "FT", &obj2)->isName("Btn")) {
-      field = new FormFieldButton(xrefA, obj, pref, parent, usedParents);
+      field = new FormFieldButton(docA, obj, pref, parent, usedParents);
     } else if (obj2.isName("Tx")) {
-      field = new FormFieldText(xrefA, obj, pref, parent, usedParents);
+      field = new FormFieldText(docA, obj, pref, parent, usedParents);
     } else if (obj2.isName("Ch")) {
-      field = new FormFieldChoice(xrefA, obj, pref, parent, usedParents);
+      field = new FormFieldChoice(docA, obj, pref, parent, usedParents);
     } else if (obj2.isName("Sig")) {
-      field = new FormFieldSignature(xrefA, obj, pref, parent, usedParents);
+      field = new FormFieldSignature(docA, obj, pref, parent, usedParents);
     } else { //we don't have an FT entry => non-terminal field
-      field = new FormField(xrefA, obj, pref, parent, usedParents);
+      field = new FormField(docA, obj, pref, parent, usedParents);
     }
     obj2.free();
 
@@ -1404,7 +1405,7 @@ void Form::postWidgetsLoad()
   // a FormWidget the Catalog is still creating the form object
   for (int i = 0; i < numFields; i++) {
     rootFields[i]->fillChildrenSiblingsID();
-    rootFields[i]->createWidgetAnnotations(doc);
+    rootFields[i]->createWidgetAnnotations();
   }
 }
 
diff --git a/poppler/Form.h b/poppler/Form.h
index 3fb6a4a..fa3c718 100644
--- a/poppler/Form.h
+++ b/poppler/Form.h
@@ -106,7 +106,7 @@ public:
   // decode id and retrieve pageNum and fieldNum
   static void decodeID (unsigned id, unsigned* pageNum, unsigned* fieldNum);
 
-  void createWidgetAnnotation(PDFDoc *docA);
+  void createWidgetAnnotation();
   AnnotWidget *getWidgetAnnotation() const { return widget; }
 
 #ifdef DEBUG_FORMS
@@ -114,13 +114,14 @@ public:
 #endif
 
 protected:
-  FormWidget(XRef *xrefA, Object *aobj, unsigned num, Ref aref, FormField *fieldA);
+  FormWidget(PDFDoc *docA, Object *aobj, unsigned num, Ref aref, FormField *fieldA);
 
   AnnotWidget *widget;
   FormField* field;
   FormFieldType type;
   Object obj;
   Ref ref;
+  PDFDoc *doc;
   XRef *xref;
 
   //index of this field in the parent's child list
@@ -143,7 +144,7 @@ protected:
 
 class FormWidgetButton: public FormWidget {
 public:
-  FormWidgetButton(XRef *xrefA, Object *dict, unsigned num, Ref ref, FormField *p);
+  FormWidgetButton(PDFDoc *docA, Object *dict, unsigned num, Ref ref, FormField *p);
   ~FormWidgetButton ();
 
   FormButtonType getButtonType() const;
@@ -175,7 +176,7 @@ protected:
 
 class FormWidgetText: public FormWidget {
 public:
-  FormWidgetText(XRef *xrefA, Object *dict, unsigned num, Ref ref, FormField *p);
+  FormWidgetText(PDFDoc *docA, Object *dict, unsigned num, Ref ref, FormField *p);
   //return the field's content (UTF16BE)
   GooString* getContent() ;
   //return a copy of the field's content (UTF16BE)
@@ -202,7 +203,7 @@ protected:
 
 class FormWidgetChoice: public FormWidget {
 public:
-  FormWidgetChoice(XRef *xrefA, Object *dict, unsigned num, Ref ref, FormField *p);
+  FormWidgetChoice(PDFDoc *docA, Object *dict, unsigned num, Ref ref, FormField *p);
   ~FormWidgetChoice();
 
   int getNumChoices();
@@ -242,7 +243,7 @@ protected:
 
 class FormWidgetSignature: public FormWidget {
 public:
-  FormWidgetSignature(XRef *xrefA, Object *dict, unsigned num, Ref ref, FormField *p);
+  FormWidgetSignature(PDFDoc *docA, Object *dict, unsigned num, Ref ref, FormField *p);
 protected:
   FormFieldSignature *parent;
 };
@@ -256,7 +257,7 @@ protected:
 
 class FormField {
 public:
-  FormField(XRef* xrefa, Object *aobj, const Ref& aref, FormField *parent, std::set<int> *usedParents, FormFieldType t=formUndef);
+  FormField(PDFDoc *docA, Object *aobj, const Ref& aref, FormField *parent, std::set<int> *usedParents, FormFieldType t=formUndef);
 
   virtual ~FormField();
 
@@ -285,7 +286,7 @@ public:
   // only implemented in FormFieldButton
   virtual void fillChildrenSiblingsID ();
 
-  void createWidgetAnnotations(PDFDoc *docA);
+  void createWidgetAnnotations();
 
 #ifdef DEBUG_FORMS
   void printTree(int indent = 0);
@@ -301,6 +302,7 @@ public:
   Ref ref;
   bool terminal;
   Object obj;
+  PDFDoc *doc;
   XRef *xref;
   FormField **children;
   FormField *parent;
@@ -330,7 +332,7 @@ private:
 
 class FormFieldButton: public FormField {
 public:
-  FormFieldButton(XRef *xrefA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents);
+  FormFieldButton(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents);
 
   FormButtonType getButtonType () { return btype; }
 
@@ -365,7 +367,7 @@ protected:
 
 class FormFieldText: public FormField {
 public:
-  FormFieldText(XRef *xrefA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents);
+  FormFieldText(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents);
   
   GooString* getContent () { return content; }
   GooString* getContentCopy ();
@@ -403,7 +405,7 @@ protected:
 
 class FormFieldChoice: public FormField {
 public:
-  FormFieldChoice(XRef *xrefA, Object *aobj, const Ref& ref, FormField *parent, std::set<int> *usedParents);
+  FormFieldChoice(PDFDoc *docA, Object *aobj, const Ref& ref, FormField *parent, std::set<int> *usedParents);
 
   virtual ~FormFieldChoice();
 
@@ -472,7 +474,7 @@ protected:
 
 class FormFieldSignature: public FormField {
 public:
-  FormFieldSignature(XRef *xrefA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents);
+  FormFieldSignature(PDFDoc *docA, Object *dict, const Ref& ref, FormField *parent, std::set<int> *usedParents);
 
   virtual ~FormFieldSignature();
 
@@ -498,7 +500,7 @@ public:
   
   /* Creates a new Field of the type specified in obj's dict.
      used in Form::Form and FormField::FormField */
-  static FormField *createFieldFromDict (Object* obj, XRef *xref, const Ref& aref, FormField *parent, std::set<int> *usedParents);
+  static FormField *createFieldFromDict (Object* obj, PDFDoc *docA, const Ref& aref, FormField *parent, std::set<int> *usedParents);
 
   Object *getObj () const { return acroForm; }
   GBool getNeedAppearances () const { return needAppearances; }


More information about the poppler mailing list