[poppler] 4 commits - poppler/Annot.cc poppler/Annot.h poppler/Form.cc poppler/Form.h

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Mon Mar 7 11:18:05 PST 2011


 poppler/Annot.cc |  188 +++++++++++++++++++++----------------------------------
 poppler/Annot.h  |   12 +--
 poppler/Form.cc  |   44 ++++++++++++
 poppler/Form.h   |   26 +++++++
 4 files changed, 150 insertions(+), 120 deletions(-)

New commits:
commit dc100eb9080fb58164fc94c86bfb1728cecd21c3
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Mon Mar 7 20:14:27 2011 +0100

    annots: Use the field object to get MaxLen instead of parsing the field dict

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 4e8caa7..048f0be 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -3696,7 +3696,7 @@ void AnnotWidget::drawFormFieldButton(GfxResources *resources, GooString *da) {
 }
 
 void AnnotWidget::drawFormFieldText(GfxResources *resources, GooString *da) {
-  Object obj1, obj2;
+  Object obj1;
   VariableTextQuadding quadding;
   Dict *fieldDict = field->getObj()->getDict();
   FormFieldText *fieldText = static_cast<FormFieldText *>(field);
@@ -3705,11 +3705,9 @@ void AnnotWidget::drawFormFieldText(GfxResources *resources, GooString *da) {
     quadding = field->hasTextQuadding() ? field->getTextQuadding() : form->getTextQuadding();
 
     int comb = 0;
-    if (fieldText->isComb()) {
-      if (Form::fieldLookup(fieldDict, "MaxLen", &obj2)->isInt())
-        comb = obj2.getInt();
-      obj2.free();
-    }
+    if (fieldText->isComb())
+      comb = fieldText->getMaxLen();
+
     drawText(obj1.getString(), da, resources,
              fieldText->isMultiline(), comb, quadding, gTrue, gFalse, fieldText->isPassword());
   }
commit 7149634f184dc3f07f2a70c296aac207ef24952c
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Mon Mar 7 19:55:45 2011 +0100

    forms: Parse the default resources dictionary in Form
    
    And use it in AnnotWidget instead of parsing the dictionary again.

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 3ed8b45..4e8caa7 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -2983,7 +2983,7 @@ void AnnotWidget::writeString(GooString *str, GooString *appearBuf)
 }
 
 // Draw the variable text or caption for a field.
