diff options
author | Adam Seskunas <adamseskunas@gmail.com> | 2023-12-04 09:51:06 -0800 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-12-12 10:15:05 +0100 |
commit | 380081381ff3b3cae64a40c6cc2a82772cb663c1 (patch) | |
tree | 1f3c9dae7fabbaa4f67e4859b85a1fbc3cec93a2 /vcl | |
parent | 0746d13365139c356eb9d297a358c486bf47d6fb (diff) |
tdf#113866 Add test.
Test if font color persists when exporting to pdf *and*
Print Text in Black is true.
Change-Id: I20ccc59cad2e5c7b5d52c69673675fed61a76080
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160321
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/CppunitTest_vcl_pdfexport2.mk | 10 | ||||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/data/tdf113866.odt | bin | 0 -> 9786 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport2.cxx | 47 |
3 files changed, 57 insertions, 0 deletions
diff --git a/vcl/CppunitTest_vcl_pdfexport2.mk b/vcl/CppunitTest_vcl_pdfexport2.mk index 5574f515a7b0..1e3c3dc3b81c 100644 --- a/vcl/CppunitTest_vcl_pdfexport2.mk +++ b/vcl/CppunitTest_vcl_pdfexport2.mk @@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_use_libraries,vcl_pdfexport2, \ cppuhelper \ sal \ subsequenttest \ + sw \ test \ unotest \ utl \ @@ -32,9 +33,18 @@ $(eval $(call gb_CppunitTest_use_libraries,vcl_pdfexport2, \ $(eval $(call gb_CppunitTest_use_externals,vcl_pdfexport2, \ boost_headers \ + libxml2 \ $(if $(filter PDFIUM,$(BUILD_TYPE)),pdfium) \ )) +$(eval $(call gb_CppunitTest_set_include,vcl_pdfexport2,\ + -I$(SRCDIR)/sw/inc \ + -I$(SRCDIR)/sw/source/core/inc \ + -I$(SRCDIR)/sw/source/uibase/inc \ + -I$(SRCDIR)/sw/qa/inc \ + $$(INCLUDE) \ +)) + $(eval $(call gb_CppunitTest_use_sdk_api,vcl_pdfexport2)) $(eval $(call gb_CppunitTest_use_ure,vcl_pdfexport2)) diff --git a/vcl/qa/cppunit/pdfexport/data/tdf113866.odt b/vcl/qa/cppunit/pdfexport/data/tdf113866.odt Binary files differnew file mode 100644 index 000000000000..499bf4449a7e --- /dev/null +++ b/vcl/qa/cppunit/pdfexport/data/tdf113866.odt diff --git a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx index 8abb9dbe0fc6..deffb16785ce 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx @@ -38,6 +38,11 @@ #include <unotools/streamwrap.hxx> #include <rtl/math.hxx> #include <o3tl/string_view.hxx> +#include <IDocumentDeviceAccess.hxx> +#include <printdata.hxx> +#include <unotxdoc.hxx> +#include <doc.hxx> +#include <docsh.hxx> #include <vcl/filter/PDFiumLibrary.hxx> #include <comphelper/propertyvalue.hxx> @@ -4851,6 +4856,48 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf156528) bounds.getHeight(), 1); } +CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf113866) +{ + loadFromURL(u"tdf113866.odt"); + + // Set -- Printer Settings->Options->Print text in Black -- to true + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); + IDocumentDeviceAccess& rDocAccess = pDoc->getIDocumentDeviceAccess(); + SwPrintData aDocPrintData = rDocAccess.getPrintData(); + aDocPrintData.SetPrintBlackFont(true); + rDocAccess.setPrintData(aDocPrintData); + + // Export to pdf + aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + + // Parse the export result with pdfium. + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport(); + + // Non-NULL pPdfDocument means pdfium is available. + if (pPdfDocument != nullptr) + { + std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(0); + CPPUNIT_ASSERT(pPdfPage); + + int nPageObjectCount = pPdfPage->getObjectCount(); + for (int i = 0; i < nPageObjectCount; ++i) + { + std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPdfPage->getObject(i); + + if (pPageObject->getType() == vcl::pdf::PDFPageObjectType::Text) + // Without the bug fix in place the test will fail with + // - Expected: rgba[008000ff] + // - Actual : rgba[000000ff] + // With the bug fixed, the green text in the test doc will stay green, + // when exported to pdf, while Print Text in Black is true + CPPUNIT_ASSERT_EQUAL(COL_GREEN, pPageObject->getFillColor()); + } + } +} + } // end anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); |