sw/qa/extras/tiledrendering/data/large-chart-labels.odt |binary sw/qa/extras/tiledrendering/tiledrendering.cxx | 76 ++++++++++++++-- 2 files changed, 68 insertions(+), 8 deletions(-)
New commits: commit 2bacabc61f0b9b21523d7e77371cf29228a9a394 Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Wed Jan 31 21:21:04 2024 +0000 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Mon Feb 5 15:29:24 2024 +0100 add a test to detect incorrect text color in dark mode chart rendering Change-Id: I89e238dab58ffe36021520ad0fdce38e31a616e0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162868 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> (cherry picked from commit a9044a4b1de467519bec798500f3bf3d0d154f85) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162979 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sw/qa/extras/tiledrendering/data/large-chart-labels.odt b/sw/qa/extras/tiledrendering/data/large-chart-labels.odt new file mode 100644 index 000000000000..35b26e866a33 Binary files /dev/null and b/sw/qa/extras/tiledrendering/data/large-chart-labels.odt differ diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 8f52f59211cc..8dccfeb9271a 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -32,6 +32,7 @@ #include <svx/svdpage.hxx> #include <svx/svdview.hxx> #include <vcl/virdev.hxx> +#include <vcl/filter/PngImageWriter.hxx> #include <editeng/editview.hxx> #include <editeng/outliner.hxx> #include <editeng/wghtitem.hxx> @@ -1746,8 +1747,8 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testGetViewRenderState) CPPUNIT_ASSERT_EQUAL("PS;Default"_ostr, pXTextDocument->getViewRenderState()); } -// Helper function to get a tile to a bitmap and check the pixel color -static void assertTilePixelColor(SwXTextDocument* pXTextDocument, int nPixelX, int nPixelY, Color aColor) +// Helper function to get a tile to a bitmap +static Bitmap getTile(SwXTextDocument* pXTextDocument) { size_t nCanvasSize = 1024; size_t nTileSize = 256; @@ -1758,22 +1759,26 @@ static void assertTilePixelColor(SwXTextDocument* pXTextDocument, int nPixelX, i Fraction(1.0), Point(), aPixmap.data()); pXTextDocument->paintTile(*pDevice, nCanvasSize, nCanvasSize, 0, 0, 15360, 7680); pDevice->EnableMapMode(false); - Bitmap aBitmap = pDevice->GetBitmap(Point(0, 0), Size(nTileSize, nTileSize)); + return pDevice->GetBitmap(Point(0, 0), Size(nTileSize, nTileSize)); +} + +// Helper function to get a tile to a bitmap and check the pixel color +static void assertTilePixelColor(SwXTextDocument* pXTextDocument, int nPixelX, int nPixelY, Color aColor) +{ + Bitmap aBitmap = getTile(pXTextDocument); BitmapScopedReadAccess pAccess(aBitmap); Color aActualColor(pAccess->GetPixel(nPixelX, nPixelY)); CPPUNIT_ASSERT_EQUAL(aColor, aActualColor); } -// Test that changing the theme in one view doesn't change it in the other view -CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testThemeViewSeparation) +static void addDarkLightThemes(const Color& rDarkColor, const Color& rLightColor) { - Color aDarkColor(0x1c, 0x1c, 0x1c); // Add a minimal dark scheme { svtools::EditableColorConfig aColorConfig; svtools::ColorConfigValue aValue; aValue.bIsVisible = true; - aValue.nColor = aDarkColor; + aValue.nColor = rDarkColor; aColorConfig.SetColorValue(svtools::DOCCOLOR, aValue); aColorConfig.AddScheme(u"Dark"_ustr); } @@ -1782,10 +1787,17 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testThemeViewSeparation) svtools::EditableColorConfig aColorConfig; svtools::ColorConfigValue aValue; aValue.bIsVisible = true; - aValue.nColor = COL_WHITE; + aValue.nColor = rLightColor; aColorConfig.SetColorValue(svtools::DOCCOLOR, aValue); aColorConfig.AddScheme(u"Light"_ustr); } +} + +// Test that changing the theme in one view doesn't change it in the other view +CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testThemeViewSeparation) +{ + Color aDarkColor(0x1c, 0x1c, 0x1c); + addDarkLightThemes(aDarkColor, COL_WHITE); SwXTextDocument* pXTextDocument = createDoc(); int nFirstViewId = SfxLokHelper::getView(); ViewCallback aView1; @@ -4105,6 +4117,54 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testToggleFormattingMarks) CPPUNIT_ASSERT_EQUAL(OString("P" + sOrigView2RenderState), aView2.m_aViewRenderState); } +// toggling chart into dark mode should switch not leave text as black +CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testSwitchingChartToDarkMode) +{ + addDarkLightThemes(COL_BLACK, COL_WHITE); + SwXTextDocument* pXTextDocument = createDoc("large-chart-labels.odt"); + CPPUNIT_ASSERT(pXTextDocument); + + SwDoc* pDoc = pXTextDocument->GetDocShell()->GetDoc(); + SwView* pView = pDoc->GetDocShell()->GetView(); + uno::Reference<frame::XFrame> xFrame = pView->GetViewFrame().GetFrame().GetFrameInterface(); + uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence( + { + { "NewTheme", uno::Any(OUString("Dark")) }, + } + ); + comphelper::dispatchCommand(".uno:ChangeTheme", xFrame, aPropertyValues); + CPPUNIT_ASSERT_EQUAL("S;Dark"_ostr, pXTextDocument->getViewRenderState()); + + Bitmap aBitmap(getTile(pXTextDocument)); + Size aSize = aBitmap.GetSizePixel(); + +#ifdef DBGDUMP + SvFileStream aNew("/tmp/dump.png", StreamMode::WRITE | StreamMode::TRUNC); + vcl::PngImageWriter aPNGWriter(aNew); + aPNGWriter.write(BitmapEx(aBitmap)); +#endif + + int nBlackPixels = 0; + int nWhitePixels = 0; + BitmapScopedReadAccess pAccess(aBitmap); + for (tools::Long x = 0; x < aSize.Width(); ++x) + { + for (tools::Long y = 0; y < aSize.Height(); ++y) + { + Color aActualColor(pAccess->GetPixel(y, x)); + if (aActualColor.IsDark()) // ignore antialiasing + ++nBlackPixels; + else + ++nWhitePixels; + } + } + // text in white on black background should have both colors dominated by black + // background + CPPUNIT_ASSERT(nBlackPixels > 0); + CPPUNIT_ASSERT(nWhitePixels > 0); + CPPUNIT_ASSERT(nBlackPixels > nWhitePixels); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */