Update ooo320-m1
[ooovba.git] / oox / source / vml / vmlformatting.cxx
bloba45054a77b52171f8ff6a1ff3140692fe8efa191
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vmlformatting.cxx,v $
10 * $Revision: 1.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/vml/vmlformatting.hxx"
32 #include <rtl/strbuf.hxx>
33 #include "tokens.hxx"
34 #include "oox/token/tokenmap.hxx"
35 #include "oox/helper/propertymap.hxx"
36 #include "oox/core/filterbase.hxx"
37 #include "oox/drawingml/color.hxx"
38 #include "oox/drawingml/drawingmltypes.hxx"
39 #include "oox/drawingml/fillproperties.hxx"
40 #include "oox/drawingml/lineproperties.hxx"
42 using ::rtl::OStringBuffer;
43 using ::rtl::OUString;
44 using ::com::sun::star::geometry::IntegerRectangle2D;
45 using ::oox::core::FilterBase;
46 using ::oox::drawingml::Color;
47 using ::oox::drawingml::FillProperties;
48 using ::oox::drawingml::LineArrowProperties;
49 using ::oox::drawingml::LineProperties;
51 namespace oox {
52 namespace vml {
54 // ============================================================================
56 namespace {
58 bool lclExtractDouble( double& orfValue, sal_Int32& ornEndPos, const OUString& rValue )
60 // extract the double value and find start position of unit characters
61 rtl_math_ConversionStatus eConvStatus = rtl_math_ConversionStatus_Ok;
62 orfValue = ::rtl::math::stringToDouble( rValue, '.', '\0', &eConvStatus, &ornEndPos );
63 return eConvStatus == rtl_math_ConversionStatus_Ok;
66 } // namespace
68 // ----------------------------------------------------------------------------
70 /*static*/ bool ConversionHelper::separatePair( OUString& orValue1, OUString& orValue2,
71 const OUString& rValue, sal_Unicode cSep )
73 sal_Int32 nSepPos = rValue.indexOf( cSep );
74 if( nSepPos >= 0 )
76 orValue1 = rValue.copy( 0, nSepPos ).trim();
77 orValue2 = rValue.copy( nSepPos + 1 ).trim();
79 else
81 orValue1 = rValue.trim();
83 return (orValue1.getLength() > 0) && (orValue2.getLength() > 0);
86 /*static*/ bool ConversionHelper::decodeBool( const OUString& rValue )
88 // anything else than 't' or 'true' is considered to be false, as specified
89 return ((rValue.getLength() == 1) && (rValue[ 0 ] == 't')) || (rValue == CREATE_OUSTRING( "true" ));
92 /*static*/ double ConversionHelper::decodePercent( const OUString& rValue, double fDefValue )
94 if( rValue.getLength() == 0 )
95 return fDefValue;
97 double fValue = 0.0;
98 sal_Int32 nEndPos = 0;
99 if( !lclExtractDouble( fValue, nEndPos, rValue ) )
100 return fDefValue;
102 if( nEndPos == rValue.getLength() )
103 return fValue;
105 if( (nEndPos + 1 == rValue.getLength()) && (rValue[ nEndPos ] == '%') )
106 return fValue / 100.0;
108 OSL_ENSURE( false, "ConversionHelper::decodePercent - unknown measure unit" );
109 return fDefValue;
112 /*static*/ sal_Int32 ConversionHelper::decodeMeasureToEmu( const FilterBase& rFilter,
113 const OUString& rValue, sal_Int32 nRefValue, bool bPixelX, bool bDefaultAsPixel )
115 // default for missing values is 0
116 if( rValue.getLength() == 0 )
117 return 0;
119 // TODO: according to spec, value may contain "auto"
120 if( rValue.equalsAscii( "auto" ) )
122 OSL_ENSURE( false, "ConversionHelper::decodeMeasureToEmu - special value 'auto' must be handled by caller" );
123 return nRefValue;
126 // extract the double value and find start position of unit characters
127 double fValue = 0.0;
128 sal_Int32 nEndPos = 0;
129 if( !lclExtractDouble( fValue, nEndPos, rValue ) || (fValue == 0.0) )
130 return 0;
132 // process trailing unit, convert to EMU
133 static const OUString saPx = CREATE_OUSTRING( "px" );
134 OUString aUnit;
135 if( (0 < nEndPos) && (nEndPos < rValue.getLength()) )
136 aUnit = rValue.copy( nEndPos );
137 else if( bDefaultAsPixel )
138 aUnit = saPx;
139 // else default is EMU
141 if( aUnit.getLength() == 2 )
143 sal_Unicode cChar1 = aUnit[ 0 ];
144 sal_Unicode cChar2 = aUnit[ 1 ];
145 if( (cChar1 == 'i') && (cChar2 == 'n') ) // 1 inch = 914,400 EMU
146 fValue *= 914400.0;
147 else if( (cChar1 == 'c') && (cChar2 == 'm') ) // 1 cm = 360,000 EMU
148 fValue *= 360000.0;
149 else if( (cChar1 == 'm') && (cChar2 == 'm') ) // 1 mm = 36,000 EMU
150 fValue *= 36000.0;
151 else if( (cChar1 == 'p') && (cChar2 == 't') ) // 1 point = 1/72 inch = 12,700 MEU
152 fValue *= 12700.0;
153 else if( (cChar1 == 'p') && (cChar2 == 'c') ) // 1 pica = 1/6 inch = 152,400 EMU
154 fValue *= 152400.0;
155 else if( (cChar1 == 'p') && (cChar2 == 'x') ) // 1 pixel, dependent on output device, factor 360 to convert 1/100mm to EMU
156 fValue = bPixelX ? rFilter.convertScreenPixelX( 360.0 * fValue ) : rFilter.convertScreenPixelY( 360.0 * fValue );
158 else if( (aUnit.getLength() == 1) && (aUnit[ 0 ] == '%') )
160 fValue *= nRefValue / 100.0;
162 else if( bDefaultAsPixel || (aUnit.getLength() > 0) ) // default as EMU and no unit -> do nothing
164 OSL_ENSURE( false, "ConversionHelper::decodeMeasureToEmu - unknown measure unit" );
165 fValue = nRefValue;
167 return static_cast< sal_Int32 >( fValue + 0.5 );
170 /*static*/ sal_Int32 ConversionHelper::decodeMeasureToHmm( const FilterBase& rFilter,
171 const OUString& rValue, sal_Int32 nRefValue, bool bPixelX, bool bDefaultAsPixel )
173 return (decodeMeasureToEmu( rFilter, rValue, nRefValue, bPixelX, bDefaultAsPixel ) + 180) / 360;
176 // ============================================================================
178 namespace {
180 /** Converts a VML color attribute to a DrawingML color.
182 @param orDmlColor (out-parameter) The destination DrawingML color.
184 @param roVmlColor The VML string representation of the color. If existing,
185 this can be a 6-digit hexadecimal RGB value with leading '#' character,
186 a predefined color name (e.g. 'black', 'red', etc.), the index into an
187 application defined color palette in brackets with leading color name
188 (e.g. 'red [9]' or 'windowColor [64]'), or a color modifier used in
189 one-color gradients (e.g. 'fill darken(128)' or 'fill lighten(0)'.
191 @param roVmlOpacity The opacity of the color. If existing, this should be
192 a floating-point value in the range [0.0;1.0].
194 @param nDefaultRgb Deafult RGB color used if the parameter roVmlColor is
195 empty.
197 @param nPrimaryRgb If set to something else than API_RGB_TRANSPARENT,
198 specifies the color to be used to resolve the color modifiers used in
199 one-color gradients.
201 void lclGetColor( Color& orDmlColor, const FilterBase& rFilter,
202 const OptValue< OUString >& roVmlColor, const OptValue< double >& roVmlOpacity,
203 sal_Int32 nDefaultRgb, sal_Int32 nPrimaryRgb = API_RGB_TRANSPARENT )
205 // convert opacity
206 const sal_Int32 DML_FULL_OPAQUE = ::oox::drawingml::MAX_PERCENT;
207 double fOpacity = roVmlOpacity.get( 1.0 );
208 sal_Int32 nOpacity = getLimitedValue< sal_Int32, double >( fOpacity * DML_FULL_OPAQUE, 0, DML_FULL_OPAQUE );
209 if( nOpacity < DML_FULL_OPAQUE )
210 orDmlColor.addTransformation( XML_alpha, nOpacity );
212 // color attribute not present - set passed default color
213 if( !roVmlColor.has() )
215 orDmlColor.setSrgbClr( nDefaultRgb );
216 return;
219 // separate leading color name or RGB value from following palette index
220 OUString aColorName, aColorIndex;
221 ConversionHelper::separatePair( aColorName, aColorIndex, roVmlColor.get(), ' ' );
223 // RGB colors in the format '#RRGGBB'
224 if( (aColorName.getLength() == 7) && (aColorName[ 0 ] == '#') )
226 orDmlColor.setSrgbClr( aColorName.copy( 1 ).toInt32( 16 ) );
227 return;
230 // RGB colors in the format '#RGB'
231 if( (aColorName.getLength() == 4) && (aColorName[ 0 ] == '#') )
233 sal_Int32 nR = aColorName.copy( 1, 1 ).toInt32( 16 ) * 0x11;
234 sal_Int32 nG = aColorName.copy( 2, 1 ).toInt32( 16 ) * 0x11;
235 sal_Int32 nB = aColorName.copy( 3, 1 ).toInt32( 16 ) * 0x11;
236 orDmlColor.setSrgbClr( (nR << 16) | (nG << 8) | nB );
237 return;
240 /* Predefined color names or system color names (resolve to RGB to detect
241 valid color name). */
242 sal_Int32 nColorToken = StaticTokenMap::get().getTokenFromUnicode( aColorName );
243 sal_Int32 nRgbValue = Color::getVmlPresetColor( nColorToken, API_RGB_TRANSPARENT );
244 if( nRgbValue == API_RGB_TRANSPARENT )
245 nRgbValue = rFilter.getSystemColor( nColorToken, API_RGB_TRANSPARENT );
246 if( nRgbValue != API_RGB_TRANSPARENT )
248 orDmlColor.setSrgbClr( nRgbValue );
249 return;
252 // try palette colors enclosed in brackets
253 if( (aColorIndex.getLength() >= 3) && (aColorIndex[ 0 ] == '[') && (aColorIndex[ aColorIndex.getLength() - 1 ] == ']') )
255 orDmlColor.setPaletteClr( aColorIndex.copy( 1, aColorIndex.getLength() - 2 ).toInt32() );
256 return;
259 // try fill gradient modificator 'fill <modifier>(<amount>)'
260 if( (nPrimaryRgb != API_RGB_TRANSPARENT) && (nColorToken == XML_fill) )
262 sal_Int32 nOpenParen = aColorIndex.indexOf( '(' );
263 sal_Int32 nCloseParen = aColorIndex.indexOf( ')' );
264 if( (2 <= nOpenParen) && (nOpenParen + 1 < nCloseParen) && (nCloseParen + 1 == aColorIndex.getLength()) )
266 sal_Int32 nModToken = XML_TOKEN_INVALID;
267 switch( StaticTokenMap::get().getTokenFromUnicode( aColorIndex.copy( 0, nOpenParen ) ) )
269 case XML_darken: nModToken = XML_shade;
270 case XML_lighten: nModToken = XML_tint;
272 sal_Int32 nValue = aColorIndex.copy( nOpenParen + 1, nCloseParen - nOpenParen - 1 ).toInt32();
273 if( (nModToken != XML_TOKEN_INVALID) && (0 <= nValue) && (nValue < 255) )
275 /* Simulate this modifier color by a color with related transformation.
276 The modifier amount has to be converted from the range [0;255] to
277 percentage [0;100000] used by DrawingML. */
278 orDmlColor.setSrgbClr( nPrimaryRgb );
279 orDmlColor.addTransformation( nModToken, static_cast< sal_Int32 >( nValue * ::oox::drawingml::MAX_PERCENT / 255 ) );
280 return;
285 OSL_ENSURE( false, OStringBuffer( "lclGetColor - invalid VML color name '" ).
286 append( OUStringToOString( roVmlColor.get(), RTL_TEXTENCODING_ASCII_US ) ).append( '\'' ).getStr() );
287 orDmlColor.setSrgbClr( nDefaultRgb );
290 sal_Int32 lclGetEmu( const FilterBase& rFilter, const OptValue< OUString >& roValue, sal_Int32 nDefValue )
292 return roValue.has() ? ConversionHelper::decodeMeasureToEmu( rFilter, roValue.get(), 0, false, false ) : nDefValue;
295 void lclGetDmlLineDash( OptValue< sal_Int32 >& oroPresetDash, LineProperties::DashStopVector& orCustomDash, const OptValue< OUString >& roDashStyle )
297 if( roDashStyle.has() )
299 const OUString& rDashStyle = roDashStyle.get();
300 switch( StaticTokenMap::get().getTokenFromUnicode( rDashStyle ) )
302 case XML_solid: oroPresetDash = XML_solid; return;
303 case XML_shortdot: oroPresetDash = XML_sysDot; return;
304 case XML_shortdash: oroPresetDash = XML_sysDash; return;
305 case XML_shortdashdot: oroPresetDash = XML_sysDashDot; return;
306 case XML_shortdashdotdot: oroPresetDash = XML_sysDashDotDot; return;
307 case XML_dot: oroPresetDash = XML_dot; return;
308 case XML_dash: oroPresetDash = XML_dash; return;
309 case XML_dashdot: oroPresetDash = XML_dashDot; return;
310 case XML_longdash: oroPresetDash = XML_lgDash; return;
311 case XML_longdashdot: oroPresetDash = XML_lgDashDot; return;
312 case XML_longdashdotdot: oroPresetDash = XML_lgDashDotDot; return;
314 // try to convert user-defined dash style
315 default:
317 ::std::vector< sal_Int32 > aValues;
318 sal_Int32 nIndex = 0;
319 while( nIndex >= 0 )
320 aValues.push_back( rDashStyle.getToken( 0, ' ', nIndex ).toInt32() );
321 size_t nPairs = aValues.size() / 2; // ignore last value if size is odd
322 for( size_t nPairIdx = 0; nPairIdx < nPairs; ++nPairIdx )
323 orCustomDash.push_back( LineProperties::DashStop( aValues[ 2 * nPairIdx ], aValues[ 2 * nPairIdx + 1 ] ) );
329 sal_Int32 lclGetDmlArrowType( const OptValue< sal_Int32 >& roArrowType )
331 if( roArrowType.has() ) switch( roArrowType.get() )
333 case XML_none: return XML_none;
334 case XML_block: return XML_triangle;
335 case XML_classic: return XML_stealth;
336 case XML_diamond: return XML_diamond;
337 case XML_oval: return XML_oval;
338 case XML_open: return XML_arrow;
340 return XML_none;
343 sal_Int32 lclGetDmlArrowWidth( const OptValue< sal_Int32 >& roArrowWidth )
345 if( roArrowWidth.has() ) switch( roArrowWidth.get() )
347 case XML_narrow: return XML_sm;
348 case XML_medium: return XML_med;
349 case XML_wide: return XML_lg;
351 return XML_med;
354 sal_Int32 lclGetDmlArrowLength( const OptValue< sal_Int32 >& roArrowLength )
356 if( roArrowLength.has() ) switch( roArrowLength.get() )
358 case XML_short: return XML_sm;
359 case XML_medium: return XML_med;
360 case XML_long: return XML_lg;
362 return XML_med;
365 void lclConvertArrow( LineArrowProperties& orArrowProp, const StrokeArrowModel& rStrokeArrow )
367 orArrowProp.moArrowType = lclGetDmlArrowType( rStrokeArrow.moArrowType );
368 orArrowProp.moArrowWidth = lclGetDmlArrowWidth( rStrokeArrow.moArrowWidth );
369 orArrowProp.moArrowLength = lclGetDmlArrowLength( rStrokeArrow.moArrowLength );
372 sal_Int32 lclGetDmlLineCompound( const OptValue< sal_Int32 >& roLineStyle )
374 if( roLineStyle.has() ) switch( roLineStyle.get() )
376 case XML_single: return XML_sng;
377 case XML_thinThin: return XML_dbl;
378 case XML_thinThick: return XML_thinThick;
379 case XML_thickThin: return XML_thickThin;
380 case XML_thickBetweenThin: return XML_tri;
382 return XML_sng;
385 sal_Int32 lclGetDmlLineCap( const OptValue< sal_Int32 >& roEndCap )
387 if( roEndCap.has() ) switch( roEndCap.get() )
389 case XML_flat: return XML_flat;
390 case XML_square: return XML_sq;
391 case XML_round: return XML_rnd;
393 return XML_flat; // different defaults in VML (flat) and DrawingML (square)
396 sal_Int32 lclGetDmlLineJoint( const OptValue< sal_Int32 >& roJoinStyle )
398 if( roJoinStyle.has() ) switch( roJoinStyle.get() )
400 case XML_round: return XML_round;
401 case XML_bevel: return XML_bevel;
402 case XML_miter: return XML_miter;
404 return XML_round;
407 } // namespace
409 // ============================================================================
411 void StrokeArrowModel::assignUsed( const StrokeArrowModel& rSource )
413 moArrowType.assignIfUsed( rSource.moArrowType );
414 moArrowWidth.assignIfUsed( rSource.moArrowWidth );
415 moArrowLength.assignIfUsed( rSource.moArrowLength );
418 // ============================================================================
420 void StrokeModel::assignUsed( const StrokeModel& rSource )
422 moStroked.assignIfUsed( rSource.moStroked );
423 maStartArrow.assignUsed( rSource.maStartArrow );
424 maEndArrow.assignUsed( rSource.maEndArrow );
425 moColor.assignIfUsed( rSource.moColor );
426 moOpacity.assignIfUsed( rSource.moOpacity );
427 moWeight.assignIfUsed( rSource.moWeight );
428 moDashStyle.assignIfUsed( rSource.moDashStyle );
429 moLineStyle.assignIfUsed( rSource.moLineStyle );
430 moEndCap.assignIfUsed( rSource.moEndCap );
431 moJoinStyle.assignIfUsed( rSource.moJoinStyle );
434 void StrokeModel::pushToPropMap( PropertyMap& rPropMap, const FilterBase& rFilter ) const
436 /* Convert VML line formatting to DrawingML line formatting and let the
437 DrawingML code do the hard work. */
438 LineProperties aLineProps;
440 if( moStroked.get( true ) )
442 aLineProps.maLineFill.moFillType = XML_solidFill;
443 lclConvertArrow( aLineProps.maStartArrow, maStartArrow );
444 lclConvertArrow( aLineProps.maEndArrow, maEndArrow );
445 lclGetColor( aLineProps.maLineFill.maFillColor, rFilter, moColor, moOpacity, API_RGB_BLACK );
446 aLineProps.moLineWidth = lclGetEmu( rFilter, moWeight, 1 );
447 lclGetDmlLineDash( aLineProps.moPresetDash, aLineProps.maCustomDash, moDashStyle );
448 aLineProps.moLineCompound = lclGetDmlLineCompound( moLineStyle );
449 aLineProps.moLineCap = lclGetDmlLineCap( moEndCap );
450 aLineProps.moLineJoint = lclGetDmlLineJoint( moJoinStyle );
452 else
454 aLineProps.maLineFill.moFillType = XML_noFill;
457 aLineProps.pushToPropMap( rPropMap, rFilter, rFilter.getModelObjectHelper() );
460 // ============================================================================
462 void FillModel::assignUsed( const FillModel& rSource )
464 moFilled.assignIfUsed( rSource.moFilled );
465 moColor.assignIfUsed( rSource.moColor );
466 moOpacity.assignIfUsed( rSource.moOpacity );
467 moColor2.assignIfUsed( rSource.moColor2 );
468 moOpacity2.assignIfUsed( rSource.moOpacity2 );
469 moType.assignIfUsed( rSource.moType );
470 moAngle.assignIfUsed( rSource.moAngle );
471 moFocus.assignIfUsed( rSource.moFocus );
472 moFocusPos.assignIfUsed( rSource.moFocusPos );
473 moFocusSize.assignIfUsed( rSource.moFocusSize );
474 moRotate.assignIfUsed( rSource.moRotate );
477 void FillModel::pushToPropMap( PropertyMap& rPropMap, const FilterBase& rFilter ) const
479 /* Convert VML fill formatting to DrawingML fill formatting and let the
480 DrawingML code do the hard work. */
481 FillProperties aFillProps;
483 if( moFilled.get( true ) )
485 sal_Int32 nFillType = moType.get( XML_solid );
486 switch( nFillType )
488 case XML_gradient:
489 case XML_gradientRadial:
491 aFillProps.moFillType = XML_gradFill;
492 aFillProps.maGradientProps.moRotateWithShape = moRotate.get( false );
493 double fFocus = moFocus.get( 0.0 );
495 // prepare colors
496 Color aColor1, aColor2;
497 lclGetColor( aColor1, rFilter, moColor, moOpacity, API_RGB_WHITE );
498 lclGetColor( aColor2, rFilter, moColor2, moOpacity2, API_RGB_WHITE, aColor1.getColor( rFilter ) );
500 // type XML_gradient is linear or axial gradient
501 if( nFillType == XML_gradient )
503 // normalize angle to range [0;360) degrees
504 sal_Int32 nVmlAngle = getIntervalValue< sal_Int32, sal_Int32 >( moAngle.get( 0 ), 0, 360 );
506 // focus of -50% or 50% is axial gradient
507 if( ((-0.75 <= fFocus) && (fFocus <= -0.25)) || ((0.25 <= fFocus) && (fFocus <= 0.75)) )
509 /* According to spec, focus of 50% is outer-to-inner,
510 and -50% is inner-to-outer (color to color2).
511 BUT: For angles >= 180 deg., the behaviour is
512 reversed... that's not spec'ed of course. So,
513 [0;180) deg. and 50%, or [180;360) deg. and -50% is
514 outer-to-inner in fact. */
515 bool bOuterToInner = (fFocus > 0.0) == (nVmlAngle < 180);
516 // simulate axial gradient by 3-step DrawingML gradient
517 const Color& rOuterColor = bOuterToInner ? aColor1 : aColor2;
518 const Color& rInnerColor = bOuterToInner ? aColor2 : aColor1;
519 aFillProps.maGradientProps.maGradientStops[ 0.0 ] = aFillProps.maGradientProps.maGradientStops[ 1.0 ] = rOuterColor;
520 aFillProps.maGradientProps.maGradientStops[ 0.5 ] = rInnerColor;
522 else // focus of -100%, 0%, and 100% is linear gradient
524 /* According to spec, focus of -100% or 100% swaps the
525 start and stop colors, effectively reversing the
526 gradient. BUT: For angles >= 180 deg., the
527 behaviour is reversed. This means that in this case
528 a focus of 0% swaps the gradient. */
529 if( ((fFocus < -0.75) || (fFocus > 0.75)) == (nVmlAngle < 180) )
530 (nVmlAngle += 180) %= 360;
531 // set the start and stop colors
532 aFillProps.maGradientProps.maGradientStops[ 0.0 ] = aColor1;
533 aFillProps.maGradientProps.maGradientStops[ 1.0 ] = aColor2;
536 // VML counts counterclockwise from bottom, DrawingML clockwise from left
537 sal_Int32 nDmlAngle = (630 - nVmlAngle) % 360;
538 aFillProps.maGradientProps.moShadeAngle = nDmlAngle * ::oox::drawingml::PER_DEGREE;
540 else // XML_gradientRadial is rectangular gradient
542 aFillProps.maGradientProps.moGradientPath = XML_rect;
543 // convert VML focus position and size to DrawingML fill-to-rect
544 DoublePair aFocusPos = moFocusPos.get( DoublePair( 0.0, 0.0 ) );
545 DoublePair aFocusSize = moFocusSize.get( DoublePair( 0.0, 0.0 ) );
546 double fLeft = getLimitedValue< double, double >( aFocusPos.first, 0.0, 1.0 );
547 double fTop = getLimitedValue< double, double >( aFocusPos.second, 0.0, 1.0 );
548 double fRight = getLimitedValue< double, double >( fLeft + aFocusSize.first, fLeft, 1.0 );
549 double fBottom = getLimitedValue< double, double >( fTop + aFocusSize.second, fTop, 1.0 );
550 aFillProps.maGradientProps.moFillToRect = IntegerRectangle2D(
551 static_cast< sal_Int32 >( fLeft * ::oox::drawingml::MAX_PERCENT ),
552 static_cast< sal_Int32 >( fTop * ::oox::drawingml::MAX_PERCENT ),
553 static_cast< sal_Int32 >( (1.0 - fRight) * ::oox::drawingml::MAX_PERCENT ),
554 static_cast< sal_Int32 >( (1.0 - fBottom) * ::oox::drawingml::MAX_PERCENT ) );
556 // set the start and stop colors (focus of 0% means outer-to-inner)
557 bool bOuterToInner = (-0.5 <= fFocus) && (fFocus <= 0.5);
558 aFillProps.maGradientProps.maGradientStops[ 0.0 ] = bOuterToInner ? aColor2 : aColor1;
559 aFillProps.maGradientProps.maGradientStops[ 1.0 ] = bOuterToInner ? aColor1 : aColor2;
562 break;
564 case XML_solid:
565 default:
567 aFillProps.moFillType = XML_solidFill;
568 // fill color (default is white)
569 lclGetColor( aFillProps.maFillColor, rFilter, moColor, moOpacity, API_RGB_WHITE );
573 else
575 aFillProps.moFillType = XML_noFill;
578 aFillProps.pushToPropMap( rPropMap, rFilter, rFilter.getModelObjectHelper() );
581 // ============================================================================
583 } // namespace vml
584 } // namespace oox