[Libreoffice-commits] core.git: include/vcl vcl/CppunitTest_vcl_drawmode.mk vcl/inc vcl/Library_vcl.mk vcl/Module_vcl.mk vcl/qa vcl/source

Chris Sherlock (via logerrit) logerrit at kemper.freedesktop.org
Tue Aug 24 10:12:49 UTC 2021


 include/vcl/outdev.hxx                |    5 
 vcl/CppunitTest_vcl_drawmode.mk       |   47 +++
 vcl/Library_vcl.mk                    |    1 
 vcl/Module_vcl.mk                     |    1 
 vcl/inc/drawmode.hxx                  |   52 ++++
 vcl/qa/cppunit/drawmode.cxx           |  401 ++++++++++++++++++++++++++++++++++
 vcl/source/outdev/bitmap.cxx          |   70 -----
 vcl/source/outdev/hatch.cxx           |   25 --
 vcl/source/outdev/outdevstate.cxx     |   92 -------
 vcl/source/outdev/pixel.cxx           |    3 
 vcl/source/outdev/text.cxx            |   52 ----
 vcl/source/outdev/textline.cxx        |   53 ----
 vcl/source/outdev/transparent.cxx     |   33 --
 vcl/source/rendercontext/drawmode.cxx |  275 +++++++++++++++++++++++
 14 files changed, 802 insertions(+), 308 deletions(-)

New commits:
commit 0901297902c29c041ae944973b369e8247716893
Author:     Chris Sherlock <chris.sherlock79 at gmail.com>
AuthorDate: Wed May 5 18:01:43 2021 +1000
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Tue Aug 24 12:12:11 2021 +0200

    vcl: create drawmode functions
    
    Change-Id: I3cb0325dc16db84ad58de28aa9110e9c7a0b9697
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115372
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index fce10e1ef077..b529763099ca 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -478,7 +478,7 @@ public:
     AntialiasingFlags           GetAntialiasing() const { return mnAntialiasing; }
 
     void                        SetDrawMode( DrawModeFlags nDrawMode );
-    DrawModeFlags               GetDrawMode() const { return mnDrawMode; }
+    DrawModeFlags               GetDrawMode() const;
 
     void                        SetLayoutMode( ComplexTextLayoutFlags nTextLayoutMode );
     ComplexTextLayoutFlags       GetLayoutMode() const { return mnTextLayoutMode; }
@@ -1493,9 +1493,6 @@ public:
                                     bool bDownsampleBitmaps,
                                     const Color& rBackground = COL_TRANSPARENT );
 
