1*ca5ec200SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ca5ec200SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ca5ec200SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ca5ec200SAndrew Rist * distributed with this work for additional information 6*ca5ec200SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ca5ec200SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ca5ec200SAndrew Rist * "License"); you may not use this file except in compliance 9*ca5ec200SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ca5ec200SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ca5ec200SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ca5ec200SAndrew Rist * software distributed under the License is distributed on an 15*ca5ec200SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ca5ec200SAndrew Rist * KIND, either express or implied. See the License for the 17*ca5ec200SAndrew Rist * specific language governing permissions and limitations 18*ca5ec200SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ca5ec200SAndrew Rist *************************************************************/ 21*ca5ec200SAndrew Rist 22*ca5ec200SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "oox/drawingml/fillproperties.hxx" 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 27cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 28cdf0e10cSrcweir #include <com/sun/star/awt/Gradient.hpp> 29cdf0e10cSrcweir #include <com/sun/star/text/GraphicCrop.hpp> 30cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp> 31cdf0e10cSrcweir #include <com/sun/star/drawing/BitmapMode.hpp> 32cdf0e10cSrcweir #include <com/sun/star/drawing/ColorMode.hpp> 33cdf0e10cSrcweir #include <com/sun/star/drawing/FillStyle.hpp> 34cdf0e10cSrcweir #include <com/sun/star/drawing/RectanglePoint.hpp> 35cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicTransformer.hpp> 36cdf0e10cSrcweir #include "oox/helper/graphichelper.hxx" 37cdf0e10cSrcweir #include "oox/drawingml/drawingmltypes.hxx" 38cdf0e10cSrcweir #include "oox/drawingml/shapepropertymap.hxx" 39cdf0e10cSrcweir #include "oox/token/tokens.hxx" 40cdf0e10cSrcweir 41cdf0e10cSrcweir using namespace ::com::sun::star; 42cdf0e10cSrcweir using namespace ::com::sun::star::drawing; 43cdf0e10cSrcweir using namespace ::com::sun::star::graphic; 44cdf0e10cSrcweir 45cdf0e10cSrcweir using ::rtl::OUString; 46cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 47cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 48cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 49cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 50cdf0e10cSrcweir using ::com::sun::star::geometry::IntegerRectangle2D; 51cdf0e10cSrcweir 52cdf0e10cSrcweir namespace oox { 53cdf0e10cSrcweir namespace drawingml { 54cdf0e10cSrcweir 55cdf0e10cSrcweir // ============================================================================ 56cdf0e10cSrcweir 57cdf0e10cSrcweir namespace { 58cdf0e10cSrcweir 59cdf0e10cSrcweir BitmapMode lclGetBitmapMode( sal_Int32 nToken ) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir switch( nToken ) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir case XML_tile: return BitmapMode_REPEAT; 64cdf0e10cSrcweir case XML_stretch: return BitmapMode_STRETCH; 65cdf0e10cSrcweir } 66cdf0e10cSrcweir return BitmapMode_NO_REPEAT; 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir RectanglePoint lclGetRectanglePoint( sal_Int32 nToken ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir switch( nToken ) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir case XML_tl: return RectanglePoint_LEFT_TOP; 74cdf0e10cSrcweir case XML_t: return RectanglePoint_MIDDLE_TOP; 75cdf0e10cSrcweir case XML_tr: return RectanglePoint_RIGHT_TOP; 76cdf0e10cSrcweir case XML_l: return RectanglePoint_LEFT_MIDDLE; 77cdf0e10cSrcweir case XML_ctr: return RectanglePoint_MIDDLE_MIDDLE; 78cdf0e10cSrcweir case XML_r: return RectanglePoint_RIGHT_MIDDLE; 79cdf0e10cSrcweir case XML_bl: return RectanglePoint_LEFT_BOTTOM; 80cdf0e10cSrcweir case XML_b: return RectanglePoint_MIDDLE_BOTTOM; 81cdf0e10cSrcweir case XML_br: return RectanglePoint_RIGHT_BOTTOM; 82cdf0e10cSrcweir } 83cdf0e10cSrcweir return RectanglePoint_LEFT_TOP; 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir const awt::Size lclGetOriginalSize( const GraphicHelper& rGraphicHelper, const Reference< XGraphic >& rxGraphic ) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir awt::Size aSizeHmm( 0, 0 ); 89cdf0e10cSrcweir try 90cdf0e10cSrcweir { 91cdf0e10cSrcweir Reference< beans::XPropertySet > xGraphicPropertySet( rxGraphic, UNO_QUERY_THROW ); 92cdf0e10cSrcweir if( xGraphicPropertySet->getPropertyValue( CREATE_OUSTRING( "Size100thMM" ) ) >>= aSizeHmm ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir if( !aSizeHmm.Width && !aSizeHmm.Height ) 95cdf0e10cSrcweir { // MAPMODE_PIXEL USED :-( 96cdf0e10cSrcweir awt::Size aSourceSizePixel( 0, 0 ); 97cdf0e10cSrcweir if( xGraphicPropertySet->getPropertyValue( CREATE_OUSTRING( "SizePixel" ) ) >>= aSourceSizePixel ) 98cdf0e10cSrcweir aSizeHmm = rGraphicHelper.convertScreenPixelToHmm( aSourceSizePixel ); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir } 101cdf0e10cSrcweir } 102cdf0e10cSrcweir catch( Exception& ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir } 105cdf0e10cSrcweir return aSizeHmm; 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir } // namespace 109cdf0e10cSrcweir 110cdf0e10cSrcweir // ============================================================================ 111cdf0e10cSrcweir 112cdf0e10cSrcweir void GradientFillProperties::assignUsed( const GradientFillProperties& rSourceProps ) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir if( !rSourceProps.maGradientStops.empty() ) 115cdf0e10cSrcweir maGradientStops = rSourceProps.maGradientStops; 116cdf0e10cSrcweir moFillToRect.assignIfUsed( rSourceProps.moFillToRect ); 117cdf0e10cSrcweir moTileRect.assignIfUsed( rSourceProps.moTileRect ); 118cdf0e10cSrcweir moGradientPath.assignIfUsed( rSourceProps.moGradientPath ); 119cdf0e10cSrcweir moShadeAngle.assignIfUsed( rSourceProps.moShadeAngle ); 120cdf0e10cSrcweir moShadeFlip.assignIfUsed( rSourceProps.moShadeFlip ); 121cdf0e10cSrcweir moShadeScaled.assignIfUsed( rSourceProps.moShadeScaled ); 122cdf0e10cSrcweir moRotateWithShape.assignIfUsed( rSourceProps.moRotateWithShape ); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir // ============================================================================ 126cdf0e10cSrcweir 127cdf0e10cSrcweir void PatternFillProperties::assignUsed( const PatternFillProperties& rSourceProps ) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir maPattFgColor.assignIfUsed( rSourceProps.maPattFgColor ); 130cdf0e10cSrcweir maPattBgColor.assignIfUsed( rSourceProps.maPattBgColor ); 131cdf0e10cSrcweir moPattPreset.assignIfUsed( rSourceProps.moPattPreset ); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir // ============================================================================ 135cdf0e10cSrcweir 136cdf0e10cSrcweir void BlipFillProperties::assignUsed( const BlipFillProperties& rSourceProps ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir if( rSourceProps.mxGraphic.is() ) 139cdf0e10cSrcweir mxGraphic = rSourceProps.mxGraphic; 140cdf0e10cSrcweir moBitmapMode.assignIfUsed( rSourceProps.moBitmapMode ); 141cdf0e10cSrcweir moFillRect.assignIfUsed( rSourceProps.moFillRect ); 142cdf0e10cSrcweir moTileOffsetX.assignIfUsed( rSourceProps.moTileOffsetX ); 143cdf0e10cSrcweir moTileOffsetY.assignIfUsed( rSourceProps.moTileOffsetY ); 144cdf0e10cSrcweir moTileScaleX.assignIfUsed( rSourceProps.moTileScaleX ); 145cdf0e10cSrcweir moTileScaleY.assignIfUsed( rSourceProps.moTileScaleY ); 146cdf0e10cSrcweir moTileAlign.assignIfUsed( rSourceProps.moTileAlign ); 147cdf0e10cSrcweir moTileFlip.assignIfUsed( rSourceProps.moTileFlip ); 148cdf0e10cSrcweir moRotateWithShape.assignIfUsed( rSourceProps.moRotateWithShape ); 149cdf0e10cSrcweir moColorEffect.assignIfUsed( rSourceProps.moColorEffect ); 150cdf0e10cSrcweir moBrightness.assignIfUsed( rSourceProps.moBrightness ); 151cdf0e10cSrcweir moContrast.assignIfUsed( rSourceProps.moContrast ); 152cdf0e10cSrcweir maColorChangeFrom.assignIfUsed( rSourceProps.maColorChangeFrom ); 153cdf0e10cSrcweir maColorChangeTo.assignIfUsed( rSourceProps.maColorChangeTo ); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir // ============================================================================ 157cdf0e10cSrcweir 158cdf0e10cSrcweir void FillProperties::assignUsed( const FillProperties& rSourceProps ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir moFillType.assignIfUsed( rSourceProps.moFillType ); 161cdf0e10cSrcweir maFillColor.assignIfUsed( rSourceProps.maFillColor ); 162cdf0e10cSrcweir maGradientProps.assignUsed( rSourceProps.maGradientProps ); 163cdf0e10cSrcweir maPatternProps.assignUsed( rSourceProps.maPatternProps ); 164cdf0e10cSrcweir maBlipProps.assignUsed( rSourceProps.maBlipProps ); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir Color FillProperties::getBestSolidColor() const 168cdf0e10cSrcweir { 169cdf0e10cSrcweir Color aSolidColor; 170cdf0e10cSrcweir if( moFillType.has() ) switch( moFillType.get() ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir case XML_solidFill: 173cdf0e10cSrcweir aSolidColor = maFillColor; 174cdf0e10cSrcweir break; 175cdf0e10cSrcweir case XML_gradFill: 176cdf0e10cSrcweir if( !maGradientProps.maGradientStops.empty() ) 177cdf0e10cSrcweir aSolidColor = maGradientProps.maGradientStops.begin()->second; 178cdf0e10cSrcweir break; 179cdf0e10cSrcweir case XML_pattFill: 180cdf0e10cSrcweir aSolidColor = maPatternProps.maPattBgColor.isUsed() ? maPatternProps.maPattBgColor : maPatternProps.maPattFgColor; 181cdf0e10cSrcweir break; 182cdf0e10cSrcweir } 183cdf0e10cSrcweir return aSolidColor; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap, 187cdf0e10cSrcweir const GraphicHelper& rGraphicHelper, sal_Int32 nShapeRotation, sal_Int32 nPhClr ) const 188cdf0e10cSrcweir { 189cdf0e10cSrcweir if( moFillType.has() ) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir FillStyle eFillStyle = FillStyle_NONE; 192cdf0e10cSrcweir switch( moFillType.get() ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir case XML_noFill: 195cdf0e10cSrcweir eFillStyle = FillStyle_NONE; 196cdf0e10cSrcweir break; 197cdf0e10cSrcweir 198cdf0e10cSrcweir case XML_solidFill: 199cdf0e10cSrcweir if( maFillColor.isUsed() ) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir rPropMap.setProperty( SHAPEPROP_FillColor, maFillColor.getColor( rGraphicHelper, nPhClr ) ); 202cdf0e10cSrcweir if( maFillColor.hasTransparency() ) 203cdf0e10cSrcweir rPropMap.setProperty( SHAPEPROP_FillTransparency, maFillColor.getTransparency() ); 204cdf0e10cSrcweir eFillStyle = FillStyle_SOLID; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir break; 207cdf0e10cSrcweir 208cdf0e10cSrcweir case XML_gradFill: 209cdf0e10cSrcweir // do not create gradient struct if property is not supported... 210cdf0e10cSrcweir if( rPropMap.supportsProperty( SHAPEPROP_FillGradient ) ) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir awt::Gradient aGradient; 213cdf0e10cSrcweir aGradient.Angle = 900; 214cdf0e10cSrcweir aGradient.StartIntensity = 100; 215cdf0e10cSrcweir aGradient.EndIntensity = 100; 216cdf0e10cSrcweir 217cdf0e10cSrcweir size_t nColorCount = maGradientProps.maGradientStops.size(); 218cdf0e10cSrcweir if( nColorCount > 1 ) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir aGradient.StartColor = maGradientProps.maGradientStops.begin()->second.getColor( rGraphicHelper, nPhClr ); 221cdf0e10cSrcweir aGradient.EndColor = maGradientProps.maGradientStops.rbegin()->second.getColor( rGraphicHelper, nPhClr ); 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir // "rotate with shape" not set, or set to false -> do not rotate 225cdf0e10cSrcweir if ( !maGradientProps.moRotateWithShape.get( false ) ) 226cdf0e10cSrcweir nShapeRotation = 0; 227cdf0e10cSrcweir 228cdf0e10cSrcweir sal_Int32 nDmlAngle = 0; 229cdf0e10cSrcweir if( maGradientProps.moGradientPath.has() ) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir aGradient.Style = (maGradientProps.moGradientPath.get() == XML_circle) ? awt::GradientStyle_ELLIPTICAL : awt::GradientStyle_RECT; 232cdf0e10cSrcweir // position of gradient center (limited to [30%;70%], otherwise gradient is too hidden) 233cdf0e10cSrcweir IntegerRectangle2D aFillToRect = maGradientProps.moFillToRect.get( IntegerRectangle2D( 0, 0, MAX_PERCENT, MAX_PERCENT ) ); 234cdf0e10cSrcweir sal_Int32 nCenterX = (MAX_PERCENT + aFillToRect.X1 - aFillToRect.X2) / 2; 235cdf0e10cSrcweir aGradient.XOffset = getLimitedValue< sal_Int16, sal_Int32 >( nCenterX / PER_PERCENT, 30, 70 ); 236cdf0e10cSrcweir sal_Int32 nCenterY = (MAX_PERCENT + aFillToRect.Y1 - aFillToRect.Y2) / 2; 237cdf0e10cSrcweir aGradient.YOffset = getLimitedValue< sal_Int16, sal_Int32 >( nCenterY / PER_PERCENT, 30, 70 ); 238cdf0e10cSrcweir ::std::swap( aGradient.StartColor, aGradient.EndColor ); 239cdf0e10cSrcweir nDmlAngle = nShapeRotation; 240cdf0e10cSrcweir } 241cdf0e10cSrcweir else 242cdf0e10cSrcweir { 243cdf0e10cSrcweir /* Try to detect a VML axial gradient. This type of 244cdf0e10cSrcweir gradient is simulated by a 3-point linear gradient 245cdf0e10cSrcweir with equal start and end color. */ 246cdf0e10cSrcweir bool bAxial = (nColorCount == 3) && (aGradient.StartColor == aGradient.EndColor); 247cdf0e10cSrcweir aGradient.Style = bAxial ? awt::GradientStyle_AXIAL : awt::GradientStyle_LINEAR; 248cdf0e10cSrcweir if( bAxial ) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir GradientFillProperties::GradientStopMap::const_iterator aIt = maGradientProps.maGradientStops.begin(); 251cdf0e10cSrcweir // API StartColor is inner color in axial gradient 252cdf0e10cSrcweir aGradient.StartColor = (++aIt)->second.getColor( rGraphicHelper, nPhClr ); 253cdf0e10cSrcweir } 254cdf0e10cSrcweir nDmlAngle = maGradientProps.moShadeAngle.get( 0 ) - nShapeRotation; 255cdf0e10cSrcweir } 256cdf0e10cSrcweir // convert DrawingML angle (in 1/60000 degrees) to API angle (in 1/10 degrees) 257cdf0e10cSrcweir aGradient.Angle = static_cast< sal_Int16 >( (4500 - (nDmlAngle / (PER_DEGREE / 10))) % 3600 ); 258cdf0e10cSrcweir 259cdf0e10cSrcweir // push gradient or named gradient to property map 260cdf0e10cSrcweir if( rPropMap.setProperty( SHAPEPROP_FillGradient, aGradient ) ) 261cdf0e10cSrcweir eFillStyle = FillStyle_GRADIENT; 262cdf0e10cSrcweir } 263cdf0e10cSrcweir break; 264cdf0e10cSrcweir 265cdf0e10cSrcweir case XML_blipFill: 266cdf0e10cSrcweir // do not start complex graphic transformation if property is not supported... 267cdf0e10cSrcweir if( maBlipProps.mxGraphic.is() && rPropMap.supportsProperty( SHAPEPROP_FillBitmapUrl ) ) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir // TODO: "rotate with shape" is not possible with our current core 270cdf0e10cSrcweir 271cdf0e10cSrcweir OUString aGraphicUrl = rGraphicHelper.createGraphicObject( maBlipProps.mxGraphic ); 272cdf0e10cSrcweir // push bitmap or named bitmap to property map 273cdf0e10cSrcweir if( (aGraphicUrl.getLength() > 0) && rPropMap.setProperty( SHAPEPROP_FillBitmapUrl, aGraphicUrl ) ) 274cdf0e10cSrcweir eFillStyle = FillStyle_BITMAP; 275cdf0e10cSrcweir 276cdf0e10cSrcweir // set other bitmap properties, if bitmap has been inserted into the map 277cdf0e10cSrcweir if( eFillStyle == FillStyle_BITMAP ) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir // bitmap mode (single, repeat, stretch) 280cdf0e10cSrcweir BitmapMode eBitmapMode = lclGetBitmapMode( maBlipProps.moBitmapMode.get( XML_TOKEN_INVALID ) ); 281cdf0e10cSrcweir rPropMap.setProperty( SHAPEPROP_FillBitmapMode, eBitmapMode ); 282cdf0e10cSrcweir 283cdf0e10cSrcweir // additional settings for repeated bitmap 284cdf0e10cSrcweir if( eBitmapMode == BitmapMode_REPEAT ) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir // anchor position inside bitmap 287cdf0e10cSrcweir RectanglePoint eRectPoint = lclGetRectanglePoint( maBlipProps.moTileAlign.get( XML_tl ) ); 288cdf0e10cSrcweir rPropMap.setProperty( SHAPEPROP_FillBitmapRectanglePoint, eRectPoint ); 289cdf0e10cSrcweir 290cdf0e10cSrcweir awt::Size aOriginalSize = lclGetOriginalSize( rGraphicHelper, maBlipProps.mxGraphic ); 291cdf0e10cSrcweir if( (aOriginalSize.Width > 0) && (aOriginalSize.Height > 0) ) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir // size of one bitmap tile (given as 1/1000 percent of bitmap size), convert to 1/100 mm 294cdf0e10cSrcweir double fScaleX = maBlipProps.moTileScaleX.get( MAX_PERCENT ) / static_cast< double >( MAX_PERCENT ); 295cdf0e10cSrcweir sal_Int32 nFillBmpSizeX = getLimitedValue< sal_Int32, double >( aOriginalSize.Width * fScaleX, 1, SAL_MAX_INT32 ); 296cdf0e10cSrcweir rPropMap.setProperty( SHAPEPROP_FillBitmapSizeX, nFillBmpSizeX ); 297cdf0e10cSrcweir double fScaleY = maBlipProps.moTileScaleY.get( MAX_PERCENT ) / static_cast< double >( MAX_PERCENT ); 298cdf0e10cSrcweir sal_Int32 nFillBmpSizeY = getLimitedValue< sal_Int32, double >( aOriginalSize.Height * fScaleY, 1, SAL_MAX_INT32 ); 299cdf0e10cSrcweir rPropMap.setProperty( SHAPEPROP_FillBitmapSizeY, nFillBmpSizeY ); 300cdf0e10cSrcweir 301cdf0e10cSrcweir // offset of the first bitmap tile (given as EMUs), convert to percent 302cdf0e10cSrcweir sal_Int16 nTileOffsetX = getDoubleIntervalValue< sal_Int16 >( maBlipProps.moTileOffsetX.get( 0 ) / 3.6 / aOriginalSize.Width, 0, 100 ); 303cdf0e10cSrcweir rPropMap.setProperty( SHAPEPROP_FillBitmapOffsetX, nTileOffsetX ); 304cdf0e10cSrcweir sal_Int16 nTileOffsetY = getDoubleIntervalValue< sal_Int16 >( maBlipProps.moTileOffsetY.get( 0 ) / 3.6 / aOriginalSize.Height, 0, 100 ); 305cdf0e10cSrcweir rPropMap.setProperty( SHAPEPROP_FillBitmapOffsetY, nTileOffsetY ); 306cdf0e10cSrcweir } 307cdf0e10cSrcweir } 308cdf0e10cSrcweir } 309cdf0e10cSrcweir } 310cdf0e10cSrcweir break; 311cdf0e10cSrcweir 312cdf0e10cSrcweir case XML_pattFill: 313cdf0e10cSrcweir { 314cdf0e10cSrcweir // todo 315cdf0e10cSrcweir Color aColor = getBestSolidColor(); 316cdf0e10cSrcweir if( aColor.isUsed() ) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir rPropMap.setProperty( SHAPEPROP_FillColor, aColor.getColor( rGraphicHelper, nPhClr ) ); 319cdf0e10cSrcweir if( aColor.hasTransparency() ) 320cdf0e10cSrcweir rPropMap.setProperty( SHAPEPROP_FillTransparency, aColor.getTransparency() ); 321cdf0e10cSrcweir eFillStyle = FillStyle_SOLID; 322cdf0e10cSrcweir } 323cdf0e10cSrcweir } 324cdf0e10cSrcweir break; 325cdf0e10cSrcweir 326cdf0e10cSrcweir case XML_grpFill: 327cdf0e10cSrcweir // todo 328cdf0e10cSrcweir eFillStyle = FillStyle_NONE; 329cdf0e10cSrcweir break; 330cdf0e10cSrcweir } 331cdf0e10cSrcweir 332cdf0e10cSrcweir // set final fill style property 333cdf0e10cSrcweir rPropMap.setProperty( SHAPEPROP_FillStyle, eFillStyle ); 334cdf0e10cSrcweir } 335cdf0e10cSrcweir } 336cdf0e10cSrcweir 337cdf0e10cSrcweir // ============================================================================ 338cdf0e10cSrcweir 339cdf0e10cSrcweir void GraphicProperties::assignUsed( const GraphicProperties& rSourceProps ) 340cdf0e10cSrcweir { 341cdf0e10cSrcweir maBlipProps.assignUsed( rSourceProps.maBlipProps ); 342cdf0e10cSrcweir } 343cdf0e10cSrcweir 344cdf0e10cSrcweir void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelper& rGraphicHelper, sal_Int32 nPhClr ) const 345cdf0e10cSrcweir { 346cdf0e10cSrcweir if( maBlipProps.mxGraphic.is() ) 347cdf0e10cSrcweir { 348cdf0e10cSrcweir // created transformed graphic 349cdf0e10cSrcweir Reference< XGraphic > xGraphic = maBlipProps.mxGraphic; 350cdf0e10cSrcweir if( maBlipProps.maColorChangeFrom.isUsed() && maBlipProps.maColorChangeTo.isUsed() ) 351cdf0e10cSrcweir { 352cdf0e10cSrcweir sal_Int32 nFromColor = maBlipProps.maColorChangeFrom.getColor( rGraphicHelper, nPhClr ); 353cdf0e10cSrcweir sal_Int32 nToColor = maBlipProps.maColorChangeTo.getColor( rGraphicHelper, nPhClr ); 354cdf0e10cSrcweir if ( (nFromColor != nToColor) || maBlipProps.maColorChangeTo.hasTransparency() ) try 355cdf0e10cSrcweir { 356cdf0e10cSrcweir sal_Int16 nToTransparence = maBlipProps.maColorChangeTo.getTransparency(); 357cdf0e10cSrcweir sal_Int8 nToAlpha = static_cast< sal_Int8 >( (100 - nToTransparence) / 39.062 ); // ?!? correct ?!? 358cdf0e10cSrcweir Reference< XGraphicTransformer > xTransformer( maBlipProps.mxGraphic, UNO_QUERY_THROW ); 359cdf0e10cSrcweir xGraphic = xTransformer->colorChange( maBlipProps.mxGraphic, nFromColor, 9, nToColor, nToAlpha ); 360cdf0e10cSrcweir } 361cdf0e10cSrcweir catch( Exception& ) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir } 364cdf0e10cSrcweir } 365cdf0e10cSrcweir 366cdf0e10cSrcweir OUString aGraphicUrl = rGraphicHelper.createGraphicObject( xGraphic ); 367cdf0e10cSrcweir if( aGraphicUrl.getLength() > 0 ) 368cdf0e10cSrcweir rPropMap[ PROP_GraphicURL ] <<= aGraphicUrl; 369cdf0e10cSrcweir 370cdf0e10cSrcweir // cropping 371cdf0e10cSrcweir if ( maBlipProps.moClipRect.has() ) 372cdf0e10cSrcweir { 373cdf0e10cSrcweir geometry::IntegerRectangle2D oClipRect( maBlipProps.moClipRect.get() ); 374cdf0e10cSrcweir awt::Size aOriginalSize( rGraphicHelper.getOriginalSize( xGraphic ) ); 375cdf0e10cSrcweir if ( aOriginalSize.Width && aOriginalSize.Height ) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir text::GraphicCrop aGraphCrop( 0, 0, 0, 0 ); 378cdf0e10cSrcweir if ( oClipRect.X1 ) 379cdf0e10cSrcweir aGraphCrop.Left = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X1 ) / 100000 ); 380cdf0e10cSrcweir if ( oClipRect.Y1 ) 381cdf0e10cSrcweir aGraphCrop.Top = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y1 ) / 100000 ); 382cdf0e10cSrcweir if ( oClipRect.X2 ) 383cdf0e10cSrcweir aGraphCrop.Right = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X2 ) / 100000 ); 384cdf0e10cSrcweir if ( oClipRect.Y2 ) 385cdf0e10cSrcweir aGraphCrop.Bottom = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y2 ) / 100000 ); 386cdf0e10cSrcweir rPropMap[ PROP_GraphicCrop ] <<= aGraphCrop; 387cdf0e10cSrcweir } 388cdf0e10cSrcweir } 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir // color effect 392cdf0e10cSrcweir ColorMode eColorMode = ColorMode_STANDARD; 393cdf0e10cSrcweir switch( maBlipProps.moColorEffect.get( XML_TOKEN_INVALID ) ) 394cdf0e10cSrcweir { 395cdf0e10cSrcweir case XML_biLevel: eColorMode = ColorMode_MONO; break; 396cdf0e10cSrcweir case XML_grayscl: eColorMode = ColorMode_GREYS; break; 397cdf0e10cSrcweir } 398cdf0e10cSrcweir rPropMap[ PROP_GraphicColorMode ] <<= eColorMode; 399cdf0e10cSrcweir 400cdf0e10cSrcweir // brightness and contrast 401cdf0e10cSrcweir sal_Int16 nBrightness = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moBrightness.get( 0 ) / PER_PERCENT, -100, 100 ); 402cdf0e10cSrcweir if( nBrightness != 0 ) 403cdf0e10cSrcweir rPropMap[ PROP_AdjustLuminance ] <<= nBrightness; 404cdf0e10cSrcweir sal_Int16 nContrast = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moContrast.get( 0 ) / PER_PERCENT, -100, 100 ); 405cdf0e10cSrcweir if( nContrast != 0 ) 406cdf0e10cSrcweir rPropMap[ PROP_AdjustContrast ] <<= nContrast; 407cdf0e10cSrcweir } 408cdf0e10cSrcweir 409cdf0e10cSrcweir // ============================================================================ 410cdf0e10cSrcweir 411cdf0e10cSrcweir } // namespace drawingml 412cdf0e10cSrcweir } // namespace oox 413cdf0e10cSrcweir 414