Implemented support for modifying the text appearance stream text
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index bd3aaa5..e896468 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -4856,7 +4856,7 @@
VariableTextQuadding quadding;
const GooString *contents;
- contents = fieldText->getContent();
+ contents = fieldText->getAppearanceContent();
if (contents) {
quadding = fieldText->hasTextQuadding() ? fieldText->getTextQuadding() : form->getTextQuadding();
diff --git a/poppler/Form.cc b/poppler/Form.cc
index 258d235..b1231e1 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -26,6 +26,7 @@
// Copyright 2018, 2019 Nelson Benítez León <nbenitezl@gmail.com>
// Copyright 2019 Oliver Sander <oliver.sander@tu-dresden.de>
// Copyright 2019 Tomoyuki Kubota <himajin100000@gmail.com>
+// Copyright 2019 João Netto <joaonetto901@gmail.com>
//
//========================================================================
@@ -335,6 +336,11 @@
parent()->setContentCopy(new_content);
}
+void FormWidgetText::setAppearanceContent(const GooString* new_content)
+{
+ parent()->setAppearanceContentCopy(new_content);
+}
+
FormFieldText *FormWidgetText::parent() const
{
return static_cast<FormFieldText*>(field);
@@ -1147,6 +1153,7 @@
Dict* dict = obj.getDict();
Object obj1;
content = nullptr;
+ internalContent = nullptr;
multiline = password = fileSelect = doNotSpellCheck = doNotScroll = comb = richText = false;
maxLen = 0;
@@ -1214,9 +1221,21 @@
updateChildrenAppearance();
}
+void FormFieldText::setAppearanceContentCopy (const GooString* new_content)
+{
+ delete internalContent;
+ internalContent = nullptr;
+
+ if (new_content) {
+ internalContent = new_content->copy();
+ }
+ updateChildrenAppearance();
+}
+
FormFieldText::~FormFieldText()
{
delete content;
+ delete internalContent;
}
double FormFieldText::getTextFontSize()
diff --git a/poppler/Form.h b/poppler/Form.h
index 923b6c8..b6ec914 100644
--- a/poppler/Form.h
+++ b/poppler/Form.h
@@ -19,6 +19,7 @@
// Copyright 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
// Copyright 2018 Chinmoy Ranjan Pradhan <chinmoyrp65@protonmail.com>
// Copyright 2019 Oliver Sander <oliver.sander@tu-dresden.de>
+// Copyright 2019 João Netto <joaonetto901@gmail.com>
//
//========================================================================
@@ -193,6 +194,8 @@
//expects a UTF16BE string
void setContent(const GooString* new_content);
+ //sets the text inside the field appearance stream
+ void setAppearanceContent(const GooString* new_content);
void updateWidgetAppearance() override;
@@ -407,7 +410,9 @@
FormFieldText(PDFDoc *docA, Object &&dict, const Ref ref, FormField *parent, std::set<int> *usedParents);
const GooString* getContent () const { return content; }
+ const GooString* getAppearanceContent () const { return internalContent ? internalContent : content; }
void setContentCopy (const GooString* new_content);
+ void setAppearanceContentCopy (const GooString* new_content);
~FormFieldText();
bool isMultiline () const { return multiline; }
@@ -433,6 +438,7 @@
int parseDA(std::vector<GooString*>* daToks);
GooString* content;
+ GooString* internalContent;
bool multiline;
bool password;
bool fileSelect;
diff --git a/qt5/src/poppler-form.cc b/qt5/src/poppler-form.cc
index c95a962..5e37724 100644
--- a/qt5/src/poppler-form.cc
+++ b/qt5/src/poppler-form.cc
@@ -431,6 +431,14 @@
delete goo;
}
+void FormFieldText::setAppearanceText( const QString& text )
+{
+ FormWidgetText* fwt = static_cast<FormWidgetText*>(m_formData->fm);
+ GooString * goo = QStringToUnicodeGooString( text );
+ fwt->setAppearanceContent( goo );
+ delete goo;
+}
+
bool FormFieldText::isPassword() const
{
FormWidgetText* fwt = static_cast<FormWidgetText*>(m_formData->fm);
diff --git a/qt5/src/poppler-form.h b/qt5/src/poppler-form.h
index d252ff8..6b60a26 100644
--- a/qt5/src/poppler-form.h
+++ b/qt5/src/poppler-form.h
@@ -80,6 +80,9 @@
\since 0.6
*/
class POPPLER_QT5_EXPORT FormField {
+
+ friend class FormFieldData;
+
public:
/**
@@ -324,6 +327,13 @@
void setText( const QString& text );
/**
+ Sets the text inside the Appearance Stream to the specified
+ \p text
+ \since 0.80
+ */
+ void setAppearanceText( const QString& text );
+
+ /**
Whether this text field is a password input, eg its text \b must be
replaced with asterisks.
diff --git a/qt5/src/poppler-private.cc b/qt5/src/poppler-private.cc
index 8735b69..6553eb0 100644
--- a/qt5/src/poppler-private.cc
+++ b/qt5/src/poppler-private.cc
@@ -304,6 +304,11 @@
}
}
+ FormWidget *FormFieldData::getFormWidget( const FormField *f )
+ {
+ return f->m_formData->fm;
+ }
+
FormFieldIconData *FormFieldIconData::getData( const FormFieldIcon &f )
{
return f.d_ptr;
diff --git a/qt5/src/poppler-private.h b/qt5/src/poppler-private.h
index 227972d..80f6581 100644
--- a/qt5/src/poppler-private.h
+++ b/qt5/src/poppler-private.h
@@ -45,6 +45,7 @@
#include <config.h>
#include <GfxState.h>
#include <GlobalParams.h>
+#include <Form.h>
#include <PDFDoc.h>
#include <FontInfo.h>
#include <OutputDev.h>
@@ -237,6 +238,7 @@
::Page *page;
::FormWidget *fm;
QRectF box;
+ static POPPLER_QT5_EXPORT ::FormWidget *getFormWidget( const FormField *f );
};
class FormFieldIcon;
diff --git a/qt5/tests/check_forms.cpp b/qt5/tests/check_forms.cpp
index f139ed1..ac60fdc 100644
--- a/qt5/tests/check_forms.cpp
+++ b/qt5/tests/check_forms.cpp
@@ -15,6 +15,7 @@
void testCheckboxIssue159();// Test for issue #159
void testSetIcon();// Test that setIcon will always be valid.
void testSetPrintable();
+ void testSetAppearanceText();
};
void TestForms::testCheckbox()
@@ -168,5 +169,44 @@
}
}
+void TestForms::testSetAppearanceText()
+{
+ QScopedPointer< Poppler::Document > document(Poppler::Document::load(TESTDATADIR "/unittestcases/checkbox_issue_159.pdf"));
+ QVERIFY( document );
+
+ QScopedPointer< Poppler::Page > page(document->page(0));
+ QVERIFY( page );
+
+ QList<Poppler::FormField*> forms = page->formFields();
+
+ int nTextForms = 0;
+
+ Q_FOREACH (Poppler::FormField *field, forms) {
+
+ if (field->type() != Poppler::FormField::FormText)
+ continue;
+
+ nTextForms++;
+
+ Poppler::FormFieldText *fft = static_cast< Poppler::FormFieldText * >( field );
+
+ const QString textToSet = "HOLA" + fft->name();
+ fft->setAppearanceText( textToSet );
+
+ Dict *dict = Poppler::FormFieldData::getFormWidget( fft )->getObj()->getDict();
+ Object strObject = dict->lookup( "AP" ).dictLookup( "N" );
+
+ QVERIFY( strObject.isStream() );
+
+ GooString s;
+ strObject.getStream()->fillGooString(&s);
+
+ const QString textToFind = QStringLiteral("\n(%1) Tj\n").arg(textToSet);
+ QVERIFY( s.toStr().find( textToFind.toStdString() ) != std::string::npos );
+ }
+
+ QCOMPARE( nTextForms, 5 );
+}
+
QTEST_GUILESS_MAIN(TestForms)
#include "check_forms.moc"