vcl/source/gdi/outdev4.cxx | 203 ++++++++++++++------------------------------- 1 file changed, 64 insertions(+), 139 deletions(-)
New commits: commit 30e0e6ff95417295874e23376f83fc5ff26bf3d7 Author: Chris Sherlock <chris.sherloc...@gmail.com> Date: Sat Apr 12 21:09:51 2014 +1000 Unify DrawGradient functions in OutputDevice Turns out that the two versions of DrawGradient in OutputDevice are almost exactly the same in every way, except one deals with a rectangle and the other with a PolyPolygon. So I just convert the Rectangle into a PolyPolygon and use the PolyPolygon function. Now that the functions are unified, the need for a seperate function to clip and draw the gradient is no longer really required, so I've merged this back into DrawGradient. Change-Id: I94d4af1bb7dd900495672f0c0481dc9a1083ff67 diff --git a/vcl/source/gdi/outdev4.cxx b/vcl/source/gdi/outdev4.cxx index 794c6d7..6b76788 100644 --- a/vcl/source/gdi/outdev4.cxx +++ b/vcl/source/gdi/outdev4.cxx @@ -606,100 +606,11 @@ void OutputDevice::SetGrayscaleColors( Gradient &rGradient ) void OutputDevice::DrawGradient( const Rectangle& rRect, const Gradient& rGradient ) { - if ( mnDrawMode & DRAWMODE_NOGRADIENT ) - return; // nothing to draw! - - if ( mbInitClipRegion ) - ImplInitClipRegion(); - - if ( mbOutputClipped ) - return; - - if ( !rRect.IsEmpty() ) - { - if ( mnDrawMode & ( DRAWMODE_BLACKGRADIENT | DRAWMODE_WHITEGRADIENT | DRAWMODE_SETTINGSGRADIENT) ) - { - Color aColor = GetSingleColorGradientFill(); - - Push( PUSH_LINECOLOR | PUSH_FILLCOLOR ); - SetLineColor( aColor ); - SetFillColor( aColor ); - DrawRect( rRect ); - Pop(); - return; - } - - Gradient aGradient( rGradient ); - - if ( mnDrawMode & ( DRAWMODE_GRAYGRADIENT | DRAWMODE_GHOSTEDGRADIENT ) ) - { - SetGrayscaleColors( aGradient ); - } - - if( mpMetaFile ) - mpMetaFile->AddAction( new MetaGradientAction( rRect, aGradient ) ); - - if( !IsDeviceOutputNecessary() || ImplIsRecordLayout() ) - return; - - if ( !Rectangle( PixelToLogic( Point() ), GetOutputSize() ).IsEmpty() ) - { - // convert rectangle to pixels - Rectangle aRect( ImplLogicToDevicePixel( rRect ) ); - aRect.Justify(); - - // do nothing if the rectangle is empty - if ( !aRect.IsEmpty() ) - { - // we need a graphics - if ( !mpGraphics && !ImplGetGraphics() ) - return; - - // secure clip region - Push( PUSH_CLIPREGION ); - IntersectClipRegion( rRect ); - - // because we draw with no border line, we have to expand gradient - // rect to avoid missing lines on the right and bottom edge - aRect.Left()--; - aRect.Top()--; - aRect.Right()++; - aRect.Bottom()++; - - if ( mbInitClipRegion ) - ImplInitClipRegion(); - - if ( !mbOutputClipped ) - { - // gradients are drawn without border - if ( mbLineColor || mbInitLineColor ) - { - mpGraphics->SetLineColor(); - mbInitLineColor = true; - } - - mbInitFillColor = true; - - // calculate step count if necessary - if ( !aGradient.GetSteps() ) - aGradient.SetSteps( GRADIENT_DEFAULT_STEPCOUNT ); - - if( aGradient.GetStyle() == GradientStyle_LINEAR || aGradient.GetStyle() == GradientStyle_AXIAL ) - ImplDrawLinearGradient( aRect, aGradient, false, NULL ); - else - ImplDrawComplexGradient( aRect, aGradient, false, NULL ); - } - - Pop(); - } - } - } + // Convert rectangle to a PolyPolygon by first converting to a Polygon + Polygon aPolygon ( rRect ); + PolyPolygon aPolyPoly ( aPolygon ); - if( mpAlphaVDev ) - { - // #i32109#: Make gradient area opaque - mpAlphaVDev->ImplFillOpaqueRectangle( rRect ); - } + DrawGradient ( aPolyPoly, rGradient ); } void OutputDevice::ClipAndDrawGradientMetafile ( const Gradient &rGradient, const PolyPolygon &rPolyPoly ) @@ -720,69 +631,6 @@ void OutputDevice::ClipAndDrawGradientMetafile ( const Gradient &rGradient, cons EnableOutput( bOldOutput ); } -void OutputDevice::ClipAndDrawGradient ( Gradient &rGradient, const PolyPolygon &rPolyPoly ) -{ - const Rectangle aBoundRect( rPolyPoly.GetBoundRect() ); - - if( !Rectangle( PixelToLogic( Point() ), GetOutputSize() ).IsEmpty() ) - { - // convert rectangle to pixels - Rectangle aRect( ImplLogicToDevicePixel( aBoundRect ) ); - aRect.Justify(); - - // do nothing if the rectangle is empty - if ( !aRect.IsEmpty() ) - { - if( !mpGraphics && !ImplGetGraphics() ) - return; - - // secure clip region - Push( PUSH_CLIPREGION ); - IntersectClipRegion( aBoundRect ); - - if( mbInitClipRegion ) - ImplInitClipRegion(); - - if( !mbOutputClipped ) - { - PolyPolygon aClipPolyPoly( ImplLogicToDevicePixel( rPolyPoly ) ); - - // draw gradients without border - if( mbLineColor || mbInitLineColor ) - { - mpGraphics->SetLineColor(); - mbInitLineColor = true; - } - - mbInitFillColor = true; - - // calculate step count if necessary - if ( !rGradient.GetSteps() ) - rGradient.SetSteps( GRADIENT_DEFAULT_STEPCOUNT ); - - if ( rPolyPoly.IsRect() ) - { - // because we draw with no border line, we have to expand gradient - // rect to avoid missing lines on the right and bottom edge - aRect.Left()--; - aRect.Top()--; - aRect.Right()++; - aRect.Bottom()++; - } - - // if the clipping polypolygon is a rectangle, then it's the same size as the bounding of the - // polypolygon, so pass in a NULL for the clipping parameter - if( rGradient.GetStyle() == GradientStyle_LINEAR || rGradient.GetStyle() == GradientStyle_AXIAL ) - ImplDrawLinearGradient( aRect, rGradient, false, aClipPolyPoly.IsRect() ? NULL : &aClipPolyPoly ); - else - ImplDrawComplexGradient( aRect, rGradient, false, aClipPolyPoly.IsRect() ? NULL : &aClipPolyPoly ); - } - - Pop(); - } - } -} - void OutputDevice::DrawGradient( const PolyPolygon& rPolyPoly, const Gradient& rGradient ) { @@ -837,7 +685,66 @@ void OutputDevice::DrawGradient( const PolyPolygon& rPolyPoly, if( !IsDeviceOutputNecessary() || ImplIsRecordLayout() ) return; - ClipAndDrawGradient ( aGradient, rPolyPoly ); + // Clip and then draw the gradient + if( !Rectangle( PixelToLogic( Point() ), GetOutputSize() ).IsEmpty() ) + { + const Rectangle aBoundRect( rPolyPoly.GetBoundRect() ); + + // convert rectangle to pixels + Rectangle aRect( ImplLogicToDevicePixel( aBoundRect ) ); + aRect.Justify(); + + // do nothing if the rectangle is empty + if ( !aRect.IsEmpty() ) + { + if( !mpGraphics && !ImplGetGraphics() ) + return; + + // secure clip region + Push( PUSH_CLIPREGION ); + IntersectClipRegion( aBoundRect ); + + if( mbInitClipRegion ) + ImplInitClipRegion(); + + if( !mbOutputClipped ) + { + PolyPolygon aClipPolyPoly( ImplLogicToDevicePixel( rPolyPoly ) ); + + // draw gradients without border + if( mbLineColor || mbInitLineColor ) + { + mpGraphics->SetLineColor(); + mbInitLineColor = true; + } + + mbInitFillColor = true; + + // calculate step count if necessary + if ( !aGradient.GetSteps() ) + aGradient.SetSteps( GRADIENT_DEFAULT_STEPCOUNT ); + + if ( rPolyPoly.IsRect() ) + { + // because we draw with no border line, we have to expand gradient + // rect to avoid missing lines on the right and bottom edge + aRect.Left()--; + aRect.Top()--; + aRect.Right()++; + aRect.Bottom()++; + } + + // if the clipping polypolygon is a rectangle, then it's the same size as the bounding of the + // polypolygon, so pass in a NULL for the clipping parameter + if( aGradient.GetStyle() == GradientStyle_LINEAR || rGradient.GetStyle() == GradientStyle_AXIAL ) + ImplDrawLinearGradient( aRect, aGradient, false, aClipPolyPoly.IsRect() ? NULL : &aClipPolyPoly ); + else + ImplDrawComplexGradient( aRect, aGradient, false, aClipPolyPoly.IsRect() ? NULL : &aClipPolyPoly ); + } + + Pop(); + } + } } if( mpAlphaVDev ) commit 555d49bf1a5d299d45a3b29fa555efcd4e2c917a Author: Chris Sherlock <chris.sherloc...@gmail.com> Date: Sat Apr 12 20:47:29 2014 +1000 Detect if polypolygon is a rectangle in DrawGradient If the polypolygon that we use for DrawGradient is a rectangle, then we need to 1) expand the gradient rectangle to avoid missing lines on the right and bottom edge, and 2) we should pass NULL as the clipping parameter for ImplDrawLinearGradient and ImplDrawComplexGradient. Change-Id: I8d8289ace069b5c500db59d1a2addfcea8388dfb diff --git a/vcl/source/gdi/outdev4.cxx b/vcl/source/gdi/outdev4.cxx index fde2790..794c6d7 100644 --- a/vcl/source/gdi/outdev4.cxx +++ b/vcl/source/gdi/outdev4.cxx @@ -760,10 +760,22 @@ void OutputDevice::ClipAndDrawGradient ( Gradient &rGradient, const PolyPolygon if ( !rGradient.GetSteps() ) rGradient.SetSteps( GRADIENT_DEFAULT_STEPCOUNT ); + if ( rPolyPoly.IsRect() ) + { + // because we draw with no border line, we have to expand gradient + // rect to avoid missing lines on the right and bottom edge + aRect.Left()--; + aRect.Top()--; + aRect.Right()++; + aRect.Bottom()++; + } + + // if the clipping polypolygon is a rectangle, then it's the same size as the bounding of the + // polypolygon, so pass in a NULL for the clipping parameter if( rGradient.GetStyle() == GradientStyle_LINEAR || rGradient.GetStyle() == GradientStyle_AXIAL ) - ImplDrawLinearGradient( aRect, rGradient, false, &aClipPolyPoly ); + ImplDrawLinearGradient( aRect, rGradient, false, aClipPolyPoly.IsRect() ? NULL : &aClipPolyPoly ); else - ImplDrawComplexGradient( aRect, rGradient, false, &aClipPolyPoly ); + ImplDrawComplexGradient( aRect, rGradient, false, aClipPolyPoly.IsRect() ? NULL : &aClipPolyPoly ); } Pop(); commit 4981bb9eed1a51f8ce54d01c37bfb5b5d46f0637 Author: Chris Sherlock <chris.sherloc...@gmail.com> Date: Sat Apr 12 12:11:37 2014 +1000 Reduce the clip region in ClipAndDrawGradient We should reduce OutputDevice's clipping region to the bounds of the polypolygon. To do this we run OutputDevice::Push(PUSH_CLIPREGION) to have it set the clip region of the device, then intersect the clip region of the device with the bounding rectangle. Change-Id: I58ff5d1def1eca3c1213c7fd2d6a7205b70cdd01 diff --git a/vcl/source/gdi/outdev4.cxx b/vcl/source/gdi/outdev4.cxx index ed149c6..fde2790 100644 --- a/vcl/source/gdi/outdev4.cxx +++ b/vcl/source/gdi/outdev4.cxx @@ -736,6 +736,10 @@ void OutputDevice::ClipAndDrawGradient ( Gradient &rGradient, const PolyPolygon if( !mpGraphics && !ImplGetGraphics() ) return; + // secure clip region + Push( PUSH_CLIPREGION ); + IntersectClipRegion( aBoundRect ); + if( mbInitClipRegion ) ImplInitClipRegion(); @@ -761,6 +765,8 @@ void OutputDevice::ClipAndDrawGradient ( Gradient &rGradient, const PolyPolygon else ImplDrawComplexGradient( aRect, rGradient, false, &aClipPolyPoly ); } + + Pop(); } } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits