LCOV - code coverage report
Current view: top level - libreoffice/svx/source/sdr/primitive2d - sdrolecontentprimitive2d.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 65 10.8 %
Date: 2012-12-27 Functions: 2 5 40.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 <svx/sdr/primitive2d/sdrolecontentprimitive2d.hxx>
      21             : #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
      22             : #include <svx/svdoole2.hxx>
      23             : #include <vcl/svapp.hxx>
      24             : #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
      25             : #include <svtools/colorcfg.hxx>
      26             : #include <basegfx/polygon/b2dpolygontools.hxx>
      27             : #include <basegfx/polygon/b2dpolygon.hxx>
      28             : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      29             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      30             : 
      31             : //////////////////////////////////////////////////////////////////////////////
      32             : 
      33             : namespace drawinglayer
      34             : {
      35             :     namespace primitive2d
      36             :     {
      37           0 :         Primitive2DSequence SdrOleContentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
      38             :         {
      39           0 :             Primitive2DSequence aRetval;
      40           0 :             const SdrOle2Obj* pSource = (mpSdrOle2Obj.is() ? static_cast< SdrOle2Obj* >(mpSdrOle2Obj.get()) : 0);
      41           0 :             bool bScaleContent(false);
      42           0 :             Graphic aGraphic;
      43             : 
      44           0 :             if(pSource)
      45             :             {
      46           0 :                 Graphic* pOLEGraphic = pSource->GetGraphic();
      47             : 
      48           0 :                 if(pOLEGraphic)
      49             :                 {
      50           0 :                     aGraphic = *pOLEGraphic;
      51           0 :                     bScaleContent = pSource->IsEmptyPresObj();
      52             :                 }
      53             :             }
      54             : 
      55           0 :             if(GRAPHIC_NONE == aGraphic.GetType())
      56             :             {
      57             :                 // no source, use fallback resource emty OLE graphic
      58           0 :                 const Bitmap aEmptyOLEBitmap(SdrOle2Obj::GetEmtyOLEReplacementBitmap());
      59           0 :                 aGraphic = Graphic(aEmptyOLEBitmap);
      60           0 :                 bScaleContent = true;
      61             :             }
      62             : 
      63           0 :             if(GRAPHIC_NONE != aGraphic.GetType())
      64             :             {
      65           0 :                 const GraphicObject aGraphicObject(aGraphic);
      66           0 :                 const GraphicAttr aGraphicAttr;
      67           0 :                 drawinglayer::primitive2d::Primitive2DSequence xOLEContent;
      68             : 
      69           0 :                 if(bScaleContent)
      70             :                 {
      71             :                     // get transformation atoms
      72           0 :                     basegfx::B2DVector aScale, aTranslate;
      73             :                     double fRotate, fShearX;
      74           0 :                     getObjectTransform().decompose(aScale, aTranslate, fRotate, fShearX);
      75             : 
      76             :                     // get PrefSize from the graphic in 100th mm
      77           0 :                     Size aPrefSize(aGraphic.GetPrefSize());
      78             : 
      79           0 :                     if(MAP_PIXEL == aGraphic.GetPrefMapMode().GetMapUnit())
      80             :                     {
      81           0 :                         aPrefSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MAP_100TH_MM);
      82             :                     }
      83             :                     else
      84             :                     {
      85           0 :                         aPrefSize = Application::GetDefaultDevice()->LogicToLogic(aPrefSize, aGraphic.GetPrefMapMode(), MAP_100TH_MM);
      86             :                     }
      87             : 
      88           0 :                     const double fOffsetX((aScale.getX() - aPrefSize.getWidth()) / 2.0);
      89           0 :                     const double fOffsetY((aScale.getY() - aPrefSize.getHeight()) / 2.0);
      90             : 
      91           0 :                     if(basegfx::fTools::moreOrEqual(fOffsetX, 0.0) && basegfx::fTools::moreOrEqual(fOffsetY, 0.0))
      92             :                     {
      93             :                         // if content fits into frame, create it
      94             :                         basegfx::B2DHomMatrix aInnerObjectMatrix(basegfx::tools::createScaleTranslateB2DHomMatrix(
      95           0 :                             aPrefSize.getWidth(), aPrefSize.getHeight(), fOffsetX, fOffsetY));
      96             :                         aInnerObjectMatrix = basegfx::tools::createShearXRotateTranslateB2DHomMatrix(fShearX, fRotate, aTranslate)
      97           0 :                             * aInnerObjectMatrix;
      98             : 
      99             :                         const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive(
     100             :                             new drawinglayer::primitive2d::GraphicPrimitive2D(
     101             :                                 aInnerObjectMatrix,
     102             :                                 aGraphicObject,
     103           0 :                                 aGraphicAttr));
     104           0 :                         drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aGraphicPrimitive);
     105           0 :                     }
     106             :                 }
     107             :                 else
     108             :                 {
     109             :                     // create graphic primitive for content
     110             :                     const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive(
     111             :                         new drawinglayer::primitive2d::GraphicPrimitive2D(
     112             :                             getObjectTransform(),
     113             :                             aGraphicObject,
     114           0 :                             aGraphicAttr));
     115           0 :                     drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aGraphicPrimitive);
     116             :                 }
     117             : 
     118             :                 // a standard gray outline is created for scaled content
     119           0 :                 if(bScaleContent)
     120             :                 {
     121           0 :                     const svtools::ColorConfig aColorConfig;
     122           0 :                     const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES));
     123             : 
     124           0 :                     if(aColor.bIsVisible)
     125             :                     {
     126           0 :                         basegfx::B2DPolygon aOutline(basegfx::tools::createUnitPolygon());
     127           0 :                         const Color aVclColor(aColor.nColor);
     128           0 :                         aOutline.transform(getObjectTransform());
     129             :                         const drawinglayer::primitive2d::Primitive2DReference xOutline(
     130           0 :                             new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aOutline, aVclColor.getBColor()));
     131           0 :                         drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xOutline);
     132           0 :                     }
     133           0 :                 }
     134             :             }
     135             : 
     136             :             // get graphic and check scale content state
     137           0 :             return aRetval;
     138             :         }
     139             : 
     140          41 :         SdrOleContentPrimitive2D::SdrOleContentPrimitive2D(
     141             :             const SdrOle2Obj& rSdrOle2Obj,
     142             :             const basegfx::B2DHomMatrix& rObjectTransform,
     143             :             sal_uInt32 nGraphicVersion
     144             :         )
     145             :         :   BufferedDecompositionPrimitive2D(),
     146             :             mpSdrOle2Obj(const_cast< SdrOle2Obj* >(&rSdrOle2Obj)),
     147             :             maObjectTransform(rObjectTransform),
     148          41 :             mnGraphicVersion(nGraphicVersion)
     149             :         {
     150          41 :         }
     151             : 
     152           0 :         bool SdrOleContentPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
     153             :         {
     154           0 :             if( BufferedDecompositionPrimitive2D::operator==(rPrimitive) )
     155             :             {
     156           0 :                 const SdrOleContentPrimitive2D& rCompare = (SdrOleContentPrimitive2D&)rPrimitive;
     157           0 :                 const bool bBothNot(!mpSdrOle2Obj.is() && !rCompare.mpSdrOle2Obj.is());
     158           0 :                 const bool bBothAndEqual(mpSdrOle2Obj.is() && rCompare.mpSdrOle2Obj.is()
     159           0 :                     && mpSdrOle2Obj.get() == rCompare.mpSdrOle2Obj.get());
     160             : 
     161             :                 return ((bBothNot || bBothAndEqual)
     162           0 :                     && getObjectTransform() == rCompare.getObjectTransform()
     163             : 
     164             :                     // #i104867# to find out if the Graphic content of the
     165             :                     // OLE has changed, use GraphicVersion number
     166           0 :                     && getGraphicVersion() == rCompare.getGraphicVersion()
     167           0 :                 );
     168             :             }
     169             : 
     170           0 :             return false;
     171             :         }
     172             : 
     173          41 :         basegfx::B2DRange SdrOleContentPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
     174             :         {
     175          41 :             basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0);
     176          41 :             aRange.transform(getObjectTransform());
     177             : 
     178          41 :             return aRange;
     179             :         }
     180             : 
     181             :         // provide unique ID
     182           0 :         ImplPrimitrive2DIDBlock(SdrOleContentPrimitive2D, PRIMITIVE2D_ID_SDROLECONTENTPRIMITIVE2D)
     183             : 
     184             :     } // end of namespace primitive2d
     185             : } // end of namespace drawinglayer
     186             : 
     187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10