sw/qa/extras/tiledrendering/tiledrendering.cxx | 56 +++++++++++++++++++++++++ sw/source/core/doc/notxtfrm.cxx | 2 2 files changed, 57 insertions(+), 1 deletion(-)
New commits: commit 36f16718b0e1d668c19e8ff10a14e43fba64dd77 Author: Caolán McNamara <[email protected]> AuthorDate: Tue Jan 13 21:22:12 2026 +0000 Commit: Caolán McNamara <[email protected]> CommitDate: Mon Feb 9 09:18:09 2026 +0100 Resolves: tdf#168710 don't use dark/light bg color when printing chart Change-Id: I0291a86744a5aa248a4174aa9e40aa646ddd0350 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197225 Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Caolán McNamara <[email protected]> diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index a55a0a9fbde0..59204db2fb55 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -31,6 +31,7 @@ #include <svx/svdview.hxx> #include <vcl/virdev.hxx> #include <vcl/filter/PngImageWriter.hxx> +#include <vcl/pdf/PDFPageObjectType.hxx> #include <editeng/editview.hxx> #include <editeng/outliner.hxx> #include <editeng/wghtitem.hxx> @@ -3882,6 +3883,61 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testSwitchingChartToDarkMode) CPPUNIT_ASSERT(nBlackPixels > nWhitePixels); } +// Toggle chart into dark mode and print as pdf. The automatic text +// color should render into pdf as blank and not as the white of +// the on-screen representation +CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testPrintDarkModeChart) +{ + addDarkLightThemes(COL_BLACK, COL_WHITE); + SwXTextDocument* pXTextDocument = createDoc("large-chart-labels.odt"); + CPPUNIT_ASSERT(pXTextDocument); + + SwView* pView = getSwDocShell()->GetView(); + uno::Reference<frame::XFrame> xFrame = pView->GetViewFrame().GetFrame().GetFrameInterface(); + uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence( + { + { "NewTheme", uno::Any(u"Dark"_ustr) }, + } + ); + comphelper::dispatchCommand(u".uno:ChangeTheme"_ustr, xFrame, aPropertyValues); + CPPUNIT_ASSERT_EQUAL("S;Dark"_ostr, pXTextDocument->getViewRenderState()); + + uno::Sequence<css::beans::PropertyValue> args{ + comphelper::makePropertyValue(u"SynchronMode"_ustr, true), + comphelper::makePropertyValue(u"URL"_ustr, maTempFile.GetURL()) + }; + dispatchCommand(mxComponent, u".uno:ExportDirectToPDF"_ustr, args); + + std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); + + if (pPDFium) + { + SvFileStream aPDFFile(maTempFile.GetURL(), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aPDFFile); + + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument + = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); + CPPUNIT_ASSERT(pPdfDocument); + CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); + + auto pPage = pPdfDocument->openPage(0); + CPPUNIT_ASSERT(pPage); + + int nPageObjectCount = pPage->getObjectCount(); + + auto pTextPage = pPage->getTextPage(); + + for (int i = 0; i < nPageObjectCount; ++i) + { + std::unique_ptr<vcl::pdf::PDFiumPageObject> pPageObject = pPage->getObject(i); + // The text should all be black. + if (pPageObject->getType() == vcl::pdf::PDFPageObjectType::Text) + CPPUNIT_ASSERT_EQUAL(COL_BLACK, pPageObject->getFillColor()); + } + } +} + CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testTdf159626_yellowPatternFill) { SwXTextDocument* pXTextDocument = createDoc("tdf159626_yellowPatternFill.docx"); diff --git a/sw/source/core/doc/notxtfrm.cxx b/sw/source/core/doc/notxtfrm.cxx index ee06d9bfeeff..6fb1d8ecb91e 100644 --- a/sw/source/core/doc/notxtfrm.cxx +++ b/sw/source/core/doc/notxtfrm.cxx @@ -1400,7 +1400,7 @@ void SwNoTextFrame::ImplPaintPictureBitmap( vcl::RenderContext* pOut, SdrModel& rModel = pPage->getSdrModelFromSdrPage(); SdrOutliner& rOutl = rModel.GetDrawOutliner(); aOldBackColor = rOutl.GetBackgroundColor(); - rOutl.SetBackgroundColor(pPage->GetPageBackgroundColor()); + rOutl.SetBackgroundColor(pPage->GetPageBackgroundColor(nullptr, !bPrn)); } bDone = paintUsingPrimitivesHelper(
