vcl/qa/cppunit/pdfexport/data/tdf141171.odt |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx      |   55 ++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)

New commits:
commit 71f3980e40454907ee7e512678635eb48d9a4058
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Tue Mar 23 10:44:12 2021 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Mar 24 08:38:37 2021 +0100

    tdf#141171: vcl_pdfexport: Add unittest
    
    Change-Id: Ic577103b84afc97dfe9042b3b0a20988b8083e54
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112974
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>
    Tested-by: Jenkins

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf141171.odt 
b/vcl/qa/cppunit/pdfexport/data/tdf141171.odt
new file mode 100644
index 000000000000..951f69541a01
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf141171.odt differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 1074e0d1aa95..75832ec20324 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -1813,6 +1813,61 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf121615)
     CPPUNIT_ASSERT_EQUAL(COL_BLACK, aBitmap.GetPixelColor(199, 299));
 }
 
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf141171)
+{
+    vcl::filter::PDFDocument aDocument;
+    load(u"tdf141171.odt", aDocument);
+
+    // The document has one page.
+    std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size());
+
+    // Get access to the only image on the only page.
+    vcl::filter::PDFObjectElement* pResources = 
aPages[0]->LookupObject("Resources");
+    CPPUNIT_ASSERT(pResources);
+    auto pXObjects
+        = 
dynamic_cast<vcl::filter::PDFDictionaryElement*>(pResources->Lookup("XObject"));
+    CPPUNIT_ASSERT(pXObjects);
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pXObjects->GetItems().size());
+    vcl::filter::PDFObjectElement* pXObject
+        = pXObjects->LookupObject(pXObjects->GetItems().begin()->first);
+    CPPUNIT_ASSERT(pXObject);
+    vcl::filter::PDFStreamElement* pStream = pXObject->GetStream();
+    CPPUNIT_ASSERT(pStream);
+    SvMemoryStream& rObjectStream = pStream->GetMemory();
+
+    // Load the embedded image.
+    rObjectStream.Seek(0);
+    GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
+    Graphic aGraphic;
+    sal_uInt16 format;
+    ErrCode bResult = rFilter.ImportGraphic(aGraphic, OUString("import"), 
rObjectStream,
+                                            GRFILTER_FORMAT_DONTKNOW, &format);
+    CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
+
+    // The image should be grayscale 8bit JPEG.
+    sal_uInt16 jpegFormat = 
rFilter.GetImportFormatNumberForShortName(JPG_SHORTNAME);
+    CPPUNIT_ASSERT(jpegFormat != GRFILTER_FORMAT_NOTFOUND);
+    CPPUNIT_ASSERT_EQUAL(jpegFormat, format);
+    BitmapEx aBitmap = aGraphic.GetBitmapEx();
+    Size aSize = aBitmap.GetSizePixel();
+    CPPUNIT_ASSERT_EQUAL(tools::Long(878), aSize.Width());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(127), aSize.Height());
+    CPPUNIT_ASSERT_EQUAL(8, int(aBitmap.GetBitCount()));
+
+    for (tools::Long nX = 0; nX < aSize.Width(); ++nX)
+    {
+        for (tools::Long nY = 0; nY < aSize.Height(); ++nY)
+        {
+            // Check all pixels in the image are white
+            // Without the fix in place, this test would have failed with
+            // - Expected: Color: R:255 G:255 B:255 A:0
+            // - Actual  : Color: R:0 G:0 B:0 A:0
+            CPPUNIT_ASSERT_EQUAL(COL_WHITE, aBitmap.GetPixelColor(nX, nY));
+        }
+    }
+}
+
 CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf129085)
 {
     vcl::filter::PDFDocument aDocument;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to