diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-01-31 21:21:04 +0000 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-02-07 11:46:05 +0100 |
commit | d6d87429ad77ac92d1c3bde093cf4dc6d53e5e1b (patch) | |
tree | b452e19660840275695ecf9e15ac4b33e288cb81 | |
parent | 51b3a184f1d811c323d1f2e21777c72b15f5e836 (diff) |
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 <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit a9044a4b1de467519bec798500f3bf3d0d154f85)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163081
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
-rw-r--r-- | sw/qa/extras/tiledrendering/data/large-chart-labels.odt | bin | 0 -> 13936 bytes | |||
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 76 |
2 files changed, 68 insertions, 8 deletions
diff --git a/sw/qa/extras/tiledrendering/data/large-chart-labels.odt b/sw/qa/extras/tiledrendering/data/large-chart-labels.odt Binary files differnew file mode 100644 index 000000000000..35b26e866a33 --- /dev/null +++ b/sw/qa/extras/tiledrendering/data/large-chart-labels.odt diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 8f52f59211cc..f690b4ec8a40 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(OString("S;Dark"), 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 (int x = 0; x < aSize.Width(); ++x) + { + for (int 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: */ |