sw/qa/extras/tiledrendering/tiledrendering.cxx | 56 +++++++++++++++++++++++++ sw/source/core/doc/notxtfrm.cxx | 2 2 files changed, 57 insertions(+), 1 deletion(-)
New commits: commit 175091dff0d12ba6adc96a5a4e495dac147c643e Author: Caolán McNamara <[email protected]> AuthorDate: Tue Jan 13 21:22:12 2026 +0000 Commit: Ilmari Lauhakangas <[email protected]> CommitDate: Thu Feb 12 20:50:53 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/+/198908 Tested-by: Jenkins Reviewed-by: Adolfo Jayme Barrientos <[email protected]> (cherry picked from commit 1797ea2d05b5ed462305737af4a55cd1d94fe4ad) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199275 Reviewed-by: Dan Williams <[email protected]> Tested-by: Ilmari Lauhakangas <[email protected]> Reviewed-by: Ilmari Lauhakangas <[email protected]> Reviewed-by: Xisco Fauli <[email protected]> diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 66f433c21c44..2240014de0db 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> @@ -3884,6 +3885,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 b0a2f572a4eb..d5d6c4346053 100644 --- a/sw/source/core/doc/notxtfrm.cxx +++ b/sw/source/core/doc/notxtfrm.cxx @@ -1399,7 +1399,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(
