LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive2d - discreteshadowprimitive2d.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 119 0.0 %
Date: 2014-04-14 Functions: 0 14 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/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           0 :         DiscreteShadow::DiscreteShadow(const BitmapEx& rBitmapEx)
      34             :         :   maBitmapEx(rBitmapEx),
      35             :             maTopLeft(),
      36             :             maTop(),
      37             :             maTopRight(),
      38             :             maRight(),
      39             :             maBottomRight(),
      40             :             maBottom(),
      41             :             maBottomLeft(),
      42           0 :             maLeft()
      43             :         {
      44           0 :             const Size& rBitmapSize = getBitmapEx().GetSizePixel();
      45             : 
      46           0 :             if(rBitmapSize.Width() != rBitmapSize.Height() || rBitmapSize.Width() < 7)
      47             :             {
      48             :                 OSL_ENSURE(false, "DiscreteShadowPrimitive2D: wrong bitmap format (!)");
      49           0 :                 maBitmapEx = BitmapEx();
      50             :             }
      51           0 :         }
      52             : 
      53           0 :         const BitmapEx& DiscreteShadow::getTopLeft() const
      54             :         {
      55           0 :             if(maTopLeft.IsEmpty())
      56             :             {
      57           0 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
      58           0 :                 const_cast< DiscreteShadow* >(this)->maTopLeft = getBitmapEx();
      59             :                 const_cast< DiscreteShadow* >(this)->maTopLeft.Crop(
      60           0 :                     Rectangle(Point(0, 0), Size((nQuarter * 2) + 1, (nQuarter * 2) + 1)));
      61             :             }
      62             : 
      63           0 :             return maTopLeft;
      64             :         }
      65             : 
      66           0 :         const BitmapEx& DiscreteShadow::getTop() const
      67             :         {
      68           0 :             if(maTop.IsEmpty())
      69             :             {
      70           0 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
      71           0 :                 const_cast< DiscreteShadow* >(this)->maTop = getBitmapEx();
      72             :                 const_cast< DiscreteShadow* >(this)->maTop.Crop(
      73           0 :                     Rectangle(Point((nQuarter * 2) + 1, 0), Size(1, nQuarter)));
      74             :             }
      75             : 
      76           0 :             return maTop;
      77             :         }
      78             : 
      79           0 :         const BitmapEx& DiscreteShadow::getTopRight() const
      80             :         {
      81           0 :             if(maTopRight.IsEmpty())
      82             :             {
      83           0 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
      84           0 :                 const_cast< DiscreteShadow* >(this)->maTopRight = getBitmapEx();
      85             :                 const_cast< DiscreteShadow* >(this)->maTopRight.Crop(
      86           0 :                     Rectangle(Point((nQuarter * 2) + 2, 0), Size((nQuarter * 2) + 1, (nQuarter * 2) + 1)));
      87             :             }
      88             : 
      89           0 :             return maTopRight;
      90             :         }
      91             : 
      92           0 :         const BitmapEx& DiscreteShadow::getRight() const
      93             :         {
      94           0 :             if(maRight.IsEmpty())
      95             :             {
      96           0 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
      97           0 :                 const_cast< DiscreteShadow* >(this)->maRight = getBitmapEx();
      98             :                 const_cast< DiscreteShadow* >(this)->maRight.Crop(
      99           0 :                     Rectangle(Point((nQuarter * 3) + 3, (nQuarter * 2) + 1), Size(nQuarter, 1)));
     100             :             }
     101             : 
     102           0 :             return maRight;
     103             :         }
     104             : 
     105           0 :         const BitmapEx& DiscreteShadow::getBottomRight() const
     106             :         {
     107           0 :             if(maBottomRight.IsEmpty())
     108             :             {
     109           0 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
     110           0 :                 const_cast< DiscreteShadow* >(this)->maBottomRight = getBitmapEx();
     111             :                 const_cast< DiscreteShadow* >(this)->maBottomRight.Crop(
     112           0 :                     Rectangle(Point((nQuarter * 2) + 2, (nQuarter * 2) + 2), Size((nQuarter * 2) + 1, (nQuarter * 2) + 1)));
     113             :             }
     114             : 
     115           0 :             return maBottomRight;
     116             :         }
     117             : 
     118           0 :         const BitmapEx& DiscreteShadow::getBottom() const
     119             :         {
     120           0 :             if(maBottom.IsEmpty())
     121             :             {
     122           0 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
     123           0 :                 const_cast< DiscreteShadow* >(this)->maBottom = getBitmapEx();
     124             :                 const_cast< DiscreteShadow* >(this)->maBottom.Crop(
     125           0 :                     Rectangle(Point((nQuarter * 2) + 1, (nQuarter * 3) + 3), Size(1, nQuarter)));
     126             :             }
     127             : 
     128           0 :             return maBottom;
     129             :         }
     130             : 
     131           0 :         const BitmapEx& DiscreteShadow::getBottomLeft() const
     132             :         {
     133           0 :             if(maBottomLeft.IsEmpty())
     134             :             {
     135           0 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
     136           0 :                 const_cast< DiscreteShadow* >(this)->maBottomLeft = getBitmapEx();
     137             :                 const_cast< DiscreteShadow* >(this)->maBottomLeft.Crop(
     138           0 :                     Rectangle(Point(0, (nQuarter * 2) + 2), Size((nQuarter * 2) + 1, (nQuarter * 2) + 1)));
     139             :             }
     140             : 
     141           0 :             return maBottomLeft;
     142             :         }
     143             : 
     144           0 :         const BitmapEx& DiscreteShadow::getLeft() const
     145             :         {
     146           0 :             if(maLeft.IsEmpty())
     147             :             {
     148           0 :                 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
     149           0 :                 const_cast< DiscreteShadow* >(this)->maLeft = getBitmapEx();
     150             :                 const_cast< DiscreteShadow* >(this)->maLeft.Crop(
     151           0 :                     Rectangle(Point(0, (nQuarter * 2) + 1), Size(nQuarter, 1)));
     152             :             }
     153             : 
     154           0 :             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           0 :                             1.0 - (2.0 * (fBorderX + fSingleX)) + fSingleX,
     199             :                             fBorderY,
     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,
     219           0 :                             1.0 - (2.0 * (fBorderY + fSingleY)) + fSingleY,
     220             :                             1.0 + fSingleX,
     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           0 :                             1.0 - (fBorderX + fSingleX) + fSingleX,
     231           0 :                             1.0 - (fBorderY + fSingleY) + fSingleY)));
     232             : 
     233             :                 // Bottom
     234           0 :                 xRetval[5] = Primitive2DReference(
     235             :                     new BitmapPrimitive2D(
     236           0 :                         getDiscreteShadow().getBottom(),
     237             :                         basegfx::tools::createScaleTranslateB2DHomMatrix(
     238           0 :                             1.0 - (2.0 * (fBorderX + fSingleX)) + fSingleX,
     239             :                             fBorderY,
     240             :                             fBorderX + fSingleX,
     241           0 :                             1.0 + fSingleY)));
     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,
     259           0 :                             1.0 - (2.0 * (fBorderY + fSingleY)) + 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           0 :         DiscreteShadowPrimitive2D::DiscreteShadowPrimitive2D(
     276             :             const basegfx::B2DHomMatrix& rTransform,
     277             :             const DiscreteShadow& rDiscreteShadow)
     278             :         :   DiscreteMetricDependentPrimitive2D(),
     279             :             maTransform(rTransform),
     280           0 :             maDiscreteShadow(rDiscreteShadow)
     281             :         {
     282           0 :         }
     283             : 
     284           0 :         bool DiscreteShadowPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
     285             :         {
     286           0 :             if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
     287             :             {
     288           0 :                 const DiscreteShadowPrimitive2D& rCompare = (DiscreteShadowPrimitive2D&)rPrimitive;
     289             : 
     290           0 :                 return (getTransform() == rCompare.getTransform()
     291           0 :                     && getDiscreteShadow() == rCompare.getDiscreteShadow());
     292             :             }
     293             : 
     294           0 :             return false;
     295             :         }
     296             : 
     297           0 :         basegfx::B2DRange DiscreteShadowPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
     298             :         {
     299           0 :             if(getDiscreteShadow().getBitmapEx().IsEmpty())
     300             :             {
     301             :                 // no graphics without valid bitmap definition
     302           0 :                 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           0 :         ImplPrimitive2DIDBlock(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