[PATCH] Reduced duplicate code detected by simian

Christina Rossmanith ChrRossmanith at web.de
Tue Jan 24 13:26:45 PST 2012


---
 vcl/inc/vcl/outdev.hxx     |    1 +
 vcl/source/gdi/outdev.cxx  |   32 ++++++++++++++++++++------------
 vcl/source/gdi/outdev2.cxx |   35 +----------------------------------
 3 files changed, 22 insertions(+), 46 deletions(-)

diff --git a/vcl/inc/vcl/outdev.hxx b/vcl/inc/vcl/outdev.hxx
index ea7787c..1c612b5 100644
--- a/vcl/inc/vcl/outdev.hxx
+++ b/vcl/inc/vcl/outdev.hxx
@@ -547,6 +547,7 @@ public:
 
     // tells whether this output device is RTL in an LTR UI or LTR in a RTL UI
     SAL_DLLPRIVATE bool ImplIsAntiparallel() const ;
+    SAL_DLLPRIVATE Color ImplDrawModeToColor( Color );
 
     // #i101491#
     // Helper which holds the old line geometry creation and is extended to use AA when
diff --git a/vcl/source/gdi/outdev.cxx b/vcl/source/gdi/outdev.cxx
index fe49527..b55a237 100644
--- a/vcl/source/gdi/outdev.cxx
+++ b/vcl/source/gdi/outdev.cxx
@@ -1238,38 +1238,36 @@ void OutputDevice::SetLineColor()
 
 // -----------------------------------------------------------------------
 
-void OutputDevice::SetLineColor( const Color& rColor )
+Color OutputDevice::ImplDrawModeToColor( const Color rColor )
 {
-    OSL_TRACE( "OutputDevice::SetLineColor( %lx )", rColor.GetColor() );
-    DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
-
     Color aColor( rColor );
+    sal_uLong  nDrawMode = GetDrawMode();
 
-    if( mnDrawMode & ( DRAWMODE_BLACKLINE | DRAWMODE_WHITELINE |
-                       DRAWMODE_GRAYLINE | DRAWMODE_GHOSTEDLINE |
-                       DRAWMODE_SETTINGSLINE ) )
+    if( nDrawMode & ( DRAWMODE_BLACKLINE | DRAWMODE_WHITELINE |
+                      DRAWMODE_GRAYLINE | DRAWMODE_GHOSTEDLINE |
+                      DRAWMODE_SETTINGSLINE ) )
     {
         if( !ImplIsColorTransparent( aColor ) )
         {
-            if( mnDrawMode & DRAWMODE_BLACKLINE )
+            if( nDrawMode & DRAWMODE_BLACKLINE )
             {
                 aColor = Color( COL_BLACK );
             }
-            else if( mnDrawMode & DRAWMODE_WHITELINE )
+            else if( nDrawMode & DRAWMODE_WHITELINE )
             {
                 aColor = Color( COL_WHITE );
             }
-            else if( mnDrawMode & DRAWMODE_GRAYLINE )
+            else if( nDrawMode & DRAWMODE_GRAYLINE )
             {
                 const sal_uInt8 cLum = aColor.GetLuminance();
                 aColor = Color( cLum, cLum, cLum );
             }
-            else if( mnDrawMode & DRAWMODE_SETTINGSLINE )
+            else if( nDrawMode & DRAWMODE_SETTINGSLINE )
             {
                 aColor = GetSettings().GetStyleSettings().GetFontColor();
             }
 
-            if( mnDrawMode & DRAWMODE_GHOSTEDLINE )
+            if( nDrawMode & DRAWMODE_GHOSTEDLINE )
             {
                 aColor = Color( ( aColor.GetRed() >> 1 ) | 0x80,
                                 ( aColor.GetGreen() >> 1 ) | 0x80,
@@ -1277,6 +1275,16 @@ void OutputDevice::SetLineColor( const Color& rColor )
             }
         }
     }
+    return aColor;
+}
+
+
+void OutputDevice::SetLineColor( const Color& rColor )
+{
+    OSL_TRACE( "OutputDevice::SetLineColor( %lx )", rColor.GetColor() );
+    DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
+
+    Color aColor = ImplDrawModeToColor( rColor );
 
     if( mpMetaFile )
         mpMetaFile->AddAction( new MetaLineColorAction( aColor, sal_True ) );
diff --git a/vcl/source/gdi/outdev2.cxx b/vcl/source/gdi/outdev2.cxx
index 2003de8..9b0b4f3 100644
--- a/vcl/source/gdi/outdev2.cxx
+++ b/vcl/source/gdi/outdev2.cxx
@@ -1441,40 +1441,7 @@ void OutputDevice::DrawPixel( const Point& rPt, const Color& rColor )
     OSL_TRACE( "OutputDevice::DrawPixel()" );
     DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
 
-    Color aColor( rColor );
-
-    if( mnDrawMode & ( DRAWMODE_BLACKLINE | DRAWMODE_WHITELINE |
-                       DRAWMODE_GRAYLINE | DRAWMODE_GHOSTEDLINE |
-                       DRAWMODE_SETTINGSLINE ) )
-    {
-        if( !ImplIsColorTransparent( aColor ) )
-        {
-            if( mnDrawMode & DRAWMODE_BLACKLINE )
-            {
-                aColor = Color( COL_BLACK );
-            }
-            else if( mnDrawMode & DRAWMODE_WHITELINE )
-            {
-                aColor = Color( COL_WHITE );
-            }
-            else if( mnDrawMode & DRAWMODE_GRAYLINE )
-            {
-                const sal_uInt8 cLum = aColor.GetLuminance();
-                aColor = Color( cLum, cLum, cLum );
-            }
-            else if( mnDrawMode & DRAWMODE_SETTINGSLINE )
-            {
-                aColor = GetSettings().GetStyleSettings().GetFontColor();
-            }
-
-            if( mnDrawMode & DRAWMODE_GHOSTEDLINE )
-            {
-                aColor = Color( ( aColor.GetRed() >> 1 ) | 0x80,
-                                ( aColor.GetGreen() >> 1 ) | 0x80,
-                                ( aColor.GetBlue() >> 1 ) | 0x80 );
-            }
-        }
-    }
+    Color aColor = ImplDrawModeToColor( rColor );
 
     if ( mpMetaFile )
         mpMetaFile->AddAction( new MetaPixelAction( rPt, aColor ) );
-- 
1.7.4.1


--------------000407020907080304080200--


More information about the LibreOffice mailing list