1ddde725dSArmin Le Grand /************************************************************** 2ddde725dSArmin Le Grand * 3ddde725dSArmin Le Grand * Licensed to the Apache Software Foundation (ASF) under one 4ddde725dSArmin Le Grand * or more contributor license agreements. See the NOTICE file 5ddde725dSArmin Le Grand * distributed with this work for additional information 6ddde725dSArmin Le Grand * regarding copyright ownership. The ASF licenses this file 7ddde725dSArmin Le Grand * to you under the Apache License, Version 2.0 (the 8ddde725dSArmin Le Grand * "License"); you may not use this file except in compliance 9ddde725dSArmin Le Grand * with the License. You may obtain a copy of the License at 10ddde725dSArmin Le Grand * 11*2b45cf47SArmin Le Grand * http://www.apache.org/licenses/LICENSE-2.0 12ddde725dSArmin Le Grand * 13ddde725dSArmin Le Grand * Unless required by applicable law or agreed to in writing, 14ddde725dSArmin Le Grand * software distributed under the License is distributed on an 15ddde725dSArmin Le Grand * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ddde725dSArmin Le Grand * KIND, either express or implied. See the License for the 17ddde725dSArmin Le Grand * specific language governing permissions and limitations 18ddde725dSArmin Le Grand * under the License. 19ddde725dSArmin Le Grand * 20ddde725dSArmin Le Grand *************************************************************/ 21ddde725dSArmin Le Grand 22ddde725dSArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove 23ddde725dSArmin Le Grand #include "precompiled_drawinglayer.hxx" 24ddde725dSArmin Le Grand 25ddde725dSArmin Le Grand #include <drawinglayer/tools/converters.hxx> 26ddde725dSArmin Le Grand #include <drawinglayer/geometry/viewinformation2d.hxx> 27ddde725dSArmin Le Grand #include <drawinglayer/processor2d/vclpixelprocessor2d.hxx> 28ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx> 29ddde725dSArmin Le Grand #include <basegfx/matrix/b2dhommatrixtools.hxx> 30ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 31ddde725dSArmin Le Grand #include <vcl/virdev.hxx> 32ddde725dSArmin Le Grand 33ddde725dSArmin Le Grand #ifdef DBG_UTIL 34ddde725dSArmin Le Grand #include <tools/stream.hxx> 35ddde725dSArmin Le Grand #endif 36ddde725dSArmin Le Grand 37ddde725dSArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 38ddde725dSArmin Le Grand 39ddde725dSArmin Le Grand namespace drawinglayer 40ddde725dSArmin Le Grand { 41ddde725dSArmin Le Grand namespace tools 42ddde725dSArmin Le Grand { 43ddde725dSArmin Le Grand BitmapEx DRAWINGLAYER_DLLPUBLIC convertToBitmapEx( 44ddde725dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DSequence& rSeq, 45ddde725dSArmin Le Grand const geometry::ViewInformation2D& rViewInformation2D, 46ddde725dSArmin Le Grand sal_uInt32 nDiscreteWidth, 47ddde725dSArmin Le Grand sal_uInt32 nDiscreteHeight, 48ddde725dSArmin Le Grand sal_uInt32 nMaxQuadratPixels) 49ddde725dSArmin Le Grand { 50ddde725dSArmin Le Grand BitmapEx aRetval; 51ddde725dSArmin Le Grand 52ddde725dSArmin Le Grand if(rSeq.hasElements() && nDiscreteWidth && nDiscreteHeight) 53ddde725dSArmin Le Grand { 54ddde725dSArmin Le Grand // get destination size in pixels 55ddde725dSArmin Le Grand const MapMode aMapModePixel(MAP_PIXEL); 56ddde725dSArmin Le Grand const sal_uInt32 nViewVisibleArea(nDiscreteWidth * nDiscreteHeight); 57ddde725dSArmin Le Grand double fReduceFactor(1.0); 58ddde725dSArmin Le Grand drawinglayer::primitive2d::Primitive2DSequence aSequence(rSeq); 59ddde725dSArmin Le Grand 60ddde725dSArmin Le Grand if(nViewVisibleArea > nMaxQuadratPixels) 61ddde725dSArmin Le Grand { 62ddde725dSArmin Le Grand // reduce render size 63ddde725dSArmin Le Grand fReduceFactor = sqrt((double)nMaxQuadratPixels / (double)nViewVisibleArea); 64ddde725dSArmin Le Grand nDiscreteWidth = basegfx::fround((double)nDiscreteWidth * fReduceFactor); 65ddde725dSArmin Le Grand nDiscreteHeight = basegfx::fround((double)nDiscreteHeight * fReduceFactor); 66ddde725dSArmin Le Grand 67ddde725dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DReference aEmbed( 68ddde725dSArmin Le Grand new drawinglayer::primitive2d::TransformPrimitive2D( 69ddde725dSArmin Le Grand basegfx::tools::createScaleB2DHomMatrix(fReduceFactor, fReduceFactor), 70ddde725dSArmin Le Grand rSeq)); 71ddde725dSArmin Le Grand 72ddde725dSArmin Le Grand aSequence = drawinglayer::primitive2d::Primitive2DSequence(&aEmbed, 1); 73ddde725dSArmin Le Grand } 74ddde725dSArmin Le Grand 75ddde725dSArmin Le Grand const Point aEmptyPoint; 76ddde725dSArmin Le Grand const Size aSizePixel(nDiscreteWidth, nDiscreteHeight); 77ddde725dSArmin Le Grand geometry::ViewInformation2D aViewInformation2D(rViewInformation2D); 78ddde725dSArmin Le Grand VirtualDevice maContent; 79ddde725dSArmin Le Grand 80ddde725dSArmin Le Grand // prepare vdev 81ddde725dSArmin Le Grand maContent.SetOutputSizePixel(aSizePixel, false); 82ddde725dSArmin Le Grand maContent.SetMapMode(aMapModePixel); 83ddde725dSArmin Le Grand maContent.SetAntialiasing(true); 84ddde725dSArmin Le Grand 85ddde725dSArmin Le Grand // set to all white 86ddde725dSArmin Le Grand maContent.SetBackground(Wallpaper(Color(COL_WHITE))); 87ddde725dSArmin Le Grand maContent.Erase(); 88ddde725dSArmin Le Grand 89ddde725dSArmin Le Grand // create processor 90ddde725dSArmin Le Grand processor2d::VclPixelProcessor2D aContentProcessor(aViewInformation2D, maContent); 91ddde725dSArmin Le Grand 92ddde725dSArmin Le Grand // render content 93ddde725dSArmin Le Grand aContentProcessor.process(aSequence); 94ddde725dSArmin Le Grand 95ddde725dSArmin Le Grand // get content 96ddde725dSArmin Le Grand maContent.EnableMapMode(false); 97ddde725dSArmin Le Grand const Bitmap aContent(maContent.GetBitmap(aEmptyPoint, aSizePixel)); 98ddde725dSArmin Le Grand 99ddde725dSArmin Le Grand // prepare for mask creation 100ddde725dSArmin Le Grand maContent.SetMapMode(aMapModePixel); 101ddde725dSArmin Le Grand maContent.SetAntialiasing(true); 102ddde725dSArmin Le Grand 103ddde725dSArmin Le Grand // set alpha to all white (fully transparent) 104ddde725dSArmin Le Grand maContent.Erase(); 105ddde725dSArmin Le Grand 106ddde725dSArmin Le Grand // embed primitives to paint them black 107ddde725dSArmin Le Grand const primitive2d::Primitive2DReference xRef( 108ddde725dSArmin Le Grand new primitive2d::ModifiedColorPrimitive2D( 109ddde725dSArmin Le Grand aSequence, 110ddde725dSArmin Le Grand basegfx::BColorModifier( 111ddde725dSArmin Le Grand basegfx::BColor(0.0, 0.0, 0.0), 112ddde725dSArmin Le Grand 0.5, 113ddde725dSArmin Le Grand basegfx::BCOLORMODIFYMODE_REPLACE))); 114ddde725dSArmin Le Grand const primitive2d::Primitive2DSequence xSeq(&xRef, 1); 115ddde725dSArmin Le Grand 116ddde725dSArmin Le Grand // render 117ddde725dSArmin Le Grand aContentProcessor.process(xSeq); 118ddde725dSArmin Le Grand 119ddde725dSArmin Le Grand // get alpha cahannel from vdev 120ddde725dSArmin Le Grand maContent.EnableMapMode(false); 121ddde725dSArmin Le Grand const AlphaMask aAlphaMask(maContent.GetBitmap(aEmptyPoint, aSizePixel)); 122ddde725dSArmin Le Grand 123ddde725dSArmin Le Grand // create BitmapEx result 124ddde725dSArmin Le Grand aRetval = BitmapEx(aContent, aAlphaMask); 125ddde725dSArmin Le Grand } 126ddde725dSArmin Le Grand 127ddde725dSArmin Le Grand #ifdef DBG_UTIL 128ddde725dSArmin Le Grand static bool bDoSaveForVisualControl(false); 129ddde725dSArmin Le Grand if(bDoSaveForVisualControl) 130ddde725dSArmin Le Grand { 131ddde725dSArmin Le Grand SvFileStream aNew((const String&)String(ByteString( "c:\\test.png" ), RTL_TEXTENCODING_UTF8), STREAM_WRITE|STREAM_TRUNC); 132ddde725dSArmin Le Grand aNew << aRetval; 133ddde725dSArmin Le Grand } 134ddde725dSArmin Le Grand #endif 135ddde725dSArmin Le Grand 136ddde725dSArmin Le Grand return aRetval; 137ddde725dSArmin Le Grand } 138ddde725dSArmin Le Grand 139ddde725dSArmin Le Grand } // end of namespace tools 140ddde725dSArmin Le Grand } // end of namespace drawinglayer 141ddde725dSArmin Le Grand 142ddde725dSArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 143ddde725dSArmin Le Grand // eof 144