xref: /AOO41X/main/drawinglayer/source/processor2d/vclhelperbufferdevice.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <vclhelperbufferdevice.hxx>
32*cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx>
33*cdf0e10cSrcweir #include <vcl/bitmapex.hxx>
34*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
35*cdf0e10cSrcweir #include <tools/stream.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
38*cdf0e10cSrcweir // support for rendering Bitmap and BitmapEx contents
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir namespace drawinglayer
41*cdf0e10cSrcweir {
42*cdf0e10cSrcweir 	impBufferDevice::impBufferDevice(
43*cdf0e10cSrcweir 		OutputDevice& rOutDev,
44*cdf0e10cSrcweir 		const basegfx::B2DRange& rRange,
45*cdf0e10cSrcweir 		bool bAddOffsetToMapping)
46*cdf0e10cSrcweir 	:	mrOutDev(rOutDev),
47*cdf0e10cSrcweir 		maContent(rOutDev),
48*cdf0e10cSrcweir 		mpMask(0L),
49*cdf0e10cSrcweir 		mpAlpha(0L)
50*cdf0e10cSrcweir 	{
51*cdf0e10cSrcweir         basegfx::B2DRange aRangePixel(rRange);
52*cdf0e10cSrcweir         aRangePixel.transform(rOutDev.GetViewTransformation());
53*cdf0e10cSrcweir         const Rectangle aRectPixel(
54*cdf0e10cSrcweir 			(sal_Int32)floor(aRangePixel.getMinX()), (sal_Int32)floor(aRangePixel.getMinY()),
55*cdf0e10cSrcweir 			(sal_Int32)ceil(aRangePixel.getMaxX()), (sal_Int32)ceil(aRangePixel.getMaxY()));
56*cdf0e10cSrcweir 		const Point aEmptyPoint;
57*cdf0e10cSrcweir 		maDestPixel = Rectangle(aEmptyPoint, rOutDev.GetOutputSizePixel());
58*cdf0e10cSrcweir 		maDestPixel.Intersection(aRectPixel);
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 		if(isVisible())
61*cdf0e10cSrcweir 		{
62*cdf0e10cSrcweir 			maContent.SetOutputSizePixel(maDestPixel.GetSize(), false);
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir             // #i93485# assert when copying from window to VDev is used
65*cdf0e10cSrcweir             OSL_ENSURE(rOutDev.GetOutDevType() != OUTDEV_WINDOW,
66*cdf0e10cSrcweir                 "impBufferDevice render helper: Copying from Window to VDev, this should be avoided (!)");
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir 			const bool bWasEnabledSrc(rOutDev.IsMapModeEnabled());
69*cdf0e10cSrcweir 			rOutDev.EnableMapMode(false);
70*cdf0e10cSrcweir 			maContent.DrawOutDev(aEmptyPoint, maDestPixel.GetSize(), maDestPixel.TopLeft(), maDestPixel.GetSize(), rOutDev);
71*cdf0e10cSrcweir 			rOutDev.EnableMapMode(bWasEnabledSrc);
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 			MapMode aNewMapMode(rOutDev.GetMapMode());
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 			if(bAddOffsetToMapping)
76*cdf0e10cSrcweir 			{
77*cdf0e10cSrcweir 				const Point aLogicTopLeft(rOutDev.PixelToLogic(maDestPixel.TopLeft()));
78*cdf0e10cSrcweir 				aNewMapMode.SetOrigin(Point(-aLogicTopLeft.X(), -aLogicTopLeft.Y()));
79*cdf0e10cSrcweir 			}
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir 			maContent.SetMapMode(aNewMapMode);
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir             // copy AA flag for new target
84*cdf0e10cSrcweir             maContent.SetAntialiasing(mrOutDev.GetAntialiasing());
85*cdf0e10cSrcweir 		}
86*cdf0e10cSrcweir 	}
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 	impBufferDevice::~impBufferDevice()
89*cdf0e10cSrcweir 	{
90*cdf0e10cSrcweir 		delete mpMask;
91*cdf0e10cSrcweir 		delete mpAlpha;
92*cdf0e10cSrcweir 	}
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 	void impBufferDevice::paint(double fTrans)
95*cdf0e10cSrcweir 	{
96*cdf0e10cSrcweir 		const Point aEmptyPoint;
97*cdf0e10cSrcweir 		const Size aSizePixel(maContent.GetOutputSizePixel());
98*cdf0e10cSrcweir 		const bool bWasEnabledDst(mrOutDev.IsMapModeEnabled());
99*cdf0e10cSrcweir     	static bool bDoSaveForVisualControl(false);
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 		mrOutDev.EnableMapMode(false);
102*cdf0e10cSrcweir 		maContent.EnableMapMode(false);
103*cdf0e10cSrcweir 		Bitmap aContent(maContent.GetBitmap(aEmptyPoint, aSizePixel));
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 		if(bDoSaveForVisualControl)
106*cdf0e10cSrcweir 		{
107*cdf0e10cSrcweir 			SvFileStream aNew((const String&)String(ByteString( "c:\\content.bmp" ), RTL_TEXTENCODING_UTF8), STREAM_WRITE|STREAM_TRUNC);
108*cdf0e10cSrcweir 			aNew << aContent;
109*cdf0e10cSrcweir 		}
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir         if(mpAlpha)
112*cdf0e10cSrcweir 		{
113*cdf0e10cSrcweir 			mpAlpha->EnableMapMode(false);
114*cdf0e10cSrcweir 			const AlphaMask aAlphaMask(mpAlpha->GetBitmap(aEmptyPoint, aSizePixel));
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir             if(bDoSaveForVisualControl)
117*cdf0e10cSrcweir 		    {
118*cdf0e10cSrcweir 			    SvFileStream aNew((const String&)String(ByteString( "c:\\transparence.bmp" ), RTL_TEXTENCODING_UTF8), STREAM_WRITE|STREAM_TRUNC);
119*cdf0e10cSrcweir 			    aNew << aAlphaMask.GetBitmap();
120*cdf0e10cSrcweir 		    }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir             mrOutDev.DrawBitmapEx(maDestPixel.TopLeft(), BitmapEx(aContent, aAlphaMask));
123*cdf0e10cSrcweir 		}
124*cdf0e10cSrcweir 		else if(mpMask)
125*cdf0e10cSrcweir 		{
126*cdf0e10cSrcweir 			mpMask->EnableMapMode(false);
127*cdf0e10cSrcweir 			const Bitmap aMask(mpMask->GetBitmap(aEmptyPoint, aSizePixel));
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir             if(bDoSaveForVisualControl)
130*cdf0e10cSrcweir 		    {
131*cdf0e10cSrcweir 			    SvFileStream aNew((const String&)String(ByteString( "c:\\mask.bmp" ), RTL_TEXTENCODING_UTF8), STREAM_WRITE|STREAM_TRUNC);
132*cdf0e10cSrcweir 			    aNew << aMask;
133*cdf0e10cSrcweir 		    }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir             mrOutDev.DrawBitmapEx(maDestPixel.TopLeft(), BitmapEx(aContent, aMask));
136*cdf0e10cSrcweir 		}
137*cdf0e10cSrcweir 		else if(0.0 != fTrans)
138*cdf0e10cSrcweir 		{
139*cdf0e10cSrcweir 			sal_uInt8 nMaskValue((sal_uInt8)basegfx::fround(fTrans * 255.0));
140*cdf0e10cSrcweir 			const AlphaMask aAlphaMask(aSizePixel, &nMaskValue);
141*cdf0e10cSrcweir 			mrOutDev.DrawBitmapEx(maDestPixel.TopLeft(), BitmapEx(aContent, aAlphaMask));
142*cdf0e10cSrcweir 		}
143*cdf0e10cSrcweir 		else
144*cdf0e10cSrcweir 		{
145*cdf0e10cSrcweir 			mrOutDev.DrawBitmap(maDestPixel.TopLeft(), aContent);
146*cdf0e10cSrcweir 		}
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 		mrOutDev.EnableMapMode(bWasEnabledDst);
149*cdf0e10cSrcweir 	}
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 	VirtualDevice& impBufferDevice::getMask()
152*cdf0e10cSrcweir 	{
153*cdf0e10cSrcweir 		if(!mpMask)
154*cdf0e10cSrcweir 		{
155*cdf0e10cSrcweir 			mpMask = new VirtualDevice(mrOutDev, 1);
156*cdf0e10cSrcweir 			mpMask->SetOutputSizePixel(maDestPixel.GetSize(), true);
157*cdf0e10cSrcweir 			mpMask->SetMapMode(maContent.GetMapMode());
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir             // do NOT copy AA flag for mask!
160*cdf0e10cSrcweir 		}
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 		return *mpMask;
163*cdf0e10cSrcweir 	}
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 	VirtualDevice& impBufferDevice::getTransparence()
166*cdf0e10cSrcweir 	{
167*cdf0e10cSrcweir 		if(!mpAlpha)
168*cdf0e10cSrcweir 		{
169*cdf0e10cSrcweir 			mpAlpha = new VirtualDevice();
170*cdf0e10cSrcweir 			mpAlpha->SetOutputSizePixel(maDestPixel.GetSize(), true);
171*cdf0e10cSrcweir 			mpAlpha->SetMapMode(maContent.GetMapMode());
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir             // copy AA flag for new target; masking needs to be smooth
174*cdf0e10cSrcweir             mpAlpha->SetAntialiasing(maContent.GetAntialiasing());
175*cdf0e10cSrcweir 		}
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 		return *mpAlpha;
178*cdf0e10cSrcweir 	}
179*cdf0e10cSrcweir } // end of namespace drawinglayer
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
182*cdf0e10cSrcweir // eof
183