[poppler] poppler/Form.cc qt5/tests

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Nov 2 12:14:05 UTC 2018


 poppler/Form.cc           |    6 +++---
 qt5/tests/CMakeLists.txt  |    1 +
 qt5/tests/check_forms.cpp |   43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 3 deletions(-)

New commits:
commit 91fa06ee9279c8ec9569f06c7ec871dd592c49e5
Author: Nelson Benítez León <nbenitezl at gmail.com>
Date:   Mon Oct 29 22:48:08 2018 +0500

    Form.cc: fix checkbox lacking /AP cannot change state
    
    When a checkbox had no /AP key (which is not mandatory)
    poppler was silently ignoring the setState() call that
    changes the checked/unchecked state.
    
    Fixed by using getOnStr() instead of accessing onStr
    directly, as the former has code in place to return
    correct values when the field is a checkbox and has
    no names for the On/Off states (as a result of not
    having the /AP key which could contain those names).
    
    A testcase is included. An example definition of an
    affected checkbox follows:
    
    /F 4
    /FT /Btn
    /H /P
    /MK /BC [1,0,0] /BG [1,1,1] /CA (4)
    /Q 0
    /Rect [235.277,654.247,249.224,668.194]
    /Subtype /Widget
    /T (basiccheckbox)
    /Type /Annot
    /V /Off
    
    Fixes issue #655

diff --git a/poppler/Form.cc b/poppler/Form.cc
index 50ed0120..3f6f3ff4 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -235,16 +235,16 @@ void FormWidgetButton::setState (bool astate)
     return;
 
   // Silently return if can't set ON state
-  if (astate && !onStr)
+  if (astate && !getOnStr())
     return;
 
-  parent()->setState(astate ? onStr->getCString() : (char *)"Off");
+  parent()->setState(astate ? getOnStr() : (char *)"Off");
   // Parent will call setAppearanceState()
 }
 
 bool FormWidgetButton::getState () const
 {
-  return onStr ? parent()->getState(onStr->getCString()) : false;
+  return getOnStr() ? parent()->getState( getOnStr() ) : false;
 }
 
 FormFieldButton *FormWidgetButton::parent() const
diff --git a/qt5/tests/CMakeLists.txt b/qt5/tests/CMakeLists.txt
index af8de6ef..7fda2687 100644
--- a/qt5/tests/CMakeLists.txt
+++ b/qt5/tests/CMakeLists.txt
@@ -62,6 +62,7 @@ qt5_add_qtest(check_qt5_links check_links.cpp)
 qt5_add_qtest(check_qt5_annotations check_annotations.cpp)
 qt5_add_qtest(check_qt5_metadata check_metadata.cpp)
 qt5_add_qtest(check_qt5_optcontent check_optcontent.cpp)
+qt5_add_qtest(check_qt5_forms check_forms.cpp)
 qt5_add_qtest(check_qt5_pagelayout check_pagelayout.cpp)
 qt5_add_qtest(check_qt5_pagemode check_pagemode.cpp)
 qt5_add_qtest(check_qt5_password check_password.cpp)
diff --git a/qt5/tests/check_forms.cpp b/qt5/tests/check_forms.cpp
new file mode 100644
index 00000000..3c0ecf8b
--- /dev/null
+++ b/qt5/tests/check_forms.cpp
@@ -0,0 +1,43 @@
+#include <QtTest/QtTest>
+
+#include <poppler-qt5.h>
+#include <poppler-form.h>
+#include <Form.h>
+
+class TestForms: public QObject
+{
+    Q_OBJECT
+private slots:
+    void testCheckbox();// Test for issue #655
+};
+
+void TestForms::testCheckbox()
+{
+    // Test for checkbox issue #655
+    QScopedPointer< Poppler::Document > document(Poppler::Document::load(TESTDATADIR "/unittestcases/latex-hyperref-checkbox-issue-655.pdf"));
+    QVERIFY( document );
+
+    QScopedPointer< Poppler::Page > page(document->page(0));
+    QVERIFY( page );
+
+    QList<Poppler::FormField*> forms = page->formFields();
+    QCOMPARE( forms.size(), 1 );
+
+    Poppler::FormField *form = forms.at(0);
+    QCOMPARE( form->type() , Poppler::FormField::FormButton );
+
+    Poppler::FormFieldButton *chkFormFieldButton = static_cast<Poppler::FormFieldButton *>(form);
+
+    // Test this is actually a Checkbox
+    QCOMPARE( chkFormFieldButton->buttonType() , Poppler::FormFieldButton::CheckBox );
+
+    // checkbox comes initially 'unchecked'
+    QCOMPARE( chkFormFieldButton->state() , false );
+    // let's mark it as 'checked'
+    chkFormFieldButton->setState( true );
+    // now test if it was succesfully 'checked'
+    QCOMPARE( chkFormFieldButton->state() , true );
+}
+
+QTEST_GUILESS_MAIN(TestForms)
+#include "check_forms.moc"


More information about the poppler mailing list