-    SAL_DLLPRIVATE Color        ImplDrawModeToColor  ( const Color& rColor ) const;
-
-
     void                        DrawTransparent( const tools::PolyPolygon& rPolyPoly, sal_uInt16 nTransparencePercent );
 
     void                        DrawTransparent(
diff --git a/vcl/CppunitTest_vcl_drawmode.mk b/vcl/CppunitTest_vcl_drawmode.mk
new file mode 100644
index 000000000000..2a107c214a26
--- /dev/null
+++ b/vcl/CppunitTest_vcl_drawmode.mk
@@ -0,0 +1,47 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,vcl_drawmode))
+
+$(eval $(call gb_CppunitTest_set_include,vcl_drawmode,\
+    $$(INCLUDE) \
+    -I$(SRCDIR)/vcl/inc \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,vcl_drawmode, \
+	vcl/qa/cppunit/drawmode \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,vcl_drawmode, \
+	comphelper \
+	cppu \
+	cppuhelper \
+	sal \
+	svt \
+	test \
+	tl \
+	tk \
+	unotest \
+	vcl \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,vcl_drawmode))
+
+$(eval $(call gb_CppunitTest_use_ure,vcl_drawmode))
+$(eval $(call gb_CppunitTest_use_vcl,vcl_drawmode))
+
+$(eval $(call gb_CppunitTest_use_configuration,vcl_drawmode))
+
+$(eval $(call gb_CppunitTest_use_components,vcl_drawmode,\
+	configmgr/source/configmgr \
+	i18npool/util/i18npool \
+	ucb/source/core/ucb1 \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index eb0af8aa8cc4..ec5445f2968c 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -94,6 +94,7 @@ $(eval $(call gb_Library_use_externals,vcl,\
 ))
 
 $(eval $(call gb_Library_add_exception_objects,vcl,\
+    vcl/source/rendercontext/drawmode \
     vcl/skia/SkiaHelper \
     vcl/source/rendercontext/ImplMapRes \
     vcl/source/animate/Animation \
diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index 4a3eec15c119..41eb63456470 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -189,6 +189,7 @@ $(eval $(call gb_Module_add_targets,vcl,\
 endif
 
 $(eval $(call gb_Module_add_check_targets,vcl,\
+    CppunitTest_vcl_drawmode \
     CppunitTest_vcl_lifecycle \
     CppunitTest_vcl_bitmap_test \
     CppunitTest_vcl_bitmapprocessor_test \
diff --git a/vcl/inc/drawmode.hxx b/vcl/inc/drawmode.hxx
new file mode 100644
index 000000000000..9234b180b4c6
--- /dev/null
+++ b/vcl/inc/drawmode.hxx
@@ -0,0 +1,52 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <tools/color.hxx>
+
+#include <vcl/bitmapex.hxx>
+#include <vcl/font.hxx>
+#include <vcl/rendercontext/DrawModeFlags.hxx>
+
+class StyleSettings;
+
+namespace vcl::drawmode
+{
+VCL_DLLPUBLIC Color GetLineColor(Color const& rColor, DrawModeFlags nDrawMode,
+                                 StyleSettings const& rStyleSettings);
+
+VCL_DLLPUBLIC Color GetFillColor(Color const& rColor, DrawModeFlags nDrawMode,
+                                 StyleSettings const& rStyleSettings);
+
+VCL_DLLPUBLIC Color GetHatchColor(Color const& rColor, DrawModeFlags nDrawMode,
+                                  StyleSettings const& rStyleSettings);
+
+VCL_DLLPUBLIC Color GetTextColor(Color const& rColor, DrawModeFlags nDrawMode,
+                                 StyleSettings const& rStyleSettings);
+
+VCL_DLLPUBLIC vcl::Font GetFont(vcl::Font const& rFont, DrawModeFlags nDrawMode,
+                                StyleSettings const& rStyleSettings);
+
+VCL_DLLPUBLIC Bitmap GetBitmap(Bitmap const& rBitmap, DrawModeFlags nDrawMode);
+
+VCL_DLLPUBLIC BitmapEx GetBitmapEx(BitmapEx const& rBitmapEx, DrawModeFlags nDrawMode);
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/vcl/qa/cppunit/drawmode.cxx b/vcl/qa/cppunit/drawmode.cxx
new file mode 100644
index 000000000000..f3ea1af773f7
--- /dev/null
+++ b/vcl/qa/cppunit/drawmode.cxx
@@ -0,0 +1,401 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/bootstrapfixture.hxx>
+#include <cppunit/TestAssert.h>
+
+#include <tools/color.hxx>
+
+#include <vcl/font.hxx>
+#include <vcl/metric.hxx>
+#include <vcl/settings.hxx>
+
+#include <bitmap/BitmapWriteAccess.hxx>
+#include <drawmode.hxx>
+
+class VclDrawModeTest : public test::BootstrapFixture
+{
+public:
+    VclDrawModeTest()
+        : BootstrapFixture(true, false)
+    {
+    }
+
+    void testDrawModeLineColor();
+    void testDrawModeFillColor();
+    void testDrawModeHatchColor();
+    void testDrawModeTextColor();
+    void testDrawModeFontColor();
+    void testDrawModeBitmap();
+    void testDrawModeBitmapEx();
+
+    CPPUNIT_TEST_SUITE(VclDrawModeTest);
+
+    CPPUNIT_TEST(testDrawModeLineColor);
+    CPPUNIT_TEST(testDrawModeFillColor);
+    CPPUNIT_TEST(testDrawModeHatchColor);
+    CPPUNIT_TEST(testDrawModeTextColor);
+    CPPUNIT_TEST(testDrawModeFontColor);
+    CPPUNIT_TEST(testDrawModeBitmap);
+    CPPUNIT_TEST(testDrawModeBitmapEx);
+
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void VclDrawModeTest::testDrawModeLineColor()
+{
+    const Color aColor = COL_RED;
+    const sal_uInt8 cLum = aColor.GetLuminance();
+    const StyleSettings aStyleSettings;
+
+    CPPUNIT_ASSERT_EQUAL(
+        COL_BLACK, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::BlackLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        COL_WHITE, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::WhiteLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        Color(cLum, cLum, cLum),
+        vcl::drawmode::GetLineColor(aColor, DrawModeFlags::GrayLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aStyleSettings.GetFontColor(),
+        vcl::drawmode::GetLineColor(aColor, DrawModeFlags::SettingsLine, aStyleSettings));
+
+    Color aTransparentRed = COL_RED;
+    aTransparentRed.SetAlpha(100);
+
+    CPPUNIT_ASSERT_EQUAL(
+        aTransparentRed,
+        vcl::drawmode::GetLineColor(aTransparentRed, DrawModeFlags::BlackLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aTransparentRed,
+        vcl::drawmode::GetLineColor(aTransparentRed, DrawModeFlags::WhiteLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aTransparentRed,
+        vcl::drawmode::GetLineColor(aTransparentRed, DrawModeFlags::GrayLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aTransparentRed,
+        vcl::drawmode::GetLineColor(aTransparentRed, DrawModeFlags::SettingsLine, aStyleSettings));
+
+    // noops
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::NoFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::BlackFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::WhiteFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::GrayFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::SettingsFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::BlackText, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::WhiteText, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::GrayText, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::SettingsText, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::BlackBitmap, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::WhiteBitmap, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetLineColor(aColor, DrawModeFlags::GrayBitmap, aStyleSettings));
+}
+
+void VclDrawModeTest::testDrawModeFillColor()
+{
+    const Color aColor = COL_RED;
+    const sal_uInt8 cLum = aColor.GetLuminance();
+    const StyleSettings aStyleSettings;
+
+    CPPUNIT_ASSERT_EQUAL(COL_TRANSPARENT, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::NoFill,
+                                                                      aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        COL_BLACK, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::BlackFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        COL_WHITE, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::WhiteFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        Color(cLum, cLum, cLum),
+        vcl::drawmode::GetFillColor(aColor, DrawModeFlags::GrayFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aStyleSettings.GetWindowColor(),
+        vcl::drawmode::GetFillColor(aColor, DrawModeFlags::SettingsFill, aStyleSettings));
+
+    Color aTransparentRed = COL_RED;
+    aTransparentRed.SetAlpha(100);
+
+    CPPUNIT_ASSERT_EQUAL(
+        aTransparentRed,
+        vcl::drawmode::GetFillColor(aTransparentRed, DrawModeFlags::BlackLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aTransparentRed,
+        vcl::drawmode::GetFillColor(aTransparentRed, DrawModeFlags::WhiteLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aTransparentRed,
+        vcl::drawmode::GetFillColor(aTransparentRed, DrawModeFlags::GrayLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aTransparentRed,
+        vcl::drawmode::GetFillColor(aTransparentRed, DrawModeFlags::SettingsLine, aStyleSettings));
+
+    // noops
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::BlackLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::WhiteLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::GrayLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::SettingsLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::BlackText, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::WhiteText, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::GrayText, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::SettingsText, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::BlackBitmap, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::WhiteBitmap, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetFillColor(aColor, DrawModeFlags::GrayBitmap, aStyleSettings));
+}
+
+void VclDrawModeTest::testDrawModeHatchColor()
+{
+    const Color aColor = COL_RED;
+    const sal_uInt8 cLum = aColor.GetLuminance();
+    const StyleSettings aStyleSettings;
+
+    CPPUNIT_ASSERT_EQUAL(
+        COL_BLACK, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::BlackLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        COL_WHITE, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::WhiteLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        Color(cLum, cLum, cLum),
+        vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::GrayLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aStyleSettings.GetFontColor(),
+        vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::SettingsLine, aStyleSettings));
+
+    // noops
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::NoFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::BlackFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::WhiteFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::GrayFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::SettingsFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::BlackText, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::WhiteText, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::GrayText, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::SettingsText, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::BlackBitmap, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::WhiteBitmap, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetHatchColor(aColor, DrawModeFlags::GrayBitmap, aStyleSettings));
+}
+
+void VclDrawModeTest::testDrawModeTextColor()
+{
+    const Color aColor = COL_RED;
+    const sal_uInt8 cLum = aColor.GetLuminance();
+    const StyleSettings aStyleSettings;
+
+    CPPUNIT_ASSERT_EQUAL(
+        COL_BLACK, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::BlackText, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        COL_WHITE, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::WhiteText, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        Color(cLum, cLum, cLum),
+        vcl::drawmode::GetTextColor(aColor, DrawModeFlags::GrayText, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aStyleSettings.GetFontColor(),
+        vcl::drawmode::GetTextColor(aColor, DrawModeFlags::SettingsText, aStyleSettings));
+
+    // noops
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::BlackLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::WhiteLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::GrayLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::SettingsLine, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::NoFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::BlackFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::WhiteFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::GrayFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::SettingsFill, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::BlackBitmap, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::WhiteBitmap, aStyleSettings));
+    CPPUNIT_ASSERT_EQUAL(
+        aColor, vcl::drawmode::GetTextColor(aColor, DrawModeFlags::GrayBitmap, aStyleSettings));
+}
+
+void VclDrawModeTest::testDrawModeFontColor()
+{
+    const StyleSettings aStyleSettings;
+
+    vcl::Font aFont;
+    aFont.SetFillColor(COL_RED);
+
+    // black text and fill
+    aFont.SetTransparent(false);
+    vcl::Font aTestFont = vcl::drawmode::GetFont(
+        aFont, DrawModeFlags::BlackText | DrawModeFlags::BlackFill, aStyleSettings);
+    CPPUNIT_ASSERT_EQUAL(COL_BLACK, aTestFont.GetColor());
+    CPPUNIT_ASSERT_EQUAL(COL_BLACK, aTestFont.GetFillColor());
+
+    aFont.SetTransparent(true);
+    aTestFont = vcl::drawmode::GetFont(aFont, DrawModeFlags::BlackText | DrawModeFlags::BlackFill,
+                                       aStyleSettings);
+    CPPUNIT_ASSERT_EQUAL(COL_BLACK, aTestFont.GetColor());
+    CPPUNIT_ASSERT_EQUAL(COL_RED, aTestFont.GetFillColor());
+
+    // white text and fill
+    aFont.SetTransparent(false);
+    aTestFont = vcl::drawmode::GetFont(aFont, DrawModeFlags::WhiteText | DrawModeFlags::WhiteFill,
+                                       aStyleSettings);
+    CPPUNIT_ASSERT_EQUAL(COL_WHITE, aTestFont.GetColor());
+    CPPUNIT_ASSERT_EQUAL(COL_WHITE, aTestFont.GetFillColor());
+
+    aFont.SetTransparent(true);
+    aTestFont = vcl::drawmode::GetFont(aFont, DrawModeFlags::WhiteText | DrawModeFlags::WhiteFill,
+                                       aStyleSettings);
+    CPPUNIT_ASSERT_EQUAL(COL_WHITE, aTestFont.GetColor());
+    CPPUNIT_ASSERT_EQUAL(COL_RED, aTestFont.GetFillColor());
+
+    // gray text and fill
+    const sal_uInt8 cTextLum = aFont.GetColor().GetLuminance();
+    const Color aTextGray(cTextLum, cTextLum, cTextLum);
+    const sal_uInt8 cFillLum = aFont.GetFillColor().GetLuminance();
+    const Color aFillGray(cFillLum, cFillLum, cFillLum);
+
+    aFont.SetTransparent(false);
+    aTestFont = vcl::drawmode::GetFont(aFont, DrawModeFlags::GrayText | DrawModeFlags::GrayFill,
+                                       aStyleSettings);
+    CPPUNIT_ASSERT_EQUAL(aTextGray, aTestFont.GetColor());
+    CPPUNIT_ASSERT_EQUAL(aFillGray, aTestFont.GetFillColor());
+
+    aFont.SetTransparent(true);
+    aTestFont = vcl::drawmode::GetFont(aFont, DrawModeFlags::GrayText | DrawModeFlags::GrayFill,
+                                       aStyleSettings);
+    CPPUNIT_ASSERT_EQUAL(aTextGray, aTestFont.GetColor());
+    CPPUNIT_ASSERT_EQUAL(COL_RED, aTestFont.GetFillColor());
+
+    // no text fill
+    aFont.SetTransparent(false);
+    aTestFont = vcl::drawmode::GetFont(aFont, DrawModeFlags::NoFill, aStyleSettings);
+    CPPUNIT_ASSERT_EQUAL(COL_TRANSPARENT, aTestFont.GetFillColor());
+
+    aFont.SetTransparent(true);
+    aTestFont = vcl::drawmode::GetFont(aFont, DrawModeFlags::NoFill, aStyleSettings);
+    CPPUNIT_ASSERT_EQUAL(COL_RED, aTestFont.GetFillColor());
+
+    // white text and fill
+    aFont.SetTransparent(false);
+    aTestFont = vcl::drawmode::GetFont(
+        aFont, DrawModeFlags::SettingsText | DrawModeFlags::SettingsFill, aStyleSettings);
+    CPPUNIT_ASSERT_EQUAL(aStyleSettings.GetFontColor(), aTestFont.GetColor());
+    CPPUNIT_ASSERT_EQUAL(aStyleSettings.GetWindowColor(), aTestFont.GetFillColor());
+
+    aFont.SetTransparent(true);
+    aTestFont = vcl::drawmode::GetFont(
+        aFont, DrawModeFlags::SettingsText | DrawModeFlags::SettingsFill, aStyleSettings);
+    CPPUNIT_ASSERT_EQUAL(aStyleSettings.GetFontColor(), aTestFont.GetColor());
+    CPPUNIT_ASSERT_EQUAL(COL_RED, aTestFont.GetFillColor());
+}
+
+void VclDrawModeTest::testDrawModeBitmap()
+{
+    const StyleSettings aStyleSettings;
+
+    Bitmap aBmp(Size(1, 1), vcl::PixelFormat::N24_BPP);
+    BitmapWriteAccess aBmpAccess(aBmp);
+    aBmpAccess.SetPixel(0, 0, BitmapColor(COL_RED));
+
+    {
+        Bitmap aResultBitmap(vcl::drawmode::GetBitmap(aBmp, DrawModeFlags::GrayBitmap));
+        Bitmap::ScopedReadAccess pReadAccess(aResultBitmap);
+
+        const BitmapColor& rColor = pReadAccess->GetColor(0, 0);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0x26), sal_Int32(rColor.GetRed()));
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0x26), sal_Int32(rColor.GetGreen()));
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0x26), sal_Int32(rColor.GetBlue()));
+    }
+
+    // any other operation other than DrawModeFlags::GrayBitmap is a noop
+    {
+        Bitmap aResultBitmap(vcl::drawmode::GetBitmap(aBmp, DrawModeFlags::NoFill));
+        Bitmap::ScopedReadAccess pReadAccess(aResultBitmap);
+
+        const BitmapColor& rColor = pReadAccess->GetColor(0, 0);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0x80), sal_Int32(rColor.GetRed()));
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0x00), sal_Int32(rColor.GetGreen()));
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0x00), sal_Int32(rColor.GetBlue()));
+    }
+}
+
+void VclDrawModeTest::testDrawModeBitmapEx()
+{
+    const StyleSettings aStyleSettings;
+
+    Bitmap aBmp(Size(1, 1), vcl::PixelFormat::N24_BPP);
+    BitmapWriteAccess aBmpAccess(aBmp);
+    aBmpAccess.SetPixel(0, 0, BitmapColor(COL_RED));
+
+    BitmapEx aBmpEx(aBmp);
+
+    {
+        BitmapEx aResultBitmapEx(vcl::drawmode::GetBitmapEx(aBmpEx, DrawModeFlags::GrayBitmap));
+        Bitmap aResultBitmap(aResultBitmapEx.GetBitmap());
+        Bitmap::ScopedReadAccess pReadAccess(aResultBitmap);
+
+        const BitmapColor& rColor = pReadAccess->GetColor(0, 0);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0x26), sal_Int32(rColor.GetRed()));
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0x26), sal_Int32(rColor.GetGreen()));
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0x26), sal_Int32(rColor.GetBlue()));
+    }
+
+    // any other operation other than DrawModeFlags::GrayBitmap is a noop
+    {
+        BitmapEx aResultBitmapEx(vcl::drawmode::GetBitmapEx(aBmpEx, DrawModeFlags::NoFill));
+        Bitmap aResultBitmap(aResultBitmapEx.GetBitmap());
+        Bitmap::ScopedReadAccess pReadAccess(aResultBitmap);
+
+        const BitmapColor& rColor = pReadAccess->GetColor(0, 0);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0x80), sal_Int32(rColor.GetRed()));
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0x00), sal_Int32(rColor.GetGreen()));
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0x00), sal_Int32(rColor.GetBlue()));
+    }
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(VclDrawModeTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index 51a55befd8a7..f80ccb0a52bf 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -35,6 +35,7 @@
 
 #include <bitmap/BitmapWriteAccess.hxx>
 #include <bitmap/bmpfast.hxx>
+#include <drawmode.hxx>
 #include <salgdi.hxx>
 #include <salbmp.hxx>
 
@@ -82,34 +83,7 @@ void OutputDevice::DrawBitmap( const Point& rDestPt, const Size& rDestSize,
         return;
     }
 
-    Bitmap aBmp( rBitmap );
-
-    if ( mnDrawMode & ( DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap |
-                             DrawModeFlags::GrayBitmap ) )
-    {
-        if ( mnDrawMode & ( DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap ) )
-        {
-            sal_uInt8 cCmpVal;
-
-            if ( mnDrawMode & DrawModeFlags::BlackBitmap )
-                cCmpVal = 0;
-            else
-                cCmpVal = 255;
-
-            Color aCol( cCmpVal, cCmpVal, cCmpVal );
-            Push( PushFlags::LINECOLOR | PushFlags::FILLCOLOR );
-            SetLineColor( aCol );
-            SetFillColor( aCol );
-            DrawRect( tools::Rectangle( rDestPt, rDestSize ) );
-            Pop();
-            return;
-        }
-        else if( !aBmp.IsEmpty() )
-        {
-            if ( mnDrawMode & DrawModeFlags::GrayBitmap )
-                aBmp.Convert( BmpConversion::N8BitGreys );
-        }
-    }
+    Bitmap aBmp(vcl::drawmode::GetBitmap(rBitmap, GetDrawMode()));
 
     if ( mpMetaFile )
     {
@@ -316,45 +290,7 @@ void OutputDevice::DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
             return;
         }
 
-        BitmapEx aBmpEx( rBitmapEx );
-
-        if ( mnDrawMode & ( DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap |
-                                 DrawModeFlags::GrayBitmap ) )
-        {
-            if ( mnDrawMode & ( DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap ) )
-            {
-                Bitmap aColorBmp(aBmpEx.GetSizePixel(), vcl::PixelFormat::N1_BPP);
-                sal_uInt8   cCmpVal;
-
-                if ( mnDrawMode & DrawModeFlags::BlackBitmap )
-                    cCmpVal = 0;
-                else
-                    cCmpVal = 255;
-
-                aColorBmp.Erase( Color( cCmpVal, cCmpVal, cCmpVal ) );
-
-                if( aBmpEx.IsAlpha() )
-                {
-                    // Create one-bit mask out of alpha channel, by
-                    // thresholding it at alpha=0.5. As
-                    // DRAWMODE_BLACK/WHITEBITMAP requires monochrome
-                    // output, having alpha-induced grey levels is not
-                    // acceptable.
-                    BitmapEx aMaskEx(aBmpEx.GetAlpha().GetBitmap());
-                    BitmapFilter::Filter(aMaskEx, BitmapMonochromeFilter(129));
-                    aBmpEx = BitmapEx(aColorBmp, aMaskEx.GetBitmap());
-                }
-                else
-                {
-                    aBmpEx = BitmapEx( aColorBmp, aBmpEx.GetAlpha() );
-                }
-            }
-            else if( !aBmpEx.IsEmpty() )
-            {
-                if ( mnDrawMode & DrawModeFlags::GrayBitmap )
-                    aBmpEx.Convert( BmpConversion::N8BitGreys );
-            }
-        }
+        BitmapEx aBmpEx(vcl::drawmode::GetBitmapEx(rBitmapEx, GetDrawMode()));
 
         if ( mpMetaFile )
         {
diff --git a/vcl/source/outdev/hatch.cxx b/vcl/source/outdev/hatch.cxx
index 8b62fcf10375..fbbab235fee4 100644
--- a/vcl/source/outdev/hatch.cxx
+++ b/vcl/source/outdev/hatch.cxx
@@ -30,6 +30,7 @@
 #include <vcl/outdev.hxx>
 #include <vcl/virdev.hxx>
 
+#include <drawmode.hxx>
 #include <salgdi.hxx>
 
 #include <memory>
@@ -55,29 +56,7 @@ void OutputDevice::DrawHatch( const tools::PolyPolygon& rPolyPoly, const Hatch&
     assert(!is_double_buffered_window());
 
     Hatch aHatch( rHatch );
-
-    if ( mnDrawMode & ( DrawModeFlags::BlackLine | DrawModeFlags::WhiteLine |
-                        DrawModeFlags::GrayLine |
-                        DrawModeFlags::SettingsLine ) )
-    {
-        Color aColor( rHatch.GetColor() );
-
-        if ( mnDrawMode & DrawModeFlags::BlackLine )
-            aColor = COL_BLACK;
-        else if ( mnDrawMode & DrawModeFlags::WhiteLine )
-            aColor = COL_WHITE;
-        else if ( mnDrawMode & DrawModeFlags::GrayLine )
-        {
-            const sal_uInt8 cLum = aColor.GetLuminance();
-            aColor = Color( cLum, cLum, cLum );
-        }
-        else if( mnDrawMode & DrawModeFlags::SettingsLine )
-        {
-            aColor = GetSettings().GetStyleSettings().GetFontColor();
-        }
-
-        aHatch.SetColor( aColor );
-    }
+    aHatch.SetColor(vcl::drawmode::GetHatchColor(rHatch.GetColor(), GetDrawMode(), GetSettings().GetStyleSettings()));
 
     if( mpMetaFile )
         mpMetaFile->AddAction( new MetaHatchAction( rPolyPoly, aHatch ) );
diff --git a/vcl/source/outdev/outdevstate.cxx b/vcl/source/outdev/outdevstate.cxx
index 3a4d5e1d420d..0c0d1afbb955 100644
--- a/vcl/source/outdev/outdevstate.cxx
+++ b/vcl/source/outdev/outdevstate.cxx
@@ -28,6 +28,7 @@
 #include <vcl/settings.hxx>
 
 #include <outdev.h>
+#include <drawmode.hxx>
 #include <salgdi.hxx>
 
 OutDevState::OutDevState()
@@ -256,13 +257,14 @@ void OutputDevice::SetAntialiasing( AntialiasingFlags nMode )
         mpAlphaVDev->SetAntialiasing( nMode );
 }
 
-void OutputDevice::SetDrawMode( DrawModeFlags nDrawMode )
-{
+DrawModeFlags OutputDevice::GetDrawMode() const { return mnDrawMode; }
 
+void OutputDevice::SetDrawMode(DrawModeFlags nDrawMode)
+{
     mnDrawMode = nDrawMode;
 
-    if( mpAlphaVDev )
-        mpAlphaVDev->SetDrawMode( nDrawMode );
+    if (mpAlphaVDev)
+        mpAlphaVDev->SetDrawMode(nDrawMode);
 }
 
 void OutputDevice::SetLayoutMode( ComplexTextLayoutFlags nTextLayoutMode )
@@ -329,38 +331,7 @@ void OutputDevice::SetFillColor()
 
 void OutputDevice::SetFillColor( const Color& rColor )
 {
-
-    Color aColor( rColor );
-
-    if( mnDrawMode & ( DrawModeFlags::BlackFill | DrawModeFlags::WhiteFill |
-                       DrawModeFlags::GrayFill | DrawModeFlags::NoFill |
-                       DrawModeFlags::SettingsFill ) )
-    {
-        if( !aColor.IsTransparent() )
-        {
-            if( mnDrawMode & DrawModeFlags::BlackFill )
-            {
-                aColor = COL_BLACK;
-            }
-            else if( mnDrawMode & DrawModeFlags::WhiteFill )
-            {
-                aColor = COL_WHITE;
-            }
-            else if( mnDrawMode & DrawModeFlags::GrayFill )
-            {
-                const sal_uInt8 cLum = aColor.GetLuminance();
-                aColor = Color( cLum, cLum, cLum );
-            }
-            else if( mnDrawMode & DrawModeFlags::NoFill )
-            {
-                aColor = COL_TRANSPARENT;
-            }
-            else if( mnDrawMode & DrawModeFlags::SettingsFill )
-            {
-                aColor = GetSettings().GetStyleSettings().GetWindowColor();
-            }
-        }
-    }
+    Color aColor(vcl::drawmode::GetFillColor(rColor, GetDrawMode(), GetSettings().GetStyleSettings()));
 
     if ( mpMetaFile )
         mpMetaFile->AddAction( new MetaFillColorAction( aColor, true ) );
@@ -408,7 +379,7 @@ void OutputDevice::SetLineColor()
 void OutputDevice::SetLineColor( const Color& rColor )
 {
 
-    Color aColor = ImplDrawModeToColor( rColor );
+    Color aColor = vcl::drawmode::GetLineColor(rColor, GetDrawMode(), GetSettings().GetStyleSettings());
 
     if( mpMetaFile )
         mpMetaFile->AddAction( new MetaLineColorAction( aColor, true ) );
@@ -438,52 +409,7 @@ void OutputDevice::SetLineColor( const Color& rColor )
 
 void OutputDevice::SetFont( const vcl::Font& rNewFont )
 {
-
-    vcl::Font aFont( rNewFont );
-    if ( mnDrawMode & (DrawModeFlags::BlackText | DrawModeFlags::WhiteText | DrawModeFlags::GrayText | DrawModeFlags::SettingsText |
-                       DrawModeFlags::BlackFill | DrawModeFlags::WhiteFill | DrawModeFlags::GrayFill | DrawModeFlags::NoFill |
-                       DrawModeFlags::SettingsFill ) )
-    {
-        Color aTextColor( aFont.GetColor() );
-
-        if ( mnDrawMode & DrawModeFlags::BlackText )
-            aTextColor = COL_BLACK;
-        else if ( mnDrawMode & DrawModeFlags::WhiteText )
-            aTextColor = COL_WHITE;
-        else if ( mnDrawMode & DrawModeFlags::GrayText )
-        {
-            const sal_uInt8 cLum = aTextColor.GetLuminance();
-            aTextColor = Color( cLum, cLum, cLum );
-        }
-        else if ( mnDrawMode & DrawModeFlags::SettingsText )
-            aTextColor = GetSettings().GetStyleSettings().GetFontColor();
-
-        aFont.SetColor( aTextColor );
-
-        bool bTransFill = aFont.IsTransparent();
-        if ( !bTransFill )
-        {
-            Color aTextFillColor( aFont.GetFillColor() );
-
-            if ( mnDrawMode & DrawModeFlags::BlackFill )
-                aTextFillColor = COL_BLACK;
-            else if ( mnDrawMode & DrawModeFlags::WhiteFill )
-                aTextFillColor = COL_WHITE;
-            else if ( mnDrawMode & DrawModeFlags::GrayFill )
-            {
-                const sal_uInt8 cLum = aTextFillColor.GetLuminance();
-                aTextFillColor = Color( cLum, cLum, cLum );
-            }
-            else if( mnDrawMode & DrawModeFlags::SettingsFill )
-                aTextFillColor = GetSettings().GetStyleSettings().GetWindowColor();
-            else if ( mnDrawMode & DrawModeFlags::NoFill )
-            {
-                aTextFillColor = COL_TRANSPARENT;
-            }
-
-            aFont.SetFillColor( aTextFillColor );
-        }
-    }
+    vcl::Font aFont = vcl::drawmode::GetFont(rNewFont, GetDrawMode(), GetSettings().GetStyleSettings());
 
     if ( mpMetaFile )
     {
diff --git a/vcl/source/outdev/pixel.cxx b/vcl/source/outdev/pixel.cxx
index 148c44113714..b051e6a5a119 100644
--- a/vcl/source/outdev/pixel.cxx
+++ b/vcl/source/outdev/pixel.cxx
@@ -24,6 +24,7 @@
 #include <vcl/outdev.hxx>
 #include <vcl/virdev.hxx>
 
+#include <drawmode.hxx>
 #include <salgdi.hxx>
 
 Color OutputDevice::GetPixel(const Point& rPoint) const
@@ -87,7 +88,7 @@ void OutputDevice::DrawPixel( const Point& rPt, const Color& rColor )
 {
     assert(!is_double_buffered_window());
 
-    Color aColor = ImplDrawModeToColor( rColor );
+    Color aColor = vcl::drawmode::GetLineColor(rColor, GetDrawMode(), GetSettings().GetStyleSettings());
 
     if ( mpMetaFile )
         mpMetaFile->AddAction( new MetaPixelAction( rPt, aColor ) );
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index cf73436df2cf..d4d73d817654 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -41,6 +41,7 @@
 
 #include <config_fuzzers.h>
 #include <outdev.h>
+#include <drawmode.hxx>
 #include <salgdi.hxx>
 #include <svdata.hxx>
 #include <textlayout.hxx>
@@ -662,24 +663,7 @@ tools::Long OutputDevice::ImplGetTextLines( ImplMultiTextLineInfo& rLineInfo,
 void OutputDevice::SetTextColor( const Color& rColor )
 {
 
-    Color aColor( rColor );
-
-    if ( mnDrawMode & ( DrawModeFlags::BlackText | DrawModeFlags::WhiteText |
-                        DrawModeFlags::GrayText |
-                        DrawModeFlags::SettingsText ) )
-    {
-        if ( mnDrawMode & DrawModeFlags::BlackText )
-            aColor = COL_BLACK;
-        else if ( mnDrawMode & DrawModeFlags::WhiteText )
-            aColor = COL_WHITE;
-        else if ( mnDrawMode & DrawModeFlags::GrayText )
-        {
-            const sal_uInt8 cLum = aColor.GetLuminance();
-            aColor = Color( cLum, cLum, cLum );
-        }
-        else if ( mnDrawMode & DrawModeFlags::SettingsText )
-            aColor = GetSettings().GetStyleSettings().GetFontColor();
-    }
+    Color aColor(vcl::drawmode::GetTextColor(rColor, GetDrawMode(), GetSettings().GetStyleSettings()));
 
     if ( mpMetaFile )
         mpMetaFile->AddAction( new MetaTextColorAction( aColor ) );
@@ -712,41 +696,15 @@ void OutputDevice::SetTextFillColor()
 
 void OutputDevice::SetTextFillColor( const Color& rColor )
 {
-    Color aColor( rColor );
-    bool bTransFill = aColor.IsTransparent();
-
-    if ( !bTransFill )
-    {
-        if ( mnDrawMode & ( DrawModeFlags::BlackFill | DrawModeFlags::WhiteFill |
-                            DrawModeFlags::GrayFill | DrawModeFlags::NoFill |
-                            DrawModeFlags::SettingsFill ) )
-        {
-            if ( mnDrawMode & DrawModeFlags::BlackFill )
-                aColor = COL_BLACK;
-            else if ( mnDrawMode & DrawModeFlags::WhiteFill )
-                aColor = COL_WHITE;
-            else if ( mnDrawMode & DrawModeFlags::GrayFill )
-            {
-                const sal_uInt8 cLum = aColor.GetLuminance();
-                aColor = Color( cLum, cLum, cLum );
-            }
-            else if( mnDrawMode & DrawModeFlags::SettingsFill )
-                aColor = GetSettings().GetStyleSettings().GetWindowColor();
-            else if ( mnDrawMode & DrawModeFlags::NoFill )
-            {
-                aColor = COL_TRANSPARENT;
-                bTransFill = true;
-            }
-        }
-    }
+    Color aColor(vcl::drawmode::GetFillColor(rColor, GetDrawMode(), GetSettings().GetStyleSettings()));
 
     if ( mpMetaFile )
         mpMetaFile->AddAction( new MetaTextFillColorAction( aColor, true ) );
 
     if ( maFont.GetFillColor() != aColor )
         maFont.SetFillColor( aColor );
-    if ( maFont.IsTransparent() != bTransFill )
-        maFont.SetTransparent( bTransFill );
+    if ( maFont.IsTransparent() != rColor.IsTransparent() )
+        maFont.SetTransparent( rColor.IsTransparent() );
 
     if( mpAlphaVDev )
         mpAlphaVDev->SetTextFillColor( COL_BLACK );
diff --git a/vcl/source/outdev/textline.cxx b/vcl/source/outdev/textline.cxx
index 127e1ce4a139..2ce85be775ad 100644
--- a/vcl/source/outdev/textline.cxx
+++ b/vcl/source/outdev/textline.cxx
@@ -29,6 +29,7 @@
 
 #include <tools/helpers.hxx>
 
+#include <drawmode.hxx>
 #include <salgdi.hxx>
 #include <impglyphitem.hxx>
 
@@ -874,31 +875,7 @@ void OutputDevice::SetTextLineColor()
 
 void OutputDevice::SetTextLineColor( const Color& rColor )
 {
-
-    Color aColor( rColor );
-
-    if ( mnDrawMode & ( DrawModeFlags::BlackText | DrawModeFlags::WhiteText |
-                        DrawModeFlags::GrayText |
-                        DrawModeFlags::SettingsText ) )
-    {
-        if ( mnDrawMode & DrawModeFlags::BlackText )
-        {
-            aColor = COL_BLACK;
-        }
-        else if ( mnDrawMode & DrawModeFlags::WhiteText )
-        {
-            aColor = COL_WHITE;
-        }
-        else if ( mnDrawMode & DrawModeFlags::GrayText )
-        {
-            const sal_uInt8 cLum = aColor.GetLuminance();
-            aColor = Color( cLum, cLum, cLum );
-        }
-        else if ( mnDrawMode & DrawModeFlags::SettingsText )
-        {
-            aColor = GetSettings().GetStyleSettings().GetFontColor();
-        }
-    }
+    Color aColor(vcl::drawmode::GetTextColor(rColor, GetDrawMode(), GetSettings().GetStyleSettings()));
 
     if ( mpMetaFile )
         mpMetaFile->AddAction( new MetaTextLineColorAction( aColor, true ) );
@@ -923,31 +900,7 @@ void OutputDevice::SetOverlineColor()
 
 void OutputDevice::SetOverlineColor( const Color& rColor )
 {
-
-    Color aColor( rColor );
-
-    if ( mnDrawMode & ( DrawModeFlags::BlackText | DrawModeFlags::WhiteText |
-                        DrawModeFlags::GrayText |
-                        DrawModeFlags::SettingsText ) )
-    {
-        if ( mnDrawMode & DrawModeFlags::BlackText )
-        {
-            aColor = COL_BLACK;
-        }
-        else if ( mnDrawMode & DrawModeFlags::WhiteText )
-        {
-            aColor = COL_WHITE;
-        }
-        else if ( mnDrawMode & DrawModeFlags::GrayText )
-        {
-            const sal_uInt8 cLum = aColor.GetLuminance();
-            aColor = Color( cLum, cLum, cLum );
-        }
-        else if ( mnDrawMode & DrawModeFlags::SettingsText )
-        {
-            aColor = GetSettings().GetStyleSettings().GetFontColor();
-        }
-    }
+    Color aColor(vcl::drawmode::GetTextColor(rColor, GetDrawMode(), GetSettings().GetStyleSettings()));
 
     if ( mpMetaFile )
         mpMetaFile->AddAction( new MetaOverlineColorAction( aColor, true ) );
diff --git a/vcl/source/outdev/transparent.cxx b/vcl/source/outdev/transparent.cxx
index 1648745d41e0..c633ce5d0ade 100644
--- a/vcl/source/outdev/transparent.cxx
+++ b/vcl/source/outdev/transparent.cxx
@@ -74,39 +74,6 @@ namespace
     }
 }
 
-Color OutputDevice::ImplDrawModeToColor( const Color& rColor ) const
-{
-    Color aColor( rColor );
-    DrawModeFlags nDrawMode = GetDrawMode();
-
-    if( nDrawMode & ( DrawModeFlags::BlackLine | DrawModeFlags::WhiteLine |
-                      DrawModeFlags::GrayLine |
-                      DrawModeFlags::SettingsLine ) )
-    {
-        if( !aColor.IsTransparent() )
-        {
-            if( nDrawMode & DrawModeFlags::BlackLine )
-            {
-                aColor = COL_BLACK;
-            }
-            else if( nDrawMode & DrawModeFlags::WhiteLine )
-            {
-                aColor = COL_WHITE;
-            }
-            else if( nDrawMode & DrawModeFlags::GrayLine )
-            {
-                const sal_uInt8 cLum = aColor.GetLuminance();
-                aColor = Color( cLum, cLum, cLum );
-            }
-            else if( nDrawMode & DrawModeFlags::SettingsLine )
-            {
-                aColor = GetSettings().GetStyleSettings().GetFontColor();
-            }
-        }
-    }
-    return aColor;
-}
-
 // Caution: This method is nearly the same as
 // void OutputDevice::DrawPolyPolygon( const basegfx::B2DPolyPolygon& rB2DPolyPoly )
 // so when changes are made here do not forget to make changes there, too
diff --git a/vcl/source/rendercontext/drawmode.cxx b/vcl/source/rendercontext/drawmode.cxx
new file mode 100644
index 000000000000..9b2b9236b92a
--- /dev/null
+++ b/vcl/source/rendercontext/drawmode.cxx
@@ -0,0 +1,275 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <vcl/BitmapMonochromeFilter.hxx>
+#include <vcl/bitmap/BitmapTypes.hxx>
+#include <vcl/rendercontext/DrawModeFlags.hxx>
+#include <vcl/settings.hxx>
+#include <vcl/virdev.hxx>
+
+#include <drawmode.hxx>
+
+namespace vcl::drawmode
+{
+Color GetLineColor(Color const& rColor, DrawModeFlags nDrawMode,
+                   StyleSettings const& rStyleSettings)
+{
+    Color aColor(rColor);
+
+    if (nDrawMode
+        & (DrawModeFlags::BlackLine | DrawModeFlags::WhiteLine | DrawModeFlags::GrayLine
+           | DrawModeFlags::SettingsLine))
+    {
+        if (!aColor.IsTransparent())
+        {
+            if (nDrawMode & DrawModeFlags::BlackLine)
+            {
+                aColor = COL_BLACK;
+            }
+            else if (nDrawMode & DrawModeFlags::WhiteLine)
+            {
+                aColor = COL_WHITE;
+            }
+            else if (nDrawMode & DrawModeFlags::GrayLine)
+            {
+                const sal_uInt8 cLum = aColor.GetLuminance();
+                aColor = Color(cLum, cLum, cLum);
+            }
+            else if (nDrawMode & DrawModeFlags::SettingsLine)
+            {
+                aColor = rStyleSettings.GetFontColor();
+            }
+        }
+    }
+
+    return aColor;
+}
+
+Color GetFillColor(Color const& rColor, DrawModeFlags nDrawMode,
+                   StyleSettings const& rStyleSettings)
+{
+    Color aColor(rColor);
+
+    if (nDrawMode
+        & (DrawModeFlags::BlackFill | DrawModeFlags::WhiteFill | DrawModeFlags::GrayFill
+           | DrawModeFlags::NoFill | DrawModeFlags::SettingsFill))
+    {
+        if (!aColor.IsTransparent())
+        {
+            if (nDrawMode & DrawModeFlags::BlackFill)
+            {
+                aColor = COL_BLACK;
+            }
+            else if (nDrawMode & DrawModeFlags::WhiteFill)
+            {
+                aColor = COL_WHITE;
+            }
+            else if (nDrawMode & DrawModeFlags::GrayFill)
+            {
+                const sal_uInt8 cLum = aColor.GetLuminance();
+                aColor = Color(cLum, cLum, cLum);
+            }
+            else if (nDrawMode & DrawModeFlags::NoFill)
+            {
+                aColor = COL_TRANSPARENT;
+            }
+            else if (nDrawMode & DrawModeFlags::SettingsFill)
+            {
+                aColor = rStyleSettings.GetWindowColor();
+            }
+        }
+    }
+
+    return aColor;
+}
+
+Color GetHatchColor(Color const& rColor, DrawModeFlags nDrawMode,
+                    StyleSettings const& rStyleSettings)
+{
+    Color aColor(rColor);
+
+    if (nDrawMode & DrawModeFlags::BlackLine)
+    {
+        aColor = COL_BLACK;
+    }
+    else if (nDrawMode & DrawModeFlags::WhiteLine)
+    {
+        aColor = COL_WHITE;
+    }
+    else if (nDrawMode & DrawModeFlags::GrayLine)
+    {
+        const sal_uInt8 cLum = aColor.GetLuminance();
+        aColor = Color(cLum, cLum, cLum);
+    }
+    else if (nDrawMode & DrawModeFlags::SettingsLine)
+    {
+        aColor = rStyleSettings.GetFontColor();
+    }
+
+    return aColor;
+}
+
+Color GetTextColor(Color const& rColor, DrawModeFlags nDrawMode,
+                   StyleSettings const& rStyleSettings)
+{
+    Color aColor(rColor);
+
+    if (nDrawMode
+        & (DrawModeFlags::BlackText | DrawModeFlags::WhiteText | DrawModeFlags::GrayText
+           | DrawModeFlags::SettingsText))
+    {
+        if (nDrawMode & DrawModeFlags::BlackText)
+        {
+            aColor = COL_BLACK;
+        }
+        else if (nDrawMode & DrawModeFlags::WhiteText)
+        {
+            aColor = COL_WHITE;
+        }
+        else if (nDrawMode & DrawModeFlags::GrayText)
+        {
+            const sal_uInt8 cLum = aColor.GetLuminance();
+            aColor = Color(cLum, cLum, cLum);
+        }
+        else if (nDrawMode & DrawModeFlags::SettingsText)
+        {
+            aColor = rStyleSettings.GetFontColor();
+        }
+    }
+
+    return aColor;
+}
+
+vcl::Font GetFont(vcl::Font const& rFont, DrawModeFlags nDrawMode,
+                  StyleSettings const& rStyleSettings)
+{
+    vcl::Font aFont(rFont);
+
+    if (nDrawMode
+        & (DrawModeFlags::BlackText | DrawModeFlags::WhiteText | DrawModeFlags::GrayText
+           | DrawModeFlags::SettingsText | DrawModeFlags::BlackFill | DrawModeFlags::WhiteFill
+           | DrawModeFlags::GrayFill | DrawModeFlags::NoFill | DrawModeFlags::SettingsFill))
+    {
+        Color aTextColor(aFont.GetColor());
+
+        if (nDrawMode & DrawModeFlags::BlackText)
+        {
+            aTextColor = COL_BLACK;
+        }
+        else if (nDrawMode & DrawModeFlags::WhiteText)
+        {
+            aTextColor = COL_WHITE;
+        }
+        else if (nDrawMode & DrawModeFlags::GrayText)
+        {
+            const sal_uInt8 cLum = aTextColor.GetLuminance();
+            aTextColor = Color(cLum, cLum, cLum);
+        }
+        else if (nDrawMode & DrawModeFlags::SettingsText)
+        {
+            aTextColor = rStyleSettings.GetFontColor();
+        }
+
+        aFont.SetColor(aTextColor);
+
+        if (!aFont.IsTransparent())
+        {
+            Color aTextFillColor(aFont.GetFillColor());
+
+            if (nDrawMode & DrawModeFlags::BlackFill)
+            {
+                aTextFillColor = COL_BLACK;
+            }
+            else if (nDrawMode & DrawModeFlags::WhiteFill)
+            {
+                aTextFillColor = COL_WHITE;
+            }
+            else if (nDrawMode & DrawModeFlags::GrayFill)
+            {
+                const sal_uInt8 cLum = aTextFillColor.GetLuminance();
+                aTextFillColor = Color(cLum, cLum, cLum);
+            }
+            else if (nDrawMode & DrawModeFlags::SettingsFill)
+            {
+                aTextFillColor = rStyleSettings.GetWindowColor();
+            }
+            else if (nDrawMode & DrawModeFlags::NoFill)
+            {
+                aTextFillColor = COL_TRANSPARENT;
+            }
+
+            aFont.SetFillColor(aTextFillColor);
+        }
+    }
+
+    return aFont;
+}
+
+Bitmap GetBitmap(Bitmap const& rBitmap, DrawModeFlags nDrawMode)
+{
+    Bitmap aBmp(rBitmap);
+
+    if (nDrawMode & DrawModeFlags::GrayBitmap)
+    {
+        if (!aBmp.IsEmpty())
+            aBmp.Convert(BmpConversion::N8BitGreys);
+    }
+
+    return aBmp;
+}
+
+BitmapEx GetBitmapEx(BitmapEx const& rBitmapEx, DrawModeFlags nDrawMode)
+{
+    BitmapEx aBmpEx(rBitmapEx);
+
+    if (nDrawMode & (DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap))
+    {
+        Bitmap aColorBmp(aBmpEx.GetSizePixel(), vcl::PixelFormat::N1_BPP);
+        sal_uInt8 cCmpVal;
+
+        if (nDrawMode & DrawModeFlags::BlackBitmap)
+            cCmpVal = 0;
+        else
+            cCmpVal = 255;
+
+        aColorBmp.Erase(Color(cCmpVal, cCmpVal, cCmpVal));
+
+        if (aBmpEx.IsAlpha())
+        {
+            // Create one-bit mask out of alpha channel, by thresholding it at alpha=0.5. As
+            // DRAWMODE_BLACK/WHITEBITMAP requires monochrome output, having alpha-induced
+            // grey levels is not acceptable
+            BitmapEx aMaskEx(aBmpEx.GetAlpha().GetBitmap());
+            BitmapFilter::Filter(aMaskEx, BitmapMonochromeFilter(129));
+            aBmpEx = BitmapEx(aColorBmp, aMaskEx.GetBitmap());
+        }
+        else
+        {
+            aBmpEx = BitmapEx(aColorBmp, aBmpEx.GetAlpha());
+        }
+    }
+
+    if (nDrawMode & DrawModeFlags::GrayBitmap && !aBmpEx.IsEmpty())
+        aBmpEx.Convert(BmpConversion::N8BitGreys);
+
+    return aBmpEx;
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */


More information about the Libreoffice-commits mailing list