summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/vcl/outdev.hxx1
-rw-r--r--include/vcl/print.hxx1
-rw-r--r--starmath/CppunitTest_starmath_qa_cppunit.mk5
-rw-r--r--starmath/qa/cppunit/test_starmath.cxx37
-rw-r--r--starmath/source/tmpdevice.cxx32
-rw-r--r--starmath/source/tmpdevice.hxx8
-rw-r--r--vcl/qa/cppunit/outdev.cxx20
-rw-r--r--vcl/source/outdev/wallpaper.cxx10
8 files changed, 87 insertions, 27 deletions
diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index cac19b490fa3..cd3c84d13305 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -630,6 +630,7 @@ public:
const Wallpaper& GetBackground() const { return maBackground; }
virtual Color GetBackgroundColor() const;
+ virtual Color GetReadableFontColor(const Color& rFontColor, const Color& rBgColor) const;
bool IsBackground() const { return mbBackground; }
void SetFont( const vcl::Font& rNewFont );
diff --git a/include/vcl/print.hxx b/include/vcl/print.hxx
index d25af2b42bd2..86d65513829c 100644
--- a/include/vcl/print.hxx
+++ b/include/vcl/print.hxx
@@ -290,6 +290,7 @@ public:
bool SetPrinterProps( const Printer* pPrinter );
Color GetBackgroundColor() const override { return COL_WHITE; }
+ Color GetReadableFontColor(const Color&, const Color&) const override { return COL_BLACK; }
/** SetPrinterOptions is used internally only now
diff --git a/starmath/CppunitTest_starmath_qa_cppunit.mk b/starmath/CppunitTest_starmath_qa_cppunit.mk
index 19beb8c3eebd..ee436749f95a 100644
--- a/starmath/CppunitTest_starmath_qa_cppunit.mk
+++ b/starmath/CppunitTest_starmath_qa_cppunit.mk
@@ -48,6 +48,11 @@ $(eval $(call gb_CppunitTest_use_libraries,starmath_qa_cppunit,\
xo \
))
+$(eval $(call gb_CppunitTest_set_include,starmath_qa_cppunit,\
+ -I$(SRCDIR)/starmath/source \
+ $$(INCLUDE) \
+))
+
$(eval $(call gb_CppunitTest_add_exception_objects,starmath_qa_cppunit,\
starmath/qa/cppunit/test_cursor \
starmath/qa/cppunit/test_node \
diff --git a/starmath/qa/cppunit/test_starmath.cxx b/starmath/qa/cppunit/test_starmath.cxx
index f694cd888a23..793545879994 100644
--- a/starmath/qa/cppunit/test_starmath.cxx
+++ b/starmath/qa/cppunit/test_starmath.cxx
@@ -8,12 +8,17 @@
*/
#include <sal/config.h>
+
+#include <vcl/print.hxx>
+
#include <test/bootstrapfixture.hxx>
#include <smdll.hxx>
#include <document.hxx>
#include <view.hxx>
+#include <tmpdevice.hxx>
+
#include <sfx2/sfxmodelfactory.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/request.hxx>
@@ -61,6 +66,8 @@ public:
void replacePlaceholder();
void viewZoom();
+ void testSmTmpDeviceRestoreFont();
+
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(editUndoRedo);
CPPUNIT_TEST(editMarker);
@@ -80,6 +87,7 @@ public:
CPPUNIT_TEST(ParseErrorDoubleSubsupscript);
CPPUNIT_TEST(replacePlaceholder);
CPPUNIT_TEST(viewZoom);
+ CPPUNIT_TEST(testSmTmpDeviceRestoreFont);
CPPUNIT_TEST_SUITE_END();
private:
@@ -133,6 +141,35 @@ void Test::tearDown()
BootstrapFixture::tearDown();
}
+void Test::testSmTmpDeviceRestoreFont()
+{
+ ScopedVclPtrInstance<Printer> pPrinter;
+ bool bUseMap100th_mm = true;
+
+ OUString aFontName("Linux Libertine G");
+ CPPUNIT_ASSERT(pPrinter->IsFontAvailable(aFontName));
+
+ vcl::Font aOriginalFont = pPrinter->GetFont();
+ aOriginalFont.SetColor(COL_RED);
+ pPrinter->SetTextColor(COL_RED);
+
+ vcl::Font aNewFont;
+
+ {
+ SmTmpDevice aTmpDev(*pPrinter.get(), bUseMap100th_mm);
+
+ aNewFont = pPrinter->GetFont();
+ aNewFont.SetFamilyName(aFontName);
+ aTmpDev.SetFont(aNewFont);
+
+ CPPUNIT_ASSERT_EQUAL(aFontName, pPrinter->GetFont().GetFamilyName());
+ CPPUNIT_ASSERT_EQUAL(COL_BLACK, pPrinter->GetTextColor());
+ }
+
+ CPPUNIT_ASSERT(aNewFont != pPrinter->GetFont());
+ CPPUNIT_ASSERT_EQUAL(COL_RED, pPrinter->GetTextColor());
+}
+
void Test::editMarker()
{
{
diff --git a/starmath/source/tmpdevice.cxx b/starmath/source/tmpdevice.cxx
index 778d9196ad35..074903d3ceb6 100644
--- a/starmath/source/tmpdevice.cxx
+++ b/starmath/source/tmpdevice.cxx
@@ -35,8 +35,8 @@
SmTmpDevice::SmTmpDevice(OutputDevice &rTheDev, bool bUseMap100th_mm) :
rOutDev(rTheDev)
{
- rOutDev.Push( PushFlags::FONT | PushFlags::MAPMODE |
- PushFlags::LINECOLOR | PushFlags::FILLCOLOR | PushFlags::TEXTCOLOR );
+ rOutDev.Push(PushFlags::FONT | PushFlags::MAPMODE |
+ PushFlags::LINECOLOR | PushFlags::FILLCOLOR | PushFlags::TEXTCOLOR);
if (bUseMap100th_mm && MapUnit::Map100thMM != rOutDev.GetMapMode().GetMapUnit())
{
SAL_WARN("starmath", "incorrect MapMode?");
@@ -45,34 +45,22 @@ SmTmpDevice::SmTmpDevice(OutputDevice &rTheDev, bool bUseMap100th_mm) :
}
-Color SmTmpDevice::Impl_GetColor( const Color& rColor )
+Color SmTmpDevice::GetTextColor(const Color& rTextColor)
{
- Color nNewCol = rColor;
- if (nNewCol == COL_AUTO)
+ if (rTextColor == COL_AUTO)
{
- if (OUTDEV_PRINTER == rOutDev.GetOutDevType())
- nNewCol = COL_BLACK;
- else
- {
- Color aBgCol(rOutDev.GetBackgroundColor());
-
- nNewCol = SM_MOD()->GetColorConfig().GetColorValue(svtools::FONTCOLOR).nColor;
-
- Color aTmpColor( nNewCol );
- if (aBgCol.IsDark() && aTmpColor.IsDark())
- nNewCol = COL_WHITE;
- else if (aBgCol.IsBright() && aTmpColor.IsBright())
- nNewCol = COL_BLACK;
- }
+ Color aConfigFontColor = SM_MOD()->GetColorConfig().GetColorValue(svtools::FONTCOLOR).nColor;
+ return rOutDev.GetReadableFontColor(aConfigFontColor, rOutDev.GetBackgroundColor());
}
- return nNewCol;
+
+ return rTextColor;
}
void SmTmpDevice::SetFont(const vcl::Font &rNewFont)
{
- rOutDev.SetFont( rNewFont );
- rOutDev.SetTextColor( Impl_GetColor( rNewFont.GetColor() ) );
+ rOutDev.SetFont(rNewFont);
+ rOutDev.SetTextColor(GetTextColor(rNewFont.GetColor()));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/tmpdevice.hxx b/starmath/source/tmpdevice.hxx
index f03aa9d42bb3..e7c812cd69f4 100644
--- a/starmath/source/tmpdevice.hxx
+++ b/starmath/source/tmpdevice.hxx
@@ -25,12 +25,12 @@
class SmTmpDevice
{
- OutputDevice &rOutDev;
+ OutputDevice &rOutDev;
SmTmpDevice(const SmTmpDevice&) = delete;
SmTmpDevice& operator=(const SmTmpDevice&) = delete;
- Color Impl_GetColor( const Color& rColor );
+ Color GetTextColor(const Color& rTextColor);
public:
SmTmpDevice(OutputDevice &rTheDev, bool bUseMap100th_mm);
@@ -38,8 +38,8 @@ public:
void SetFont(const vcl::Font &rNewFont);
- void SetLineColor( const Color& rColor ) { rOutDev.SetLineColor( Impl_GetColor(rColor) ); }
- void SetFillColor( const Color& rColor ) { rOutDev.SetFillColor( Impl_GetColor(rColor) ); }
+ void SetLineColor(const Color& rColor) { rOutDev.SetLineColor(GetTextColor(rColor)); }
+ void SetFillColor(const Color& rColor) { rOutDev.SetFillColor(GetTextColor(rColor)); }
operator OutputDevice & () { return rOutDev; }
};
diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index b91248078ab8..0484e4a4143d 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -9,8 +9,8 @@
#include <test/bootstrapfixture.hxx>
-#include <vcl/virdev.hxx>
#include <vcl/print.hxx>
+#include <vcl/virdev.hxx>
#include <vcl/window.hxx>
#include <vcl/bitmapaccess.hxx>
@@ -25,15 +25,33 @@ public:
void testUseAfterDispose();
void testPrinterBackgroundColor();
void testWindowBackgroundColor();
+ void testGetReadableFontColorPrinter();
+ void testGetReadableFontColorWindow();
CPPUNIT_TEST_SUITE(VclOutdevTest);
CPPUNIT_TEST(testVirtualDevice);
CPPUNIT_TEST(testUseAfterDispose);
CPPUNIT_TEST(testPrinterBackgroundColor);
CPPUNIT_TEST(testWindowBackgroundColor);
+ CPPUNIT_TEST(testGetReadableFontColorPrinter);
+ CPPUNIT_TEST(testGetReadableFontColorWindow);
CPPUNIT_TEST_SUITE_END();
};
+void VclOutdevTest::testGetReadableFontColorPrinter()
+{
+ ScopedVclPtrInstance<Printer> pPrinter;
+ CPPUNIT_ASSERT_EQUAL(pPrinter->GetReadableFontColor(COL_WHITE, COL_WHITE), COL_BLACK);
+}
+
+void VclOutdevTest::testGetReadableFontColorWindow()
+{
+ ScopedVclPtrInstance<vcl::Window> pWindow(nullptr, WB_APP | WB_STDWORK);
+ CPPUNIT_ASSERT_EQUAL(pWindow->GetReadableFontColor(COL_WHITE, COL_BLACK), COL_WHITE);
+ CPPUNIT_ASSERT_EQUAL(pWindow->GetReadableFontColor(COL_WHITE, COL_WHITE), COL_BLACK);
+ CPPUNIT_ASSERT_EQUAL(pWindow->GetReadableFontColor(COL_BLACK, COL_BLACK), COL_WHITE);
+}
+
void VclOutdevTest::testPrinterBackgroundColor()
{
ScopedVclPtrInstance<Printer> pPrinter;
diff --git a/vcl/source/outdev/wallpaper.cxx b/vcl/source/outdev/wallpaper.cxx
index 8a64137ed407..ae3687d79f35 100644
--- a/vcl/source/outdev/wallpaper.cxx
+++ b/vcl/source/outdev/wallpaper.cxx
@@ -24,6 +24,16 @@
#include <vcl/outdev.hxx>
#include <vcl/virdev.hxx>
+Color OutputDevice::GetReadableFontColor(const Color& rFontColor, const Color& rBgColor) const
+{
+ if (rBgColor.IsDark() && rFontColor.IsDark())
+ return COL_WHITE;
+ else if (rBgColor.IsBright() && rFontColor.IsBright())
+ return COL_BLACK;
+ else
+ return rFontColor;
+}
+
Color OutputDevice::GetBackgroundColor() const
{
return GetBackground().GetColor();