Kaydet (Commit) 9153a36b authored tarafından Chris Sherlock's avatar Chris Sherlock

fdo#74702 Refactor OutputDevice::DrawTransparent()

I have refactored OutputDevice::DrawTransparent() - functionality
is now in the functions DrawInvisiblePolygon(),
DrawTransparentNatively() and EmulateDrawTransparent().

DrawTransparentNatively() will return true if it is successful,
otherwise it will return false if it isn't possible to draw the
transparency natively. This allows us to fall back to a VCL based
emulation.

The function EmulateDrawTransparent() is virtual because Printer
handles transparencies differently to pixel based devices.

Change-Id: I300850ccea03c17673666dadd287bcddd40ec5ef
Reviewed-on: https://gerrit.libreoffice.org/8779Reviewed-by: 's avatarChris Sherlock <chris.sherlock79@gmail.com>
Tested-by: 's avatarChris Sherlock <chris.sherlock79@gmail.com>
üst bb20d370
......@@ -805,6 +805,7 @@ protected:
const Point& rSrcPtPixel, const Size& rSrcSizePixel );
virtual long ImplGetGradientStepCount( long nMinRect );
/** Transform and draw a bitmap directly
@param aFullTransform The B2DHomMatrix used for the transformation
......@@ -839,6 +840,8 @@ protected:
const Point& rSrcPtPixel, const Size& rSrcSizePixel,
BitmapEx& rBitmapEx );
virtual void EmulateDrawTransparent( const PolyPolygon& rPolyPoly, sal_uInt16 nTransparencePercent );
void DrawInvisiblePolygon( const PolyPolygon& rPolyPoly );
private:
typedef void ( OutputDevice::* FontUpdateHandler_t )( bool );
......@@ -852,7 +855,9 @@ private:
SAL_DLLPRIVATE long ImplGetGradientSteps( const Gradient& rGradient, const Rectangle& rRect, bool bMtf );
// not implemented; to detect misuses of DrawOutDev(...OutputDevice&);
void DrawOutDev( const Point&, const Size&, const Point&, const Size&, const Printer&);
void DrawOutDev( const Point&, const Size&, const Point&, const Size&, const Printer&);
bool DrawTransparentNatively( const PolyPolygon& rPolyPoly, sal_uInt16 nTransparencePercent );
public:
virtual ~OutputDevice();
......
......@@ -286,6 +286,7 @@ protected:
virtual void ImplPrintMask ( const Bitmap& rMask, const Color& rMaskColor,
const Point& rDestPt, const Size& rDestSize,
const Point& rSrcPtPixel, const Size& rSrcSizePixel ) SAL_OVERRIDE;
bool DrawTransformBitmapExDirect(
const basegfx::B2DHomMatrix& aFullTransform,
const BitmapEx& rBitmapEx) SAL_OVERRIDE;
......@@ -300,6 +301,8 @@ protected:
const Point& rSrcPtPixel, const Size& rSrcSizePixel,
BitmapEx& rBitmapEx ) SAL_OVERRIDE;
virtual void EmulateDrawTransparent( const PolyPolygon& rPolyPoly, sal_uInt16 nTransparencePercent ) SAL_OVERRIDE;
public:
Printer();
Printer( const JobSetup& rJobSetup );
......
This diff is collapsed.
......@@ -250,6 +250,85 @@ void Printer::DrawDeviceBitmap( const Point& rDestPt, const Size& rDestSize,
}
}
void Printer::EmulateDrawTransparent ( const PolyPolygon& rPolyPoly,
sal_uInt16 nTransparencePercent )
{
// #110958# Disable alpha VDev, we perform the necessary
VirtualDevice* pOldAlphaVDev = mpAlphaVDev;
// operation explicitly further below.
if( mpAlphaVDev )
mpAlphaVDev = NULL;
GDIMetaFile* pOldMetaFile = mpMetaFile;
mpMetaFile = NULL;
mpMetaFile = pOldMetaFile;
// #110958# Restore disabled alpha VDev
mpAlphaVDev = pOldAlphaVDev;
Rectangle aPolyRect( LogicToPixel( rPolyPoly ).GetBoundRect() );
const Size aDPISize( LogicToPixel( Size( 1, 1 ), MAP_INCH ) );
const long nBaseExtent = std::max( FRound( aDPISize.Width() / 300. ), 1L );
long nMove;
const sal_uInt16 nTrans = ( nTransparencePercent < 13 ) ? 0 :
( nTransparencePercent < 38 ) ? 25 :
( nTransparencePercent < 63 ) ? 50 :
( nTransparencePercent < 88 ) ? 75 : 100;
switch( nTrans )
{
case( 25 ): nMove = nBaseExtent * 3; break;
case( 50 ): nMove = nBaseExtent * 4; break;
case( 75 ): nMove = nBaseExtent * 6; break;
// #i112959# very transparent (88 < nTransparencePercent <= 99)
case( 100 ): nMove = nBaseExtent * 8; break;
// #i112959# not transparent (nTransparencePercent < 13)
default: nMove = 0; break;
}
Push( PUSH_CLIPREGION | PUSH_LINECOLOR );
IntersectClipRegion(Region(rPolyPoly));
SetLineColor( GetFillColor() );
const bool bOldMap = mbMap;
EnableMapMode( false );
if(nMove)
{
Rectangle aRect( aPolyRect.TopLeft(), Size( aPolyRect.GetWidth(), nBaseExtent ) );
while( aRect.Top() <= aPolyRect.Bottom() )
{
DrawRect( aRect );
aRect.Move( 0, nMove );
}
aRect = Rectangle( aPolyRect.TopLeft(), Size( nBaseExtent, aPolyRect.GetHeight() ) );
while( aRect.Left() <= aPolyRect.Right() )
{
DrawRect( aRect );
aRect.Move( nMove, 0 );
}
}
else
{
// #i112959# if not transparent, draw full rectangle in clip region
DrawRect( aPolyRect );
}
EnableMapMode( bOldMap );
Pop();
mpMetaFile = pOldMetaFile;
// #110958# Restore disabled alpha VDev
mpAlphaVDev = pOldAlphaVDev;
}
void Printer::DrawOutDev( const Point& /*rDestPt*/, const Size& /*rDestSize*/,
const Point& /*rSrcPt*/, const Size& /*rSrcSize*/ )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment