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