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>
diff --git a/vcl/CppunitTest_vcl_pdfexport2.mk b/vcl/CppunitTest_vcl_pdfexport2.mk
index 5574f51..1e3c3dc 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
new file mode 100644
index 0000000..499bf44
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/tdf113866.odt
Binary files differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx
index 8abb9db..deffb16 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();