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

Generated by: LCOV version 1.10