vcl/CppunitTest_vcl_pdfexport2.mk           |   10 +++++
 vcl/qa/cppunit/pdfexport/data/tdf113866.odt |binary
 vcl/qa/cppunit/pdfexport/pdfexport2.cxx     |   47 ++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+)

New commits:
commit 380081381ff3b3cae64a40c6cc2a82772cb663c1
Author:     Adam Seskunas <adamsesku...@gmail.com>
AuthorDate: Mon Dec 4 09:51:06 2023 -0800
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Dec 12 10:15:05 2023 +0100

    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 <xiscofa...@libreoffice.org>

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
new file mode 100644
index 000000000000..499bf4449a7e
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf113866.odt differ
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();

Reply via email to