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 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( "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( "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 399 : void GradientFillProperties::assignUsed( const GradientFillProperties& rSourceProps )
111 : {
112 399 : if( !rSourceProps.maGradientStops.empty() )
113 5 : maGradientStops = rSourceProps.maGradientStops;
114 399 : moFillToRect.assignIfUsed( rSourceProps.moFillToRect );
115 399 : moTileRect.assignIfUsed( rSourceProps.moTileRect );
116 399 : moGradientPath.assignIfUsed( rSourceProps.moGradientPath );
117 399 : moShadeAngle.assignIfUsed( rSourceProps.moShadeAngle );
118 399 : moShadeFlip.assignIfUsed( rSourceProps.moShadeFlip );
119 399 : moShadeScaled.assignIfUsed( rSourceProps.moShadeScaled );
120 399 : moRotateWithShape.assignIfUsed( rSourceProps.moRotateWithShape );
121 399 : }
122 :
123 : // ============================================================================
124 :
125 399 : void PatternFillProperties::assignUsed( const PatternFillProperties& rSourceProps )
126 : {
127 399 : maPattFgColor.assignIfUsed( rSourceProps.maPattFgColor );
128 399 : maPattBgColor.assignIfUsed( rSourceProps.maPattBgColor );
129 399 : moPattPreset.assignIfUsed( rSourceProps.moPattPreset );
130 399 : }
131 :
132 : // ============================================================================
133 :
134 399 : void BlipFillProperties::assignUsed( const BlipFillProperties& rSourceProps )
135 : {
136 399 : if( rSourceProps.mxGraphic.is() )
137 0 : mxGraphic = rSourceProps.mxGraphic;
138 399 : moBitmapMode.assignIfUsed( rSourceProps.moBitmapMode );
139 399 : moFillRect.assignIfUsed( rSourceProps.moFillRect );
140 399 : moTileOffsetX.assignIfUsed( rSourceProps.moTileOffsetX );
141 399 : moTileOffsetY.assignIfUsed( rSourceProps.moTileOffsetY );
142 399 : moTileScaleX.assignIfUsed( rSourceProps.moTileScaleX );
143 399 : moTileScaleY.assignIfUsed( rSourceProps.moTileScaleY );
144 399 : moTileAlign.assignIfUsed( rSourceProps.moTileAlign );
145 399 : moTileFlip.assignIfUsed( rSourceProps.moTileFlip );
146 399 : moRotateWithShape.assignIfUsed( rSourceProps.moRotateWithShape );
147 399 : moColorEffect.assignIfUsed( rSourceProps.moColorEffect );
148 399 : moBrightness.assignIfUsed( rSourceProps.moBrightness );
149 399 : moContrast.assignIfUsed( rSourceProps.moContrast );
150 399 : maColorChangeFrom.assignIfUsed( rSourceProps.maColorChangeFrom );
151 399 : maColorChangeTo.assignIfUsed( rSourceProps.maColorChangeTo );
152 399 : }
153 :
154 : // ============================================================================
155 :
156 399 : void FillProperties::assignUsed( const FillProperties& rSourceProps )
157 : {
158 399 : moFillType.assignIfUsed( rSourceProps.moFillType );
159 399 : maFillColor.assignIfUsed( rSourceProps.maFillColor );
160 399 : maGradientProps.assignUsed( rSourceProps.maGradientProps );
161 399 : maPatternProps.assignUsed( rSourceProps.maPatternProps );
162 399 : maBlipProps.assignUsed( rSourceProps.maBlipProps );
163 399 : }
164 :
165 203 : Color FillProperties::getBestSolidColor() const
166 : {
167 203 : Color aSolidColor;
168 203 : if( moFillType.has() ) switch( moFillType.get() )
169 : {
170 : case XML_solidFill:
171 108 : aSolidColor = maFillColor;
172 108 : 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 0 : break;
180 : }
181 203 : return aSolidColor;
182 : }
183 :
184 : /// Maps the hatch token to drawing::Hatch.
185 51 : static drawing::Hatch createHatch( sal_Int32 nHatchToken, sal_Int32 nColor )
186 : {
187 51 : drawing::Hatch aHatch;
188 51 : aHatch.Color = nColor;
189 :
190 : // best-effort mapping; we do not support all the styles in core
191 51 : switch ( nHatchToken )
192 : {
193 1 : case XML_pct5: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 250; aHatch.Angle = 450; break;
194 1 : case XML_pct10: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 200; aHatch.Angle = 450; break;
195 1 : case XML_pct20: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 450; break;
196 1 : case XML_pct25: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 200; aHatch.Angle = 450; break;
197 3 : case XML_pct30: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 175; aHatch.Angle = 450; break;
198 1 : case XML_pct40: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 150; aHatch.Angle = 450; break;
199 1 : case XML_pct50: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 125; aHatch.Angle = 450; break;
200 1 : case XML_pct60: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 150; aHatch.Angle = 450; break;
201 1 : case XML_pct70: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 125; aHatch.Angle = 450; break;
202 1 : case XML_pct75: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 100; aHatch.Angle = 450; break;
203 1 : case XML_pct80: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 75; aHatch.Angle = 450; break;
204 1 : case XML_pct90: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 50; aHatch.Angle = 450; break;
205 0 : case XML_horz: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 0; break;
206 0 : case XML_vert: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 900; break;
207 1 : case XML_ltHorz: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 0; break;
208 1 : case XML_ltVert: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 900; break;
209 1 : case XML_dkHorz: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 25; aHatch.Angle = 0; break;
210 1 : case XML_dkVert: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 25; aHatch.Angle = 900; break;
211 1 : case XML_narHorz: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50; aHatch.Angle = 0; break;
212 2 : case XML_narVert: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50; aHatch.Angle = 900; break;
213 1 : case XML_dashHorz: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 0; break;
214 1 : case XML_dashVert: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 900; break;
215 0 : case XML_cross: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 0; break;
216 0 : case XML_dnDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 1350; break;
217 0 : case XML_upDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 450; break;
218 1 : case XML_ltDnDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 1350; break;
219 1 : case XML_ltUpDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 450; break;
220 1 : case XML_dkDnDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50; aHatch.Angle = 1350; break;
221 1 : case XML_dkUpDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50; aHatch.Angle = 450; break;
222 1 : case XML_wdDnDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 200; aHatch.Angle = 1350; break;
223 1 : case XML_wdUpDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 200; aHatch.Angle = 450; break;
224 1 : case XML_dashDnDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 1350; break;
225 1 : case XML_dashUpDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 450; break;
226 0 : case XML_diagCross: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 450; break;
227 1 : case XML_smCheck: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 50; aHatch.Angle = 450; break;
228 1 : case XML_lgCheck: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 450; break;
229 1 : case XML_smGrid: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 150; aHatch.Angle = 0; break;
230 1 : case XML_lgGrid: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 250; aHatch.Angle = 0; break;
231 1 : case XML_dotGrid: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 400; aHatch.Angle = 0; break;
232 1 : case XML_smConfetti: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 200; aHatch.Angle = 600; break;
233 1 : case XML_lgConfetti: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 600; break;
234 1 : case XML_horzBrick: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 300; aHatch.Angle = 0; break;
235 1 : case XML_diagBrick: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 300; aHatch.Angle = 450; break;
236 1 : case XML_solidDmnd: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 150; aHatch.Angle = 450; break;
237 1 : case XML_openDmnd: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 200; aHatch.Angle = 450; break;
238 1 : case XML_dotDmnd: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 300; aHatch.Angle = 450; break;
239 1 : case XML_plaid: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 200; aHatch.Angle = 900; break;
240 1 : case XML_sphere: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 100; aHatch.Angle = 0; break;
241 1 : case XML_weave: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 150; aHatch.Angle = 450; break;
242 1 : case XML_divot: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 400; aHatch.Angle = 450; break;
243 1 : case XML_shingle: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 200; aHatch.Angle = 1350; break;
244 1 : case XML_wave: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 0; break;
245 1 : case XML_trellis: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 75; aHatch.Angle = 450; break;
246 1 : case XML_zigZag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 75; aHatch.Angle = 0; break;
247 : }
248 :
249 51 : return aHatch;
250 : }
251 :
252 207 : void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap,
253 : const GraphicHelper& rGraphicHelper, sal_Int32 nShapeRotation, sal_Int32 nPhClr,
254 : bool bFlipH, bool bFlipV ) const
255 : {
256 207 : if( moFillType.has() )
257 : {
258 205 : FillStyle eFillStyle = FillStyle_NONE;
259 : OSL_ASSERT((moFillType.get() & sal_Int32(0xFFFF0000))==0);
260 205 : switch( moFillType.get() )
261 : {
262 : case XML_noFill:
263 98 : eFillStyle = FillStyle_NONE;
264 98 : break;
265 :
266 : case XML_solidFill:
267 43 : if( maFillColor.isUsed() )
268 : {
269 43 : rPropMap.setProperty( SHAPEPROP_FillColor, maFillColor.getColor( rGraphicHelper, nPhClr ) );
270 43 : if( maFillColor.hasTransparency() )
271 7 : rPropMap.setProperty( SHAPEPROP_FillTransparency, maFillColor.getTransparency() );
272 43 : eFillStyle = FillStyle_SOLID;
273 : }
274 43 : break;
275 :
276 : case XML_gradFill:
277 : // do not create gradient struct if property is not supported...
278 13 : if( rPropMap.supportsProperty( SHAPEPROP_FillGradient ) )
279 : {
280 13 : sal_Int32 nEndTrans = 0;
281 13 : sal_Int32 nStartTrans = 0;
282 13 : awt::Gradient aGradient;
283 13 : aGradient.Angle = 900;
284 13 : aGradient.StartIntensity = 100;
285 13 : aGradient.EndIntensity = 100;
286 :
287 13 : size_t nColorCount = maGradientProps.maGradientStops.size();
288 13 : if( nColorCount > 1 )
289 : {
290 13 : aGradient.StartColor = maGradientProps.maGradientStops.begin()->second.getColor( rGraphicHelper, nPhClr );
291 13 : aGradient.EndColor = maGradientProps.maGradientStops.rbegin()->second.getColor( rGraphicHelper, nPhClr );
292 13 : if( maGradientProps.maGradientStops.rbegin()->second.hasTransparency() )
293 1 : nEndTrans = maGradientProps.maGradientStops.rbegin()->second.getTransparency()*255/100;
294 13 : if( maGradientProps.maGradientStops.begin()->second.hasTransparency() )
295 2 : nStartTrans = maGradientProps.maGradientStops.begin()->second.getTransparency()*255/100;
296 : }
297 :
298 : // Adjust for flips
299 13 : if ( bFlipH )
300 1 : nShapeRotation = 180*60000 - nShapeRotation;
301 13 : if ( bFlipV )
302 0 : nShapeRotation = -nShapeRotation;
303 :
304 : // "rotate with shape" not set, or set to false -> do not rotate
305 13 : if ( !maGradientProps.moRotateWithShape.get( false ) )
306 8 : nShapeRotation = 0;
307 :
308 13 : sal_Int32 nDmlAngle = 0;
309 13 : if( maGradientProps.moGradientPath.has() )
310 : {
311 0 : aGradient.Style = (maGradientProps.moGradientPath.get() == XML_circle) ? awt::GradientStyle_ELLIPTICAL : awt::GradientStyle_RECT;
312 : // position of gradient center (limited to [30%;70%], otherwise gradient is too hidden)
313 0 : IntegerRectangle2D aFillToRect = maGradientProps.moFillToRect.get( IntegerRectangle2D( 0, 0, MAX_PERCENT, MAX_PERCENT ) );
314 0 : sal_Int32 nCenterX = (MAX_PERCENT + aFillToRect.X1 - aFillToRect.X2) / 2;
315 0 : aGradient.XOffset = getLimitedValue< sal_Int16, sal_Int32 >( nCenterX / PER_PERCENT, 30, 70 );
316 0 : sal_Int32 nCenterY = (MAX_PERCENT + aFillToRect.Y1 - aFillToRect.Y2) / 2;
317 0 : aGradient.YOffset = getLimitedValue< sal_Int16, sal_Int32 >( nCenterY / PER_PERCENT, 30, 70 );
318 0 : ::std::swap( aGradient.StartColor, aGradient.EndColor );
319 0 : ::std::swap( nStartTrans, nEndTrans );
320 0 : nDmlAngle = nShapeRotation;
321 : }
322 : else
323 : {
324 : /* Try to detect a VML axial gradient. This type of
325 : gradient is simulated by a 3-point linear gradient.
326 : Even if its a multi-color linear gradient, its probably better to assume
327 : axial gradient, when there are 3 or more points.
328 : */
329 13 : bool bAxial = (nColorCount >= 3);
330 13 : aGradient.Style = bAxial ? awt::GradientStyle_AXIAL : awt::GradientStyle_LINEAR;
331 13 : nDmlAngle = maGradientProps.moShadeAngle.get( 0 ) - nShapeRotation;
332 : // convert DrawingML angle (in 1/60000 degrees) to API angle (in 1/10 degrees)
333 13 : aGradient.Angle = static_cast< sal_Int16 >( (4500 - (nDmlAngle / (PER_DEGREE / 10))) % 3600 );
334 13 : if( bAxial )
335 : {
336 8 : GradientFillProperties::GradientStopMap::const_iterator aIt = maGradientProps.maGradientStops.begin();
337 : // Try to find the axial median
338 16 : for(size_t i=0;i<nColorCount;i+=3)
339 8 : ++aIt;
340 : // API StartColor is inner color in axial gradient
341 : // aIt->second.hasColor() kind would be better than Color != API_RGB_WHITE
342 24 : if( aGradient.StartColor == aGradient.EndColor &&
343 8 : ( !aIt->second.hasTransparency() || aIt->second.getColor( rGraphicHelper, nPhClr ) != API_RGB_WHITE ) )
344 : {
345 8 : aGradient.StartColor = aIt->second.getColor( rGraphicHelper, nPhClr );
346 : }
347 :
348 8 : if( nStartTrans == nEndTrans && aIt->second.hasTransparency() )
349 0 : nStartTrans = aIt->second.getTransparency()*255/100;
350 : }
351 : }
352 :
353 : // push gradient or named gradient to property map
354 13 : if( rPropMap.setProperty( SHAPEPROP_FillGradient, aGradient ) )
355 13 : eFillStyle = FillStyle_GRADIENT;
356 :
357 : // push gradient transparency to property map
358 13 : if( nStartTrans != 0 || nEndTrans != 0 )
359 : {
360 3 : awt::Gradient aGrad(aGradient);
361 3 : uno::Any aVal;
362 3 : aGrad.EndColor = (sal_Int32)( nEndTrans | nEndTrans << 8 | nEndTrans << 16 );
363 3 : aGrad.StartColor = (sal_Int32)( nStartTrans | nStartTrans << 8 | nStartTrans << 16 );
364 3 : aVal <<= aGrad;
365 3 : rPropMap.setProperty( SHAPEPROP_GradientTransparency, aGrad );
366 : }
367 :
368 : }
369 13 : break;
370 :
371 : case XML_blipFill:
372 : // do not start complex graphic transformation if property is not supported...
373 0 : if( maBlipProps.mxGraphic.is() && rPropMap.supportsProperty( SHAPEPROP_FillBitmapUrl ) )
374 : {
375 : // TODO: "rotate with shape" is not possible with our current core
376 :
377 0 : OUString aGraphicUrl = rGraphicHelper.createGraphicObject( maBlipProps.mxGraphic );
378 : // push bitmap or named bitmap to property map
379 0 : if( !aGraphicUrl.isEmpty() && rPropMap.setProperty( SHAPEPROP_FillBitmapUrl, aGraphicUrl ) )
380 0 : eFillStyle = FillStyle_BITMAP;
381 :
382 : // set other bitmap properties, if bitmap has been inserted into the map
383 0 : if( eFillStyle == FillStyle_BITMAP )
384 : {
385 : // bitmap mode (single, repeat, stretch)
386 0 : BitmapMode eBitmapMode = lclGetBitmapMode( maBlipProps.moBitmapMode.get( XML_TOKEN_INVALID ) );
387 0 : rPropMap.setProperty( SHAPEPROP_FillBitmapMode, eBitmapMode );
388 :
389 : // additional settings for repeated bitmap
390 0 : if( eBitmapMode == BitmapMode_REPEAT )
391 : {
392 : // anchor position inside bitmap
393 0 : RectanglePoint eRectPoint = lclGetRectanglePoint( maBlipProps.moTileAlign.get( XML_tl ) );
394 0 : rPropMap.setProperty( SHAPEPROP_FillBitmapRectanglePoint, eRectPoint );
395 :
396 0 : awt::Size aOriginalSize = lclGetOriginalSize( rGraphicHelper, maBlipProps.mxGraphic );
397 0 : if( (aOriginalSize.Width > 0) && (aOriginalSize.Height > 0) )
398 : {
399 : // size of one bitmap tile (given as 1/1000 percent of bitmap size), convert to 1/100 mm
400 0 : double fScaleX = maBlipProps.moTileScaleX.get( MAX_PERCENT ) / static_cast< double >( MAX_PERCENT );
401 0 : sal_Int32 nFillBmpSizeX = getLimitedValue< sal_Int32, double >( aOriginalSize.Width * fScaleX, 1, SAL_MAX_INT32 );
402 0 : rPropMap.setProperty( SHAPEPROP_FillBitmapSizeX, nFillBmpSizeX );
403 0 : double fScaleY = maBlipProps.moTileScaleY.get( MAX_PERCENT ) / static_cast< double >( MAX_PERCENT );
404 0 : sal_Int32 nFillBmpSizeY = getLimitedValue< sal_Int32, double >( aOriginalSize.Height * fScaleY, 1, SAL_MAX_INT32 );
405 0 : rPropMap.setProperty( SHAPEPROP_FillBitmapSizeY, nFillBmpSizeY );
406 :
407 : // offset of the first bitmap tile (given as EMUs), convert to percent
408 0 : sal_Int16 nTileOffsetX = getDoubleIntervalValue< sal_Int16 >( maBlipProps.moTileOffsetX.get( 0 ) / 3.6 / aOriginalSize.Width, 0, 100 );
409 0 : rPropMap.setProperty( SHAPEPROP_FillBitmapOffsetX, nTileOffsetX );
410 0 : sal_Int16 nTileOffsetY = getDoubleIntervalValue< sal_Int16 >( maBlipProps.moTileOffsetY.get( 0 ) / 3.6 / aOriginalSize.Height, 0, 100 );
411 0 : rPropMap.setProperty( SHAPEPROP_FillBitmapOffsetY, nTileOffsetY );
412 : }
413 : }
414 0 : }
415 : }
416 0 : break;
417 :
418 : case XML_pattFill:
419 : {
420 51 : if( rPropMap.supportsProperty( SHAPEPROP_FillHatch ) )
421 : {
422 51 : Color aColor( maPatternProps.maPattFgColor );
423 51 : if( aColor.isUsed() && maPatternProps.moPattPreset.has() )
424 : {
425 : // we do not support hatches that have background
426 : // color too, so all this is some best-effort approach
427 51 : eFillStyle = FillStyle_HATCH;
428 51 : rPropMap.setProperty( SHAPEPROP_FillHatch, createHatch( maPatternProps.moPattPreset.get(), aColor.getColor( rGraphicHelper, nPhClr ) ) );
429 : }
430 0 : else if ( maPatternProps.maPattBgColor.isUsed() )
431 : {
432 0 : aColor = maPatternProps.maPattBgColor;
433 0 : rPropMap.setProperty( SHAPEPROP_FillColor, aColor.getColor( rGraphicHelper, nPhClr ) );
434 0 : if( aColor.hasTransparency() )
435 0 : rPropMap.setProperty( SHAPEPROP_FillTransparency, aColor.getTransparency() );
436 0 : eFillStyle = FillStyle_SOLID;
437 51 : }
438 : }
439 : }
440 51 : break;
441 :
442 : case XML_grpFill:
443 : // todo
444 0 : eFillStyle = FillStyle_NONE;
445 0 : break;
446 : }
447 :
448 : // set final fill style property
449 205 : rPropMap.setProperty( SHAPEPROP_FillStyle, eFillStyle );
450 : }
451 207 : }
452 :
453 : // ============================================================================
454 :
455 17 : void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelper& rGraphicHelper, sal_Int32 nPhClr ) const
456 : {
457 17 : if( maBlipProps.mxGraphic.is() )
458 : {
459 : // created transformed graphic
460 15 : Reference< XGraphic > xGraphic = maBlipProps.mxGraphic;
461 15 : if( maBlipProps.maColorChangeFrom.isUsed() && maBlipProps.maColorChangeTo.isUsed() )
462 : {
463 0 : sal_Int32 nFromColor = maBlipProps.maColorChangeFrom.getColor( rGraphicHelper, nPhClr );
464 0 : sal_Int32 nToColor = maBlipProps.maColorChangeTo.getColor( rGraphicHelper, nPhClr );
465 0 : if ( (nFromColor != nToColor) || maBlipProps.maColorChangeTo.hasTransparency() ) try
466 : {
467 0 : sal_Int16 nToTransparence = maBlipProps.maColorChangeTo.getTransparency();
468 0 : sal_Int8 nToAlpha = static_cast< sal_Int8 >( (100 - nToTransparence) / 39.062 ); // ?!? correct ?!?
469 0 : Reference< XGraphicTransformer > xTransformer( maBlipProps.mxGraphic, UNO_QUERY_THROW );
470 0 : xGraphic = xTransformer->colorChange( maBlipProps.mxGraphic, nFromColor, 9, nToColor, nToAlpha );
471 : }
472 0 : catch( Exception& )
473 : {
474 : }
475 : }
476 :
477 15 : rPropMap[ PROP_Graphic ] <<= xGraphic;
478 :
479 : // do we still need to set GraphicURL as well? (TODO)
480 30 : OUString aGraphicUrl = rGraphicHelper.createGraphicObject( xGraphic );
481 15 : if( !aGraphicUrl.isEmpty() )
482 15 : rPropMap[ PROP_GraphicURL ] <<= aGraphicUrl;
483 :
484 : // cropping
485 15 : if ( maBlipProps.moClipRect.has() )
486 : {
487 5 : geometry::IntegerRectangle2D oClipRect( maBlipProps.moClipRect.get() );
488 5 : awt::Size aOriginalSize( rGraphicHelper.getOriginalSize( xGraphic ) );
489 5 : if ( aOriginalSize.Width && aOriginalSize.Height )
490 : {
491 5 : text::GraphicCrop aGraphCrop( 0, 0, 0, 0 );
492 5 : if ( oClipRect.X1 )
493 0 : aGraphCrop.Left = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X1 ) / 100000 );
494 5 : if ( oClipRect.Y1 )
495 0 : aGraphCrop.Top = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y1 ) / 100000 );
496 5 : if ( oClipRect.X2 )
497 0 : aGraphCrop.Right = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X2 ) / 100000 );
498 5 : if ( oClipRect.Y2 )
499 0 : aGraphCrop.Bottom = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y2 ) / 100000 );
500 5 : rPropMap[ PROP_GraphicCrop ] <<= aGraphCrop;
501 : }
502 15 : }
503 : }
504 :
505 : // color effect
506 17 : ColorMode eColorMode = ColorMode_STANDARD;
507 17 : switch( maBlipProps.moColorEffect.get( XML_TOKEN_INVALID ) )
508 : {
509 0 : case XML_biLevel: eColorMode = ColorMode_MONO; break;
510 0 : case XML_grayscl: eColorMode = ColorMode_GREYS; break;
511 : }
512 17 : rPropMap[ PROP_GraphicColorMode ] <<= eColorMode;
513 :
514 : // brightness and contrast
515 17 : sal_Int16 nBrightness = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moBrightness.get( 0 ) / PER_PERCENT, -100, 100 );
516 17 : if( nBrightness != 0 )
517 0 : rPropMap[ PROP_AdjustLuminance ] <<= nBrightness;
518 17 : sal_Int16 nContrast = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moContrast.get( 0 ) / PER_PERCENT, -100, 100 );
519 17 : if( nContrast != 0 )
520 0 : rPropMap[ PROP_AdjustContrast ] <<= nContrast;
521 :
522 : // Media content
523 17 : if( !maAudio.msEmbed.isEmpty() )
524 0 : rPropMap[ PROP_MediaURL ] <<= maAudio.msEmbed;
525 17 : }
526 :
527 : // ============================================================================
528 :
529 : } // namespace drawingml
530 141 : } // namespace oox
531 :
532 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|