LCOV - code coverage report
Current view: top level - svx/source/sdr/primitive2d - sdrolecontentprimitive2d.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 64 65 98.5 %
Date: 2012-08-25 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 82 168 48.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <svx/sdr/primitive2d/sdrolecontentprimitive2d.hxx>
      30                 :            : #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
      31                 :            : #include <svx/svdoole2.hxx>
      32                 :            : #include <vcl/svapp.hxx>
      33                 :            : #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
      34                 :            : #include <svtools/colorcfg.hxx>
      35                 :            : #include <basegfx/polygon/b2dpolygontools.hxx>
      36                 :            : #include <basegfx/polygon/b2dpolygon.hxx>
      37                 :            : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      38                 :            : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      39                 :            : 
      40                 :            : //////////////////////////////////////////////////////////////////////////////
      41                 :            : 
      42                 :            : namespace drawinglayer
      43                 :            : {
      44                 :            :     namespace primitive2d
      45                 :            :     {
      46                 :         68 :         Primitive2DSequence SdrOleContentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
      47                 :            :         {
      48         [ +  - ]:         68 :             Primitive2DSequence aRetval;
      49         [ +  - ]:         68 :             const SdrOle2Obj* pSource = (mpSdrOle2Obj.is() ? static_cast< SdrOle2Obj* >(mpSdrOle2Obj.get()) : 0);
      50                 :         68 :             bool bScaleContent(false);
      51         [ +  - ]:         68 :             Graphic aGraphic;
      52                 :            : 
      53         [ +  - ]:         68 :             if(pSource)
      54                 :            :             {
      55         [ +  - ]:         68 :                 Graphic* pOLEGraphic = pSource->GetGraphic();
      56                 :            : 
      57         [ +  + ]:         68 :                 if(pOLEGraphic)
      58                 :            :                 {
      59         [ +  - ]:         65 :                     aGraphic = *pOLEGraphic;
      60         [ +  - ]:         65 :                     bScaleContent = pSource->IsEmptyPresObj();
      61                 :            :                 }
      62                 :            :             }
      63                 :            : 
      64 [ +  - ][ +  + ]:         68 :             if(GRAPHIC_NONE == aGraphic.GetType())
      65                 :            :             {
      66                 :            :                 // no source, use fallback resource emty OLE graphic
      67         [ +  - ]:          3 :                 const Bitmap aEmptyOLEBitmap(SdrOle2Obj::GetEmtyOLEReplacementBitmap());
      68 [ +  - ][ +  - ]:          3 :                 aGraphic = Graphic(aEmptyOLEBitmap);
                 [ +  - ]
      69         [ +  - ]:          3 :                 bScaleContent = true;
      70                 :            :             }
      71                 :            : 
      72 [ +  - ][ +  - ]:         68 :             if(GRAPHIC_NONE != aGraphic.GetType())
      73                 :            :             {
      74         [ +  - ]:         68 :                 const GraphicObject aGraphicObject(aGraphic);
      75         [ +  - ]:         68 :                 const GraphicAttr aGraphicAttr;
      76         [ +  - ]:         68 :                 drawinglayer::primitive2d::Primitive2DSequence xOLEContent;
      77                 :            : 
      78         [ +  + ]:         68 :                 if(bScaleContent)
      79                 :            :                 {
      80                 :            :                     // get transformation atoms
      81                 :          3 :                     basegfx::B2DVector aScale, aTranslate;
      82                 :            :                     double fRotate, fShearX;
      83         [ +  - ]:          3 :                     getObjectTransform().decompose(aScale, aTranslate, fRotate, fShearX);
      84                 :            : 
      85                 :            :                     // get PrefSize from the graphic in 100th mm
      86         [ +  - ]:          3 :                     Size aPrefSize(aGraphic.GetPrefSize());
      87                 :            : 
      88 [ +  - ][ +  - ]:          3 :                     if(MAP_PIXEL == aGraphic.GetPrefMapMode().GetMapUnit())
                 [ +  - ]
      89                 :            :                     {
      90 [ +  - ][ +  - ]:          3 :                         aPrefSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MAP_100TH_MM);
         [ +  - ][ +  - ]
      91                 :            :                     }
      92                 :            :                     else
      93                 :            :                     {
      94 [ #  # ][ #  # ]:          0 :                         aPrefSize = Application::GetDefaultDevice()->LogicToLogic(aPrefSize, aGraphic.GetPrefMapMode(), MAP_100TH_MM);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      95                 :            :                     }
      96                 :            : 
      97                 :          3 :                     const double fOffsetX((aScale.getX() - aPrefSize.getWidth()) / 2.0);
      98                 :          3 :                     const double fOffsetY((aScale.getY() - aPrefSize.getHeight()) / 2.0);
      99                 :            : 
     100 [ +  - ][ +  - ]:          3 :                     if(basegfx::fTools::moreOrEqual(fOffsetX, 0.0) && basegfx::fTools::moreOrEqual(fOffsetY, 0.0))
         [ +  - ][ +  - ]
                 [ +  - ]
     101                 :            :                     {
     102                 :            :                         // if content fits into frame, create it
     103                 :            :                         basegfx::B2DHomMatrix aInnerObjectMatrix(basegfx::tools::createScaleTranslateB2DHomMatrix(
     104         [ +  - ]:          3 :                             aPrefSize.getWidth(), aPrefSize.getHeight(), fOffsetX, fOffsetY));
     105                 :            :                         aInnerObjectMatrix = basegfx::tools::createShearXRotateTranslateB2DHomMatrix(fShearX, fRotate, aTranslate)
     106 [ +  - ][ +  - ]:          3 :                             * aInnerObjectMatrix;
         [ +  - ][ +  - ]
                 [ +  - ]
     107                 :            : 
     108                 :            :                         const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive(
     109                 :            :                             new drawinglayer::primitive2d::GraphicPrimitive2D(
     110                 :            :                                 aInnerObjectMatrix,
     111                 :            :                                 aGraphicObject,
     112 [ +  - ][ +  - ]:          3 :                                 aGraphicAttr));
                 [ +  - ]
     113 [ +  - ][ +  - ]:          3 :                         drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aGraphicPrimitive);
     114                 :          3 :                     }
     115                 :            :                 }
     116                 :            :                 else
     117                 :            :                 {
     118                 :            :                     // create graphic primitive for content
     119                 :            :                     const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive(
     120                 :            :                         new drawinglayer::primitive2d::GraphicPrimitive2D(
     121                 :            :                             getObjectTransform(),
     122                 :            :                             aGraphicObject,
     123 [ +  - ][ +  - ]:         65 :                             aGraphicAttr));
                 [ +  - ]
     124         [ +  - ]:         65 :                     drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aGraphicPrimitive);
     125                 :            :                 }
     126                 :            : 
     127                 :            :                 // a standard gray outline is created for scaled content
     128         [ +  + ]:         68 :                 if(bScaleContent)
     129                 :            :                 {
     130         [ +  - ]:          3 :                     const svtools::ColorConfig aColorConfig;
     131         [ +  - ]:          3 :                     const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES));
     132                 :            : 
     133         [ +  - ]:          3 :                     if(aColor.bIsVisible)
     134                 :            :                     {
     135         [ +  - ]:          3 :                         basegfx::B2DPolygon aOutline(basegfx::tools::createUnitPolygon());
     136                 :          3 :                         const Color aVclColor(aColor.nColor);
     137         [ +  - ]:          3 :                         aOutline.transform(getObjectTransform());
     138                 :            :                         const drawinglayer::primitive2d::Primitive2DReference xOutline(
     139 [ +  - ][ +  - ]:          3 :                             new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aOutline, aVclColor.getBColor()));
                 [ +  - ]
     140 [ +  - ][ +  - ]:          3 :                         drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xOutline);
     141         [ +  - ]:          3 :                     }
     142 [ +  - ][ +  - ]:         68 :                 }
                 [ +  - ]
     143                 :            :             }
     144                 :            : 
     145                 :            :             // get graphic and check scale content state
     146         [ +  - ]:         68 :             return aRetval;
     147                 :            :         }
     148                 :            : 
     149                 :        181 :         SdrOleContentPrimitive2D::SdrOleContentPrimitive2D(
     150                 :            :             const SdrOle2Obj& rSdrOle2Obj,
     151                 :            :             const basegfx::B2DHomMatrix& rObjectTransform,
     152                 :            :             sal_uInt32 nGraphicVersion
     153                 :            :         )
     154                 :            :         :   BufferedDecompositionPrimitive2D(),
     155                 :            :             mpSdrOle2Obj(const_cast< SdrOle2Obj* >(&rSdrOle2Obj)),
     156                 :            :             maObjectTransform(rObjectTransform),
     157 [ +  - ][ +  - ]:        181 :             mnGraphicVersion(nGraphicVersion)
     158                 :            :         {
     159                 :        181 :         }
     160                 :            : 
     161                 :        152 :         bool SdrOleContentPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
     162                 :            :         {
     163         [ +  - ]:        152 :             if( BufferedDecompositionPrimitive2D::operator==(rPrimitive) )
     164                 :            :             {
     165                 :        152 :                 const SdrOleContentPrimitive2D& rCompare = (SdrOleContentPrimitive2D&)rPrimitive;
     166 [ -  + ][ #  # ]:        152 :                 const bool bBothNot(!mpSdrOle2Obj.is() && !rCompare.mpSdrOle2Obj.is());
     167                 :        304 :                 const bool bBothAndEqual(mpSdrOle2Obj.is() && rCompare.mpSdrOle2Obj.is()
     168         [ +  - ]:        304 :                     && mpSdrOle2Obj.get() == rCompare.mpSdrOle2Obj.get());
           [ +  -  +  - ]
     169                 :            : 
     170                 :            :                 return ((bBothNot || bBothAndEqual)
     171                 :        152 :                     && getObjectTransform() == rCompare.getObjectTransform()
     172                 :            : 
     173                 :            :                     // #i104867# to find out if the Graphic content of the
     174                 :            :                     // OLE has changed, use GraphicVersion number
     175                 :        152 :                     && getGraphicVersion() == rCompare.getGraphicVersion()
     176 [ +  - ][ +  -  :        456 :                 );
             +  -  +  + ]
     177                 :            :             }
     178                 :            : 
     179                 :        152 :             return false;
     180                 :            :         }
     181                 :            : 
     182                 :        410 :         basegfx::B2DRange SdrOleContentPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
     183                 :            :         {
     184                 :        410 :             basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0);
     185                 :        410 :             aRange.transform(getObjectTransform());
     186                 :            : 
     187                 :        410 :             return aRange;
     188                 :            :         }
     189                 :            : 
     190                 :            :         // provide unique ID
     191                 :        375 :         ImplPrimitrive2DIDBlock(SdrOleContentPrimitive2D, PRIMITIVE2D_ID_SDROLECONTENTPRIMITIVE2D)
     192                 :            : 
     193                 :            :     } // end of namespace primitive2d
     194                 :            : } // end of namespace drawinglayer
     195                 :            : 
     196                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10