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/vmlshapecontext.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "oox/vml/vmldrawing.hxx" 31*cdf0e10cSrcweir #include "oox/vml/vmlshape.hxx" 32*cdf0e10cSrcweir #include "oox/vml/vmlshapecontainer.hxx" 33*cdf0e10cSrcweir #include "oox/vml/vmltextboxcontext.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir namespace oox { 36*cdf0e10cSrcweir namespace vml { 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir // ============================================================================ 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir using namespace ::com::sun::star::awt; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir using ::oox::core::ContextHandler2; 43*cdf0e10cSrcweir using ::oox::core::ContextHandler2Helper; 44*cdf0e10cSrcweir using ::oox::core::ContextHandlerRef; 45*cdf0e10cSrcweir using ::rtl::OUString; 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir // ============================================================================ 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir namespace { 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir /** Returns the boolean value from the specified VML attribute (if present). 52*cdf0e10cSrcweir */ 53*cdf0e10cSrcweir OptValue< bool > lclDecodeBool( const AttributeList& rAttribs, sal_Int32 nToken ) 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir OptValue< OUString > oValue = rAttribs.getString( nToken ); 56*cdf0e10cSrcweir if( oValue.has() ) return OptValue< bool >( ConversionHelper::decodeBool( oValue.get() ) ); 57*cdf0e10cSrcweir return OptValue< bool >(); 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir /** Returns the percentage value from the specified VML attribute (if present). 61*cdf0e10cSrcweir The value will be normalized (1.0 is returned for 100%). 62*cdf0e10cSrcweir */ 63*cdf0e10cSrcweir OptValue< double > lclDecodePercent( const AttributeList& rAttribs, sal_Int32 nToken, double fDefValue ) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir OptValue< OUString > oValue = rAttribs.getString( nToken ); 66*cdf0e10cSrcweir if( oValue.has() ) return OptValue< double >( ConversionHelper::decodePercent( oValue.get(), fDefValue ) ); 67*cdf0e10cSrcweir return OptValue< double >(); 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir /** Returns the integer value pair from the specified VML attribute (if present). 71*cdf0e10cSrcweir */ 72*cdf0e10cSrcweir OptValue< Int32Pair > lclDecodeInt32Pair( const AttributeList& rAttribs, sal_Int32 nToken ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir OptValue< OUString > oValue = rAttribs.getString( nToken ); 75*cdf0e10cSrcweir OptValue< Int32Pair > oRetValue; 76*cdf0e10cSrcweir if( oValue.has() ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir OUString aValue1, aValue2; 79*cdf0e10cSrcweir ConversionHelper::separatePair( aValue1, aValue2, oValue.get(), ',' ); 80*cdf0e10cSrcweir oRetValue = Int32Pair( aValue1.toInt32(), aValue2.toInt32() ); 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir return oRetValue; 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir /** Returns the percentage pair from the specified VML attribute (if present). 86*cdf0e10cSrcweir */ 87*cdf0e10cSrcweir OptValue< DoublePair > lclDecodePercentPair( const AttributeList& rAttribs, sal_Int32 nToken ) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir OptValue< OUString > oValue = rAttribs.getString( nToken ); 90*cdf0e10cSrcweir OptValue< DoublePair > oRetValue; 91*cdf0e10cSrcweir if( oValue.has() ) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir OUString aValue1, aValue2; 94*cdf0e10cSrcweir ConversionHelper::separatePair( aValue1, aValue2, oValue.get(), ',' ); 95*cdf0e10cSrcweir oRetValue = DoublePair( 96*cdf0e10cSrcweir ConversionHelper::decodePercent( aValue1, 0.0 ), 97*cdf0e10cSrcweir ConversionHelper::decodePercent( aValue2, 0.0 ) ); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir return oRetValue; 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir /** Returns the boolean value from the passed string of an attribute in the x: 103*cdf0e10cSrcweir namespace (VML for spreadsheets). Supported values: f, t, False, True. 104*cdf0e10cSrcweir @param bDefaultForEmpty Default value for the empty string. 105*cdf0e10cSrcweir */ 106*cdf0e10cSrcweir bool lclDecodeVmlxBool( const OUString& rValue, bool bDefaultForEmpty ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir if( rValue.getLength() == 0 ) return bDefaultForEmpty; 109*cdf0e10cSrcweir sal_Int32 nToken = AttributeConversion::decodeToken( rValue ); 110*cdf0e10cSrcweir // anything else than 't' or 'True' is considered to be false, as specified 111*cdf0e10cSrcweir return (nToken == XML_t) || (nToken == XML_True); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir } // namespace 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir // ============================================================================ 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir ShapeLayoutContext::ShapeLayoutContext( ContextHandler2Helper& rParent, Drawing& rDrawing ) : 119*cdf0e10cSrcweir ContextHandler2( rParent ), 120*cdf0e10cSrcweir mrDrawing( rDrawing ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir ContextHandlerRef ShapeLayoutContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir switch( nElement ) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir case O_TOKEN( idmap ): 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir OUString aBlockIds = rAttribs.getString( XML_data, OUString() ); 132*cdf0e10cSrcweir sal_Int32 nIndex = 0; 133*cdf0e10cSrcweir while( nIndex >= 0 ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir OUString aToken = aBlockIds.getToken( 0, ' ', nIndex ).trim(); 136*cdf0e10cSrcweir if( aToken.getLength() > 0 ) 137*cdf0e10cSrcweir mrDrawing.registerBlockId( aToken.toInt32() ); 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir break; 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir return 0; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir // ============================================================================ 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir ClientDataContext::ClientDataContext( ContextHandler2Helper& rParent, 148*cdf0e10cSrcweir ClientData& rClientData, const AttributeList& rAttribs ) : 149*cdf0e10cSrcweir ContextHandler2( rParent ), 150*cdf0e10cSrcweir mrClientData( rClientData ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir mrClientData.mnObjType = rAttribs.getToken( XML_ObjectType, XML_TOKEN_INVALID ); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir ContextHandlerRef ClientDataContext::onCreateContext( sal_Int32 /*nElement*/, const AttributeList& /*rAttribs*/ ) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir if( isRootElement() ) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir maElementText = OUString(); 160*cdf0e10cSrcweir return this; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir return 0; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir void ClientDataContext::onCharacters( const OUString& rChars ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir /* Empty but existing elements have special meaning, e.g. 'true'. Collect 168*cdf0e10cSrcweir existing text and convert it in onEndElement(). */ 169*cdf0e10cSrcweir maElementText = rChars; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir void ClientDataContext::onEndElement() 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir switch( getCurrentElement() ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir case VMLX_TOKEN( Anchor ): mrClientData.maAnchor = maElementText; break; 177*cdf0e10cSrcweir case VMLX_TOKEN( FmlaMacro ): mrClientData.maFmlaMacro = maElementText; break; 178*cdf0e10cSrcweir case VMLX_TOKEN( FmlaPict ): mrClientData.maFmlaPict = maElementText; break; 179*cdf0e10cSrcweir case VMLX_TOKEN( FmlaLink ): mrClientData.maFmlaLink = maElementText; break; 180*cdf0e10cSrcweir case VMLX_TOKEN( FmlaRange ): mrClientData.maFmlaRange = maElementText; break; 181*cdf0e10cSrcweir case VMLX_TOKEN( FmlaGroup ): mrClientData.maFmlaGroup = maElementText; break; 182*cdf0e10cSrcweir case VMLX_TOKEN( TextHAlign ): mrClientData.mnTextHAlign = AttributeConversion::decodeToken( maElementText ); break; 183*cdf0e10cSrcweir case VMLX_TOKEN( TextVAlign ): mrClientData.mnTextVAlign = AttributeConversion::decodeToken( maElementText ); break; 184*cdf0e10cSrcweir case VMLX_TOKEN( Column ): mrClientData.mnCol = maElementText.toInt32(); break; 185*cdf0e10cSrcweir case VMLX_TOKEN( Row ): mrClientData.mnRow = maElementText.toInt32(); break; 186*cdf0e10cSrcweir case VMLX_TOKEN( Checked ): mrClientData.mnChecked = maElementText.toInt32(); break; 187*cdf0e10cSrcweir case VMLX_TOKEN( DropStyle ): mrClientData.mnDropStyle = AttributeConversion::decodeToken( maElementText ); break; 188*cdf0e10cSrcweir case VMLX_TOKEN( DropLines ): mrClientData.mnDropLines = maElementText.toInt32(); break; 189*cdf0e10cSrcweir case VMLX_TOKEN( Val ): mrClientData.mnVal = maElementText.toInt32(); break; 190*cdf0e10cSrcweir case VMLX_TOKEN( Min ): mrClientData.mnMin = maElementText.toInt32(); break; 191*cdf0e10cSrcweir case VMLX_TOKEN( Max ): mrClientData.mnMax = maElementText.toInt32(); break; 192*cdf0e10cSrcweir case VMLX_TOKEN( Inc ): mrClientData.mnInc = maElementText.toInt32(); break; 193*cdf0e10cSrcweir case VMLX_TOKEN( Page ): mrClientData.mnPage = maElementText.toInt32(); break; 194*cdf0e10cSrcweir case VMLX_TOKEN( SelType ): mrClientData.mnSelType = AttributeConversion::decodeToken( maElementText ); break; 195*cdf0e10cSrcweir case VMLX_TOKEN( VTEdit ): mrClientData.mnVTEdit = maElementText.toInt32(); break; 196*cdf0e10cSrcweir case VMLX_TOKEN( PrintObject ): mrClientData.mbPrintObject = lclDecodeVmlxBool( maElementText, true ); break; 197*cdf0e10cSrcweir case VMLX_TOKEN( Visible ): mrClientData.mbVisible = lclDecodeVmlxBool( maElementText, true ); break; 198*cdf0e10cSrcweir case VMLX_TOKEN( DDE ): mrClientData.mbDde = lclDecodeVmlxBool( maElementText, true ); break; 199*cdf0e10cSrcweir case VMLX_TOKEN( NoThreeD ): mrClientData.mbNo3D = lclDecodeVmlxBool( maElementText, true ); break; 200*cdf0e10cSrcweir case VMLX_TOKEN( NoThreeD2 ): mrClientData.mbNo3D2 = lclDecodeVmlxBool( maElementText, true ); break; 201*cdf0e10cSrcweir case VMLX_TOKEN( MultiLine ): mrClientData.mbMultiLine = lclDecodeVmlxBool( maElementText, true ); break; 202*cdf0e10cSrcweir case VMLX_TOKEN( VScroll ): mrClientData.mbVScroll = lclDecodeVmlxBool( maElementText, true ); break; 203*cdf0e10cSrcweir case VMLX_TOKEN( SecretEdit ): mrClientData.mbSecretEdit = lclDecodeVmlxBool( maElementText, true ); break; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir // ============================================================================ 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir ShapeContextBase::ShapeContextBase( ContextHandler2Helper& rParent ) : 210*cdf0e10cSrcweir ContextHandler2( rParent ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir /*static*/ ContextHandlerRef ShapeContextBase::createShapeContext( ContextHandler2Helper& rParent, 215*cdf0e10cSrcweir ShapeContainer& rShapes, sal_Int32 nElement, const AttributeList& rAttribs ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir switch( nElement ) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir case O_TOKEN( shapelayout ): 220*cdf0e10cSrcweir return new ShapeLayoutContext( rParent, rShapes.getDrawing() ); 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir case VML_TOKEN( shapetype ): 223*cdf0e10cSrcweir return new ShapeTypeContext( rParent, rShapes.createShapeType(), rAttribs ); 224*cdf0e10cSrcweir case VML_TOKEN( group ): 225*cdf0e10cSrcweir return new GroupShapeContext( rParent, rShapes.createShape< GroupShape >(), rAttribs ); 226*cdf0e10cSrcweir case VML_TOKEN( shape ): 227*cdf0e10cSrcweir return new ShapeContext( rParent, rShapes.createShape< ComplexShape >(), rAttribs ); 228*cdf0e10cSrcweir case VML_TOKEN( rect ): 229*cdf0e10cSrcweir case VML_TOKEN( roundrect ): 230*cdf0e10cSrcweir return new ShapeContext( rParent, rShapes.createShape< RectangleShape >(), rAttribs ); 231*cdf0e10cSrcweir case VML_TOKEN( oval ): 232*cdf0e10cSrcweir return new ShapeContext( rParent, rShapes.createShape< EllipseShape >(), rAttribs ); 233*cdf0e10cSrcweir case VML_TOKEN( polyline ): 234*cdf0e10cSrcweir return new ShapeContext( rParent, rShapes.createShape< PolyLineShape >(), rAttribs ); 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir // TODO: 237*cdf0e10cSrcweir case VML_TOKEN( arc ): 238*cdf0e10cSrcweir case VML_TOKEN( curve ): 239*cdf0e10cSrcweir case VML_TOKEN( line ): 240*cdf0e10cSrcweir case VML_TOKEN( diagram ): 241*cdf0e10cSrcweir case VML_TOKEN( image ): 242*cdf0e10cSrcweir return new ShapeContext( rParent, rShapes.createShape< ComplexShape >(), rAttribs ); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir return 0; 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir // ============================================================================ 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir ShapeTypeContext::ShapeTypeContext( ContextHandler2Helper& rParent, ShapeType& rShapeType, const AttributeList& rAttribs ) : 250*cdf0e10cSrcweir ShapeContextBase( rParent ), 251*cdf0e10cSrcweir mrTypeModel( rShapeType.getTypeModel() ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir // shape identifier and shape name 254*cdf0e10cSrcweir bool bHasOspid = rAttribs.hasAttribute( O_TOKEN( spid ) ); 255*cdf0e10cSrcweir mrTypeModel.maShapeId = rAttribs.getXString( bHasOspid ? O_TOKEN( spid ) : XML_id, OUString() ); 256*cdf0e10cSrcweir OSL_ENSURE( mrTypeModel.maShapeId.getLength() > 0, "ShapeTypeContext::ShapeTypeContext - missing shape identifier" ); 257*cdf0e10cSrcweir // if the o:spid attribute exists, the id attribute contains the user-defined shape name 258*cdf0e10cSrcweir if( bHasOspid ) 259*cdf0e10cSrcweir mrTypeModel.maShapeName = rAttribs.getXString( XML_id, OUString() ); 260*cdf0e10cSrcweir // builtin shape type identifier 261*cdf0e10cSrcweir mrTypeModel.moShapeType = rAttribs.getInteger( O_TOKEN( spt ) ); 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir // coordinate system position/size, CSS style 264*cdf0e10cSrcweir mrTypeModel.moCoordPos = lclDecodeInt32Pair( rAttribs, XML_coordorigin ); 265*cdf0e10cSrcweir mrTypeModel.moCoordSize = lclDecodeInt32Pair( rAttribs, XML_coordsize ); 266*cdf0e10cSrcweir setStyle( rAttribs.getString( XML_style, OUString() ) ); 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir // stroke settings (may be overridden by v:stroke element later) 269*cdf0e10cSrcweir mrTypeModel.maStrokeModel.moStroked = lclDecodeBool( rAttribs, XML_stroked ); 270*cdf0e10cSrcweir mrTypeModel.maStrokeModel.moColor = rAttribs.getString( XML_strokecolor ); 271*cdf0e10cSrcweir mrTypeModel.maStrokeModel.moWeight = rAttribs.getString( XML_strokeweight ); 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir // fill settings (may be overridden by v:fill element later) 274*cdf0e10cSrcweir mrTypeModel.maFillModel.moFilled = lclDecodeBool( rAttribs, XML_filled ); 275*cdf0e10cSrcweir mrTypeModel.maFillModel.moColor = rAttribs.getString( XML_fillcolor ); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir ContextHandlerRef ShapeTypeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir if( isRootElement() ) switch( nElement ) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir case VML_TOKEN( stroke ): 283*cdf0e10cSrcweir mrTypeModel.maStrokeModel.moStroked.assignIfUsed( lclDecodeBool( rAttribs, XML_on ) ); 284*cdf0e10cSrcweir mrTypeModel.maStrokeModel.maStartArrow.moArrowType = rAttribs.getToken( XML_startarrow ); 285*cdf0e10cSrcweir mrTypeModel.maStrokeModel.maStartArrow.moArrowWidth = rAttribs.getToken( XML_startarrowwidth ); 286*cdf0e10cSrcweir mrTypeModel.maStrokeModel.maStartArrow.moArrowLength = rAttribs.getToken( XML_startarrowlength ); 287*cdf0e10cSrcweir mrTypeModel.maStrokeModel.maEndArrow.moArrowType = rAttribs.getToken( XML_endarrow ); 288*cdf0e10cSrcweir mrTypeModel.maStrokeModel.maEndArrow.moArrowWidth = rAttribs.getToken( XML_endarrowwidth ); 289*cdf0e10cSrcweir mrTypeModel.maStrokeModel.maEndArrow.moArrowLength = rAttribs.getToken( XML_endarrowlength ); 290*cdf0e10cSrcweir mrTypeModel.maStrokeModel.moColor.assignIfUsed( rAttribs.getString( XML_color ) ); 291*cdf0e10cSrcweir mrTypeModel.maStrokeModel.moOpacity = lclDecodePercent( rAttribs, XML_opacity, 1.0 ); 292*cdf0e10cSrcweir mrTypeModel.maStrokeModel.moWeight.assignIfUsed( rAttribs.getString( XML_weight ) ); 293*cdf0e10cSrcweir mrTypeModel.maStrokeModel.moDashStyle = rAttribs.getString( XML_dashstyle ); 294*cdf0e10cSrcweir mrTypeModel.maStrokeModel.moLineStyle = rAttribs.getToken( XML_linestyle ); 295*cdf0e10cSrcweir mrTypeModel.maStrokeModel.moEndCap = rAttribs.getToken( XML_endcap ); 296*cdf0e10cSrcweir mrTypeModel.maStrokeModel.moJoinStyle = rAttribs.getToken( XML_joinstyle ); 297*cdf0e10cSrcweir break; 298*cdf0e10cSrcweir case VML_TOKEN( fill ): 299*cdf0e10cSrcweir mrTypeModel.maFillModel.moFilled.assignIfUsed( lclDecodeBool( rAttribs, XML_on ) ); 300*cdf0e10cSrcweir mrTypeModel.maFillModel.moColor.assignIfUsed( rAttribs.getString( XML_color ) ); 301*cdf0e10cSrcweir mrTypeModel.maFillModel.moOpacity = lclDecodePercent( rAttribs, XML_opacity, 1.0 ); 302*cdf0e10cSrcweir mrTypeModel.maFillModel.moColor2 = rAttribs.getString( XML_color2 ); 303*cdf0e10cSrcweir mrTypeModel.maFillModel.moOpacity2 = lclDecodePercent( rAttribs, XML_opacity2, 1.0 ); 304*cdf0e10cSrcweir mrTypeModel.maFillModel.moType = rAttribs.getToken( XML_type ); 305*cdf0e10cSrcweir mrTypeModel.maFillModel.moAngle = rAttribs.getInteger( XML_angle ); 306*cdf0e10cSrcweir mrTypeModel.maFillModel.moFocus = lclDecodePercent( rAttribs, XML_focus, 0.0 ); 307*cdf0e10cSrcweir mrTypeModel.maFillModel.moFocusPos = lclDecodePercentPair( rAttribs, XML_focusposition ); 308*cdf0e10cSrcweir mrTypeModel.maFillModel.moFocusSize = lclDecodePercentPair( rAttribs, XML_focussize ); 309*cdf0e10cSrcweir mrTypeModel.maFillModel.moBitmapPath = decodeFragmentPath( rAttribs, O_TOKEN( relid ) ); 310*cdf0e10cSrcweir mrTypeModel.maFillModel.moRotate = lclDecodeBool( rAttribs, XML_rotate ); 311*cdf0e10cSrcweir break; 312*cdf0e10cSrcweir case VML_TOKEN( imagedata ): 313*cdf0e10cSrcweir mrTypeModel.moGraphicPath = decodeFragmentPath( rAttribs, O_TOKEN( relid ) ); 314*cdf0e10cSrcweir mrTypeModel.moGraphicTitle = rAttribs.getString( O_TOKEN( title ) ); 315*cdf0e10cSrcweir break; 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir return 0; 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir OptValue< OUString > ShapeTypeContext::decodeFragmentPath( const AttributeList& rAttribs, sal_Int32 nToken ) const 321*cdf0e10cSrcweir { 322*cdf0e10cSrcweir OptValue< OUString > oFragmentPath; 323*cdf0e10cSrcweir OptValue< OUString > oRelId = rAttribs.getString( nToken ); 324*cdf0e10cSrcweir if( oRelId.has() ) 325*cdf0e10cSrcweir oFragmentPath = getFragmentPathFromRelId( oRelId.get() ); 326*cdf0e10cSrcweir return oFragmentPath; 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir void ShapeTypeContext::setStyle( const OUString& rStyle ) 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir sal_Int32 nIndex = 0; 332*cdf0e10cSrcweir while( nIndex >= 0 ) 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir OUString aName, aValue; 335*cdf0e10cSrcweir if( ConversionHelper::separatePair( aName, aValue, rStyle.getToken( 0, ';', nIndex ), ':' ) ) 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir if( aName.equalsAscii( "position" ) ) mrTypeModel.maPosition = aValue; 338*cdf0e10cSrcweir else if( aName.equalsAscii( "left" ) ) mrTypeModel.maLeft = aValue; 339*cdf0e10cSrcweir else if( aName.equalsAscii( "top" ) ) mrTypeModel.maTop = aValue; 340*cdf0e10cSrcweir else if( aName.equalsAscii( "width" ) ) mrTypeModel.maWidth = aValue; 341*cdf0e10cSrcweir else if( aName.equalsAscii( "height" ) ) mrTypeModel.maHeight = aValue; 342*cdf0e10cSrcweir else if( aName.equalsAscii( "margin-left" ) ) mrTypeModel.maMarginLeft = aValue; 343*cdf0e10cSrcweir else if( aName.equalsAscii( "margin-top" ) ) mrTypeModel.maMarginTop = aValue; 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir // ============================================================================ 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir ShapeContext::ShapeContext( ContextHandler2Helper& rParent, ShapeBase& rShape, const AttributeList& rAttribs ) : 351*cdf0e10cSrcweir ShapeTypeContext( rParent, rShape, rAttribs ), 352*cdf0e10cSrcweir mrShapeModel( rShape.getShapeModel() ) 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir // collect shape specific attributes 355*cdf0e10cSrcweir mrShapeModel.maType = rAttribs.getXString( XML_type, OUString() ); 356*cdf0e10cSrcweir // polyline path 357*cdf0e10cSrcweir setPoints( rAttribs.getString( XML_points, OUString() ) ); 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir ContextHandlerRef ShapeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir // Excel specific shape client data 363*cdf0e10cSrcweir if( isRootElement() ) switch( nElement ) 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir case VML_TOKEN( textbox ): 366*cdf0e10cSrcweir return new TextBoxContext( *this, mrShapeModel.createTextBox(), rAttribs ); 367*cdf0e10cSrcweir case VMLX_TOKEN( ClientData ): 368*cdf0e10cSrcweir return new ClientDataContext( *this, mrShapeModel.createClientData(), rAttribs ); 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir // handle remaining stuff in base class 371*cdf0e10cSrcweir return ShapeTypeContext::onCreateContext( nElement, rAttribs ); 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir void ShapeContext::setPoints( const OUString& rPoints ) 375*cdf0e10cSrcweir { 376*cdf0e10cSrcweir mrShapeModel.maPoints.clear(); 377*cdf0e10cSrcweir sal_Int32 nIndex = 0; 378*cdf0e10cSrcweir while( nIndex >= 0 ) 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir sal_Int32 nX = rPoints.getToken( 0, ',', nIndex ).toInt32(); 381*cdf0e10cSrcweir sal_Int32 nY = rPoints.getToken( 0, ',', nIndex ).toInt32(); 382*cdf0e10cSrcweir mrShapeModel.maPoints.push_back( Point( nX, nY ) ); 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir // ============================================================================ 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir GroupShapeContext::GroupShapeContext( ContextHandler2Helper& rParent, GroupShape& rShape, const AttributeList& rAttribs ) : 389*cdf0e10cSrcweir ShapeContext( rParent, rShape, rAttribs ), 390*cdf0e10cSrcweir mrShapes( rShape.getChildren() ) 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir ContextHandlerRef GroupShapeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir // try to create a context of an embedded shape 397*cdf0e10cSrcweir ContextHandlerRef xContext = createShapeContext( *this, mrShapes, nElement, rAttribs ); 398*cdf0e10cSrcweir // handle remaining stuff of this shape in base class 399*cdf0e10cSrcweir return xContext.get() ? xContext : ShapeContext::onCreateContext( nElement, rAttribs ); 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir // ============================================================================ 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir } // namespace vml 405*cdf0e10cSrcweir } // namespace oox 406*cdf0e10cSrcweir 407