1*464702f4SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*464702f4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*464702f4SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*464702f4SAndrew Rist * distributed with this work for additional information 6*464702f4SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*464702f4SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*464702f4SAndrew Rist * "License"); you may not use this file except in compliance 9*464702f4SAndrew Rist * with the License. You may obtain a copy of the License at 10*464702f4SAndrew Rist * 11*464702f4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*464702f4SAndrew Rist * 13*464702f4SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*464702f4SAndrew Rist * software distributed under the License is distributed on an 15*464702f4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*464702f4SAndrew Rist * KIND, either express or implied. See the License for the 17*464702f4SAndrew Rist * specific language governing permissions and limitations 18*464702f4SAndrew Rist * under the License. 19*464702f4SAndrew Rist * 20*464702f4SAndrew Rist *************************************************************/ 21*464702f4SAndrew Rist 22*464702f4SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <vclhelperbufferdevice.hxx> 28cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx> 29cdf0e10cSrcweir #include <vcl/bitmapex.hxx> 30cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 31cdf0e10cSrcweir #include <tools/stream.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 34cdf0e10cSrcweir // support for rendering Bitmap and BitmapEx contents 35cdf0e10cSrcweir 36cdf0e10cSrcweir namespace drawinglayer 37cdf0e10cSrcweir { 38cdf0e10cSrcweir impBufferDevice::impBufferDevice( 39cdf0e10cSrcweir OutputDevice& rOutDev, 40cdf0e10cSrcweir const basegfx::B2DRange& rRange, 41cdf0e10cSrcweir bool bAddOffsetToMapping) 42cdf0e10cSrcweir : mrOutDev(rOutDev), 43cdf0e10cSrcweir maContent(rOutDev), 44cdf0e10cSrcweir mpMask(0L), 45cdf0e10cSrcweir mpAlpha(0L) 46cdf0e10cSrcweir { 47cdf0e10cSrcweir basegfx::B2DRange aRangePixel(rRange); 48cdf0e10cSrcweir aRangePixel.transform(rOutDev.GetViewTransformation()); 49cdf0e10cSrcweir const Rectangle aRectPixel( 50cdf0e10cSrcweir (sal_Int32)floor(aRangePixel.getMinX()), (sal_Int32)floor(aRangePixel.getMinY()), 51cdf0e10cSrcweir (sal_Int32)ceil(aRangePixel.getMaxX()), (sal_Int32)ceil(aRangePixel.getMaxY())); 52cdf0e10cSrcweir const Point aEmptyPoint; 53cdf0e10cSrcweir maDestPixel = Rectangle(aEmptyPoint, rOutDev.GetOutputSizePixel()); 54cdf0e10cSrcweir maDestPixel.Intersection(aRectPixel); 55cdf0e10cSrcweir 56cdf0e10cSrcweir if(isVisible()) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir maContent.SetOutputSizePixel(maDestPixel.GetSize(), false); 59cdf0e10cSrcweir 60cdf0e10cSrcweir // #i93485# assert when copying from window to VDev is used 61cdf0e10cSrcweir OSL_ENSURE(rOutDev.GetOutDevType() != OUTDEV_WINDOW, 62cdf0e10cSrcweir "impBufferDevice render helper: Copying from Window to VDev, this should be avoided (!)"); 63cdf0e10cSrcweir 64cdf0e10cSrcweir const bool bWasEnabledSrc(rOutDev.IsMapModeEnabled()); 65cdf0e10cSrcweir rOutDev.EnableMapMode(false); 66cdf0e10cSrcweir maContent.DrawOutDev(aEmptyPoint, maDestPixel.GetSize(), maDestPixel.TopLeft(), maDestPixel.GetSize(), rOutDev); 67cdf0e10cSrcweir rOutDev.EnableMapMode(bWasEnabledSrc); 68cdf0e10cSrcweir 69cdf0e10cSrcweir MapMode aNewMapMode(rOutDev.GetMapMode()); 70cdf0e10cSrcweir 71cdf0e10cSrcweir if(bAddOffsetToMapping) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir const Point aLogicTopLeft(rOutDev.PixelToLogic(maDestPixel.TopLeft())); 74cdf0e10cSrcweir aNewMapMode.SetOrigin(Point(-aLogicTopLeft.X(), -aLogicTopLeft.Y())); 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir maContent.SetMapMode(aNewMapMode); 78cdf0e10cSrcweir 79cdf0e10cSrcweir // copy AA flag for new target 80cdf0e10cSrcweir maContent.SetAntialiasing(mrOutDev.GetAntialiasing()); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir impBufferDevice::~impBufferDevice() 85cdf0e10cSrcweir { 86cdf0e10cSrcweir delete mpMask; 87cdf0e10cSrcweir delete mpAlpha; 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir void impBufferDevice::paint(double fTrans) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir const Point aEmptyPoint; 93cdf0e10cSrcweir const Size aSizePixel(maContent.GetOutputSizePixel()); 94cdf0e10cSrcweir const bool bWasEnabledDst(mrOutDev.IsMapModeEnabled()); 95cdf0e10cSrcweir static bool bDoSaveForVisualControl(false); 96cdf0e10cSrcweir 97cdf0e10cSrcweir mrOutDev.EnableMapMode(false); 98cdf0e10cSrcweir maContent.EnableMapMode(false); 99cdf0e10cSrcweir Bitmap aContent(maContent.GetBitmap(aEmptyPoint, aSizePixel)); 100cdf0e10cSrcweir 101cdf0e10cSrcweir if(bDoSaveForVisualControl) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir SvFileStream aNew((const String&)String(ByteString( "c:\\content.bmp" ), RTL_TEXTENCODING_UTF8), STREAM_WRITE|STREAM_TRUNC); 104cdf0e10cSrcweir aNew << aContent; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir if(mpAlpha) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir mpAlpha->EnableMapMode(false); 110cdf0e10cSrcweir const AlphaMask aAlphaMask(mpAlpha->GetBitmap(aEmptyPoint, aSizePixel)); 111cdf0e10cSrcweir 112cdf0e10cSrcweir if(bDoSaveForVisualControl) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir SvFileStream aNew((const String&)String(ByteString( "c:\\transparence.bmp" ), RTL_TEXTENCODING_UTF8), STREAM_WRITE|STREAM_TRUNC); 115cdf0e10cSrcweir aNew << aAlphaMask.GetBitmap(); 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir mrOutDev.DrawBitmapEx(maDestPixel.TopLeft(), BitmapEx(aContent, aAlphaMask)); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir else if(mpMask) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir mpMask->EnableMapMode(false); 123cdf0e10cSrcweir const Bitmap aMask(mpMask->GetBitmap(aEmptyPoint, aSizePixel)); 124cdf0e10cSrcweir 125cdf0e10cSrcweir if(bDoSaveForVisualControl) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir SvFileStream aNew((const String&)String(ByteString( "c:\\mask.bmp" ), RTL_TEXTENCODING_UTF8), STREAM_WRITE|STREAM_TRUNC); 128cdf0e10cSrcweir aNew << aMask; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir mrOutDev.DrawBitmapEx(maDestPixel.TopLeft(), BitmapEx(aContent, aMask)); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir else if(0.0 != fTrans) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir sal_uInt8 nMaskValue((sal_uInt8)basegfx::fround(fTrans * 255.0)); 136cdf0e10cSrcweir const AlphaMask aAlphaMask(aSizePixel, &nMaskValue); 137cdf0e10cSrcweir mrOutDev.DrawBitmapEx(maDestPixel.TopLeft(), BitmapEx(aContent, aAlphaMask)); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir else 140cdf0e10cSrcweir { 141cdf0e10cSrcweir mrOutDev.DrawBitmap(maDestPixel.TopLeft(), aContent); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir mrOutDev.EnableMapMode(bWasEnabledDst); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir VirtualDevice& impBufferDevice::getMask() 148cdf0e10cSrcweir { 149cdf0e10cSrcweir if(!mpMask) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir mpMask = new VirtualDevice(mrOutDev, 1); 152cdf0e10cSrcweir mpMask->SetOutputSizePixel(maDestPixel.GetSize(), true); 153cdf0e10cSrcweir mpMask->SetMapMode(maContent.GetMapMode()); 154cdf0e10cSrcweir 155cdf0e10cSrcweir // do NOT copy AA flag for mask! 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir return *mpMask; 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir VirtualDevice& impBufferDevice::getTransparence() 162cdf0e10cSrcweir { 163cdf0e10cSrcweir if(!mpAlpha) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir mpAlpha = new VirtualDevice(); 166cdf0e10cSrcweir mpAlpha->SetOutputSizePixel(maDestPixel.GetSize(), true); 167cdf0e10cSrcweir mpAlpha->SetMapMode(maContent.GetMapMode()); 168cdf0e10cSrcweir 169cdf0e10cSrcweir // copy AA flag for new target; masking needs to be smooth 170cdf0e10cSrcweir mpAlpha->SetAntialiasing(maContent.GetAntialiasing()); 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir return *mpAlpha; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir } // end of namespace drawinglayer 176cdf0e10cSrcweir 177cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 178cdf0e10cSrcweir // eof 179