Bump for 3.6-28
[LibreOffice.git] / xmloff / source / draw / ximpcustomshape.cxx
blobf8966a1f275fc080d468185547fb2ced70072603
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "ximpcustomshape.hxx"
30 #include "ximpshap.hxx"
31 #include <rtl/math.hxx>
32 #include <rtl/ustrbuf.hxx>
33 #include <rtl/ustring.hxx>
34 #include <com/sun/star/uno/Reference.h>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/xml/sax/XAttributeList.hpp>
37 #include <com/sun/star/container/XIndexContainer.hpp>
38 #include <xmloff/xmltoken.hxx>
39 #include "EnhancedCustomShapeToken.hxx"
40 #include <xmloff/xmlimp.hxx>
41 #include <xmloff/xmltkmap.hxx>
42 #include "xmloff/xmlnmspe.hxx"
43 #include <xmloff/nmspmap.hxx>
44 #include <xmloff/xmluconv.hxx>
45 #include "xexptran.hxx"
46 #include "xmloff/xmlerror.hxx"
47 #include <com/sun/star/drawing/Direction3D.hpp>
48 #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
49 #include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>
50 #include <com/sun/star/drawing/EnhancedCustomShapeTextFrame.hpp>
51 #include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp>
52 #include <com/sun/star/drawing/EnhancedCustomShapeSegment.hpp>
53 #include <com/sun/star/drawing/EnhancedCustomShapeSegmentCommand.hpp>
54 #include <com/sun/star/drawing/EnhancedCustomShapeTextPathMode.hpp>
55 #include <com/sun/star/drawing/ProjectionMode.hpp>
56 #include <boost/unordered_map.hpp>
57 #include <sax/tools/converter.hxx>
59 using namespace ::com::sun::star;
60 using namespace ::xmloff::token;
61 using namespace ::xmloff::EnhancedCustomShapeToken;
63 TYPEINIT1( XMLEnhancedCustomShapeContext, SvXMLImportContext );
65 XMLEnhancedCustomShapeContext::XMLEnhancedCustomShapeContext( SvXMLImport& rImport,
66 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape,
67 sal_uInt16 nPrefix, const rtl::OUString& rLocalName,
68 std::vector< com::sun::star::beans::PropertyValue >& rCustomShapeGeometry ) :
69 SvXMLImportContext( rImport, nPrefix, rLocalName ),
70 mrUnitConverter( rImport.GetMM100UnitConverter() ),
71 mrxShape( rxShape ),
72 mrCustomShapeGeometry( rCustomShapeGeometry )
76 const SvXMLEnumMapEntry aXML_GluePointEnumMap[] =
78 { XML_NONE, 0 },
79 { XML_SEGMENTS, 1 },
80 { XML_NONE, 2 },
81 { XML_RECTANGLE, 3 },
82 { XML_TOKEN_INVALID, 0 }
84 void GetBool( std::vector< com::sun::star::beans::PropertyValue >& rDest,
85 const rtl::OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
87 bool bAttrBool;
88 if (::sax::Converter::convertBool( bAttrBool, rValue ))
90 beans::PropertyValue aProp;
91 aProp.Name = EASGet( eDestProp );
92 aProp.Value <<= bAttrBool;
93 rDest.push_back( aProp );
97 void GetInt32( std::vector< com::sun::star::beans::PropertyValue >& rDest,
98 const rtl::OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
100 sal_Int32 nAttrNumber;
101 if (::sax::Converter::convertNumber( nAttrNumber, rValue ))
103 beans::PropertyValue aProp;
104 aProp.Name = EASGet( eDestProp );
105 aProp.Value <<= nAttrNumber;
106 rDest.push_back( aProp );
110 void GetDouble( std::vector< com::sun::star::beans::PropertyValue >& rDest,
111 const rtl::OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
113 double fAttrDouble;
114 if (::sax::Converter::convertDouble( fAttrDouble, rValue ))
116 beans::PropertyValue aProp;
117 aProp.Name = EASGet( eDestProp );
118 aProp.Value <<= fAttrDouble;
119 rDest.push_back( aProp );
123 void GetDistance( std::vector< com::sun::star::beans::PropertyValue >& rDest,
124 const rtl::OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
126 double fAttrDouble;
127 sal_Int16 const eSrcUnit( ::sax::Converter::GetUnitFromString(
128 rValue, util::MeasureUnit::MM_100TH) );
129 if (::sax::Converter::convertDouble(fAttrDouble, rValue, eSrcUnit,
130 util::MeasureUnit::MM_100TH))
132 beans::PropertyValue aProp;
133 aProp.Name = EASGet( eDestProp );
134 aProp.Value <<= fAttrDouble;
135 rDest.push_back( aProp );
139 void GetString( std::vector< com::sun::star::beans::PropertyValue >& rDest,
140 const rtl::OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
142 beans::PropertyValue aProp;
143 aProp.Name = EASGet( eDestProp );
144 aProp.Value <<= rValue;
145 rDest.push_back( aProp );
148 void GetEnum( std::vector< com::sun::star::beans::PropertyValue >& rDest,
149 const rtl::OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp,
150 const SvXMLEnumMapEntry& rMap )
152 sal_uInt16 eKind;
153 if( SvXMLUnitConverter::convertEnum( eKind, rValue, &rMap ) )
155 sal_Int16 nEnum = (sal_Int16)eKind;
156 beans::PropertyValue aProp;
157 aProp.Name = EASGet( eDestProp );
158 aProp.Value <<= nEnum;
159 rDest.push_back( aProp );
163 void GetDoublePercentage( std::vector< com::sun::star::beans::PropertyValue >& rDest,
164 const rtl::OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
166 sal_Int16 const eSrcUnit = ::sax::Converter::GetUnitFromString(
167 rValue, util::MeasureUnit::MM_100TH);
168 if (util::MeasureUnit::PERCENT == eSrcUnit)
170 rtl_math_ConversionStatus eStatus;
171 double fAttrDouble = ::rtl::math::stringToDouble( rValue,
172 (sal_Unicode)('.'), (sal_Unicode)(','), &eStatus, NULL );
173 if ( eStatus == rtl_math_ConversionStatus_Ok )
175 beans::PropertyValue aProp;
176 aProp.Name = EASGet( eDestProp );
177 aProp.Value <<= fAttrDouble;
178 rDest.push_back( aProp );
183 void GetB3DVector( std::vector< com::sun::star::beans::PropertyValue >& rDest,
184 const rtl::OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
186 ::basegfx::B3DVector aB3DVector;
187 if ( SvXMLUnitConverter::convertB3DVector( aB3DVector, rValue ) )
189 drawing::Direction3D aDirection3D( aB3DVector.getX(), aB3DVector.getY(), aB3DVector.getZ() );
190 beans::PropertyValue aProp;
191 aProp.Name = EASGet( eDestProp );
192 aProp.Value <<= aDirection3D;
193 rDest.push_back( aProp );
197 sal_Bool GetEquationName( const rtl::OUString& rEquation, const sal_Int32 nStart, rtl::OUString& rEquationName )
199 sal_Int32 nIndex = nStart;
200 while( nIndex < rEquation.getLength() )
202 sal_Unicode nChar = rEquation[ nIndex ];
203 if (
204 ( ( nChar >= 'a' ) && ( nChar <= 'z' ) )
205 || ( ( nChar >= 'A' ) && ( nChar <= 'Z' ) )
206 || ( ( nChar >= '0' ) && ( nChar <= '9' ) )
209 nIndex++;
211 else
212 break;
214 sal_Bool bValid = ( nIndex - nStart ) != 0;
215 if ( bValid )
216 rEquationName = rEquation.copy( nStart, nIndex - nStart );
217 return bValid;
220 sal_Bool GetNextParameter( com::sun::star::drawing::EnhancedCustomShapeParameter& rParameter, sal_Int32& nIndex, const rtl::OUString& rParaString )
222 if ( nIndex >= rParaString.getLength() )
223 return sal_False;
225 sal_Bool bValid = sal_True;
226 sal_Bool bNumberRequired = sal_True;
227 sal_Bool bMustBePositiveWholeNumbered = sal_False;
229 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::NORMAL;
230 if ( rParaString[ nIndex ] == (sal_Unicode)'$' )
232 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::ADJUSTMENT;
233 bMustBePositiveWholeNumbered = sal_True;
234 nIndex++;
236 else if ( rParaString[ nIndex ] == (sal_Unicode)'?' )
238 nIndex++;
239 bNumberRequired = sal_False;
240 rtl::OUString aEquationName;
241 bValid = GetEquationName( rParaString, nIndex, aEquationName );
242 if ( bValid )
244 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::EQUATION;
245 rParameter.Value <<= aEquationName;
246 nIndex += aEquationName.getLength();
249 else if ( rParaString[ nIndex ] > (sal_Unicode)'9' )
251 bNumberRequired = sal_False;
252 if ( rParaString.matchIgnoreAsciiCaseAsciiL( "left", 4, nIndex ) )
254 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::LEFT;
255 nIndex += 4;
257 else if ( rParaString.matchIgnoreAsciiCaseAsciiL( "top", 3, nIndex ) )
259 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::TOP;
260 nIndex += 3;
262 else if ( rParaString.matchIgnoreAsciiCaseAsciiL( "right", 5, nIndex ) )
264 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::RIGHT;
265 nIndex += 5;
267 else if ( rParaString.matchIgnoreAsciiCaseAsciiL( "bottom", 6, nIndex ) )
269 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::BOTTOM;
270 nIndex += 6;
272 else if ( rParaString.matchIgnoreAsciiCaseAsciiL( "xstretch", 8, nIndex ) )
274 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::XSTRETCH;
275 nIndex += 8;
277 else if ( rParaString.matchIgnoreAsciiCaseAsciiL( "ystretch", 8, nIndex ) )
279 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::YSTRETCH;
280 nIndex += 8;
282 else if ( rParaString.matchIgnoreAsciiCaseAsciiL( "hasstroke", 9, nIndex ) )
284 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::HASSTROKE;
285 nIndex += 9;
287 else if ( rParaString.matchIgnoreAsciiCaseAsciiL( "hasfill", 7, nIndex ) )
289 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::HASFILL;
290 nIndex += 7;
292 else if ( rParaString.matchIgnoreAsciiCaseAsciiL( "width", 5, nIndex ) )
294 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::WIDTH;
295 nIndex += 5;
297 else if ( rParaString.matchIgnoreAsciiCaseAsciiL( "height", 6, nIndex ) )
299 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::HEIGHT;
300 nIndex += 6;
302 else if ( rParaString.matchIgnoreAsciiCaseAsciiL( "logwidth", 8, nIndex ) )
304 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::LOGWIDTH;
305 nIndex += 8;
307 else if ( rParaString.matchIgnoreAsciiCaseAsciiL( "logheight", 9, nIndex ) )
309 rParameter.Type = com::sun::star::drawing::EnhancedCustomShapeParameterType::LOGHEIGHT;
310 nIndex += 9;
312 else
313 bValid = sal_False;
315 if ( bValid )
317 if ( bNumberRequired )
319 sal_Int32 nStartIndex = nIndex;
320 sal_Int32 nEIndex = 0; // index of "E" in double
322 sal_Bool bE = sal_False; // set if a double is including a "E" statement
323 sal_Bool bENum = sal_False; // there is at least one number after "E"
324 sal_Bool bDot = sal_False; // set if there is a dot included
325 sal_Bool bEnd = sal_False; // set for each value that can not be part of a double/integer
327 while( ( nIndex < rParaString.getLength() ) && bValid )
329 switch( rParaString[ nIndex ] )
331 case '.' :
333 if ( bMustBePositiveWholeNumbered )
334 bValid = sal_False;
335 else
337 if ( bDot )
338 bValid = sal_False;
339 else
340 bDot = sal_True;
343 break;
344 case '-' :
346 if ( bMustBePositiveWholeNumbered )
347 bValid = sal_False;
348 else
350 if ( nStartIndex == nIndex )
351 bValid = sal_True;
352 else if ( bE )
354 if ( nEIndex + 1 == nIndex )
355 bValid = sal_True;
356 else if ( bENum )
357 bEnd = sal_True;
358 else
359 bValid = sal_False;
363 break;
365 case 'e' :
366 case 'E' :
368 if ( bMustBePositiveWholeNumbered )
369 bEnd = sal_True;
370 else
372 if ( !bE )
374 bE = sal_True;
375 nEIndex = nIndex;
377 else
378 bEnd = sal_True;
381 break;
382 case '0' :
383 case '1' :
384 case '2' :
385 case '3' :
386 case '4' :
387 case '5' :
388 case '6' :
389 case '7' :
390 case '8' :
391 case '9' :
393 if ( bE && ! bENum )
394 bENum = sal_True;
396 break;
397 default:
398 bEnd = sal_True;
400 if ( !bEnd )
401 nIndex++;
402 else
403 break;
405 if ( nIndex == nStartIndex )
406 bValid = sal_False;
407 if ( bValid )
409 rtl::OUString aNumber( rParaString.copy( nStartIndex, nIndex - nStartIndex ) );
410 if ( bE || bDot )
412 double fAttrDouble;
413 if (::sax::Converter::convertDouble(fAttrDouble, aNumber))
414 rParameter.Value <<= fAttrDouble;
415 else
416 bValid = sal_False;
418 else
420 sal_Int32 nValue;
421 if (::sax::Converter::convertNumber(nValue, aNumber))
422 rParameter.Value <<= nValue;
423 else
424 bValid = sal_False;
429 if ( bValid )
430 { // skipping white spaces
431 while( ( nIndex < rParaString.getLength() ) && rParaString[ nIndex ] == (sal_Unicode)' ' )
432 nIndex++;
434 return bValid;
437 void GetPosition3D( std::vector< com::sun::star::beans::PropertyValue >& rDest, // e.g. draw:extrusion-viewpoint
438 const rtl::OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp,
439 SvXMLUnitConverter& rUnitConverter )
441 drawing::Position3D aPosition3D;
442 if ( rUnitConverter.convertPosition3D( aPosition3D, rValue ) )
444 beans::PropertyValue aProp;
445 aProp.Name = EASGet( eDestProp );
446 aProp.Value <<= aPosition3D;
447 rDest.push_back( aProp );
451 void GetDoubleSequence( std::vector< com::sun::star::beans::PropertyValue >& rDest, // e.g. draw:glue-point-leaving-directions
452 const rtl::OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
454 std::vector< double > vDirection;
455 sal_Int32 nIndex = 0;
458 double fAttrDouble;
459 rtl::OUString aToken( rValue.getToken( 0, ',', nIndex ) );
460 if (!::sax::Converter::convertDouble( fAttrDouble, aToken ))
461 break;
462 else
463 vDirection.push_back( fAttrDouble );
465 while ( nIndex >= 0 );
467 if ( !vDirection.empty() )
469 uno::Sequence< double > aDirectionsSeq( vDirection.size() );
470 std::vector< double >::const_iterator aIter = vDirection.begin();
471 std::vector< double >::const_iterator aEnd = vDirection.end();
472 double* pValues = aDirectionsSeq.getArray();
474 while ( aIter != aEnd )
475 *pValues++ = *aIter++;
477 beans::PropertyValue aProp;
478 aProp.Name = EASGet( eDestProp );
479 aProp.Value <<= aDirectionsSeq;
480 rDest.push_back( aProp );
484 void GetEnhancedParameter( std::vector< com::sun::star::beans::PropertyValue >& rDest, // e.g. draw:handle-position
485 const rtl::OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
487 sal_Int32 nIndex = 0;
488 com::sun::star::drawing::EnhancedCustomShapeParameter aParameter;
489 if ( GetNextParameter( aParameter, nIndex, rValue ) )
491 beans::PropertyValue aProp;
492 aProp.Name = EASGet( eDestProp );
493 aProp.Value <<= aParameter;
494 rDest.push_back( aProp );
498 void GetEnhancedParameterPair( std::vector< com::sun::star::beans::PropertyValue >& rDest, // e.g. draw:handle-position
499 const rtl::OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
501 sal_Int32 nIndex = 0;
502 com::sun::star::drawing::EnhancedCustomShapeParameterPair aParameterPair;
503 if ( GetNextParameter( aParameterPair.First, nIndex, rValue )
504 && GetNextParameter( aParameterPair.Second, nIndex, rValue ) )
506 beans::PropertyValue aProp;
507 aProp.Name = EASGet( eDestProp );
508 aProp.Value <<= aParameterPair;
509 rDest.push_back( aProp );
513 sal_Int32 GetEnhancedParameterPairSequence( std::vector< com::sun::star::beans::PropertyValue >& rDest, // e.g. draw:glue-points
514 const rtl::OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
516 std::vector< com::sun::star::drawing::EnhancedCustomShapeParameterPair > vParameter;
517 com::sun::star::drawing::EnhancedCustomShapeParameterPair aParameter;
519 sal_Int32 nIndex = 0;
520 while ( GetNextParameter( aParameter.First, nIndex, rValue )
521 && GetNextParameter( aParameter.Second, nIndex, rValue ) )
523 vParameter.push_back( aParameter );
525 if ( !vParameter.empty() )
527 uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair > aParameterSeq( vParameter.size() );
528 std::vector< com::sun::star::drawing::EnhancedCustomShapeParameterPair >::const_iterator aIter = vParameter.begin();
529 std::vector< com::sun::star::drawing::EnhancedCustomShapeParameterPair >::const_iterator aEnd = vParameter.end();
530 com::sun::star::drawing::EnhancedCustomShapeParameterPair* pValues = aParameterSeq.getArray();
532 while ( aIter != aEnd )
533 *pValues++ = *aIter++;
535 beans::PropertyValue aProp;
536 aProp.Name = EASGet( eDestProp );
537 aProp.Value <<= aParameterSeq;
538 rDest.push_back( aProp );
540 return vParameter.size();
543 void GetEnhancedRectangleSequence( std::vector< com::sun::star::beans::PropertyValue >& rDest, // e.g. draw:text-areas
544 const rtl::OUString& rValue, const EnhancedCustomShapeTokenEnum eDestProp )
546 std::vector< com::sun::star::drawing::EnhancedCustomShapeTextFrame > vTextFrame;
547 com::sun::star::drawing::EnhancedCustomShapeTextFrame aParameter;
549 sal_Int32 nIndex = 0;
551 while ( GetNextParameter( aParameter.TopLeft.First, nIndex, rValue )
552 && GetNextParameter( aParameter.TopLeft.Second, nIndex, rValue )
553 && GetNextParameter( aParameter.BottomRight.First, nIndex, rValue )
554 && GetNextParameter( aParameter.BottomRight.Second, nIndex, rValue ) )
556 vTextFrame.push_back( aParameter );
558 if ( !vTextFrame.empty() )
560 uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeTextFrame > aTextFrameSeq( vTextFrame.size() );
561 std::vector< com::sun::star::drawing::EnhancedCustomShapeTextFrame >::const_iterator aIter = vTextFrame.begin();
562 std::vector< com::sun::star::drawing::EnhancedCustomShapeTextFrame >::const_iterator aEnd = vTextFrame.end();
563 com::sun::star::drawing::EnhancedCustomShapeTextFrame* pValues = aTextFrameSeq.getArray();
565 while ( aIter != aEnd )
566 *pValues++ = *aIter++;
568 beans::PropertyValue aProp;
569 aProp.Name = EASGet( eDestProp );
570 aProp.Value <<= aTextFrameSeq;
571 rDest.push_back( aProp );
575 void GetEnhancedPath( std::vector< com::sun::star::beans::PropertyValue >& rDest, // e.g. draw:enhanced-path
576 const rtl::OUString& rValue )
578 std::vector< com::sun::star::drawing::EnhancedCustomShapeParameterPair > vCoordinates;
579 std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment > vSegments;
581 sal_Int32 nIndex = 0;
582 sal_Int32 nParameterCount = 0;
584 sal_Int32 nParametersNeeded = 1;
585 sal_Int16 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::MOVETO;
587 sal_Bool bValid = sal_True;
589 while( bValid && ( nIndex < rValue.getLength() ) )
591 switch( rValue[ nIndex ] )
593 case 'M' :
595 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::MOVETO;
596 nParametersNeeded = 1;
597 nIndex++;
599 break;
600 case 'L' :
602 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::LINETO;
603 nParametersNeeded = 1;
604 nIndex++;
606 break;
607 case 'C' :
609 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::CURVETO;
610 nParametersNeeded = 3;
611 nIndex++;
613 break;
614 case 'Z' :
616 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::CLOSESUBPATH;
617 nParametersNeeded = 0;
618 nIndex++;
620 break;
621 case 'N' :
623 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ENDSUBPATH;
624 nParametersNeeded = 0;
625 nIndex++;
627 break;
628 case 'F' :
630 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::NOFILL;
631 nParametersNeeded = 0;
632 nIndex++;
634 break;
635 case 'S' :
637 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::NOSTROKE;
638 nParametersNeeded = 0;
639 nIndex++;
641 break;
642 case 'T' :
644 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ANGLEELLIPSETO;
645 nParametersNeeded = 3;
646 nIndex++;
648 break;
649 case 'U' :
651 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ANGLEELLIPSE;
652 nParametersNeeded = 3;
653 nIndex++;
655 break;
656 case 'A' :
658 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ARCTO;
659 nParametersNeeded = 4;
660 nIndex++;
662 break;
663 case 'B' :
665 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ARC;
666 nParametersNeeded = 4;
667 nIndex++;
669 break;
670 case 'G' :
672 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ARCANGLETO;
673 nParametersNeeded = 2;
674 nIndex++;
676 break;
677 case 'W' :
679 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::CLOCKWISEARCTO;
680 nParametersNeeded = 4;
681 nIndex++;
683 break;
684 case 'V' :
686 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::CLOCKWISEARC;
687 nParametersNeeded = 4;
688 nIndex++;
690 break;
691 case 'X' :
693 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTX;
694 nParametersNeeded = 1;
695 nIndex++;
697 break;
698 case 'Y' :
700 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTY;
701 nParametersNeeded = 1;
702 nIndex++;
704 break;
705 case 'Q' :
707 nLatestSegmentCommand = com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::QUADRATICCURVETO;
708 nParametersNeeded = 2;
709 nIndex++;
711 break;
712 case ' ' :
714 nIndex++;
716 break;
718 case '$' :
719 case '?' :
720 case '0' :
721 case '1' :
722 case '2' :
723 case '3' :
724 case '4' :
725 case '5' :
726 case '6' :
727 case '7' :
728 case '8' :
729 case '9' :
730 case '.' :
731 case '-' :
733 com::sun::star::drawing::EnhancedCustomShapeParameterPair aPair;
734 if ( GetNextParameter( aPair.First, nIndex, rValue ) &&
735 GetNextParameter( aPair.Second, nIndex, rValue ) )
737 vCoordinates.push_back( aPair );
738 nParameterCount++;
740 else
741 bValid = sal_False;
743 break;
744 default:
745 nIndex++;
746 break;
748 if ( !nParameterCount && !nParametersNeeded )
750 com::sun::star::drawing::EnhancedCustomShapeSegment aSegment;
751 aSegment.Command = nLatestSegmentCommand;
752 aSegment.Count = 0;
753 vSegments.push_back( aSegment );
754 nParametersNeeded = 0x7fffffff;
756 else if ( nParameterCount >= nParametersNeeded )
758 // check if the last command is identical,
759 // if so, we just need to increment the count
760 if ( !vSegments.empty() && ( vSegments[ vSegments.size() - 1 ].Command == nLatestSegmentCommand ) )
761 vSegments[ vSegments.size() -1 ].Count++;
762 else
764 com::sun::star::drawing::EnhancedCustomShapeSegment aSegment;
765 aSegment.Command = nLatestSegmentCommand;
766 aSegment.Count = 1;
767 vSegments.push_back( aSegment );
769 nParameterCount = 0;
772 // adding the Coordinates property
773 uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair > seqCoordinates( vCoordinates.size() );
774 std::vector< com::sun::star::drawing::EnhancedCustomShapeParameterPair >::const_iterator aCoordinatesIter = vCoordinates.begin();
775 std::vector< com::sun::star::drawing::EnhancedCustomShapeParameterPair >::const_iterator aCoordinatesEnd = vCoordinates.end();
776 com::sun::star::drawing::EnhancedCustomShapeParameterPair* pCoordinateValues = seqCoordinates.getArray();
778 while ( aCoordinatesIter != aCoordinatesEnd )
779 *pCoordinateValues++ = *aCoordinatesIter++;
781 beans::PropertyValue aProp;
782 aProp.Name = EASGet( EAS_Coordinates );
783 aProp.Value <<= seqCoordinates;
784 rDest.push_back( aProp );
787 // adding the Segments property
788 uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeSegment > seqSegments( vSegments.size() );
789 std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >::const_iterator aSegmentsIter = vSegments.begin();
790 std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >::const_iterator aSegmentsEnd = vSegments.end();
791 com::sun::star::drawing::EnhancedCustomShapeSegment* pSegmentValues = seqSegments.getArray();
793 while ( aSegmentsIter != aSegmentsEnd )
794 *pSegmentValues++ = *aSegmentsIter++;
796 aProp.Name = EASGet( EAS_Segments );
797 aProp.Value <<= seqSegments;
798 rDest.push_back( aProp );
801 void GetAdjustmentValues( std::vector< com::sun::star::beans::PropertyValue >& rDest, // draw:adjustments
802 const rtl::OUString& rValue )
804 std::vector< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue > vAdjustmentValue;
805 com::sun::star::drawing::EnhancedCustomShapeParameter aParameter;
806 sal_Int32 nIndex = 0;
807 while ( GetNextParameter( aParameter, nIndex, rValue ) )
809 com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue aAdj;
810 if ( aParameter.Type == com::sun::star::drawing::EnhancedCustomShapeParameterType::NORMAL )
812 aAdj.Value <<= aParameter.Value;
813 aAdj.State = beans::PropertyState_DIRECT_VALUE;
815 else
816 aAdj.State = beans::PropertyState_DEFAULT_VALUE; // this should not be, but better than setting nothing
818 vAdjustmentValue.push_back( aAdj );
821 sal_Int32 nAdjustmentValues = vAdjustmentValue.size();
822 if ( nAdjustmentValues )
824 uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue > aAdjustmentValues( nAdjustmentValues );
825 std::vector< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue >::const_iterator aIter = vAdjustmentValue.begin();
826 std::vector< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue >::const_iterator aEnd = vAdjustmentValue.end();
827 com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue* pValues = aAdjustmentValues.getArray();
829 while ( aIter != aEnd )
830 *pValues++ = *aIter++;
832 beans::PropertyValue aProp;
833 aProp.Name = EASGet( EAS_AdjustmentValues );
834 aProp.Value <<= aAdjustmentValues;
835 rDest.push_back( aProp );
839 void XMLEnhancedCustomShapeContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
841 sal_Int16 nLength = xAttrList->getLength();
842 if ( nLength )
844 sal_Int32 nAttrNumber;
845 for( sal_Int16 nAttr = 0; nAttr < nLength; nAttr++ )
847 rtl::OUString aLocalName;
848 const rtl::OUString& rValue = xAttrList->getValueByIndex( nAttr );
849 /* sven fixme, this must be checked! sal_uInt16 nPrefix = */ GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( nAttr ), &aLocalName );
851 switch( EASGet( aLocalName ) )
853 case EAS_type :
854 GetString( mrCustomShapeGeometry, rValue, EAS_Type );
855 break;
856 case EAS_mirror_horizontal :
857 GetBool( mrCustomShapeGeometry, rValue, EAS_MirroredX );
858 break;
859 case EAS_mirror_vertical :
860 GetBool( mrCustomShapeGeometry, rValue, EAS_MirroredY );
861 break;
862 case EAS_viewBox :
864 SdXMLImExViewBox aViewBox( rValue, GetImport().GetMM100UnitConverter() );
865 awt::Rectangle aRect( aViewBox.GetX(), aViewBox.GetY(), aViewBox.GetWidth(), aViewBox.GetHeight() );
866 beans::PropertyValue aProp;
867 aProp.Name = EASGet( EAS_ViewBox );
868 aProp.Value <<= aRect;
869 mrCustomShapeGeometry.push_back( aProp );
871 break;
872 case EAS_text_rotate_angle :
873 GetDouble( mrCustomShapeGeometry, rValue, EAS_TextRotateAngle );
874 break;
875 case EAS_extrusion_allowed :
876 GetBool( maPath, rValue, EAS_ExtrusionAllowed );
877 break;
878 case EAS_text_path_allowed :
879 GetBool( maPath, rValue, EAS_TextPathAllowed );
880 break;
881 case EAS_concentric_gradient_fill_allowed :
882 GetBool( maPath, rValue, EAS_ConcentricGradientFillAllowed );
883 break;
884 case EAS_extrusion :
885 GetBool( maExtrusion, rValue, EAS_Extrusion );
886 break;
887 case EAS_extrusion_brightness :
888 GetDoublePercentage( maExtrusion, rValue, EAS_Brightness );
889 break;
890 case EAS_extrusion_depth :
892 sal_Int32 nIndex = 0;
893 com::sun::star::drawing::EnhancedCustomShapeParameterPair aParameterPair;
894 com::sun::star::drawing::EnhancedCustomShapeParameter& rDepth = aParameterPair.First;
895 com::sun::star::drawing::EnhancedCustomShapeParameter& rFraction = aParameterPair.Second;
896 if ( GetNextParameter( rDepth, nIndex, rValue ) )
898 // try to catch the unit for the depth
899 sal_Int16 const eSrcUnit(
900 ::sax::Converter::GetUnitFromString(
901 rValue, util::MeasureUnit::MM_100TH));
903 rtl::OUStringBuffer aUnitStr;
904 double fFactor = ::sax::Converter::GetConversionFactor(
905 aUnitStr, util::MeasureUnit::MM_100TH, eSrcUnit);
906 if ( ( fFactor != 1.0 ) && ( fFactor != 0.0 ) )
908 double fDepth(0.0);
909 if ( rDepth.Value >>= fDepth )
911 fDepth /= fFactor;
912 rDepth.Value <<= fDepth;
915 if ( rValue.matchIgnoreAsciiCase( aUnitStr.toString(), nIndex ) )
916 nIndex += aUnitStr.getLength();
918 // skipping white spaces
919 while( ( nIndex < rValue.getLength() ) && rValue[ nIndex ] == (sal_Unicode)' ' )
920 nIndex++;
922 if ( GetNextParameter( rFraction, nIndex, rValue ) )
924 beans::PropertyValue aProp;
925 aProp.Name = EASGet( EAS_Depth );
926 aProp.Value <<= aParameterPair;
927 maExtrusion.push_back( aProp );
931 break;
932 case EAS_extrusion_diffusion :
933 GetDoublePercentage( maExtrusion, rValue, EAS_Diffusion );
934 break;
935 case EAS_extrusion_number_of_line_segments :
936 GetInt32( maExtrusion, rValue, EAS_NumberOfLineSegments );
937 break;
938 case EAS_extrusion_light_face :
939 GetBool( maExtrusion, rValue, EAS_LightFace );
940 break;
941 case EAS_extrusion_first_light_harsh :
942 GetBool( maExtrusion, rValue, EAS_FirstLightHarsh );
943 break;
944 case EAS_extrusion_second_light_harsh :
945 GetBool( maExtrusion, rValue, EAS_SecondLightHarsh );
946 break;
947 case EAS_extrusion_first_light_level :
948 GetDoublePercentage( maExtrusion, rValue, EAS_FirstLightLevel );
949 break;
950 case EAS_extrusion_second_light_level :
951 GetDoublePercentage( maExtrusion, rValue, EAS_SecondLightLevel );
952 break;
953 case EAS_extrusion_first_light_direction :
954 GetB3DVector( maExtrusion, rValue, EAS_FirstLightDirection );
955 break;
956 case EAS_extrusion_second_light_direction :
957 GetB3DVector( maExtrusion, rValue, EAS_SecondLightDirection );
958 break;
959 case EAS_extrusion_metal :
960 GetBool( maExtrusion, rValue, EAS_Metal );
961 break;
962 case EAS_shade_mode :
964 drawing::ShadeMode eShadeMode( drawing::ShadeMode_FLAT );
965 if( IsXMLToken( rValue, XML_PHONG ) )
966 eShadeMode = drawing::ShadeMode_PHONG;
967 else if ( IsXMLToken( rValue, XML_GOURAUD ) )
968 eShadeMode = drawing::ShadeMode_SMOOTH;
969 else if ( IsXMLToken( rValue, XML_DRAFT ) )
970 eShadeMode = drawing::ShadeMode_DRAFT;
972 beans::PropertyValue aProp;
973 aProp.Name = EASGet( EAS_ShadeMode );
974 aProp.Value <<= eShadeMode;
975 maExtrusion.push_back( aProp );
977 break;
978 case EAS_extrusion_rotation_angle :
979 GetEnhancedParameterPair( maExtrusion, rValue, EAS_RotateAngle );
980 break;
981 case EAS_extrusion_rotation_center :
982 GetB3DVector( maExtrusion, rValue, EAS_RotationCenter );
983 break;
984 case EAS_extrusion_shininess :
985 GetDoublePercentage( maExtrusion, rValue, EAS_Shininess );
986 break;
987 case EAS_extrusion_skew :
988 GetEnhancedParameterPair( maExtrusion, rValue, EAS_Skew );
989 break;
990 case EAS_extrusion_specularity :
991 GetDoublePercentage( maExtrusion, rValue, EAS_Specularity );
992 break;
993 case EAS_projection :
995 drawing::ProjectionMode eProjectionMode( drawing::ProjectionMode_PERSPECTIVE );
996 if( IsXMLToken( rValue, XML_PARALLEL ) )
997 eProjectionMode = drawing::ProjectionMode_PARALLEL;
999 beans::PropertyValue aProp;
1000 aProp.Name = EASGet( EAS_ProjectionMode );
1001 aProp.Value <<= eProjectionMode;
1002 maExtrusion.push_back( aProp );
1004 break;
1005 case EAS_extrusion_viewpoint :
1006 GetPosition3D( maExtrusion, rValue, EAS_ViewPoint, mrUnitConverter );
1007 break;
1008 case EAS_extrusion_origin :
1009 GetEnhancedParameterPair( maExtrusion, rValue, EAS_Origin );
1010 break;
1011 case EAS_extrusion_color :
1012 GetBool( maExtrusion, rValue, EAS_Color );
1013 break;
1014 case EAS_enhanced_path :
1015 GetEnhancedPath( maPath, rValue );
1016 break;
1017 case EAS_path_stretchpoint_x :
1019 if (::sax::Converter::convertNumber(nAttrNumber, rValue))
1021 beans::PropertyValue aProp;
1022 aProp.Name = EASGet( EAS_StretchX );
1023 aProp.Value <<= nAttrNumber;
1024 maPath.push_back( aProp );
1027 break;
1028 case EAS_path_stretchpoint_y :
1030 if (::sax::Converter::convertNumber(nAttrNumber, rValue))
1032 beans::PropertyValue aProp;
1033 aProp.Name = EASGet( EAS_StretchY );
1034 aProp.Value <<= nAttrNumber;
1035 maPath.push_back( aProp );
1038 break;
1039 case EAS_text_areas :
1040 GetEnhancedRectangleSequence( maPath, rValue, EAS_TextFrames );
1041 break;
1042 case EAS_glue_points :
1044 sal_Int32 i, nPairs = GetEnhancedParameterPairSequence( maPath, rValue, EAS_GluePoints );
1045 GetImport().GetShapeImport()->moveGluePointMapping( mrxShape, nPairs );
1046 for ( i = 0; i < nPairs; i++ )
1047 GetImport().GetShapeImport()->addGluePointMapping( mrxShape, i + 4, i + 4 );
1049 break;
1050 case EAS_glue_point_type :
1051 GetEnum( maPath, rValue, EAS_GluePointType, *aXML_GluePointEnumMap );
1052 break;
1053 case EAS_glue_point_leaving_directions :
1054 GetDoubleSequence( maPath, rValue, EAS_GluePointLeavingDirections );
1055 break;
1056 case EAS_text_path :
1057 GetBool( maTextPath, rValue, EAS_TextPath );
1058 break;
1059 case EAS_text_path_mode :
1061 com::sun::star::drawing::EnhancedCustomShapeTextPathMode eTextPathMode( com::sun::star::drawing::EnhancedCustomShapeTextPathMode_NORMAL );
1062 if( IsXMLToken( rValue, XML_PATH ) )
1063 eTextPathMode = com::sun::star::drawing::EnhancedCustomShapeTextPathMode_PATH;
1064 else if ( IsXMLToken( rValue, XML_SHAPE ) )
1065 eTextPathMode = com::sun::star::drawing::EnhancedCustomShapeTextPathMode_SHAPE;
1067 beans::PropertyValue aProp;
1068 aProp.Name = EASGet( EAS_TextPathMode );
1069 aProp.Value <<= eTextPathMode;
1070 maTextPath.push_back( aProp );
1072 break;
1073 case EAS_text_path_scale :
1075 sal_Bool bScaleX = IsXMLToken( rValue, XML_SHAPE );
1076 beans::PropertyValue aProp;
1077 aProp.Name = EASGet( EAS_ScaleX );
1078 aProp.Value <<= bScaleX;
1079 maTextPath.push_back( aProp );
1081 break;
1082 case EAS_text_path_same_letter_heights :
1083 GetBool( maTextPath, rValue, EAS_SameLetterHeights );
1084 break;
1085 case EAS_modifiers :
1086 GetAdjustmentValues( mrCustomShapeGeometry, rValue );
1087 break;
1088 default:
1089 break;
1095 void SdXMLCustomShapePropertyMerge( std::vector< com::sun::star::beans::PropertyValue >& rPropVec,
1096 const std::vector< beans::PropertyValues >& rElement,
1097 const rtl::OUString& rElementName )
1099 if ( !rElement.empty() )
1101 uno::Sequence< beans::PropertyValues > aPropSeq( rElement.size() );
1102 std::vector< beans::PropertyValues >::const_iterator aIter = rElement.begin();
1103 std::vector< beans::PropertyValues >::const_iterator aEnd = rElement.end();
1104 beans::PropertyValues* pValues = aPropSeq.getArray();
1106 while ( aIter != aEnd )
1107 *pValues++ = *aIter++;
1109 beans::PropertyValue aProp;
1110 aProp.Name = rElementName;
1111 aProp.Value <<= aPropSeq;
1112 rPropVec.push_back( aProp );
1116 void SdXMLCustomShapePropertyMerge( std::vector< com::sun::star::beans::PropertyValue >& rPropVec,
1117 const std::vector< rtl::OUString >& rElement,
1118 const rtl::OUString& rElementName )
1120 if ( !rElement.empty() )
1122 uno::Sequence< rtl::OUString > aPropSeq( rElement.size() );
1123 std::vector< rtl::OUString >::const_iterator aIter = rElement.begin();
1124 std::vector< rtl::OUString >::const_iterator aEnd = rElement.end();
1125 rtl::OUString* pValues = aPropSeq.getArray();
1127 while ( aIter != aEnd )
1128 *pValues++ = *aIter++;
1130 beans::PropertyValue aProp;
1131 aProp.Name = rElementName;
1132 aProp.Value <<= aPropSeq;
1133 rPropVec.push_back( aProp );
1137 void SdXMLCustomShapePropertyMerge( std::vector< com::sun::star::beans::PropertyValue >& rPropVec,
1138 const std::vector< com::sun::star::beans::PropertyValue >& rElement,
1139 const rtl::OUString& rElementName )
1141 if ( !rElement.empty() )
1143 uno::Sequence< beans::PropertyValue > aPropSeq( rElement.size() );
1144 std::vector< beans::PropertyValue >::const_iterator aIter = rElement.begin();
1145 std::vector< beans::PropertyValue >::const_iterator aEnd = rElement.end();
1146 beans::PropertyValue* pValues = aPropSeq.getArray();
1148 while ( aIter != aEnd )
1149 *pValues++ = *aIter++;
1151 beans::PropertyValue aProp;
1152 aProp.Name = rElementName;
1153 aProp.Value <<= aPropSeq;
1154 rPropVec.push_back( aProp );
1158 typedef boost::unordered_map< rtl::OUString, sal_Int32, rtl::OUStringHash, OUStringEqFunc> EquationHashMap;
1160 /* if rPara.Type is from type EnhancedCustomShapeParameterType::EQUATION, the name of the equation
1161 will be converted from rtl::OUString to index */
1162 void CheckAndResolveEquationParameter( com::sun::star::drawing::EnhancedCustomShapeParameter& rPara, EquationHashMap* pH )
1164 if ( rPara.Type == com::sun::star::drawing::EnhancedCustomShapeParameterType::EQUATION )
1166 rtl::OUString aEquationName;
1167 if ( rPara.Value >>= aEquationName )
1169 sal_Int32 nIndex = 0;
1170 EquationHashMap::iterator aHashIter( pH->find( aEquationName ) );
1171 if ( aHashIter != pH->end() )
1172 nIndex = (*aHashIter).second;
1173 rPara.Value <<= nIndex;
1178 void XMLEnhancedCustomShapeContext::EndElement()
1180 // resolve properties that are indexing a Equation
1181 if ( !maEquations.empty() )
1183 // creating hash map containing the name and index of each equation
1184 EquationHashMap* pH = new EquationHashMap;
1185 std::vector< rtl::OUString >::iterator aEquationNameIter = maEquationNames.begin();
1186 std::vector< rtl::OUString >::iterator aEquationNameEnd = maEquationNames.end();
1187 while( aEquationNameIter != aEquationNameEnd )
1189 (*pH)[ *aEquationNameIter ] = (sal_Int32)( aEquationNameIter - maEquationNames.begin() );
1190 ++aEquationNameIter;
1193 // resolve equation
1194 std::vector< rtl::OUString >::iterator aEquationIter = maEquations.begin();
1195 std::vector< rtl::OUString >::iterator aEquationEnd = maEquations.end();
1196 while( aEquationIter != aEquationEnd )
1198 sal_Int32 nIndexOf = 0;
1201 nIndexOf = aEquationIter->indexOf( '?', nIndexOf );
1202 if ( nIndexOf != -1 )
1204 rtl::OUString aEquationName;
1205 if ( GetEquationName( *aEquationIter, nIndexOf + 1, aEquationName ) )
1207 // copying first characters inclusive '?'
1208 rtl::OUString aNew( aEquationIter->copy( 0, nIndexOf + 1 ) );
1209 sal_Int32 nIndex = 0;
1210 EquationHashMap::iterator aHashIter( pH->find( aEquationName ) );
1211 if ( aHashIter != pH->end() )
1212 nIndex = (*aHashIter).second;
1213 aNew += rtl::OUString::valueOf( nIndex );
1214 aNew += aEquationIter->copy( nIndexOf + aEquationName.getLength() + 1 );
1215 *aEquationIter = aNew;
1217 nIndexOf++;
1220 while( nIndexOf != -1 );
1221 ++aEquationIter;
1224 // Path
1225 sal_Int32 i;
1226 std::vector< beans::PropertyValue >::iterator aPathIter = maPath.begin();
1227 std::vector< beans::PropertyValue >::iterator aPathEnd = maPath.end();
1228 while ( aPathIter != aPathEnd )
1230 switch( EASGet( aPathIter->Name ) )
1232 case EAS_Coordinates :
1233 case EAS_GluePoints :
1235 uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair >& rSeq =
1236 *((uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair >*)
1237 aPathIter->Value.getValue());
1238 for ( i = 0; i < rSeq.getLength(); i++ )
1240 CheckAndResolveEquationParameter( rSeq[ i ].First, pH );
1241 CheckAndResolveEquationParameter( rSeq[ i ].Second, pH );
1244 break;
1245 case EAS_TextFrames :
1247 uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeTextFrame >& rSeq =
1248 *((uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeTextFrame >*)
1249 aPathIter->Value.getValue());
1250 for ( i = 0; i < rSeq.getLength(); i++ )
1252 CheckAndResolveEquationParameter( rSeq[ i ].TopLeft.First, pH );
1253 CheckAndResolveEquationParameter( rSeq[ i ].TopLeft.Second, pH );
1254 CheckAndResolveEquationParameter( rSeq[ i ].BottomRight.First, pH );
1255 CheckAndResolveEquationParameter( rSeq[ i ].BottomRight.Second, pH );
1258 break;
1259 default:
1260 break;
1262 ++aPathIter;
1264 std::vector< beans::PropertyValues >::iterator aHandleIter = maHandles.begin();
1265 std::vector< beans::PropertyValues >::iterator aHandleEnd = maHandles.end();
1266 while ( aHandleIter != aHandleEnd )
1268 beans::PropertyValue* pValues = aHandleIter->getArray();
1269 for ( i = 0; i < aHandleIter->getLength(); i++ )
1271 switch( EASGet( pValues->Name ) )
1273 case EAS_RangeYMinimum :
1274 case EAS_RangeYMaximum :
1275 case EAS_RangeXMinimum :
1276 case EAS_RangeXMaximum :
1277 case EAS_RadiusRangeMinimum :
1278 case EAS_RadiusRangeMaximum :
1280 CheckAndResolveEquationParameter( *((com::sun::star::drawing::EnhancedCustomShapeParameter*)
1281 pValues->Value.getValue()), pH );
1283 break;
1285 case EAS_Position :
1286 case EAS_Polar :
1288 CheckAndResolveEquationParameter( (*((com::sun::star::drawing::EnhancedCustomShapeParameterPair*)
1289 pValues->Value.getValue())).First, pH );
1290 CheckAndResolveEquationParameter( (*((com::sun::star::drawing::EnhancedCustomShapeParameterPair*)
1291 pValues->Value.getValue())).Second, pH );
1293 break;
1294 default:
1295 break;
1297 pValues++;
1299 ++aHandleIter;
1301 delete pH;
1304 SdXMLCustomShapePropertyMerge( mrCustomShapeGeometry, maExtrusion, EASGet( EAS_Extrusion ) );
1305 SdXMLCustomShapePropertyMerge( mrCustomShapeGeometry, maPath, EASGet( EAS_Path ) );
1306 SdXMLCustomShapePropertyMerge( mrCustomShapeGeometry, maTextPath, EASGet( EAS_TextPath ) );
1307 SdXMLCustomShapePropertyMerge( mrCustomShapeGeometry, maEquations, EASGet( EAS_Equations ) );
1308 if ( !maHandles.empty() )
1309 SdXMLCustomShapePropertyMerge( mrCustomShapeGeometry, maHandles, EASGet( EAS_Handles ) );
1312 SvXMLImportContext* XMLEnhancedCustomShapeContext::CreateChildContext( sal_uInt16 nPrefix,const rtl::OUString& rLocalName,
1313 const uno::Reference< xml::sax::XAttributeList> & xAttrList )
1315 EnhancedCustomShapeTokenEnum aTokenEnum = EASGet( rLocalName );
1316 if ( aTokenEnum == EAS_equation )
1318 sal_Int16 nLength = xAttrList->getLength();
1319 if ( nLength )
1321 rtl::OUString aFormula;
1322 rtl::OUString aFormulaName;
1323 for( sal_Int16 nAttr = 0; nAttr < nLength; nAttr++ )
1325 rtl::OUString aLocalName;
1326 const rtl::OUString& rValue = xAttrList->getValueByIndex( nAttr );
1327 /* fixme sven, this needs to be chekced! sal_uInt16 nPrefix = */ GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( nAttr ), &aLocalName );
1329 switch( EASGet( aLocalName ) )
1331 case EAS_formula :
1332 aFormula = rValue;
1333 break;
1334 case EAS_name :
1335 aFormulaName = rValue;
1336 break;
1337 default:
1338 break;
1341 if ( !aFormulaName.isEmpty() || !aFormula.isEmpty() )
1343 maEquations.push_back( aFormula );
1344 maEquationNames.push_back( aFormulaName );
1348 else if ( aTokenEnum == EAS_handle )
1350 std::vector< com::sun::star::beans::PropertyValue > aHandle;
1351 const sal_Int16 nLength = xAttrList->getLength();
1352 for( sal_Int16 nAttr = 0; nAttr < nLength; nAttr++ )
1354 rtl::OUString aLocalName;
1355 const rtl::OUString& rValue = xAttrList->getValueByIndex( nAttr );
1356 /* fixme sven, this needs to be chekced! sal_uInt16 nPrefix = */ GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( nAttr ), &aLocalName );
1357 switch( EASGet( aLocalName ) )
1359 case EAS_handle_mirror_vertical :
1360 GetBool( aHandle, rValue, EAS_MirroredY );
1361 break;
1362 case EAS_handle_mirror_horizontal :
1363 GetBool( aHandle, rValue, EAS_MirroredX );
1364 break;
1365 case EAS_handle_switched :
1366 GetBool( aHandle, rValue, EAS_Switched );
1367 break;
1368 case EAS_handle_position :
1369 GetEnhancedParameterPair( aHandle, rValue, EAS_Position );
1370 break;
1371 case EAS_handle_range_x_minimum :
1372 GetEnhancedParameter( aHandle, rValue, EAS_RangeXMinimum );
1373 break;
1374 case EAS_handle_range_x_maximum :
1375 GetEnhancedParameter( aHandle, rValue, EAS_RangeXMaximum );
1376 break;
1377 case EAS_handle_range_y_minimum :
1378 GetEnhancedParameter( aHandle, rValue, EAS_RangeYMinimum );
1379 break;
1380 case EAS_handle_range_y_maximum :
1381 GetEnhancedParameter( aHandle, rValue, EAS_RangeYMaximum );
1382 break;
1383 case EAS_handle_polar :
1384 GetEnhancedParameterPair( aHandle, rValue, EAS_Polar );
1385 break;
1386 case EAS_handle_radius_range_minimum :
1387 GetEnhancedParameter( aHandle, rValue, EAS_RadiusRangeMinimum );
1388 break;
1389 case EAS_handle_radius_range_maximum :
1390 GetEnhancedParameter( aHandle, rValue, EAS_RadiusRangeMaximum );
1391 break;
1392 default:
1393 break;
1396 beans::PropertyValues aPropSeq( aHandle.size() );
1397 std::vector< beans::PropertyValue >::const_iterator aIter = aHandle.begin();
1398 std::vector< beans::PropertyValue >::const_iterator aEnd = aHandle.end();
1399 beans::PropertyValue* pValues = aPropSeq.getArray();
1401 while ( aIter != aEnd )
1402 *pValues++ = *aIter++;
1404 maHandles.push_back( aPropSeq );
1406 return SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
1409 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */