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

Generated by: LCOV version 1.10