LCOV - code coverage report
Current view: top level - oox/source/drawingml - fillproperties.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 245 323 75.9 %
Date: 2014-04-11 Functions: 13 15 86.7 %
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/fillproperties.hxx"
      21             : 
      22             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/awt/Gradient.hpp>
      25             : #include <com/sun/star/text/GraphicCrop.hpp>
      26             : #include <com/sun/star/awt/Size.hpp>
      27             : #include <com/sun/star/drawing/BitmapMode.hpp>
      28             : #include <com/sun/star/drawing/ColorMode.hpp>
      29             : #include <com/sun/star/drawing/FillStyle.hpp>
      30             : #include <com/sun/star/drawing/Hatch.hpp>
      31             : #include <com/sun/star/drawing/RectanglePoint.hpp>
      32             : #include <com/sun/star/graphic/XGraphicTransformer.hpp>
      33             : #include "oox/helper/graphichelper.hxx"
      34             : #include "oox/drawingml/drawingmltypes.hxx"
      35             : #include "oox/drawingml/shapepropertymap.hxx"
      36             : #include "oox/token/tokens.hxx"
      37             : 
      38             : using namespace ::com::sun::star;
      39             : using namespace ::com::sun::star::drawing;
      40             : using namespace ::com::sun::star::graphic;
      41             : 
      42             : using ::com::sun::star::uno::Reference;
      43             : using ::com::sun::star::uno::Exception;
      44             : using ::com::sun::star::uno::UNO_QUERY;
      45             : using ::com::sun::star::uno::UNO_QUERY_THROW;
      46             : using ::com::sun::star::geometry::IntegerRectangle2D;
      47             : 
      48             : namespace oox {
      49             : namespace drawingml {
      50             : 
      51             : 
      52             : 
      53             : namespace {
      54             : 
      55         187 : Reference< XGraphic > lclCheckAndApplyDuotoneTransform( const BlipFillProperties& aBlipProps, Reference< XGraphic > xGraphic,
      56             :                                                         const GraphicHelper& rGraphicHelper, const sal_Int32 nPhClr )
      57             : {
      58         187 :     if( aBlipProps.maDuotoneColors[0].isUsed() && aBlipProps.maDuotoneColors[1].isUsed() )
      59             :     {
      60           1 :         sal_Int32 nColor1 = aBlipProps.maDuotoneColors[0].getColor( rGraphicHelper, nPhClr );
      61           1 :         sal_Int32 nColor2 = aBlipProps.maDuotoneColors[1].getColor( rGraphicHelper, nPhClr );
      62             :         try
      63             :         {
      64           1 :             Reference< XGraphicTransformer > xTransformer( aBlipProps.mxGraphic, UNO_QUERY_THROW );
      65           1 :             xGraphic = xTransformer->applyDuotone( xGraphic, nColor1, nColor2 );
      66             :         }
      67           0 :         catch( Exception& )
      68             :         {
      69             :         }
      70             :     }
      71         187 :     return xGraphic;
      72             : }
      73             : 
      74         163 : Reference< XGraphic > lclCheckAndApplyChangeColorTransform( const BlipFillProperties &aBlipProps, Reference< XGraphic > xGraphic,
      75             :                                                             const GraphicHelper& rGraphicHelper, const sal_Int32 nPhClr )
      76             : {
      77         163 :     if( aBlipProps.maColorChangeFrom.isUsed() && aBlipProps.maColorChangeTo.isUsed() )
      78             :     {
      79           0 :         sal_Int32 nFromColor = aBlipProps.maColorChangeFrom.getColor( rGraphicHelper, nPhClr );
      80           0 :         sal_Int32 nToColor = aBlipProps.maColorChangeTo.getColor( rGraphicHelper, nPhClr );
      81           0 :         if ( (nFromColor != nToColor) || aBlipProps.maColorChangeTo.hasTransparency() ) try
      82             :         {
      83           0 :             sal_Int16 nToTransparence = aBlipProps.maColorChangeTo.getTransparency();
      84           0 :             sal_Int8 nToAlpha = static_cast< sal_Int8 >( (100 - nToTransparence) * 2.55 );
      85           0 :             Reference< XGraphicTransformer > xTransformer( aBlipProps.mxGraphic, UNO_QUERY_THROW );
      86           0 :             xGraphic = xTransformer->colorChange( xGraphic, nFromColor, 9, nToColor, nToAlpha );
      87             :         }
      88           0 :         catch( Exception& )
      89             :         {
      90             :         }
      91             :     }
      92         163 :     return xGraphic;
      93             : }
      94             : 
      95             : 
      96             : 
      97          24 : BitmapMode lclGetBitmapMode( sal_Int32 nToken )
      98             : {
      99             :     OSL_ASSERT((nToken & sal_Int32(0xFFFF0000))==0);
     100          24 :     switch( nToken )
     101             :     {
     102           0 :         case XML_tile:      return BitmapMode_REPEAT;
     103          24 :         case XML_stretch:   return BitmapMode_STRETCH;
     104             :     }
     105           0 :     return BitmapMode_NO_REPEAT;
     106             : }
     107             : 
     108           0 : RectanglePoint lclGetRectanglePoint( sal_Int32 nToken )
     109             : {
     110             :     OSL_ASSERT((nToken & sal_Int32(0xFFFF0000))==0);
     111           0 :     switch( nToken )
     112             :     {
     113           0 :         case XML_tl:    return RectanglePoint_LEFT_TOP;
     114           0 :         case XML_t:     return RectanglePoint_MIDDLE_TOP;
     115           0 :         case XML_tr:    return RectanglePoint_RIGHT_TOP;
     116           0 :         case XML_l:     return RectanglePoint_LEFT_MIDDLE;
     117           0 :         case XML_ctr:   return RectanglePoint_MIDDLE_MIDDLE;
     118           0 :         case XML_r:     return RectanglePoint_RIGHT_MIDDLE;
     119           0 :         case XML_bl:    return RectanglePoint_LEFT_BOTTOM;
     120           0 :         case XML_b:     return RectanglePoint_MIDDLE_BOTTOM;
     121           0 :         case XML_br:    return RectanglePoint_RIGHT_BOTTOM;
     122             :     }
     123           0 :     return RectanglePoint_LEFT_TOP;
     124             : }
     125             : 
     126           0 : const awt::Size lclGetOriginalSize( const GraphicHelper& rGraphicHelper, const Reference< XGraphic >& rxGraphic )
     127             : {
     128           0 :     awt::Size aSizeHmm( 0, 0 );
     129             :     try
     130             :     {
     131           0 :         Reference< beans::XPropertySet > xGraphicPropertySet( rxGraphic, UNO_QUERY_THROW );
     132           0 :         if( xGraphicPropertySet->getPropertyValue( "Size100thMM" ) >>= aSizeHmm )
     133             :         {
     134           0 :             if( !aSizeHmm.Width && !aSizeHmm.Height )
     135             :             {   // MAPMODE_PIXEL USED :-(
     136           0 :                 awt::Size aSourceSizePixel( 0, 0 );
     137           0 :                 if( xGraphicPropertySet->getPropertyValue( "SizePixel" ) >>= aSourceSizePixel )
     138           0 :                     aSizeHmm = rGraphicHelper.convertScreenPixelToHmm( aSourceSizePixel );
     139             :             }
     140           0 :         }
     141             :     }
     142           0 :     catch( Exception& )
     143             :     {
     144             :     }
     145           0 :     return aSizeHmm;
     146             : }
     147             : 
     148             : } // namespace
     149             : 
     150             : 
     151             : 
     152       45362 : void GradientFillProperties::assignUsed( const GradientFillProperties& rSourceProps )
     153             : {
     154       45362 :     if( !rSourceProps.maGradientStops.empty() )
     155         166 :         maGradientStops = rSourceProps.maGradientStops;
     156       45362 :     moFillToRect.assignIfUsed( rSourceProps.moFillToRect );
     157       45362 :     moTileRect.assignIfUsed( rSourceProps.moTileRect );
     158       45362 :     moGradientPath.assignIfUsed( rSourceProps.moGradientPath );
     159       45362 :     moShadeAngle.assignIfUsed( rSourceProps.moShadeAngle );
     160       45362 :     moShadeFlip.assignIfUsed( rSourceProps.moShadeFlip );
     161       45362 :     moShadeScaled.assignIfUsed( rSourceProps.moShadeScaled );
     162       45362 :     moRotateWithShape.assignIfUsed( rSourceProps.moRotateWithShape );
     163       45362 : }
     164             : 
     165             : 
     166             : 
     167        6243 : void PatternFillProperties::assignUsed( const PatternFillProperties& rSourceProps )
     168             : {
     169        6243 :     maPattFgColor.assignIfUsed( rSourceProps.maPattFgColor );
     170        6243 :     maPattBgColor.assignIfUsed( rSourceProps.maPattBgColor );
     171        6243 :     moPattPreset.assignIfUsed( rSourceProps.moPattPreset );
     172        6243 : }
     173             : 
     174             : 
     175             : 
     176        6243 : void BlipFillProperties::assignUsed( const BlipFillProperties& rSourceProps )
     177             : {
     178        6243 :     if( rSourceProps.mxGraphic.is() )
     179          23 :         mxGraphic = rSourceProps.mxGraphic;
     180        6243 :     moBitmapMode.assignIfUsed( rSourceProps.moBitmapMode );
     181        6243 :     moFillRect.assignIfUsed( rSourceProps.moFillRect );
     182        6243 :     moTileOffsetX.assignIfUsed( rSourceProps.moTileOffsetX );
     183        6243 :     moTileOffsetY.assignIfUsed( rSourceProps.moTileOffsetY );
     184        6243 :     moTileScaleX.assignIfUsed( rSourceProps.moTileScaleX );
     185        6243 :     moTileScaleY.assignIfUsed( rSourceProps.moTileScaleY );
     186        6243 :     moTileAlign.assignIfUsed( rSourceProps.moTileAlign );
     187        6243 :     moTileFlip.assignIfUsed( rSourceProps.moTileFlip );
     188        6243 :     moRotateWithShape.assignIfUsed( rSourceProps.moRotateWithShape );
     189        6243 :     moColorEffect.assignIfUsed( rSourceProps.moColorEffect );
     190        6243 :     moBrightness.assignIfUsed( rSourceProps.moBrightness );
     191        6243 :     moContrast.assignIfUsed( rSourceProps.moContrast );
     192        6243 :     maColorChangeFrom.assignIfUsed( rSourceProps.maColorChangeFrom );
     193        6243 :     maColorChangeTo.assignIfUsed( rSourceProps.maColorChangeTo );
     194        6243 :     maDuotoneColors[0].assignIfUsed( rSourceProps.maDuotoneColors[0] );
     195        6243 :     maDuotoneColors[1].assignIfUsed( rSourceProps.maDuotoneColors[1] );
     196        6243 : }
     197             : 
     198             : 
     199             : 
     200        6243 : void FillProperties::assignUsed( const FillProperties& rSourceProps )
     201             : {
     202        6243 :     moFillType.assignIfUsed( rSourceProps.moFillType );
     203        6243 :     maFillColor.assignIfUsed( rSourceProps.maFillColor );
     204        6243 :     maGradientProps.assignUsed( rSourceProps.maGradientProps );
     205        6243 :     maPatternProps.assignUsed( rSourceProps.maPatternProps );
     206        6243 :     maBlipProps.assignUsed( rSourceProps.maBlipProps );
     207        6243 : }
     208             : 
     209        3048 : Color FillProperties::getBestSolidColor() const
     210             : {
     211        3048 :     Color aSolidColor;
     212        3048 :     if( moFillType.has() ) switch( moFillType.get() )
     213             :     {
     214             :         case XML_solidFill:
     215        1710 :             aSolidColor = maFillColor;
     216        1710 :         break;
     217             :         case XML_gradFill:
     218           0 :             if( !maGradientProps.maGradientStops.empty() )
     219           0 :                 aSolidColor = maGradientProps.maGradientStops.begin()->second;
     220           0 :         break;
     221             :         case XML_pattFill:
     222           0 :             aSolidColor = maPatternProps.maPattBgColor.isUsed() ? maPatternProps.maPattBgColor : maPatternProps.maPattFgColor;
     223           0 :         break;
     224             :     }
     225        3048 :     return aSolidColor;
     226             : }
     227             : 
     228             : /// Maps the hatch token to drawing::Hatch.
     229          96 : static drawing::Hatch createHatch( sal_Int32 nHatchToken, sal_Int32 nColor )
     230             : {
     231          96 :     drawing::Hatch aHatch;
     232          96 :     aHatch.Color = nColor;
     233             : 
     234             :     // best-effort mapping; we do not support all the styles in core
     235          96 :     switch ( nHatchToken )
     236             :     {
     237           2 :         case XML_pct5:       aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 250; aHatch.Angle = 450;  break;
     238           1 :         case XML_pct10:      aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 200; aHatch.Angle = 450;  break;
     239           1 :         case XML_pct20:      aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 450;  break;
     240           1 :         case XML_pct25:      aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 200; aHatch.Angle = 450;  break;
     241           3 :         case XML_pct30:      aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 175; aHatch.Angle = 450;  break;
     242           1 :         case XML_pct40:      aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 150; aHatch.Angle = 450;  break;
     243           1 :         case XML_pct50:      aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 125; aHatch.Angle = 450;  break;
     244           1 :         case XML_pct60:      aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 150; aHatch.Angle = 450;  break;
     245           1 :         case XML_pct70:      aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 125; aHatch.Angle = 450;  break;
     246           1 :         case XML_pct75:      aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 100; aHatch.Angle = 450;  break;
     247           1 :         case XML_pct80:      aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 75;  aHatch.Angle = 450;  break;
     248           1 :         case XML_pct90:      aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 50;  aHatch.Angle = 450;  break;
     249           3 :         case XML_horz:       aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 0;    break;
     250           3 :         case XML_vert:       aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 900;  break;
     251           4 :         case XML_ltHorz:     aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 0;    break;
     252           9 :         case XML_ltVert:     aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 900;  break;
     253           1 :         case XML_dkHorz:     aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 25;  aHatch.Angle = 0;    break;
     254           4 :         case XML_dkVert:     aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 25;  aHatch.Angle = 900;  break;
     255           1 :         case XML_narHorz:    aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 0;    break;
     256           2 :         case XML_narVert:    aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 900;  break;
     257           1 :         case XML_dashHorz:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 0;    break;
     258           1 :         case XML_dashVert:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 900;  break;
     259           0 :         case XML_cross:      aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 0;    break;
     260           0 :         case XML_dnDiag:     aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 1350; break;
     261           0 :         case XML_upDiag:     aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 450;  break;
     262           4 :         case XML_ltDnDiag:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 1350; break;
     263           4 :         case XML_ltUpDiag:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 450;  break;
     264           1 :         case XML_dkDnDiag:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 1350; break;
     265           1 :         case XML_dkUpDiag:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50;  aHatch.Angle = 450;  break;
     266           4 :         case XML_wdDnDiag:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 1350; break;
     267           4 :         case XML_wdUpDiag:   aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 450;  break;
     268           1 :         case XML_dashDnDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 1350; break;
     269           1 :         case XML_dashUpDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 450;  break;
     270           0 :         case XML_diagCross:  aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 450;  break;
     271           4 :         case XML_smCheck:    aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 50;  aHatch.Angle = 450;  break;
     272           1 :         case XML_lgCheck:    aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 450;  break;
     273           4 :         case XML_smGrid:     aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 50;  aHatch.Angle = 0;    break;
     274           4 :         case XML_lgGrid:     aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 0;    break;
     275           1 :         case XML_dotGrid:    aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 400; aHatch.Angle = 0;    break;
     276           1 :         case XML_smConfetti: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 200; aHatch.Angle = 600;  break;
     277           1 :         case XML_lgConfetti: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 600;  break;
     278           1 :         case XML_horzBrick:  aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 300; aHatch.Angle = 0;    break;
     279           1 :         case XML_diagBrick:  aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 300; aHatch.Angle = 450;  break;
     280           1 :         case XML_solidDmnd:  aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 450;  break;
     281           4 :         case XML_openDmnd:   aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 450;  break;
     282           1 :         case XML_dotDmnd:    aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 300; aHatch.Angle = 450;  break;
     283           1 :         case XML_plaid:      aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 200; aHatch.Angle = 900;  break;
     284           1 :         case XML_sphere:     aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 100; aHatch.Angle = 0;    break;
     285           1 :         case XML_weave:      aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 150; aHatch.Angle = 450;  break;
     286           1 :         case XML_divot:      aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 400; aHatch.Angle = 450;  break;
     287           1 :         case XML_shingle:    aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 200; aHatch.Angle = 1350; break;
     288           1 :         case XML_wave:       aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 0;    break;
     289           1 :         case XML_trellis:    aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 75;  aHatch.Angle = 450;  break;
     290           1 :         case XML_zigZag:     aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 75;  aHatch.Angle = 0;    break;
     291             :     }
     292             : 
     293          96 :     return aHatch;
     294             : }
     295             : 
     296        2990 : void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap,
     297             :         const GraphicHelper& rGraphicHelper, sal_Int32 nShapeRotation, sal_Int32 nPhClr,
     298             :         bool bFlipH, bool bFlipV ) const
     299             : {
     300        2990 :     if( moFillType.has() )
     301             :     {
     302        2935 :         FillStyle eFillStyle = FillStyle_NONE;
     303             :         OSL_ASSERT((moFillType.get() & sal_Int32(0xFFFF0000))==0);
     304        2935 :         switch( moFillType.get() )
     305             :         {
     306             :             case XML_noFill:
     307        1215 :                 eFillStyle = FillStyle_NONE;
     308        1215 :             break;
     309             : 
     310             :             case XML_solidFill:
     311        1484 :                 if( maFillColor.isUsed() )
     312             :                 {
     313        1484 :                     rPropMap.setProperty( SHAPEPROP_FillColor, maFillColor.getColor( rGraphicHelper, nPhClr ) );
     314        1484 :                     if( maFillColor.hasTransparency() )
     315          97 :                         rPropMap.setProperty( SHAPEPROP_FillTransparency, maFillColor.getTransparency() );
     316        1484 :                     eFillStyle = FillStyle_SOLID;
     317             :                 }
     318        1484 :             break;
     319             : 
     320             :             case XML_gradFill:
     321             :                 // do not create gradient struct if property is not supported...
     322         116 :                 if( rPropMap.supportsProperty( SHAPEPROP_FillGradient ) )
     323             :                 {
     324         116 :                     sal_Int32 nEndTrans     = 0;
     325         116 :                     sal_Int32 nStartTrans   = 0;
     326         116 :                     awt::Gradient aGradient;
     327         116 :                     aGradient.Angle = 900;
     328         116 :                     aGradient.StartIntensity = 100;
     329         116 :                     aGradient.EndIntensity = 100;
     330             : 
     331         116 :                     size_t nColorCount = maGradientProps.maGradientStops.size();
     332         116 :                     if( nColorCount > 1 )
     333             :                     {
     334         116 :                         aGradient.StartColor = maGradientProps.maGradientStops.begin()->second.getColor( rGraphicHelper, nPhClr );
     335         116 :                         aGradient.EndColor = maGradientProps.maGradientStops.rbegin()->second.getColor( rGraphicHelper, nPhClr );
     336         116 :                         if( maGradientProps.maGradientStops.rbegin()->second.hasTransparency() )
     337           1 :                             nEndTrans = maGradientProps.maGradientStops.rbegin()->second.getTransparency()*255/100;
     338         116 :                         if( maGradientProps.maGradientStops.begin()->second.hasTransparency() )
     339          18 :                             nStartTrans = maGradientProps.maGradientStops.begin()->second.getTransparency()*255/100;
     340             :                     }
     341             : 
     342             :                     // Adjust for flips
     343         116 :                     if ( bFlipH )
     344           1 :                         nShapeRotation = 180*60000 - nShapeRotation;
     345         116 :                     if ( bFlipV )
     346           0 :                         nShapeRotation = -nShapeRotation;
     347             : 
     348             :                     // "rotate with shape" not set, or set to false -> do not rotate
     349         116 :                     if ( !maGradientProps.moRotateWithShape.get( false ) )
     350          90 :                         nShapeRotation = 0;
     351             : 
     352         116 :                     sal_Int32 nDmlAngle = 0;
     353         116 :                     if( maGradientProps.moGradientPath.has() )
     354             :                     {
     355           0 :                         aGradient.Style = (maGradientProps.moGradientPath.get() == XML_circle) ? awt::GradientStyle_ELLIPTICAL : awt::GradientStyle_RECT;
     356             :                         // position of gradient center (limited to [30%;70%], otherwise gradient is too hidden)
     357           0 :                         IntegerRectangle2D aFillToRect = maGradientProps.moFillToRect.get( IntegerRectangle2D( 0, 0, MAX_PERCENT, MAX_PERCENT ) );
     358           0 :                         sal_Int32 nCenterX = (MAX_PERCENT + aFillToRect.X1 - aFillToRect.X2) / 2;
     359           0 :                         aGradient.XOffset = getLimitedValue< sal_Int16, sal_Int32 >( nCenterX / PER_PERCENT, 30, 70 );
     360           0 :                         sal_Int32 nCenterY = (MAX_PERCENT + aFillToRect.Y1 - aFillToRect.Y2) / 2;
     361           0 :                         aGradient.YOffset = getLimitedValue< sal_Int16, sal_Int32 >( nCenterY / PER_PERCENT, 30, 70 );
     362           0 :                         ::std::swap( aGradient.StartColor, aGradient.EndColor );
     363           0 :                         ::std::swap( nStartTrans, nEndTrans );
     364           0 :                         nDmlAngle = nShapeRotation;
     365             :                     }
     366             :                     else
     367             :                     {
     368             :                         /*  Try to detect a VML axial gradient. This type of
     369             :                             gradient is simulated by a 3-point linear gradient.
     370             :                             Even if it's a multi-color linear gradient, its probably better to assume
     371             :                             axial gradient, when there are 3 or more points.
     372             :                          */
     373         116 :                         bool bAxial = (nColorCount >= 3);
     374         116 :                         aGradient.Style = bAxial ? awt::GradientStyle_AXIAL : awt::GradientStyle_LINEAR;
     375         116 :                         nDmlAngle = maGradientProps.moShadeAngle.get( 0 ) - nShapeRotation;
     376             :                         // convert DrawingML angle (in 1/60000 degrees) to API angle (in 1/10 degrees)
     377         116 :                         aGradient.Angle = static_cast< sal_Int16 >( (4500 - (nDmlAngle / (PER_DEGREE / 10))) % 3600 );
     378         116 :                         if( bAxial )
     379             :                         {
     380          87 :                             GradientFillProperties::GradientStopMap::const_iterator aIt = maGradientProps.maGradientStops.begin();
     381             :                             // Try to find the axial median
     382         174 :                             for(size_t i=0;i<nColorCount;i+=3)
     383          87 :                                 ++aIt;
     384             :                             // API StartColor is inner color in axial gradient
     385             :                             // aIt->second.hasColor() kind would be better than Color != API_RGB_WHITE
     386         225 :                             if( aGradient.StartColor == aGradient.EndColor &&
     387          69 :                                 ( !aIt->second.hasTransparency() || aIt->second.getColor( rGraphicHelper, nPhClr ) != API_RGB_WHITE ) )
     388             :                             {
     389          69 :                                 aGradient.StartColor = aIt->second.getColor( rGraphicHelper, nPhClr );
     390             :                             }
     391             : 
     392          87 :                             if( nStartTrans == nEndTrans && aIt->second.hasTransparency() )
     393           3 :                                 nStartTrans = aIt->second.getTransparency()*255/100;
     394             :                         }
     395             :                     }
     396             : 
     397             :                     // push gradient or named gradient to property map
     398         116 :                     if( rPropMap.setProperty( SHAPEPROP_FillGradient, aGradient ) )
     399         116 :                         eFillStyle = FillStyle_GRADIENT;
     400             : 
     401             :                     // push gradient transparency to property map
     402         116 :                     if( nStartTrans != 0 || nEndTrans != 0 )
     403             :                     {
     404          22 :                         awt::Gradient aGrad(aGradient);
     405          22 :                         uno::Any aVal;
     406          22 :                         aGrad.EndColor = (sal_Int32)( nEndTrans | nEndTrans << 8 | nEndTrans << 16 );
     407          22 :                         aGrad.StartColor = (sal_Int32)( nStartTrans | nStartTrans << 8 | nStartTrans << 16 );
     408          22 :                         aVal <<= aGrad;
     409          22 :                         rPropMap.setProperty( SHAPEPROP_GradientTransparency, aGrad );
     410             :                     }
     411             : 
     412             :                 }
     413         116 :             break;
     414             : 
     415             :             case XML_blipFill:
     416             :                 // do not start complex graphic transformation if property is not supported...
     417          24 :                 if( maBlipProps.mxGraphic.is() && rPropMap.supportsProperty( SHAPEPROP_FillBitmapUrl ) )
     418             :                 {
     419          24 :                     Reference< XGraphic > xGraphic = lclCheckAndApplyDuotoneTransform( maBlipProps, maBlipProps.mxGraphic, rGraphicHelper, nPhClr );
     420             :                     // TODO: "rotate with shape" is not possible with our current core
     421             : 
     422          48 :                     OUString aGraphicUrl = rGraphicHelper.createGraphicObject( xGraphic );
     423             :                     // push bitmap or named bitmap to property map
     424          24 :                     if( !aGraphicUrl.isEmpty() && rPropMap.supportsProperty( SHAPEPROP_FillBitmapNameFromUrl ) && rPropMap.setProperty( SHAPEPROP_FillBitmapNameFromUrl, aGraphicUrl ) )
     425          22 :                         eFillStyle = FillStyle_BITMAP;
     426           2 :                     else if( !aGraphicUrl.isEmpty() && rPropMap.setProperty( SHAPEPROP_FillBitmapUrl, aGraphicUrl ) )
     427           2 :                         eFillStyle = FillStyle_BITMAP;
     428             : 
     429             :                     // set other bitmap properties, if bitmap has been inserted into the map
     430          24 :                     if( eFillStyle == FillStyle_BITMAP )
     431             :                     {
     432             :                         // bitmap mode (single, repeat, stretch)
     433          24 :                         BitmapMode eBitmapMode = lclGetBitmapMode( maBlipProps.moBitmapMode.get( XML_TOKEN_INVALID ) );
     434          24 :                         rPropMap.setProperty( SHAPEPROP_FillBitmapMode, eBitmapMode );
     435             : 
     436             :                         // additional settings for repeated bitmap
     437          24 :                         if( eBitmapMode == BitmapMode_REPEAT )
     438             :                         {
     439             :                             // anchor position inside bitmap
     440           0 :                             RectanglePoint eRectPoint = lclGetRectanglePoint( maBlipProps.moTileAlign.get( XML_tl ) );
     441           0 :                             rPropMap.setProperty( SHAPEPROP_FillBitmapRectanglePoint, eRectPoint );
     442             : 
     443           0 :                             awt::Size aOriginalSize = lclGetOriginalSize( rGraphicHelper, maBlipProps.mxGraphic );
     444           0 :                             if( (aOriginalSize.Width > 0) && (aOriginalSize.Height > 0) )
     445             :                             {
     446             :                                 // size of one bitmap tile (given as 1/1000 percent of bitmap size), convert to 1/100 mm
     447           0 :                                 double fScaleX = maBlipProps.moTileScaleX.get( MAX_PERCENT ) / static_cast< double >( MAX_PERCENT );
     448           0 :                                 sal_Int32 nFillBmpSizeX = getLimitedValue< sal_Int32, double >( aOriginalSize.Width * fScaleX, 1, SAL_MAX_INT32 );
     449           0 :                                 rPropMap.setProperty( SHAPEPROP_FillBitmapSizeX, nFillBmpSizeX );
     450           0 :                                 double fScaleY = maBlipProps.moTileScaleY.get( MAX_PERCENT ) / static_cast< double >( MAX_PERCENT );
     451           0 :                                 sal_Int32 nFillBmpSizeY = getLimitedValue< sal_Int32, double >( aOriginalSize.Height * fScaleY, 1, SAL_MAX_INT32 );
     452           0 :                                 rPropMap.setProperty( SHAPEPROP_FillBitmapSizeY, nFillBmpSizeY );
     453             : 
     454             :                                 // offset of the first bitmap tile (given as EMUs), convert to percent
     455           0 :                                 sal_Int16 nTileOffsetX = getDoubleIntervalValue< sal_Int16 >( maBlipProps.moTileOffsetX.get( 0 ) / 3.6 / aOriginalSize.Width, 0, 100 );
     456           0 :                                 rPropMap.setProperty( SHAPEPROP_FillBitmapOffsetX, nTileOffsetX );
     457           0 :                                 sal_Int16 nTileOffsetY = getDoubleIntervalValue< sal_Int16 >( maBlipProps.moTileOffsetY.get( 0 ) / 3.6 / aOriginalSize.Height, 0, 100 );
     458           0 :                                 rPropMap.setProperty( SHAPEPROP_FillBitmapOffsetY, nTileOffsetY );
     459             :                             }
     460             :                         }
     461          24 :                         else if ( eBitmapMode == BitmapMode_STRETCH && maBlipProps.moFillRect.has() )
     462             :                         {
     463          24 :                             geometry::IntegerRectangle2D aFillRect( maBlipProps.moFillRect.get() );
     464          24 :                             awt::Size aOriginalSize( rGraphicHelper.getOriginalSize( xGraphic ) );
     465          24 :                             if ( aOriginalSize.Width && aOriginalSize.Height )
     466             :                             {
     467          24 :                                 text::GraphicCrop aGraphCrop( 0, 0, 0, 0 );
     468          24 :                                 if ( aFillRect.X1 )
     469           6 :                                     aGraphCrop.Left = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * aFillRect.X1 ) / 100000 );
     470          24 :                                 if ( aFillRect.Y1 )
     471          15 :                                     aGraphCrop.Top = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * aFillRect.Y1 ) / 100000 );
     472          24 :                                 if ( aFillRect.X2 )
     473           6 :                                     aGraphCrop.Right = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * aFillRect.X2 ) / 100000 );
     474          24 :                                 if ( aFillRect.Y2 )
     475          15 :                                     aGraphCrop.Bottom = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * aFillRect.Y2 ) / 100000 );
     476          24 :                                 rPropMap.setProperty(PROP_GraphicCrop, aGraphCrop);
     477             :                             }
     478             :                         }
     479          24 :                     }
     480             :                 }
     481          24 :             break;
     482             : 
     483             :             case XML_pattFill:
     484             :             {
     485          96 :                 if( rPropMap.supportsProperty( SHAPEPROP_FillHatch ) )
     486             :                 {
     487          96 :                     Color aColor( maPatternProps.maPattFgColor );
     488          96 :                     if( aColor.isUsed() && maPatternProps.moPattPreset.has() )
     489             :                     {
     490             :                         // we do not support hatches that have background
     491             :                         // color too, so all this is some best-effort approach
     492          96 :                         eFillStyle = FillStyle_HATCH;
     493          96 :                         rPropMap.setProperty( SHAPEPROP_FillHatch, createHatch( maPatternProps.moPattPreset.get(), aColor.getColor( rGraphicHelper, nPhClr ) ) );
     494             :                     }
     495           0 :                     else if ( maPatternProps.maPattBgColor.isUsed() )
     496             :                     {
     497           0 :                         aColor = maPatternProps.maPattBgColor;
     498           0 :                         rPropMap.setProperty( SHAPEPROP_FillColor, aColor.getColor( rGraphicHelper, nPhClr ) );
     499           0 :                         if( aColor.hasTransparency() )
     500           0 :                             rPropMap.setProperty( SHAPEPROP_FillTransparency, aColor.getTransparency() );
     501           0 :                         eFillStyle = FillStyle_SOLID;
     502          96 :                     }
     503             :                 }
     504             :             }
     505          96 :             break;
     506             : 
     507             :             case XML_grpFill:
     508             :                 // todo
     509           0 :                 eFillStyle = FillStyle_NONE;
     510           0 :             break;
     511             :         }
     512             : 
     513             :         // set final fill style property
     514        2935 :         rPropMap.setProperty( SHAPEPROP_FillStyle, eFillStyle );
     515             :     }
     516        2990 : }
     517             : 
     518             : 
     519             : 
     520         179 : void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelper& rGraphicHelper, sal_Int32 nPhClr ) const
     521             : {
     522         179 :     if( maBlipProps.mxGraphic.is() )
     523             :     {
     524             :         // created transformed graphic
     525         163 :         Reference< XGraphic > xGraphic = lclCheckAndApplyDuotoneTransform( maBlipProps, maBlipProps.mxGraphic, rGraphicHelper, nPhClr );
     526         163 :         xGraphic = lclCheckAndApplyChangeColorTransform( maBlipProps, xGraphic, rGraphicHelper, nPhClr );
     527             : 
     528         163 :         rPropMap.setProperty(PROP_Graphic, xGraphic);
     529             : 
     530             :         // do we still need to set GraphicURL as well? (TODO)
     531         326 :         OUString aGraphicUrl = rGraphicHelper.createGraphicObject( xGraphic );
     532         163 :         if( !aGraphicUrl.isEmpty() )
     533         163 :             rPropMap.setProperty(PROP_GraphicURL, aGraphicUrl);
     534             : 
     535             :         // cropping
     536         163 :         if ( maBlipProps.moClipRect.has() )
     537             :         {
     538          64 :             geometry::IntegerRectangle2D oClipRect( maBlipProps.moClipRect.get() );
     539          64 :             awt::Size aOriginalSize( rGraphicHelper.getOriginalSize( xGraphic ) );
     540          64 :             if ( aOriginalSize.Width && aOriginalSize.Height )
     541             :             {
     542          64 :                 text::GraphicCrop aGraphCrop( 0, 0, 0, 0 );
     543          64 :                 if ( oClipRect.X1 )
     544          10 :                     aGraphCrop.Left = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X1 ) / 100000 );
     545          64 :                 if ( oClipRect.Y1 )
     546          10 :                     aGraphCrop.Top = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y1 ) / 100000 );
     547          64 :                 if ( oClipRect.X2 )
     548           9 :                     aGraphCrop.Right = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X2 ) / 100000 );
     549          64 :                 if ( oClipRect.Y2 )
     550           9 :                     aGraphCrop.Bottom = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y2 ) / 100000 );
     551          64 :                 rPropMap.setProperty(PROP_GraphicCrop, aGraphCrop);
     552             :             }
     553         163 :         }
     554             :     }
     555             : 
     556             :     // color effect
     557         179 :     ColorMode eColorMode = ColorMode_STANDARD;
     558         179 :     switch( maBlipProps.moColorEffect.get( XML_TOKEN_INVALID ) )
     559             :     {
     560           0 :         case XML_biLevel:   eColorMode = ColorMode_MONO;    break;
     561           0 :         case XML_grayscl:   eColorMode = ColorMode_GREYS;   break;
     562             :     }
     563         179 :     rPropMap.setProperty(PROP_GraphicColorMode, eColorMode);
     564             : 
     565             :     // brightness and contrast
     566         179 :     sal_Int16 nBrightness = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moBrightness.get( 0 ) / PER_PERCENT, -100, 100 );
     567         179 :     if( nBrightness != 0 )
     568           1 :         rPropMap.setProperty(PROP_AdjustLuminance, nBrightness);
     569         179 :     sal_Int16 nContrast = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moContrast.get( 0 ) / PER_PERCENT, -100, 100 );
     570         179 :     if( nContrast != 0 )
     571           1 :         rPropMap.setProperty(PROP_AdjustContrast, nContrast);
     572             : 
     573             :     // Media content
     574         179 :     if( !maAudio.msEmbed.isEmpty() )
     575           0 :         rPropMap.setProperty(PROP_MediaURL, maAudio.msEmbed);
     576         179 : }
     577             : 
     578             : 
     579             : 
     580             : } // namespace drawingml
     581         177 : } // namespace oox
     582             : 
     583             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10