-void AnnotWidget::drawText(GooString *text, GooString *da, GfxFontDict *fontDict,
+void AnnotWidget::drawText(GooString *text, GooString *da, GfxResources *resources,
     GBool multiline, int comb, int quadding,
     GBool txField, GBool forceZapfDingbats,
     GBool password) {
@@ -3043,7 +3043,7 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxFontDict *fontDict
   if (tfPos >= 0) {
     tok = (GooString *)daToks->get(tfPos);
     if (tok->getLength() >= 1 && tok->getChar(0) == '/') {
-      if (!fontDict || !(font = fontDict->lookup(tok->getCString() + 1))) {
+      if (!resources || !(font = resources->lookupFont(tok->getCString() + 1))) {
         if (forceZapfDingbats) {
           // We are forcing ZaDb but the font does not exist
           // so create a fake one
@@ -3369,7 +3369,7 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxFontDict *fontDict
 
 // Draw the variable text or caption for a field.
 void AnnotWidget::drawListBox(FormFieldChoice *fieldChoice,
-			      GooString *da, GfxFontDict *fontDict, int quadding) {
+			      GooString *da, GfxResources *resources, int quadding) {
   GooList *daToks;
   GooString *tok, *convertedText;
   GfxFont *font;
@@ -3414,7 +3414,7 @@ void AnnotWidget::drawListBox(FormFieldChoice *fieldChoice,
   if (tfPos >= 0) {
     tok = (GooString *)daToks->get(tfPos);
     if (tok->getLength() >= 1 && tok->getChar(0) == '/') {
-      if (!fontDict || !(font = fontDict->lookup(tok->getCString() + 1))) {
+      if (!resources || !(font = resources->lookupFont(tok->getCString() + 1))) {
         error(-1, "Unknown font in field's DA string");
       }
     } else {
@@ -3645,7 +3645,7 @@ void AnnotWidget::drawBorder() {
   }
 }
 
-void AnnotWidget::drawFormFieldButton(GfxFontDict *fontDict, GooString *da) {
+void AnnotWidget::drawFormFieldButton(GfxResources *resources, GooString *da) {
   Object obj1, obj2;
   Dict *annot = widget->getObj()->getDict();
   Dict *fieldDict = field->getObj()->getDict();
@@ -3660,7 +3660,7 @@ void AnnotWidget::drawFormFieldButton(GfxFontDict *fontDict, GooString *da) {
       if (annot->lookup("AS", &obj2)->isName(obj1.getName()) &&
           strcmp (obj1.getName(), "Off") != 0) {
         if (caption) {
-          drawText(caption, da, fontDict, gFalse, 0, fieldQuadCenter,
+          drawText(caption, da, resources, gFalse, 0, fieldQuadCenter,
                    gFalse, gTrue);
         } else if (appearCharacs) {
           AnnotColor *aColor = appearCharacs->getBorderColor();
@@ -3678,16 +3678,16 @@ void AnnotWidget::drawFormFieldButton(GfxFontDict *fontDict, GooString *da) {
     break;
   case formButtonPush:
     if (caption)
-      drawText(caption, da, fontDict, gFalse, 0, fieldQuadCenter, gFalse, gFalse);
+      drawText(caption, da, resources, gFalse, 0, fieldQuadCenter, gFalse, gFalse);
     break;
   case formButtonCheck:
     if (annot->lookup("AS", &obj1)->isName() &&
         strcmp(obj1.getName(), "Off") != 0) {
       if (!caption) {
         GooString checkMark("3");
-        drawText(&checkMark, da, fontDict, gFalse, 0, fieldQuadCenter, gFalse, gTrue);
+        drawText(&checkMark, da, resources, gFalse, 0, fieldQuadCenter, gFalse, gTrue);
       } else {
-        drawText(caption, da, fontDict, gFalse, 0, fieldQuadCenter, gFalse, gTrue);
+        drawText(caption, da, resources, gFalse, 0, fieldQuadCenter, gFalse, gTrue);
       }
     }
     obj1.free();
@@ -3695,7 +3695,7 @@ void AnnotWidget::drawFormFieldButton(GfxFontDict *fontDict, GooString *da) {
   }
 }
 
-void AnnotWidget::drawFormFieldText(GfxFontDict *fontDict, GooString *da) {
+void AnnotWidget::drawFormFieldText(GfxResources *resources, GooString *da) {
   Object obj1, obj2;
   VariableTextQuadding quadding;
   Dict *fieldDict = field->getObj()->getDict();
@@ -3710,13 +3710,13 @@ void AnnotWidget::drawFormFieldText(GfxFontDict *fontDict, GooString *da) {
         comb = obj2.getInt();
       obj2.free();
     }
-    drawText(obj1.getString(), da, fontDict,
+    drawText(obj1.getString(), da, resources,
              fieldText->isMultiline(), comb, quadding, gTrue, gFalse, fieldText->isPassword());
   }
   obj1.free();
 }
 
-void AnnotWidget::drawFormFieldChoice(GfxFontDict *fontDict, GooString *da) {
+void AnnotWidget::drawFormFieldChoice(GfxResources *resources, GooString *da) {
   Object obj1;
   Dict *fieldDict = field->getObj()->getDict();
   VariableTextQuadding quadding;
@@ -3726,23 +3726,22 @@ void AnnotWidget::drawFormFieldChoice(GfxFontDict *fontDict, GooString *da) {
 
   if (fieldChoice->isCombo()) {
     if (Form::fieldLookup(fieldDict, "V", &obj1)->isString()) {
-      drawText(obj1.getString(), da, fontDict, gFalse, 0, quadding, gTrue, gFalse);
+      drawText(obj1.getString(), da, resources, gFalse, 0, quadding, gTrue, gFalse);
       //~ Acrobat draws a popup icon on the right side
     }
     obj1.free();
   // list box
   } else {
-    drawListBox(fieldChoice, da, fontDict, quadding);
+    drawListBox(fieldChoice, da, resources, quadding);
   }
 }
 
 void AnnotWidget::generateFieldAppearance() {
-  Object appearDict, drObj, obj1, obj2;
+  Object appearDict, obj1, obj2;
   Dict *fieldDict;
   Dict *annot;
-  Dict *acroForm;
+  GfxResources *resources;
   MemStream *appearStream;
-  GfxFontDict *fontDict;
   GooString *da;
   GBool modified;
 
@@ -3752,8 +3751,7 @@ void AnnotWidget::generateFieldAppearance() {
   field = widget->getField();
   fieldDict = field->getObj()->getDict();
   annot = widget->getObj ()->getDict ();
-  acroForm = form->getObj ()->getDict ();
-  
+
   // do not regenerate appearence if widget has not changed
   modified = widget->isModified ();
 
@@ -3779,31 +3777,22 @@ void AnnotWidget::generateFieldAppearance() {
   if (appearCharacs && border && border->getWidth() > 0)
     drawBorder();
 
-  // get the resource dictionary
-  acroForm->lookup("DR", &drObj);
-
-  // build the font dictionary
-  if (drObj.isDict() && drObj.dictLookup("Font", &obj1)->isDict()) {
-    fontDict = new GfxFontDict(xref, NULL, obj1.getDict());
-  } else {
-    fontDict = NULL;
-  }
-  obj1.free();
-
   da = field->getDefaultAppearance();
   if (!da)
     da = form->getDefaultAppearance();
 
+  resources = form->getDefaultResources();
+
   // draw the field contents
   switch (field->getType()) {
   case formButton:
-    drawFormFieldButton(fontDict, da);
+    drawFormFieldButton(resources, da);
     break;
   case formText:
-    drawFormFieldText(fontDict, da);
+    drawFormFieldText(resources, da);
     break;
   case formChoice:
-    drawFormFieldChoice(fontDict, da);
+    drawFormFieldChoice(resources, da);
     break;
   case formSignature:
     //~unimp
@@ -3826,10 +3815,10 @@ void AnnotWidget::generateFieldAppearance() {
   appearDict.dictAdd(copyString("BBox"), &obj1);
 
   // set the resource dictionary
-  if (drObj.isDict()) {
-    appearDict.dictAdd(copyString("Resources"), drObj.copy(&obj1));
+  Object *resDict = form->getDefaultResourcesObj();
+  if (resDict->isDict()) {
+    appearDict.dictAdd(copyString("Resources"), resDict->copy(&obj1));
   }
-  drObj.free();
 
   // build the appearance stream
   appearStream = new MemStream(strdup(appearBuf->getCString()), 0,
@@ -3875,10 +3864,6 @@ void AnnotWidget::generateFieldAppearance() {
     xref->setModifiedObject(&dictObj, ref);
     dictObj.free();
   }
-
-  if (fontDict) {
-    delete fontDict;
-  }
 }
 
 
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 7776119..4efd762 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -40,7 +40,7 @@ class Gfx;
 class Catalog;
 class CharCodeToUnicode;
 class GfxFont;
-class GfxFontDict;
+class GfxResources;
 class Form;
 class FormWidget;
 class FormField;
@@ -1136,9 +1136,9 @@ public:
   virtual void draw(Gfx *gfx, GBool printing);
 
   void drawBorder();
-  void drawFormFieldButton(GfxFontDict *fontDict, GooString *da);
-  void drawFormFieldText(GfxFontDict *fontDict, GooString *da);
-  void drawFormFieldChoice(GfxFontDict *fontDict, GooString *da);
+  void drawFormFieldButton(GfxResources *resources, GooString *da);
+  void drawFormFieldText(GfxResources *resources, GooString *da);
+  void drawFormFieldChoice(GfxResources *resources, GooString *da);
   void generateFieldAppearance ();
 
   AnnotWidgetHighlightMode getMode() { return mode; }
@@ -1151,12 +1151,12 @@ private:
 
   void initialize(XRef *xrefA, Catalog *catalog, Dict *dict);
 
-  void drawText(GooString *text, GooString *da, GfxFontDict *fontDict,
+  void drawText(GooString *text, GooString *da, GfxResources *resources,
 		GBool multiline, int comb, int quadding,
 		GBool txField, GBool forceZapfDingbats,
 		GBool password=false);
   void drawListBox(FormFieldChoice *fieldChoice,
-		   GooString *da, GfxFontDict *fontDict, int quadding);
+		   GooString *da, GfxResources *resources, int quadding);
   void layoutText(GooString *text, GooString *outBuf, int *i, GfxFont *font,
 		  double *width, double widthLimit, int *charCount,
 		  GBool noReencode);
diff --git a/poppler/Form.cc b/poppler/Form.cc
index 370b82c..2abb10f 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -32,6 +32,7 @@
 #include "Object.h"
 #include "Array.h"
 #include "Dict.h"
+#include "Gfx.h"
 #include "Form.h"
 #include "XRef.h"
 #include "PDFDocEncoding.h"
@@ -1249,6 +1250,7 @@ Form::Form(XRef *xrefA, Object* acroFormA)
   rootFields = NULL;
   quadding = quaddingLeftJustified;
   defaultAppearance = NULL;
+  defaultResources = NULL;
 
   acroForm->dictLookup("NeedAppearances", &obj1);
   needAppearances = (obj1.isBool() && obj1.getBool());
@@ -1262,6 +1264,18 @@ Form::Form(XRef *xrefA, Object* acroFormA)
     quadding = static_cast<VariableTextQuadding>(obj1.getInt());
   obj1.free();
 
+  acroForm->dictLookup("DR", &resDict);
+  if (resDict.isDict()) {
+    // At a minimum, this dictionary shall contain a Font entry
+    if (resDict.dictLookup("Font", &obj1)->isDict())
+      defaultResources = new GfxResources(xref, resDict.getDict(), NULL);
+    obj1.free();
+  }
+  if (!defaultResources) {
+    resDict.free();
+    resDict.initNull();
+  }
+
   acroForm->dictLookup("Fields", &obj1);
   if (obj1.isArray()) {
     Array *array = obj1.getArray();
@@ -1308,6 +1322,8 @@ Form::~Form() {
     delete rootFields[i];
   gfree (rootFields);
   delete defaultAppearance;
+  delete defaultResources;
+  resDict.free();
 }
 
 // Look up an inheritable field dictionary entry.
diff --git a/poppler/Form.h b/poppler/Form.h
index af913c4..5bea2c1 100644
--- a/poppler/Form.h
+++ b/poppler/Form.h
@@ -30,6 +30,7 @@ class Annot;
 class Annots;
 class Catalog;
 class LinkAction;
+class GfxResources;
 
 enum FormFieldType {
   formButton,
@@ -480,6 +481,8 @@ public:
   FormField* getRootField(int i) const { return rootFields[i]; }
   GooString* getDefaultAppearance() const { return defaultAppearance; }
   VariableTextQuadding getTextQuadding() const { return quadding; }
+  GfxResources* getDefaultResources() const { return defaultResources; }
+  Object* getDefaultResourcesObj() { return &resDict; }
 
   FormWidget* findWidgetByRef (Ref aref);
 
@@ -491,6 +494,8 @@ private:
   XRef* xref;
   Object *acroForm;
   GBool needAppearances;
+  GfxResources *defaultResources;
+  Object resDict;
 
   // Variable Text
   GooString *defaultAppearance;
commit 2e73f17975811177c0b3c16b8bd97c7eb912bc44
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Mon Mar 7 18:41:48 2011 +0100

    forms: Parse field variable text entries (DA, Q) in FormField()
    
    And use them from AnnotWidget instead of parsing the field dictionary
    again.

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 554d36e..3ed8b45 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -3702,11 +3702,7 @@ void AnnotWidget::drawFormFieldText(GfxFontDict *fontDict, GooString *da) {
   FormFieldText *fieldText = static_cast<FormFieldText *>(field);
 
   if (Form::fieldLookup(fieldDict, "V", &obj1)->isString()) {
-    if (Form::fieldLookup(fieldDict, "Q", &obj2)->isInt())
-      quadding = static_cast<VariableTextQuadding>(obj2.getInt());
-    else
-      quadding = form->getTextQuadding();
-    obj2.free();
+    quadding = field->hasTextQuadding() ? field->getTextQuadding() : form->getTextQuadding();
 
     int comb = 0;
     if (fieldText->isComb()) {
@@ -3726,12 +3722,7 @@ void AnnotWidget::drawFormFieldChoice(GfxFontDict *fontDict, GooString *da) {
   VariableTextQuadding quadding;
   FormFieldChoice *fieldChoice = static_cast<FormFieldChoice *>(field);
 
-  if (Form::fieldLookup(fieldDict, "Q", &obj1)->isInt()) {
-    quadding = static_cast<VariableTextQuadding>(obj1.getInt());
-  } else {
-    quadding = form->getTextQuadding();
-  }
-  obj1.free();
+  quadding = field->hasTextQuadding() ? field->getTextQuadding() : form->getTextQuadding();
 
   if (fieldChoice->isCombo()) {
     if (Form::fieldLookup(fieldDict, "V", &obj1)->isString()) {
@@ -3799,14 +3790,9 @@ void AnnotWidget::generateFieldAppearance() {
   }
   obj1.free();
 
-  if (Form::fieldLookup(fieldDict, "DA", &obj1)->isString()) {
-    da = obj1.getString()->copy();
-    //TODO: look for a font size / name HERE
-    // => create a function
-  } else {
-    da = form->getDefaultAppearance()->copy();
-  }
-  obj1.free();
+  da = field->getDefaultAppearance();
+  if (!da)
+    da = form->getDefaultAppearance();
 
   // draw the field contents
   switch (field->getType()) {
@@ -3827,10 +3813,6 @@ void AnnotWidget::generateFieldAppearance() {
     error(-1, "Unknown field type");
   }
 
-  if (da) {
-    delete da;
-  }
-
   // build the appearance stream dictionary
   appearDict.initDict(xref);
   appearDict.dictAdd(copyString("Length"),
diff --git a/poppler/Form.cc b/poppler/Form.cc
index d7c094d..370b82c 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -790,6 +790,10 @@ FormField::FormField(XRef* xrefA, Object *aobj, const Ref& aref, std::set<int> *
   terminal = false;
   widgets = NULL;
   readOnly = false;
+  defaultAppearance = NULL;
+  quadding = quaddingLeftJustified;
+  hasQuadding = gFalse;
+
   ref = aref;
 
   Object obj1;
@@ -869,6 +873,17 @@ FormField::FormField(XRef* xrefA, Object *aobj, const Ref& aref, std::set<int> *
     }
   }
   obj1.free();
+
+  // Variable Text
+  if (Form::fieldLookup(dict, "DA", &obj1)->isString())
+    defaultAppearance = obj1.getString()->copy();
+  obj1.free();
+
+  if (Form::fieldLookup(dict, "Q", &obj1)->isInt()) {
+    quadding = static_cast<VariableTextQuadding>(obj1.getInt());
+    hasQuadding = gTrue;
+  }
+  obj1.free();
 }
 
 FormField::~FormField()
@@ -885,6 +900,8 @@ FormField::~FormField()
     gfree (widgets);
   }
   obj.free();
+
+  delete defaultAppearance;
 }
 
 void FormField::loadChildrenDefaults ()
diff --git a/poppler/Form.h b/poppler/Form.h
index b5291a4..af913c4 100644
--- a/poppler/Form.h
+++ b/poppler/Form.h
@@ -283,6 +283,10 @@ public:
   void setReadOnly (bool b) { readOnly = b; }
   bool isReadOnly () const { return readOnly; }
 
+  GooString* getDefaultAppearance() const { return defaultAppearance; }
+  GBool hasTextQuadding() const { return hasQuadding; }
+  VariableTextQuadding getTextQuadding() const { return quadding; }
+
   FormWidget* findWidgetByRef (Ref aref);
   // Since while loading their defaults, children may call parents methods, it's better
   // to do that when parents are completly constructed
@@ -305,6 +309,11 @@ public:
   FormWidget **widgets;
   bool readOnly;
 
+  // Variable Text
+  GooString *defaultAppearance;
+  GBool hasQuadding;
+  VariableTextQuadding quadding;
+
 private:
   FormField() {}
 };
commit 8677a34911563a712b2dcf0b6e411cee0bad9c44
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Mon Mar 7 18:24:07 2011 +0100

    forms: Parse default variable text entries (DA, Q) on Form construction
    
    And use them from AnnotWidget instead of parsing the acroForm dictionary
    again.

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index d6d3b2f..554d36e 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -3164,16 +3164,16 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxFontDict *fontDict
 
       // compute text start position
       switch (quadding) {
-        case fieldQuadLeft:
-        default:
-          x = borderWidth + 2;
-          break;
-        case fieldQuadCenter:
-          x = (rect->x2 - rect->x1 - w) / 2;
-          break;
-        case fieldQuadRight:
-          x = rect->x2 - rect->x1 - borderWidth - 2 - w;
-          break;
+      case quaddingLeftJustified:
+      default:
+        x = borderWidth + 2;
+        break;
+      case quaddingCentered:
+        x = (rect->x2 - rect->x1 - w) / 2;
+        break;
+      case quaddingRightJustified:
+        x = rect->x2 - rect->x1 - borderWidth - 2 - w;
+        break;
       }
 
       // draw the line
@@ -3218,16 +3218,16 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxFontDict *fontDict
 
       // compute starting text cell
       switch (quadding) {
-        case fieldQuadLeft:
-        default:
+      case quaddingLeftJustified:
+      default:
           x = borderWidth;
-          break;
-        case fieldQuadCenter:
-          x = borderWidth + (comb - charCount) / 2 * w;
-          break;
-        case fieldQuadRight:
-          x = borderWidth + (comb - charCount) * w;
-          break;
+        break;
+      case quaddingCentered:
+        x = borderWidth + (comb - charCount) / 2 * w;
+        break;
+      case quaddingRightJustified:
+        x = borderWidth + (comb - charCount) * w;
+        break;
       }
       y = 0.5 * (rect->y2 - rect->y1) - 0.4 * fontSize;
 
@@ -3309,16 +3309,16 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxFontDict *fontDict
       // compute text start position
       w *= fontSize;
       switch (quadding) {
-        case fieldQuadLeft:
-        default:
-          x = borderWidth + 2;
-          break;
-        case fieldQuadCenter:
-          x = (rect->x2 - rect->x1 - w) / 2;
-          break;
-        case fieldQuadRight:
-          x = rect->x2 - rect->x1 - borderWidth - 2 - w;
-          break;
+      case quaddingLeftJustified:
+      default:
+        x = borderWidth + 2;
+        break;
+      case quaddingCentered:
+        x = (rect->x2 - rect->x1 - w) / 2;
+        break;
+      case quaddingRightJustified:
+        x = rect->x2 - rect->x1 - borderWidth - 2 - w;
+        break;
       }
       y = 0.5 * (rect->y2 - rect->y1) - 0.4 * fontSize;
 
@@ -3483,16 +3483,16 @@ void AnnotWidget::drawListBox(FormFieldChoice *fieldChoice,
     layoutText(fieldChoice->getChoice(i), convertedText, &j, font, &w, 0.0, NULL, gFalse);
     w *= fontSize;
     switch (quadding) {
-      case fieldQuadLeft:
-      default:
-        x = borderWidth + 2;
-        break;
-      case fieldQuadCenter:
-        x = (rect->x2 - rect->x1 - w) / 2;
-        break;
-      case fieldQuadRight:
-        x = rect->x2 - rect->x1 - borderWidth - 2 - w;
-        break;
+    case quaddingLeftJustified:
+    default:
+      x = borderWidth + 2;
+      break;
+    case quaddingCentered:
+      x = (rect->x2 - rect->x1 - w) / 2;
+      break;
+    case quaddingRightJustified:
+      x = rect->x2 - rect->x1 - borderWidth - 2 - w;
+      break;
     }
 
     // set the font matrix
@@ -3697,15 +3697,15 @@ void AnnotWidget::drawFormFieldButton(GfxFontDict *fontDict, GooString *da) {
 
 void AnnotWidget::drawFormFieldText(GfxFontDict *fontDict, GooString *da) {
   Object obj1, obj2;
-  int quadding;
+  VariableTextQuadding quadding;
   Dict *fieldDict = field->getObj()->getDict();
   FormFieldText *fieldText = static_cast<FormFieldText *>(field);
 
   if (Form::fieldLookup(fieldDict, "V", &obj1)->isString()) {
     if (Form::fieldLookup(fieldDict, "Q", &obj2)->isInt())
-      quadding = obj2.getInt();
+      quadding = static_cast<VariableTextQuadding>(obj2.getInt());
     else
-      quadding = fieldQuadLeft;
+      quadding = form->getTextQuadding();
     obj2.free();
 
     int comb = 0;
@@ -3723,13 +3723,13 @@ void AnnotWidget::drawFormFieldText(GfxFontDict *fontDict, GooString *da) {
 void AnnotWidget::drawFormFieldChoice(GfxFontDict *fontDict, GooString *da) {
   Object obj1;
   Dict *fieldDict = field->getObj()->getDict();
-  int quadding;
+  VariableTextQuadding quadding;
   FormFieldChoice *fieldChoice = static_cast<FormFieldChoice *>(field);
 
   if (Form::fieldLookup(fieldDict, "Q", &obj1)->isInt()) {
-    quadding = obj1.getInt();
+    quadding = static_cast<VariableTextQuadding>(obj1.getInt());
   } else {
-    quadding = fieldQuadLeft;
+    quadding = form->getTextQuadding();
   }
   obj1.free();
 
@@ -3799,17 +3799,12 @@ void AnnotWidget::generateFieldAppearance() {
   }
   obj1.free();
 
-  // get the default appearance string
-  if (Form::fieldLookup(fieldDict, "DA", &obj1)->isNull()) {
-    obj1.free();
-    acroForm->lookup("DA", &obj1);
-  }
-  if (obj1.isString()) {
+  if (Form::fieldLookup(fieldDict, "DA", &obj1)->isString()) {
     da = obj1.getString()->copy();
     //TODO: look for a font size / name HERE
     // => create a function
   } else {
-    da = NULL;
+    da = form->getDefaultAppearance()->copy();
   }
   obj1.free();
 
diff --git a/poppler/Form.cc b/poppler/Form.cc
index 09848b2..d7c094d 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -1230,11 +1230,21 @@ Form::Form(XRef *xrefA, Object* acroFormA)
   size = 0;
   numFields = 0;
   rootFields = NULL;
+  quadding = quaddingLeftJustified;
+  defaultAppearance = NULL;
 
   acroForm->dictLookup("NeedAppearances", &obj1);
   needAppearances = (obj1.isBool() && obj1.getBool());
   obj1.free();
 
+  if (acroForm->dictLookup("DA", &obj1)->isString())
+    defaultAppearance = obj1.getString()->copy();
+  obj1.free();
+
+  if (acroForm->dictLookup("Q", &obj1)->isInt())
+    quadding = static_cast<VariableTextQuadding>(obj1.getInt());
+  obj1.free();
+
   acroForm->dictLookup("Fields", &obj1);
   if (obj1.isArray()) {
     Array *array = obj1.getArray();
@@ -1280,6 +1290,7 @@ Form::~Form() {
   for(i = 0; i< numFields; ++i)
     delete rootFields[i];
   gfree (rootFields);
+  delete defaultAppearance;
 }
 
 // Look up an inheritable field dictionary entry.
diff --git a/poppler/Form.h b/poppler/Form.h
index f3938d1..b5291a4 100644
--- a/poppler/Form.h
+++ b/poppler/Form.h
@@ -45,6 +45,12 @@ enum FormButtonType {
   formButtonRadio
 };
 
+enum VariableTextQuadding {
+  quaddingLeftJustified,
+  quaddingCentered,
+  quaddingRightJustified
+};
+
 class Form;
 class FormField;
 class FormFieldButton;
@@ -463,6 +469,8 @@ public:
   GBool getNeedAppearances () const { return needAppearances; }
   int getNumFields() const { return numFields; }
   FormField* getRootField(int i) const { return rootFields[i]; }
+  GooString* getDefaultAppearance() const { return defaultAppearance; }
+  VariableTextQuadding getTextQuadding() const { return quadding; }
 
   FormWidget* findWidgetByRef (Ref aref);
 
@@ -474,6 +482,10 @@ private:
   XRef* xref;
   Object *acroForm;
   GBool needAppearances;
+
+  // Variable Text
+  GooString *defaultAppearance;
+  VariableTextQuadding quadding;
 };
 
 //------------------------------------------------------------------------


More information about the poppler mailing list