bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / draw / ximpcustomshape.cxx
blobe7516973d8f2a09a47f77f66be0f2aa4fd418475
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 "ximpcustomshape.hxx"
21 #include "ximpshap.hxx"
22 #include <rtl/math.hxx>
23 #include <rtl/ustrbuf.hxx>
24 #include <rtl/ustring.hxx>
25 #include <com/sun/star/uno/Reference.h>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/xml/sax/XAttributeList.hpp>
28 #include <com/sun/star/container/XIndexContainer.hpp>
29 #include <xmloff/xmltoken.hxx>
30 #include "EnhancedCustomShapeToken.hxx"
31 #include <xmloff/xmlimp.hxx>
32 #include <xmloff/xmltkmap.hxx>
33 #include <xmloff/xmlnmspe.hxx>
34 #include <xmloff/nmspmap.hxx>
35 #include <xmloff/xmluconv.hxx>
36 #include "xexptran.hxx"
37 #include <xmloff/xmlerror.hxx>
38 #include <com/sun/star/drawing/Direction3D.hpp>
39 #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
40 #include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>
41 #include <com/sun/star/drawing/EnhancedCustomShapeTextFrame.hpp>
42 #include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp>
43 #include <com/sun/star/drawing/EnhancedCustomShapeSegment.hpp>
44 #include <com/sun/star/drawing/EnhancedCustomShapeSegmentCommand.hpp>
45 #include <com/sun/star/drawing/EnhancedCustomShapeTextPathMode.hpp>
46 #include <com/sun/star/drawing/ProjectionMode.hpp>
47 #include <sax/tools/converter.hxx>
48 #include <unordered_map>
50 using namespace ::com::sun::star;
51 using namespace ::xmloff::token;
52 using namespace ::xmloff::EnhancedCustomShapeToken;
54 TYPEINIT1( XMLEnhancedCustomShapeContext, SvXMLImportContext );
56 XMLEnhancedCustomShapeContext::XMLEnhancedCustomShapeContext( SvXMLImport& rImport,
57 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape,
58 sal_uInt16 nPrefix, const OUString& rLocalName,
59 std::vector< com::sun::star::beans::PropertyValue >& rCustomShapeGeometry ) :
60 SvXMLImportContext( rImport, nPrefix, rLocalName ),
61 mrUnitConverter( rImport.GetMM100UnitConverter() ),
62 mrxShape( rxShape ),
63 mrCustomShapeGeometry( rCustomShapeGeometry )
67 const SvXMLEnumMapEntry aXML_GluePointEnumMap[] =
69 { XML_NONE, 0 },
70 { XML_SEGMENTS, 1 },
71 { XML_NONE, 2 },
72 { XML_RECTANGLE, 3 },
73 { XML_TOKEN_INVALID, 0 }
75 void GetBool( std::vector< com::sun::star::beans::PropertyValue >& rDest,
76 const OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
78 bool bAttrBool;
79 if (::sax::Converter::convertBool( bAttrBool, rValue ))
81 beans::PropertyValue aProp;
82 aProp.Name = EASGet( eDestProp );
83 aProp.Value <<= bAttrBool;
84 rDest.push_back( aProp );
88 void GetInt32( std::vector< com::sun::star::beans::PropertyValue >& rDest,
89 const OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
91 sal_Int32 nAttrNumber;
92 if (::sax::Converter::convertNumber( nAttrNumber, rValue ))
94 beans::PropertyValue aProp;
95 aProp.Name = EASGet( eDestProp );
96 aProp.Value <<= nAttrNumber;
97 rDest.push_back( aProp );
101 void GetDouble( std::vector< com::sun::star::beans::PropertyValue >& rDest,
102 const OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
104 double fAttrDouble;
105 if (::sax::Converter::convertDouble( fAttrDouble, rValue ))
107 beans::PropertyValue aProp;
108 aProp.Name = EASGet( eDestProp );
109 aProp.Value <<= fAttrDouble;
110 rDest.push_back( aProp );
114 void GetString( std::vector< com::sun::star::beans::PropertyValue >& rDest,
115 const OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
117 beans::PropertyValue aProp;
118 aProp.Name = EASGet( eDestProp );
119 aProp.Value <<= rValue;
120 rDest.push_back( aProp );
123 void GetEnum( std::vector< com::sun::star::beans::PropertyValue >& rDest,
124 const OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp,
125 const SvXMLEnumMapEntry& rMap )
127 sal_uInt16 eKind;
128 if( SvXMLUnitConverter::convertEnum( eKind, rValue, &rMap ) )
130 sal_Int16 nEnum = (sal_Int16)eKind;
131 beans::PropertyValue aProp;
132 aProp.Name = EASGet( eDestProp );
133 aProp.Value <<= nEnum;
134 rDest.push_back( aProp );
138 void GetDoublePercentage( std::vector< com::sun::star::beans::PropertyValue >& rDest,
139 const OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
141 sal_Int16 const eSrcUnit = ::sax::Converter::GetUnitFromString(
142 rValue, util::MeasureUnit::MM_100TH);
143 if (util::MeasureUnit::PERCENT == eSrcUnit)
145 rtl_math_ConversionStatus eStatus;
146 double fAttrDouble = ::rtl::math::stringToDouble( rValue,
147 '.', ',', &eStatus, NULL );
148 if ( eStatus == rtl_math_ConversionStatus_Ok )
150 beans::PropertyValue aProp;
151 aProp.Name = EASGet( eDestProp );
152 aProp.Value <<= fAttrDouble;
153 rDest.push_back( aProp );
158 void GetB3DVector( std::vector< com::sun::star::beans::PropertyValue >& rDest,
159 const OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
161 ::basegfx::B3DVector aB3DVector;
162 if ( SvXMLUnitConverter::convertB3DVector( aB3DVector, rValue ) )
164 drawing::Direction3D aDirection3D( aB3DVector.getX(), aB3DVector.getY(), aB3DVector.getZ() );
165 beans::PropertyValue aProp;
166 aProp.Name = EASGet( eDestProp );
167 aProp.Value <<= aDirection3D;
168 rDest.push_back( aProp );
172 bool GetEquationName( const OUString& rEquation, const sal_Int32 nStart, OUString& rEquationName )
174 sal_Int32 nIndex = nStart;
175 while( nIndex < rEquation.getLength() )
177 sal_Unicode nChar = rEquation[ nIndex ];
178 if (
179 ( ( nChar >= 'a' ) && ( nChar <= 'z' ) )
180 || ( ( nChar >= 'A' ) && ( nChar <= 'Z' ) )
181 || ( ( nChar >= '0' ) && ( nChar <= '9' ) )
184 nIndex++;
186 else
187 break;
189 bool bValid = ( nIndex - nStart ) != 0;
190 if ( bValid )
191 rEquationName = rEquation.copy( nStart, nIndex - nStart );
192 return bValid;
195 bool GetNextParameter( com::sun::star::drawing::EnhancedCustomShapeParameter& rParameter, sal_Int32& nIndex, const OUString& rParaString )
197 if ( nIndex >= rParaString.getLength() )
198 return false;
200 bool bValid = true;
201 bool bNumberRequired = true;
202 bool bMustBePositiveWholeNumbered = false;
204 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::NORMAL;
205 if ( rParaString[ nIndex ] == '$' )
207 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::ADJUSTMENT;
208 bMustBePositiveWholeNumbered = true;
209 nIndex++;
211 else if ( rParaString[ nIndex ] == '?' )
213 nIndex++;
214 bNumberRequired = false;
215 OUString aEquationName;
216 bValid = GetEquationName( rParaString, nIndex, aEquationName );
217 if ( bValid )
219 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::EQUATION;
220 rParameter.Value <<= aEquationName;
221 nIndex += aEquationName.getLength();
224 else if ( rParaString[ nIndex ] > '9' )
226 bNumberRequired = false;
227 if ( rParaString.matchIgnoreAsciiCase( "left", nIndex ) )
229 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::LEFT;
230 nIndex += 4;
232 else if ( rParaString.matchIgnoreAsciiCase( "top", nIndex ) )
234 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::TOP;
235 nIndex += 3;
237 else if ( rParaString.matchIgnoreAsciiCase( "right", nIndex ) )
239 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::RIGHT;
240 nIndex += 5;
242 else if ( rParaString.matchIgnoreAsciiCase( "bottom", nIndex ) )
244 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::BOTTOM;
245 nIndex += 6;
247 else if ( rParaString.matchIgnoreAsciiCase( "xstretch", nIndex ) )
249 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::XSTRETCH;
250 nIndex += 8;
252 else if ( rParaString.matchIgnoreAsciiCase( "ystretch", nIndex ) )
254 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::YSTRETCH;
255 nIndex += 8;
257 else if ( rParaString.matchIgnoreAsciiCase( "hasstroke", nIndex ) )
259 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::HASSTROKE;
260 nIndex += 9;
262 else if ( rParaString.matchIgnoreAsciiCase( "hasfill", nIndex ) )
264 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::HASFILL;
265 nIndex += 7;
267 else if ( rParaString.matchIgnoreAsciiCase( "width", nIndex ) )
269 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::WIDTH;
270 nIndex += 5;
272 else if ( rParaString.matchIgnoreAsciiCase( "height", nIndex ) )
274 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::HEIGHT;
275 nIndex += 6;
277 else if ( rParaString.matchIgnoreAsciiCase( "logwidth", nIndex ) )
279 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::LOGWIDTH;
280 nIndex += 8;
282 else if ( rParaString.matchIgnoreAsciiCase( "logheight", nIndex ) )
284 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::LOGHEIGHT;
285 nIndex += 9;
287 else
288 bValid = false;
290 if ( bValid )
292 if ( bNumberRequired )
294 sal_Int32 nStartIndex = nIndex;
295 sal_Int32 nEIndex = 0; // index of "E" in double
297 bool bE = false; // set if a double is including a "E" statement
298 bool bENum = false; // there is at least one number after "E"
299 bool bDot = false; // set if there is a dot included
300 bool bEnd = false; // set for each value that can not be part of a double/integer
302 while( ( nIndex < rParaString.getLength() ) && bValid )
304 switch( rParaString[ nIndex ] )
306 case '.' :
308 if ( bMustBePositiveWholeNumbered )
309 bValid = false;
310 else
312 if ( bDot )
313 bValid = false;
314 else
315 bDot = true;
318 break;
319 case '-' :
321 if ( bMustBePositiveWholeNumbered )
322 bValid = false;
323 else
325 if ( nStartIndex == nIndex )
326 bValid = true;
327 else if ( bE )
329 if ( nEIndex + 1 == nIndex )
330 bValid = true;
331 else if ( bENum )
332 bEnd = true;
333 else
334 bValid = false;
338 break;
340 case 'e' :
341 case 'E' :
343 if ( bMustBePositiveWholeNumbered )
344 bEnd = true;
345 else
347 if ( !bE )
349 bE = true;
350 nEIndex = nIndex;
352 else
353 bEnd = true;
356 break;
357 case '0' :
358 case '1' :
359 case '2' :
360 case '3' :
361 case '4' :
362 case '5' :
363 case '6' :
364 case '7' :
365 case '8' :
366 case '9' :
368 if ( bE && ! bENum )
369 bENum = true;
371 break;
372 default:
373 bEnd = true;
375 if ( !bEnd )
376 nIndex++;
377 else
378 break;
380 if ( nIndex == nStartIndex )
381 bValid = false;
382 if ( bValid )
384 OUString aNumber( rParaString.copy( nStartIndex, nIndex - nStartIndex ) );
385 if ( bE || bDot )
387 double fAttrDouble;
388 if (::sax::Converter::convertDouble(fAttrDouble, aNumber))
389 rParameter.Value <<= fAttrDouble;
390 else
391 bValid = false;
393 else
395 sal_Int32 nValue;
396 if (::sax::Converter::convertNumber(nValue, aNumber))
397 rParameter.Value <<= nValue;
398 else
399 bValid = false;
404 if ( bValid )
406 // skipping white spaces and commas (#i121507#)
407 const sal_Unicode aSpace(' ');
408 const sal_Unicode aCommata(',');
410 while(nIndex < rParaString.getLength())
412 const sal_Unicode aCandidate(rParaString[nIndex]);
414 if(aSpace == aCandidate || aCommata == aCandidate)
416 nIndex++;
418 else
420 break;
424 return bValid;
427 void GetPosition3D( std::vector< com::sun::star::beans::PropertyValue >& rDest, // e.g. draw:extrusion-viewpoint
428 const OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp,
429 SvXMLUnitConverter& rUnitConverter )
431 drawing::Position3D aPosition3D;
432 if ( rUnitConverter.convertPosition3D( aPosition3D, rValue ) )
434 beans::PropertyValue aProp;
435 aProp.Name = EASGet( eDestProp );
436 aProp.Value <<= aPosition3D;
437 rDest.push_back( aProp );
441 void GetDoubleSequence( std::vector< com::sun::star::beans::PropertyValue >& rDest, // e.g. draw:glue-point-leaving-directions
442 const OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
444 std::vector< double > vDirection;
445 sal_Int32 nIndex = 0;
448 double fAttrDouble;
449 OUString aToken( rValue.getToken( 0, ',', nIndex ) );
450 if (!::sax::Converter::convertDouble( fAttrDouble, aToken ))
451 break;
452 else
453 vDirection.push_back( fAttrDouble );
455 while ( nIndex >= 0 );
457 if ( !vDirection.empty() )
459 uno::Sequence< double > aDirectionsSeq( vDirection.size() );
460 std::vector< double >::const_iterator aIter = vDirection.begin();
461 std::vector< double >::const_iterator aEnd = vDirection.end();
462 double* pValues = aDirectionsSeq.getArray();
464 while ( aIter != aEnd )
465 *pValues++ = *aIter++;
467 beans::PropertyValue aProp;
468 aProp.Name = EASGet( eDestProp );
469 aProp.Value <<= aDirectionsSeq;
470 rDest.push_back( aProp );
474 void GetSizeSequence( std::vector< com::sun::star::beans::PropertyValue >& rDest,
475 const OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
477 std::vector< sal_Int32 > vNum;
478 sal_Int32 nIndex = 0;
481 sal_Int32 n;
482 OUString aToken( rValue.getToken( 0, ' ', nIndex ) );
483 if (!::sax::Converter::convertNumber( n, aToken ))
484 break;
485 else
486 vNum.push_back( n );
488 while ( nIndex >= 0 );
490 if ( !vNum.empty() )
492 uno::Sequence< awt::Size > aSizeSeq( vNum.size() / 2 );
493 std::vector< sal_Int32 >::const_iterator aIter = vNum.begin();
494 std::vector< sal_Int32 >::const_iterator aEnd = vNum.end();
495 awt::Size* pValues = aSizeSeq.getArray();
497 while ( aIter != aEnd ) {
498 pValues->Width = *aIter++;
499 if ( aIter != aEnd )
500 pValues->Height = *aIter++;
501 pValues ++;
504 beans::PropertyValue aProp;
505 aProp.Name = EASGet( eDestProp );
506 aProp.Value <<= aSizeSeq;
507 rDest.push_back( aProp );
511 void GetEnhancedParameter( std::vector< com::sun::star::beans::PropertyValue >& rDest, // e.g. draw:handle-position
512 const OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
514 sal_Int32 nIndex = 0;
515 com::sun::star::drawing::EnhancedCustomShapeParameter aParameter;
516 if ( GetNextParameter( aParameter, nIndex, rValue ) )
518 beans::PropertyValue aProp;
519 aProp.Name = EASGet( eDestProp );
520 aProp.Value <<= aParameter;
521 rDest.push_back( aProp );
525 void GetEnhancedParameterPair( std::vector< com::sun::star::beans::PropertyValue >& rDest, // e.g. draw:handle-position
526 const OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
528 sal_Int32 nIndex = 0;
529 com::sun::star::drawing::EnhancedCustomShapeParameterPair aParameterPair;
530 if ( GetNextParameter( aParameterPair.First, nIndex, rValue )
531 && GetNextParameter( aParameterPair.Second, nIndex, rValue ) )
533 beans::PropertyValue aProp;
534 aProp.Name = EASGet( eDestProp );
535 aProp.Value <<= aParameterPair;
536 rDest.push_back( aProp );
540 sal_Int32 GetEnhancedParameterPairSequence( std::vector< com::sun::star::beans::PropertyValue >& rDest, // e.g. draw:glue-points
541 const OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
543 std::vector< com::sun::star::drawing::EnhancedCustomShapeParameterPair > vParameter;
544 com::sun::star::drawing::EnhancedCustomShapeParameterPair aParameter;
546 sal_Int32 nIndex = 0;
547 while ( GetNextParameter( aParameter.First, nIndex, rValue )
548 && GetNextParameter( aParameter.Second, nIndex, rValue ) )
550 vParameter.push_back( aParameter );
552 if ( !vParameter.empty() )
554 uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair > aParameterSeq( vParameter.size() );
555 std::vector< com::sun::star::drawing::EnhancedCustomShapeParameterPair >::const_iterator aIter = vParameter.begin();
556 std::vector< com::sun::star::drawing::EnhancedCustomShapeParameterPair >::const_iterator aEnd = vParameter.end();
557 com::sun::star::drawing::EnhancedCustomShapeParameterPair* pValues = aParameterSeq.getArray();
559 while ( aIter != aEnd )
560 *pValues++ = *aIter++;
562 beans::PropertyValue aProp;
563 aProp.Name = EASGet( eDestProp );
564 aProp.Value <<= aParameterSeq;
565 rDest.push_back( aProp );
567 return vParameter.size();
570 void GetEnhancedRectangleSequence( std::vector< com::sun::star::beans::PropertyValue >& rDest, // e.g. draw:text-areas
571 const OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
573 std::vector< com::sun::star::drawing::EnhancedCustomShapeTextFrame > vTextFrame;
574 com::sun::star::drawing::EnhancedCustomShapeTextFrame aParameter;
576 sal_Int32 nIndex = 0;
578 while ( GetNextParameter( aParameter.TopLeft.First, nIndex, rValue )
579 && GetNextParameter( aParameter.TopLeft.Second, nIndex, rValue )
580 && GetNextParameter( aParameter.BottomRight.First, nIndex, rValue )
581 && GetNextParameter( aParameter.BottomRight.Second, nIndex, rValue ) )
583 vTextFrame.push_back( aParameter );
585 if ( !vTextFrame.empty() )
587 uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeTextFrame > aTextFrameSeq( vTextFrame.size() );
588 std::vector< com::sun::star::drawing::EnhancedCustomShapeTextFrame >::const_iterator aIter = vTextFrame.begin();
589 std::vector< com::sun::star::drawing::EnhancedCustomShapeTextFrame >::const_iterator aEnd = vTextFrame.end();
590 com::sun::star::drawing::EnhancedCustomShapeTextFrame* pValues = aTextFrameSeq.getArray();
592 while ( aIter != aEnd )
593 *pValues++ = *aIter++;
595 beans::PropertyValue aProp;
596 aProp.Name = EASGet( eDestProp );
597 aProp.Value <<= aTextFrameSeq;
598 rDest.push_back( aProp );
602 void GetEnhancedPath( std::vector< com::sun::star::beans::PropertyValue >& rDest, // e.g. draw:enhanced-path
603 const OUString& rValue )
605 std::vector< com::sun::star::drawing::EnhancedCustomShapeParameterPair > vCoordinates;
606 std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment > vSegments;
608 sal_Int32 nIndex = 0;
609 sal_Int32 nParameterCount = 0;
611 sal_Int32 nParametersNeeded = 1;
612 sal_Int16 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::MOVETO;
614 bool bValid = true;
616 while( bValid && ( nIndex < rValue.getLength() ) )
618 switch( rValue[ nIndex ] )
620 case 'M' :
622 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::MOVETO;
623 nParametersNeeded = 1;
624 nIndex++;
626 break;
627 case 'L' :
629 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::LINETO;
630 nParametersNeeded = 1;
631 nIndex++;
633 break;
634 case 'C' :
636 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::CURVETO;
637 nParametersNeeded = 3;
638 nIndex++;
640 break;
641 case 'Z' :
643 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::CLOSESUBPATH;
644 nParametersNeeded = 0;
645 nIndex++;
647 break;
648 case 'N' :
650 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ENDSUBPATH;
651 nParametersNeeded = 0;
652 nIndex++;
654 break;
655 case 'F' :
657 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::NOFILL;
658 nParametersNeeded = 0;
659 nIndex++;
661 break;
662 case 'S' :
664 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::NOSTROKE;
665 nParametersNeeded = 0;
666 nIndex++;
668 break;
669 case 'T' :
671 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ANGLEELLIPSETO;
672 nParametersNeeded = 3;
673 nIndex++;
675 break;
676 case 'U' :
678 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ANGLEELLIPSE;
679 nParametersNeeded = 3;
680 nIndex++;
682 break;
683 case 'A' :
685 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ARCTO;
686 nParametersNeeded = 4;
687 nIndex++;
689 break;
690 case 'B' :
692 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ARC;
693 nParametersNeeded = 4;
694 nIndex++;
696 break;
697 case 'G' :
699 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ARCANGLETO;
700 nParametersNeeded = 2;
701 nIndex++;
703 break;
704 case 'H' :
706 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::DARKEN;
707 nParametersNeeded = 0;
708 nIndex++;
710 break;
711 case 'I' :
713 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::DARKENLESS;
714 nParametersNeeded = 0;
715 nIndex++;
717 break;
718 case 'J' :
720 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::LIGHTEN;
721 nParametersNeeded = 0;
722 nIndex++;
724 break;
725 case 'K' :
727 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::LIGHTENLESS;
728 nParametersNeeded = 0;
729 nIndex++;
731 break;
732 case 'W' :
734 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::CLOCKWISEARCTO;
735 nParametersNeeded = 4;
736 nIndex++;
738 break;
739 case 'V' :
741 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::CLOCKWISEARC;
742 nParametersNeeded = 4;
743 nIndex++;
745 break;
746 case 'X' :
748 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTX;
749 nParametersNeeded = 1;
750 nIndex++;
752 break;
753 case 'Y' :
755 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTY;
756 nParametersNeeded = 1;
757 nIndex++;
759 break;
760 case 'Q' :
762 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::QUADRATICCURVETO;
763 nParametersNeeded = 2;
764 nIndex++;
766 break;
767 case ' ' :
769 nIndex++;
771 break;
773 case '$' :
774 case '?' :
775 case '0' :
776 case '1' :
777 case '2' :
778 case '3' :
779 case '4' :
780 case '5' :
781 case '6' :
782 case '7' :
783 case '8' :
784 case '9' :
785 case '.' :
786 case '-' :
788 com::sun::star::drawing::EnhancedCustomShapeParameterPair aPair;
789 if ( GetNextParameter( aPair.First, nIndex, rValue ) &&
790 GetNextParameter( aPair.Second, nIndex, rValue ) )
792 vCoordinates.push_back( aPair );
793 nParameterCount++;
795 else
796 bValid = false;
798 break;
799 default:
800 nIndex++;
801 break;
803 if ( !nParameterCount && !nParametersNeeded )
805 com::sun::star::drawing::EnhancedCustomShapeSegment aSegment;
806 aSegment.Command = nLatestSegmentCommand;
807 aSegment.Count = 0;
808 vSegments.push_back( aSegment );
809 nParametersNeeded = 0x7fffffff;
811 else if ( nParameterCount >= nParametersNeeded )
813 // check if the last command is identical,
814 // if so, we just need to increment the count
815 if ( !vSegments.empty() && ( vSegments[ vSegments.size() - 1 ].Command == nLatestSegmentCommand ) )
816 vSegments[ vSegments.size() -1 ].Count++;
817 else
819 com::sun::star::drawing::EnhancedCustomShapeSegment aSegment;
820 aSegment.Command = nLatestSegmentCommand;
821 aSegment.Count = 1;
822 vSegments.push_back( aSegment );
824 nParameterCount = 0;
827 // adding the Coordinates property
828 uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair > seqCoordinates( vCoordinates.size() );
829 std::vector< com::sun::star::drawing::EnhancedCustomShapeParameterPair >::const_iterator aCoordinatesIter = vCoordinates.begin();
830 std::vector< com::sun::star::drawing::EnhancedCustomShapeParameterPair >::const_iterator aCoordinatesEnd = vCoordinates.end();
831 com::sun::star::drawing::EnhancedCustomShapeParameterPair* pCoordinateValues = seqCoordinates.getArray();
833 while ( aCoordinatesIter != aCoordinatesEnd )
834 *pCoordinateValues++ = *aCoordinatesIter++;
836 beans::PropertyValue aProp;
837 aProp.Name = EASGet( EAS_Coordinates );
838 aProp.Value <<= seqCoordinates;
839 rDest.push_back( aProp );
842 // adding the Segments property
843 uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeSegment > seqSegments( vSegments.size() );
844 std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >::const_iterator aSegmentsIter = vSegments.begin();
845 std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >::const_iterator aSegmentsEnd = vSegments.end();
846 com::sun::star::drawing::EnhancedCustomShapeSegment* pSegmentValues = seqSegments.getArray();
848 while ( aSegmentsIter != aSegmentsEnd )
849 *pSegmentValues++ = *aSegmentsIter++;
851 aProp.Name = EASGet( EAS_Segments );
852 aProp.Value <<= seqSegments;
853 rDest.push_back( aProp );
856 void GetAdjustmentValues( std::vector< com::sun::star::beans::PropertyValue >& rDest, // draw:adjustments
857 const OUString& rValue )
859 std::vector< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue > vAdjustmentValue;
860 com::sun::star::drawing::EnhancedCustomShapeParameter aParameter;
861 sal_Int32 nIndex = 0;
862 while ( GetNextParameter( aParameter, nIndex, rValue ) )
864 com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue aAdj;
865 if ( aParameter.Type == com::sun::star::drawing::EnhancedCustomShapeParameterType::NORMAL )
867 aAdj.Value <<= aParameter.Value;
868 aAdj.State = beans::PropertyState_DIRECT_VALUE;
870 else
871 aAdj.State = beans::PropertyState_DEFAULT_VALUE; // this should not be, but better than setting nothing
873 vAdjustmentValue.push_back( aAdj );
876 sal_Int32 nAdjustmentValues = vAdjustmentValue.size();
877 if ( nAdjustmentValues )
879 uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue > aAdjustmentValues( nAdjustmentValues );
880 std::vector< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue >::const_iterator aIter = vAdjustmentValue.begin();
881 std::vector< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue >::const_iterator aEnd = vAdjustmentValue.end();
882 com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue* pValues = aAdjustmentValues.getArray();
884 while ( aIter != aEnd )
885 *pValues++ = *aIter++;
887 beans::PropertyValue aProp;
888 aProp.Name = EASGet( EAS_AdjustmentValues );
889 aProp.Value <<= aAdjustmentValues;
890 rDest.push_back( aProp );
894 void XMLEnhancedCustomShapeContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
896 sal_Int16 nLength = xAttrList->getLength();
897 if ( nLength )
899 sal_Int32 nAttrNumber;
900 for( sal_Int16 nAttr = 0; nAttr < nLength; nAttr++ )
902 OUString aLocalName;
903 const OUString& rValue = xAttrList->getValueByIndex( nAttr );
904 /* sven fixme, this must be checked! sal_uInt16 nPrefix = */ GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( nAttr ), &aLocalName );
906 switch( EASGet( aLocalName ) )
908 case EAS_type :
909 GetString( mrCustomShapeGeometry, rValue, EAS_Type );
910 break;
911 case EAS_mirror_horizontal :
912 GetBool( mrCustomShapeGeometry, rValue, EAS_MirroredX );
913 break;
914 case EAS_mirror_vertical :
915 GetBool( mrCustomShapeGeometry, rValue, EAS_MirroredY );
916 break;
917 case EAS_viewBox :
919 SdXMLImExViewBox aViewBox( rValue, GetImport().GetMM100UnitConverter() );
920 awt::Rectangle aRect( aViewBox.GetX(), aViewBox.GetY(), aViewBox.GetWidth(), aViewBox.GetHeight() );
921 beans::PropertyValue aProp;
922 aProp.Name = EASGet( EAS_ViewBox );
923 aProp.Value <<= aRect;
924 mrCustomShapeGeometry.push_back( aProp );
926 break;
927 case EAS_sub_view_size:
928 GetSizeSequence( maPath, rValue, EAS_SubViewSize );
929 break;
930 case EAS_text_rotate_angle :
931 GetDouble( mrCustomShapeGeometry, rValue, EAS_TextRotateAngle );
932 break;
933 case EAS_extrusion_allowed :
934 GetBool( maPath, rValue, EAS_ExtrusionAllowed );
935 break;
936 case EAS_text_path_allowed :
937 GetBool( maPath, rValue, EAS_TextPathAllowed );
938 break;
939 case EAS_concentric_gradient_fill_allowed :
940 GetBool( maPath, rValue, EAS_ConcentricGradientFillAllowed );
941 break;
942 case EAS_extrusion :
943 GetBool( maExtrusion, rValue, EAS_Extrusion );
944 break;
945 case EAS_extrusion_brightness :
946 GetDoublePercentage( maExtrusion, rValue, EAS_Brightness );
947 break;
948 case EAS_extrusion_depth :
950 sal_Int32 nIndex = 0;
951 com::sun::star::drawing::EnhancedCustomShapeParameterPair aParameterPair;
952 com::sun::star::drawing::EnhancedCustomShapeParameter& rDepth = aParameterPair.First;
953 com::sun::star::drawing::EnhancedCustomShapeParameter& rFraction = aParameterPair.Second;
954 if ( GetNextParameter( rDepth, nIndex, rValue ) )
956 // try to catch the unit for the depth
957 sal_Int16 const eSrcUnit(
958 ::sax::Converter::GetUnitFromString(
959 rValue, util::MeasureUnit::MM_100TH));
961 OUStringBuffer aUnitStr;
962 double fFactor = ::sax::Converter::GetConversionFactor(
963 aUnitStr, util::MeasureUnit::MM_100TH, eSrcUnit);
964 if ( ( fFactor != 1.0 ) && ( fFactor != 0.0 ) )
966 double fDepth(0.0);
967 if ( rDepth.Value >>= fDepth )
969 fDepth /= fFactor;
970 rDepth.Value <<= fDepth;
973 if ( rValue.matchIgnoreAsciiCase( aUnitStr.toString(), nIndex ) )
974 nIndex += aUnitStr.getLength();
976 // skipping white spaces
977 while( ( nIndex < rValue.getLength() ) && rValue[ nIndex ] == ' ' )
978 nIndex++;
980 if ( GetNextParameter( rFraction, nIndex, rValue ) )
982 beans::PropertyValue aProp;
983 aProp.Name = EASGet( EAS_Depth );
984 aProp.Value <<= aParameterPair;
985 maExtrusion.push_back( aProp );
989 break;
990 case EAS_extrusion_diffusion :
991 GetDoublePercentage( maExtrusion, rValue, EAS_Diffusion );
992 break;
993 case EAS_extrusion_number_of_line_segments :
994 GetInt32( maExtrusion, rValue, EAS_NumberOfLineSegments );
995 break;
996 case EAS_extrusion_light_face :
997 GetBool( maExtrusion, rValue, EAS_LightFace );
998 break;
999 case EAS_extrusion_first_light_harsh :
1000 GetBool( maExtrusion, rValue, EAS_FirstLightHarsh );
1001 break;
1002 case EAS_extrusion_second_light_harsh :
1003 GetBool( maExtrusion, rValue, EAS_SecondLightHarsh );
1004 break;
1005 case EAS_extrusion_first_light_level :
1006 GetDoublePercentage( maExtrusion, rValue, EAS_FirstLightLevel );
1007 break;
1008 case EAS_extrusion_second_light_level :
1009 GetDoublePercentage( maExtrusion, rValue, EAS_SecondLightLevel );
1010 break;
1011 case EAS_extrusion_first_light_direction :
1012 GetB3DVector( maExtrusion, rValue, EAS_FirstLightDirection );
1013 break;
1014 case EAS_extrusion_second_light_direction :
1015 GetB3DVector( maExtrusion, rValue, EAS_SecondLightDirection );
1016 break;
1017 case EAS_extrusion_metal :
1018 GetBool( maExtrusion, rValue, EAS_Metal );
1019 break;
1020 case EAS_shade_mode :
1022 drawing::ShadeMode eShadeMode( drawing::ShadeMode_FLAT );
1023 if( IsXMLToken( rValue, XML_PHONG ) )
1024 eShadeMode = drawing::ShadeMode_PHONG;
1025 else if ( IsXMLToken( rValue, XML_GOURAUD ) )
1026 eShadeMode = drawing::ShadeMode_SMOOTH;
1027 else if ( IsXMLToken( rValue, XML_DRAFT ) )
1028 eShadeMode = drawing::ShadeMode_DRAFT;
1030 beans::PropertyValue aProp;
1031 aProp.Name = EASGet( EAS_ShadeMode );
1032 aProp.Value <<= eShadeMode;
1033 maExtrusion.push_back( aProp );
1035 break;
1036 case EAS_extrusion_rotation_angle :
1037 GetEnhancedParameterPair( maExtrusion, rValue, EAS_RotateAngle );
1038 break;
1039 case EAS_extrusion_rotation_center :
1040 GetB3DVector( maExtrusion, rValue, EAS_RotationCenter );
1041 break;
1042 case EAS_extrusion_shininess :
1043 GetDoublePercentage( maExtrusion, rValue, EAS_Shininess );
1044 break;
1045 case EAS_extrusion_skew :
1046 GetEnhancedParameterPair( maExtrusion, rValue, EAS_Skew );
1047 break;
1048 case EAS_extrusion_specularity :
1049 GetDoublePercentage( maExtrusion, rValue, EAS_Specularity );
1050 break;
1051 case EAS_projection :
1053 drawing::ProjectionMode eProjectionMode( drawing::ProjectionMode_PERSPECTIVE );
1054 if( IsXMLToken( rValue, XML_PARALLEL ) )
1055 eProjectionMode = drawing::ProjectionMode_PARALLEL;
1057 beans::PropertyValue aProp;
1058 aProp.Name = EASGet( EAS_ProjectionMode );
1059 aProp.Value <<= eProjectionMode;
1060 maExtrusion.push_back( aProp );
1062 break;
1063 case EAS_extrusion_viewpoint :
1064 GetPosition3D( maExtrusion, rValue, EAS_ViewPoint, mrUnitConverter );
1065 break;
1066 case EAS_extrusion_origin :
1067 GetEnhancedParameterPair( maExtrusion, rValue, EAS_Origin );
1068 break;
1069 case EAS_extrusion_color :
1070 GetBool( maExtrusion, rValue, EAS_Color );
1071 break;
1072 case EAS_enhanced_path :
1073 GetEnhancedPath( maPath, rValue );
1074 break;
1075 case EAS_path_stretchpoint_x :
1077 if (::sax::Converter::convertNumber(nAttrNumber, rValue))
1079 beans::PropertyValue aProp;
1080 aProp.Name = EASGet( EAS_StretchX );
1081 aProp.Value <<= nAttrNumber;
1082 maPath.push_back( aProp );
1085 break;
1086 case EAS_path_stretchpoint_y :
1088 if (::sax::Converter::convertNumber(nAttrNumber, rValue))
1090 beans::PropertyValue aProp;
1091 aProp.Name = EASGet( EAS_StretchY );
1092 aProp.Value <<= nAttrNumber;
1093 maPath.push_back( aProp );
1096 break;
1097 case EAS_text_areas :
1098 GetEnhancedRectangleSequence( maPath, rValue, EAS_TextFrames );
1099 break;
1100 case EAS_glue_points :
1102 sal_Int32 i, nPairs = GetEnhancedParameterPairSequence( maPath, rValue, EAS_GluePoints );
1103 GetImport().GetShapeImport()->moveGluePointMapping( mrxShape, nPairs );
1104 for ( i = 0; i < nPairs; i++ )
1105 GetImport().GetShapeImport()->addGluePointMapping( mrxShape, i + 4, i + 4 );
1107 break;
1108 case EAS_glue_point_type :
1109 GetEnum( maPath, rValue, EAS_GluePointType, *aXML_GluePointEnumMap );
1110 break;
1111 case EAS_glue_point_leaving_directions :
1112 GetDoubleSequence( maPath, rValue, EAS_GluePointLeavingDirections );
1113 break;
1114 case EAS_text_path :
1115 GetBool( maTextPath, rValue, EAS_TextPath );
1116 break;
1117 case EAS_text_path_mode :
1119 com::sun::star::drawing::EnhancedCustomShapeTextPathMode eTextPathMode( com::sun::star::drawing::EnhancedCustomShapeTextPathMode_NORMAL );
1120 if( IsXMLToken( rValue, XML_PATH ) )
1121 eTextPathMode = com::sun::star::drawing::EnhancedCustomShapeTextPathMode_PATH;
1122 else if ( IsXMLToken( rValue, XML_SHAPE ) )
1123 eTextPathMode = com::sun::star::drawing::EnhancedCustomShapeTextPathMode_SHAPE;
1125 beans::PropertyValue aProp;
1126 aProp.Name = EASGet( EAS_TextPathMode );
1127 aProp.Value <<= eTextPathMode;
1128 maTextPath.push_back( aProp );
1130 break;
1131 case EAS_text_path_scale :
1133 bool bScaleX = IsXMLToken( rValue, XML_SHAPE );
1134 beans::PropertyValue aProp;
1135 aProp.Name = EASGet( EAS_ScaleX );
1136 aProp.Value <<= bScaleX;
1137 maTextPath.push_back( aProp );
1139 break;
1140 case EAS_text_path_same_letter_heights :
1141 GetBool( maTextPath, rValue, EAS_SameLetterHeights );
1142 break;
1143 case EAS_modifiers :
1144 GetAdjustmentValues( mrCustomShapeGeometry, rValue );
1145 break;
1146 default:
1147 break;
1153 void SdXMLCustomShapePropertyMerge( std::vector< com::sun::star::beans::PropertyValue >& rPropVec,
1154 const std::vector< beans::PropertyValues >& rElement,
1155 const OUString& rElementName )
1157 if ( !rElement.empty() )
1159 uno::Sequence< beans::PropertyValues > aPropSeq( rElement.size() );
1160 std::vector< beans::PropertyValues >::const_iterator aIter = rElement.begin();
1161 std::vector< beans::PropertyValues >::const_iterator aEnd = rElement.end();
1162 beans::PropertyValues* pValues = aPropSeq.getArray();
1164 while ( aIter != aEnd )
1165 *pValues++ = *aIter++;
1167 beans::PropertyValue aProp;
1168 aProp.Name = rElementName;
1169 aProp.Value <<= aPropSeq;
1170 rPropVec.push_back( aProp );
1174 void SdXMLCustomShapePropertyMerge( std::vector< com::sun::star::beans::PropertyValue >& rPropVec,
1175 const std::vector< OUString >& rElement,
1176 const OUString& rElementName )
1178 if ( !rElement.empty() )
1180 uno::Sequence< OUString > aPropSeq( rElement.size() );
1181 std::vector< OUString >::const_iterator aIter = rElement.begin();
1182 std::vector< OUString >::const_iterator aEnd = rElement.end();
1183 OUString* pValues = aPropSeq.getArray();
1185 while ( aIter != aEnd )
1186 *pValues++ = *aIter++;
1188 beans::PropertyValue aProp;
1189 aProp.Name = rElementName;
1190 aProp.Value <<= aPropSeq;
1191 rPropVec.push_back( aProp );
1195 void SdXMLCustomShapePropertyMerge( std::vector< com::sun::star::beans::PropertyValue >& rPropVec,
1196 const std::vector< com::sun::star::beans::PropertyValue >& rElement,
1197 const OUString& rElementName )
1199 if ( !rElement.empty() )
1201 uno::Sequence< beans::PropertyValue > aPropSeq( rElement.size() );
1202 std::vector< beans::PropertyValue >::const_iterator aIter = rElement.begin();
1203 std::vector< beans::PropertyValue >::const_iterator aEnd = rElement.end();
1204 beans::PropertyValue* pValues = aPropSeq.getArray();
1206 while ( aIter != aEnd )
1207 *pValues++ = *aIter++;
1209 beans::PropertyValue aProp;
1210 aProp.Name = rElementName;
1211 aProp.Value <<= aPropSeq;
1212 rPropVec.push_back( aProp );
1216 typedef std::unordered_map< OUString, sal_Int32, OUStringHash > EquationHashMap;
1218 /* if rPara.Type is from type EnhancedCustomShapeParameterType::EQUATION, the name of the equation
1219 will be converted from OUString to index */
1220 void CheckAndResolveEquationParameter( com::sun::star::drawing::EnhancedCustomShapeParameter& rPara, EquationHashMap* pH )
1222 if ( rPara.Type == com::sun::star::drawing::EnhancedCustomShapeParameterType::EQUATION )
1224 OUString aEquationName;
1225 if ( rPara.Value >>= aEquationName )
1227 sal_Int32 nIndex = 0;
1228 EquationHashMap::iterator aHashIter( pH->find( aEquationName ) );
1229 if ( aHashIter != pH->end() )
1230 nIndex = (*aHashIter).second;
1231 rPara.Value <<= nIndex;
1236 void XMLEnhancedCustomShapeContext::EndElement()
1238 // resolve properties that are indexing a Equation
1239 if ( !maEquations.empty() )
1241 // creating hash map containing the name and index of each equation
1242 EquationHashMap* pH = new EquationHashMap;
1243 std::vector< OUString >::iterator aEquationNameIter = maEquationNames.begin();
1244 std::vector< OUString >::iterator aEquationNameEnd = maEquationNames.end();
1245 while( aEquationNameIter != aEquationNameEnd )
1247 (*pH)[ *aEquationNameIter ] = (sal_Int32)( aEquationNameIter - maEquationNames.begin() );
1248 ++aEquationNameIter;
1251 // resolve equation
1252 std::vector< OUString >::iterator aEquationIter = maEquations.begin();
1253 std::vector< OUString >::iterator aEquationEnd = maEquations.end();
1254 while( aEquationIter != aEquationEnd )
1256 sal_Int32 nIndexOf = 0;
1259 nIndexOf = aEquationIter->indexOf( '?', nIndexOf );
1260 if ( nIndexOf != -1 )
1262 OUString aEquationName;
1263 if ( GetEquationName( *aEquationIter, nIndexOf + 1, aEquationName ) )
1265 // copying first characters inclusive '?'
1266 OUString aNew( aEquationIter->copy( 0, nIndexOf + 1 ) );
1267 sal_Int32 nIndex = 0;
1268 EquationHashMap::iterator aHashIter( pH->find( aEquationName ) );
1269 if ( aHashIter != pH->end() )
1270 nIndex = (*aHashIter).second;
1271 aNew += OUString::number( nIndex );
1272 aNew += aEquationIter->copy( nIndexOf + aEquationName.getLength() + 1 );
1273 *aEquationIter = aNew;
1275 nIndexOf++;
1278 while( nIndexOf != -1 );
1279 ++aEquationIter;
1282 // Path
1283 sal_Int32 i;
1284 std::vector< beans::PropertyValue >::iterator aPathIter = maPath.begin();
1285 std::vector< beans::PropertyValue >::iterator aPathEnd = maPath.end();
1286 while ( aPathIter != aPathEnd )
1288 switch( EASGet( aPathIter->Name ) )
1290 case EAS_Coordinates :
1291 case EAS_GluePoints :
1293 uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair > const & rSeq =
1294 *static_cast<uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair > const *>(
1295 aPathIter->Value.getValue());
1296 for ( i = 0; i < rSeq.getLength(); i++ )
1298 CheckAndResolveEquationParameter( const_cast<css::drawing::EnhancedCustomShapeParameter &>(rSeq[ i ].First), pH );
1299 CheckAndResolveEquationParameter( const_cast<css::drawing::EnhancedCustomShapeParameter &>(rSeq[ i ].Second), pH );
1302 break;
1303 case EAS_TextFrames :
1305 uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeTextFrame > const & rSeq =
1306 *static_cast<uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeTextFrame > const *>(
1307 aPathIter->Value.getValue());
1308 for ( i = 0; i < rSeq.getLength(); i++ )
1310 CheckAndResolveEquationParameter( const_cast<css::drawing::EnhancedCustomShapeParameter &>(rSeq[ i ].TopLeft.First), pH );
1311 CheckAndResolveEquationParameter( const_cast<css::drawing::EnhancedCustomShapeParameter &>(rSeq[ i ].TopLeft.Second), pH );
1312 CheckAndResolveEquationParameter( const_cast<css::drawing::EnhancedCustomShapeParameter &>(rSeq[ i ].BottomRight.First), pH );
1313 CheckAndResolveEquationParameter( const_cast<css::drawing::EnhancedCustomShapeParameter &>(rSeq[ i ].BottomRight.Second), pH );
1316 break;
1317 default:
1318 break;
1320 ++aPathIter;
1322 std::vector< beans::PropertyValues >::iterator aHandleIter = maHandles.begin();
1323 std::vector< beans::PropertyValues >::iterator aHandleEnd = maHandles.end();
1324 while ( aHandleIter != aHandleEnd )
1326 beans::PropertyValue* pValues = aHandleIter->getArray();
1327 for ( i = 0; i < aHandleIter->getLength(); i++ )
1329 switch( EASGet( pValues->Name ) )
1331 case EAS_RangeYMinimum :
1332 case EAS_RangeYMaximum :
1333 case EAS_RangeXMinimum :
1334 case EAS_RangeXMaximum :
1335 case EAS_RadiusRangeMinimum :
1336 case EAS_RadiusRangeMaximum :
1338 CheckAndResolveEquationParameter( *const_cast<css::drawing::EnhancedCustomShapeParameter *>(static_cast<com::sun::star::drawing::EnhancedCustomShapeParameter const *>(
1339 pValues->Value.getValue())), pH );
1341 break;
1343 case EAS_Position :
1344 case EAS_Polar :
1346 CheckAndResolveEquationParameter( const_cast<css::drawing::EnhancedCustomShapeParameter &>((*static_cast<com::sun::star::drawing::EnhancedCustomShapeParameterPair const *>(
1347 pValues->Value.getValue())).First), pH );
1348 CheckAndResolveEquationParameter( const_cast<css::drawing::EnhancedCustomShapeParameter &>((*static_cast<com::sun::star::drawing::EnhancedCustomShapeParameterPair const *>(
1349 pValues->Value.getValue())).Second), pH );
1351 break;
1352 default:
1353 break;
1355 pValues++;
1357 ++aHandleIter;
1359 delete pH;
1362 SdXMLCustomShapePropertyMerge( mrCustomShapeGeometry, maExtrusion, EASGet( EAS_Extrusion ) );
1363 SdXMLCustomShapePropertyMerge( mrCustomShapeGeometry, maPath, EASGet( EAS_Path ) );
1364 SdXMLCustomShapePropertyMerge( mrCustomShapeGeometry, maTextPath, EASGet( EAS_TextPath ) );
1365 SdXMLCustomShapePropertyMerge( mrCustomShapeGeometry, maEquations, EASGet( EAS_Equations ) );
1366 if ( !maHandles.empty() )
1367 SdXMLCustomShapePropertyMerge( mrCustomShapeGeometry, maHandles, EASGet( EAS_Handles ) );
1370 SvXMLImportContext* XMLEnhancedCustomShapeContext::CreateChildContext( sal_uInt16 nPrefix,const OUString& rLocalName,
1371 const uno::Reference< xml::sax::XAttributeList> & xAttrList )
1373 EnhancedCustomShapeTokenEnum aTokenEnum = EASGet( rLocalName );
1374 if ( aTokenEnum == EAS_equation )
1376 sal_Int16 nLength = xAttrList->getLength();
1377 if ( nLength )
1379 OUString aFormula;
1380 OUString aFormulaName;
1381 for( sal_Int16 nAttr = 0; nAttr < nLength; nAttr++ )
1383 OUString aLocalName;
1384 const OUString& rValue = xAttrList->getValueByIndex( nAttr );
1385 /* fixme sven, this needs to be chekced! sal_uInt16 nPrefix = */ GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( nAttr ), &aLocalName );
1387 switch( EASGet( aLocalName ) )
1389 case EAS_formula :
1390 aFormula = rValue;
1391 break;
1392 case EAS_name :
1393 aFormulaName = rValue;
1394 break;
1395 default:
1396 break;
1399 if ( !aFormulaName.isEmpty() || !aFormula.isEmpty() )
1401 maEquations.push_back( aFormula );
1402 maEquationNames.push_back( aFormulaName );
1406 else if ( aTokenEnum == EAS_handle )
1408 std::vector< com::sun::star::beans::PropertyValue > aHandle;
1409 const sal_Int16 nLength = xAttrList->getLength();
1410 for( sal_Int16 nAttr = 0; nAttr < nLength; nAttr++ )
1412 OUString aLocalName;
1413 const OUString& rValue = xAttrList->getValueByIndex( nAttr );
1414 /* fixme sven, this needs to be chekced! sal_uInt16 nPrefix = */ GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( nAttr ), &aLocalName );
1415 switch( EASGet( aLocalName ) )
1417 case EAS_handle_mirror_vertical :
1418 GetBool( aHandle, rValue, EAS_MirroredY );
1419 break;
1420 case EAS_handle_mirror_horizontal :
1421 GetBool( aHandle, rValue, EAS_MirroredX );
1422 break;
1423 case EAS_handle_switched :
1424 GetBool( aHandle, rValue, EAS_Switched );
1425 break;
1426 case EAS_handle_position :
1427 GetEnhancedParameterPair( aHandle, rValue, EAS_Position );
1428 break;
1429 case EAS_handle_range_x_minimum :
1430 GetEnhancedParameter( aHandle, rValue, EAS_RangeXMinimum );
1431 break;
1432 case EAS_handle_range_x_maximum :
1433 GetEnhancedParameter( aHandle, rValue, EAS_RangeXMaximum );
1434 break;
1435 case EAS_handle_range_y_minimum :
1436 GetEnhancedParameter( aHandle, rValue, EAS_RangeYMinimum );
1437 break;
1438 case EAS_handle_range_y_maximum :
1439 GetEnhancedParameter( aHandle, rValue, EAS_RangeYMaximum );
1440 break;
1441 case EAS_handle_polar :
1442 GetEnhancedParameterPair( aHandle, rValue, EAS_Polar );
1443 break;
1444 case EAS_handle_radius_range_minimum :
1445 GetEnhancedParameter( aHandle, rValue, EAS_RadiusRangeMinimum );
1446 break;
1447 case EAS_handle_radius_range_maximum :
1448 GetEnhancedParameter( aHandle, rValue, EAS_RadiusRangeMaximum );
1449 break;
1450 default:
1451 break;
1454 beans::PropertyValues aPropSeq( aHandle.size() );
1455 std::vector< beans::PropertyValue >::const_iterator aIter = aHandle.begin();
1456 std::vector< beans::PropertyValue >::const_iterator aEnd = aHandle.end();
1457 beans::PropertyValue* pValues = aPropSeq.getArray();
1459 while ( aIter != aEnd )
1460 *pValues++ = *aIter++;
1462 maHandles.push_back( aPropSeq );
1464 return SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
1467 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */