LCOV - code coverage report
Current view: top level - libreoffice/drawinglayer/source/primitive2d - discreteshadowprimitive2d.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 66 114 57.9 %
Date: 2012-12-27 Functions: 13 14 92.9 %
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/primitive2d/discreteshadowprimitive2d.hxx>
      21             : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
      22             : #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
      23             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      24             : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
      25             : #include <drawinglayer/geometry/viewinformation2d.hxx>
      26             : 
      27             : //////////////////////////////////////////////////////////////////////////////
      28             : 
      29             : namespace drawinglayer
      30             : {
      31             :     namespace primitive2d
      32             :     {
      33           8 :         DiscreteShadow::DiscreteShadow(const BitmapEx& rBitmapEx)
      34             :         :   maBitmapEx(rBitmapEx),
      35             :             maTopLeft(),
      36             :             maTop(),
      37             :             maTopRight(),
      38             :             maRight(),
      39             :             maBottomRight(),
      40             :             maBottom(),
      41             :             maBottomLeft(),
      42           8 :             maLeft()
      43             :         {
      44           8 :             const Size& rBitmapSize = getBitmapEx().GetSizePixel();
      45             : 
      46           8 :             if(rBitmapSize.Width() != rBitmapSize.Height() || rBitmapSize.Width() < 7)
      47             :             {
      48             :                 OSL_ENSURE(false, "DiscreteShadowPrimitive2D: wrong bitmap format (!)");
      49           8 :                 maBitmapEx = BitmapEx();
      50             :             }
      51           8 :         }
      52             : 
      53           7 :         const BitmapEx& DiscreteShadow::getTopLeft() const
      54             :         {
      55           7 :             if(maTopLeft.IsEmpty())
      56             :             {
      57           7 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
      58           7 :                 const_cast< DiscreteShadow* >(this)->maTopLeft = getBitmapEx();
      59             :                 const_cast< DiscreteShadow* >(this)->maTopLeft.Crop(
      60           7 :                     Rectangle(Point(0,0),Size(nQuarter*2+1,nQuarter*2+1)));
      61             :             }
      62             : 
      63           7 :             return maTopLeft;
      64             :         }
      65             : 
      66           7 :         const BitmapEx& DiscreteShadow::getTop() const
      67             :         {
      68           7 :             if(maTop.IsEmpty())
      69             :             {
      70           7 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
      71           7 :                 const_cast< DiscreteShadow* >(this)->maTop = getBitmapEx();
      72             :                 const_cast< DiscreteShadow* >(this)->maTop.Crop(
      73           7 :                     Rectangle(Point(nQuarter*2+1,0),Size(1,nQuarter+1)));
      74             :             }
      75             : 
      76           7 :             return maTop;
      77             :         }
      78             : 
      79           7 :         const BitmapEx& DiscreteShadow::getTopRight() const
      80             :         {
      81           7 :             if(maTopRight.IsEmpty())
      82             :             {
      83           7 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
      84           7 :                 const_cast< DiscreteShadow* >(this)->maTopRight = getBitmapEx();
      85             :                 const_cast< DiscreteShadow* >(this)->maTopRight.Crop(
      86           7 :                     Rectangle(Point(nQuarter*2+2,0),Size(nQuarter*2+1,nQuarter*2+1)));
      87             :             }
      88             : 
      89           7 :             return maTopRight;
      90             :         }
      91             : 
      92           7 :         const BitmapEx& DiscreteShadow::getRight() const
      93             :         {
      94           7 :             if(maRight.IsEmpty())
      95             :             {
      96           7 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
      97           7 :                 const_cast< DiscreteShadow* >(this)->maRight = getBitmapEx();
      98             :                 const_cast< DiscreteShadow* >(this)->maRight.Crop(
      99           7 :                     Rectangle(Point(nQuarter*3+2,nQuarter*2+1),Size(nQuarter+1,1)));
     100             :             }
     101             : 
     102           7 :             return maRight;
     103             :         }
     104             : 
     105           7 :         const BitmapEx& DiscreteShadow::getBottomRight() const
     106             :         {
     107           7 :             if(maBottomRight.IsEmpty())
     108             :             {
     109           7 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
     110           7 :                 const_cast< DiscreteShadow* >(this)->maBottomRight = getBitmapEx();
     111             :                 const_cast< DiscreteShadow* >(this)->maBottomRight.Crop(
     112           7 :                     Rectangle(Point(nQuarter*2+2,nQuarter*2+2),Size(nQuarter*2+1,nQuarter*2+1)));
     113             :             }
     114             : 
     115           7 :             return maBottomRight;
     116             :         }
     117             : 
     118           7 :         const BitmapEx& DiscreteShadow::getBottom() const
     119             :         {
     120           7 :             if(maBottom.IsEmpty())
     121             :             {
     122           7 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
     123           7 :                 const_cast< DiscreteShadow* >(this)->maBottom = getBitmapEx();
     124             :                 const_cast< DiscreteShadow* >(this)->maBottom.Crop(
     125           7 :                     Rectangle(Point(nQuarter*2+1,nQuarter*3+2),Size(1,nQuarter+1)));
     126             :             }
     127             : 
     128           7 :             return maBottom;
     129             :         }
     130             : 
     131           7 :         const BitmapEx& DiscreteShadow::getBottomLeft() const
     132             :         {
     133           7 :             if(maBottomLeft.IsEmpty())
     134             :             {
     135           7 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
     136           7 :                 const_cast< DiscreteShadow* >(this)->maBottomLeft = getBitmapEx();
     137             :                 const_cast< DiscreteShadow* >(this)->maBottomLeft.Crop(
     138           7 :                     Rectangle(Point(0,nQuarter*2+2),Size(nQuarter*2+1,nQuarter*2+1)));
     139             :             }
     140             : 
     141           7 :             return maBottomLeft;
     142             :         }
     143             : 
     144           7 :         const BitmapEx& DiscreteShadow::getLeft() const
     145             :         {
     146           7 :             if(maLeft.IsEmpty())
     147             :             {
     148           7 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
     149           7 :                 const_cast< DiscreteShadow* >(this)->maLeft = getBitmapEx();
     150             :                 const_cast< DiscreteShadow* >(this)->maLeft.Crop(
     151           7 :                     Rectangle(Point(0,nQuarter*2+1),Size(nQuarter+1,1)));
     152             :             }
     153             : 
     154           7 :             return maLeft;
     155             :         }
     156             : 
     157             :     } // end of namespace primitive2d
     158             : } // end of namespace drawinglayer
     159             : 
     160             : //////////////////////////////////////////////////////////////////////////////
     161             : 
     162             : namespace drawinglayer
     163             : {
     164             :     namespace primitive2d
     165             :     {
     166           0 :         Primitive2DSequence DiscreteShadowPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
     167             :         {
     168           0 :             Primitive2DSequence xRetval;
     169             : 
     170           0 :             if(!getDiscreteShadow().getBitmapEx().IsEmpty())
     171             :             {
     172           0 :                 const sal_Int32 nQuarter((getDiscreteShadow().getBitmapEx().GetSizePixel().Width() - 3) >> 2);
     173           0 :                 const basegfx::B2DVector aScale(getTransform() * basegfx::B2DVector(1.0, 1.0));
     174           0 :                 const double fSingleX(getDiscreteUnit() / aScale.getX());
     175           0 :                 const double fSingleY(getDiscreteUnit() / aScale.getY());
     176           0 :                 const double fBorderX(fSingleX * nQuarter);
     177           0 :                 const double fBorderY(fSingleY * nQuarter);
     178           0 :                 const double fBigLenX((fBorderX * 2.0) + fSingleX);
     179           0 :                 const double fBigLenY((fBorderY * 2.0) + fSingleY);
     180             : 
     181           0 :                 xRetval.realloc(8);
     182             : 
     183             :                 // TopLeft
     184           0 :                 xRetval[0] = Primitive2DReference(
     185             :                     new BitmapPrimitive2D(
     186           0 :                         getDiscreteShadow().getTopLeft(),
     187             :                         basegfx::tools::createScaleTranslateB2DHomMatrix(
     188             :                             fBigLenX,
     189             :                             fBigLenY,
     190             :                             -fBorderX,
     191           0 :                             -fBorderY)));
     192             : 
     193             :                 // Top
     194           0 :                 xRetval[1] = Primitive2DReference(
     195             :                     new BitmapPrimitive2D(
     196           0 :                         getDiscreteShadow().getTop(),
     197             :                         basegfx::tools::createScaleTranslateB2DHomMatrix(
     198             :                             1.0 - (2.0 * fBorderX) - fSingleX,
     199             :                             fBorderY + fSingleY,
     200             :                             fBorderX + fSingleX,
     201           0 :                             -fBorderY)));
     202             : 
     203             :                 // TopRight
     204           0 :                 xRetval[2] = Primitive2DReference(
     205             :                     new BitmapPrimitive2D(
     206           0 :                         getDiscreteShadow().getTopRight(),
     207             :                         basegfx::tools::createScaleTranslateB2DHomMatrix(
     208             :                             fBigLenX,
     209             :                             fBigLenY,
     210             :                             1.0 - fBorderX,
     211           0 :                             -fBorderY)));
     212             : 
     213             :                 // Right
     214           0 :                 xRetval[3] = Primitive2DReference(
     215             :                     new BitmapPrimitive2D(
     216           0 :                         getDiscreteShadow().getRight(),
     217             :                         basegfx::tools::createScaleTranslateB2DHomMatrix(
     218             :                             fBorderX + fSingleX,
     219             :                             1.0 - (2.0 * fBorderY) - fSingleY,
     220             :                             1.0,
     221           0 :                             fBorderY + fSingleY)));
     222             : 
     223             :                 // BottomRight
     224           0 :                 xRetval[4] = Primitive2DReference(
     225             :                     new BitmapPrimitive2D(
     226           0 :                         getDiscreteShadow().getBottomRight(),
     227             :                         basegfx::tools::createScaleTranslateB2DHomMatrix(
     228             :                             fBigLenX,
     229             :                             fBigLenY,
     230             :                             1.0 - fBorderX,
     231           0 :                             1.0 - fBorderY)));
     232             : 
     233             :                 // Bottom
     234           0 :                 xRetval[5] = Primitive2DReference(
     235             :                     new BitmapPrimitive2D(
     236           0 :                         getDiscreteShadow().getBottom(),
     237             :                         basegfx::tools::createScaleTranslateB2DHomMatrix(
     238             :                             1.0 - (2.0 * fBorderX) - fSingleX,
     239             :                             fBorderY + fSingleY,
     240             :                             fBorderX + fSingleX,
     241           0 :                             1.0)));
     242             : 
     243             :                 // BottomLeft
     244           0 :                 xRetval[6] = Primitive2DReference(
     245             :                     new BitmapPrimitive2D(
     246           0 :                         getDiscreteShadow().getBottomLeft(),
     247             :                         basegfx::tools::createScaleTranslateB2DHomMatrix(
     248             :                             fBigLenX,
     249             :                             fBigLenY,
     250             :                             -fBorderX,
     251           0 :                             1.0 - fBorderY)));
     252             : 
     253             :                 // Left
     254           0 :                 xRetval[7] = Primitive2DReference(
     255             :                     new BitmapPrimitive2D(
     256           0 :                         getDiscreteShadow().getLeft(),
     257             :                         basegfx::tools::createScaleTranslateB2DHomMatrix(
     258             :                             fBorderX + fSingleX,
     259             :                             1.0 - (2.0 * fBorderY) - fSingleY,
     260             :                             -fBorderX,
     261           0 :                             fBorderY + fSingleY)));
     262             : 
     263             :                 // put all in object transformation to get to target positions
     264             :                 const Primitive2DReference xTransformed(
     265             :                     new TransformPrimitive2D(
     266             :                         getTransform(),
     267           0 :                         xRetval));
     268             : 
     269           0 :                 xRetval = Primitive2DSequence(&xTransformed, 1);
     270             :             }
     271             : 
     272           0 :             return xRetval;
     273             :         }
     274             : 
     275           4 :         DiscreteShadowPrimitive2D::DiscreteShadowPrimitive2D(
     276             :             const basegfx::B2DHomMatrix& rTransform,
     277             :             const DiscreteShadow& rDiscreteShadow)
     278             :         :   DiscreteMetricDependentPrimitive2D(),
     279             :             maTransform(rTransform),
     280           4 :             maDiscreteShadow(rDiscreteShadow)
     281             :         {
     282           4 :         }
     283             : 
     284           6 :         bool DiscreteShadowPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
     285             :         {
     286           6 :             if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
     287             :             {
     288           6 :                 const DiscreteShadowPrimitive2D& rCompare = (DiscreteShadowPrimitive2D&)rPrimitive;
     289             : 
     290           6 :                 return (getTransform() == rCompare.getTransform()
     291           6 :                     && getDiscreteShadow() == rCompare.getDiscreteShadow());
     292             :             }
     293             : 
     294           0 :             return false;
     295             :         }
     296             : 
     297           6 :         basegfx::B2DRange DiscreteShadowPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
     298             :         {
     299           6 :             if(getDiscreteShadow().getBitmapEx().IsEmpty())
     300             :             {
     301             :                 // no graphics without valid bitmap definition
     302           6 :                 return basegfx::B2DRange();
     303             :             }
     304             :             else
     305             :             {
     306             :                 // prepare normal objectrange
     307           0 :                 basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
     308           0 :                 aRetval.transform(getTransform());
     309             : 
     310             :                 // extract discrete shadow size and grow
     311           0 :                 const basegfx::B2DVector aScale(rViewInformation.getViewTransformation() * basegfx::B2DVector(1.0, 1.0));
     312           0 :                 const sal_Int32 nQuarter((getDiscreteShadow().getBitmapEx().GetSizePixel().Width() - 3) >> 2);
     313           0 :                 const double fGrowX((1.0 / aScale.getX()) * nQuarter);
     314           0 :                 const double fGrowY((1.0 / aScale.getY()) * nQuarter);
     315           0 :                 aRetval.grow(std::max(fGrowX, fGrowY));
     316             : 
     317           0 :                 return aRetval;
     318             :             }
     319             :         }
     320             : 
     321             :         // provide unique ID
     322          14 :         ImplPrimitrive2DIDBlock(DiscreteShadowPrimitive2D, PRIMITIVE2D_ID_DISCRETESHADOWPRIMITIVE2D)
     323             : 
     324             :     } // end of namespace primitive2d
     325             : } // end of namespace drawinglayer
     326             : 
     327             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10