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