1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "oox/vml/vmlformatting.hxx" 29 30 #include <rtl/strbuf.hxx> 31 #include "oox/drawingml/color.hxx" 32 #include "oox/drawingml/drawingmltypes.hxx" 33 #include "oox/drawingml/fillproperties.hxx" 34 #include "oox/drawingml/lineproperties.hxx" 35 #include "oox/drawingml/shapepropertymap.hxx" 36 #include "oox/helper/attributelist.hxx" 37 #include "oox/helper/graphichelper.hxx" 38 39 namespace oox { 40 namespace vml { 41 42 // ============================================================================ 43 44 using namespace ::com::sun::star::geometry; 45 46 using ::oox::drawingml::Color; 47 using ::oox::drawingml::FillProperties; 48 using ::oox::drawingml::LineArrowProperties; 49 using ::oox::drawingml::LineProperties; 50 using ::oox::drawingml::ShapePropertyMap; 51 using ::rtl::OStringBuffer; 52 using ::rtl::OUString; 53 54 // ============================================================================ 55 56 namespace { 57 58 bool lclExtractDouble( double& orfValue, sal_Int32& ornEndPos, const OUString& rValue ) 59 { 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; 64 } 65 66 } // namespace 67 68 // ---------------------------------------------------------------------------- 69 70 /*static*/ bool ConversionHelper::separatePair( OUString& orValue1, OUString& orValue2, 71 const OUString& rValue, sal_Unicode cSep ) 72 { 73 sal_Int32 nSepPos = rValue.indexOf( cSep ); 74 if( nSepPos >= 0 ) 75 { 76 orValue1 = rValue.copy( 0, nSepPos ).trim(); 77 orValue2 = rValue.copy( nSepPos + 1 ).trim(); 78 } 79 else 80 { 81 orValue1 = rValue.trim(); 82 } 83 return (orValue1.getLength() > 0) && (orValue2.getLength() > 0); 84 } 85 86 /*static*/ bool ConversionHelper::decodeBool( const OUString& rValue ) 87 { 88 sal_Int32 nToken = AttributeConversion::decodeToken( rValue ); 89 // anything else than 't' or 'true' is considered to be false, as specified 90 return (nToken == XML_t) || (nToken == XML_true); 91 } 92 93 /*static*/ double ConversionHelper::decodePercent( const OUString& rValue, double fDefValue ) 94 { 95 if( rValue.getLength() == 0 ) 96 return fDefValue; 97 98 double fValue = 0.0; 99 sal_Int32 nEndPos = 0; 100 if( !lclExtractDouble( fValue, nEndPos, rValue ) ) 101 return fDefValue; 102 103 if( nEndPos == rValue.getLength() ) 104 return fValue; 105 106 if( (nEndPos + 1 == rValue.getLength()) && (rValue[ nEndPos ] == '%') ) 107 return fValue / 100.0; 108 109 OSL_ENSURE( false, "ConversionHelper::decodePercent - unknown measure unit" ); 110 return fDefValue; 111 } 112 113 /*static*/ sal_Int64 ConversionHelper::decodeMeasureToEmu( const GraphicHelper& rGraphicHelper, 114 const OUString& rValue, sal_Int32 nRefValue, bool bPixelX, bool bDefaultAsPixel ) 115 { 116 // default for missing values is 0 117 if( rValue.getLength() == 0 ) 118 return 0; 119 120 // TODO: according to spec, value may contain "auto" 121 if( rValue.equalsAscii( "auto" ) ) 122 { 123 OSL_ENSURE( false, "ConversionHelper::decodeMeasureToEmu - special value 'auto' must be handled by caller" ); 124 return nRefValue; 125 } 126 127 // extract the double value and find start position of unit characters 128 double fValue = 0.0; 129 sal_Int32 nEndPos = 0; 130 if( !lclExtractDouble( fValue, nEndPos, rValue ) || (fValue == 0.0) ) 131 return 0; 132 133 // process trailing unit, convert to EMU 134 static const OUString saPx = CREATE_OUSTRING( "px" ); 135 OUString aUnit; 136 if( (0 < nEndPos) && (nEndPos < rValue.getLength()) ) 137 aUnit = rValue.copy( nEndPos ); 138 else if( bDefaultAsPixel ) 139 aUnit = saPx; 140 // else default is EMU 141 142 if( aUnit.getLength() == 2 ) 143 { 144 sal_Unicode cChar1 = aUnit[ 0 ]; 145 sal_Unicode cChar2 = aUnit[ 1 ]; 146 if( (cChar1 == 'i') && (cChar2 == 'n') ) // 1 inch = 914,400 EMU 147 fValue *= 914400.0; 148 else if( (cChar1 == 'c') && (cChar2 == 'm') ) // 1 cm = 360,000 EMU 149 fValue *= 360000.0; 150 else if( (cChar1 == 'm') && (cChar2 == 'm') ) // 1 mm = 36,000 EMU 151 fValue *= 36000.0; 152 else if( (cChar1 == 'p') && (cChar2 == 't') ) // 1 point = 1/72 inch = 12,700 MEU 153 fValue *= 12700.0; 154 else if( (cChar1 == 'p') && (cChar2 == 'c') ) // 1 pica = 1/6 inch = 152,400 EMU 155 fValue *= 152400.0; 156 else if( (cChar1 == 'p') && (cChar2 == 'x') ) // 1 pixel, dependent on output device 157 fValue = static_cast< double >( ::oox::drawingml::convertHmmToEmu( 158 bPixelX ? 159 rGraphicHelper.convertScreenPixelXToHmm( fValue ) : 160 rGraphicHelper.convertScreenPixelYToHmm( fValue ) ) ); 161 } 162 else if( (aUnit.getLength() == 1) && (aUnit[ 0 ] == '%') ) 163 { 164 fValue *= nRefValue / 100.0; 165 } 166 else if( bDefaultAsPixel || (aUnit.getLength() > 0) ) // default as EMU and no unit -> do nothing 167 { 168 OSL_ENSURE( false, "ConversionHelper::decodeMeasureToEmu - unknown measure unit" ); 169 fValue = nRefValue; 170 } 171 return static_cast< sal_Int64 >( fValue + 0.5 ); 172 } 173 174 /*static*/ sal_Int32 ConversionHelper::decodeMeasureToHmm( const GraphicHelper& rGraphicHelper, 175 const OUString& rValue, sal_Int32 nRefValue, bool bPixelX, bool bDefaultAsPixel ) 176 { 177 return ::oox::drawingml::convertEmuToHmm( decodeMeasureToEmu( rGraphicHelper, rValue, nRefValue, bPixelX, bDefaultAsPixel ) ); 178 } 179 180 /*static*/ Color ConversionHelper::decodeColor( const GraphicHelper& rGraphicHelper, 181 const OptValue< OUString >& roVmlColor, const OptValue< double >& roVmlOpacity, 182 sal_Int32 nDefaultRgb, sal_Int32 nPrimaryRgb ) 183 { 184 Color aDmlColor; 185 186 // convert opacity 187 const sal_Int32 DML_FULL_OPAQUE = ::oox::drawingml::MAX_PERCENT; 188 double fOpacity = roVmlOpacity.get( 1.0 ); 189 sal_Int32 nOpacity = getLimitedValue< sal_Int32, double >( fOpacity * DML_FULL_OPAQUE, 0, DML_FULL_OPAQUE ); 190 if( nOpacity < DML_FULL_OPAQUE ) 191 aDmlColor.addTransformation( XML_alpha, nOpacity ); 192 193 // color attribute not present - set passed default color 194 if( !roVmlColor.has() ) 195 { 196 aDmlColor.setSrgbClr( nDefaultRgb ); 197 return aDmlColor; 198 } 199 200 // separate leading color name or RGB value from following palette index 201 OUString aColorName, aColorIndex; 202 separatePair( aColorName, aColorIndex, roVmlColor.get(), ' ' ); 203 204 // RGB colors in the format '#RRGGBB' 205 if( (aColorName.getLength() == 7) && (aColorName[ 0 ] == '#') ) 206 { 207 aDmlColor.setSrgbClr( aColorName.copy( 1 ).toInt32( 16 ) ); 208 return aDmlColor; 209 } 210 211 // RGB colors in the format '#RGB' 212 if( (aColorName.getLength() == 4) && (aColorName[ 0 ] == '#') ) 213 { 214 sal_Int32 nR = aColorName.copy( 1, 1 ).toInt32( 16 ) * 0x11; 215 sal_Int32 nG = aColorName.copy( 2, 1 ).toInt32( 16 ) * 0x11; 216 sal_Int32 nB = aColorName.copy( 3, 1 ).toInt32( 16 ) * 0x11; 217 aDmlColor.setSrgbClr( (nR << 16) | (nG << 8) | nB ); 218 return aDmlColor; 219 } 220 221 /* Predefined color names or system color names (resolve to RGB to detect 222 valid color name). */ 223 sal_Int32 nColorToken = AttributeConversion::decodeToken( aColorName ); 224 sal_Int32 nRgbValue = Color::getVmlPresetColor( nColorToken, API_RGB_TRANSPARENT ); 225 if( nRgbValue == API_RGB_TRANSPARENT ) 226 nRgbValue = rGraphicHelper.getSystemColor( nColorToken, API_RGB_TRANSPARENT ); 227 if( nRgbValue != API_RGB_TRANSPARENT ) 228 { 229 aDmlColor.setSrgbClr( nRgbValue ); 230 return aDmlColor; 231 } 232 233 // try palette colors enclosed in brackets 234 if( (aColorIndex.getLength() >= 3) && (aColorIndex[ 0 ] == '[') && (aColorIndex[ aColorIndex.getLength() - 1 ] == ']') ) 235 { 236 aDmlColor.setPaletteClr( aColorIndex.copy( 1, aColorIndex.getLength() - 2 ).toInt32() ); 237 return aDmlColor; 238 } 239 240 // try fill gradient modificator 'fill <modifier>(<amount>)' 241 if( (nPrimaryRgb != API_RGB_TRANSPARENT) && (nColorToken == XML_fill) ) 242 { 243 sal_Int32 nOpenParen = aColorIndex.indexOf( '(' ); 244 sal_Int32 nCloseParen = aColorIndex.indexOf( ')' ); 245 if( (2 <= nOpenParen) && (nOpenParen + 1 < nCloseParen) && (nCloseParen + 1 == aColorIndex.getLength()) ) 246 { 247 sal_Int32 nModToken = XML_TOKEN_INVALID; 248 switch( AttributeConversion::decodeToken( aColorIndex.copy( 0, nOpenParen ) ) ) 249 { 250 case XML_darken: nModToken = XML_shade; 251 case XML_lighten: nModToken = XML_tint; 252 } 253 sal_Int32 nValue = aColorIndex.copy( nOpenParen + 1, nCloseParen - nOpenParen - 1 ).toInt32(); 254 if( (nModToken != XML_TOKEN_INVALID) && (0 <= nValue) && (nValue < 255) ) 255 { 256 /* Simulate this modifier color by a color with related transformation. 257 The modifier amount has to be converted from the range [0;255] to 258 percentage [0;100000] used by DrawingML. */ 259 aDmlColor.setSrgbClr( nPrimaryRgb ); 260 aDmlColor.addTransformation( nModToken, static_cast< sal_Int32 >( nValue * ::oox::drawingml::MAX_PERCENT / 255 ) ); 261 return aDmlColor; 262 } 263 } 264 } 265 266 OSL_ENSURE( false, OStringBuffer( "ConversionHelper::decodeColor - invalid VML color name '" ). 267 append( OUStringToOString( roVmlColor.get(), RTL_TEXTENCODING_ASCII_US ) ).append( '\'' ).getStr() ); 268 aDmlColor.setSrgbClr( nDefaultRgb ); 269 return aDmlColor; 270 } 271 272 // ============================================================================ 273 274 namespace { 275 276 sal_Int64 lclGetEmu( const GraphicHelper& rGraphicHelper, const OptValue< OUString >& roValue, sal_Int64 nDefValue ) 277 { 278 return roValue.has() ? ConversionHelper::decodeMeasureToEmu( rGraphicHelper, roValue.get(), 0, false, false ) : nDefValue; 279 } 280 281 void lclGetDmlLineDash( OptValue< sal_Int32 >& oroPresetDash, LineProperties::DashStopVector& orCustomDash, const OptValue< OUString >& roDashStyle ) 282 { 283 if( roDashStyle.has() ) 284 { 285 const OUString& rDashStyle = roDashStyle.get(); 286 switch( AttributeConversion::decodeToken( rDashStyle ) ) 287 { 288 case XML_solid: oroPresetDash = XML_solid; return; 289 case XML_shortdot: oroPresetDash = XML_sysDot; return; 290 case XML_shortdash: oroPresetDash = XML_sysDash; return; 291 case XML_shortdashdot: oroPresetDash = XML_sysDashDot; return; 292 case XML_shortdashdotdot: oroPresetDash = XML_sysDashDotDot; return; 293 case XML_dot: oroPresetDash = XML_dot; return; 294 case XML_dash: oroPresetDash = XML_dash; return; 295 case XML_dashdot: oroPresetDash = XML_dashDot; return; 296 case XML_longdash: oroPresetDash = XML_lgDash; return; 297 case XML_longdashdot: oroPresetDash = XML_lgDashDot; return; 298 case XML_longdashdotdot: oroPresetDash = XML_lgDashDotDot; return; 299 300 // try to convert user-defined dash style 301 default: 302 { 303 ::std::vector< sal_Int32 > aValues; 304 sal_Int32 nIndex = 0; 305 while( nIndex >= 0 ) 306 aValues.push_back( rDashStyle.getToken( 0, ' ', nIndex ).toInt32() ); 307 size_t nPairs = aValues.size() / 2; // ignore last value if size is odd 308 for( size_t nPairIdx = 0; nPairIdx < nPairs; ++nPairIdx ) 309 orCustomDash.push_back( LineProperties::DashStop( aValues[ 2 * nPairIdx ], aValues[ 2 * nPairIdx + 1 ] ) ); 310 } 311 } 312 } 313 } 314 315 sal_Int32 lclGetDmlArrowType( const OptValue< sal_Int32 >& roArrowType ) 316 { 317 if( roArrowType.has() ) switch( roArrowType.get() ) 318 { 319 case XML_none: return XML_none; 320 case XML_block: return XML_triangle; 321 case XML_classic: return XML_stealth; 322 case XML_diamond: return XML_diamond; 323 case XML_oval: return XML_oval; 324 case XML_open: return XML_arrow; 325 } 326 return XML_none; 327 } 328 329 sal_Int32 lclGetDmlArrowWidth( const OptValue< sal_Int32 >& roArrowWidth ) 330 { 331 if( roArrowWidth.has() ) switch( roArrowWidth.get() ) 332 { 333 case XML_narrow: return XML_sm; 334 case XML_medium: return XML_med; 335 case XML_wide: return XML_lg; 336 } 337 return XML_med; 338 } 339 340 sal_Int32 lclGetDmlArrowLength( const OptValue< sal_Int32 >& roArrowLength ) 341 { 342 if( roArrowLength.has() ) switch( roArrowLength.get() ) 343 { 344 case XML_short: return XML_sm; 345 case XML_medium: return XML_med; 346 case XML_long: return XML_lg; 347 } 348 return XML_med; 349 } 350 351 void lclConvertArrow( LineArrowProperties& orArrowProp, const StrokeArrowModel& rStrokeArrow ) 352 { 353 orArrowProp.moArrowType = lclGetDmlArrowType( rStrokeArrow.moArrowType ); 354 orArrowProp.moArrowWidth = lclGetDmlArrowWidth( rStrokeArrow.moArrowWidth ); 355 orArrowProp.moArrowLength = lclGetDmlArrowLength( rStrokeArrow.moArrowLength ); 356 } 357 358 sal_Int32 lclGetDmlLineCompound( const OptValue< sal_Int32 >& roLineStyle ) 359 { 360 if( roLineStyle.has() ) switch( roLineStyle.get() ) 361 { 362 case XML_single: return XML_sng; 363 case XML_thinThin: return XML_dbl; 364 case XML_thinThick: return XML_thinThick; 365 case XML_thickThin: return XML_thickThin; 366 case XML_thickBetweenThin: return XML_tri; 367 } 368 return XML_sng; 369 } 370 371 sal_Int32 lclGetDmlLineCap( const OptValue< sal_Int32 >& roEndCap ) 372 { 373 if( roEndCap.has() ) switch( roEndCap.get() ) 374 { 375 case XML_flat: return XML_flat; 376 case XML_square: return XML_sq; 377 case XML_round: return XML_rnd; 378 } 379 return XML_flat; // different defaults in VML (flat) and DrawingML (square) 380 } 381 382 sal_Int32 lclGetDmlLineJoint( const OptValue< sal_Int32 >& roJoinStyle ) 383 { 384 if( roJoinStyle.has() ) switch( roJoinStyle.get() ) 385 { 386 case XML_round: return XML_round; 387 case XML_bevel: return XML_bevel; 388 case XML_miter: return XML_miter; 389 } 390 return XML_round; 391 } 392 393 } // namespace 394 395 // ============================================================================ 396 397 void StrokeArrowModel::assignUsed( const StrokeArrowModel& rSource ) 398 { 399 moArrowType.assignIfUsed( rSource.moArrowType ); 400 moArrowWidth.assignIfUsed( rSource.moArrowWidth ); 401 moArrowLength.assignIfUsed( rSource.moArrowLength ); 402 } 403 404 // ============================================================================ 405 406 void StrokeModel::assignUsed( const StrokeModel& rSource ) 407 { 408 moStroked.assignIfUsed( rSource.moStroked ); 409 maStartArrow.assignUsed( rSource.maStartArrow ); 410 maEndArrow.assignUsed( rSource.maEndArrow ); 411 moColor.assignIfUsed( rSource.moColor ); 412 moOpacity.assignIfUsed( rSource.moOpacity ); 413 moWeight.assignIfUsed( rSource.moWeight ); 414 moDashStyle.assignIfUsed( rSource.moDashStyle ); 415 moLineStyle.assignIfUsed( rSource.moLineStyle ); 416 moEndCap.assignIfUsed( rSource.moEndCap ); 417 moJoinStyle.assignIfUsed( rSource.moJoinStyle ); 418 } 419 420 void StrokeModel::pushToPropMap( ShapePropertyMap& rPropMap, const GraphicHelper& rGraphicHelper ) const 421 { 422 /* Convert VML line formatting to DrawingML line formatting and let the 423 DrawingML code do the hard work. */ 424 LineProperties aLineProps; 425 426 if( moStroked.get( true ) ) 427 { 428 aLineProps.maLineFill.moFillType = XML_solidFill; 429 lclConvertArrow( aLineProps.maStartArrow, maStartArrow ); 430 lclConvertArrow( aLineProps.maEndArrow, maEndArrow ); 431 aLineProps.maLineFill.maFillColor = ConversionHelper::decodeColor( rGraphicHelper, moColor, moOpacity, API_RGB_BLACK ); 432 aLineProps.moLineWidth = getLimitedValue< sal_Int32, sal_Int64 >( lclGetEmu( rGraphicHelper, moWeight, 1 ), 0, SAL_MAX_INT32 ); 433 lclGetDmlLineDash( aLineProps.moPresetDash, aLineProps.maCustomDash, moDashStyle ); 434 aLineProps.moLineCompound = lclGetDmlLineCompound( moLineStyle ); 435 aLineProps.moLineCap = lclGetDmlLineCap( moEndCap ); 436 aLineProps.moLineJoint = lclGetDmlLineJoint( moJoinStyle ); 437 } 438 else 439 { 440 aLineProps.maLineFill.moFillType = XML_noFill; 441 } 442 443 aLineProps.pushToPropMap( rPropMap, rGraphicHelper ); 444 } 445 446 // ============================================================================ 447 448 void FillModel::assignUsed( const FillModel& rSource ) 449 { 450 moFilled.assignIfUsed( rSource.moFilled ); 451 moColor.assignIfUsed( rSource.moColor ); 452 moOpacity.assignIfUsed( rSource.moOpacity ); 453 moColor2.assignIfUsed( rSource.moColor2 ); 454 moOpacity2.assignIfUsed( rSource.moOpacity2 ); 455 moType.assignIfUsed( rSource.moType ); 456 moAngle.assignIfUsed( rSource.moAngle ); 457 moFocus.assignIfUsed( rSource.moFocus ); 458 moFocusPos.assignIfUsed( rSource.moFocusPos ); 459 moFocusSize.assignIfUsed( rSource.moFocusSize ); 460 moBitmapPath.assignIfUsed( rSource.moBitmapPath ); 461 moRotate.assignIfUsed( rSource.moRotate ); 462 } 463 464 void FillModel::pushToPropMap( ShapePropertyMap& rPropMap, const GraphicHelper& rGraphicHelper ) const 465 { 466 /* Convert VML fill formatting to DrawingML fill formatting and let the 467 DrawingML code do the hard work. */ 468 FillProperties aFillProps; 469 470 if( moFilled.get( true ) ) 471 { 472 sal_Int32 nFillType = moType.get( XML_solid ); 473 switch( nFillType ) 474 { 475 case XML_gradient: 476 case XML_gradientRadial: 477 { 478 aFillProps.moFillType = XML_gradFill; 479 aFillProps.maGradientProps.moRotateWithShape = moRotate.get( false ); 480 double fFocus = moFocus.get( 0.0 ); 481 482 // prepare colors 483 Color aColor1 = ConversionHelper::decodeColor( rGraphicHelper, moColor, moOpacity, API_RGB_WHITE ); 484 Color aColor2 = ConversionHelper::decodeColor( rGraphicHelper, moColor2, moOpacity2, API_RGB_WHITE, aColor1.getColor( rGraphicHelper ) ); 485 486 // type XML_gradient is linear or axial gradient 487 if( nFillType == XML_gradient ) 488 { 489 // normalize angle to range [0;360) degrees 490 sal_Int32 nVmlAngle = getIntervalValue< sal_Int32, sal_Int32 >( moAngle.get( 0 ), 0, 360 ); 491 492 // focus of -50% or 50% is axial gradient 493 if( ((-0.75 <= fFocus) && (fFocus <= -0.25)) || ((0.25 <= fFocus) && (fFocus <= 0.75)) ) 494 { 495 /* According to spec, focus of 50% is outer-to-inner, 496 and -50% is inner-to-outer (color to color2). 497 BUT: For angles >= 180 deg., the behaviour is 498 reversed... that's not spec'ed of course. So, 499 [0;180) deg. and 50%, or [180;360) deg. and -50% is 500 outer-to-inner in fact. */ 501 bool bOuterToInner = (fFocus > 0.0) == (nVmlAngle < 180); 502 // simulate axial gradient by 3-step DrawingML gradient 503 const Color& rOuterColor = bOuterToInner ? aColor1 : aColor2; 504 const Color& rInnerColor = bOuterToInner ? aColor2 : aColor1; 505 aFillProps.maGradientProps.maGradientStops[ 0.0 ] = aFillProps.maGradientProps.maGradientStops[ 1.0 ] = rOuterColor; 506 aFillProps.maGradientProps.maGradientStops[ 0.5 ] = rInnerColor; 507 } 508 else // focus of -100%, 0%, and 100% is linear gradient 509 { 510 /* According to spec, focus of -100% or 100% swaps the 511 start and stop colors, effectively reversing the 512 gradient. BUT: For angles >= 180 deg., the 513 behaviour is reversed. This means that in this case 514 a focus of 0% swaps the gradient. */ 515 if( ((fFocus < -0.75) || (fFocus > 0.75)) == (nVmlAngle < 180) ) 516 (nVmlAngle += 180) %= 360; 517 // set the start and stop colors 518 aFillProps.maGradientProps.maGradientStops[ 0.0 ] = aColor1; 519 aFillProps.maGradientProps.maGradientStops[ 1.0 ] = aColor2; 520 } 521 522 // VML counts counterclockwise from bottom, DrawingML clockwise from left 523 sal_Int32 nDmlAngle = (630 - nVmlAngle) % 360; 524 aFillProps.maGradientProps.moShadeAngle = nDmlAngle * ::oox::drawingml::PER_DEGREE; 525 } 526 else // XML_gradientRadial is rectangular gradient 527 { 528 aFillProps.maGradientProps.moGradientPath = XML_rect; 529 // convert VML focus position and size to DrawingML fill-to-rect 530 DoublePair aFocusPos = moFocusPos.get( DoublePair( 0.0, 0.0 ) ); 531 DoublePair aFocusSize = moFocusSize.get( DoublePair( 0.0, 0.0 ) ); 532 double fLeft = getLimitedValue< double, double >( aFocusPos.first, 0.0, 1.0 ); 533 double fTop = getLimitedValue< double, double >( aFocusPos.second, 0.0, 1.0 ); 534 double fRight = getLimitedValue< double, double >( fLeft + aFocusSize.first, fLeft, 1.0 ); 535 double fBottom = getLimitedValue< double, double >( fTop + aFocusSize.second, fTop, 1.0 ); 536 aFillProps.maGradientProps.moFillToRect = IntegerRectangle2D( 537 static_cast< sal_Int32 >( fLeft * ::oox::drawingml::MAX_PERCENT ), 538 static_cast< sal_Int32 >( fTop * ::oox::drawingml::MAX_PERCENT ), 539 static_cast< sal_Int32 >( (1.0 - fRight) * ::oox::drawingml::MAX_PERCENT ), 540 static_cast< sal_Int32 >( (1.0 - fBottom) * ::oox::drawingml::MAX_PERCENT ) ); 541 542 // set the start and stop colors (focus of 0% means outer-to-inner) 543 bool bOuterToInner = (-0.5 <= fFocus) && (fFocus <= 0.5); 544 aFillProps.maGradientProps.maGradientStops[ 0.0 ] = bOuterToInner ? aColor2 : aColor1; 545 aFillProps.maGradientProps.maGradientStops[ 1.0 ] = bOuterToInner ? aColor1 : aColor2; 546 } 547 } 548 break; 549 550 case XML_pattern: 551 case XML_tile: 552 case XML_frame: 553 { 554 if( moBitmapPath.has() && moBitmapPath.get().getLength() > 0 ) 555 { 556 aFillProps.maBlipProps.mxGraphic = rGraphicHelper.importEmbeddedGraphic( moBitmapPath.get() ); 557 if( aFillProps.maBlipProps.mxGraphic.is() ) 558 { 559 aFillProps.moFillType = XML_blipFill; 560 aFillProps.maBlipProps.moBitmapMode = (nFillType == XML_frame) ? XML_stretch : XML_tile; 561 break; // do not break if bitmap is missing, but run to XML_solid instead 562 } 563 } 564 } 565 // run-through to XML_solid in case of missing bitmap path intended! 566 567 case XML_solid: 568 default: 569 { 570 aFillProps.moFillType = XML_solidFill; 571 // fill color (default is white) 572 aFillProps.maFillColor = ConversionHelper::decodeColor( rGraphicHelper, moColor, moOpacity, API_RGB_WHITE ); 573 } 574 } 575 } 576 else 577 { 578 aFillProps.moFillType = XML_noFill; 579 } 580 581 aFillProps.pushToPropMap( rPropMap, rGraphicHelper ); 582 } 583 584 // ============================================================================ 585 586 } // namespace vml 587 } // namespace oox 588