From 742977f943b30638427d1ef6532acbc3d1c36bff Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Thu, 13 Apr 2017 15:28:20 -0400 Subject: Add embeddertest for form text rendering and saving MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL adds an embeddertest that adds text to a textfield and saves it. It also adds a new 'charcode' option for .evt files in pdfium_test. Change-Id: I14fbf50e2b1d5ae0bdc68d1dd25dc4f889c49bfb Reviewed-on: https://pdfium-review.googlesource.com/4150 Commit-Queue: Nicolás Peña Commit-Queue: dsinclair Reviewed-by: Tom Sepez Reviewed-by: dsinclair --- testing/resources/text_form.in | 57 ++++++++++++++++++++++++++++++++++ testing/resources/text_form.pdf | 69 +++++++++++++++++++++++++++++++++++++++++ testing/test_support.cpp | 17 ++++++++++ testing/test_support.h | 6 ++++ 4 files changed, 149 insertions(+) create mode 100644 testing/resources/text_form.in create mode 100644 testing/resources/text_form.pdf (limited to 'testing') diff --git a/testing/resources/text_form.in b/testing/resources/text_form.in new file mode 100644 index 0000000000..4872986af1 --- /dev/null +++ b/testing/resources/text_form.in @@ -0,0 +1,57 @@ +{{header}} +{{object 1 0}} +<< + /Type /Catalog + /Pages 2 0 R + /AcroForm << /Fields [ 4 0 R ] /DR 5 0 R >> +>> +endobj +{{object 2 0}} +<< /Count 1 /Kids [ 3 0 R ] /Type /Pages >> +endobj +{{object 3 0}} +<< + /Type /Page + /Parent 2 0 R + /Resources 5 0 R + /MediaBox [ 0 0 300 300 ] + /Contents 8 0 R + /Annots [ 4 0 R ] +>> +endobj +{{object 4 0}} +<< + /Type /Annot + /FT /Tx + /T (Text Box) + /DA (0 0 0 rg /F1 12 Tf) + /Rect [ 100 100 200 130 ] + /Subtype /Widget +>> +endobj +{{object 5 0}} +<< /Font 6 0 R >> +endobj +{{object 6 0}} +<< /F1 7 0 R >> +endobj +{{object 7 0}} << + /Type /Font + /Subtype /Type1 + /BaseFont /Helvetica +>> +{{object 8 0}} +<< /Length 51 >> +stream +BT +0 0 0 rg +/F1 12 Tf +100 150 Td +(Test Form) Tj +ET +endstream +endobj +{{xref}} +trailer<< /Size 8 /Root 1 0 R >> +{{startxref}} +%%EOF diff --git a/testing/resources/text_form.pdf b/testing/resources/text_form.pdf new file mode 100644 index 0000000000..f72a73567b --- /dev/null +++ b/testing/resources/text_form.pdf @@ -0,0 +1,69 @@ +%PDF-1.7 +% ò¤ô +1 0 obj +<< + /Type /Catalog + /Pages 2 0 R + /AcroForm << /Fields [ 4 0 R ] /DR 5 0 R >> +>> +endobj +2 0 obj +<< /Count 1 /Kids [ 3 0 R ] /Type /Pages >> +endobj +3 0 obj +<< + /Type /Page + /Parent 2 0 R + /Resources 5 0 R + /MediaBox [ 0 0 300 300 ] + /Contents 8 0 R + /Annots [ 4 0 R ] +>> +endobj +4 0 obj +<< + /Type /Annot + /FT /Tx + /T (Text Box) + /DA (0 0 0 rg /F1 12 Tf) + /Rect [ 100 100 200 130 ] + /Subtype /Widget +>> +endobj +5 0 obj +<< /Font 6 0 R >> +endobj +6 0 obj +<< /F1 7 0 R >> +endobj +7 0 obj << + /Type /Font + /Subtype /Type1 + /BaseFont /Helvetica +>> +8 0 obj +<< /Length 51 >> +stream +BT +0 0 0 rg +/F1 12 Tf +100 150 Td +(Test Form) Tj +ET +endstream +endobj +xref +0 9 +0000000000 65535 f +0000000015 00000 n +0000000114 00000 n +0000000173 00000 n +0000000309 00000 n +0000000445 00000 n +0000000478 00000 n +0000000509 00000 n +0000000578 00000 n +trailer<< /Size 8 /Root 1 0 R >> +startxref +678 +%%EOF diff --git a/testing/test_support.cpp b/testing/test_support.cpp index 20f1cadf09..1f527811c4 100644 --- a/testing/test_support.cpp +++ b/testing/test_support.cpp @@ -212,6 +212,23 @@ int TestSaver::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, return 1; } +// static +int TestSaver::GetBlockFromString(void* param, + unsigned long pos, + unsigned char* buf, + unsigned long size) { + std::string* new_file = static_cast(param); + if (!new_file || pos + size < pos) + return 0; + + unsigned long file_size = new_file->size(); + if (pos + size > file_size) + return 0; + + memcpy(buf, new_file->data() + pos, size); + return 1; +} + namespace pdfium { void FPDF_Test::SetUp() { diff --git a/testing/test_support.h b/testing/test_support.h index b734bc31f0..f175811078 100644 --- a/testing/test_support.h +++ b/testing/test_support.h @@ -115,6 +115,12 @@ class TestSaver : public FPDF_FILEWRITE { void ClearString(); const std::string& GetString() const { return m_String; } + protected: + static int GetBlockFromString(void* param, + unsigned long pos, + unsigned char* buf, + unsigned long size); + private: static int WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, const void* data, -- cgit v1.2.3