LCOV - code coverage report
Current view: top level - oox/source/drawingml - shapepropertymap.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 25 58 43.1 %
Date: 2012-08-25 Functions: 7 12 58.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 27 116 23.3 %

           Branch data     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::awt;
      34                 :            : using namespace ::com::sun::star::beans;
      35                 :            : using namespace ::com::sun::star::drawing;
      36                 :            : using namespace ::com::sun::star::uno;
      37                 :            : 
      38                 :            : using ::rtl::OUString;
      39                 :            : 
      40                 :            : // ============================================================================
      41                 :            : 
      42                 :            : namespace {
      43                 :            : 
      44                 :            : static const sal_Int32 spnDefaultShapeIds[ SHAPEPROP_END ] =
      45                 :            : {
      46                 :            :     PROP_LineStyle, PROP_LineWidth, PROP_LineColor, PROP_LineTransparence, PROP_LineDash, PROP_LineJoint,
      47                 :            :     PROP_LineStartName, PROP_LineStartWidth, PROP_LineStartCenter, PROP_LineEndName, PROP_LineEndWidth, PROP_LineEndCenter,
      48                 :            :     PROP_FillStyle, PROP_FillColor, PROP_FillTransparence, PROP_FillTransparenceGradientName, PROP_FillGradient,
      49                 :            :     PROP_FillBitmapURL, PROP_FillBitmapMode, PROP_FillBitmapSizeX, PROP_FillBitmapSizeY,
      50                 :            :     PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint
      51                 :            : };
      52                 :            : 
      53                 :            : } // namespace
      54                 :            : 
      55                 :         95 : ShapePropertyInfo ShapePropertyInfo::DEFAULT( spnDefaultShapeIds, true, false, false, false );
      56                 :            : 
      57                 :        380 : ShapePropertyInfo::ShapePropertyInfo( const sal_Int32* pnPropertyIds,
      58                 :            :         bool bNamedLineMarker, bool bNamedLineDash, bool bNamedFillGradient, bool bNamedFillBitmapUrl ) :
      59                 :            :     mpnPropertyIds( pnPropertyIds ),
      60                 :            :     mbNamedLineMarker( bNamedLineMarker ),
      61                 :            :     mbNamedLineDash( bNamedLineDash ),
      62                 :            :     mbNamedFillGradient( bNamedFillGradient ),
      63                 :        380 :     mbNamedFillBitmapUrl( bNamedFillBitmapUrl )
      64                 :            : {
      65                 :            :     OSL_ENSURE( mpnPropertyIds != 0, "ShapePropertyInfo::ShapePropertyInfo - missing property identifiers" );
      66                 :        380 : }
      67                 :            : 
      68                 :            : // ============================================================================
      69                 :            : 
      70                 :        129 : ShapePropertyMap::ShapePropertyMap( ModelObjectHelper& rModelObjHelper, const ShapePropertyInfo& rShapePropInfo ) :
      71                 :            :     mrModelObjHelper( rModelObjHelper ),
      72                 :        129 :     maShapePropInfo( rShapePropInfo )
      73                 :            : {
      74                 :        129 : }
      75                 :            : 
      76                 :          0 : bool ShapePropertyMap::supportsProperty( ShapePropertyId ePropId ) const
      77                 :            : {
      78                 :          0 :     return maShapePropInfo.has( ePropId );
      79                 :            : }
      80                 :            : 
      81                 :         24 : bool ShapePropertyMap::hasNamedLineMarkerInTable( const OUString& rMarkerName ) const
      82                 :            : {
      83 [ +  - ][ +  + ]:         24 :     return maShapePropInfo.mbNamedLineMarker && mrModelObjHelper.hasLineMarker( rMarkerName );
      84                 :            : }
      85                 :            : 
      86                 :        582 : bool ShapePropertyMap::setAnyProperty( ShapePropertyId ePropId, const Any& rValue )
      87                 :            : {
      88                 :            :     // get current property identifier for the specified property
      89                 :        582 :     sal_Int32 nPropId = maShapePropInfo[ ePropId ];
      90         [ -  + ]:        582 :     if( nPropId < 0 ) return false;
      91                 :            : 
      92                 :            :     // special handling for properties supporting named objects in tables
      93   [ +  -  -  -  :        582 :     switch( ePropId )
                   -  + ]
      94                 :            :     {
      95                 :            :         case SHAPEPROP_LineStart:
      96                 :            :         case SHAPEPROP_LineEnd:
      97         [ +  - ]:         24 :             return setLineMarker( nPropId, rValue );
      98                 :            : 
      99                 :            :         case SHAPEPROP_LineDash:
     100         [ #  # ]:          0 :             return setLineDash( nPropId, rValue );
     101                 :            : 
     102                 :            :         case SHAPEPROP_FillGradient:
     103         [ #  # ]:          0 :             return setFillGradient( nPropId, rValue );
     104                 :            : 
     105                 :            :         case SHAPEPROP_GradientTransparency:
     106         [ #  # ]:          0 :             return setGradientTrans( nPropId, rValue );
     107                 :            : 
     108                 :            :         case SHAPEPROP_FillBitmapUrl:
     109         [ #  # ]:          0 :             return setFillBitmapUrl( nPropId, rValue );
     110                 :            : 
     111                 :            :         default:;   // suppress compiler warnings
     112                 :            :     }
     113                 :            : 
     114                 :            :     // set plain property value
     115         [ +  - ]:        558 :     operator[]( nPropId ) = rValue;
     116                 :        582 :     return true;
     117                 :            : }
     118                 :            : 
     119                 :            : // private --------------------------------------------------------------------
     120                 :            : 
     121                 :         24 : bool ShapePropertyMap::setLineMarker( sal_Int32 nPropId, const Any& rValue )
     122                 :            : {
     123                 :         24 :     NamedValue aNamedMarker;
     124 [ +  - ][ +  - ]:         24 :     if( (rValue >>= aNamedMarker) && !aNamedMarker.Name.isEmpty() )
         [ +  - ][ +  - ]
     125                 :            :     {
     126                 :            :         // push line marker explicitly
     127         [ -  + ]:         24 :         if( !maShapePropInfo.mbNamedLineMarker )
     128         [ #  # ]:          0 :             return setAnyProperty( nPropId, aNamedMarker.Value );
     129                 :            : 
     130                 :            :         // create named line marker (if coordinates have been passed) and push its name
     131         [ +  - ]:         24 :         bool bInserted = !aNamedMarker.Value.has< PolyPolygonBezierCoords >() ||
     132 [ +  + ][ +  - ]:         24 :             mrModelObjHelper.insertLineMarker( aNamedMarker.Name, aNamedMarker.Value.get< PolyPolygonBezierCoords >() );
         [ +  - ][ +  - ]
         [ +  + ][ +  - ]
                 [ #  # ]
     133 [ +  - ][ +  - ]:         24 :         return bInserted && setProperty( nPropId, aNamedMarker.Name );
                 [ +  - ]
     134                 :            :     }
     135                 :         24 :     return false;
     136                 :            : }
     137                 :            : 
     138                 :          0 : bool ShapePropertyMap::setLineDash( sal_Int32 nPropId, const Any& rValue )
     139                 :            : {
     140                 :            :     // push line dash explicitly
     141         [ #  # ]:          0 :     if( !maShapePropInfo.mbNamedLineDash )
     142                 :          0 :         return setAnyProperty( nPropId, rValue );
     143                 :            : 
     144                 :            :     // create named line dash and push its name
     145         [ #  # ]:          0 :     if( rValue.has< LineDash >() )
     146                 :            :     {
     147 [ #  # ][ #  # ]:          0 :         OUString aDashName = mrModelObjHelper.insertLineDash( rValue.get< LineDash >() );
     148 [ #  # ][ #  # ]:          0 :         return !aDashName.isEmpty() && setProperty( nPropId, aDashName );
                 [ #  # ]
     149                 :            :     }
     150                 :            : 
     151                 :          0 :     return false;
     152                 :            : }
     153                 :            : 
     154                 :          0 : bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId, const Any& rValue )
     155                 :            : {
     156                 :            :     // push gradient explicitly
     157         [ #  # ]:          0 :     if( !maShapePropInfo.mbNamedFillGradient )
     158                 :          0 :         return setAnyProperty( nPropId, rValue );
     159                 :            : 
     160                 :            :     // create named gradient and push its name
     161         [ #  # ]:          0 :     if( rValue.has< Gradient >() )
     162                 :            :     {
     163 [ #  # ][ #  # ]:          0 :         OUString aGradientName = mrModelObjHelper.insertFillGradient( rValue.get< Gradient >() );
     164 [ #  # ][ #  # ]:          0 :         return !aGradientName.isEmpty() && setProperty( nPropId, aGradientName );
                 [ #  # ]
     165                 :            :     }
     166                 :            : 
     167                 :          0 :     return false;
     168                 :            : }
     169                 :            : 
     170                 :          0 : bool ShapePropertyMap::setGradientTrans( sal_Int32 nPropId, const Any& rValue )
     171                 :            : {
     172                 :            :     // create named gradient and push its name
     173         [ #  # ]:          0 :     if( rValue.has< Gradient >() )
     174                 :            :     {
     175 [ #  # ][ #  # ]:          0 :         OUString aGradientName = mrModelObjHelper.insertTransGrandient( rValue.get< Gradient >() );
     176 [ #  # ][ #  # ]:          0 :         return !aGradientName.isEmpty()  && setProperty( nPropId, aGradientName );
                 [ #  # ]
     177                 :            :     }
     178                 :            : 
     179                 :          0 :     return false;
     180                 :            : }
     181                 :            : 
     182                 :          0 : bool ShapePropertyMap::setFillBitmapUrl( sal_Int32 nPropId, const Any& rValue )
     183                 :            : {
     184                 :            :     // push bitmap URL explicitly
     185         [ #  # ]:          0 :     if( !maShapePropInfo.mbNamedFillBitmapUrl )
     186                 :          0 :         return setAnyProperty( nPropId, rValue );
     187                 :            : 
     188                 :            :     // create named bitmap URL and push its name
     189         [ #  # ]:          0 :     if( rValue.has< OUString >() )
     190                 :            :     {
     191 [ #  # ][ #  # ]:          0 :         OUString aBitmapUrlName = mrModelObjHelper.insertFillBitmapUrl( rValue.get< OUString >() );
     192 [ #  # ][ #  # ]:          0 :         return !aBitmapUrlName.isEmpty() && setProperty( nPropId, aBitmapUrlName );
                 [ #  # ]
     193                 :            :     }
     194                 :            : 
     195                 :          0 :     return false;
     196                 :            : }
     197                 :            : 
     198                 :            : // ============================================================================
     199                 :            : 
     200                 :            : } // namespace drawingml
     201 [ +  - ][ +  - ]:        285 : } // namespace oox
     202                 :            : 
     203                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10