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