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 : Reference< XGraphic > lclCheckAndApplyDuotoneTransform( const BlipFillProperties& aBlipProps, Reference< XGraphic > xGraphic,
56 : const GraphicHelper& rGraphicHelper, const sal_Int32 nPhClr )
57 : {
58 0 : if( aBlipProps.maDuotoneColors[0].isUsed() && aBlipProps.maDuotoneColors[1].isUsed() )
59 : {
60 0 : sal_Int32 nColor1 = aBlipProps.maDuotoneColors[0].getColor( rGraphicHelper, nPhClr );
61 0 : sal_Int32 nColor2 = aBlipProps.maDuotoneColors[1].getColor( rGraphicHelper, nPhClr );
62 : try
63 : {
64 0 : Reference< XGraphicTransformer > xTransformer( aBlipProps.mxGraphic, UNO_QUERY_THROW );
65 0 : xGraphic = xTransformer->applyDuotone( xGraphic, nColor1, nColor2 );
66 : }
67 0 : catch( Exception& )
68 : {
69 : }
70 : }
71 0 : return xGraphic;
72 : }
73 :
74 0 : Reference< XGraphic > lclCheckAndApplyChangeColorTransform( const BlipFillProperties &aBlipProps, Reference< XGraphic > xGraphic,
75 : const GraphicHelper& rGraphicHelper, const sal_Int32 nPhClr )
76 : {
77 0 : 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 0 : return xGraphic;
93 : }
94 :
95 :
96 :
97 0 : BitmapMode lclGetBitmapMode( sal_Int32 nToken )
98 : {
99 : OSL_ASSERT((nToken & sal_Int32(0xFFFF0000))==0);
100 0 : switch( nToken )
101 : {
102 0 : case XML_tile: return BitmapMode_REPEAT;
103 0 : 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 0 : void GradientFillProperties::assignUsed( const GradientFillProperties& rSourceProps )
153 : {
154 0 : if( !rSourceProps.maGradientStops.empty() )
155 0 : maGradientStops = rSourceProps.maGradientStops;
156 0 : moFillToRect.assignIfUsed( rSourceProps.moFillToRect );
157 0 : moTileRect.assignIfUsed( rSourceProps.moTileRect );
158 0 : moGradientPath.assignIfUsed( rSourceProps.moGradientPath );
159 0 : moShadeAngle.assignIfUsed( rSourceProps.moShadeAngle );
160 0 : moShadeFlip.assignIfUsed( rSourceProps.moShadeFlip );
161 0 : moShadeScaled.assignIfUsed( rSourceProps.moShadeScaled );
162 0 : moRotateWithShape.assignIfUsed( rSourceProps.moRotateWithShape );
163 0 : }
164 :
165 :
166 :
167 0 : void PatternFillProperties::assignUsed( const PatternFillProperties& rSourceProps )
168 : {
169 0 : maPattFgColor.assignIfUsed( rSourceProps.maPattFgColor );
170 0 : maPattBgColor.assignIfUsed( rSourceProps.maPattBgColor );
171 0 : moPattPreset.assignIfUsed( rSourceProps.moPattPreset );
172 0 : }
173 :
174 :
175 :
176 0 : void BlipFillProperties::assignUsed( const BlipFillProperties& rSourceProps )
177 : {
178 0 : if( rSourceProps.mxGraphic.is() )
179 0 : mxGraphic = rSourceProps.mxGraphic;
180 0 : moBitmapMode.assignIfUsed( rSourceProps.moBitmapMode );
181 0 : moFillRect.assignIfUsed( rSourceProps.moFillRect );
182 0 : moTileOffsetX.assignIfUsed( rSourceProps.moTileOffsetX );
183 0 : moTileOffsetY.assignIfUsed( rSourceProps.moTileOffsetY );
184 0 : moTileScaleX.assignIfUsed( rSourceProps.moTileScaleX );
185 0 : moTileScaleY.assignIfUsed( rSourceProps.moTileScaleY );
186 0 : moTileAlign.assignIfUsed( rSourceProps.moTileAlign );
187 0 : moTileFlip.assignIfUsed( rSourceProps.moTileFlip );
188 0 : moRotateWithShape.assignIfUsed( rSourceProps.moRotateWithShape );
189 0 : moColorEffect.assignIfUsed( rSourceProps.moColorEffect );
190 0 : moBrightness.assignIfUsed( rSourceProps.moBrightness );
191 0 : moContrast.assignIfUsed( rSourceProps.moContrast );
192 0 : maColorChangeFrom.assignIfUsed( rSourceProps.maColorChangeFrom );
193 0 : maColorChangeTo.assignIfUsed( rSourceProps.maColorChangeTo );
194 0 : maDuotoneColors[0].assignIfUsed( rSourceProps.maDuotoneColors[0] );
195 0 : maDuotoneColors[1].assignIfUsed( rSourceProps.maDuotoneColors[1] );
196 0 : }
197 :
198 :
199 :
200 0 : void FillProperties::assignUsed( const FillProperties& rSourceProps )
201 : {
202 0 : moFillType.assignIfUsed( rSourceProps.moFillType );
203 0 : maFillColor.assignIfUsed( rSourceProps.maFillColor );
204 0 : maGradientProps.assignUsed( rSourceProps.maGradientProps );
205 0 : maPatternProps.assignUsed( rSourceProps.maPatternProps );
206 0 : maBlipProps.assignUsed( rSourceProps.maBlipProps );
207 0 : }
208 :
209 0 : Color FillProperties::getBestSolidColor() const
210 : {
211 0 : Color aSolidColor;
212 0 : if( moFillType.has() ) switch( moFillType.get() )
213 : {
214 : case XML_solidFill:
215 0 : aSolidColor = maFillColor;
216 0 : 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 0 : return aSolidColor;
226 : }
227 :
228 : /// Maps the hatch token to drawing::Hatch.
229 0 : static drawing::Hatch createHatch( sal_Int32 nHatchToken, sal_Int32 nColor )
230 : {
231 0 : drawing::Hatch aHatch;
232 0 : aHatch.Color = nColor;
233 :
234 : // best-effort mapping; we do not support all the styles in core
235 0 : switch ( nHatchToken )
236 : {
237 0 : case XML_pct5: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 250; aHatch.Angle = 450; break;
238 0 : case XML_pct10: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 200; aHatch.Angle = 450; break;
239 0 : case XML_pct20: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 450; break;
240 0 : case XML_pct25: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 200; aHatch.Angle = 450; break;
241 0 : case XML_pct30: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 175; aHatch.Angle = 450; break;
242 0 : case XML_pct40: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 150; aHatch.Angle = 450; break;
243 0 : case XML_pct50: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 125; aHatch.Angle = 450; break;
244 0 : case XML_pct60: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 150; aHatch.Angle = 450; break;
245 0 : case XML_pct70: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 125; aHatch.Angle = 450; break;
246 0 : case XML_pct75: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 100; aHatch.Angle = 450; break;
247 0 : case XML_pct80: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 75; aHatch.Angle = 450; break;
248 0 : case XML_pct90: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 50; aHatch.Angle = 450; break;
249 0 : case XML_horz: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 0; break;
250 0 : case XML_vert: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 900; break;
251 0 : case XML_ltHorz: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50; aHatch.Angle = 0; break;
252 0 : case XML_ltVert: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50; aHatch.Angle = 900; break;
253 0 : case XML_dkHorz: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 25; aHatch.Angle = 0; break;
254 0 : case XML_dkVert: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 25; aHatch.Angle = 900; break;
255 0 : case XML_narHorz: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50; aHatch.Angle = 0; break;
256 0 : case XML_narVert: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50; aHatch.Angle = 900; break;
257 0 : case XML_dashHorz: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 0; break;
258 0 : 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 0 : case XML_ltDnDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50; aHatch.Angle = 1350; break;
263 0 : case XML_ltUpDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50; aHatch.Angle = 450; break;
264 0 : case XML_dkDnDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50; aHatch.Angle = 1350; break;
265 0 : case XML_dkUpDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 50; aHatch.Angle = 450; break;
266 0 : case XML_wdDnDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 1350; break;
267 0 : case XML_wdUpDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 450; break;
268 0 : case XML_dashDnDiag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 150; aHatch.Angle = 1350; break;
269 0 : 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 0 : case XML_smCheck: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 50; aHatch.Angle = 450; break;
272 0 : case XML_lgCheck: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 450; break;
273 0 : case XML_smGrid: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 50; aHatch.Angle = 0; break;
274 0 : case XML_lgGrid: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 0; break;
275 0 : case XML_dotGrid: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 400; aHatch.Angle = 0; break;
276 0 : case XML_smConfetti: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 200; aHatch.Angle = 600; break;
277 0 : case XML_lgConfetti: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 600; break;
278 0 : case XML_horzBrick: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 300; aHatch.Angle = 0; break;
279 0 : case XML_diagBrick: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 300; aHatch.Angle = 450; break;
280 0 : case XML_solidDmnd: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 450; break;
281 0 : case XML_openDmnd: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 100; aHatch.Angle = 450; break;
282 0 : case XML_dotDmnd: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 300; aHatch.Angle = 450; break;
283 0 : case XML_plaid: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 200; aHatch.Angle = 900; break;
284 0 : case XML_sphere: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 100; aHatch.Angle = 0; break;
285 0 : case XML_weave: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 150; aHatch.Angle = 450; break;
286 0 : case XML_divot: aHatch.Style = drawing::HatchStyle_TRIPLE; aHatch.Distance = 400; aHatch.Angle = 450; break;
287 0 : case XML_shingle: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 200; aHatch.Angle = 1350; break;
288 0 : case XML_wave: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 100; aHatch.Angle = 0; break;
289 0 : case XML_trellis: aHatch.Style = drawing::HatchStyle_DOUBLE; aHatch.Distance = 75; aHatch.Angle = 450; break;
290 0 : case XML_zigZag: aHatch.Style = drawing::HatchStyle_SINGLE; aHatch.Distance = 75; aHatch.Angle = 0; break;
291 : }
292 :
293 0 : return aHatch;
294 : }
295 :
296 0 : void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap,
297 : const GraphicHelper& rGraphicHelper, sal_Int32 nShapeRotation, sal_Int32 nPhClr,
298 : bool bFlipH, bool bFlipV ) const
299 : {
300 0 : if( moFillType.has() )
301 : {
302 0 : FillStyle eFillStyle = FillStyle_NONE;
303 : OSL_ASSERT((moFillType.get() & sal_Int32(0xFFFF0000))==0);
304 0 : switch( moFillType.get() )
305 : {
306 : case XML_noFill:
307 0 : eFillStyle = FillStyle_NONE;
308 0 : break;
309 :
310 : case XML_solidFill:
311 0 : if( maFillColor.isUsed() )
312 : {
313 0 : rPropMap.setProperty( SHAPEPROP_FillColor, maFillColor.getColor( rGraphicHelper, nPhClr ) );
314 0 : if( maFillColor.hasTransparency() )
315 0 : rPropMap.setProperty( SHAPEPROP_FillTransparency, maFillColor.getTransparency() );
316 0 : eFillStyle = FillStyle_SOLID;
317 : }
318 0 : break;
319 :
320 : case XML_gradFill:
321 : // do not create gradient struct if property is not supported...
322 0 : if( rPropMap.supportsProperty( SHAPEPROP_FillGradient ) )
323 : {
324 0 : sal_Int32 nEndTrans = 0;
325 0 : sal_Int32 nStartTrans = 0;
326 0 : awt::Gradient aGradient;
327 0 : aGradient.Angle = 900;
328 0 : aGradient.StartIntensity = 100;
329 0 : aGradient.EndIntensity = 100;
330 :
331 0 : size_t nColorCount = maGradientProps.maGradientStops.size();
332 0 : if( nColorCount > 1 )
333 : {
334 0 : aGradient.StartColor = maGradientProps.maGradientStops.begin()->second.getColor( rGraphicHelper, nPhClr );
335 0 : aGradient.EndColor = maGradientProps.maGradientStops.rbegin()->second.getColor( rGraphicHelper, nPhClr );
336 0 : if( maGradientProps.maGradientStops.rbegin()->second.hasTransparency() )
337 0 : nEndTrans = maGradientProps.maGradientStops.rbegin()->second.getTransparency()*255/100;
338 0 : if( maGradientProps.maGradientStops.begin()->second.hasTransparency() )
339 0 : nStartTrans = maGradientProps.maGradientStops.begin()->second.getTransparency()*255/100;
340 : }
341 :
342 : // Adjust for flips
343 0 : if ( bFlipH )
344 0 : nShapeRotation = 180*60000 - nShapeRotation;
345 0 : if ( bFlipV )
346 0 : nShapeRotation = -nShapeRotation;
347 :
348 : // "rotate with shape" not set, or set to false -> do not rotate
349 0 : if ( !maGradientProps.moRotateWithShape.get( false ) )
350 0 : nShapeRotation = 0;
351 :
352 0 : sal_Int32 nDmlAngle = 0;
353 0 : 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 0 : bool bAxial = (nColorCount >= 3);
374 0 : aGradient.Style = bAxial ? awt::GradientStyle_AXIAL : awt::GradientStyle_LINEAR;
375 0 : nDmlAngle = maGradientProps.moShadeAngle.get( 0 ) - nShapeRotation;
376 : // convert DrawingML angle (in 1/60000 degrees) to API angle (in 1/10 degrees)
377 0 : aGradient.Angle = static_cast< sal_Int16 >( (4500 - (nDmlAngle / (PER_DEGREE / 10))) % 3600 );
378 0 : if( bAxial )
379 : {
380 0 : GradientFillProperties::GradientStopMap::const_iterator aIt = maGradientProps.maGradientStops.begin();
381 : // Try to find the axial median
382 0 : for(size_t i=0;i<nColorCount;i+=3)
383 0 : ++aIt;
384 : // API StartColor is inner color in axial gradient
385 : // aIt->second.hasColor() kind would be better than Color != API_RGB_WHITE
386 0 : if( aGradient.StartColor == aGradient.EndColor &&
387 0 : ( !aIt->second.hasTransparency() || aIt->second.getColor( rGraphicHelper, nPhClr ) != API_RGB_WHITE ) )
388 : {
389 0 : aGradient.StartColor = aIt->second.getColor( rGraphicHelper, nPhClr );
390 : }
391 :
392 0 : if( nStartTrans == nEndTrans && aIt->second.hasTransparency() )
393 0 : nStartTrans = aIt->second.getTransparency()*255/100;
394 : }
395 : }
396 :
397 : // push gradient or named gradient to property map
398 0 : if( rPropMap.setProperty( SHAPEPROP_FillGradient, aGradient ) )
399 0 : eFillStyle = FillStyle_GRADIENT;
400 :
401 : // push gradient transparency to property map
402 0 : if( nStartTrans != 0 || nEndTrans != 0 )
403 : {
404 0 : awt::Gradient aGrad(aGradient);
405 0 : uno::Any aVal;
406 0 : aGrad.EndColor = (sal_Int32)( nEndTrans | nEndTrans << 8 | nEndTrans << 16 );
407 0 : aGrad.StartColor = (sal_Int32)( nStartTrans | nStartTrans << 8 | nStartTrans << 16 );
408 0 : aVal <<= aGrad;
409 0 : rPropMap.setProperty( SHAPEPROP_GradientTransparency, aGrad );
410 : }
411 :
412 : }
413 0 : break;
414 :
415 : case XML_blipFill:
416 : // do not start complex graphic transformation if property is not supported...
417 0 : if( maBlipProps.mxGraphic.is() && rPropMap.supportsProperty( SHAPEPROP_FillBitmapUrl ) )
418 : {
419 0 : Reference< XGraphic > xGraphic = lclCheckAndApplyDuotoneTransform( maBlipProps, maBlipProps.mxGraphic, rGraphicHelper, nPhClr );
420 : // TODO: "rotate with shape" is not possible with our current core
421 :
422 0 : OUString aGraphicUrl = rGraphicHelper.createGraphicObject( xGraphic );
423 : // push bitmap or named bitmap to property map
424 0 : if( !aGraphicUrl.isEmpty() && rPropMap.supportsProperty( SHAPEPROP_FillBitmapNameFromUrl ) && rPropMap.setProperty( SHAPEPROP_FillBitmapNameFromUrl, aGraphicUrl ) )
425 0 : eFillStyle = FillStyle_BITMAP;
426 0 : else if( !aGraphicUrl.isEmpty() && rPropMap.setProperty( SHAPEPROP_FillBitmapUrl, aGraphicUrl ) )
427 0 : eFillStyle = FillStyle_BITMAP;
428 :
429 : // set other bitmap properties, if bitmap has been inserted into the map
430 0 : if( eFillStyle == FillStyle_BITMAP )
431 : {
432 : // bitmap mode (single, repeat, stretch)
433 0 : BitmapMode eBitmapMode = lclGetBitmapMode( maBlipProps.moBitmapMode.get( XML_TOKEN_INVALID ) );
434 0 : rPropMap.setProperty( SHAPEPROP_FillBitmapMode, eBitmapMode );
435 :
436 : // additional settings for repeated bitmap
437 0 : 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 0 : else if ( eBitmapMode == BitmapMode_STRETCH && maBlipProps.moFillRect.has() )
462 : {
463 0 : geometry::IntegerRectangle2D aFillRect( maBlipProps.moFillRect.get() );
464 0 : awt::Size aOriginalSize( rGraphicHelper.getOriginalSize( xGraphic ) );
465 0 : if ( aOriginalSize.Width && aOriginalSize.Height )
466 : {
467 0 : text::GraphicCrop aGraphCrop( 0, 0, 0, 0 );
468 0 : if ( aFillRect.X1 )
469 0 : aGraphCrop.Left = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * aFillRect.X1 ) / 100000 );
470 0 : if ( aFillRect.Y1 )
471 0 : aGraphCrop.Top = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * aFillRect.Y1 ) / 100000 );
472 0 : if ( aFillRect.X2 )
473 0 : aGraphCrop.Right = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * aFillRect.X2 ) / 100000 );
474 0 : if ( aFillRect.Y2 )
475 0 : aGraphCrop.Bottom = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * aFillRect.Y2 ) / 100000 );
476 0 : rPropMap.setProperty(PROP_GraphicCrop, aGraphCrop);
477 : }
478 : }
479 0 : }
480 : }
481 0 : break;
482 :
483 : case XML_pattFill:
484 : {
485 0 : if( rPropMap.supportsProperty( SHAPEPROP_FillHatch ) )
486 : {
487 0 : Color aColor( maPatternProps.maPattFgColor );
488 0 : 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 0 : eFillStyle = FillStyle_HATCH;
493 0 : 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 0 : }
503 : }
504 : }
505 0 : 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 0 : rPropMap.setProperty( SHAPEPROP_FillStyle, eFillStyle );
515 : }
516 0 : }
517 :
518 :
519 :
520 0 : void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelper& rGraphicHelper, sal_Int32 nPhClr ) const
521 : {
522 0 : if( maBlipProps.mxGraphic.is() )
523 : {
524 : // created transformed graphic
525 0 : Reference< XGraphic > xGraphic = lclCheckAndApplyDuotoneTransform( maBlipProps, maBlipProps.mxGraphic, rGraphicHelper, nPhClr );
526 0 : xGraphic = lclCheckAndApplyChangeColorTransform( maBlipProps, xGraphic, rGraphicHelper, nPhClr );
527 :
528 0 : rPropMap.setProperty(PROP_Graphic, xGraphic);
529 :
530 : // do we still need to set GraphicURL as well? (TODO)
531 0 : OUString aGraphicUrl = rGraphicHelper.createGraphicObject( xGraphic );
532 0 : if( !aGraphicUrl.isEmpty() )
533 0 : rPropMap.setProperty(PROP_GraphicURL, aGraphicUrl);
534 :
535 : // cropping
536 0 : if ( maBlipProps.moClipRect.has() )
537 : {
538 0 : geometry::IntegerRectangle2D oClipRect( maBlipProps.moClipRect.get() );
539 0 : awt::Size aOriginalSize( rGraphicHelper.getOriginalSize( xGraphic ) );
540 0 : if ( aOriginalSize.Width && aOriginalSize.Height )
541 : {
542 0 : text::GraphicCrop aGraphCrop( 0, 0, 0, 0 );
543 0 : if ( oClipRect.X1 )
544 0 : aGraphCrop.Left = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X1 ) / 100000 );
545 0 : if ( oClipRect.Y1 )
546 0 : aGraphCrop.Top = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y1 ) / 100000 );
547 0 : if ( oClipRect.X2 )
548 0 : aGraphCrop.Right = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X2 ) / 100000 );
549 0 : if ( oClipRect.Y2 )
550 0 : aGraphCrop.Bottom = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y2 ) / 100000 );
551 0 : rPropMap.setProperty(PROP_GraphicCrop, aGraphCrop);
552 : }
553 0 : }
554 : }
555 :
556 : // color effect
557 0 : ColorMode eColorMode = ColorMode_STANDARD;
558 0 : 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 0 : rPropMap.setProperty(PROP_GraphicColorMode, eColorMode);
564 :
565 : // brightness and contrast
566 0 : sal_Int16 nBrightness = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moBrightness.get( 0 ) / PER_PERCENT, -100, 100 );
567 0 : if( nBrightness != 0 )
568 0 : rPropMap.setProperty(PROP_AdjustLuminance, nBrightness);
569 0 : sal_Int16 nContrast = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moContrast.get( 0 ) / PER_PERCENT, -100, 100 );
570 0 : if( nContrast != 0 )
571 0 : rPropMap.setProperty(PROP_AdjustContrast, nContrast);
572 :
573 : // Media content
574 0 : if( !maAudio.msEmbed.isEmpty() )
575 0 : rPropMap.setProperty(PROP_MediaURL, maAudio.msEmbed);
576 0 : }
577 :
578 :
579 :
580 : } // namespace drawingml
581 0 : } // namespace oox
582 :
583 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|