fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / oox / source / drawingml / customshapegeometry.cxx
blobb8857c02b9cb67328d6d6f1a4ac4d20ba7890f61
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 "drawingml/customshapegeometry.hxx"
21 #include <drawingml/customshapeproperties.hxx>
23 #include <com/sun/star/xml/sax/FastToken.hpp>
24 #include <osl/diagnose.h>
25 #include "oox/helper/helper.hxx"
26 #include "oox/helper/attributelist.hxx"
27 #include "oox/helper/propertymap.hxx"
28 #include <unordered_map>
30 using namespace ::oox::core;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::beans;
33 using namespace ::com::sun::star::drawing;
34 using namespace ::com::sun::star::xml::sax;
36 namespace oox { namespace drawingml {
38 enum FormularCommand
40 FC_MULDIV = 0,
41 FC_PLUSMINUS,
42 FC_PLUSDIV,
43 FC_IFELSE,
44 FC_IFELSE1,
45 FC_ABS,
46 FC_AT2,
47 FC_CAT2,
48 FC_COS,
49 FC_MAX,
50 FC_MIN,
51 FC_MOD,
52 FC_PIN,
53 FC_SAT2,
54 FC_SIN,
55 FC_SQRT,
56 FC_TAN,
57 FC_VAL,
58 FC_LAST
60 struct FormularCommandNameTable
62 const char* pS;
63 FormularCommand pE;
65 static const FormularCommandNameTable pFormularCommandNameTable[] =
67 { "*/", FC_MULDIV },
68 { "+-", FC_PLUSMINUS },
69 { "+/", FC_PLUSDIV },
70 { "ifelse", FC_IFELSE },
71 { "?:", FC_IFELSE1 },
72 { "abs", FC_ABS },
73 { "at2", FC_AT2 },
74 { "cat2", FC_CAT2 },
75 { "cos", FC_COS },
76 { "max", FC_MAX },
77 { "min", FC_MIN },
78 { "mod", FC_MOD },
79 { "pin", FC_PIN },
80 { "sat2", FC_SAT2 },
81 { "sin", FC_SIN },
82 { "sqrt", FC_SQRT },
83 { "tan", FC_TAN },
84 { "val", FC_VAL }
87 typedef std::unordered_map< OUString, FormularCommand, OUStringHash > FormulaCommandHMap;
89 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::number( fValue );
104 else
106 sal_Int32 nValue = 0;
107 if ( rParameter.Value >>= nValue )
108 aRet = OUString::number( 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::number( 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::number( 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 static EnhancedCustomShapeParameter GetAdjCoordinate( CustomShapeProperties& rCustomShapeProperties, const OUString& rValue, bool bNoSymbols = true )
226 com::sun::star::drawing::EnhancedCustomShapeParameter aRet;
227 if ( !rValue.isEmpty() )
229 bool bConstant = true;
230 sal_Int32 nConstant = -1;
231 sal_Int32 nIntVal = 0;
233 // first check if it's a constant value
234 switch( AttributeConversion::decodeToken( rValue ) )
236 case XML_3cd4 : nConstant = 270 * 60000; break;
237 case XML_3cd8 : nConstant = 135 * 60000; break;
238 case XML_5cd8 : nConstant = 225 * 60000; break;
239 case XML_7cd8 : nConstant = 315 * 60000; break;
240 case XML_cd2 : nConstant = 180 * 60000; break;
241 case XML_cd3 : nConstant = 120 * 60000; break;
242 case XML_cd4 : nConstant = 90 * 60000; break;
243 case XML_cd8 : nConstant = 45 * 60000; break;
245 case XML_b : // variable height of the shape defined in spPr
246 case XML_h :
248 if ( bNoSymbols )
250 CustomShapeGuide aGuide;
251 aGuide.maName = rValue;
252 aGuide.maFormula = "logheight" ;
254 aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) );
255 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
257 else
258 aRet.Type = EnhancedCustomShapeParameterType::LOGHEIGHT; // TODO: HEIGHT needs to be implemented
260 break;
262 case XML_hd10 : // !!PASSTHROUGH INTENDED
263 nIntVal += 2; // */ h 1.0 10.0
264 case XML_hd8 : // */ h 1.0 8.0
265 nIntVal += 2;
266 case XML_hd6 : // */ h 1.0 6.0
267 nIntVal++;
268 case XML_hd5 : // */ h 1.0 5.0
269 nIntVal++;
270 case XML_hd4 : // */ h 1.0 4.0
271 nIntVal++;
272 case XML_hd3 : // */ h 1.0 3.0
273 nIntVal++;
274 case XML_hd2 : // */ h 1.0 2.0
275 case XML_vc : // */ h 1.0 2.0
277 nIntVal += 2;
279 CustomShapeGuide aGuide;
280 aGuide.maName = rValue;
281 aGuide.maFormula = "logheight/" + OUString::number( nIntVal );
283 aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) );
284 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
286 break;
288 case XML_t :
289 case XML_l :
291 nConstant = 0;
292 aRet.Type = EnhancedCustomShapeParameterType::NORMAL;
294 break;
296 case XML_ls : // longest side: max w h
298 CustomShapeGuide aGuide;
299 aGuide.maName = rValue;
300 aGuide.maFormula = "max(logwidth,logheight)";
302 aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) );
303 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
305 break;
306 case XML_ss : // shortest side: min w h
308 CustomShapeGuide aGuide;
309 aGuide.maName = rValue;
310 aGuide.maFormula = "min(logwidth,logheight)";
312 aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) );
313 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
315 break;
316 case XML_ssd32 : // */ ss 1.0 32.0
317 nIntVal += 16;
318 case XML_ssd16 : // */ ss 1.0 16.0
319 nIntVal += 8;
320 case XML_ssd8 : // */ ss 1.0 8.0
321 nIntVal += 2;
322 case XML_ssd6 : // */ ss 1.0 6.0
323 nIntVal += 2;
324 case XML_ssd4 : // */ ss 1.0 4.0
325 nIntVal += 2;
326 case XML_ssd2 : // */ ss 1.0 2.0
328 nIntVal += 2;
330 CustomShapeGuide aGuide;
331 aGuide.maName = rValue;
332 aGuide.maFormula = "min(logwidth,logheight)/" + OUString::number( nIntVal );
334 aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) );
335 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
337 break;
339 case XML_r : // variable width of the shape defined in spPr
340 case XML_w :
342 if ( bNoSymbols )
344 CustomShapeGuide aGuide;
345 aGuide.maName = rValue;
346 aGuide.maFormula = "logwidth" ;
348 aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) );
349 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
351 else
352 aRet.Type = EnhancedCustomShapeParameterType::LOGWIDTH;
354 break;
356 case XML_wd32 : // */ w 1.0 32.0
357 nIntVal += 20;
358 case XML_wd12 : // */ w 1.0 12.0
359 nIntVal += 2;
360 case XML_wd10 : // */ w 1.0 10.0
361 nIntVal += 2;
362 case XML_wd8 : // */ w 1.0 8.0
363 nIntVal += 2;
364 case XML_wd6 : // */ w 1.0 6.0
365 nIntVal++;
366 case XML_wd5 : // */ w 1.0 5.0
367 nIntVal++;
368 case XML_wd4 : // */ w 1.0 4.0
369 nIntVal++;
370 case XML_wd3 : // */ w 1.0 3.0
371 nIntVal++;
372 case XML_hc : // */ w 1.0 2.0
373 case XML_wd2 : // */ w 1.0 2.0
375 nIntVal += 2;
377 CustomShapeGuide aGuide;
378 aGuide.maName = rValue;
379 aGuide.maFormula = "logwidth/" + OUString::number( nIntVal );
381 aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) );
382 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
384 break;
386 default:
387 bConstant = false;
388 break;
390 if ( bConstant )
392 if (nConstant != -1) {
393 aRet.Value = Any( nConstant );
394 aRet.Type = EnhancedCustomShapeParameterType::NORMAL;
397 else
399 sal_Unicode n = rValue[ 0 ];
400 if ( ( n == '+' ) || ( n == '-' ) )
402 if ( rValue.getLength() > 1 )
403 n = rValue[ 1 ];
405 if ( ( n >= '0' ) && ( n <= '9' ) )
406 { // seems to be a ST_Coordinate
407 aRet.Value = Any( (sal_Int32)(rValue.toInt32() ) );
408 aRet.Type = EnhancedCustomShapeParameterType::NORMAL;
410 else
412 sal_Int32 nGuideIndex = CustomShapeProperties::GetCustomShapeGuideValue( rCustomShapeProperties.getAdjustmentGuideList(), rValue );
413 if ( nGuideIndex >= 0 )
415 aRet.Value = Any( nGuideIndex );
416 aRet.Type = EnhancedCustomShapeParameterType::ADJUSTMENT;
418 else
420 nGuideIndex = CustomShapeProperties::GetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), rValue );
421 if ( nGuideIndex >= 0 )
423 aRet.Value = Any( nGuideIndex );
424 aRet.Type = EnhancedCustomShapeParameterType::EQUATION;
426 else
428 OSL_TRACE("error: unhandled value '%s'", OUStringToOString( rValue, RTL_TEXTENCODING_ASCII_US ).getStr());
429 aRet.Value = Any( rValue );
435 return aRet;
438 // CT_GeomGuideList
439 class GeomGuideListContext : public ContextHandler2
441 public:
442 GeomGuideListContext( ContextHandler2Helper& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< CustomShapeGuide >& rGuideList );
443 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const ::oox::AttributeList& rAttribs ) SAL_OVERRIDE;
445 protected:
446 std::vector< CustomShapeGuide >& mrGuideList;
447 CustomShapeProperties& mrCustomShapeProperties;
450 GeomGuideListContext::GeomGuideListContext( ContextHandler2Helper& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< CustomShapeGuide >& rGuideList )
451 : ContextHandler2( rParent )
452 , mrGuideList( rGuideList )
453 , mrCustomShapeProperties( rCustomShapeProperties )
457 static OUString convertToOOEquation( CustomShapeProperties& rCustomShapeProperties, const OUString& rSource )
459 if ( !pCommandHashMap )
461 FormulaCommandHMap* pHM = new FormulaCommandHMap();
462 for( sal_Int32 i = 0; i < FC_LAST; i++ )
463 (*pHM)[ OUString::createFromAscii( pFormularCommandNameTable[ i ].pS ) ] = pFormularCommandNameTable[ i ].pE;
464 pCommandHashMap = pHM;
467 std::vector< OUString > aTokens;
468 sal_Int32 nIndex = 0;
471 OUString aToken( rSource.getToken( 0, ' ', nIndex ) );
472 if ( !aToken.isEmpty() )
473 aTokens.push_back( aToken );
475 while ( nIndex >= 0 );
477 OUString aEquation;
478 if ( !aTokens.empty() )
480 sal_Int32 i, nParameters = aTokens.size() - 1;
481 if ( nParameters > 3 )
482 nParameters = 3;
484 OUString sParameters[ 3 ];
486 for ( i = 0; i < nParameters; i++ )
487 sParameters[ i ] = GetFormulaParameter( GetAdjCoordinate( rCustomShapeProperties, aTokens[ i + 1 ], false ) );
489 const FormulaCommandHMap::const_iterator aIter( pCommandHashMap->find( aTokens[ 0 ] ) );
490 if ( aIter != pCommandHashMap->end() )
492 switch( aIter->second )
494 case FC_MULDIV :
496 if ( nParameters == 3 )
497 aEquation = sParameters[ 0 ] + "*" + sParameters[ 1 ]
498 + "/" + sParameters[ 2 ];
500 break;
501 case FC_PLUSMINUS :
503 if ( nParameters == 3 )
504 aEquation = sParameters[ 0 ] + "+" + sParameters[ 1 ]
505 + "-" + sParameters[ 2 ];
507 break;
508 case FC_PLUSDIV :
510 if ( nParameters == 3 )
511 aEquation = "(" + sParameters[ 0 ] + "+"
512 + sParameters[ 1 ] + ")/" + sParameters[ 2 ];
514 break;
515 case FC_IFELSE :
516 case FC_IFELSE1 :
518 if ( nParameters == 3 )
519 aEquation = "if(" + sParameters[ 0 ] + ","
520 + sParameters[ 1 ] + "," + sParameters[ 2 ] + ")";
522 break;
523 case FC_ABS :
525 if ( nParameters == 1 )
526 aEquation = "abs(" + sParameters[ 0 ] + ")";
528 break;
529 case FC_AT2 :
531 if ( nParameters == 2 )
532 aEquation = "(10800000*atan2(" + sParameters[ 1 ] + ","
533 + sParameters[ 0 ] + "))/pi";
535 break;
536 case FC_CAT2 :
538 if ( nParameters == 3 )
539 aEquation = sParameters[ 0 ] + "*(cos(atan2(" +
540 sParameters[ 2 ] + "," + sParameters[ 1 ] + ")))";
542 break;
543 case FC_COS :
545 if ( nParameters == 2 )
546 aEquation = sParameters[ 0 ] + "*cos(pi*(" +
547 sParameters[ 1 ] + ")/10800000)";
549 break;
550 case FC_MAX :
552 if ( nParameters == 2 )
553 aEquation = "max(" + sParameters[ 0 ] + "," +
554 sParameters[ 1 ] + ")";
556 break;
557 case FC_MIN :
559 if ( nParameters == 2 )
560 aEquation = "min(" + sParameters[ 0 ] + "," +
561 sParameters[ 1 ] + ")";
563 break;
564 case FC_MOD :
566 if ( nParameters == 3 )
567 aEquation = "sqrt("
568 + sParameters[ 0 ] + "*" + sParameters[ 0 ] + "+"
569 + sParameters[ 1 ] + "*" + sParameters[ 1 ] + "+"
570 + sParameters[ 2 ] + "*" + sParameters[ 2 ] + ")";
572 break;
573 case FC_PIN :
575 if ( nParameters == 3 ) // if(x-y,x,if(y-z,z,y))
576 aEquation = "if(" + sParameters[ 0 ] + "-" + sParameters[ 1 ]
577 + "," + sParameters[ 0 ] + ",if(" + sParameters[ 2 ]
578 + "-" + sParameters[ 1 ] + "," + sParameters[ 1 ]
579 + "," + sParameters[ 2 ] + "))";
581 break;
582 case FC_SAT2 :
584 if ( nParameters == 3 )
585 aEquation = sParameters[ 0 ] + "*(sin(atan2(" +
586 sParameters[ 2 ] + "," + sParameters[ 1 ] + ")))";
588 break;
589 case FC_SIN :
591 if ( nParameters == 2 )
592 aEquation = sParameters[ 0 ] + "*sin(pi*(" +
593 sParameters[ 1 ] + ")/10800000)";
595 break;
596 case FC_SQRT :
598 if ( nParameters == 1 )
599 aEquation = "sqrt(" + sParameters[ 0 ] + ")";
601 break;
602 case FC_TAN :
604 if ( nParameters == 2 )
605 aEquation = sParameters[ 0 ] + "*tan(pi*(" +
606 sParameters[ 1 ] + ")/10800000)";
608 break;
609 case FC_VAL :
611 if ( nParameters == 1 )
612 aEquation = sParameters[ 0 ];
614 break;
615 default :
616 break;
620 return aEquation;
623 ContextHandlerRef GeomGuideListContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
625 if ( aElementToken == A_TOKEN( gd ) ) // CT_GeomGuide
627 CustomShapeGuide aGuide;
628 aGuide.maName = rAttribs.getString( XML_name ).get();
629 aGuide.maFormula = convertToOOEquation( mrCustomShapeProperties, rAttribs.getString( XML_fmla ).get() );
630 mrGuideList.push_back( aGuide );
632 return this;
635 static const OUString GetGeomGuideName( const OUString& rValue )
637 return rValue;
640 // CT_AdjPoint2D
641 class AdjPoint2DContext : public ContextHandler2
643 public:
644 AdjPoint2DContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D );
647 AdjPoint2DContext::AdjPoint2DContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D )
648 : ContextHandler2( rParent )
650 rAdjPoint2D.First = GetAdjCoordinate( rCustomShapeProperties, rAttribs.getString( XML_x ).get(), true );
651 rAdjPoint2D.Second = GetAdjCoordinate( rCustomShapeProperties, rAttribs.getString( XML_y ).get(), true );
654 // CT_XYAdjustHandle
655 class XYAdjustHandleContext : public ContextHandler2
657 public:
658 XYAdjustHandleContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, CustomShapeProperties& rCustomShapeProperties, AdjustHandle& rAdjustHandle );
659 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const ::oox::AttributeList& rAttribs ) SAL_OVERRIDE;
661 protected:
662 AdjustHandle& mrAdjustHandle;
663 CustomShapeProperties& mrCustomShapeProperties;
666 XYAdjustHandleContext::XYAdjustHandleContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, CustomShapeProperties& rCustomShapeProperties, AdjustHandle& rAdjustHandle )
667 : ContextHandler2( rParent )
668 , mrAdjustHandle( rAdjustHandle )
669 , mrCustomShapeProperties( rCustomShapeProperties )
671 const OUString aEmptyDefault;
672 if ( rAttribs.hasAttribute( XML_gdRefX ) )
674 mrAdjustHandle.gdRef1 = GetGeomGuideName( rAttribs.getString( XML_gdRefX, aEmptyDefault ) );
676 if ( rAttribs.hasAttribute( XML_minX ) )
678 mrAdjustHandle.min1 = GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_minX, aEmptyDefault ), true );
680 if ( rAttribs.hasAttribute( XML_maxX ) )
682 mrAdjustHandle.max1 = GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_maxX, aEmptyDefault ), true );
684 if ( rAttribs.hasAttribute( XML_gdRefY ) )
686 mrAdjustHandle.gdRef2 = GetGeomGuideName( rAttribs.getString( XML_gdRefY, aEmptyDefault ) );
688 if ( rAttribs.hasAttribute( XML_minY ) )
690 mrAdjustHandle.min2 = GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_minY, aEmptyDefault ), true );
692 if ( rAttribs.hasAttribute( XML_maxY ) )
694 mrAdjustHandle.max2 = GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_maxY, aEmptyDefault ), true );
698 ContextHandlerRef XYAdjustHandleContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
700 if ( aElementToken == A_TOKEN( pos ) )
701 return new AdjPoint2DContext( *this, rAttribs, mrCustomShapeProperties, mrAdjustHandle.pos ); // CT_AdjPoint2D
702 return 0;
705 // CT_PolarAdjustHandle
706 class PolarAdjustHandleContext : public ContextHandler2
708 public:
709 PolarAdjustHandleContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, CustomShapeProperties& rCustomShapeProperties, AdjustHandle& rAdjustHandle );
710 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const ::oox::AttributeList& rAttribs ) SAL_OVERRIDE;
712 protected:
713 AdjustHandle& mrAdjustHandle;
714 CustomShapeProperties& mrCustomShapeProperties;
717 PolarAdjustHandleContext::PolarAdjustHandleContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, CustomShapeProperties& rCustomShapeProperties, AdjustHandle& rAdjustHandle )
718 : ContextHandler2( rParent )
719 , mrAdjustHandle( rAdjustHandle )
720 , mrCustomShapeProperties( rCustomShapeProperties )
722 const OUString aEmptyDefault;
723 if ( rAttribs.hasAttribute( XML_gdRefR ) )
725 mrAdjustHandle.gdRef1 = GetGeomGuideName( rAttribs.getString( XML_gdRefR, aEmptyDefault ) );
727 if ( rAttribs.hasAttribute( XML_minR ) )
729 mrAdjustHandle.min1 = GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_minR, aEmptyDefault ), true );
731 if ( rAttribs.hasAttribute( XML_maxR ) )
733 mrAdjustHandle.max1 = GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_maxR, aEmptyDefault ), true );
735 if ( rAttribs.hasAttribute( XML_gdRefAng ) )
737 mrAdjustHandle.gdRef2 = GetGeomGuideName( rAttribs.getString( XML_gdRefAng, aEmptyDefault ) );
739 if ( rAttribs.hasAttribute( XML_minAng ) )
741 mrAdjustHandle.min2 = GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_minAng, aEmptyDefault ) );
743 if ( rAttribs.hasAttribute( XML_maxAng ) )
745 mrAdjustHandle.max2 = GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_maxAng, aEmptyDefault ) );
749 ContextHandlerRef PolarAdjustHandleContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
751 if ( aElementToken == A_TOKEN( pos ) )
752 return new AdjPoint2DContext( *this, rAttribs, mrCustomShapeProperties, mrAdjustHandle.pos ); // CT_AdjPoint2D
753 return 0;
756 // CT_AdjustHandleList
757 class AdjustHandleListContext : public ContextHandler2
759 public:
760 AdjustHandleListContext( ContextHandler2Helper& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< AdjustHandle >& rAdjustHandleList );
761 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const ::oox::AttributeList& rAttribs ) SAL_OVERRIDE;
763 protected:
764 std::vector< AdjustHandle >& mrAdjustHandleList;
765 CustomShapeProperties& mrCustomShapeProperties;
768 AdjustHandleListContext::AdjustHandleListContext( ContextHandler2Helper& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< AdjustHandle >& rAdjustHandleList )
769 : ContextHandler2( rParent )
770 , mrAdjustHandleList( rAdjustHandleList )
771 , mrCustomShapeProperties( rCustomShapeProperties )
775 ContextHandlerRef AdjustHandleListContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
777 if ( aElementToken == A_TOKEN( ahXY ) ) // CT_XYAdjustHandle
779 AdjustHandle aAdjustHandle( false );
780 mrAdjustHandleList.push_back( aAdjustHandle );
781 return new XYAdjustHandleContext( *this, rAttribs, mrCustomShapeProperties, mrAdjustHandleList.back() );
783 else if ( aElementToken == A_TOKEN( ahPolar ) ) // CT_PolarAdjustHandle
785 AdjustHandle aAdjustHandle( true );
786 mrAdjustHandleList.push_back( aAdjustHandle );
787 return new PolarAdjustHandleContext( *this, rAttribs, mrCustomShapeProperties, mrAdjustHandleList.back() );
789 return 0;
792 // CT_ConnectionSite
793 class ConnectionSiteContext : public ContextHandler2
795 public:
796 ConnectionSiteContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, CustomShapeProperties& rCustomShapeProperties, ConnectionSite& rConnectionSite );
797 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const ::oox::AttributeList& rAttribs ) SAL_OVERRIDE;
799 protected:
800 ConnectionSite& mrConnectionSite;
801 CustomShapeProperties& mrCustomShapeProperties;
804 ConnectionSiteContext::ConnectionSiteContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, CustomShapeProperties& rCustomShapeProperties, ConnectionSite& rConnectionSite )
805 : ContextHandler2( rParent )
806 , mrConnectionSite( rConnectionSite )
807 , mrCustomShapeProperties( rCustomShapeProperties )
809 mrConnectionSite.ang = GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_ang ).get() );
812 ContextHandlerRef ConnectionSiteContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
814 if ( aElementToken == A_TOKEN( pos ) )
815 return new AdjPoint2DContext( *this, rAttribs, mrCustomShapeProperties, mrConnectionSite.pos ); // CT_AdjPoint2D
816 return 0;
819 // CT_Path2DMoveTo
820 class Path2DMoveToContext : public ContextHandler2
822 public:
823 Path2DMoveToContext( ContextHandler2Helper& rParent, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D );
824 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const ::oox::AttributeList& rAttribs ) SAL_OVERRIDE;
826 protected:
827 EnhancedCustomShapeParameterPair& mrAdjPoint2D;
828 CustomShapeProperties& mrCustomShapeProperties;
831 Path2DMoveToContext::Path2DMoveToContext( ContextHandler2Helper& rParent, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D )
832 : ContextHandler2( rParent )
833 , mrAdjPoint2D( rAdjPoint2D )
834 , mrCustomShapeProperties( rCustomShapeProperties )
838 ContextHandlerRef Path2DMoveToContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
840 if ( aElementToken == A_TOKEN( pt ) )
841 return new AdjPoint2DContext( *this, rAttribs, mrCustomShapeProperties, mrAdjPoint2D ); // CT_AdjPoint2D
842 return 0;
845 // CT_Path2DLineTo
846 class Path2DLineToContext : public ContextHandler2
848 public:
849 Path2DLineToContext( ContextHandler2Helper& rParent, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D );
850 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const ::oox::AttributeList& rAttribs ) SAL_OVERRIDE;
852 protected:
853 EnhancedCustomShapeParameterPair& mrAdjPoint2D;
854 CustomShapeProperties& mrCustomShapeProperties;
857 Path2DLineToContext::Path2DLineToContext( ContextHandler2Helper& rParent, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D )
858 : ContextHandler2( rParent )
859 , mrAdjPoint2D( rAdjPoint2D )
860 , mrCustomShapeProperties( rCustomShapeProperties )
864 ContextHandlerRef Path2DLineToContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
866 if ( aElementToken == A_TOKEN( pt ) )
867 return new AdjPoint2DContext( *this, rAttribs, mrCustomShapeProperties, mrAdjPoint2D ); // CT_AdjPoint2D
868 return 0;
871 // CT_Path2DQuadBezierTo
872 class Path2DQuadBezierToContext : public ContextHandler2
874 public:
875 Path2DQuadBezierToContext( ContextHandler2Helper& rParent, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rPt1, EnhancedCustomShapeParameterPair& rPt2 );
876 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const ::oox::AttributeList& rAttribs ) SAL_OVERRIDE;
878 protected:
879 EnhancedCustomShapeParameterPair& mrPt1;
880 EnhancedCustomShapeParameterPair& mrPt2;
881 int nCount;
882 CustomShapeProperties& mrCustomShapeProperties;
885 Path2DQuadBezierToContext::Path2DQuadBezierToContext( ContextHandler2Helper& rParent,
886 CustomShapeProperties& rCustomShapeProperties,
887 EnhancedCustomShapeParameterPair& rPt1,
888 EnhancedCustomShapeParameterPair& rPt2 )
889 : ContextHandler2( rParent )
890 , mrPt1( rPt1 )
891 , mrPt2( rPt2 )
892 , nCount( 0 )
893 , mrCustomShapeProperties( rCustomShapeProperties )
897 ContextHandlerRef Path2DQuadBezierToContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
899 if ( aElementToken == A_TOKEN( pt ) )
900 return new AdjPoint2DContext( *this, rAttribs, mrCustomShapeProperties, nCount++ ? mrPt2 : mrPt1 ); // CT_AdjPoint2D
901 return 0;
904 // CT_Path2DCubicBezierTo
905 class Path2DCubicBezierToContext : public ContextHandler2
907 public:
908 Path2DCubicBezierToContext( ContextHandler2Helper& rParent, CustomShapeProperties& rCustomShapeProperties,
909 EnhancedCustomShapeParameterPair&, EnhancedCustomShapeParameterPair&, EnhancedCustomShapeParameterPair& );
910 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const ::oox::AttributeList& rAttribs ) SAL_OVERRIDE;
912 protected:
913 CustomShapeProperties& mrCustomShapeProperties;
914 EnhancedCustomShapeParameterPair& mrControlPt1;
915 EnhancedCustomShapeParameterPair& mrControlPt2;
916 EnhancedCustomShapeParameterPair& mrEndPt;
917 int nCount;
920 Path2DCubicBezierToContext::Path2DCubicBezierToContext( ContextHandler2Helper& rParent, CustomShapeProperties& rCustomShapeProperties,
921 EnhancedCustomShapeParameterPair& rControlPt1,
922 EnhancedCustomShapeParameterPair& rControlPt2,
923 EnhancedCustomShapeParameterPair& rEndPt )
924 : ContextHandler2( rParent )
925 , mrCustomShapeProperties( rCustomShapeProperties )
926 , mrControlPt1( rControlPt1 )
927 , mrControlPt2( rControlPt2 )
928 , mrEndPt( rEndPt )
929 , nCount( 0 )
933 ContextHandlerRef Path2DCubicBezierToContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
935 if ( aElementToken == A_TOKEN( pt ) )
936 return new AdjPoint2DContext( *this, rAttribs, mrCustomShapeProperties,
937 nCount++ ? nCount == 2 ? mrControlPt2 : mrEndPt : mrControlPt1 ); // CT_AdjPoint2D
938 return 0;
941 // CT_Path2DContext
942 class Path2DContext : public ContextHandler2
944 public:
945 Path2DContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, CustomShapeProperties& rCustomShapeProperties, std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >& rSegments, Path2D& rPath2D );
946 virtual ~Path2DContext();
947 virtual ::oox::core::ContextHandlerRef
948 onCreateContext( sal_Int32 aElementToken, const ::oox::AttributeList& rAttribs ) SAL_OVERRIDE;
950 protected:
951 Path2D& mrPath2D;
952 std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >& mrSegments;
953 CustomShapeProperties& mrCustomShapeProperties;
956 Path2DContext::Path2DContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, CustomShapeProperties& rCustomShapeProperties, std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >& rSegments, Path2D& rPath2D )
957 : ContextHandler2( rParent )
958 , mrPath2D( rPath2D )
959 , mrSegments( rSegments )
960 , mrCustomShapeProperties( rCustomShapeProperties )
962 const OUString aEmptyString;
964 rPath2D.w = rAttribs.getString( XML_w, aEmptyString ).toInt64();
965 rPath2D.h = rAttribs.getString( XML_h, aEmptyString ).toInt64();
966 rPath2D.fill = rAttribs.getToken( XML_fill, XML_norm );
967 rPath2D.stroke = rAttribs.getBool( XML_stroke, true );
968 rPath2D.extrusionOk = rAttribs.getBool( XML_extrusionOk, true );
971 Path2DContext::~Path2DContext()
973 EnhancedCustomShapeSegment aNewSegment;
974 switch ( mrPath2D.fill )
976 case XML_none:
977 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::NOFILL;
978 break;
979 case XML_darken:
980 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::DARKEN;
981 break;
982 case XML_darkenLess:
983 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::DARKENLESS;
984 break;
985 case XML_lighten:
986 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::LIGHTEN;
987 break;
988 case XML_lightenLess:
989 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::LIGHTENLESS;
990 break;
992 if (mrPath2D.fill != XML_norm) {
993 aNewSegment.Count = 0;
994 mrSegments.push_back( aNewSegment );
996 if ( !mrPath2D.stroke )
998 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::NOSTROKE;
999 aNewSegment.Count = 0;
1000 mrSegments.push_back( aNewSegment );
1002 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::ENDSUBPATH;
1003 aNewSegment.Count = 0;
1004 mrSegments.push_back( aNewSegment );
1007 ContextHandlerRef Path2DContext::onCreateContext( sal_Int32 aElementToken,
1008 const AttributeList& rAttribs )
1010 switch( aElementToken )
1012 case A_TOKEN( close ) :
1014 // ignore close after move to (ppt does seems to do the same, see accentCallout2 preset for example)
1015 if ( mrSegments.empty() || ( mrSegments.back().Command != EnhancedCustomShapeSegmentCommand::MOVETO ) ) {
1016 EnhancedCustomShapeSegment aNewSegment;
1017 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::CLOSESUBPATH;
1018 aNewSegment.Count = 0;
1019 mrSegments.push_back( aNewSegment );
1022 break;
1023 case A_TOKEN( moveTo ) :
1025 EnhancedCustomShapeSegment aNewSegment;
1026 aNewSegment.Command = EnhancedCustomShapeSegmentCommand::MOVETO;
1027 aNewSegment.Count = 1;
1028 mrSegments.push_back( aNewSegment );
1030 EnhancedCustomShapeParameterPair aAdjPoint2D;
1031 mrPath2D.parameter.push_back( aAdjPoint2D );
1032 return new Path2DMoveToContext( *this, mrCustomShapeProperties, mrPath2D.parameter.back() );
1034 break;
1035 case A_TOKEN( lnTo ) :
1037 if ( !mrSegments.empty() && ( mrSegments.back().Command == EnhancedCustomShapeSegmentCommand::LINETO ) )
1038 mrSegments.back().Count++;
1039 else
1041 EnhancedCustomShapeSegment aSegment;
1042 aSegment.Command = EnhancedCustomShapeSegmentCommand::LINETO;
1043 aSegment.Count = 1;
1044 mrSegments.push_back( aSegment );
1046 EnhancedCustomShapeParameterPair aAdjPoint2D;
1047 mrPath2D.parameter.push_back( aAdjPoint2D );
1048 return new Path2DLineToContext( *this, mrCustomShapeProperties, mrPath2D.parameter.back() );
1050 break;
1051 case A_TOKEN( arcTo ) : // CT_Path2DArcTo
1053 if ( !mrSegments.empty() && ( mrSegments.back().Command == EnhancedCustomShapeSegmentCommand::ARCANGLETO ) )
1054 mrSegments.back().Count++;
1055 else
1057 EnhancedCustomShapeSegment aSegment;
1058 aSegment.Command = EnhancedCustomShapeSegmentCommand::ARCANGLETO;
1059 aSegment.Count = 1;
1060 mrSegments.push_back( aSegment );
1063 EnhancedCustomShapeParameterPair aScale;
1064 EnhancedCustomShapeParameterPair aAngles;
1066 aScale.First = GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_wR ).get(), true );
1067 aScale.Second = GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_hR ).get(), true );
1069 CustomShapeGuide aGuide;
1070 sal_Int32 nArcNum = mrCustomShapeProperties.getArcNum();
1072 // start angle
1073 aGuide.maName = "arctosa" + OUString::number( nArcNum );
1074 aGuide.maFormula = "("
1075 + GetFormulaParameter( GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_stAng ).get() ) )
1076 + ")/60000.0";
1077 aAngles.First.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( mrCustomShapeProperties.getGuideList(), aGuide ) );
1078 aAngles.First.Type = EnhancedCustomShapeParameterType::EQUATION;
1080 // swing angle
1081 aGuide.maName = "arctosw" + OUString::number( nArcNum );
1082 aGuide.maFormula = "("
1083 + GetFormulaParameter( GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_swAng ).get() ) )
1084 + ")/60000.0";
1085 aAngles.Second.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( mrCustomShapeProperties.getGuideList(), aGuide ) );
1086 aAngles.Second.Type = EnhancedCustomShapeParameterType::EQUATION;
1088 mrPath2D.parameter.push_back( aScale );
1089 mrPath2D.parameter.push_back( aAngles );
1091 break;
1092 case A_TOKEN( quadBezTo ) :
1094 if ( !mrSegments.empty() && ( mrSegments.back().Command == EnhancedCustomShapeSegmentCommand::QUADRATICCURVETO ) )
1095 mrSegments.back().Count++;
1096 else
1098 EnhancedCustomShapeSegment aSegment;
1099 aSegment.Command = EnhancedCustomShapeSegmentCommand::QUADRATICCURVETO;
1100 aSegment.Count = 1;
1101 mrSegments.push_back( aSegment );
1103 EnhancedCustomShapeParameterPair aPt1;
1104 EnhancedCustomShapeParameterPair aPt2;
1105 mrPath2D.parameter.push_back( aPt1 );
1106 mrPath2D.parameter.push_back( aPt2 );
1107 return new Path2DQuadBezierToContext( *this, mrCustomShapeProperties,
1108 mrPath2D.parameter[ mrPath2D.parameter.size() - 2 ],
1109 mrPath2D.parameter.back() );
1111 break;
1112 case A_TOKEN( cubicBezTo ) :
1114 if ( !mrSegments.empty() && ( mrSegments.back().Command == EnhancedCustomShapeSegmentCommand::CURVETO ) )
1115 mrSegments.back().Count++;
1116 else
1118 EnhancedCustomShapeSegment aSegment;
1119 aSegment.Command = EnhancedCustomShapeSegmentCommand::CURVETO;
1120 aSegment.Count = 1;
1121 mrSegments.push_back( aSegment );
1123 EnhancedCustomShapeParameterPair aControlPt1;
1124 EnhancedCustomShapeParameterPair aControlPt2;
1125 EnhancedCustomShapeParameterPair aEndPt;
1126 mrPath2D.parameter.push_back( aControlPt1 );
1127 mrPath2D.parameter.push_back( aControlPt2 );
1128 mrPath2D.parameter.push_back( aEndPt );
1129 return new Path2DCubicBezierToContext( *this, mrCustomShapeProperties,
1130 mrPath2D.parameter[ mrPath2D.parameter.size() - 3 ],
1131 mrPath2D.parameter[ mrPath2D.parameter.size() - 2 ],
1132 mrPath2D.parameter.back() );
1134 break;
1136 return 0;
1139 // CT_Path2DList
1140 class Path2DListContext : public ContextHandler2
1142 public:
1143 Path2DListContext( ContextHandler2Helper& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< EnhancedCustomShapeSegment >& rSegments,
1144 std::vector< Path2D >& rPath2DList );
1146 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const ::oox::AttributeList& rAttribs ) SAL_OVERRIDE;
1148 protected:
1150 CustomShapeProperties& mrCustomShapeProperties;
1151 std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >& mrSegments;
1152 std::vector< Path2D >& mrPath2DList;
1155 Path2DListContext::Path2DListContext( ContextHandler2Helper& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< EnhancedCustomShapeSegment >& rSegments,
1156 std::vector< Path2D >& rPath2DList )
1157 : ContextHandler2( rParent )
1158 , mrCustomShapeProperties( rCustomShapeProperties )
1159 , mrSegments( rSegments )
1160 , mrPath2DList( rPath2DList )
1164 ContextHandlerRef Path2DListContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
1166 if ( aElementToken == A_TOKEN( path ) )
1168 Path2D aPath2D;
1169 mrPath2DList.push_back( aPath2D );
1170 return new Path2DContext( *this, rAttribs, mrCustomShapeProperties, mrSegments, mrPath2DList.back() );
1172 return 0;
1175 // CT_CustomGeometry2D
1176 CustomShapeGeometryContext::CustomShapeGeometryContext( ContextHandler2Helper& rParent, const AttributeList& /* rAttribs */, CustomShapeProperties& rCustomShapeProperties )
1177 : ContextHandler2( rParent )
1178 , mrCustomShapeProperties( rCustomShapeProperties )
1182 ContextHandlerRef CustomShapeGeometryContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
1184 switch( aElementToken )
1186 case A_TOKEN( avLst ): // CT_GeomGuideList adjust value list
1187 return new GeomGuideListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getAdjustmentGuideList() );
1188 case A_TOKEN( gdLst ): // CT_GeomGuideList guide list
1189 return new GeomGuideListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getGuideList() );
1190 case A_TOKEN( ahLst ): // CT_AdjustHandleList adjust handle list
1191 return new AdjustHandleListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getAdjustHandleList() );
1192 case A_TOKEN( cxnLst ): // CT_ConnectionSiteList connection site list
1193 return this;
1194 case A_TOKEN( rect ): // CT_GeomRectList geometry rect list
1196 GeomRect aGeomRect;
1197 aGeomRect.l = GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_l ).get(), true );
1198 aGeomRect.t = GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_t ).get(), true );
1199 aGeomRect.r = GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_r ).get(), true );
1200 aGeomRect.b = GetAdjCoordinate( mrCustomShapeProperties, rAttribs.getString( XML_b ).get(), true );
1201 mrCustomShapeProperties.getTextRect() = aGeomRect;
1203 break;
1204 case A_TOKEN( pathLst ): // CT_Path2DList 2d path list
1205 return new Path2DListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getSegments(), mrCustomShapeProperties.getPath2DList() );
1207 // from cxnLst:
1208 case A_TOKEN( cxn ): // CT_ConnectionSite
1210 ConnectionSite aConnectionSite;
1211 mrCustomShapeProperties.getConnectionSiteList().push_back( aConnectionSite );
1212 return new ConnectionSiteContext( *this, rAttribs, mrCustomShapeProperties, mrCustomShapeProperties.getConnectionSiteList().back() );
1215 return 0;
1218 // CT_PresetGeometry2D
1219 PresetShapeGeometryContext::PresetShapeGeometryContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, CustomShapeProperties& rCustomShapeProperties )
1220 : ContextHandler2( rParent )
1221 , mrCustomShapeProperties( rCustomShapeProperties )
1223 sal_Int32 nShapeType = rAttribs.getToken( XML_prst, FastToken::DONTKNOW );
1224 OSL_ENSURE( nShapeType != FastToken::DONTKNOW, "oox::drawingml::CustomShapeCustomGeometryContext::CustomShapeCustomGeometryContext(), unknown shape type" );
1225 mrCustomShapeProperties.setShapePresetType( nShapeType );
1228 ContextHandlerRef PresetShapeGeometryContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& )
1230 if ( aElementToken == A_TOKEN( avLst ) )
1231 return new GeomGuideListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getAdjustmentGuideList() );
1232 else
1233 return this;
1236 // CT_PresetTextShape
1237 PresetTextShapeContext::PresetTextShapeContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, CustomShapeProperties& rCustomShapeProperties )
1238 : ContextHandler2( rParent )
1239 , mrCustomShapeProperties( rCustomShapeProperties )
1241 sal_Int32 nShapeType = rAttribs.getToken( XML_prst, FastToken::DONTKNOW );
1242 OSL_ENSURE( nShapeType != FastToken::DONTKNOW, "oox::drawingml::CustomShapeCustomGeometryContext::CustomShapeCustomGeometryContext(), unknown shape type" );
1243 mrCustomShapeProperties.setShapePresetType( nShapeType );
1246 ContextHandlerRef PresetTextShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& )
1248 if ( aElementToken == A_TOKEN( avLst ) )
1249 return new GeomGuideListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getAdjustmentGuideList() );
1250 else
1251 return this;
1256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */