LCOV - code coverage report
Current view: top level - oox/source/drawingml - shapepropertymap.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 57 68 83.8 %
Date: 2014-11-03 Functions: 13 13 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 "oox/drawingml/shapepropertymap.hxx"
      21             : 
      22             : #include <com/sun/star/awt/Gradient.hpp>
      23             : #include <com/sun/star/beans/NamedValue.hpp>
      24             : #include <com/sun/star/drawing/LineDash.hpp>
      25             : #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
      26             : #include "oox/helper/modelobjecthelper.hxx"
      27             : 
      28             : namespace oox {
      29             : namespace drawingml {
      30             : 
      31             : using namespace ::com::sun::star;
      32             : using namespace ::com::sun::star::beans;
      33             : using namespace ::com::sun::star::drawing;
      34             : using namespace ::com::sun::star::uno;
      35             : 
      36             : namespace {
      37             : 
      38             : static const sal_Int32 spnDefaultShapeIds[ SHAPEPROP_END + 1 ] = // one for the PROP_END_LIST
      39             : {
      40             :     PROP_LineStyle, PROP_LineWidth, PROP_LineColor, PROP_LineTransparence, PROP_LineDash, PROP_LineJoint,
      41             :     PROP_LineStartName, PROP_LineStartWidth, PROP_LineStartCenter, PROP_LineEndName, PROP_LineEndWidth, PROP_LineEndCenter,
      42             :     PROP_FillStyle, PROP_FillColor, PROP_FillTransparence, PROP_FillTransparenceGradientName, PROP_FillGradient,
      43             :     PROP_FillBitmapURL, PROP_FillBitmapMode, PROP_FillBitmapSizeX, PROP_FillBitmapSizeY,
      44             :     PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint,
      45             :     PROP_FillHatch,
      46             :     PROP_ShadowXDistance,
      47             :     PROP_FillBitmapName,
      48             :     PROP_END_LIST
      49             : };
      50             : 
      51             : } // namespace
      52             : 
      53         136 : ShapePropertyInfo ShapePropertyInfo::DEFAULT( spnDefaultShapeIds, true, false, false, false );
      54             : 
      55         544 : ShapePropertyInfo::ShapePropertyInfo( const sal_Int32* pnPropertyIds,
      56             :         bool bNamedLineMarker, bool bNamedLineDash, bool bNamedFillGradient, bool bNamedFillBitmapUrl ) :
      57             :     mbNamedLineMarker( bNamedLineMarker ),
      58             :     mbNamedLineDash( bNamedLineDash ),
      59             :     mbNamedFillGradient( bNamedFillGradient ),
      60         544 :     mbNamedFillBitmapUrl( bNamedFillBitmapUrl )
      61             : {
      62             :     assert(pnPropertyIds);
      63             :     // normally we should not reach PROP_COUNT but it prevents infinite loops if we hit a bug
      64       14008 :     for(size_t i = 0; i < static_cast<size_t>(PROP_COUNT); ++i)
      65             :     {
      66       14008 :         if(pnPropertyIds[i] == PROP_END_LIST)
      67         544 :             break;
      68             : 
      69       13464 :         maPropertyIds.push_back(pnPropertyIds[i]);
      70             :     }
      71         544 : }
      72             : 
      73        9740 : ShapePropertyMap::ShapePropertyMap( ModelObjectHelper& rModelObjHelper, const ShapePropertyInfo& rShapePropInfo ) :
      74             :     mrModelObjHelper( rModelObjHelper ),
      75        9740 :     maShapePropInfo( rShapePropInfo )
      76             : {
      77        9740 : }
      78             : 
      79         750 : bool ShapePropertyMap::supportsProperty( ShapePropertyId ePropId ) const
      80             : {
      81         750 :     return maShapePropInfo.has( ePropId );
      82             : }
      83             : 
      84         250 : bool ShapePropertyMap::hasNamedLineMarkerInTable( const OUString& rMarkerName ) const
      85             : {
      86         250 :     return maShapePropInfo.mbNamedLineMarker && mrModelObjHelper.hasLineMarker( rMarkerName );
      87             : }
      88             : 
      89       40700 : bool ShapePropertyMap::setAnyProperty( ShapePropertyId ePropId, const Any& rValue )
      90             : {
      91             :     // get current property identifier for the specified property
      92       40700 :     sal_Int32 nPropId = maShapePropInfo[ ePropId ];
      93       40700 :     if( nPropId < 0 ) return false;
      94             : 
      95             :     // special handling for properties supporting named objects in tables
      96       40216 :     switch( ePropId )
      97             :     {
      98             :         case SHAPEPROP_LineStart:
      99             :         case SHAPEPROP_LineEnd:
     100         250 :             return setLineMarker( nPropId, rValue );
     101             : 
     102             :         case SHAPEPROP_LineDash:
     103          90 :             return setLineDash( nPropId, rValue );
     104             : 
     105             :         case SHAPEPROP_FillGradient:
     106         338 :             return setFillGradient( nPropId, rValue );
     107             : 
     108             :         case SHAPEPROP_GradientTransparency:
     109          60 :             return setGradientTrans( nPropId, rValue );
     110             : 
     111             :         case SHAPEPROP_FillBitmapUrl:
     112           4 :             return setFillBitmapUrl( nPropId, rValue );
     113             : 
     114             :         case SHAPEPROP_FillBitmapNameFromUrl:
     115         106 :             return setFillBitmapNameFromUrl( nPropId, rValue );
     116             : 
     117             :         default:;   // suppress compiler warnings
     118             :     }
     119             : 
     120             :     // set plain property value
     121       39368 :     setAnyProperty( nPropId, rValue );
     122       39368 :     return true;
     123             : }
     124             : 
     125             : // private --------------------------------------------------------------------
     126             : 
     127         250 : bool ShapePropertyMap::setLineMarker( sal_Int32 nPropId, const Any& rValue )
     128             : {
     129         250 :     NamedValue aNamedMarker;
     130         250 :     if( (rValue >>= aNamedMarker) && !aNamedMarker.Name.isEmpty() )
     131             :     {
     132             :         // push line marker explicitly
     133         250 :         if( !maShapePropInfo.mbNamedLineMarker )
     134           0 :             return setAnyProperty( nPropId, aNamedMarker.Value );
     135             : 
     136             :         // create named line marker (if coordinates have been passed) and push its name
     137         382 :         bool bInserted = !aNamedMarker.Value.has< PolyPolygonBezierCoords >() ||
     138         382 :             mrModelObjHelper.insertLineMarker( aNamedMarker.Name, aNamedMarker.Value.get< PolyPolygonBezierCoords >() );
     139         250 :         return bInserted && setProperty( nPropId, aNamedMarker.Name );
     140             :     }
     141           0 :     return false;
     142             : }
     143             : 
     144          90 : bool ShapePropertyMap::setLineDash( sal_Int32 nPropId, const Any& rValue )
     145             : {
     146             :     // push line dash explicitly
     147          90 :     if( !maShapePropInfo.mbNamedLineDash )
     148          90 :         return setAnyProperty( nPropId, rValue );
     149             : 
     150             :     // create named line dash and push its name
     151           0 :     if( rValue.has< LineDash >() )
     152             :     {
     153           0 :         OUString aDashName = mrModelObjHelper.insertLineDash( rValue.get< LineDash >() );
     154           0 :         return !aDashName.isEmpty() && setProperty( nPropId, aDashName );
     155             :     }
     156             : 
     157           0 :     return false;
     158             : }
     159             : 
     160         338 : bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId, const Any& rValue )
     161             : {
     162             :     // push gradient explicitly
     163         338 :     if( !maShapePropInfo.mbNamedFillGradient )
     164         330 :         return setAnyProperty( nPropId, rValue );
     165             : 
     166             :     // create named gradient and push its name
     167           8 :     if( rValue.has< awt::Gradient >() )
     168             :     {
     169           8 :         OUString aGradientName = mrModelObjHelper.insertFillGradient( rValue.get< awt::Gradient >() );
     170           8 :         return !aGradientName.isEmpty() && setProperty( nPropId, aGradientName );
     171             :     }
     172             : 
     173           0 :     return false;
     174             : }
     175             : 
     176          60 : bool ShapePropertyMap::setGradientTrans( sal_Int32 nPropId, const Any& rValue )
     177             : {
     178             :     // create named gradient and push its name
     179          60 :     if( rValue.has< awt::Gradient >() )
     180             :     {
     181          60 :         OUString aGradientName = mrModelObjHelper.insertTransGrandient( rValue.get< awt::Gradient >() );
     182          60 :         return !aGradientName.isEmpty()  && setProperty( nPropId, aGradientName );
     183             :     }
     184             : 
     185           0 :     return false;
     186             : }
     187             : 
     188           4 : bool ShapePropertyMap::setFillBitmapUrl( sal_Int32 nPropId, const Any& rValue )
     189             : {
     190             :     // push bitmap URL explicitly
     191           4 :     if( !maShapePropInfo.mbNamedFillBitmapUrl )
     192           0 :         return setAnyProperty( nPropId, rValue );
     193             : 
     194             :     // create named bitmap URL and push its name
     195           4 :     if( rValue.has< OUString >() )
     196             :     {
     197           4 :         OUString aBitmapUrlName = mrModelObjHelper.insertFillBitmapUrl( rValue.get< OUString >() );
     198           4 :         return !aBitmapUrlName.isEmpty() && setProperty( nPropId, aBitmapUrlName );
     199             :     }
     200             : 
     201           0 :     return false;
     202             : }
     203             : 
     204         106 : bool ShapePropertyMap::setFillBitmapNameFromUrl( sal_Int32 /*nPropId*/, const Any& rValue )
     205             : {
     206         106 :     if( rValue.has< OUString >() )
     207             :     {
     208         106 :         OUString aBitmapUrlName = mrModelObjHelper.insertFillBitmapUrl( rValue.get< OUString >() );
     209         106 :         return !aBitmapUrlName.isEmpty() && setProperty( PROP_FillBitmapName, aBitmapUrlName );
     210             :     }
     211           0 :     return false;
     212             : }
     213             : 
     214             : } // namespace drawingml
     215         408 : } // namespace oox
     216             : 
     217             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10