1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: vclhelperbufferdevice.cxx,v $
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,
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
)
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
);
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()
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
);
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
));
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
);
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
));
153 mrOutDev
.DrawBitmap(maDestPixel
.TopLeft(), aContent
);
156 mrOutDev
.EnableMapMode(bWasEnabledDst
);
159 VirtualDevice
& impBufferDevice::getMask()
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!
173 VirtualDevice
& impBufferDevice::getAlpha()
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());
187 } // end of namespace drawinglayer
189 //////////////////////////////////////////////////////////////////////////////