Update ooo320-m1
[ooovba.git] / drawinglayer / source / processor2d / vclhelperbufferdevice.cxx
blob39db373b1c7b8cffbad0a451e792e77545321e4e
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: vclhelperbufferdevice.cxx,v $
7 * $Revision: 1.6 $
9 * last change: $Author: aw $ $Date: 2008-05-27 14:11:22 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <vclhelperbufferdevice.hxx>
40 #include <basegfx/range/b2drange.hxx>
41 #include <vcl/bitmapex.hxx>
42 #include <basegfx/matrix/b2dhommatrix.hxx>
43 #include <tools/stream.hxx>
45 //////////////////////////////////////////////////////////////////////////////
46 // support for rendering Bitmap and BitmapEx contents
48 namespace drawinglayer
50 impBufferDevice::impBufferDevice(
51 OutputDevice& rOutDev,
52 const basegfx::B2DRange& rRange,
53 bool bAddOffsetToMapping)
54 : mrOutDev(rOutDev),
55 maContent(rOutDev),
56 mpMask(0L),
57 mpAlpha(0L)
59 basegfx::B2DRange aRangePixel(rRange);
60 aRangePixel.transform(rOutDev.GetViewTransformation());
61 const Rectangle aRectPixel(
62 (sal_Int32)floor(aRangePixel.getMinX()), (sal_Int32)floor(aRangePixel.getMinY()),
63 (sal_Int32)ceil(aRangePixel.getMaxX()), (sal_Int32)ceil(aRangePixel.getMaxY()));
64 const Point aEmptyPoint;
65 maDestPixel = Rectangle(aEmptyPoint, rOutDev.GetOutputSizePixel());
66 maDestPixel.Intersection(aRectPixel);
68 if(isVisible())
70 maContent.SetOutputSizePixel(maDestPixel.GetSize(), false);
72 // #i93485# assert when copying from window to VDev is used
73 OSL_ENSURE(rOutDev.GetOutDevType() != OUTDEV_WINDOW,
74 "impBufferDevice render helper: Copying from Window to VDev, this should be avoided (!)");
76 const bool bWasEnabledSrc(rOutDev.IsMapModeEnabled());
77 rOutDev.EnableMapMode(false);
78 maContent.DrawOutDev(aEmptyPoint, maDestPixel.GetSize(), maDestPixel.TopLeft(), maDestPixel.GetSize(), rOutDev);
79 rOutDev.EnableMapMode(bWasEnabledSrc);
81 MapMode aNewMapMode(rOutDev.GetMapMode());
83 if(bAddOffsetToMapping)
85 const Point aLogicTopLeft(rOutDev.PixelToLogic(maDestPixel.TopLeft()));
86 aNewMapMode.SetOrigin(Point(-aLogicTopLeft.X(), -aLogicTopLeft.Y()));
89 maContent.SetMapMode(aNewMapMode);
91 // copy AA flag for new target
92 maContent.SetAntialiasing(mrOutDev.GetAntialiasing());
96 impBufferDevice::~impBufferDevice()
98 delete mpMask;
99 delete mpAlpha;
102 void impBufferDevice::paint(double fTrans)
104 const Point aEmptyPoint;
105 const Size aSizePixel(maContent.GetOutputSizePixel());
106 const bool bWasEnabledDst(mrOutDev.IsMapModeEnabled());
107 static bool bDoSaveForVisualControl(false);
109 mrOutDev.EnableMapMode(false);
110 maContent.EnableMapMode(false);
111 Bitmap aContent(maContent.GetBitmap(aEmptyPoint, aSizePixel));
113 if(bDoSaveForVisualControl)
115 SvFileStream aNew((const String&)String(ByteString( "c:\\content.bmp" ), RTL_TEXTENCODING_UTF8), STREAM_WRITE|STREAM_TRUNC);
116 aNew << aContent;
119 if(mpAlpha)
121 mpAlpha->EnableMapMode(false);
122 const AlphaMask aAlphaMask(mpAlpha->GetBitmap(aEmptyPoint, aSizePixel));
124 if(bDoSaveForVisualControl)
126 SvFileStream aNew((const String&)String(ByteString( "c:\\alpha.bmp" ), RTL_TEXTENCODING_UTF8), STREAM_WRITE|STREAM_TRUNC);
127 aNew << aAlphaMask.GetBitmap();
130 mrOutDev.DrawBitmapEx(maDestPixel.TopLeft(), BitmapEx(aContent, aAlphaMask));
132 else if(mpMask)
134 mpMask->EnableMapMode(false);
135 const Bitmap aMask(mpMask->GetBitmap(aEmptyPoint, aSizePixel));
137 if(bDoSaveForVisualControl)
139 SvFileStream aNew((const String&)String(ByteString( "c:\\mask.bmp" ), RTL_TEXTENCODING_UTF8), STREAM_WRITE|STREAM_TRUNC);
140 aNew << aMask;
143 mrOutDev.DrawBitmapEx(maDestPixel.TopLeft(), BitmapEx(aContent, aMask));
145 else if(0.0 != fTrans)
147 sal_uInt8 nMaskValue((sal_uInt8)basegfx::fround(fTrans * 255.0));
148 const AlphaMask aAlphaMask(aSizePixel, &nMaskValue);
149 mrOutDev.DrawBitmapEx(maDestPixel.TopLeft(), BitmapEx(aContent, aAlphaMask));
151 else
153 mrOutDev.DrawBitmap(maDestPixel.TopLeft(), aContent);
156 mrOutDev.EnableMapMode(bWasEnabledDst);
159 VirtualDevice& impBufferDevice::getMask()
161 if(!mpMask)
163 mpMask = new VirtualDevice(mrOutDev, 1);
164 mpMask->SetOutputSizePixel(maDestPixel.GetSize(), true);
165 mpMask->SetMapMode(maContent.GetMapMode());
167 // do NOT copy AA flag for mask!
170 return *mpMask;
173 VirtualDevice& impBufferDevice::getAlpha()
175 if(!mpAlpha)
177 mpAlpha = new VirtualDevice();
178 mpAlpha->SetOutputSizePixel(maDestPixel.GetSize(), true);
179 mpAlpha->SetMapMode(maContent.GetMapMode());
181 // copy AA flag for new target; masking needs to be smooth
182 mpAlpha->SetAntialiasing(maContent.GetAntialiasing());
185 return *mpAlpha;
187 } // end of namespace drawinglayer
189 //////////////////////////////////////////////////////////////////////////////
190 // eof