Hi,
please have a look at the comments marked with "crossmanith". I can push
on my own but a short review (and feedback) would be nice.
Christina
From ac8d464245852f701478039f89ae876d6584fb88 Mon Sep 17 00:00:00 2001
From: Christina Rossmanith <ChrRossmanith@web.de>
Date: Tue, 31 Jan 2012 10:07:19 +0100
Subject: [PATCH] SIMIAN: Reduced duplicate code
---
vcl/source/gdi/outdev4.cxx | 118 +++++++++++++++++--------------------------
1 files changed, 47 insertions(+), 71 deletions(-)
diff --git a/vcl/source/gdi/outdev4.cxx b/vcl/source/gdi/outdev4.cxx
index 735a85e..63c53e4 100644
--- a/vcl/source/gdi/outdev4.cxx
+++ b/vcl/source/gdi/outdev4.cxx
@@ -168,6 +168,45 @@ inline sal_uInt8 ImplGetGradientColorValue( long nValue )
}
// -----------------------------------------------------------------------
+long ImplCalcGradientSteps( const Gradient& rGradient, const sal_Bool bMtf, const long nSize,
const OutDevType outdevtype, const long nMaxSteps )
+{
+ long nStepCount;
+
+ // calculate number of steps if no value was passed in rGradient
+ if( !rGradient.GetSteps() )
+ {
+ long nInc;
+
+ if ( outdevtype != OUTDEV_PRINTER && !bMtf )
+ {
+ nInc = ( nSize < 50 ) ? 2 : 4;
+ }
+ else
+ {
+ // #105998# Use display-equivalent step size calculation
+ nInc = ( nSize < 800 ) ? 10 : 20;
+ }
+
+ if( !nInc )
+ nInc = 1; // (crossmanith: code reachable???)
+
+ nStepCount = nSize / nInc;
+ }
+ else {
+ nStepCount = rGradient.GetSteps();
+ }
+
+ // minimum number of steps: 3 (crossmanith: or is it 2?)
+ // maximum number of steps: nMaxSteps
+ long nSteps = Max( nStepCount, 2L );
+
+ if ( nSteps > nMaxSteps )
+ nSteps = nMaxSteps;
+ if ( !nSteps )
+ nSteps = 1;
+
+ return nSteps;
+}
void OutputDevice::ImplDrawLinearGradient( const Rectangle& rRect,
const Gradient& rGradient,
@@ -226,50 +265,19 @@ void OutputDevice::ImplDrawLinearGradient( const Rectangle& rRect,
long nRedSteps = nEndRed - nStartRed;
long nGreenSteps = nEndGreen - nStartGreen;
long nBlueSteps = nEndBlue - nStartBlue;
- long nStepCount = rGradient.GetSteps();
- // Bei nicht linearen Farbverlaeufen haben wir nur die halben Steps
+ // Bei axialen Farbverlaeufen haben wir nur die halben Steps
// pro Farbe
- if ( !bLinear )
+ if ( rGradient.GetStyle() == GRADIENT_AXIAL )
{
nRedSteps <<= 1;
nGreenSteps <<= 1;
nBlueSteps <<= 1;
}
- // Anzahl der Schritte berechnen, falls nichts uebergeben wurde
- if ( !nStepCount )
- {
- long nInc;
-
- if ( meOutDevType != OUTDEV_PRINTER && !bMtf )
- {
- nInc = (nMinRect < 50) ? 2 : 4;
- }
- else
- {
- // #105998# Use display-equivalent step size calculation
- nInc = (nMinRect < 800) ? 10 : 20;
- }
-
- if ( !nInc )
- nInc = 1;
-
- nStepCount = nMinRect / nInc;
- }
- // minimal drei Schritte und maximal die Anzahl der Farbunterschiede
- long nSteps = Max( nStepCount, 2L );
- long nCalcSteps = Abs( nRedSteps );
- long nTempSteps = Abs( nGreenSteps );
- if ( nTempSteps > nCalcSteps )
- nCalcSteps = nTempSteps;
- nTempSteps = Abs( nBlueSteps );
- if ( nTempSteps > nCalcSteps )
- nCalcSteps = nTempSteps;
- if ( nCalcSteps < nSteps )
- nSteps = nCalcSteps;
- if ( !nSteps )
- nSteps = 1;
+ // max(red,green,blue)
+ long nMaxGradientSteps = Max( Max( Abs( nRedSteps ), Abs( nGreenSteps ) ), Abs( nBlueSteps ));
+ long nSteps = ImplCalcGradientSteps( rGradient, bMtf, nMinRect, meOutDevType,
nMaxGradientSteps );
// Falls axialer Farbverlauf, muss die Schrittanzahl ungerade sein
if ( !bLinear && !(nSteps & 1) )
@@ -437,7 +445,6 @@ void OutputDevice::ImplDrawComplexGradient( const Rectangle& rRect,
long nRedSteps = nEndRed - nStartRed;
long nGreenSteps = nEndGreen - nStartGreen;
long nBlueSteps = nEndBlue - nStartBlue;
- long nStepCount = rGradient.GetSteps();
sal_uInt16 nAngle = rGradient.GetAngle() % 3600;
rGradient.GetBoundRect( rRect, aRect, aCenter );
@@ -449,40 +456,9 @@ void OutputDevice::ImplDrawComplexGradient( const Rectangle& rRect,
long nMinRect = Min( aRect.GetWidth(), aRect.GetHeight() );
- // Anzahl der Schritte berechnen, falls nichts uebergeben wurde
- if( !nStepCount )
- {
- long nInc;
-
- if ( meOutDevType != OUTDEV_PRINTER && !bMtf )
- {
- nInc = ( nMinRect < 50 ) ? 2 : 4;
- }
- else
- {
- // #105998# Use display-equivalent step size calculation
- nInc = (nMinRect < 800) ? 10 : 20;
- }
-
- if( !nInc )
- nInc = 1;
-
- nStepCount = nMinRect / nInc;
- }
-
- // minimal drei Schritte und maximal die Anzahl der Farbunterschiede
- long nSteps = Max( nStepCount, 2L );
- long nCalcSteps = Abs( nRedSteps );
- long nTempSteps = Abs( nGreenSteps );
- if ( nTempSteps > nCalcSteps )
- nCalcSteps = nTempSteps;
- nTempSteps = Abs( nBlueSteps );
- if ( nTempSteps > nCalcSteps )
- nCalcSteps = nTempSteps;
- if ( nCalcSteps < nSteps )
- nSteps = nCalcSteps;
- if ( !nSteps )
- nSteps = 1;
+ // max(red,green,blue)
+ long nMaxGradientSteps = Max( Max( Abs( nRedSteps ), Abs( nGreenSteps ) ), Abs( nBlueSteps ));
+ long nSteps = ImplCalcGradientSteps( rGradient, bMtf, nMinRect, meOutDevType,
nMaxGradientSteps );
// Ausgabebegrenzungen und Schrittweite fuer jede Richtung festlegen
Polygon aPoly;
--
1.7.4.1
Context
- [Libreoffice] [PATCH] SIMIAN: Reduced duplicate code · Chr. Rossmanith
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.