On Wednesday, October 17, 2012 08:45:05 PM Fabio D'Urso wrote:
> On Wednesday, October 17, 2012 08:51:37 AM Adam Reichold wrote:
> > Just noticed something odd: When I save a modified copy of a PDF file
> > with a custom text entered into a combo box form field and reload it,
> > the new file still shows the custom text but
> > FormWidgetChoice::getEditChoice returns a null string...
> >
> > Could this be a problem with the parsing in FormFieldChoice?
>
> Seems like it's not been implemented.
>
> In FormFieldChoice::FormFieldChoice (poppler/Form.cc), editedChoice is
> initially assigned NULL and never changed.
> I think it should be given the value in /V if /V is a string and doesn't
> match any of the predefined choices. Note that the piece of code that
> parses /V is one of the things that I'm working on (thread: "Patches for
> form choice fields").
>
> By the way, I noticed that FormFieldChoice::setEditChoice internally calls 
> unselectAll to deselect predefined options. Maybe select/selectAll/etc.. 
> should similarly set editedChoice to NULL?

Patches attached, to be applied on top those from that thread (these ones: 
http://lists.freedesktop.org/archives/poppler/2012-November/009729.html ).

In detail:

== 0001-FormFieldChoice-ctor-Stop-scanning-if-V-is-a-string-.patch ==

Pretty straightforward patch that prepares FormFieldChoice::FormFieldChoice 
for the next patch. It also adds a break that avoids unnecessary loop 
iterations.

== 0002-FormFieldChoice-ctor-Added-support-to-recognize-user.patch ==

This patch fixes the problem reported by Adam
( http://lists.freedesktop.org/archives/poppler/2012-October/009688.html )
by doing exactly what I've described in the previous message (the "I think it 
should be given" part).

== 0003-Editable-FormFieldChoice-Clear-editedChoice-when-one.patch ==

This patch fixes the issue I've described in the previous message (the "By the 
way" part). Without it, it's impossible to select a predefined option after a 
custom value has been entered.

Once again, these three patches must be applied on top of the ones from the 
other thread, which are currently waiting for Carlos' review.

In the meantime, please let me know if there's any other issue you've noticed.

Thank you,
Fabio
From e1c5c043663fe278e3ce63c2db35809c561a1f2e Mon Sep 17 00:00:00 2001
From: Fabio D'Urso <[email protected]>
Date: Wed, 31 Oct 2012 19:56:37 +0100
Subject: [PATCH 1/3] FormFieldChoice ctor: Stop scanning if /V is a string
 and the corresponding option has been identified

---
 poppler/Form.cc |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

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++) {
-- 
1.7.6.5

From 205e6318b5b5885ec95df78f38c609b558f3a222 Mon Sep 17 00:00:00 2001
From: Fabio D'Urso <[email protected]>
Date: Thu, 1 Nov 2012 00:58:51 +0100
Subject: [PATCH 2/3] FormFieldChoice ctor: Added support to recognize user
 strings as /V value

Fixes http://lists.freedesktop.org/archives/poppler/2012-October/009688.html
---
 poppler/Form.cc |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

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++) {
-- 
1.7.6.5

From 2823e90d9d7f64853d16c436203f75fd1a1c9f67 Mon Sep 17 00:00:00 2001
From: Fabio D'Urso <[email protected]>
Date: Fri, 2 Nov 2012 01:53:24 +0100
Subject: [PATCH 3/3] 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.
---
 poppler/Form.cc |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

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();
 }
-- 
1.7.6.5

_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to