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