update credits
[LibreOffice.git] / oox / source / drawingml / customshapegeometry.cxx
blob3155b893c198550f565b22ee5a85691dfaae59b7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "oox/drawingml/customshapegeometry.hxx"
22 #include <com/sun/star/xml/sax/FastToken.hpp>
23 #include <comphelper/stl_types.hxx>
24 #include <boost/unordered_map.hpp>
25 #include "oox/helper/helper.hxx"
26 #include "oox/helper/attributelist.hxx"
27 #include "oox/helper/propertymap.hxx"
29 using namespace ::oox::core;
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::beans;
32 using namespace ::com::sun::star::drawing;
33 using namespace ::com::sun::star::xml::sax;
35 namespace oox { namespace drawingml {
37 enum FormularCommand
39 FC_MULDIV = 0,
40 FC_PLUSMINUS,
41 FC_PLUSDIV,
42 FC_IFELSE,
43 FC_IFELSE1,
44 FC_ABS,
45 FC_AT2,
46 FC_CAT2,
47 FC_COS,
48 FC_MAX,
49 FC_MIN,
50 FC_MOD,
51 FC_PIN,
52 FC_SAT2,
53 FC_SIN,
54 FC_SQRT,
55 FC_TAN,
56 FC_VAL,
57 FC_LAST
59 struct FormularCommandNameTable
61 const char* pS;
62 FormularCommand pE;
64 static FormularCommandNameTable pFormularCommandNameTable[] =
66 { "*/", FC_MULDIV },
67 { "+-", FC_PLUSMINUS },
68 { "+/", FC_PLUSDIV },
69 { "ifelse", FC_IFELSE },
70 { "?:", FC_IFELSE1 },
71 { "abs", FC_ABS },
72 { "at2", FC_AT2 },
73 { "cat2", FC_CAT2 },
74 { "cos", FC_COS },
75 { "max", FC_MAX },
76 { "min", FC_MIN },
77 { "mod", FC_MOD },
78 { "pin", FC_PIN },
79 { "sat2", FC_SAT2 },
80 { "sin", FC_SIN },
81 { "sqrt", FC_SQRT },
82 { "tan", FC_TAN },
83 { "val", FC_VAL }
86 typedef boost::unordered_map< OUString, FormularCommand, OUStringHash, comphelper::UStringEqual > FormulaCommandHMap;
88 static const FormulaCommandHMap* pCommandHashMap;
91 OUString GetFormulaParameter( const EnhancedCustomShapeParameter& rParameter )
93 OUString aRet;
94 switch( rParameter.Type )
96 case EnhancedCustomShapeParameterType::NORMAL :
98 if ( rParameter.Value.getValueTypeClass() == TypeClass_DOUBLE )
100 double fValue = 0.0;
101 if ( rParameter.Value >>= fValue )
102 aRet = OUString::valueOf( fValue );
104 else
106 sal_Int32 nValue = 0;
107 if ( rParameter.Value >>= nValue )
108 aRet = OUString::valueOf( nValue );
111 break;
112 case EnhancedCustomShapeParameterType::EQUATION :
114 if ( rParameter.Value.getValueTypeClass() == TypeClass_LONG )
116 sal_Int32 nFormulaIndex;
117 if ( rParameter.Value >>= nFormulaIndex )
119 aRet = "?"
120 + OUString::valueOf( nFormulaIndex )
121 + " ";
124 else
126 // ups... we should have an index here and not the formula name
129 break;
130 case EnhancedCustomShapeParameterType::ADJUSTMENT :
132 if ( rParameter.Value.getValueTypeClass() == TypeClass_LONG )
134 sal_Int32 nAdjustmentIndex;
135 if ( rParameter.Value >>= nAdjustmentIndex )
137 aRet = "$"
138 + OUString::valueOf( nAdjustmentIndex )
139 + " ";
142 else
144 // ups... we should have an index here and not the formula name
147 break;
148 case EnhancedCustomShapeParameterType::LEFT :
150 const OUString sLeft( "left" );
151 aRet = sLeft;
153 break;
154 case EnhancedCustomShapeParameterType::TOP :
156 const OUString sTop( "top" );
157 aRet = sTop;
159 break;
160 case EnhancedCustomShapeParameterType::RIGHT :
162 const OUString sRight( "right" );
163 aRet = sRight;
165 break;
166 case EnhancedCustomShapeParameterType::BOTTOM :
168 const OUString sBottom( "bottom" );
169 aRet = sBottom;
171 break;
172 case EnhancedCustomShapeParameterType::XSTRETCH :
174 const OUString sXStretch( "xstretch" );
175 aRet = sXStretch;
177 break;
178 case EnhancedCustomShapeParameterType::YSTRETCH :
180 const OUString sYStretch( "ystretch" );
181 aRet = sYStretch;
183 break;
184 case EnhancedCustomShapeParameterType::HASSTROKE :
186 const OUString sHasStroke( "hasstroke" );
187 aRet = sHasStroke;
189 break;
190 case EnhancedCustomShapeParameterType::HASFILL :
192 const OUString sHasFill( "hasfill" );
193 aRet = sHasFill;
195 break;
196 case EnhancedCustomShapeParameterType::WIDTH :
198 const OUString sWidth( "width" );
199 aRet = sWidth;
201 break;
202 case EnhancedCustomShapeParameterType::HEIGHT :
204 const OUString sHeight( "height" );
205 aRet = sHeight;
207 break;
208 case EnhancedCustomShapeParameterType::LOGWIDTH :
210 const OUString sLogWidth( "logwidth" );
211 aRet = sLogWidth;
213 break;
214 case EnhancedCustomShapeParameterType::LOGHEIGHT :
216 const OUString sLogHeight( "logheight" );
217 aRet = sLogHeight;
219 break;
221 return aRet;
224 // ---------------------------------------------------------------------
226 static EnhancedCustomShapeParameter GetAdjCoordinate( CustomShapeProperties& rCustomShapeProperties, const OUString& rValue, sal_Bool bNoSymbols = sal_True )
228 com::sun::star::drawing::EnhancedCustomShapeParameter aRet;
229 if ( !rValue.isEmpty() )
231 sal_Bool bConstant = sal_True;
232 sal_Int32 nConstant = -1;
233 sal_Int32 nIntVal = 0;
235 // first check if its a constant value
236 switch( AttributeConversion::decodeToken( rValue ) )
238 case XML_3cd4 : nConstant = 270 * 60000; break;
239 case XML_3cd8 : nConstant = 135 * 60000; break;
240 case XML_5cd8 : nConstant = 225 * 60000; break;
241 case XML_7cd8 : nConstant = 315 * 60000; break;
242 case XML_cd2 : nConstant = 180 * 60000; break;
243 case XML_cd3 : nConstant = 120 * 60000; break;
244 case XML_cd4 : nConstant = 90 * 60000; break;
245 case XML_cd8 : nConstant = 45 * 60000; break;
247 case XML_b : // variable height of the shape defined in spPr
248 case XML_h :
250 if ( bNoSymbols )
252 CustomShapeGuide aGuide;
253 aGuide.maName = rValue;
254 aGuide.maFormula = "logheight" ;
256 aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) );
257 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
259 else
260 aRet.Type = EnhancedCustomShapeParameterType::LOGHEIGHT; // TODO: HEIGHT needs to be implemented
262 break;
265 case XML_hd10 : // !!PASSTHROUGH INTENDED
266 nIntVal += 2; // */ h 1.0 10.0
267 case XML_hd8 : // */ h 1.0 8.0
268 nIntVal += 2;
269 case XML_hd6 : // */ h 1.0 6.0
270 nIntVal++;
271 case XML_hd5 : // */ h 1.0 5.0
272 nIntVal++;
273 case XML_hd4 : // */ h 1.0 4.0
274 nIntVal++;
275 case XML_hd3 : // */ h 1.0 3.0
276 nIntVal++;
277 case XML_hd2 : // */ h 1.0 2.0
278 case XML_vc : // */ h 1.0 2.0
280 nIntVal += 2;
282 CustomShapeGuide aGuide;
283 aGuide.maName = rValue;
284 aGuide.maFormula = "logheight/" + OUString::valueOf( nIntVal );
286 aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) );
287 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
289 break;
291 case XML_t :
292 case XML_l :
294 nConstant = 0;
295 aRet.Type = EnhancedCustomShapeParameterType::NORMAL;
297 break;
299 case XML_ls : // longest side: max w h
301 CustomShapeGuide aGuide;
302 aGuide.maName = rValue;
303 aGuide.maFormula = "max(logwidth,logheight)";
305 aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) );
306 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
308 break;
309 case XML_ss : // shortest side: min w h
311 CustomShapeGuide aGuide;
312 aGuide.maName = rValue;
313 aGuide.maFormula = "min(logwidth,logheight)";
315 aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) );
316 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
318 break;
319 case XML_ssd32 : // */ ss 1.0 32.0
320 nIntVal += 16;
321 case XML_ssd16 : // */ ss 1.0 16.0
322 nIntVal += 8;
323 case XML_ssd8 : // */ ss 1.0 8.0
324 nIntVal += 2;
325 case XML_ssd6 : // */ ss 1.0 6.0
326 nIntVal += 2;
327 case XML_ssd4 : // */ ss 1.0 4.0
328 nIntVal += 2;
329 case XML_ssd2 : // */ ss 1.0 2.0
331 nIntVal += 2;
333 CustomShapeGuide aGuide;
334 aGuide.maName = rValue;
335 aGuide.maFormula = "min(logwidth,logheight)/" + OUString::valueOf( nIntVal );
337 aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) );
338 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
340 break;
342 case XML_r : // variable width of the shape defined in spPr
343 case XML_w :
345 if ( bNoSymbols )
347 CustomShapeGuide aGuide;
348 aGuide.maName = rValue;
349 aGuide.maFormula = "logwidth" ;
351 aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) );
352 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
354 else
355 aRet.Type = EnhancedCustomShapeParameterType::LOGWIDTH;
357 break;
359 case XML_wd32 : // */ w 1.0 32.0
360 nIntVal += 20;
361 case XML_wd12 : // */ w 1.0 12.0
362 nIntVal += 2;
363 case XML_wd10 : // */ w 1.0 10.0
364 nIntVal += 2;
365 case XML_wd8 : // */ w 1.0 8.0
366 nIntVal += 2;
367 case XML_wd6 : // */ w 1.0 6.0
368 nIntVal++;
369 case XML_wd5 : // */ w 1.0 5.0
370 nIntVal++;
371 case XML_wd4 : // */ w 1.0 4.0
372 nIntVal++;
373 case XML_wd3 : // */ w 1.0 3.0
374 nIntVal++;
375 case XML_hc : // */ w 1.0 2.0
376 case XML_wd2 : // */ w 1.0 2.0
378 nIntVal += 2;
380 CustomShapeGuide aGuide;
381 aGuide.maName = rValue;
382 aGuide.maFormula = "logwidth/" + OUString::valueOf( nIntVal );
384 aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) );
385 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
387 break;
389 default:
390 bConstant = sal_False;
391 break;
393 if ( bConstant )
395 if (nConstant != -1) {
396 aRet.Value = Any( nConstant );
397 aRet.Type = EnhancedCustomShapeParameterType::NORMAL;
400 else
402 sal_Unicode n = rValue[ 0 ];
403 if ( ( n == '+' ) || ( n == '-' ) )
405 if ( rValue.getLength() > 1 )
406 n = rValue[ 1 ];
408 if ( ( n >= '0' ) && ( n <= '9' ) )
409 { // seems to be a ST_Coordinate
410 aRet.Value = Any( (sal_Int32)(rValue.toInt32() ) );
411 aRet.Type = EnhancedCustomShapeParameterType::NORMAL;
413 else
415 sal_Int32 nGuideIndex = CustomShapeProperties::GetCustomShapeGuideValue( rCustomShapeProperties.getAdjustmentGuideList(), rValue );
416 if ( nGuideIndex >= 0 )
418 aRet.Value = Any( nGuideIndex );
419 aRet.Type = EnhancedCustomShapeParameterType::ADJUSTMENT;
421 else
423 nGuideIndex = CustomShapeProperties::GetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), rValue );
424 if ( nGuideIndex >= 0 )
426 aRet.Value = Any( nGuideIndex );
427 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
429 else
431 OSL_TRACE("error: unhandled value '%s'", OUStringToOString( rValue, RTL_TEXTENCODING_ASCII_US ).getStr());
432 aRet.Value = Any( rValue );
438 return aRet;
441 // ---------------------------------------------------------------------
442 // CT_GeomGuideList
443 class GeomGuideListContext : public ContextHandler
445 public:
446 GeomGuideListContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< CustomShapeGuide >& rGuideList );
447 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
449 protected:
450 std::vector< CustomShapeGuide >& mrGuideList;
451 CustomShapeProperties& mrCustomShapeProperties;
454 GeomGuideListContext::GeomGuideListContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< CustomShapeGuide >& rGuideList )
455 : ContextHandler( rParent )
456 , mrGuideList( rGuideList )
457 , mrCustomShapeProperties( rCustomShapeProperties )
461 static OUString convertToOOEquation( CustomShapeProperties& rCustomShapeProperties, const OUString& rSource )
463 if ( !pCommandHashMap )
465 FormulaCommandHMap* pHM = new FormulaCommandHMap();
466 for( sal_Int32 i = 0; i < FC_LAST; i++ )
467 (*pHM)[ OUString::createFromAscii( pFormularCommandNameTable[ i ].pS ) ] = pFormularCommandNameTable[ i ].pE;
468 pCommandHashMap = pHM;
471 std::vector< OUString > aTokens;
472 sal_Int32 nIndex = 0;
475 OUString aToken( rSource.getToken( 0, ' ', nIndex ) );
476 if ( !aToken.isEmpty() )
477 aTokens.push_back( aToken );
479 while ( nIndex >= 0 );
481 OUString aEquation;
482 if ( !aTokens.empty() )
484 sal_Int32 i, nParameters = aTokens.size() - 1;
485 if ( nParameters > 3 )
486 nParameters = 3;
488 OUString sParameters[ 3 ];
490 for ( i = 0; i < nParameters; i++ )
491 sParameters[ i ] = GetFormulaParameter( GetAdjCoordinate( rCustomShapeProperties, aTokens[ i + 1 ], sal_False ) );
493 const FormulaCommandHMap::const_iterator aIter( pCommandHashMap->find( aTokens[ 0 ] ) );
494 if ( aIter != pCommandHashMap->end() )
496 switch( aIter->second )
498 case FC_MULDIV :
500 if ( nParameters == 3 )
501 aEquation = sParameters[ 0 ] + "*" + sParameters[ 1 ]
502 + "/" + sParameters[ 2 ];
504 break;
505 case FC_PLUSMINUS :
507 if ( nParameters == 3 )
508 aEquation = sParameters[ 0 ] + "+" + sParameters[ 1 ]
509 + "-" + sParameters[ 2 ];
511 break;
512 case FC_PLUSDIV :
514 if ( nParameters == 3 )
515 aEquation = "(" + sParameters[ 0 ] + "+"
516 + sParameters[ 1 ] + ")/" + sParameters[ 2 ];
518 break;
519 case FC_IFELSE :
520 case FC_IFELSE1 :
522 if ( nParameters == 3 )
523 aEquation = "if(" + sParameters[ 0 ] + ","
524 + sParameters[ 1 ] + "," + sParameters[ 2 ] + ")";
526 break;
527 case FC_ABS :
529 if ( nParameters == 1 )
530 aEquation = "abs(" + sParameters[ 0 ] + ")";
532 break;
533 case FC_AT2 :
535 if ( nParameters == 2 )
536 aEquation = "(10800000*atan2(" + sParameters[ 1 ] + ","
537 + sParameters[ 0 ] + "))/pi";
539 break;
540 case FC_CAT2 :
542 if ( nParameters == 3 )
543 aEquation = sParameters[ 0 ] + "*(cos(atan2(" +
544 sParameters[ 2 ] + "," + sParameters[ 1 ] + ")))";
546 break;
547 case FC_COS :
549 if ( nParameters == 2 )
550 aEquation = sParameters[ 0 ] + "*cos(pi*(" +
551 sParameters[ 1 ] + ")/10800000)";
553 break;
554 case FC_MAX :
556 if ( nParameters == 2 )
557 aEquation = "max(" + sParameters[ 0 ] + "," +
558 sParameters[ 1 ] + ")";
560 break;
561 case FC_MIN :
563 if ( nParameters == 2 )
564 aEquation = "min(" + sParameters[ 0 ] + "," +
565 sParameters[ 1 ] + ")";
567 break;
568 case FC_MOD :
570 if ( nParameters == 3 )
571 aEquation = "sqrt("
572 + sParameters[ 0 ] + "*" + sParameters[ 0 ] + "+"
573 + sParameters[ 1 ] + "*" + sParameters[ 1 ] + "+"
574 + sParameters[ 2 ] + "*" + sParameters[ 2 ] + ")";
576 break;
577 case FC_PIN :
579 if ( nParameters == 3 ) // if(x-y,x,if(y-z,z,y))
580 aEquation = "if(" + sParameters[ 0 ] + "-" + sParameters[ 1 ]
581 + "," + sParameters[ 0 ] + ",if(" + sParameters[ 2 ]
582 + "-" + sParameters[ 1 ] + "," + sParameters[ 1 ]
583 + "," + sParameters[ 2 ] + "))";
585 break;
586 case FC_SAT2 :
588 if ( nParameters == 3 )
589 aEquation = sParameters[ 0 ] + "*(sin(atan2(" +
590 sParameters[ 2 ] + "," + sParameters[ 1 ] + ")))";
592 break;
593 case FC_SIN :
595 if ( nParameters == 2 )
596 aEquation = sParameters[ 0 ] + "*sin(pi*(" +
597 sParameters[ 1 ] + ")/10800000)";
599 break;
600 case FC_SQRT :
602 if ( nParameters == 1 )
603 aEquation = "sqrt(" + sParameters[ 0 ] + ")";
605 break;
606 case FC_TAN :
608 if ( nParameters == 2 )
609 aEquation = sParameters[ 0 ] + "*tan(pi*(" +
610 sParameters[ 1 ] + ")/10800000)";
612 break;
613 case FC_VAL :
615 if ( nParameters == 1 )
616 aEquation = sParameters[ 0 ];
618 break;
619 default :
620 break;
624 return aEquation;
627 Reference< XFastContextHandler > GeomGuideListContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
629 if ( aElementToken == A_TOKEN( gd ) ) // CT_GeomGuide
631 CustomShapeGuide aGuide;
632 aGuide.maName = xAttribs->getOptionalValue( XML_name );
633 aGuide.maFormula = convertToOOEquation( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_fmla ) );
634 mrGuideList.push_back( aGuide );
636 return this;
639 // ---------------------------------------------------------------------
641 static const OUString GetGeomGuideName( const OUString& rValue )
643 return rValue;
646 // ---------------------------------------------------------------------
647 // CT_AdjPoint2D
648 class AdjPoint2DContext : public ContextHandler
650 public:
651 AdjPoint2DContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D );
654 AdjPoint2DContext::AdjPoint2DContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D )
655 : ContextHandler( rParent )
657 rAdjPoint2D.First = GetAdjCoordinate( rCustomShapeProperties, xAttribs->getOptionalValue( XML_x ), sal_True );
658 rAdjPoint2D.Second = GetAdjCoordinate( rCustomShapeProperties, xAttribs->getOptionalValue( XML_y ), sal_True );
661 // ---------------------------------------------------------------------
662 // CT_XYAdjustHandle
663 class XYAdjustHandleContext : public ContextHandler
665 public:
666 XYAdjustHandleContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, AdjustHandle& rAdjustHandle );
667 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
669 protected:
670 AdjustHandle& mrAdjustHandle;
671 CustomShapeProperties& mrCustomShapeProperties;
674 XYAdjustHandleContext::XYAdjustHandleContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, AdjustHandle& rAdjustHandle )
675 : ContextHandler( rParent )
676 , mrAdjustHandle( rAdjustHandle )
677 , mrCustomShapeProperties( rCustomShapeProperties )
679 const OUString aEmptyDefault;
680 AttributeList aAttribs( xAttribs );
681 if ( aAttribs.hasAttribute( XML_gdRefX ) )
683 mrAdjustHandle.gdRef1 = GetGeomGuideName( aAttribs.getString( XML_gdRefX, aEmptyDefault ) );
685 if ( aAttribs.hasAttribute( XML_minX ) )
687 mrAdjustHandle.min1 = GetAdjCoordinate( mrCustomShapeProperties, aAttribs.getString( XML_minX, aEmptyDefault ), sal_True );
689 if ( aAttribs.hasAttribute( XML_maxX ) )
691 mrAdjustHandle.max1 = GetAdjCoordinate( mrCustomShapeProperties, aAttribs.getString( XML_maxX, aEmptyDefault ), sal_True );
693 if ( aAttribs.hasAttribute( XML_gdRefY ) )
695 mrAdjustHandle.gdRef2 = GetGeomGuideName( aAttribs.getString( XML_gdRefY, aEmptyDefault ) );
697 if ( aAttribs.hasAttribute( XML_minY ) )
699 mrAdjustHandle.min2 = GetAdjCoordinate( mrCustomShapeProperties, aAttribs.getString( XML_minY, aEmptyDefault ), sal_True );
701 if ( aAttribs.hasAttribute( XML_maxY ) )
703 mrAdjustHandle.max2 = GetAdjCoordinate( mrCustomShapeProperties, aAttribs.getString( XML_maxY, aEmptyDefault ), sal_True );
707 Reference< XFastContextHandler > XYAdjustHandleContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
709 Reference< XFastContextHandler > xContext;
710 if ( aElementToken == A_TOKEN( pos ) )
711 xContext = new AdjPoint2DContext( *this, xAttribs, mrCustomShapeProperties, mrAdjustHandle.pos ); // CT_AdjPoint2D
712 return xContext;
715 // ---------------------------------------------------------------------
716 // CT_PolarAdjustHandle
717 class PolarAdjustHandleContext : public ContextHandler
719 public:
720 PolarAdjustHandleContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, AdjustHandle& rAdjustHandle );
721 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
723 protected:
724 AdjustHandle& mrAdjustHandle;
725 CustomShapeProperties& mrCustomShapeProperties;
728 PolarAdjustHandleContext::PolarAdjustHandleContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, AdjustHandle& rAdjustHandle )
729 : ContextHandler( rParent )
730 , mrAdjustHandle( rAdjustHandle )
731 , mrCustomShapeProperties( rCustomShapeProperties )
733 const OUString aEmptyDefault;
734 AttributeList aAttribs( xAttribs );
735 if ( aAttribs.hasAttribute( XML_gdRefR ) )
737 mrAdjustHandle.gdRef1 = GetGeomGuideName( aAttribs.getString( XML_gdRefR, aEmptyDefault ) );
739 if ( aAttribs.hasAttribute( XML_minR ) )
741 mrAdjustHandle.min1 = GetAdjCoordinate( mrCustomShapeProperties, aAttribs.getString( XML_minR, aEmptyDefault ), sal_True );
743 if ( aAttribs.hasAttribute( XML_maxR ) )
745 mrAdjustHandle.max1 = GetAdjCoordinate( mrCustomShapeProperties, aAttribs.getString( XML_maxR, aEmptyDefault ), sal_True );
747 if ( aAttribs.hasAttribute( XML_gdRefAng ) )
749 mrAdjustHandle.gdRef2 = GetGeomGuideName( aAttribs.getString( XML_gdRefAng, aEmptyDefault ) );
751 if ( aAttribs.hasAttribute( XML_minAng ) )
753 mrAdjustHandle.min2 = GetAdjCoordinate( mrCustomShapeProperties, aAttribs.getString( XML_minAng, aEmptyDefault ) );
755 if ( aAttribs.hasAttribute( XML_maxAng ) )
757 mrAdjustHandle.max2 = GetAdjCoordinate( mrCustomShapeProperties, aAttribs.getString( XML_maxAng, aEmptyDefault ) );
761 Reference< XFastContextHandler > PolarAdjustHandleContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
763 Reference< XFastContextHandler > xContext;
764 if ( aElementToken == A_TOKEN( pos ) )
765 xContext = new AdjPoint2DContext( *this, xAttribs, mrCustomShapeProperties, mrAdjustHandle.pos ); // CT_AdjPoint2D
766 return xContext;
769 // ---------------------------------------------------------------------
770 // CT_AdjustHandleList
771 class AdjustHandleListContext : public ContextHandler
773 public:
774 AdjustHandleListContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< AdjustHandle >& rAdjustHandleList );
775 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
777 protected:
778 std::vector< AdjustHandle >& mrAdjustHandleList;
779 CustomShapeProperties& mrCustomShapeProperties;
782 AdjustHandleListContext::AdjustHandleListContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< AdjustHandle >& rAdjustHandleList )
783 : ContextHandler( rParent )
784 , mrAdjustHandleList( rAdjustHandleList )
785 , mrCustomShapeProperties( rCustomShapeProperties )
789 Reference< XFastContextHandler > AdjustHandleListContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
791 Reference< XFastContextHandler > xContext;
792 if ( aElementToken == A_TOKEN( ahXY ) ) // CT_XYAdjustHandle
794 AdjustHandle aAdjustHandle( sal_False );
795 mrAdjustHandleList.push_back( aAdjustHandle );
796 xContext = new XYAdjustHandleContext( *this, xAttribs, mrCustomShapeProperties, mrAdjustHandleList.back() );
798 else if ( aElementToken == A_TOKEN( ahPolar ) ) // CT_PolarAdjustHandle
800 AdjustHandle aAdjustHandle( sal_True );
801 mrAdjustHandleList.push_back( aAdjustHandle );
802 xContext = new PolarAdjustHandleContext( *this, xAttribs, mrCustomShapeProperties, mrAdjustHandleList.back() );
804 return xContext;
807 // ---------------------------------------------------------------------
808 // CT_ConnectionSite
809 class ConnectionSiteContext : public ContextHandler
811 public:
812 ConnectionSiteContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, ConnectionSite& rConnectionSite );
813 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
815 protected:
816 ConnectionSite& mrConnectionSite;
817 CustomShapeProperties& mrCustomShapeProperties;
820 ConnectionSiteContext::ConnectionSiteContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, ConnectionSite& rConnectionSite )
821 : ContextHandler( rParent )
822 , mrConnectionSite( rConnectionSite )
823 , mrCustomShapeProperties( rCustomShapeProperties )
825 mrConnectionSite.ang = GetAdjCoordinate( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_ang ) );
828 Reference< XFastContextHandler > ConnectionSiteContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
830 Reference< XFastContextHandler > xContext;
831 if ( aElementToken == A_TOKEN( pos ) )
832 xContext = new AdjPoint2DContext( *this, xAttribs, mrCustomShapeProperties, mrConnectionSite.pos ); // CT_AdjPoint2D
833 return xContext;
836 // ---------------------------------------------------------------------
837 // CT_Path2DMoveTo
838 class Path2DMoveToContext : public ContextHandler
840 public:
841 Path2DMoveToContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D );
842 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
844 protected:
845 EnhancedCustomShapeParameterPair& mrAdjPoint2D;
846 CustomShapeProperties& mrCustomShapeProperties;
849 Path2DMoveToContext::Path2DMoveToContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D )
850 : ContextHandler( rParent )
851 , mrAdjPoint2D( rAdjPoint2D )
852 , mrCustomShapeProperties( rCustomShapeProperties )
856 Reference< XFastContextHandler > Path2DMoveToContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
858 Reference< XFastContextHandler > xContext;
859 if ( aElementToken == A_TOKEN( pt ) )
860 xContext = new AdjPoint2DContext( *this, xAttribs, mrCustomShapeProperties, mrAdjPoint2D ); // CT_AdjPoint2D
861 return xContext;
864 // ---------------------------------------------------------------------
865 // CT_Path2DLineTo
866 class Path2DLineToContext : public ContextHandler
868 public:
869 Path2DLineToContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D );
870 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
872 protected:
873 EnhancedCustomShapeParameterPair& mrAdjPoint2D;
874 CustomShapeProperties& mrCustomShapeProperties;
877 Path2DLineToContext::Path2DLineToContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D )
878 : ContextHandler( rParent )
879 , mrAdjPoint2D( rAdjPoint2D )
880 , mrCustomShapeProperties( rCustomShapeProperties )
884 Reference< XFastContextHandler > Path2DLineToContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
886 Reference< XFastContextHandler > xContext;
887 if ( aElementToken == A_TOKEN( pt ) )
888 xContext = new AdjPoint2DContext( *this, xAttribs, mrCustomShapeProperties, mrAdjPoint2D ); // CT_AdjPoint2D
889 return xContext;
892 // ---------------------------------------------------------------------
893 // CT_Path2DQuadBezierTo
894 class Path2DQuadBezierToContext : public ContextHandler
896 public:
897 Path2DQuadBezierToContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rPt1, EnhancedCustomShapeParameterPair& rPt2 );
898 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
900 protected:
901 EnhancedCustomShapeParameterPair& mrPt1;
902 EnhancedCustomShapeParameterPair& mrPt2;
903 int nCount;
904 CustomShapeProperties& mrCustomShapeProperties;
907 Path2DQuadBezierToContext::Path2DQuadBezierToContext( ContextHandler& rParent,
908 CustomShapeProperties& rCustomShapeProperties,
909 EnhancedCustomShapeParameterPair& rPt1,
910 EnhancedCustomShapeParameterPair& rPt2 )
911 : ContextHandler( rParent )
912 , mrPt1( rPt1 )
913 , mrPt2( rPt2 )
914 , nCount( 0 )
915 , mrCustomShapeProperties( rCustomShapeProperties )
919 Reference< XFastContextHandler > Path2DQuadBezierToContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
921 Reference< XFastContextHandler > xContext;
922 if ( aElementToken == A_TOKEN( pt ) )
923 xContext = new AdjPoint2DContext( *this, xAttribs, mrCustomShapeProperties, nCount++ ? mrPt2 : mrPt1 ); // CT_AdjPoint2D
924 return xContext;
927 // ---------------------------------------------------------------------
928 // CT_Path2DCubicBezierTo
929 class Path2DCubicBezierToContext : public ContextHandler
931 public:
932 Path2DCubicBezierToContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties,
933 EnhancedCustomShapeParameterPair&, EnhancedCustomShapeParameterPair&, EnhancedCustomShapeParameterPair& );
934 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
936 protected:
937 CustomShapeProperties& mrCustomShapeProperties;
938 EnhancedCustomShapeParameterPair& mrControlPt1;
939 EnhancedCustomShapeParameterPair& mrControlPt2;
940 EnhancedCustomShapeParameterPair& mrEndPt;
941 int nCount;
944 Path2DCubicBezierToContext::Path2DCubicBezierToContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties,
945 EnhancedCustomShapeParameterPair& rControlPt1,
946 EnhancedCustomShapeParameterPair& rControlPt2,
947 EnhancedCustomShapeParameterPair& rEndPt )
948 : ContextHandler( rParent )
949 , mrCustomShapeProperties( rCustomShapeProperties )
950 , mrControlPt1( rControlPt1 )
951 , mrControlPt2( rControlPt2 )
952 , mrEndPt( rEndPt )
953 , nCount( 0 )
957 Reference< XFastContextHandler > Path2DCubicBezierToContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
959 Reference< XFastContextHandler > xContext;
960 if ( aElementToken == A_TOKEN( pt ) )
961 xContext = new AdjPoint2DContext( *this, xAttribs, mrCustomShapeProperties,
962 nCount++ ? nCount == 2 ? mrControlPt2 : mrEndPt : mrControlPt1 ); // CT_AdjPoint2D
963 return xContext;
966 // ---------------------------------------------------------------------
967 // CT_Path2DContext
968 class Path2DContext : public ContextHandler
970 public:
971 Path2DContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >& rSegments, Path2D& rPath2D );
972 virtual ~Path2DContext();
973 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL
974 createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs )
975 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
977 protected:
978 Path2D& mrPath2D;
979 std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >& mrSegments;
980 CustomShapeProperties& mrCustomShapeProperties;
983 Path2DContext::Path2DContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >& rSegments, Path2D& rPath2D )
984 : ContextHandler( rParent )
985 , mrPath2D( rPath2D )
986 , mrSegments( rSegments )
987 , mrCustomShapeProperties( rCustomShapeProperties )
989 const OUString aEmptyString;
991 AttributeList aAttribs( xAttribs );
992 rPath2D.w = aAttribs.getString( XML_w, aEmptyString ).toInt64();
993 rPath2D.h = aAttribs.getString( XML_h, aEmptyString ).toInt64();
994 rPath2D.fill = aAttribs.getToken( XML_fill, XML_norm );
995 rPath2D.stroke = aAttribs.getBool( XML_stroke, sal_True );
996 rPath2D.extrusionOk = aAttribs.getBool( XML_extrusionOk, sal_True );
999 Path2DContext::~Path2DContext()
1001 EnhancedCustomShapeSegment aNewSegment;
1002 switch ( mrPath2D.fill )
1004 case XML_none:
1005 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::NOFILL;
1006 break;
1007 case XML_darken:
1008 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::DARKEN;
1009 break;
1010 case XML_darkenLess:
1011 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::DARKENLESS;
1012 break;
1013 case XML_lighten:
1014 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::LIGHTEN;
1015 break;
1016 case XML_lightenLess:
1017 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::LIGHTENLESS;
1018 break;
1020 if (mrPath2D.fill != XML_norm) {
1021 aNewSegment.Count = 0;
1022 mrSegments.push_back( aNewSegment );
1024 if ( !mrPath2D.stroke )
1026 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::NOSTROKE;
1027 aNewSegment.Count = 0;
1028 mrSegments.push_back( aNewSegment );
1030 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::ENDSUBPATH;
1031 aNewSegment.Count = 0;
1032 mrSegments.push_back( aNewSegment );
1035 Reference< XFastContextHandler > Path2DContext::createFastChildContext( sal_Int32 aElementToken,
1036 const Reference< XFastAttributeList >& xAttribs ) throw ( SAXException, RuntimeException )
1038 Reference< XFastContextHandler > xContext;
1039 switch( aElementToken )
1041 case A_TOKEN( close ) :
1043 // ignore close after move to (ppt does seems to do the same, see accentCallout2 preset for example)
1044 if ( mrSegments.empty() || ( mrSegments.back().Command != EnhancedCustomShapeSegmentCommand::MOVETO ) ) {
1045 EnhancedCustomShapeSegment aNewSegment;
1046 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::CLOSESUBPATH;
1047 aNewSegment.Count = 0;
1048 mrSegments.push_back( aNewSegment );
1051 break;
1052 case A_TOKEN( moveTo ) :
1054 EnhancedCustomShapeSegment aNewSegment;
1055 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::MOVETO;
1056 aNewSegment.Count = 1;
1057 mrSegments.push_back( aNewSegment );
1059 EnhancedCustomShapeParameterPair aAdjPoint2D;
1060 mrPath2D.parameter.push_back( aAdjPoint2D );
1061 xContext = new Path2DMoveToContext( *this, mrCustomShapeProperties, mrPath2D.parameter.back() );
1063 break;
1064 case A_TOKEN( lnTo ) :
1066 if ( !mrSegments.empty() && ( mrSegments.back().Command == EnhancedCustomShapeSegmentCommand::LINETO ) )
1067 mrSegments.back().Count++;
1068 else
1070 EnhancedCustomShapeSegment aSegment;
1071 aSegment.Command = EnhancedCustomShapeSegmentCommand::LINETO;
1072 aSegment.Count = 1;
1073 mrSegments.push_back( aSegment );
1075 EnhancedCustomShapeParameterPair aAdjPoint2D;
1076 mrPath2D.parameter.push_back( aAdjPoint2D );
1077 xContext = new Path2DLineToContext( *this, mrCustomShapeProperties, mrPath2D.parameter.back() );
1079 break;
1080 case A_TOKEN( arcTo ) : // CT_Path2DArcTo
1082 if ( !mrSegments.empty() && ( mrSegments.back().Command == EnhancedCustomShapeSegmentCommand::ARCANGLETO ) )
1083 mrSegments.back().Count++;
1084 else
1086 EnhancedCustomShapeSegment aSegment;
1087 aSegment.Command = EnhancedCustomShapeSegmentCommand::ARCANGLETO;
1088 aSegment.Count = 1;
1089 mrSegments.push_back( aSegment );
1092 EnhancedCustomShapeParameterPair aScale;
1093 EnhancedCustomShapeParameterPair aAngles;
1095 aScale.First = GetAdjCoordinate( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_wR ), sal_True );
1096 aScale.Second = GetAdjCoordinate( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_hR ), sal_True );
1098 CustomShapeGuide aGuide;
1099 sal_Int32 nArcNum = mrCustomShapeProperties.getArcNum();
1101 // start angle
1102 aGuide.maName = "arctosa" + OUString::valueOf( nArcNum );
1103 aGuide.maFormula = "("
1104 + GetFormulaParameter( GetAdjCoordinate( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_stAng ) ) )
1105 + ")/60000.0";
1106 aAngles.First.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( mrCustomShapeProperties.getGuideList(), aGuide ) );
1107 aAngles.First.Type = EnhancedCustomShapeParameterType::EQUATION;
1109 // swing angle
1110 aGuide.maName = "arctosw" + OUString::valueOf( nArcNum );
1111 aGuide.maFormula = "("
1112 + GetFormulaParameter( GetAdjCoordinate( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_swAng ) ) )
1113 + ")/60000.0";
1114 aAngles.Second.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( mrCustomShapeProperties.getGuideList(), aGuide ) );
1115 aAngles.Second.Type = EnhancedCustomShapeParameterType::EQUATION;
1117 mrPath2D.parameter.push_back( aScale );
1118 mrPath2D.parameter.push_back( aAngles );
1120 break;
1121 case A_TOKEN( quadBezTo ) :
1123 if ( !mrSegments.empty() && ( mrSegments.back().Command == EnhancedCustomShapeSegmentCommand::QUADRATICCURVETO ) )
1124 mrSegments.back().Count++;
1125 else
1127 EnhancedCustomShapeSegment aSegment;
1128 aSegment.Command = EnhancedCustomShapeSegmentCommand::QUADRATICCURVETO;
1129 aSegment.Count = 1;
1130 mrSegments.push_back( aSegment );
1132 EnhancedCustomShapeParameterPair aPt1;
1133 EnhancedCustomShapeParameterPair aPt2;
1134 mrPath2D.parameter.push_back( aPt1 );
1135 mrPath2D.parameter.push_back( aPt2 );
1136 xContext = new Path2DQuadBezierToContext( *this, mrCustomShapeProperties,
1137 mrPath2D.parameter[ mrPath2D.parameter.size() - 2 ],
1138 mrPath2D.parameter.back() );
1140 break;
1141 case A_TOKEN( cubicBezTo ) :
1143 if ( !mrSegments.empty() && ( mrSegments.back().Command == EnhancedCustomShapeSegmentCommand::CURVETO ) )
1144 mrSegments.back().Count++;
1145 else
1147 EnhancedCustomShapeSegment aSegment;
1148 aSegment.Command = EnhancedCustomShapeSegmentCommand::CURVETO;
1149 aSegment.Count = 1;
1150 mrSegments.push_back( aSegment );
1152 EnhancedCustomShapeParameterPair aControlPt1;
1153 EnhancedCustomShapeParameterPair aControlPt2;
1154 EnhancedCustomShapeParameterPair aEndPt;
1155 mrPath2D.parameter.push_back( aControlPt1 );
1156 mrPath2D.parameter.push_back( aControlPt2 );
1157 mrPath2D.parameter.push_back( aEndPt );
1158 xContext = new Path2DCubicBezierToContext( *this, mrCustomShapeProperties,
1159 mrPath2D.parameter[ mrPath2D.parameter.size() - 3 ],
1160 mrPath2D.parameter[ mrPath2D.parameter.size() - 2 ],
1161 mrPath2D.parameter.back() );
1163 break;
1165 return xContext;
1168 // ---------------------------------------------------------------------
1169 // CT_Path2DList
1170 class Path2DListContext : public ContextHandler
1172 public:
1173 Path2DListContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< EnhancedCustomShapeSegment >& rSegments,
1174 std::vector< Path2D >& rPath2DList );
1176 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
1178 protected:
1180 CustomShapeProperties& mrCustomShapeProperties;
1181 std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >& mrSegments;
1182 std::vector< Path2D >& mrPath2DList;
1185 Path2DListContext::Path2DListContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< EnhancedCustomShapeSegment >& rSegments,
1186 std::vector< Path2D >& rPath2DList )
1187 : ContextHandler( rParent )
1188 , mrCustomShapeProperties( rCustomShapeProperties )
1189 , mrSegments( rSegments )
1190 , mrPath2DList( rPath2DList )
1194 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL Path2DListContext::createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException)
1196 Reference< XFastContextHandler > xContext;
1197 if ( aElementToken == A_TOKEN( path ) )
1199 Path2D aPath2D;
1200 mrPath2DList.push_back( aPath2D );
1201 xContext = new Path2DContext( *this, xAttribs, mrCustomShapeProperties, mrSegments, mrPath2DList.back() );
1203 return xContext;
1206 // ---------------------------------------------------------------------
1207 // CT_CustomGeometry2D
1208 CustomShapeGeometryContext::CustomShapeGeometryContext( ContextHandler& rParent, const Reference< XFastAttributeList >& /* xAttribs */, CustomShapeProperties& rCustomShapeProperties )
1209 : ContextHandler( rParent )
1210 , mrCustomShapeProperties( rCustomShapeProperties )
1214 Reference< XFastContextHandler > CustomShapeGeometryContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
1216 Reference< XFastContextHandler > xContext;
1217 switch( aElementToken )
1219 case A_TOKEN( avLst ): // CT_GeomGuideList adjust value list
1220 xContext = new GeomGuideListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getAdjustmentGuideList() );
1221 break;
1222 case A_TOKEN( gdLst ): // CT_GeomGuideList guide list
1223 xContext = new GeomGuideListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getGuideList() );
1224 break;
1225 case A_TOKEN( ahLst ): // CT_AdjustHandleList adjust handle list
1226 xContext = new AdjustHandleListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getAdjustHandleList() );
1227 break;
1228 case A_TOKEN( cxnLst ): // CT_ConnectionSiteList connection site list
1229 xContext = this;
1230 break;
1231 case A_TOKEN( rect ): // CT_GeomRectList geometry rect list
1233 GeomRect aGeomRect;
1234 aGeomRect.l = GetAdjCoordinate( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_l ), sal_True );
1235 aGeomRect.t = GetAdjCoordinate( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_t ), sal_True );
1236 aGeomRect.r = GetAdjCoordinate( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_r ), sal_True );
1237 aGeomRect.b = GetAdjCoordinate( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_b ), sal_True );
1238 mrCustomShapeProperties.getTextRect() = aGeomRect;
1240 break;
1241 case A_TOKEN( pathLst ): // CT_Path2DList 2d path list
1242 xContext = new Path2DListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getSegments(), mrCustomShapeProperties.getPath2DList() );
1243 break;
1245 // from cxnLst:
1246 case A_TOKEN( cxn ): // CT_ConnectionSite
1248 ConnectionSite aConnectionSite;
1249 mrCustomShapeProperties.getConnectionSiteList().push_back( aConnectionSite );
1250 xContext = new ConnectionSiteContext( *this, xAttribs, mrCustomShapeProperties, mrCustomShapeProperties.getConnectionSiteList().back() );
1252 break;
1254 return xContext;
1257 // ---------------------------------------------------------------------
1258 // CT_PresetGeometry2D
1259 PresetShapeGeometryContext::PresetShapeGeometryContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties )
1260 : ContextHandler( rParent )
1261 , mrCustomShapeProperties( rCustomShapeProperties )
1263 sal_Int32 nShapeType = xAttribs->getOptionalValueToken( XML_prst, FastToken::DONTKNOW );
1264 OSL_ENSURE( nShapeType != FastToken::DONTKNOW, "oox::drawingml::CustomShapeCustomGeometryContext::CustomShapeCustomGeometryContext(), unknown shape type" );
1265 mrCustomShapeProperties.setShapePresetType( nShapeType );
1268 Reference< XFastContextHandler > PresetShapeGeometryContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException)
1270 if ( aElementToken == A_TOKEN( avLst ) )
1271 return new GeomGuideListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getAdjustmentGuideList() );
1272 else
1273 return this;
1276 // ---------------------------------------------------------------------
1277 // CT_PresetTextShape
1278 PresetTextShapeContext::PresetTextShapeContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties )
1279 : ContextHandler( rParent )
1280 , mrCustomShapeProperties( rCustomShapeProperties )
1282 sal_Int32 nShapeType = xAttribs->getOptionalValueToken( XML_prst, FastToken::DONTKNOW );
1283 OSL_ENSURE( nShapeType != FastToken::DONTKNOW, "oox::drawingml::CustomShapeCustomGeometryContext::CustomShapeCustomGeometryContext(), unknown shape type" );
1284 mrCustomShapeProperties.setShapePresetType( nShapeType );
1287 Reference< XFastContextHandler > PresetTextShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException)
1289 if ( aElementToken == A_TOKEN( avLst ) )
1290 return new GeomGuideListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getAdjustmentGuideList() );
1291 else
1292 return this;
1297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */