Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "oox/vml/vmlshapecontext.hxx"
21 :
22 : #include "oox/core/xmlfilterbase.hxx"
23 : #include "oox/vml/vmldrawing.hxx"
24 : #include "oox/vml/vmlshape.hxx"
25 : #include "oox/vml/vmlshapecontainer.hxx"
26 : #include "oox/vml/vmltextboxcontext.hxx"
27 :
28 : namespace oox {
29 : namespace vml {
30 :
31 : // ============================================================================
32 :
33 : using namespace ::com::sun::star;
34 :
35 : using ::oox::core::ContextHandler2;
36 : using ::oox::core::ContextHandler2Helper;
37 : using ::oox::core::ContextHandlerRef;
38 : using ::rtl::OUString;
39 :
40 : // ============================================================================
41 :
42 : namespace {
43 :
44 : /** Returns the boolean value from the specified VML attribute (if present).
45 : */
46 149 : OptValue< bool > lclDecodeBool( const AttributeList& rAttribs, sal_Int32 nToken )
47 : {
48 149 : OptValue< OUString > oValue = rAttribs.getString( nToken );
49 149 : if( oValue.has() ) return OptValue< bool >( ConversionHelper::decodeBool( oValue.get() ) );
50 119 : return OptValue< bool >();
51 : }
52 :
53 : /** Returns the percentage value from the specified VML attribute (if present).
54 : The value will be normalized (1.0 is returned for 100%).
55 : */
56 23 : OptValue< double > lclDecodePercent( const AttributeList& rAttribs, sal_Int32 nToken, double fDefValue )
57 : {
58 23 : OptValue< OUString > oValue = rAttribs.getString( nToken );
59 23 : if( oValue.has() ) return OptValue< double >( ConversionHelper::decodePercent( oValue.get(), fDefValue ) );
60 23 : return OptValue< double >();
61 : }
62 :
63 : /** Returns the integer value pair from the specified VML attribute (if present).
64 : */
65 86 : OptValue< Int32Pair > lclDecodeInt32Pair( const AttributeList& rAttribs, sal_Int32 nToken )
66 : {
67 86 : OptValue< OUString > oValue = rAttribs.getString( nToken );
68 86 : OptValue< Int32Pair > oRetValue;
69 86 : if( oValue.has() )
70 : {
71 23 : OUString aValue1, aValue2;
72 23 : ConversionHelper::separatePair( aValue1, aValue2, oValue.get(), ',' );
73 23 : oRetValue = Int32Pair( aValue1.toInt32(), aValue2.toInt32() );
74 : }
75 86 : return oRetValue;
76 : }
77 :
78 : /** Returns the percentage pair from the specified VML attribute (if present).
79 : */
80 6 : OptValue< DoublePair > lclDecodePercentPair( const AttributeList& rAttribs, sal_Int32 nToken )
81 : {
82 6 : OptValue< OUString > oValue = rAttribs.getString( nToken );
83 6 : OptValue< DoublePair > oRetValue;
84 6 : if( oValue.has() )
85 : {
86 0 : OUString aValue1, aValue2;
87 0 : ConversionHelper::separatePair( aValue1, aValue2, oValue.get(), ',' );
88 : oRetValue = DoublePair(
89 0 : ConversionHelper::decodePercent( aValue1, 0.0 ),
90 0 : ConversionHelper::decodePercent( aValue2, 0.0 ) );
91 : }
92 6 : return oRetValue;
93 : }
94 :
95 : /** Returns the boolean value from the passed string of an attribute in the x:
96 : namespace (VML for spreadsheets). Supported values: f, t, False, True.
97 : @param bDefaultForEmpty Default value for the empty string.
98 : */
99 1 : bool lclDecodeVmlxBool( const OUString& rValue, bool bDefaultForEmpty )
100 : {
101 1 : if( rValue.isEmpty() ) return bDefaultForEmpty;
102 0 : sal_Int32 nToken = AttributeConversion::decodeToken( rValue );
103 : // anything else than 't' or 'True' is considered to be false, as specified
104 0 : return (nToken == XML_t) || (nToken == XML_True);
105 : }
106 :
107 : } // namespace
108 :
109 : // ============================================================================
110 :
111 1 : ShapeLayoutContext::ShapeLayoutContext( ContextHandler2Helper& rParent, Drawing& rDrawing ) :
112 : ContextHandler2( rParent ),
113 1 : mrDrawing( rDrawing )
114 : {
115 1 : }
116 :
117 :
118 1 : ContextHandlerRef ShapeLayoutContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
119 : {
120 1 : switch( nElement )
121 : {
122 : case O_TOKEN( idmap ):
123 : {
124 1 : OUString aBlockIds = rAttribs.getString( XML_data, OUString() );
125 1 : sal_Int32 nIndex = 0;
126 3 : while( nIndex >= 0 )
127 : {
128 1 : OUString aToken = aBlockIds.getToken( 0, ' ', nIndex ).trim();
129 1 : if( !aToken.isEmpty() )
130 1 : mrDrawing.registerBlockId( aToken.toInt32() );
131 2 : }
132 : }
133 1 : break;
134 : }
135 1 : return 0;
136 : }
137 :
138 : // ============================================================================
139 :
140 2 : ClientDataContext::ClientDataContext( ContextHandler2Helper& rParent,
141 : ClientData& rClientData, const AttributeList& rAttribs ) :
142 : ContextHandler2( rParent ),
143 2 : mrClientData( rClientData )
144 : {
145 2 : mrClientData.mnObjType = rAttribs.getToken( XML_ObjectType, XML_TOKEN_INVALID );
146 2 : }
147 :
148 13 : ContextHandlerRef ClientDataContext::onCreateContext( sal_Int32 /*nElement*/, const AttributeList& /*rAttribs*/ )
149 : {
150 13 : if( isRootElement() )
151 : {
152 13 : maElementText = OUString();
153 13 : return this;
154 : }
155 0 : return 0;
156 : }
157 :
158 17 : void ClientDataContext::onCharacters( const OUString& rChars )
159 : {
160 : /* Empty but existing elements have special meaning, e.g. 'true'. Collect
161 : existing text and convert it in onEndElement(). */
162 17 : maElementText = rChars;
163 17 : }
164 :
165 15 : void ClientDataContext::onEndElement()
166 : {
167 15 : switch( getCurrentElement() )
168 : {
169 2 : case VMLX_TOKEN( Anchor ): mrClientData.maAnchor = maElementText; break;
170 0 : case VMLX_TOKEN( FmlaMacro ): mrClientData.maFmlaMacro = maElementText; break;
171 0 : case VMLX_TOKEN( FmlaPict ): mrClientData.maFmlaPict = maElementText; break;
172 0 : case VMLX_TOKEN( FmlaLink ): mrClientData.maFmlaLink = maElementText; break;
173 0 : case VMLX_TOKEN( FmlaRange ): mrClientData.maFmlaRange = maElementText; break;
174 0 : case VMLX_TOKEN( FmlaGroup ): mrClientData.maFmlaGroup = maElementText; break;
175 0 : case VMLX_TOKEN( TextHAlign ): mrClientData.mnTextHAlign = AttributeConversion::decodeToken( maElementText ); break;
176 1 : case VMLX_TOKEN( TextVAlign ): mrClientData.mnTextVAlign = AttributeConversion::decodeToken( maElementText ); break;
177 1 : case VMLX_TOKEN( Column ): mrClientData.mnCol = maElementText.toInt32(); break;
178 1 : case VMLX_TOKEN( Row ): mrClientData.mnRow = maElementText.toInt32(); break;
179 1 : case VMLX_TOKEN( Checked ): mrClientData.mnChecked = maElementText.toInt32(); break;
180 0 : case VMLX_TOKEN( DropStyle ): mrClientData.mnDropStyle = AttributeConversion::decodeToken( maElementText ); break;
181 0 : case VMLX_TOKEN( DropLines ): mrClientData.mnDropLines = maElementText.toInt32(); break;
182 0 : case VMLX_TOKEN( Val ): mrClientData.mnVal = maElementText.toInt32(); break;
183 0 : case VMLX_TOKEN( Min ): mrClientData.mnMin = maElementText.toInt32(); break;
184 0 : case VMLX_TOKEN( Max ): mrClientData.mnMax = maElementText.toInt32(); break;
185 0 : case VMLX_TOKEN( Inc ): mrClientData.mnInc = maElementText.toInt32(); break;
186 0 : case VMLX_TOKEN( Page ): mrClientData.mnPage = maElementText.toInt32(); break;
187 0 : case VMLX_TOKEN( SelType ): mrClientData.mnSelType = AttributeConversion::decodeToken( maElementText ); break;
188 0 : case VMLX_TOKEN( VTEdit ): mrClientData.mnVTEdit = maElementText.toInt32(); break;
189 0 : case VMLX_TOKEN( PrintObject ): mrClientData.mbPrintObject = lclDecodeVmlxBool( maElementText, true ); break;
190 0 : case VMLX_TOKEN( Visible ): mrClientData.mbVisible = lclDecodeVmlxBool( maElementText, true ); break;
191 0 : case VMLX_TOKEN( DDE ): mrClientData.mbDde = lclDecodeVmlxBool( maElementText, true ); break;
192 1 : case VMLX_TOKEN( NoThreeD ): mrClientData.mbNo3D = lclDecodeVmlxBool( maElementText, true ); break;
193 0 : case VMLX_TOKEN( NoThreeD2 ): mrClientData.mbNo3D2 = lclDecodeVmlxBool( maElementText, true ); break;
194 0 : case VMLX_TOKEN( MultiLine ): mrClientData.mbMultiLine = lclDecodeVmlxBool( maElementText, true ); break;
195 0 : case VMLX_TOKEN( VScroll ): mrClientData.mbVScroll = lclDecodeVmlxBool( maElementText, true ); break;
196 0 : case VMLX_TOKEN( SecretEdit ): mrClientData.mbSecretEdit = lclDecodeVmlxBool( maElementText, true ); break;
197 : }
198 15 : }
199 :
200 : // ============================================================================
201 :
202 43 : ShapeContextBase::ShapeContextBase( ContextHandler2Helper& rParent ) :
203 43 : ContextHandler2( rParent )
204 : {
205 43 : }
206 :
207 47 : /*static*/ ContextHandlerRef ShapeContextBase::createShapeContext( ContextHandler2Helper& rParent,
208 : ShapeContainer& rShapes, sal_Int32 nElement, const AttributeList& rAttribs )
209 : {
210 47 : switch( nElement )
211 : {
212 : case O_TOKEN( shapelayout ):
213 1 : return new ShapeLayoutContext( rParent, rShapes.getDrawing() );
214 :
215 : case VML_TOKEN( shapetype ):
216 12 : return new ShapeTypeContext( rParent, rShapes.createShapeType(), rAttribs );
217 : case VML_TOKEN( group ):
218 5 : return new GroupShapeContext( rParent, rShapes.createShape< GroupShape >(), rAttribs );
219 : case VML_TOKEN( shape ):
220 16 : if (rAttribs.hasAttribute(XML_path))
221 1 : return new ShapeContext( rParent, rShapes.createShape< BezierShape >(), rAttribs );
222 : else
223 15 : return new ShapeContext( rParent, rShapes.createShape< ComplexShape >(), rAttribs );
224 : case VML_TOKEN( rect ):
225 7 : return new RectangleShapeContext( rParent, rAttribs, rShapes.createShape< RectangleShape >() );
226 : case VML_TOKEN( roundrect ):
227 1 : return new ShapeContext( rParent, rShapes.createShape< RectangleShape >(), rAttribs );
228 : case VML_TOKEN( oval ):
229 1 : return new ShapeContext( rParent, rShapes.createShape< EllipseShape >(), rAttribs );
230 : case VML_TOKEN( polyline ):
231 0 : return new ShapeContext( rParent, rShapes.createShape< PolyLineShape >(), rAttribs );
232 : case VML_TOKEN( line ):
233 1 : return new ShapeContext( rParent, rShapes.createShape< LineShape >(), rAttribs );
234 : case VML_TOKEN( curve ):
235 0 : return new ShapeContext( rParent, rShapes.createShape< BezierShape >(), rAttribs );
236 :
237 : // TODO:
238 : case VML_TOKEN( arc ):
239 : case VML_TOKEN( diagram ):
240 : case VML_TOKEN( image ):
241 0 : return new ShapeContext( rParent, rShapes.createShape< ComplexShape >(), rAttribs );
242 : }
243 3 : return 0;
244 : }
245 :
246 : // ============================================================================
247 :
248 43 : ShapeTypeContext::ShapeTypeContext( ContextHandler2Helper& rParent, ShapeType& rShapeType, const AttributeList& rAttribs ) :
249 : ShapeContextBase( rParent ),
250 43 : mrTypeModel( rShapeType.getTypeModel() )
251 : {
252 : // shape identifier and shape name
253 43 : bool bHasOspid = rAttribs.hasAttribute( O_TOKEN( spid ) );
254 43 : mrTypeModel.maShapeId = rAttribs.getXString( bHasOspid ? O_TOKEN( spid ) : XML_id, OUString() );
255 : OSL_ENSURE( !mrTypeModel.maShapeId.isEmpty(), "ShapeTypeContext::ShapeTypeContext - missing shape identifier" );
256 : // if the o:spid attribute exists, the id attribute contains the user-defined shape name
257 43 : if( bHasOspid )
258 4 : mrTypeModel.maShapeName = rAttribs.getXString( XML_id, OUString() );
259 : // builtin shape type identifier
260 43 : mrTypeModel.moShapeType = rAttribs.getInteger( O_TOKEN( spt ) );
261 :
262 : // coordinate system position/size, CSS style
263 43 : mrTypeModel.moCoordPos = lclDecodeInt32Pair( rAttribs, XML_coordorigin );
264 43 : mrTypeModel.moCoordSize = lclDecodeInt32Pair( rAttribs, XML_coordsize );
265 43 : setStyle( rAttribs.getString( XML_style, OUString() ) );
266 43 : if( lclDecodeBool( rAttribs, O_TOKEN( hr )).get( false ))
267 : { // MSO's handling of o:hr width is nowhere near what the spec says:
268 : // - o:hrpct is not in % but in 0.1%
269 : // - if o:hrpct is not given, 100% width is assumed
270 : // - given width is used only if explicit o:hrpct="0" is given
271 0 : OUString hrpct = rAttribs.getString( O_TOKEN( hrpct ), "1000" );
272 0 : if( hrpct != "0" )
273 0 : mrTypeModel.maWidth = OUString::valueOf( hrpct.toInt32() / 10 ) + "%";
274 : }
275 :
276 : // stroke settings (may be overridden by v:stroke element later)
277 43 : mrTypeModel.maStrokeModel.moStroked = lclDecodeBool( rAttribs, XML_stroked );
278 43 : mrTypeModel.maStrokeModel.moColor = rAttribs.getString( XML_strokecolor );
279 43 : mrTypeModel.maStrokeModel.moWeight = rAttribs.getString( XML_strokeweight );
280 :
281 : // fill settings (may be overridden by v:fill element later)
282 43 : mrTypeModel.maFillModel.moFilled = lclDecodeBool( rAttribs, XML_filled );
283 43 : mrTypeModel.maFillModel.moColor = rAttribs.getString( XML_fillcolor );
284 :
285 : // For roundrect we may have a arcsize attribute to read
286 43 : mrTypeModel.maArcsize = rAttribs.getString( XML_arcsize,rtl::OUString( ) );
287 43 : }
288 :
289 56 : ContextHandlerRef ShapeTypeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
290 : {
291 56 : if( isRootElement() ) switch( nElement )
292 : {
293 : case VML_TOKEN( stroke ):
294 14 : mrTypeModel.maStrokeModel.moStroked.assignIfUsed( lclDecodeBool( rAttribs, XML_on ) );
295 14 : mrTypeModel.maStrokeModel.maStartArrow.moArrowType = rAttribs.getToken( XML_startarrow );
296 14 : mrTypeModel.maStrokeModel.maStartArrow.moArrowWidth = rAttribs.getToken( XML_startarrowwidth );
297 14 : mrTypeModel.maStrokeModel.maStartArrow.moArrowLength = rAttribs.getToken( XML_startarrowlength );
298 14 : mrTypeModel.maStrokeModel.maEndArrow.moArrowType = rAttribs.getToken( XML_endarrow );
299 14 : mrTypeModel.maStrokeModel.maEndArrow.moArrowWidth = rAttribs.getToken( XML_endarrowwidth );
300 14 : mrTypeModel.maStrokeModel.maEndArrow.moArrowLength = rAttribs.getToken( XML_endarrowlength );
301 14 : mrTypeModel.maStrokeModel.moColor.assignIfUsed( rAttribs.getString( XML_color ) );
302 14 : mrTypeModel.maStrokeModel.moOpacity = lclDecodePercent( rAttribs, XML_opacity, 1.0 );
303 14 : mrTypeModel.maStrokeModel.moWeight.assignIfUsed( rAttribs.getString( XML_weight ) );
304 14 : mrTypeModel.maStrokeModel.moDashStyle = rAttribs.getString( XML_dashstyle );
305 14 : mrTypeModel.maStrokeModel.moLineStyle = rAttribs.getToken( XML_linestyle );
306 14 : mrTypeModel.maStrokeModel.moEndCap = rAttribs.getToken( XML_endcap );
307 14 : mrTypeModel.maStrokeModel.moJoinStyle = rAttribs.getToken( XML_joinstyle );
308 14 : break;
309 : case VML_TOKEN( fill ):
310 3 : mrTypeModel.maFillModel.moFilled.assignIfUsed( lclDecodeBool( rAttribs, XML_on ) );
311 3 : mrTypeModel.maFillModel.moColor.assignIfUsed( rAttribs.getString( XML_color ) );
312 3 : mrTypeModel.maFillModel.moOpacity = lclDecodePercent( rAttribs, XML_opacity, 1.0 );
313 3 : mrTypeModel.maFillModel.moColor2 = rAttribs.getString( XML_color2 );
314 3 : mrTypeModel.maFillModel.moOpacity2 = lclDecodePercent( rAttribs, XML_opacity2, 1.0 );
315 3 : mrTypeModel.maFillModel.moType = rAttribs.getToken( XML_type );
316 3 : mrTypeModel.maFillModel.moAngle = rAttribs.getInteger( XML_angle );
317 3 : mrTypeModel.maFillModel.moFocus = lclDecodePercent( rAttribs, XML_focus, 0.0 );
318 3 : mrTypeModel.maFillModel.moFocusPos = lclDecodePercentPair( rAttribs, XML_focusposition );
319 3 : mrTypeModel.maFillModel.moFocusSize = lclDecodePercentPair( rAttribs, XML_focussize );
320 3 : mrTypeModel.maFillModel.moBitmapPath = decodeFragmentPath( rAttribs, O_TOKEN( relid ) );
321 3 : mrTypeModel.maFillModel.moRotate = lclDecodeBool( rAttribs, XML_rotate );
322 3 : break;
323 : case VML_TOKEN( imagedata ):
324 : {
325 : // shapes in docx use r:id for the relationship id
326 : // in xlsx it they use o:relid
327 5 : bool bHasORelId = rAttribs.hasAttribute( O_TOKEN( relid ) );
328 5 : mrTypeModel.moGraphicPath = decodeFragmentPath( rAttribs, bHasORelId ? O_TOKEN( relid ) : R_TOKEN( id ) );
329 5 : mrTypeModel.moGraphicTitle = rAttribs.getString( O_TOKEN( title ) );
330 : }
331 5 : break;
332 : case NMSP_vmlWord | XML_wrap:
333 11 : mrTypeModel.moWrapAnchorX = rAttribs.getString(XML_anchorx);
334 11 : mrTypeModel.moWrapAnchorY = rAttribs.getString(XML_anchory);
335 11 : break;
336 : }
337 56 : return 0;
338 : }
339 :
340 8 : OptValue< OUString > ShapeTypeContext::decodeFragmentPath( const AttributeList& rAttribs, sal_Int32 nToken ) const
341 : {
342 8 : OptValue< OUString > oFragmentPath;
343 8 : OptValue< OUString > oRelId = rAttribs.getString( nToken );
344 8 : if( oRelId.has() )
345 5 : oFragmentPath = getFragmentPathFromRelId( oRelId.get() );
346 8 : return oFragmentPath;
347 : }
348 :
349 43 : void ShapeTypeContext::setStyle( const OUString& rStyle )
350 : {
351 43 : sal_Int32 nIndex = 0;
352 355 : while( nIndex >= 0 )
353 : {
354 269 : OUString aName, aValue;
355 269 : if( ConversionHelper::separatePair( aName, aValue, rStyle.getToken( 0, ';', nIndex ), ':' ) )
356 : {
357 257 : if( aName == "position" ) mrTypeModel.maPosition = aValue;
358 229 : else if( aName == "left" ) mrTypeModel.maLeft = aValue;
359 219 : else if( aName == "top" ) mrTypeModel.maTop = aValue;
360 211 : else if( aName == "width" ) mrTypeModel.maWidth = aValue;
361 181 : else if( aName == "height" ) mrTypeModel.maHeight = aValue;
362 151 : else if( aName == "margin-left" ) mrTypeModel.maMarginLeft = aValue;
363 133 : else if( aName == "margin-top" ) mrTypeModel.maMarginTop = aValue;
364 115 : else if( aName == "mso-position-vertical-relative" ) mrTypeModel.maPositionVerticalRelative = aValue;
365 104 : else if( aName == "mso-position-horizontal-relative" ) mrTypeModel.maPositionHorizontalRelative = aValue;
366 93 : else if( aName == "mso-position-horizontal" ) mrTypeModel.maPositionHorizontal = aValue;
367 84 : else if( aName == "mso-position-vertical" ) mrTypeModel.maPositionVertical = aValue;
368 76 : else if( aName == "mso-width-percent" ) mrTypeModel.maWidthPercent = aValue;
369 60 : else if( aName == "mso-width-relative" ) mrTypeModel.maWidthRelative = aValue;
370 55 : else if( aName == "mso-height-percent" ) mrTypeModel.maHeightPercent = aValue;
371 45 : else if( aName == "mso-height-relative" ) mrTypeModel.maHeightRelative = aValue;
372 39 : else if( aName == "mso-fit-shape-to-text" ) mrTypeModel.mbAutoHeight = sal_True;
373 39 : else if( aName == "rotation" ) mrTypeModel.maRotation = aValue;
374 38 : else if( aName == "flip" ) mrTypeModel.maFlip = aValue;
375 37 : else if( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "visibility" ) ) )
376 4 : mrTypeModel.mbVisible = !aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("hidden") );
377 33 : else if( aName == "mso-wrap-style" ) mrTypeModel.maWrapStyle = aValue;
378 : }
379 269 : }
380 43 : }
381 :
382 : // ============================================================================
383 :
384 31 : ShapeContext::ShapeContext( ContextHandler2Helper& rParent, ShapeBase& rShape, const AttributeList& rAttribs ) :
385 : ShapeTypeContext( rParent, rShape, rAttribs ),
386 : mrShape( rShape ),
387 31 : mrShapeModel( rShape.getShapeModel() )
388 : {
389 : // collect shape specific attributes
390 31 : mrShapeModel.maType = rAttribs.getXString( XML_type, OUString() );
391 : // polyline path
392 31 : setPoints( rAttribs.getString( XML_points, OUString() ) );
393 : // line start and end positions
394 31 : setFrom(rAttribs.getString(XML_from, OUString()));
395 31 : setTo(rAttribs.getString(XML_to, OUString()));
396 31 : setControl1(rAttribs.getString(XML_control1, OUString()));
397 31 : setControl2(rAttribs.getString(XML_control2, OUString()));
398 31 : setVmlPath(rAttribs.getString(XML_path, OUString()));
399 31 : }
400 :
401 46 : ContextHandlerRef ShapeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
402 : {
403 : // Excel specific shape client data
404 46 : if( isRootElement() ) switch( nElement )
405 : {
406 : case VML_TOKEN( textbox ):
407 15 : if (getParentElement() != VML_TOKEN( group ))
408 : {
409 : // Custom shape in Writer with a textbox are transformed into a frame
410 9 : dynamic_cast<SimpleShape&>( mrShape ).setService(
411 18 : "com.sun.star.text.TextFrame");
412 : }
413 15 : return new TextBoxContext( *this, mrShapeModel.createTextBox(mrShape.getTypeModel()), rAttribs,
414 15 : mrShape.getDrawing().getFilter().getGraphicHelper());
415 : case VMLX_TOKEN( ClientData ):
416 2 : return new ClientDataContext( *this, mrShapeModel.createClientData(), rAttribs );
417 : case VMLPPT_TOKEN( textdata ):
418 : // Force RectangleShape, this is ugly :(
419 : // and is there because of the lines above which change it to TextFrame
420 0 : dynamic_cast< SimpleShape& >( mrShape ).setService(
421 0 : "com.sun.star.drawing.RectangleShape");
422 0 : mrShapeModel.maLegacyDiagramPath = getFragmentPathFromRelId(rAttribs.getString(XML_id, OUString()));
423 0 : break;
424 : }
425 : // handle remaining stuff in base class
426 29 : return ShapeTypeContext::onCreateContext( nElement, rAttribs );
427 : }
428 :
429 31 : void ShapeContext::setPoints( const OUString& rPoints )
430 : {
431 31 : mrShapeModel.maPoints.clear();
432 31 : sal_Int32 nIndex = 0;
433 :
434 93 : while( nIndex >= 0 )
435 : {
436 31 : sal_Int32 nX = rPoints.getToken( 0, ',', nIndex ).toInt32();
437 31 : sal_Int32 nY = rPoints.getToken( 0, ',', nIndex ).toInt32();
438 31 : mrShapeModel.maPoints.push_back( awt::Point( nX, nY ) );
439 : }
440 31 : }
441 :
442 31 : void ShapeContext::setFrom( const OUString& rPoints )
443 : {
444 31 : if (!rPoints.isEmpty())
445 1 : mrShapeModel.maFrom = rPoints;
446 31 : }
447 :
448 31 : void ShapeContext::setTo( const OUString& rPoints )
449 : {
450 31 : if (!rPoints.isEmpty())
451 1 : mrShapeModel.maTo = rPoints;
452 31 : }
453 :
454 31 : void ShapeContext::setControl1( const OUString& rPoints )
455 : {
456 31 : if (!rPoints.isEmpty())
457 0 : mrShapeModel.maControl1 = rPoints;
458 31 : }
459 :
460 31 : void ShapeContext::setControl2( const OUString& rPoints )
461 : {
462 31 : if (!rPoints.isEmpty())
463 0 : mrShapeModel.maControl2 = rPoints;
464 31 : }
465 31 : void ShapeContext::setVmlPath( const OUString& rPath )
466 : {
467 31 : if (!rPath.isEmpty())
468 1 : mrShapeModel.maVmlPath = rPath;
469 31 : }
470 :
471 :
472 : // ============================================================================
473 :
474 5 : GroupShapeContext::GroupShapeContext( ContextHandler2Helper& rParent, GroupShape& rShape, const AttributeList& rAttribs ) :
475 : ShapeContext( rParent, rShape, rAttribs ),
476 5 : mrShapes( rShape.getChildren() )
477 : {
478 5 : }
479 :
480 11 : ContextHandlerRef GroupShapeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
481 : {
482 : // try to create a context of an embedded shape
483 11 : ContextHandlerRef xContext = createShapeContext( *this, mrShapes, nElement, rAttribs );
484 : // handle remaining stuff of this shape in base class
485 11 : return xContext.get() ? xContext : ShapeContext::onCreateContext( nElement, rAttribs );
486 : }
487 :
488 : // ============================================================================
489 :
490 7 : RectangleShapeContext::RectangleShapeContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, RectangleShape& rShape ) :
491 7 : ShapeContext( rParent, rShape, rAttribs )
492 : {
493 7 : }
494 :
495 9 : ContextHandlerRef RectangleShapeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
496 : {
497 : // The parent class's context is fine
498 9 : return ShapeContext::onCreateContext( nElement, rAttribs );
499 : }
500 : // ============================================================================
501 :
502 : } // namespace vml
503 51 : } // namespace oox
504 :
505 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|