summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2021-10-28 17:20:36 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2021-10-29 14:40:01 +0200
commit80afffed57564e40854c1bb8a539fdc3c22b9684 (patch)
tree80739c74001bad27ca2943aedeccd9ac662f4dfd /vcl
parent19c611f3275de7ffc47e517ad1f3141695fa83fb (diff)
tdf#145274: vcl_pdfexport: Add unittest
Exporting to PDF was the only way I could find to test this issue Change-Id: Id2af0f98b505c49ad912e74477d7bb5246cf850c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124341 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/qa/cppunit/pdfexport/data/tdf145274.docxbin0 -> 3788 bytes
-rw-r--r--vcl/qa/cppunit/pdfexport/pdfexport.cxx45
2 files changed, 45 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf145274.docx b/vcl/qa/cppunit/pdfexport/data/tdf145274.docx
new file mode 100644
index 000000000000..5b3b6afecfec
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/tdf145274.docx
Binary files differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index ad19395c5669..73ef63661236 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -1150,6 +1150,51 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf115117_2a)
#endif
}
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf145274)
+{
+ // Import the bugdoc and export as PDF.
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf145274.docx";
+ mxComponent = loadFromDesktop(aURL);
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ utl::MediaDescriptor aMediaDescriptor;
+ aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+ xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+
+ // Parse the export result with pdfium.
+ SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
+ SvMemoryStream aMemory;
+ aMemory.WriteStream(aFile);
+ std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get();
+ std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument
+ = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize());
+ CPPUNIT_ASSERT(pPdfDocument);
+
+ CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
+
+ auto pPage = pPdfDocument->openPage(0);
+ CPPUNIT_ASSERT(pPage);
+
+ int nPageObjectCount = pPage->getObjectCount();
+
+ // Without the fix in place, this test would have failed with
+ // - Expected: 6
+ // - Actual : 4
+ CPPUNIT_ASSERT_EQUAL(6, nPageObjectCount);
+
+ auto pTextPage = pPage->getTextPage();
+
+ for (int i = 0; i < nPageObjectCount; ++i)
+ {
+ std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPage->getObject(i);
+ if (pPageObject->getType() != vcl::pdf::PDFPageObjectType::Text)
+ continue;
+
+ CPPUNIT_ASSERT_EQUAL(11.0, pPageObject->getFontSize());
+ CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFTextRenderMode::Fill, pPageObject->getTextRenderMode());
+ CPPUNIT_ASSERT_EQUAL(COL_RED, pPageObject->getFillColor());
+ }
+}
+
/// Test writing ToUnicode CMAP for doubly encoded glyphs.
CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf66597_1)
{