summaryrefslogtreecommitdiff
path: root/vcl/qa
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-05-05 11:18:30 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-05-05 13:34:04 +0200
commit92cba30d5ce45e4f4a9516a80c9fe9915add6905 (patch)
treeb95e57cbd2bfcca46799a031742aa12eb518ba2b /vcl/qa
parent17bf458c86a9130cc56fad035f81558fd91ed974 (diff)
vcl pdfium render: handle widget annotations for form fields
Note that we render the bitmaps without FPDF_ANNOT, so comments are not rendered into the bitmaps, rather we create them on top of the bitmaps in Draw, explicitly. FPDF_FFLDraw() draws content which is already an annotation, but not yet interactive content; so this just fixes "missing text", as far as the user is concerned. Verified that e.g. vcl/qa/cppunit/data/PangramAcrobatAnnotations.pdf indeed still doesn't render comments into bitmaps after this. Change-Id: I2b74d585729305cc1d3a9fefa258d4d76d1bd038 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115122 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'vcl/qa')
-rw-r--r--vcl/qa/cppunit/PDFiumLibraryTest.cxx39
-rw-r--r--vcl/qa/cppunit/data/form-fields.pdf95
2 files changed, 134 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/PDFiumLibraryTest.cxx b/vcl/qa/cppunit/PDFiumLibraryTest.cxx
index 71ed79dd59e3..707d60fd1c3b 100644
--- a/vcl/qa/cppunit/PDFiumLibraryTest.cxx
+++ b/vcl/qa/cppunit/PDFiumLibraryTest.cxx
@@ -23,6 +23,8 @@
#include <tools/stream.hxx>
#include <vcl/filter/PDFiumLibrary.hxx>
+#include <vcl/pdfread.hxx>
+#include <vcl/BitmapReadAccess.hxx>
class PDFiumLibraryTest : public test::BootstrapFixtureBase
{
@@ -38,6 +40,7 @@ class PDFiumLibraryTest : public test::BootstrapFixtureBase
void testAnnotationsMadeInAcrobat();
void testAnnotationsDifferentTypes();
void testTools();
+ void testFormFields();
CPPUNIT_TEST_SUITE(PDFiumLibraryTest);
CPPUNIT_TEST(testDocument);
@@ -47,6 +50,7 @@ class PDFiumLibraryTest : public test::BootstrapFixtureBase
CPPUNIT_TEST(testAnnotationsMadeInAcrobat);
CPPUNIT_TEST(testAnnotationsDifferentTypes);
CPPUNIT_TEST(testTools);
+ CPPUNIT_TEST(testFormFields);
CPPUNIT_TEST_SUITE_END();
};
@@ -279,6 +283,41 @@ void PDFiumLibraryTest::testAnnotationsMadeInAcrobat()
}
}
+void PDFiumLibraryTest::testFormFields()
+{
+ // Given a document with a form field that looks like plain text:
+ OUString aURL = getFullUrl(u"form-fields.pdf");
+ SvFileStream aFileStream(aURL, StreamMode::READ);
+ SvMemoryStream aMemory;
+ aMemory.WriteStream(aFileStream);
+ aMemory.Seek(0);
+
+ // When rendering its first (and only) page to a bitmap:
+ std::vector<BitmapEx> aBitmaps;
+ int nRet = vcl::RenderPDFBitmaps(aMemory.GetData(), aMemory.GetSize(), aBitmaps);
+ CPPUNIT_ASSERT(nRet);
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aBitmaps.size());
+
+ // Then make sure the bitmap contains that text:
+ Bitmap aBitmap = aBitmaps[0].GetBitmap();
+ BitmapReadAccess aAccess(aBitmap);
+ Size aSize = aBitmap.GetSizePixel();
+ std::set<sal_uInt32> aColors;
+ for (tools::Long y = 0; y < aSize.Height(); ++y)
+ {
+ for (tools::Long x = 0; x < aSize.Width(); ++x)
+ {
+ aColors.insert(static_cast<sal_uInt32>(aAccess.GetPixel(y, x)));
+ }
+ }
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected greater than: 1
+ // - Actual : 1
+ // i.e. at least black text and white background is expected (possibly more, due to
+ // anti-aliasing), but nothing was rendered.
+ CPPUNIT_ASSERT_GREATER(static_cast<size_t>(1), aColors.size());
+}
+
void PDFiumLibraryTest::testAnnotationsDifferentTypes()
{
OUString aURL = getFullUrl(u"PangramWithMultipleTypeOfAnnotations.pdf");
diff --git a/vcl/qa/cppunit/data/form-fields.pdf b/vcl/qa/cppunit/data/form-fields.pdf
new file mode 100644
index 000000000000..a014b36c9821
--- /dev/null
+++ b/vcl/qa/cppunit/data/form-fields.pdf
@@ -0,0 +1,95 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+ /Type /Catalog
+ /Pages 5 0 R
+>>
+endobj
+
+2 0 obj <<
+ /Length 0
+>>
+stream
+endstream
+endobj
+
+3 0 obj <<
+ /Font <<
+ /TT1 4 0 R
+ >>
+>>
+endobj
+
+4 0 obj <<
+ /Type /Font
+ /Subtype /Type1
+ /Name /TT1
+ /BaseFont/Helvetica
+>>
+endobj
+
+5 0 obj <<
+ /Type /Pages
+ /Kids [6 0 R]
+ /Count 1
+ /MediaBox [ 0 0 612 446 ]
+>>
+endobj
+
+6 0 obj <<
+ /Type /Page
+ /Parent 5 0 R
+ /Resources 3 0 R
+ /Contents 2 0 R
+ /Annots [7 0 R]
+>>
+endobj
+
+7 0 obj <<
+ /Type /Annot
+ /Subtype /Widget
+ /T (T)
+ /V (V)
+ /DA (/Helv 0 Tf 0 g)
+ /Rect [ 0 0 612 446 ]
+ /FT /Tx
+ /AP <<
+ /N 8 0 R
+ >>
+>>
+endobj
+
+8 0 obj <<
+ /Type /XObject
+ /Subtype /Form
+ /Matrix [1.0 0.0 0.0 1.0 0.0 0.0]
+ /Resources 3 0 R
+ /BBox [ 0 0 612 446 ]
+ /Length 55
+>>
+stream
+ BT
+ /TT1 24 Tf
+ 1 0 0 1 260 254 Tm
+ (test)Tj
+ ET
+endstream
+endobj
+xref
+0 9
+0000000000 65535 f
+0000000015 00000 n
+0000000069 00000 n
+0000000121 00000 n
+0000000174 00000 n
+0000000259 00000 n
+0000000351 00000 n
+0000000458 00000 n
+0000000616 00000 n
+trailer <<
+ /Root 1 0 R
+ /Size 9
+>>
+startxref
+836
+%%EOF