summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Eric Pelloux-Prayer <pierre-eric@lanedo.com>2013-09-02 13:57:41 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2013-09-04 08:09:12 +0000
commit02988a7a97dab7619d4f33e83385cce3982dc6e0 (patch)
treef83fb143af5bf30ef9abfd32a70d73a9f457955e
parent853167931600777e7bf44a35e051628a1169bcfc (diff)
sw/paint: replace bools by enum in DrawGraphic method
This change has 2 purposes: * fix gradient background when writing pdf. Before a gradient filled frame would be displayed as white (or transparent), because the transp. rendering mode was taking precedence over the gradient one. * making the code more readable by grouping multiple conditions in an enum. Change-Id: I5a30756b72be5eabf364c67e175c7b9d22bfa1c0 Reviewed-on: https://gerrit.libreoffice.org/5759 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r--sw/source/core/layout/paintfrm.cxx133
1 files changed, 81 insertions, 52 deletions
diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx
index 55e1952a38a0..afba1d643198 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -2013,9 +2013,24 @@ void DrawGraphic( const SvxBrushItem *pBrush,
/// ( background color is transparent OR
/// background graphic is transparent and background color is "no fill"
/// )
- bool bDrawTransparent = bConsiderBackgroundTransparency &&
- ( ( aColor.GetTransparency() != 0) ||
- bTransparentGrfWithNoFillBackgrd );
+
+ enum DrawStyle {
+ Default,
+ Transparent,
+ Gradient
+ } eDrawStyle = DrawStyle::Default;
+
+ // Gradient and transparency are mutually exclusive (need to check gradient first)
+ if (pFillStyleItem && pFillStyleItem->GetValue() == XFILL_GRADIENT && pFillGradientItem)
+ {
+ eDrawStyle = DrawStyle::Gradient;
+ }
+ else if (bConsiderBackgroundTransparency &&
+ ( ( aColor.GetTransparency() != 0) ||
+ bTransparentGrfWithNoFillBackgrd ) )
+ {
+ eDrawStyle = DrawStyle::Transparent;
+ }
// #i75614# reset draw mode in high contrast mode in order to get fill color set
const sal_uLong nOldDrawMode = pOutDev->GetDrawMode();
@@ -2028,15 +2043,20 @@ void DrawGraphic( const SvxBrushItem *pBrush,
/// OD 06.08.2002 #99657# - if background region have to be drawn
/// transparent, set only the RGB values of the background color as
/// the fill color for the output device.
- if ( bDrawTransparent )
- {
- if( pOutDev->GetFillColor() != aColor.GetRGBColor() )
- pOutDev->SetFillColor( aColor.GetRGBColor() );
- }
- else
+ switch (eDrawStyle)
{
- if( pOutDev->GetFillColor() != aColor )
- pOutDev->SetFillColor( aColor );
+ case DrawStyle::Transparent:
+ {
+ if( pOutDev->GetFillColor() != aColor.GetRGBColor() )
+ pOutDev->SetFillColor( aColor.GetRGBColor() );
+ break;
+ }
+ default:
+ {
+ if( pOutDev->GetFillColor() != aColor )
+ pOutDev->SetFillColor( aColor );
+ break;
+ }
}
// #i75614#
@@ -2044,57 +2064,66 @@ void DrawGraphic( const SvxBrushItem *pBrush,
pOutDev->SetDrawMode( nOldDrawMode );
/// OD 02.09.2002 #99657#
- if ( bDrawTransparent )
+ switch (eDrawStyle)
{
- /// background region have to be drawn transparent.
- /// Thus, create a poly-polygon from the region and draw it with
- /// the corresponding transparency precent.
- PolyPolygon aDrawPoly( rOut.SVRect() );
- if ( aGrf.HasArea() )
+ case DrawStyle::Transparent:
{
- if ( !bGrfIsTransparent )
+ /// background region have to be drawn transparent.
+ /// Thus, create a poly-polygon from the region and draw it with
+ /// the corresponding transparency precent.
+ PolyPolygon aDrawPoly( rOut.SVRect() );
+ if ( aGrf.HasArea() )
{
- /// substract area of background graphic from draw area
- /// OD 08.10.2002 #103898# - consider only that part of the
- /// graphic area that is overlapping with draw area.
- SwRect aTmpGrf = aGrf;
- aTmpGrf.Intersection( rOut );
- if ( aTmpGrf.HasArea() )
+ if ( !bGrfIsTransparent )
{
- Polygon aGrfPoly( aTmpGrf.SVRect() );
- aDrawPoly.Insert( aGrfPoly );
+ /// substract area of background graphic from draw area
+ /// OD 08.10.2002 #103898# - consider only that part of the
+ /// graphic area that is overlapping with draw area.
+ SwRect aTmpGrf = aGrf;
+ aTmpGrf.Intersection( rOut );
+ if ( aTmpGrf.HasArea() )
+ {
+ Polygon aGrfPoly( aTmpGrf.SVRect() );
+ aDrawPoly.Insert( aGrfPoly );
+ }
}
+ else
+ bGrfBackgrdAlreadyDrawn = true;
}
- else
- bGrfBackgrdAlreadyDrawn = true;
+ /// calculate transparency percent:
+ /// ( <transparency value[0x01..0xFF]>*100 + 0x7F ) / 0xFF
+ /// If there is a background graphic with a background color "no fill"/"auto fill",
+ /// the transparency value is taken from the background graphic,
+ /// otherwise take the transparency value from the color.
+ sal_Int8 nTransparencyPercent = static_cast<sal_Int8>(
+ (( bTransparentGrfWithNoFillBackgrd ? nGrfTransparency : aColor.GetTransparency()
+ )*100 + 0x7F)/0xFF);
+ /// draw poly-polygon transparent
+ pOutDev->DrawTransparent( aDrawPoly, nTransparencyPercent );
+
+ break;
}
- /// calculate transparency percent:
- /// ( <transparency value[0x01..0xFF]>*100 + 0x7F ) / 0xFF
- /// If there is a background graphic with a background color "no fill"/"auto fill",
- /// the transparency value is taken from the background graphic,
- /// otherwise take the transparency value from the color.
- sal_Int8 nTransparencyPercent = static_cast<sal_Int8>(
- (( bTransparentGrfWithNoFillBackgrd ? nGrfTransparency : aColor.GetTransparency()
- )*100 + 0x7F)/0xFF);
- /// draw poly-polygon transparent
- pOutDev->DrawTransparent( aDrawPoly, nTransparencyPercent );
- }
- else if (!pFillStyleItem || pFillStyleItem->GetValue() != XFILL_GRADIENT || !pFillGradientItem)
- {
- SwRegionRects aRegion( rOut, 4 );
- if ( !bGrfIsTransparent )
- aRegion -= aGrf;
- else
- bGrfBackgrdAlreadyDrawn = true;
- /// loop rectangles of background region, which has to be drawn
- for( sal_uInt16 i = 0; i < aRegion.size(); ++i )
+ case DrawStyle::Gradient:
{
- pOutDev->DrawRect( aRegion[i].SVRect() );
+ pOutDev->DrawGradient(rOut.SVRect(), pFillGradientItem->GetGradientValue().VclGradient());
+ break;
+ }
+ case DrawStyle::Default:
+ default:
+ {
+ SwRegionRects aRegion( rOut, 4 );
+ if ( !bGrfIsTransparent )
+ aRegion -= aGrf;
+ else
+ bGrfBackgrdAlreadyDrawn = true;
+ /// loop rectangles of background region, which has to be drawn
+ for( sal_uInt16 i = 0; i < aRegion.size(); ++i )
+ {
+ pOutDev->DrawRect( aRegion[i].SVRect() );
+ }
}
}
- else
- pOutDev->DrawGradient(rOut.SVRect(), pFillGradientItem->GetGradientValue().VclGradient());
- pOutDev ->Pop();
+ pOutDev ->Pop();
}
if( bDraw && aGrf.IsOver( rOut ) )