LCOV - code coverage report
Current view: top level - libreoffice/drawinglayer/source/tools - converters.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 36 0.0 %
Date: 2012-12-17 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <drawinglayer/tools/converters.hxx>
      21             : #include <drawinglayer/geometry/viewinformation2d.hxx>
      22             : #include <drawinglayer/processor2d/vclpixelprocessor2d.hxx>
      23             : #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
      24             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      25             : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
      26             : #include <vcl/virdev.hxx>
      27             : 
      28             : #ifdef DBG_UTIL
      29             : #include <tools/stream.hxx>
      30             : #endif
      31             : 
      32             : //////////////////////////////////////////////////////////////////////////////
      33             : 
      34             : namespace drawinglayer
      35             : {
      36             :     namespace tools
      37             :     {
      38           0 :         BitmapEx DRAWINGLAYER_DLLPUBLIC convertToBitmapEx(
      39             :             const drawinglayer::primitive2d::Primitive2DSequence& rSeq,
      40             :             const geometry::ViewInformation2D& rViewInformation2D,
      41             :             sal_uInt32 nDiscreteWidth,
      42             :             sal_uInt32 nDiscreteHeight,
      43             :             sal_uInt32 nMaxQuadratPixels)
      44             :         {
      45           0 :             BitmapEx aRetval;
      46             : 
      47           0 :             if(rSeq.hasElements() && nDiscreteWidth && nDiscreteHeight)
      48             :             {
      49             :                 // get destination size in pixels
      50           0 :                 const MapMode aMapModePixel(MAP_PIXEL);
      51           0 :                 const sal_uInt32 nViewVisibleArea(nDiscreteWidth * nDiscreteHeight);
      52           0 :                 double fReduceFactor(1.0);
      53           0 :                 drawinglayer::primitive2d::Primitive2DSequence aSequence(rSeq);
      54             : 
      55           0 :                 if(nViewVisibleArea > nMaxQuadratPixels)
      56             :                 {
      57             :                     // reduce render size
      58           0 :                     fReduceFactor = sqrt((double)nMaxQuadratPixels / (double)nViewVisibleArea);
      59           0 :                     nDiscreteWidth = basegfx::fround((double)nDiscreteWidth * fReduceFactor);
      60           0 :                     nDiscreteHeight = basegfx::fround((double)nDiscreteHeight * fReduceFactor);
      61             : 
      62             :                     const drawinglayer::primitive2d::Primitive2DReference aEmbed(
      63             :                         new drawinglayer::primitive2d::TransformPrimitive2D(
      64             :                             basegfx::tools::createScaleB2DHomMatrix(fReduceFactor, fReduceFactor),
      65           0 :                             rSeq));
      66             : 
      67           0 :                     aSequence = drawinglayer::primitive2d::Primitive2DSequence(&aEmbed, 1);
      68             :                 }
      69             : 
      70           0 :                 const Point aEmptyPoint;
      71           0 :                 const Size aSizePixel(nDiscreteWidth, nDiscreteHeight);
      72           0 :                 geometry::ViewInformation2D aViewInformation2D(rViewInformation2D);
      73           0 :                 VirtualDevice maContent;
      74             : 
      75             :                 // prepare vdev
      76           0 :                 maContent.SetOutputSizePixel(aSizePixel, false);
      77           0 :                 maContent.SetMapMode(aMapModePixel);
      78           0 :                 maContent.SetAntialiasing(true);
      79             : 
      80             :                 // set to all white
      81           0 :                 maContent.SetBackground(Wallpaper(Color(COL_WHITE)));
      82           0 :                 maContent.Erase();
      83             : 
      84             :                 // create processor
      85           0 :                 processor2d::VclPixelProcessor2D aContentProcessor(aViewInformation2D, maContent);
      86             : 
      87             :                 // render content
      88           0 :                 aContentProcessor.process(aSequence);
      89             : 
      90             :                 // get content
      91           0 :                 maContent.EnableMapMode(false);
      92           0 :                 const Bitmap aContent(maContent.GetBitmap(aEmptyPoint, aSizePixel));
      93             : 
      94             :                 // prepare for mask creation
      95           0 :                 maContent.SetMapMode(aMapModePixel);
      96           0 :                 maContent.SetAntialiasing(true);
      97             : 
      98             :                 // set alpha to all white (fully transparent)
      99           0 :                 maContent.Erase();
     100             : 
     101             :                 // embed primitives to paint them black
     102             :                 const primitive2d::Primitive2DReference xRef(
     103             :                     new primitive2d::ModifiedColorPrimitive2D(
     104             :                         aSequence,
     105             :                         basegfx::BColorModifier(
     106             :                             basegfx::BColor(0.0, 0.0, 0.0),
     107             :                             0.5,
     108           0 :                             basegfx::BCOLORMODIFYMODE_REPLACE)));
     109           0 :                 const primitive2d::Primitive2DSequence xSeq(&xRef, 1);
     110             : 
     111             :                 // render
     112           0 :                 aContentProcessor.process(xSeq);
     113             : 
     114             :                 // get alpha cahannel from vdev
     115           0 :                 maContent.EnableMapMode(false);
     116           0 :                 const AlphaMask aAlphaMask(maContent.GetBitmap(aEmptyPoint, aSizePixel));
     117             : 
     118             :                 // create BitmapEx result
     119           0 :                 aRetval = BitmapEx(aContent, aAlphaMask);
     120             :             }
     121             : 
     122             : #ifdef DBG_UTIL
     123             :             static bool bDoSaveForVisualControl(false);
     124             :             if(bDoSaveForVisualControl)
     125             :             {
     126             :                 SvFileStream aNew(rtl::OUString("c:\\test.png"), STREAM_WRITE|STREAM_TRUNC);
     127             :                 aNew << aRetval;
     128             :             }
     129             : #endif
     130             : 
     131           0 :             return aRetval;
     132             :         }
     133             : 
     134             :     } // end of namespace tools
     135             : } // end of namespace drawinglayer
     136             : 
     137             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10