summaryrefslogtreecommitdiff
path: root/vcl/qa
diff options
context:
space:
mode:
authorAdam Seskunas <adamseskunas@gmail.com>2023-12-04 09:51:06 -0800
committerXisco Fauli <xiscofauli@libreoffice.org>2023-12-12 10:15:05 +0100
commit380081381ff3b3cae64a40c6cc2a82772cb663c1 (patch)
tree1f3c9dae7fabbaa4f67e4859b85a1fbc3cec93a2 /vcl/qa
parent0746d13365139c356eb9d297a358c486bf47d6fb (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/qa')
-rw-r--r--vcl/qa/cppunit/pdfexport/data/tdf113866.odtbin0 -> 9786 bytes
-rw-r--r--vcl/qa/cppunit/pdfexport/pdfexport2.cxx47
2 files changed, 47 insertions, 0 deletions
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
--- /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 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();