sw/qa/extras/tiledrendering/tiledrendering.cxx |   56 +++++++++++++++++++++++++
 sw/source/core/doc/notxtfrm.cxx                |    2 
 2 files changed, 57 insertions(+), 1 deletion(-)

New commits:
commit 39368fad8cc0c4fbba2cafac6d93fecd0133b725
Author:     Caolán McNamara <[email protected]>
AuthorDate: Tue Jan 13 21:22:12 2026 +0000
Commit:     Miklos Vajna <[email protected]>
CommitDate: Mon Feb 9 11:57:38 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/+/198909
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 35a84bdb3d7f..97d6e96b11bb 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -30,6 +30,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>
@@ -3861,6 +3862,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 black 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 a0a992982a4b..58afc816b7b6 100644
--- a/sw/source/core/doc/notxtfrm.cxx
+++ b/sw/source/core/doc/notxtfrm.cxx
@@ -1397,7 +1397,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(

Reply via email to