[poppler] 3 commits - poppler/Form.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Sat Nov 3 04:52:02 PDT 2012


 poppler/Form.cc |   26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

New commits:
commit f3f5a166bcd16b6f2cb516cceb2b3f41b6faf0b4
Author: Fabio D'Urso <fabiodurso at hotmail.it>
Date:   Fri Nov 2 01:53:24 2012 +0100

    Editable FormFieldChoice: Clear editedChoice when one of the predefined option is selected
    
    This patch clears the user-entered text when the user interacts with
    predefined options.

diff --git a/poppler/Form.cc b/poppler/Form.cc
index f3bf39d..78c25e3 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -1286,20 +1286,30 @@ void FormFieldChoice::unselectAll ()
 }
 
 void FormFieldChoice::deselectAll () {
+  delete editedChoice;
+  editedChoice = NULL;
+
   unselectAll();
   updateSelection();
 }
 
 void FormFieldChoice::toggle (int i)
 {
+  delete editedChoice;
+  editedChoice = NULL;
+
   choices[i].selected = !choices[i].selected;
   updateSelection();
 }
 
 void FormFieldChoice::select (int i)
 {
+  delete editedChoice;
+  editedChoice = NULL;
+
   if (!multiselect)
     unselectAll();
+
   choices[i].selected = true;
   updateSelection();
 }
commit ddcd5dc0ceecc02f0d4f740cb6c9b557dfd33c74
Author: Fabio D'Urso <fabiodurso at hotmail.it>
Date:   Thu Nov 1 00:58:51 2012 +0100

    FormFieldChoice ctor: Added support to recognize user strings as /V value
    
    Fixes http://lists.freedesktop.org/archives/poppler/2012-October/009688.html

diff --git a/poppler/Form.cc b/poppler/Form.cc
index d38f2a9..f3bf39d 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -1165,6 +1165,11 @@ FormFieldChoice::FormFieldChoice(PDFDoc *docA, Object *aobj, const Ref& ref, For
           break; // We've determined that this option is selected. No need to keep on scanning
         }
       }
+
+      // Set custom value if /V doesn't refer to any predefined option and the field is user-editable
+      if (!optionFound && edit) {
+        editedChoice = obj1.getString()->copy();
+      }
     } else if (obj1.isArray()) {
       for (int i = 0; i < numChoices; i++) {
         for (int j = 0; j < obj1.arrayGetLength(); j++) {
commit 1302bf52bba7e6446f01358240a4b5b583e196a9
Author: Fabio D'Urso <fabiodurso at hotmail.it>
Date:   Wed Oct 31 19:56:37 2012 +0100

    FormFieldChoice ctor: Stop scanning if /V is a string and the corresponding option has been identified

diff --git a/poppler/Form.cc b/poppler/Form.cc
index 586482d..d38f2a9 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -1147,16 +1147,23 @@ FormFieldChoice::FormFieldChoice(PDFDoc *docA, Object *aobj, const Ref& ref, For
     // However, if /Opt is an array of (exportVal,optionName) pairs, acroread
     // seems to expect the exportVal instead of the optionName and so we do too.
     if (Form::fieldLookup(dict, "V", &obj1)->isString()) {
+      GBool optionFound = gFalse;
+
       for (int i = 0; i < numChoices; i++) {
         if (choices[i].exportVal) {
           if (choices[i].exportVal->cmp(obj1.getString()) == 0) {
-            choices[i].selected = true;
+            optionFound = gTrue;
           }
         } else if (choices[i].optionName) {
           if (choices[i].optionName->cmp(obj1.getString()) == 0) {
-            choices[i].selected = true;
+            optionFound = gTrue;
           }
         }
+
+        if (optionFound) {
+          choices[i].selected = true;
+          break; // We've determined that this option is selected. No need to keep on scanning
+        }
       }
     } else if (obj1.isArray()) {
       for (int i = 0; i < numChoices; i++) {


More information about the poppler mailing list