LCOV - code coverage report
Current view: top level - libreoffice/oox/source/drawingml - shapepropertymap.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 24 58 41.4 %
Date: 2012-12-27 Functions: 7 12 58.3 %
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 ] =
      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             : };
      50             : 
      51             : } // namespace
      52             : 
      53          17 : ShapePropertyInfo ShapePropertyInfo::DEFAULT( spnDefaultShapeIds, true, false, false, false );
      54             : 
      55          68 : ShapePropertyInfo::ShapePropertyInfo( const sal_Int32* pnPropertyIds,
      56             :         bool bNamedLineMarker, bool bNamedLineDash, bool bNamedFillGradient, bool bNamedFillBitmapUrl ) :
      57             :     mpnPropertyIds( pnPropertyIds ),
      58             :     mbNamedLineMarker( bNamedLineMarker ),
      59             :     mbNamedLineDash( bNamedLineDash ),
      60             :     mbNamedFillGradient( bNamedFillGradient ),
      61          68 :     mbNamedFillBitmapUrl( bNamedFillBitmapUrl )
      62             : {
      63             :     OSL_ENSURE( mpnPropertyIds != 0, "ShapePropertyInfo::ShapePropertyInfo - missing property identifiers" );
      64          68 : }
      65             : 
      66             : // ============================================================================
      67             : 
      68          63 : ShapePropertyMap::ShapePropertyMap( ModelObjectHelper& rModelObjHelper, const ShapePropertyInfo& rShapePropInfo ) :
      69             :     mrModelObjHelper( rModelObjHelper ),
      70          63 :     maShapePropInfo( rShapePropInfo )
      71             : {
      72          63 : }
      73             : 
      74           0 : bool ShapePropertyMap::supportsProperty( ShapePropertyId ePropId ) const
      75             : {
      76           0 :     return maShapePropInfo.has( ePropId );
      77             : }
      78             : 
      79           8 : bool ShapePropertyMap::hasNamedLineMarkerInTable( const OUString& rMarkerName ) const
      80             : {
      81           8 :     return maShapePropInfo.mbNamedLineMarker && mrModelObjHelper.hasLineMarker( rMarkerName );
      82             : }
      83             : 
      84         263 : bool ShapePropertyMap::setAnyProperty( ShapePropertyId ePropId, const Any& rValue )
      85             : {
      86             :     // get current property identifier for the specified property
      87         263 :     sal_Int32 nPropId = maShapePropInfo[ ePropId ];
      88         263 :     if( nPropId < 0 ) return false;
      89             : 
      90             :     // special handling for properties supporting named objects in tables
      91         263 :     switch( ePropId )
      92             :     {
      93             :         case SHAPEPROP_LineStart:
      94             :         case SHAPEPROP_LineEnd:
      95           8 :             return setLineMarker( nPropId, rValue );
      96             : 
      97             :         case SHAPEPROP_LineDash:
      98           0 :             return setLineDash( nPropId, rValue );
      99             : 
     100             :         case SHAPEPROP_FillGradient:
     101           0 :             return setFillGradient( nPropId, rValue );
     102             : 
     103             :         case SHAPEPROP_GradientTransparency:
     104           0 :             return setGradientTrans( nPropId, rValue );
     105             : 
     106             :         case SHAPEPROP_FillBitmapUrl:
     107           0 :             return setFillBitmapUrl( nPropId, rValue );
     108             : 
     109             :         default:;   // suppress compiler warnings
     110             :     }
     111             : 
     112             :     // set plain property value
     113         255 :     operator[]( nPropId ) = rValue;
     114         255 :     return true;
     115             : }
     116             : 
     117             : // private --------------------------------------------------------------------
     118             : 
     119           8 : bool ShapePropertyMap::setLineMarker( sal_Int32 nPropId, const Any& rValue )
     120             : {
     121           8 :     NamedValue aNamedMarker;
     122           8 :     if( (rValue >>= aNamedMarker) && !aNamedMarker.Name.isEmpty() )
     123             :     {
     124             :         // push line marker explicitly
     125           8 :         if( !maShapePropInfo.mbNamedLineMarker )
     126           0 :             return setAnyProperty( nPropId, aNamedMarker.Value );
     127             : 
     128             :         // create named line marker (if coordinates have been passed) and push its name
     129           8 :         bool bInserted = !aNamedMarker.Value.has< PolyPolygonBezierCoords >() ||
     130          16 :             mrModelObjHelper.insertLineMarker( aNamedMarker.Name, aNamedMarker.Value.get< PolyPolygonBezierCoords >() );
     131           8 :         return bInserted && setProperty( nPropId, aNamedMarker.Name );
     132             :     }
     133           0 :     return false;
     134             : }
     135             : 
     136           0 : bool ShapePropertyMap::setLineDash( sal_Int32 nPropId, const Any& rValue )
     137             : {
     138             :     // push line dash explicitly
     139           0 :     if( !maShapePropInfo.mbNamedLineDash )
     140           0 :         return setAnyProperty( nPropId, rValue );
     141             : 
     142             :     // create named line dash and push its name
     143           0 :     if( rValue.has< LineDash >() )
     144             :     {
     145           0 :         OUString aDashName = mrModelObjHelper.insertLineDash( rValue.get< LineDash >() );
     146           0 :         return !aDashName.isEmpty() && setProperty( nPropId, aDashName );
     147             :     }
     148             : 
     149           0 :     return false;
     150             : }
     151             : 
     152           0 : bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId, const Any& rValue )
     153             : {
     154             :     // push gradient explicitly
     155           0 :     if( !maShapePropInfo.mbNamedFillGradient )
     156           0 :         return setAnyProperty( nPropId, rValue );
     157             : 
     158             :     // create named gradient and push its name
     159           0 :     if( rValue.has< awt::Gradient >() )
     160             :     {
     161           0 :         OUString aGradientName = mrModelObjHelper.insertFillGradient( rValue.get< awt::Gradient >() );
     162           0 :         return !aGradientName.isEmpty() && setProperty( nPropId, aGradientName );
     163             :     }
     164             : 
     165           0 :     return false;
     166             : }
     167             : 
     168           0 : bool ShapePropertyMap::setGradientTrans( sal_Int32 nPropId, const Any& rValue )
     169             : {
     170             :     // create named gradient and push its name
     171           0 :     if( rValue.has< awt::Gradient >() )
     172             :     {
     173           0 :         OUString aGradientName = mrModelObjHelper.insertTransGrandient( rValue.get< awt::Gradient >() );
     174           0 :         return !aGradientName.isEmpty()  && setProperty( nPropId, aGradientName );
     175             :     }
     176             : 
     177           0 :     return false;
     178             : }
     179             : 
     180           0 : bool ShapePropertyMap::setFillBitmapUrl( sal_Int32 nPropId, const Any& rValue )
     181             : {
     182             :     // push bitmap URL explicitly
     183           0 :     if( !maShapePropInfo.mbNamedFillBitmapUrl )
     184           0 :         return setAnyProperty( nPropId, rValue );
     185             : 
     186             :     // create named bitmap URL and push its name
     187           0 :     if( rValue.has< OUString >() )
     188             :     {
     189           0 :         OUString aBitmapUrlName = mrModelObjHelper.insertFillBitmapUrl( rValue.get< OUString >() );
     190           0 :         return !aBitmapUrlName.isEmpty() && setProperty( nPropId, aBitmapUrlName );
     191             :     }
     192             : 
     193           0 :     return false;
     194             : }
     195             : 
     196             : // ============================================================================
     197             : 
     198             : } // namespace drawingml
     199          51 : } // namespace oox
     200             : 
     201             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10