LCOV - code coverage report
Current view: top level - oox/source/drawingml - fillproperties.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 421 581 72.5 %
Date: 2014-11-03 Functions: 19 21 90.5 %
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 <iterator>
      21             : #include <boost/utility.hpp>
      22             : 
      23             : #include <oox/drawingml/fillproperties.hxx>
      24             : #include <drawingml/graphicproperties.hxx>
      25             : 
      26             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      27             : #include <com/sun/star/beans/XPropertySet.hpp>
      28             : #include <com/sun/star/awt/Gradient.hpp>
      29             : #include <com/sun/star/text/GraphicCrop.hpp>
      30             : #include <com/sun/star/awt/Size.hpp>
      31             : #include <com/sun/star/drawing/BitmapMode.hpp>
      32             : #include <com/sun/star/drawing/ColorMode.hpp>
      33             : #include <com/sun/star/drawing/FillStyle.hpp>
      34             : #include <com/sun/star/drawing/Hatch.hpp>
      35             : #include <com/sun/star/drawing/RectanglePoint.hpp>
      36             : #include <com/sun/star/graphic/XGraphicTransformer.hpp>
      37             : #include <oox/core/fragmenthandler.hxx>
      38             : #include "oox/helper/graphichelper.hxx"
      39             : #include "oox/drawingml/drawingmltypes.hxx"
      40             : #include "oox/drawingml/shapepropertymap.hxx"
      41             : #include "oox/token/tokens.hxx"
      42             : #include <rtl/math.hxx>
      43             : 
      44             : using namespace ::com::sun::star;
      45             : using namespace ::com::sun::star::drawing;
      46             : using namespace ::com::sun::star::graphic;
      47             : 
      48             : using ::com::sun::star::uno::Reference;
      49             : using ::com::sun::star::uno::Exception;
      50             : using ::com::sun::star::uno::UNO_QUERY;
      51             : using ::com::sun::star::uno::UNO_QUERY_THROW;
      52             : using ::com::sun::star::geometry::IntegerRectangle2D;
      53             : 
      54             : namespace oox {
      55             : namespace drawingml {
      56             : 
      57             : namespace {
      58             : 
      59         614 : Reference< XGraphic > lclCheckAndApplyDuotoneTransform( const BlipFillProperties& aBlipProps, Reference< XGraphic > xGraphic,
      60             :                                                         const GraphicHelper& rGraphicHelper, const sal_Int32 nPhClr )
      61             : {
      62         614 :     if( aBlipProps.maDuotoneColors[0].isUsed() && aBlipProps.maDuotoneColors[1].isUsed() )
      63             :     {
      64           2 :         sal_Int32 nColor1 = aBlipProps.maDuotoneColors[0].getColor( rGraphicHelper, nPhClr );
      65           2 :         sal_Int32 nColor2 = aBlipProps.maDuotoneColors[1].getColor( rGraphicHelper, nPhClr );
      66             :         try
      67             :         {
      68           2 :             Reference< XGraphicTransformer > xTransformer( aBlipProps.mxGraphic, UNO_QUERY_THROW );
      69           2 :             xGraphic = xTransformer->applyDuotone( xGraphic, nColor1, nColor2 );
      70             :         }
      71           0 :         catch( Exception& )
      72             :         {
      73             :         }
      74             :     }
      75         614 :     return xGraphic;
      76             : }
      77             : 
      78         504 : Reference< XGraphic > lclCheckAndApplyChangeColorTransform( const BlipFillProperties &aBlipProps, Reference< XGraphic > xGraphic,
      79             :                                                             const GraphicHelper& rGraphicHelper, const sal_Int32 nPhClr )
      80             : {
      81         504 :     if( aBlipProps.maColorChangeFrom.isUsed() && aBlipProps.maColorChangeTo.isUsed() )
      82             :     {
      83           0 :         sal_Int32 nFromColor = aBlipProps.maColorChangeFrom.getColor( rGraphicHelper, nPhClr );
      84           0 :         sal_Int32 nToColor = aBlipProps.maColorChangeTo.getColor( rGraphicHelper, nPhClr );
      85           0 :         if ( (nFromColor != nToColor) || aBlipProps.maColorChangeTo.hasTransparency() ) try
      86             :         {
      87           0 :             sal_Int16 nToTransparence = aBlipProps.maColorChangeTo.getTransparency();
      88           0 :             sal_Int8 nToAlpha = static_cast< sal_Int8 >( (100 - nToTransparence) * 2.55 );
      89           0 :             Reference< XGraphicTransformer > xTransformer( aBlipProps.mxGraphic, UNO_QUERY_THROW );
      90           0 :             xGraphic = xTransformer->colorChange( xGraphic, nFromColor, 9, nToColor, nToAlpha );
      91             :         }
      92           0 :         catch( Exception& )
      93             :         {
      94             :         }
      95             :     }
      96         504 :     return xGraphic;
      97             : }
      98             : 
      99           4 : Reference< XGraphic > applyBrightnessContrast( Reference< XGraphic > xGraphic, sal_Int32 brightness, sal_Int32 contrast )
     100             : {
     101             :     try
     102             :         {
     103           4 :             Reference< XGraphicTransformer > xTransformer( xGraphic, UNO_QUERY_THROW );
     104           4 :             xGraphic = xTransformer->applyBrightnessContrast( xGraphic, brightness, contrast, true );
     105             :         }
     106           0 :         catch( Exception& )
     107             :         {
     108             :         }
     109           4 :     return xGraphic;
     110             : }
     111             : 
     112         110 : BitmapMode lclGetBitmapMode( sal_Int32 nToken )
     113             : {
     114             :     OSL_ASSERT((nToken & sal_Int32(0xFFFF0000))==0);
     115         110 :     switch( nToken )
     116             :     {
     117           0 :         case XML_tile:      return BitmapMode_REPEAT;
     118         110 :         case XML_stretch:   return BitmapMode_STRETCH;
     119             :     }
     120           0 :     return BitmapMode_NO_REPEAT;
     121             : }
     122             : 
     123           0 : RectanglePoint lclGetRectanglePoint( sal_Int32 nToken )
     124             : {
     125             :     OSL_ASSERT((nToken & sal_Int32(0xFFFF0000))==0);
     126           0 :     switch( nToken )
     127             :     {
     128           0 :         case XML_tl:    return RectanglePoint_LEFT_TOP;
     129           0 :         case XML_t:     return RectanglePoint_MIDDLE_TOP;
     130           0 :         case XML_tr:    return RectanglePoint_RIGHT_TOP;
     131           0 :         case XML_l:     return RectanglePoint_LEFT_MIDDLE;
     132           0 :         case XML_ctr:   return RectanglePoint_MIDDLE_MIDDLE;
     133           0 :         case XML_r:     return RectanglePoint_RIGHT_MIDDLE;
     134           0 :         case XML_bl:    return RectanglePoint_LEFT_BOTTOM;
     135           0 :         case XML_b:     return RectanglePoint_MIDDLE_BOTTOM;
     136           0 :         case XML_br:    return RectanglePoint_RIGHT_BOTTOM;
     137             :     }
     138           0 :     return RectanglePoint_LEFT_TOP;
     139             : }
     140             : 
     141           0 : const awt::Size lclGetOriginalSize( const GraphicHelper& rGraphicHelper, const Reference< XGraphic >& rxGraphic )
     142             : {
     143           0 :     awt::Size aSizeHmm( 0, 0 );
     144             :     try
     145             :     {
     146           0 :         Reference< beans::XPropertySet > xGraphicPropertySet( rxGraphic, UNO_QUERY_THROW );
     147           0 :         if( xGraphicPropertySet->getPropertyValue( "Size100thMM" ) >>= aSizeHmm )
     148             :         {
     149           0 :             if( !aSizeHmm.Width && !aSizeHmm.Height )
     150             :             {   // MAPMODE_PIXEL USED :-(
     151           0 :                 awt::Size aSourceSizePixel( 0, 0 );
     152           0 :                 if( xGraphicPropertySet->getPropertyValue( "SizePixel" ) >>= aSourceSizePixel )
     153           0 :                     aSizeHmm = rGraphicHelper.convertScreenPixelToHmm( aSourceSizePixel );
     154             :             }
     155           0 :         }
     156             :     }
     157           0 :     catch( Exception& )
     158             :     {
     159             :     }
     160           0 :     return aSizeHmm;
     161             : }
     162             : 
     163             : } // namespace
     164             : 
     165      142186 : void GradientFillProperties::assignUsed( const GradientFillProperties& rSourceProps )
     166             : {
     167      142186 :     if( !rSourceProps.maGradientStops.empty() )
     168         402 :         maGradientStops = rSourceProps.maGradientStops;
     169      142186 :     moFillToRect.assignIfUsed( rSourceProps.moFillToRect );
     170      142186 :     moTileRect.assignIfUsed( rSourceProps.moTileRect );
     171      142186 :     moGradientPath.assignIfUsed( rSourceProps.moGradientPath );
     172      142186 :     moShadeAngle.assignIfUsed( rSourceProps.moShadeAngle );
     173      142186 :     moShadeFlip.assignIfUsed( rSourceProps.moShadeFlip );
     174      142186 :     moShadeScaled.assignIfUsed( rSourceProps.moShadeScaled );
     175      142186 :     moRotateWithShape.assignIfUsed( rSourceProps.moRotateWithShape );
     176      142186 : }
     177             : 
     178       19382 : void PatternFillProperties::assignUsed( const PatternFillProperties& rSourceProps )
     179             : {
     180       19382 :     maPattFgColor.assignIfUsed( rSourceProps.maPattFgColor );
     181       19382 :     maPattBgColor.assignIfUsed( rSourceProps.maPattBgColor );
     182       19382 :     moPattPreset.assignIfUsed( rSourceProps.moPattPreset );
     183       19382 : }
     184             : 
     185       19382 : void BlipFillProperties::assignUsed( const BlipFillProperties& rSourceProps )
     186             : {
     187       19382 :     if( rSourceProps.mxGraphic.is() )
     188         100 :         mxGraphic = rSourceProps.mxGraphic;
     189       19382 :     moBitmapMode.assignIfUsed( rSourceProps.moBitmapMode );
     190       19382 :     moFillRect.assignIfUsed( rSourceProps.moFillRect );
     191       19382 :     moTileOffsetX.assignIfUsed( rSourceProps.moTileOffsetX );
     192       19382 :     moTileOffsetY.assignIfUsed( rSourceProps.moTileOffsetY );
     193       19382 :     moTileScaleX.assignIfUsed( rSourceProps.moTileScaleX );
     194       19382 :     moTileScaleY.assignIfUsed( rSourceProps.moTileScaleY );
     195       19382 :     moTileAlign.assignIfUsed( rSourceProps.moTileAlign );
     196       19382 :     moTileFlip.assignIfUsed( rSourceProps.moTileFlip );
     197       19382 :     moRotateWithShape.assignIfUsed( rSourceProps.moRotateWithShape );
     198       19382 :     moColorEffect.assignIfUsed( rSourceProps.moColorEffect );
     199       19382 :     moBrightness.assignIfUsed( rSourceProps.moBrightness );
     200       19382 :     moContrast.assignIfUsed( rSourceProps.moContrast );
     201       19382 :     maColorChangeFrom.assignIfUsed( rSourceProps.maColorChangeFrom );
     202       19382 :     maColorChangeTo.assignIfUsed( rSourceProps.maColorChangeTo );
     203       19382 :     maDuotoneColors[0].assignIfUsed( rSourceProps.maDuotoneColors[0] );
     204       19382 :     maDuotoneColors[1].assignIfUsed( rSourceProps.maDuotoneColors[1] );
     205       19382 :     maEffect.assignUsed( rSourceProps.maEffect );
     206       19382 : }
     207             : 
     208       19382 : void FillProperties::assignUsed( const FillProperties& rSourceProps )
     209             : {
     210       19382 :     moFillType.assignIfUsed( rSourceProps.moFillType );
     211       19382 :     maFillColor.assignIfUsed( rSourceProps.maFillColor );
     212       19382 :     maGradientProps.assignUsed( rSourceProps.maGradientProps );
     213       19382 :     maPatternProps.assignUsed( rSourceProps.maPatternProps );
     214       19382 :     maBlipProps.assignUsed( rSourceProps.maBlipProps );
     215       19382 : }
     216             : 
     217        9594 : Color FillProperties::getBestSolidColor() const
     218             : {
     219        9594 :     Color aSolidColor;
     220        9594 :     if( moFillType.has() ) switch( moFillType.get() )
     221             :     {
     222             :         case XML_solidFill:
     223        4722 :             aSolidColor = maFillColor;
     224        4722 :         break;
     225             :         case XML_gradFill:
     226          48 :             if( !maGradientProps.maGradientStops.empty() )
     227             :             {
     228             :                 GradientFillProperties::GradientStopMap::const_iterator aGradientStop =
     229          48 :                     maGradientProps.maGradientStops.begin();
     230          48 :                 if (maGradientProps.maGradientStops.size() > 2)
     231          48 :                     ++aGradientStop;
     232          48 :                 aSolidColor = aGradientStop->second;
     233             :             }
     234          48 :         break;
     235             :         case XML_pattFill:
     236           0 :             aSolidColor = maPatternProps.maPattBgColor.isUsed() ? maPatternProps.maPattBgColor : maPatternProps.maPattFgColor;
     237           0 :         break;
     238             :     }
     239        9594 :     return aSolidColor;
     240             : }
     241             : 
     242             : /// Maps the hatch token to drawing::Hatch.
     243         192 : static drawing::Hatch createHatch( sal_Int32 nHatchToken, sal_Int32 nColor )
     244             : {
     245         192 :     drawing::Hatch aHatch;
     246         192 :     aHatch.Color = nColor;
     247             : 
     248             :     // best-effort mapping; we do not support all the styles in core
     249         192 :     switch ( nHatchToken )
     250             :     {
     251           4 :         case XML_pct5:       aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 250; aHatch.Angle = 450;  break;
     252           2 :         case XML_pct10:      aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 200; aHatch.Angle = 450;  break;
     253           2 :         case XML_pct20:      aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 450;  break;
     254           2 :         case XML_pct25:      aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 200; aHatch.Angle = 450;  break;
     255           6 :         case XML_pct30:      aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 175; aHatch.Angle = 450;  break;
     256           2 :         case XML_pct40:      aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 150; aHatch.Angle = 450;  break;
     257           2 :         case XML_pct50:      aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 125; aHatch.Angle = 450;  break;
     258           2 :         case XML_pct60:      aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 150; aHatch.Angle = 450;  break;
     259           2 :         case XML_pct70:      aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 125; aHatch.Angle = 450;  break;
     260           2 :         case XML_pct75:      aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 100; aHatch.Angle = 450;  break;
     261           2 :         case XML_pct80:      aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 75;  aHatch.Angle = 450;  break;
     262           2 :         case XML_pct90:      aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 50;  aHatch.Angle = 450;  break;
     263           6 :         case XML_horz:       aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 0;    break;
     264           6 :         case XML_vert:       aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 900;  break;
     265           8 :         case XML_ltHorz:     aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 0;    break;
     266          18 :         case XML_ltVert:     aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 900;  break;
     267           2 :         case XML_dkHorz:     aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 25;  aHatch.Angle = 0;    break;
     268           8 :         case XML_dkVert:     aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 25;  aHatch.Angle = 900;  break;
     269           2 :         case XML_narHorz:    aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 0;    break;
     270           4 :         case XML_narVert:    aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 900;  break;
     271           2 :         case XML_dashHorz:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 0;    break;
     272           2 :         case XML_dashVert:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 900;  break;
     273           0 :         case XML_cross:      aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 0;    break;
     274           0 :         case XML_dnDiag:     aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 1350; break;
     275           0 :         case XML_upDiag:     aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 450;  break;
     276           8 :         case XML_ltDnDiag:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 1350; break;
     277           8 :         case XML_ltUpDiag:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 450;  break;
     278           2 :         case XML_dkDnDiag:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 1350; break;
     279           2 :         case XML_dkUpDiag:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 450;  break;
     280           8 :         case XML_wdDnDiag:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 1350; break;
     281           8 :         case XML_wdUpDiag:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 450;  break;
     282           2 :         case XML_dashDnDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 1350; break;
     283           2 :         case XML_dashUpDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 450;  break;
     284           0 :         case XML_diagCross:  aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 450;  break;
     285           8 :         case XML_smCheck:    aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 50;  aHatch.Angle = 450;  break;
     286           2 :         case XML_lgCheck:    aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 450;  break;
     287           8 :         case XML_smGrid:     aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 50;  aHatch.Angle = 0;    break;
     288           8 :         case XML_lgGrid:     aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 0;    break;
     289           2 :         case XML_dotGrid:    aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 400; aHatch.Angle = 0;    break;
     290           2 :         case XML_smConfetti: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 200; aHatch.Angle = 600;  break;
     291           2 :         case XML_lgConfetti: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 600;  break;
     292           2 :         case XML_horzBrick:  aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 300; aHatch.Angle = 0;    break;
     293           2 :         case XML_diagBrick:  aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 300; aHatch.Angle = 450;  break;
     294           2 :         case XML_solidDmnd:  aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 450;  break;
     295           8 :         case XML_openDmnd:   aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 450;  break;
     296           2 :         case XML_dotDmnd:    aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 300; aHatch.Angle = 450;  break;
     297           2 :         case XML_plaid:      aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 200; aHatch.Angle = 900;  break;
     298           2 :         case XML_sphere:     aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 100; aHatch.Angle = 0;    break;
     299           2 :         case XML_weave:      aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 150; aHatch.Angle = 450;  break;
     300           2 :         case XML_divot:      aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 400; aHatch.Angle = 450;  break;
     301           2 :         case XML_shingle:    aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 200; aHatch.Angle = 1350; break;
     302           2 :         case XML_wave:       aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 0;    break;
     303           2 :         case XML_trellis:    aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 75;  aHatch.Angle = 450;  break;
     304           2 :         case XML_zigZag:     aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 75;  aHatch.Angle = 0;    break;
     305             :     }
     306             : 
     307         192 :     return aHatch;
     308             : }
     309             : 
     310        8920 : void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap,
     311             :         const GraphicHelper& rGraphicHelper, sal_Int32 nShapeRotation, sal_Int32 nPhClr,
     312             :         bool bFlipH, bool bFlipV ) const
     313             : {
     314        8920 :     if( moFillType.has() )
     315             :     {
     316        8832 :         FillStyle eFillStyle = FillStyle_NONE;
     317             :         OSL_ASSERT((moFillType.get() & sal_Int32(0xFFFF0000))==0);
     318        8832 :         switch( moFillType.get() )
     319             :         {
     320             :             case XML_noFill:
     321        3784 :                 eFillStyle = FillStyle_NONE;
     322        3784 :             break;
     323             : 
     324             :             case XML_solidFill:
     325        4408 :                 if( maFillColor.isUsed() )
     326             :                 {
     327        4408 :                     rPropMap.setProperty( SHAPEPROP_FillColor, maFillColor.getColor( rGraphicHelper, nPhClr ) );
     328        4408 :                     if( maFillColor.hasTransparency() )
     329         252 :                         rPropMap.setProperty( SHAPEPROP_FillTransparency, maFillColor.getTransparency() );
     330        4408 :                     eFillStyle = FillStyle_SOLID;
     331             :                 }
     332        4408 :             break;
     333             : 
     334             :             case XML_gradFill:
     335             :                 // do not create gradient struct if property is not supported...
     336         338 :                 if( rPropMap.supportsProperty( SHAPEPROP_FillGradient ) )
     337             :                 {
     338         338 :                     sal_Int32 nEndTrans     = 0;
     339         338 :                     sal_Int32 nStartTrans   = 0;
     340         338 :                     awt::Gradient aGradient;
     341         338 :                     aGradient.Angle = 900;
     342         338 :                     aGradient.StartIntensity = 100;
     343         338 :                     aGradient.EndIntensity = 100;
     344             : 
     345             :                     // Old code, values in aGradient overwritten in many cases by newer code below
     346         338 :                     if( maGradientProps.maGradientStops.size() > 1 )
     347             :                     {
     348         338 :                         aGradient.StartColor = maGradientProps.maGradientStops.begin()->second.getColor( rGraphicHelper, nPhClr );
     349         338 :                         aGradient.EndColor = maGradientProps.maGradientStops.rbegin()->second.getColor( rGraphicHelper, nPhClr );
     350         338 :                         if( maGradientProps.maGradientStops.rbegin()->second.hasTransparency() )
     351           2 :                             nEndTrans = maGradientProps.maGradientStops.rbegin()->second.getTransparency()*255/100;
     352         338 :                         if( maGradientProps.maGradientStops.begin()->second.hasTransparency() )
     353          52 :                             nStartTrans = maGradientProps.maGradientStops.begin()->second.getTransparency()*255/100;
     354             :                     }
     355             : 
     356             :                     // Adjust for flips
     357         338 :                     if ( bFlipH )
     358           2 :                         nShapeRotation = 180*60000 - nShapeRotation;
     359         338 :                     if ( bFlipV )
     360           0 :                         nShapeRotation = -nShapeRotation;
     361             : 
     362             :                     // "rotate with shape" not set, or set to false -> do not rotate
     363         338 :                     if ( !maGradientProps.moRotateWithShape.get( false ) )
     364         272 :                         nShapeRotation = 0;
     365             : 
     366         338 :                     sal_Int32 nDmlAngle = 0;
     367         338 :                     if( maGradientProps.moGradientPath.has() )
     368             :                     {
     369          10 :                         aGradient.Style = (maGradientProps.moGradientPath.get() == XML_circle) ? awt::GradientStyle_ELLIPTICAL : awt::GradientStyle_RECT;
     370             :                         // position of gradient center (limited to [30%;70%], otherwise gradient is too hidden)
     371          10 :                         IntegerRectangle2D aFillToRect = maGradientProps.moFillToRect.get( IntegerRectangle2D( 0, 0, MAX_PERCENT, MAX_PERCENT ) );
     372          10 :                         sal_Int32 nCenterX = (MAX_PERCENT + aFillToRect.X1 - aFillToRect.X2) / 2;
     373          10 :                         aGradient.XOffset = getLimitedValue< sal_Int16, sal_Int32 >( nCenterX / PER_PERCENT, 30, 70 );
     374          10 :                         sal_Int32 nCenterY = (MAX_PERCENT + aFillToRect.Y1 - aFillToRect.Y2) / 2;
     375          10 :                         aGradient.YOffset = getLimitedValue< sal_Int16, sal_Int32 >( nCenterY / PER_PERCENT, 30, 70 );
     376          10 :                         ::std::swap( aGradient.StartColor, aGradient.EndColor );
     377          10 :                         ::std::swap( nStartTrans, nEndTrans );
     378          10 :                         nDmlAngle = nShapeRotation;
     379             :                     }
     380             :                     else
     381             :                     {
     382             :                         // A copy of the gradient stops for local modification
     383         328 :                         GradientFillProperties::GradientStopMap aGradientStops(maGradientProps.maGradientStops);
     384             : 
     385             :                         // Add a fake gradient stop at 0% and 100% if necessary, so that the gradient always starts
     386             :                         // at 0% and ends at 100%, to make following logic clearer (?).
     387         328 :                         if( aGradientStops.find(0.0) == aGradientStops.end() )
     388             :                         {
     389             :                             // temp variable required
     390           0 :                             Color aFirstColor(aGradientStops.begin()->second);
     391           0 :                             aGradientStops[0.0] = aFirstColor;
     392             :                         }
     393             : 
     394         328 :                         if( aGradientStops.find(1.0) == aGradientStops.end() )
     395             :                         {
     396             :                             // ditto
     397           0 :                             Color aLastColor(aGradientStops.rbegin()->second);
     398           0 :                             aGradientStops[1.0] = aLastColor;
     399             :                         }
     400             : 
     401             :                         // Check if the gradient is symmetric, which we will emulate with an "axial" gradient.
     402         328 :                         bool bSymmetric(true);
     403             :                         {
     404         328 :                             GradientFillProperties::GradientStopMap::const_iterator aItA( aGradientStops.begin() );
     405         328 :                             GradientFillProperties::GradientStopMap::const_iterator aItZ( boost::prior( aGradientStops.end() ) );
     406         984 :                             while( bSymmetric && aItA->first < aItZ->first )
     407             :                             {
     408         482 :                                 if( aItA->second.getColor( rGraphicHelper, nPhClr ) != aItZ->second.getColor( rGraphicHelper, nPhClr ) ||
     409         154 :                                     aItA->second.getTransparency() != aItZ->second.getTransparency() )
     410         178 :                                     bSymmetric = false;
     411             :                                 else
     412             :                                 {
     413         150 :                                     ++aItA;
     414         150 :                                     aItZ = boost::prior(aItZ);
     415             :                                 }
     416             :                             }
     417             :                             // Don't be fooled if the middlemost stop isn't at 0.5.
     418         328 :                             if( bSymmetric && aItA == aItZ && aItA->first != 0.5 )
     419         102 :                                 bSymmetric = false;
     420             : 
     421             :                             // If symmetric, do the rest of the logic for just a half.
     422         328 :                             if( bSymmetric )
     423             :                             {
     424             :                                 // aItZ already points to the colour for the middle, but insert a fake stop at the
     425             :                                 // exact middle if necessary.
     426          48 :                                 if( aItA->first != aItZ->first )
     427             :                                 {
     428           4 :                                     Color aMiddleColor = aItZ->second;
     429           4 :                                     aGradientStops[0.5] = aMiddleColor;
     430             :                                 }
     431             :                                 // Drop the rest of the stops
     432         144 :                                 while( aGradientStops.rbegin()->first > 0.5 )
     433          48 :                                     aGradientStops.erase( aGradientStops.rbegin()->first );
     434             :                             }
     435             :                         }
     436             : 
     437             :                         SAL_INFO("oox.drawingml.gradient", "symmetric: " << (bSymmetric ? "YES" : "NO") <<
     438             :                                  ", number of stops: " << aGradientStops.size());
     439        2572 :                         for (GradientFillProperties::GradientStopMap::iterator p(aGradientStops.begin());
     440        2244 :                              p != aGradientStops.end();
     441             :                              ++p)
     442             :                             SAL_INFO("oox.drawingml.gradient", "  " << std::distance(aGradientStops.begin(), p) << ": " <<
     443             :                                      p->first << ": " <<
     444             :                                      std::hex << p->second.getColor( rGraphicHelper, nPhClr ) << std::dec <<
     445             :                                      "@" << (100-p->second.getTransparency()) << "%");
     446             : 
     447             :                         // Now estimate the simple LO style gradient (only two stops, at n% and 100%, where n ==
     448             :                         // the "border") that best emulates the gradient between begin() and prior(end()).
     449             : 
     450             :                         // First look for the largest segment in the gradient.
     451         328 :                         GradientFillProperties::GradientStopMap::iterator aIt(aGradientStops.begin());
     452         328 :                         double nWidestWidth = -1;
     453         328 :                         GradientFillProperties::GradientStopMap::iterator aWidestSegmentStart;
     454         328 :                         ++aIt;
     455        1122 :                         while( aIt != aGradientStops.end() )
     456             :                         {
     457         466 :                             if( aIt->first - boost::prior(aIt)->first > nWidestWidth )
     458             :                             {
     459         436 :                                 nWidestWidth = aIt->first - boost::prior(aIt)->first;
     460         436 :                                 aWidestSegmentStart = boost::prior(aIt);
     461             :                             }
     462         466 :                             ++aIt;
     463             :                         }
     464             :                         assert( nWidestWidth > 0 );
     465             : 
     466         328 :                         double nBorder = 0;
     467         328 :                         bool bSwap(false);
     468             : 
     469             :                         // Do we have just two segments, and either one is of uniform colour, or three or more
     470             :                         // segments, and the widest one is the first or last one, and is it of uniform colour? If
     471             :                         // so, deduce the border from it, and drop that segment.
     472        1588 :                         if( aGradientStops.size() == 3 &&
     473        1704 :                             aGradientStops.begin()->second.getColor( rGraphicHelper, nPhClr ) == boost::next(aGradientStops.begin())->second.getColor( rGraphicHelper, nPhClr ) &&
     474         634 :                             aGradientStops.begin()->second.getTransparency() == boost::next(aGradientStops.begin())->second.getTransparency( ) )
     475             :                         {
     476             :                             // Two segments, first is uniformly coloured
     477             :                             SAL_INFO("oox.drawingml.gradient", "two segments, first is uniformly coloured");
     478         102 :                             nBorder = boost::next(aGradientStops.begin())->first - aGradientStops.begin()->first;
     479         102 :                             aGradientStops.erase(aGradientStops.begin());
     480         102 :                             aWidestSegmentStart = aGradientStops.begin();
     481             :                         }
     482        1046 :                         else if( !bSymmetric &&
     483         286 :                                  aGradientStops.size() == 3 &&
     484         822 :                                  boost::next(aGradientStops.begin())->second.getColor( rGraphicHelper, nPhClr ) == boost::prior(aGradientStops.end())->second.getColor( rGraphicHelper, nPhClr ) &&
     485         226 :                                  boost::next(aGradientStops.begin())->second.getTransparency() == boost::prior(aGradientStops.end())->second.getTransparency( ) )
     486             :                         {
     487             :                             // Two segments, second is uniformly coloured
     488             :                             SAL_INFO("oox.drawingml.gradient", "two segments, second is uniformly coloured");
     489           0 :                             nBorder = boost::prior(aGradientStops.end())->first - boost::next(aGradientStops.begin())->first;
     490           0 :                             aGradientStops.erase(boost::next(aGradientStops.begin()));
     491           0 :                             aWidestSegmentStart = aGradientStops.begin();
     492           0 :                             bSwap = true;
     493           0 :                             nShapeRotation = 180*60000 - nShapeRotation;
     494             :                         }
     495        1082 :                         else if( !bSymmetric &&
     496         178 :                                  aGradientStops.size() >= 4 &&
     497         226 :                                  aWidestSegmentStart->second.getColor( rGraphicHelper, nPhClr ) == boost::next(aWidestSegmentStart)->second.getColor( rGraphicHelper, nPhClr ) &&
     498         678 :                                  aWidestSegmentStart->second.getTransparency() == boost::next(aWidestSegmentStart)->second.getTransparency() &&
     499         226 :                                  ( aWidestSegmentStart == aGradientStops.begin() ||
     500         226 :                                    boost::next(aWidestSegmentStart) == boost::prior( aGradientStops.end() ) ) )
     501             :                         {
     502             :                             // Not symmetric, three or more segments, the widest is first or last and is uniformly coloured
     503             :                             SAL_INFO("oox.drawingml.gradient", "first or last segment is widest and is uniformly coloured");
     504           0 :                             nBorder = boost::next(aWidestSegmentStart)->first - aWidestSegmentStart->first;
     505             : 
     506             :                             // If it's the last segment that is uniformly coloured, rotate the gradient 180
     507             :                             // degrees and swap start and end colours
     508           0 :                             if( boost::next(aWidestSegmentStart) == boost::prior( aGradientStops.end() ) )
     509             :                             {
     510           0 :                                 bSwap = true;
     511           0 :                                 nShapeRotation = 180*60000 - nShapeRotation;
     512             :                             }
     513             : 
     514           0 :                             aGradientStops.erase( aWidestSegmentStart++ );
     515             : 
     516             :                             // Look for which is widest now
     517           0 :                             aIt = boost::next(aGradientStops.begin());
     518           0 :                             nWidestWidth = -1;
     519           0 :                             while( aIt != aGradientStops.end() )
     520             :                             {
     521           0 :                                 if( aIt->first - boost::prior(aIt)->first > nWidestWidth )
     522             :                                 {
     523           0 :                                     nWidestWidth = aIt->first - boost::prior(aIt)->first;
     524           0 :                                     aWidestSegmentStart = boost::prior(aIt);
     525             :                                 }
     526           0 :                                 ++aIt;
     527             :                             }
     528             :                         }
     529             :                         SAL_INFO("oox.drawingml.gradient", "widest segment start: " << aWidestSegmentStart->first << ", border: " << nBorder);
     530             :                         assert( (!bSymmetric && !bSwap) || !(bSymmetric && bSwap) );
     531             : 
     532             :                         // Now we have a potential border and a largest segment. Use those.
     533             : 
     534         328 :                         aGradient.Style = bSymmetric ? awt::GradientStyle_AXIAL : awt::GradientStyle_LINEAR;
     535         328 :                         nDmlAngle = maGradientProps.moShadeAngle.get( 0 ) - nShapeRotation;
     536             :                         // convert DrawingML angle (in 1/60000 degrees) to API angle (in 1/10 degrees)
     537         328 :                         aGradient.Angle = static_cast< sal_Int16 >( (4500 - (nDmlAngle / (PER_DEGREE / 10))) % 3600 );
     538         656 :                         Color aStartColor, aEndColor;
     539         328 :                         if( bSymmetric )
     540             :                         {
     541          48 :                             aStartColor = boost::next(aWidestSegmentStart)->second;
     542          48 :                             aEndColor = aWidestSegmentStart->second;
     543          48 :                             nBorder *= 2;
     544             :                         }
     545         280 :                         else if( bSwap )
     546             :                         {
     547           0 :                             aStartColor = boost::next(aWidestSegmentStart)->second;
     548           0 :                             aEndColor = aWidestSegmentStart->second;
     549             :                         }
     550             :                         else
     551             :                         {
     552         280 :                             aStartColor = aWidestSegmentStart->second;
     553         280 :                             aEndColor = boost::next(aWidestSegmentStart)->second;
     554             :                         }
     555             : 
     556             :                         SAL_INFO("oox.drawingml.gradient", "start color: " << std::hex << aStartColor.getColor( rGraphicHelper, nPhClr ) << std::dec <<
     557             :                                  "@" << (100-aStartColor.getTransparency()) << "%"
     558             :                                  ", end color: " << std::hex << aEndColor.getColor( rGraphicHelper, nPhClr ) << std::dec <<
     559             :                                  "@" << (100-aEndColor.getTransparency()) << "%");
     560             : 
     561         328 :                         aGradient.StartColor = aStartColor.getColor( rGraphicHelper, nPhClr );
     562         328 :                         aGradient.EndColor = aEndColor.getColor( rGraphicHelper, nPhClr );
     563             : 
     564         328 :                         if( aStartColor.hasTransparency() )
     565          52 :                             nStartTrans = aStartColor.getTransparency()*255/100;
     566         328 :                         if( aEndColor.hasTransparency() )
     567           8 :                             nEndTrans = aEndColor.getTransparency()*255/100;
     568             : 
     569         656 :                         aGradient.Border = rtl::math::round(100*nBorder);
     570             :                     }
     571             : 
     572             :                     // push gradient or named gradient to property map
     573         338 :                     if( rPropMap.setProperty( SHAPEPROP_FillGradient, aGradient ) )
     574         338 :                         eFillStyle = FillStyle_GRADIENT;
     575             : 
     576             :                     // push gradient transparency to property map
     577         338 :                     if( nStartTrans != 0 || nEndTrans != 0 )
     578             :                     {
     579          60 :                         awt::Gradient aGrad(aGradient);
     580          60 :                         uno::Any aVal;
     581          60 :                         aGrad.EndColor = (sal_Int32)( nEndTrans | nEndTrans << 8 | nEndTrans << 16 );
     582          60 :                         aGrad.StartColor = (sal_Int32)( nStartTrans | nStartTrans << 8 | nStartTrans << 16 );
     583          60 :                         aVal <<= aGrad;
     584          60 :                         rPropMap.setProperty( SHAPEPROP_GradientTransparency, aGrad );
     585             :                     }
     586             : 
     587             :                 }
     588         338 :             break;
     589             : 
     590             :             case XML_blipFill:
     591             :                 // do not start complex graphic transformation if property is not supported...
     592         110 :                 if( maBlipProps.mxGraphic.is() && rPropMap.supportsProperty( SHAPEPROP_FillBitmapUrl ) )
     593             :                 {
     594         110 :                     Reference< XGraphic > xGraphic = lclCheckAndApplyDuotoneTransform( maBlipProps, maBlipProps.mxGraphic, rGraphicHelper, nPhClr );
     595             :                     // TODO: "rotate with shape" is not possible with our current core
     596             : 
     597         220 :                     OUString aGraphicUrl = rGraphicHelper.createGraphicObject( xGraphic );
     598             :                     // push bitmap or named bitmap to property map
     599         110 :                     if( !aGraphicUrl.isEmpty() && rPropMap.supportsProperty( SHAPEPROP_FillBitmapNameFromUrl ) && rPropMap.setProperty( SHAPEPROP_FillBitmapNameFromUrl, aGraphicUrl ) )
     600         106 :                         eFillStyle = FillStyle_BITMAP;
     601           4 :                     else if( !aGraphicUrl.isEmpty() && rPropMap.setProperty( SHAPEPROP_FillBitmapUrl, aGraphicUrl ) )
     602           4 :                         eFillStyle = FillStyle_BITMAP;
     603             : 
     604             :                     // set other bitmap properties, if bitmap has been inserted into the map
     605         110 :                     if( eFillStyle == FillStyle_BITMAP )
     606             :                     {
     607             :                         // bitmap mode (single, repeat, stretch)
     608         110 :                         BitmapMode eBitmapMode = lclGetBitmapMode( maBlipProps.moBitmapMode.get( XML_TOKEN_INVALID ) );
     609         110 :                         rPropMap.setProperty( SHAPEPROP_FillBitmapMode, eBitmapMode );
     610             : 
     611             :                         // additional settings for repeated bitmap
     612         110 :                         if( eBitmapMode == BitmapMode_REPEAT )
     613             :                         {
     614             :                             // anchor position inside bitmap
     615           0 :                             RectanglePoint eRectPoint = lclGetRectanglePoint( maBlipProps.moTileAlign.get( XML_tl ) );
     616           0 :                             rPropMap.setProperty( SHAPEPROP_FillBitmapRectanglePoint, eRectPoint );
     617             : 
     618           0 :                             awt::Size aOriginalSize = lclGetOriginalSize( rGraphicHelper, maBlipProps.mxGraphic );
     619           0 :                             if( (aOriginalSize.Width > 0) && (aOriginalSize.Height > 0) )
     620             :                             {
     621             :                                 // size of one bitmap tile (given as 1/1000 percent of bitmap size), convert to 1/100 mm
     622           0 :                                 double fScaleX = maBlipProps.moTileScaleX.get( MAX_PERCENT ) / static_cast< double >( MAX_PERCENT );
     623           0 :                                 sal_Int32 nFillBmpSizeX = getLimitedValue< sal_Int32, double >( aOriginalSize.Width * fScaleX, 1, SAL_MAX_INT32 );
     624           0 :                                 rPropMap.setProperty( SHAPEPROP_FillBitmapSizeX, nFillBmpSizeX );
     625           0 :                                 double fScaleY = maBlipProps.moTileScaleY.get( MAX_PERCENT ) / static_cast< double >( MAX_PERCENT );
     626           0 :                                 sal_Int32 nFillBmpSizeY = getLimitedValue< sal_Int32, double >( aOriginalSize.Height * fScaleY, 1, SAL_MAX_INT32 );
     627           0 :                                 rPropMap.setProperty( SHAPEPROP_FillBitmapSizeY, nFillBmpSizeY );
     628             : 
     629             :                                 // offset of the first bitmap tile (given as EMUs), convert to percent
     630           0 :                                 sal_Int16 nTileOffsetX = getDoubleIntervalValue< sal_Int16 >( maBlipProps.moTileOffsetX.get( 0 ) / 3.6 / aOriginalSize.Width, 0, 100 );
     631           0 :                                 rPropMap.setProperty( SHAPEPROP_FillBitmapOffsetX, nTileOffsetX );
     632           0 :                                 sal_Int16 nTileOffsetY = getDoubleIntervalValue< sal_Int16 >( maBlipProps.moTileOffsetY.get( 0 ) / 3.6 / aOriginalSize.Height, 0, 100 );
     633           0 :                                 rPropMap.setProperty( SHAPEPROP_FillBitmapOffsetY, nTileOffsetY );
     634             :                             }
     635             :                         }
     636         110 :                         else if ( eBitmapMode == BitmapMode_STRETCH && maBlipProps.moFillRect.has() )
     637             :                         {
     638         110 :                             geometry::IntegerRectangle2D aFillRect( maBlipProps.moFillRect.get() );
     639         110 :                             awt::Size aOriginalSize( rGraphicHelper.getOriginalSize( xGraphic ) );
     640         110 :                             if ( aOriginalSize.Width && aOriginalSize.Height )
     641             :                             {
     642         110 :                                 text::GraphicCrop aGraphCrop( 0, 0, 0, 0 );
     643         110 :                                 if ( aFillRect.X1 )
     644          74 :                                     aGraphCrop.Left = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * aFillRect.X1 ) / 100000 );
     645         110 :                                 if ( aFillRect.Y1 )
     646          36 :                                     aGraphCrop.Top = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * aFillRect.Y1 ) / 100000 );
     647         110 :                                 if ( aFillRect.X2 )
     648          74 :                                     aGraphCrop.Right = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * aFillRect.X2 ) / 100000 );
     649         110 :                                 if ( aFillRect.Y2 )
     650          36 :                                     aGraphCrop.Bottom = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * aFillRect.Y2 ) / 100000 );
     651         110 :                                 rPropMap.setProperty(PROP_GraphicCrop, aGraphCrop);
     652             :                             }
     653             :                         }
     654         110 :                     }
     655             :                 }
     656         110 :             break;
     657             : 
     658             :             case XML_pattFill:
     659             :             {
     660         192 :                 if( rPropMap.supportsProperty( SHAPEPROP_FillHatch ) )
     661             :                 {
     662         192 :                     Color aColor( maPatternProps.maPattFgColor );
     663         192 :                     if( aColor.isUsed() && maPatternProps.moPattPreset.has() )
     664             :                     {
     665             :                         // we do not support hatches that have background
     666             :                         // color too, so all this is some best-effort approach
     667         192 :                         eFillStyle = FillStyle_HATCH;
     668         192 :                         rPropMap.setProperty( SHAPEPROP_FillHatch, createHatch( maPatternProps.moPattPreset.get(), aColor.getColor( rGraphicHelper, nPhClr ) ) );
     669             :                     }
     670           0 :                     else if ( maPatternProps.maPattBgColor.isUsed() )
     671             :                     {
     672           0 :                         aColor = maPatternProps.maPattBgColor;
     673           0 :                         rPropMap.setProperty( SHAPEPROP_FillColor, aColor.getColor( rGraphicHelper, nPhClr ) );
     674           0 :                         if( aColor.hasTransparency() )
     675           0 :                             rPropMap.setProperty( SHAPEPROP_FillTransparency, aColor.getTransparency() );
     676           0 :                         eFillStyle = FillStyle_SOLID;
     677         192 :                     }
     678             :                 }
     679             :             }
     680         192 :             break;
     681             : 
     682             :             case XML_grpFill:
     683             :                 // todo
     684           0 :                 eFillStyle = FillStyle_NONE;
     685           0 :             break;
     686             :         }
     687             : 
     688             :         // set final fill style property
     689        8832 :         rPropMap.setProperty( SHAPEPROP_FillStyle, eFillStyle );
     690             :     }
     691        8920 : }
     692             : 
     693         572 : void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelper& rGraphicHelper, sal_Int32 nPhClr ) const
     694             : {
     695         572 :     sal_Int16 nBrightness = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moBrightness.get( 0 ) / PER_PERCENT, -100, 100 );
     696         572 :     sal_Int16 nContrast = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moContrast.get( 0 ) / PER_PERCENT, -100, 100 );
     697         572 :     if( maBlipProps.mxGraphic.is() )
     698             :     {
     699             :         // created transformed graphic
     700         504 :         Reference< XGraphic > xGraphic = lclCheckAndApplyDuotoneTransform( maBlipProps, maBlipProps.mxGraphic, rGraphicHelper, nPhClr );
     701         504 :         xGraphic = lclCheckAndApplyChangeColorTransform( maBlipProps, xGraphic, rGraphicHelper, nPhClr );
     702             :         // MSO uses a different algorithm for contrast+brightness, LO applies contrast before brightness,
     703             :         // while MSO apparently applies half of brightness before contrast and half after. So if only
     704             :         // contrast or brightness need to be altered, the result is the same, but if both are involved,
     705             :         // there's no way to map that, so just force a conversion of the image.
     706         504 :         if( nBrightness != 0 && nContrast != 0 )
     707             :         {
     708           4 :             xGraphic = applyBrightnessContrast( xGraphic, nBrightness, nContrast );
     709           4 :             nBrightness = 0;
     710           4 :             nContrast = 0;
     711             :         }
     712         504 :         rPropMap.setProperty(PROP_Graphic, xGraphic);
     713             : 
     714             :         // do we still need to set GraphicURL as well? (TODO)
     715        1008 :         OUString aGraphicUrl = rGraphicHelper.createGraphicObject( xGraphic );
     716         504 :         if( !aGraphicUrl.isEmpty() )
     717         504 :             rPropMap.setProperty(PROP_GraphicURL, aGraphicUrl);
     718             : 
     719             :         // cropping
     720         504 :         if ( maBlipProps.moClipRect.has() )
     721             :         {
     722         156 :             geometry::IntegerRectangle2D oClipRect( maBlipProps.moClipRect.get() );
     723         156 :             awt::Size aOriginalSize( rGraphicHelper.getOriginalSize( xGraphic ) );
     724         156 :             if ( aOriginalSize.Width && aOriginalSize.Height )
     725             :             {
     726         156 :                 text::GraphicCrop aGraphCrop( 0, 0, 0, 0 );
     727         156 :                 if ( oClipRect.X1 )
     728          20 :                     aGraphCrop.Left = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X1 ) / 100000 );
     729         156 :                 if ( oClipRect.Y1 )
     730          22 :                     aGraphCrop.Top = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y1 ) / 100000 );
     731         156 :                 if ( oClipRect.X2 )
     732          20 :                     aGraphCrop.Right = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X2 ) / 100000 );
     733         156 :                 if ( oClipRect.Y2 )
     734          20 :                     aGraphCrop.Bottom = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y2 ) / 100000 );
     735         156 :                 rPropMap.setProperty(PROP_GraphicCrop, aGraphCrop);
     736             :             }
     737         504 :         }
     738             :     }
     739             : 
     740             :     // color effect
     741         572 :     ColorMode eColorMode = ColorMode_STANDARD;
     742         572 :     switch( maBlipProps.moColorEffect.get( XML_TOKEN_INVALID ) )
     743             :     {
     744           0 :         case XML_biLevel:   eColorMode = ColorMode_MONO;    break;
     745           2 :         case XML_grayscl:   eColorMode = ColorMode_GREYS;   break;
     746             :     }
     747         572 :     rPropMap.setProperty(PROP_GraphicColorMode, eColorMode);
     748             : 
     749             :     // brightness and contrast
     750         572 :     if( nBrightness != 0 )
     751           0 :         rPropMap.setProperty(PROP_AdjustLuminance, nBrightness);
     752         572 :     if( nContrast != 0 )
     753           0 :         rPropMap.setProperty(PROP_AdjustContrast, nContrast);
     754             : 
     755             :     // Media content
     756             :     assert(m_xMediaStream.is() != m_sMediaPackageURL.isEmpty());
     757         572 :     if (m_xMediaStream.is() && !m_sMediaPackageURL.isEmpty())
     758             :     {
     759           4 :         rPropMap.setProperty(PROP_PrivateStream, m_xMediaStream);
     760           4 :         rPropMap.setProperty(PROP_MediaURL, m_sMediaPackageURL);
     761             :     }
     762         572 : }
     763             : 
     764       24368 : bool ArtisticEffectProperties::isEmpty() const
     765             : {
     766       24368 :     return msName.isEmpty();
     767             : }
     768             : 
     769          38 : css::beans::PropertyValue ArtisticEffectProperties::getEffect()
     770             : {
     771          38 :     css::beans::PropertyValue pRet;
     772          38 :     if( msName.isEmpty() )
     773           0 :         return pRet;
     774             : 
     775          76 :     css::uno::Sequence< css::beans::PropertyValue > aSeq( maAttribs.size() + 1 );
     776          38 :     sal_uInt32 i = 0;
     777          92 :     for( std::map< OUString, css::uno::Any >::iterator it = maAttribs.begin(); it != maAttribs.end(); ++it )
     778             :     {
     779          54 :         aSeq[i].Name = it->first;
     780          54 :         aSeq[i].Value = it->second;
     781          54 :         i++;
     782             :     }
     783             : 
     784          38 :     if( mrOleObjectInfo.maEmbeddedData.hasElements() )
     785             :     {
     786          38 :         css::uno::Sequence< css::beans::PropertyValue > aGraphicSeq( 2 );
     787          38 :         aGraphicSeq[0].Name = "Id";
     788          38 :         aGraphicSeq[0].Value = uno::makeAny( mrOleObjectInfo.maProgId );
     789          38 :         aGraphicSeq[1].Name = "Data";
     790          38 :         aGraphicSeq[1].Value = uno::makeAny( mrOleObjectInfo.maEmbeddedData );
     791             : 
     792          38 :         aSeq[i].Name = "OriginalGraphic";
     793          38 :         aSeq[i].Value = uno::makeAny( aGraphicSeq );
     794             :     }
     795             : 
     796          38 :     pRet.Name = msName;
     797          38 :     pRet.Value = css::uno::Any( aSeq );
     798             : 
     799          38 :     return pRet;
     800             : }
     801             : 
     802       19382 : void ArtisticEffectProperties::assignUsed( const ArtisticEffectProperties& rSourceProps )
     803             : {
     804       19382 :     if( !rSourceProps.isEmpty() )
     805             :     {
     806           0 :         msName = rSourceProps.msName;
     807           0 :         maAttribs = rSourceProps.maAttribs;
     808             :     }
     809       19382 : }
     810             : 
     811          92 : OUString ArtisticEffectProperties::getEffectString( sal_Int32 nToken )
     812             : {
     813          92 :     switch( nToken )
     814             :     {
     815             :         // effects
     816           0 :         case OOX_TOKEN( a14, artisticBlur ):                return OUString( "artisticBlur" );
     817           0 :         case OOX_TOKEN( a14, artisticCement ):              return OUString( "artisticCement" );
     818           0 :         case OOX_TOKEN( a14, artisticChalkSketch ):         return OUString( "artisticChalkSketch" );
     819           0 :         case OOX_TOKEN( a14, artisticCrisscrossEtching ):   return OUString( "artisticCrisscrossEtching" );
     820           0 :         case OOX_TOKEN( a14, artisticCutout ):              return OUString( "artisticCutout" );
     821           0 :         case OOX_TOKEN( a14, artisticFilmGrain ):           return OUString( "artisticFilmGrain" );
     822           0 :         case OOX_TOKEN( a14, artisticGlass ):               return OUString( "artisticGlass" );
     823           0 :         case OOX_TOKEN( a14, artisticGlowDiffused ):        return OUString( "artisticGlowDiffused" );
     824           0 :         case OOX_TOKEN( a14, artisticGlowEdges ):           return OUString( "artisticGlowEdges" );
     825           6 :         case OOX_TOKEN( a14, artisticLightScreen ):         return OUString( "artisticLightScreen" );
     826           0 :         case OOX_TOKEN( a14, artisticLineDrawing ):         return OUString( "artisticLineDrawing" );
     827           6 :         case OOX_TOKEN( a14, artisticMarker ):              return OUString( "artisticMarker" );
     828           0 :         case OOX_TOKEN( a14, artisticMosiaicBubbles ):      return OUString( "artisticMosiaicBubbles" );
     829           0 :         case OOX_TOKEN( a14, artisticPaintStrokes ):        return OUString( "artisticPaintStrokes" );
     830           0 :         case OOX_TOKEN( a14, artisticPaintBrush ):          return OUString( "artisticPaintBrush" );
     831           0 :         case OOX_TOKEN( a14, artisticPastelsSmooth ):       return OUString( "artisticPastelsSmooth" );
     832           8 :         case OOX_TOKEN( a14, artisticPencilGrayscale ):     return OUString( "artisticPencilGrayscale" );
     833           6 :         case OOX_TOKEN( a14, artisticPencilSketch ):        return OUString( "artisticPencilSketch" );
     834           6 :         case OOX_TOKEN( a14, artisticPhotocopy ):           return OUString( "artisticPhotocopy" );
     835           0 :         case OOX_TOKEN( a14, artisticPlasticWrap ):         return OUString( "artisticPlasticWrap" );
     836           0 :         case OOX_TOKEN( a14, artisticTexturizer ):          return OUString( "artisticTexturizer" );
     837           6 :         case OOX_TOKEN( a14, artisticWatercolorSponge ):    return OUString( "artisticWatercolorSponge" );
     838           0 :         case OOX_TOKEN( a14, artisticBrightnessContrast ):  return OUString( "artisticBrightnessContrast" );
     839           0 :         case OOX_TOKEN( a14, artisticColorTemperature ):    return OUString( "artisticColorTemperature" );
     840           0 :         case OOX_TOKEN( a14, artisticSaturation ):          return OUString( "artisticSaturation" );
     841           0 :         case OOX_TOKEN( a14, artisticSharpenSoften ):       return OUString( "artisticSharpenSoften" );
     842             : 
     843             :         // attributes
     844           0 :         case XML_visible:           return OUString( "visible" );
     845          24 :         case XML_trans:             return OUString( "trans" );
     846           0 :         case XML_crackSpacing:      return OUString( "crackSpacing" );
     847           6 :         case XML_pressure:          return OUString( "pressure" );
     848           0 :         case XML_numberOfShades:    return OUString( "numberOfShades" );
     849           0 :         case XML_grainSize:         return OUString( "grainSize" );
     850           0 :         case XML_intensity:         return OUString( "intensity" );
     851           0 :         case XML_smoothness:        return OUString( "smoothness" );
     852           6 :         case XML_gridSize:          return OUString( "gridSize" );
     853           6 :         case XML_pencilSize:        return OUString( "pencilSize" );
     854           6 :         case XML_size:              return OUString( "size" );
     855           6 :         case XML_brushSize:         return OUString( "brushSize" );
     856           0 :         case XML_scaling:           return OUString( "scaling" );
     857           0 :         case XML_detail:            return OUString( "detail" );
     858           0 :         case XML_bright:            return OUString( "bright" );
     859           0 :         case XML_contrast:          return OUString( "contrast" );
     860           0 :         case XML_colorTemp:         return OUString( "colorTemp" );
     861           0 :         case XML_sat:               return OUString( "sat" );
     862           0 :         case XML_amount:            return OUString( "amount" );
     863             :     }
     864             :     SAL_WARN( "oox.drawingml", "ArtisticEffectProperties::getEffectString - unexpected token" );
     865           0 :     return OUString();
     866             : }
     867             : 
     868         152 : sal_Int32 ArtisticEffectProperties::getEffectToken( const OUString& sName )
     869             : {
     870             :     // effects
     871         152 :     if( sName == "artisticBlur" )
     872           0 :         return XML_artisticBlur;
     873         152 :     else if( sName == "artisticCement" )
     874           0 :         return XML_artisticCement;
     875         152 :     else if( sName == "artisticChalkSketch" )
     876           0 :         return XML_artisticChalkSketch;
     877         152 :     else if( sName == "artisticCrisscrossEtching" )
     878           0 :         return XML_artisticCrisscrossEtching;
     879         152 :     else if( sName == "artisticCutout" )
     880           0 :         return XML_artisticCutout;
     881         152 :     else if( sName == "artisticFilmGrain" )
     882           0 :         return XML_artisticFilmGrain;
     883         152 :     else if( sName == "artisticGlass" )
     884           0 :         return XML_artisticGlass;
     885         152 :     else if( sName == "artisticGlowDiffused" )
     886           0 :         return XML_artisticGlowDiffused;
     887         152 :     else if( sName == "artisticGlowEdges" )
     888           0 :         return XML_artisticGlowEdges;
     889         152 :     else if( sName == "artisticLightScreen" )
     890           2 :         return XML_artisticLightScreen;
     891         150 :     else if( sName == "artisticLineDrawing" )
     892           0 :         return XML_artisticLineDrawing;
     893         150 :     else if( sName == "artisticMarker" )
     894           2 :         return XML_artisticMarker;
     895         148 :     else if( sName == "artisticMosiaicBubbles" )
     896           0 :         return XML_artisticMosiaicBubbles;
     897         148 :     else if( sName == "artisticPaintStrokes" )
     898           0 :         return XML_artisticPaintStrokes;
     899         148 :     else if( sName == "artisticPaintBrush" )
     900           0 :         return XML_artisticPaintBrush;
     901         148 :     else if( sName == "artisticPastelsSmooth" )
     902           0 :         return XML_artisticPastelsSmooth;
     903         148 :     else if( sName == "artisticPencilGrayscale" )
     904           2 :         return XML_artisticPencilGrayscale;
     905         146 :     else if( sName == "artisticPencilSketch" )
     906           2 :         return XML_artisticPencilSketch;
     907         144 :     else if( sName == "artisticPhotocopy" )
     908           2 :         return XML_artisticPhotocopy;
     909         142 :     else if( sName == "artisticPlasticWrap" )
     910           0 :         return XML_artisticPlasticWrap;
     911         142 :     else if( sName == "artisticTexturizer" )
     912           0 :         return XML_artisticTexturizer;
     913         142 :     else if( sName == "artisticWatercolorSponge" )
     914           2 :         return XML_artisticWatercolorSponge;
     915         140 :     else if( sName == "artisticBrightnessContrast" )
     916           0 :         return XML_artisticBrightnessContrast;
     917         140 :     else if( sName == "artisticColorTemperature" )
     918           0 :         return XML_artisticColorTemperature;
     919         140 :     else if( sName == "artisticSaturation" )
     920           0 :         return XML_artisticSaturation;
     921         140 :     else if( sName == "artisticSharpenSoften" )
     922           0 :         return XML_artisticSharpenSoften;
     923             : 
     924             :     // attributes
     925         140 :     else if( sName == "visible" )
     926           0 :         return XML_visible;
     927         140 :     else if( sName == "trans" )
     928           8 :         return XML_trans;
     929         132 :     else if( sName == "crackSpacing" )
     930           0 :         return XML_crackSpacing;
     931         132 :     else if( sName == "pressure" )
     932           2 :         return XML_pressure;
     933         130 :     else if( sName == "numberOfShades" )
     934           0 :         return XML_numberOfShades;
     935         130 :     else if( sName == "grainSize" )
     936           0 :         return XML_grainSize;
     937         130 :     else if( sName == "intensity" )
     938           0 :         return XML_intensity;
     939         130 :     else if( sName == "smoothness" )
     940           0 :         return XML_smoothness;
     941         130 :     else if( sName == "gridSize" )
     942           2 :         return XML_gridSize;
     943         128 :     else if( sName == "pencilSize" )
     944           2 :         return XML_pencilSize;
     945         126 :     else if( sName == "size" )
     946           2 :         return XML_size;
     947         124 :     else if( sName == "brushSize" )
     948           2 :         return XML_brushSize;
     949         122 :     else if( sName == "scaling" )
     950           0 :         return XML_scaling;
     951         122 :     else if( sName == "detail" )
     952           0 :         return XML_detail;
     953         122 :     else if( sName == "bright" )
     954           0 :         return XML_bright;
     955         122 :     else if( sName == "contrast" )
     956           0 :         return XML_contrast;
     957         122 :     else if( sName == "colorTemp" )
     958           0 :         return XML_colorTemp;
     959         122 :     else if( sName == "sat" )
     960           0 :         return XML_sat;
     961         122 :     else if( sName == "amount" )
     962           0 :         return XML_amount;
     963             : 
     964             :     SAL_WARN( "oox.drawingml", "ArtisticEffectProperties::getEffectToken - unexpected token name" );
     965         122 :     return XML_none;
     966             : }
     967             : 
     968             : } // namespace drawingml
     969         408 : } // namespace oox
     970             : 
     971             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10