[poppler] Poppler try to use check/radio included AP by default (pre-patch)

Guillermo Antonio Amaral Bastidas gamaral at amaral.com.mx
Fri Jul 31 23:22:44 PDT 2009


Hi guys,

I wanted to submit this patch for review, it's still a little hard around the
edges since I`m still learning the codebase but I tried to make it fit in as
much as possible, but the idea seems solid and fixes a few bugs along the way.
I would like to get feed back on this.

The idea is simple, I have noticed that many Btn fields send there own APs,
but poppler seems to want to use the dingbat instead. In some cases this
renders a few forms useless since rendering doesn't go as planed and you get
no visible change to the field.

What this patch does is check if we are rendering a Btn that isn't a
Push button, check to see if this button contains an AP dict and that inside
that there is an N dict and use the current AS to get the propper reference
and use that instead of rendering it by hand. If something fails, it drops
back to the standard rendering procedure so no harm no fault.

* I would really like to hear from anybody that knows this area of the code.

An idea I had was to pre-render both AP states (maybe just the Yes/On state)
on non push Btns missing an AP dict and/or N dict and use them on rendering
instead of doing it when something changes. Any thoughts ?

Cheers and be kind :P,
GA

ATTACH: patch
TEST CASE: http://downloads.guillermoamaral.com/kdab/09_r100pdf_a.pdf
TEST CASE: http://downloads.guillermoamaral.com/kdab/01_ump_a_2009.pdf

-- 
gamaral
-------------- next part --------------
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 99c3731..dfd1d49 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -3023,6 +3023,40 @@ void AnnotWidget::generateFieldAppearance() {
     return;
   }
 
+  // get the field type
+  Form::fieldLookup(field, "FT", &ftObj);
+
+  // get the field flags (Ff) value
+  if (Form::fieldLookup(field, "Ff", &obj1)->isInt()) {
+    ff = obj1.getInt();
+  } else {
+    ff = 0;
+  }
+  obj1.free();
+
+  // if checkbox or radio button, try to use included AS xobjs
+  if (ftObj.isName("Btn") && !(ff & fieldFlagPushbutton)) {
+
+    if (annot->lookup("AP", &obj1)->isDict()) {
+
+      if (annot->lookup("AS", &obj2)->isName()) {
+
+        if (obj1.dictLookup("N", &obj3)->isDict()) {
+          Object obj4;
+
+          if (obj3.dictLookupNF(obj2.getName(), &obj4)->isRef()) {
+            obj4.copy(&appearance);
+            return;
+          }
+          obj4.free();
+        }
+        obj3.free();
+      }
+      obj2.free();
+    }
+    obj1.free();
+  }
+
   appearBuf = new GooString ();
   // get the appearance characteristics (MK) dictionary
   if (annot->lookup("MK", &mkObj)->isDict()) {
@@ -3041,17 +3075,6 @@ void AnnotWidget::generateFieldAppearance() {
     obj1.free();
   }
 
-  // get the field type
-  Form::fieldLookup(field, "FT", &ftObj);
-
-  // get the field flags (Ff) value
-  if (Form::fieldLookup(field, "Ff", &obj1)->isInt()) {
-    ff = obj1.getInt();
-  } else {
-    ff = 0;
-  }
-  obj1.free();
-
   // draw the border
   if (mkDict && border) {
     w = border->getWidth();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/poppler/attachments/20090731/4ff437ad/attachment.pgp 


More information about the poppler mailing list