Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "eschesdo.hxx"
21 : #include <svx/svdxcgv.hxx>
22 : #include <svx/svdomedia.hxx>
23 : #include <svx/xflftrit.hxx>
24 : #include <filter/msfilter/escherex.hxx>
25 : #include <filter/msfilter/util.hxx>
26 : #include <svx/unoapi.hxx>
27 : #include <svx/svdobj.hxx>
28 : #include <svx/svdoashp.hxx>
29 : #include <svx/svdoole2.hxx>
30 : #include <svx/svdmodel.hxx>
31 : #include <editeng/outlobj.hxx>
32 : #include <vcl/gradient.hxx>
33 : #include <vcl/graph.hxx>
34 : #include <vcl/cvtgrf.hxx>
35 : #include <vcl/svapp.hxx>
36 : #include <vcl/wrkwin.hxx>
37 : #include <tools/stream.hxx>
38 : #include <tools/zcodec.hxx>
39 : #include <svx/svdopath.hxx>
40 : #include <stdlib.h>
41 : #include <vcl/graphicfilter.hxx>
42 : #include "svx/EnhancedCustomShapeTypeNames.hxx"
43 : #include "svx/EnhancedCustomShapeGeometry.hxx"
44 : #include <svx/EnhancedCustomShapeFunctionParser.hxx>
45 : #include "svx/EnhancedCustomShape2d.hxx"
46 : #include <com/sun/star/beans/PropertyValues.hpp>
47 : #include <com/sun/star/beans/XPropertyState.hpp>
48 : #include <com/sun/star/awt/GradientStyle.hpp>
49 : #include <com/sun/star/awt/RasterOperation.hpp>
50 : #include <com/sun/star/awt/Gradient.hpp>
51 : #include <com/sun/star/drawing/LineStyle.hpp>
52 : #include <com/sun/star/drawing/LineJoint.hpp>
53 : #include <com/sun/star/drawing/LineCap.hpp>
54 : #include <com/sun/star/drawing/FillStyle.hpp>
55 : #include <com/sun/star/drawing/LineDash.hpp>
56 : #include <com/sun/star/drawing/BezierPoint.hpp>
57 : #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
58 : #include <com/sun/star/drawing/ConnectorType.hpp>
59 : #include <com/sun/star/drawing/ConnectionType.hpp>
60 : #include <com/sun/star/drawing/CircleKind.hpp>
61 : #include <com/sun/star/drawing/PointSequence.hpp>
62 : #include <com/sun/star/drawing/FlagSequence.hpp>
63 : #include <com/sun/star/drawing/PolygonFlags.hpp>
64 : #include <com/sun/star/text/WritingMode.hpp>
65 : #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
66 : #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
67 : #include <com/sun/star/drawing/EnhancedCustomShapeSegment.hpp>
68 : #include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>
69 : #include <com/sun/star/drawing/EnhancedCustomShapeGluePointType.hpp>
70 : #include <com/sun/star/drawing/EnhancedCustomShapeSegmentCommand.hpp>
71 : #include <com/sun/star/drawing/EnhancedCustomShapeTextFrame.hpp>
72 : #include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp>
73 : #include <com/sun/star/drawing/EnhancedCustomShapeTextPathMode.hpp>
74 : #include <com/sun/star/drawing/ProjectionMode.hpp>
75 : #include <com/sun/star/text/XSimpleText.hpp>
76 : #include <com/sun/star/drawing/ShadeMode.hpp>
77 : #include <com/sun/star/drawing/TextFitToSizeType.hpp>
78 : #include <vcl/hatch.hxx>
79 : #include <com/sun/star/awt/XGraphics.hpp>
80 : #include <com/sun/star/awt/FontSlant.hpp>
81 : #include <com/sun/star/awt/FontWeight.hpp>
82 : #include <com/sun/star/drawing/ColorMode.hpp>
83 : #include <com/sun/star/drawing/Position3D.hpp>
84 : #include <com/sun/star/drawing/Direction3D.hpp>
85 : #include <com/sun/star/text/GraphicCrop.hpp>
86 : #include <unotools/ucbstreamhelper.hxx>
87 : #include <unotools/localfilehelper.hxx>
88 : #include <comphelper/string.hxx>
89 : #include <toolkit/helper/vclunohelper.hxx>
90 : #include <vcl/virdev.hxx>
91 : #include <rtl/crc.h>
92 : #include <rtl/strbuf.hxx>
93 : #include <boost/scoped_array.hpp>
94 : #include <boost/scoped_ptr.hpp>
95 :
96 : using namespace ::com::sun::star;
97 :
98 :
99 0 : EscherExContainer::EscherExContainer( SvStream& rSt, const sal_uInt16 nRecType, const sal_uInt16 nInstance ) :
100 0 : rStrm ( rSt )
101 : {
102 0 : rStrm.WriteUInt32( ( ( 0xf | ( nInstance << 4 ) ) | ( nRecType << 16 ) ) ).WriteUInt32( 0 );
103 0 : nContPos = rStrm.Tell();
104 0 : }
105 0 : EscherExContainer::~EscherExContainer()
106 : {
107 0 : sal_uInt32 nPos = rStrm.Tell();
108 0 : sal_uInt32 nSize= nPos - nContPos;
109 0 : if ( nSize )
110 : {
111 0 : rStrm.Seek( nContPos - 4 );
112 0 : rStrm.WriteUInt32( nSize );
113 0 : rStrm.Seek( nPos );
114 : }
115 0 : }
116 :
117 0 : EscherExAtom::EscherExAtom( SvStream& rSt, const sal_uInt16 nRecType, const sal_uInt16 nInstance, const sal_uInt8 nVersion ) :
118 0 : rStrm ( rSt )
119 : {
120 0 : rStrm.WriteUInt32( ( ( nVersion | ( nInstance << 4 ) ) | ( nRecType << 16 ) ) ).WriteUInt32( 0 );
121 0 : nContPos = rStrm.Tell();
122 0 : }
123 0 : EscherExAtom::~EscherExAtom()
124 : {
125 0 : sal_uInt32 nPos = rStrm.Tell();
126 0 : sal_uInt32 nSize= nPos - nContPos;
127 0 : if ( nSize )
128 : {
129 0 : rStrm.Seek( nContPos - 4 );
130 0 : rStrm.WriteUInt32( nSize );
131 0 : rStrm.Seek( nPos );
132 : }
133 0 : }
134 :
135 72 : EscherExClientRecord_Base::~EscherExClientRecord_Base()
136 : {
137 72 : }
138 :
139 30 : EscherExClientAnchor_Base::~EscherExClientAnchor_Base()
140 : {
141 30 : }
142 :
143 1670 : void EscherPropertyContainer::ImplInit()
144 : {
145 1670 : nSortCount = 0;
146 1670 : nCountCount = 0;
147 1670 : nCountSize = 0;
148 1670 : nSortBufSize = 64;
149 1670 : bHasComplexData = false;
150 1670 : pSortStruct = new EscherPropSortStruct[ nSortBufSize ];
151 1670 : }
152 :
153 42 : EscherPropertyContainer::EscherPropertyContainer()
154 : : pGraphicProvider(NULL)
155 : , pPicOutStrm(NULL)
156 42 : , pShapeBoundRect(NULL)
157 : {
158 42 : ImplInit();
159 42 : }
160 :
161 1628 : EscherPropertyContainer::EscherPropertyContainer(
162 : EscherGraphicProvider& rGraphProv,
163 : SvStream* pPiOutStrm,
164 : Rectangle& rBoundRect ) :
165 :
166 : pGraphicProvider ( &rGraphProv ),
167 : pPicOutStrm ( pPiOutStrm ),
168 1628 : pShapeBoundRect ( &rBoundRect )
169 : {
170 1628 : ImplInit();
171 1628 : }
172 :
173 1670 : EscherPropertyContainer::~EscherPropertyContainer()
174 : {
175 1670 : if ( bHasComplexData )
176 : {
177 31426 : while ( nSortCount-- )
178 28674 : delete[] pSortStruct[ nSortCount ].pBuf;
179 : }
180 1670 : delete[] pSortStruct;
181 1670 : };
182 :
183 29146 : void EscherPropertyContainer::AddOpt( sal_uInt16 nPropID, sal_uInt32 nPropValue, bool bBlib )
184 : {
185 29146 : AddOpt( nPropID, bBlib, nPropValue, NULL, 0 );
186 29146 : }
187 :
188 986 : void EscherPropertyContainer::AddOpt( sal_uInt16 nPropID, const OUString& rString )
189 : {
190 986 : sal_Int32 j, i, nLen = rString.getLength() * 2 + 2;
191 986 : sal_uInt8* pBuf = new sal_uInt8[ nLen ];
192 14058 : for ( j = i = 0; i < rString.getLength(); i++ )
193 : {
194 13072 : sal_uInt16 nChar = (sal_uInt16)rString[ i ];
195 13072 : pBuf[ j++ ] = (sal_uInt8)nChar;
196 13072 : pBuf[ j++ ] = (sal_uInt8)( nChar >> 8 );
197 : }
198 986 : pBuf[ j++ ] = 0;
199 986 : pBuf[ j++ ] = 0;
200 986 : AddOpt( nPropID, true, nLen, pBuf, nLen );
201 986 : }
202 :
203 33866 : void EscherPropertyContainer::AddOpt( sal_uInt16 nPropID, bool bBlib, sal_uInt32 nPropValue, sal_uInt8* pProp, sal_uInt32 nPropSize )
204 : {
205 33866 : if ( bBlib ) // bBlib is only valid when fComplex = 0
206 4190 : nPropID |= 0x4000;
207 33866 : if ( pProp )
208 4720 : nPropID |= 0x8000; // fComplex = sal_True;
209 :
210 : sal_uInt32 i;
211 379824 : for( i = 0; i < nSortCount; i++ )
212 : {
213 346918 : if ( ( pSortStruct[ i ].nPropId &~0xc000 ) == ( nPropID &~0xc000 ) ) // check, whether the Property only gets replaced
214 : {
215 960 : pSortStruct[ i ].nPropId = nPropID;
216 960 : if ( pSortStruct[ i ].pBuf )
217 : {
218 0 : nCountSize -= pSortStruct[ i ].nPropSize;
219 0 : delete[] pSortStruct[ i ].pBuf;
220 : }
221 960 : pSortStruct[ i ].pBuf = pProp;
222 960 : pSortStruct[ i ].nPropSize = nPropSize;
223 960 : pSortStruct[ i ].nPropValue = nPropValue;
224 960 : if ( pProp )
225 0 : nCountSize += nPropSize;
226 34826 : return;
227 : }
228 : }
229 32906 : nCountCount++;
230 32906 : nCountSize += 6;
231 32906 : if ( nSortCount == nSortBufSize ) // increase buffer
232 : {
233 0 : nSortBufSize <<= 1;
234 0 : EscherPropSortStruct* pTemp = new EscherPropSortStruct[ nSortBufSize ];
235 0 : for( i = 0; i < nSortCount; i++ )
236 : {
237 0 : pTemp[ i ] = pSortStruct[ i ];
238 : }
239 0 : delete[] pSortStruct;
240 0 : pSortStruct = pTemp;
241 : }
242 32906 : pSortStruct[ nSortCount ].nPropId = nPropID; // insert property
243 32906 : pSortStruct[ nSortCount ].pBuf = pProp;
244 32906 : pSortStruct[ nSortCount ].nPropSize = nPropSize;
245 32906 : pSortStruct[ nSortCount++ ].nPropValue = nPropValue;
246 :
247 32906 : if ( pProp )
248 : {
249 4720 : nCountSize += nPropSize;
250 4720 : bHasComplexData = true;
251 : }
252 : }
253 :
254 32256 : bool EscherPropertyContainer::GetOpt( sal_uInt16 nPropId, sal_uInt32& rPropValue ) const
255 : {
256 : EscherPropSortStruct aPropStruct;
257 :
258 32256 : if ( GetOpt( nPropId, aPropStruct ) )
259 : {
260 13824 : rPropValue = aPropStruct.nPropValue;
261 13824 : return true;
262 : }
263 18432 : return false;
264 : }
265 :
266 35244 : bool EscherPropertyContainer::GetOpt( sal_uInt16 nPropId, EscherPropSortStruct& rPropValue ) const
267 : {
268 538988 : for( sal_uInt32 i = 0; i < nSortCount; i++ )
269 : {
270 519506 : if ( ( pSortStruct[ i ].nPropId &~0xc000 ) == ( nPropId &~0xc000 ) )
271 : {
272 15762 : rPropValue = pSortStruct[ i ];
273 15762 : return true;
274 : }
275 : }
276 19482 : return false;
277 : }
278 :
279 1386 : EscherProperties EscherPropertyContainer::GetOpts() const
280 : {
281 1386 : EscherProperties aVector;
282 :
283 27148 : for ( sal_uInt32 i = 0; i < nSortCount; ++i )
284 25762 : aVector.push_back( pSortStruct[ i ] );
285 :
286 1386 : return aVector;
287 : }
288 :
289 1726 : extern "C" int SAL_CALL EscherPropSortFunc( const void* p1, const void* p2 )
290 : {
291 1726 : sal_Int16 nID1 = ((EscherPropSortStruct*)p1)->nPropId &~0xc000;
292 1726 : sal_Int16 nID2 = ((EscherPropSortStruct*)p2)->nPropId &~0xc000;
293 :
294 1726 : if( nID1 < nID2 )
295 1074 : return -1;
296 652 : else if( nID1 > nID2 )
297 652 : return 1;
298 : else
299 0 : return 0;
300 : }
301 :
302 62 : void EscherPropertyContainer::Commit( SvStream& rSt, sal_uInt16 nVersion, sal_uInt16 nRecType )
303 : {
304 62 : rSt.WriteUInt16( ( ( nCountCount << 4 ) | ( nVersion & 0xf ) ) ).WriteUInt16( nRecType ).WriteUInt32( nCountSize );
305 62 : if ( nSortCount )
306 : {
307 62 : qsort( pSortStruct, nSortCount, sizeof( EscherPropSortStruct ), EscherPropSortFunc );
308 : sal_uInt32 i;
309 :
310 798 : for ( i = 0; i < nSortCount; i++ )
311 : {
312 736 : sal_uInt32 nPropValue = pSortStruct[ i ].nPropValue;
313 736 : sal_uInt16 nPropId = pSortStruct[ i ].nPropId;
314 :
315 736 : rSt.WriteUInt16( nPropId )
316 736 : .WriteUInt32( nPropValue );
317 : }
318 62 : if ( bHasComplexData )
319 : {
320 120 : for ( i = 0; i < nSortCount; i++ )
321 : {
322 112 : if ( pSortStruct[ i ].pBuf )
323 8 : rSt.Write( pSortStruct[ i ].pBuf, pSortStruct[ i ].nPropSize );
324 : }
325 : }
326 : }
327 62 : }
328 :
329 296 : bool EscherPropertyContainer::IsFontWork() const
330 : {
331 296 : sal_uInt32 nTextPathFlags = 0;
332 296 : GetOpt( DFF_Prop_gtextFStrikethrough, nTextPathFlags );
333 296 : return ( nTextPathFlags & 0x4000 ) != 0;
334 : }
335 :
336 2728 : sal_uInt32 EscherPropertyContainer::ImplGetColor( const sal_uInt32 nSOColor, bool bSwap )
337 : {
338 2728 : if ( bSwap )
339 : {
340 2700 : sal_uInt32 nColor = nSOColor & 0xff00; // green
341 2700 : nColor |= (sal_uInt8)( nSOColor ) << 16; // red
342 2700 : nColor |= (sal_uInt8)( nSOColor >> 16 ); // blue
343 2700 : return nColor;
344 : }
345 : else
346 28 : return nSOColor & 0xffffff;
347 : }
348 :
349 224 : sal_uInt32 EscherPropertyContainer::GetGradientColor(
350 : const ::com::sun::star::awt::Gradient* pGradient,
351 : sal_uInt32 nStartColor )
352 : {
353 224 : sal_uInt32 nIntensity = 100;
354 224 : Color aColor;
355 :
356 224 : if ( pGradient )
357 : {
358 224 : if ( nStartColor & 1 )
359 : {
360 112 : nIntensity = pGradient->StartIntensity;
361 112 : aColor = pGradient->StartColor;
362 : }
363 : else
364 : {
365 112 : nIntensity = pGradient->EndIntensity;
366 112 : aColor = pGradient->EndColor;
367 : }
368 : }
369 224 : sal_uInt32 nRed = ( ( aColor.GetRed() * nIntensity ) / 100 );
370 224 : sal_uInt32 nGreen = ( ( aColor.GetGreen() * nIntensity ) / 100 ) << 8;
371 224 : sal_uInt32 nBlue = ( ( aColor.GetBlue() * nIntensity ) / 100 ) << 16;
372 224 : return nRed | nGreen | nBlue;
373 : }
374 :
375 0 : void EscherPropertyContainer::CreateGradientProperties(
376 : const ::com::sun::star::awt::Gradient & rGradient )
377 : {
378 0 : sal_uInt32 nFillType = ESCHER_FillShadeScale;
379 0 : sal_uInt32 nAngle = 0;
380 0 : sal_uInt32 nFillFocus = 0;
381 0 : sal_uInt32 nFillLR = 0;
382 0 : sal_uInt32 nFillTB = 0;
383 0 : sal_uInt32 nFirstColor = 0;
384 0 : bool bWriteFillTo = false;
385 :
386 0 : switch ( rGradient.Style )
387 : {
388 : case ::com::sun::star::awt::GradientStyle_LINEAR :
389 : case ::com::sun::star::awt::GradientStyle_AXIAL :
390 : {
391 0 : nFillType = ESCHER_FillShadeScale;
392 0 : nAngle = (rGradient.Angle * 0x10000) / 10;
393 0 : nFillFocus = (sal::static_int_cast<int>(rGradient.Style) ==
394 0 : sal::static_int_cast<int>(GradientStyle_LINEAR)) ? 0 : 50;
395 : }
396 0 : break;
397 : case ::com::sun::star::awt::GradientStyle_RADIAL :
398 : case ::com::sun::star::awt::GradientStyle_ELLIPTICAL :
399 : case ::com::sun::star::awt::GradientStyle_SQUARE :
400 : case ::com::sun::star::awt::GradientStyle_RECT :
401 : {
402 0 : nFillLR = (rGradient.XOffset * 0x10000) / 100;
403 0 : nFillTB = (rGradient.YOffset * 0x10000) / 100;
404 0 : if ( ((nFillLR > 0) && (nFillLR < 0x10000)) || ((nFillTB > 0) && (nFillTB < 0x10000)) )
405 0 : nFillType = ESCHER_FillShadeShape;
406 : else
407 0 : nFillType = ESCHER_FillShadeCenter;
408 0 : nFirstColor = 1;
409 0 : bWriteFillTo = true;
410 : }
411 0 : break;
412 0 : case ::com::sun::star::awt::GradientStyle_MAKE_FIXED_SIZE : break;
413 : }
414 0 : AddOpt( ESCHER_Prop_fillType, nFillType );
415 0 : AddOpt( ESCHER_Prop_fillAngle, nAngle );
416 0 : AddOpt( ESCHER_Prop_fillColor, GetGradientColor( &rGradient, nFirstColor ) );
417 0 : AddOpt( ESCHER_Prop_fillBackColor, GetGradientColor( &rGradient, nFirstColor ^ 1 ) );
418 0 : AddOpt( ESCHER_Prop_fillFocus, nFillFocus );
419 0 : if ( bWriteFillTo )
420 : {
421 0 : AddOpt( ESCHER_Prop_fillToLeft, nFillLR );
422 0 : AddOpt( ESCHER_Prop_fillToTop, nFillTB );
423 0 : AddOpt( ESCHER_Prop_fillToRight, nFillLR );
424 0 : AddOpt( ESCHER_Prop_fillToBottom, nFillTB );
425 : }
426 0 : }
427 :
428 112 : void EscherPropertyContainer::CreateGradientProperties(
429 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet , bool bTransparentGradient)
430 : {
431 112 : ::com::sun::star::uno::Any aAny;
432 112 : ::com::sun::star::awt::Gradient* pGradient = NULL;
433 :
434 112 : sal_uInt32 nFillType = ESCHER_FillShadeScale;
435 112 : sal_Int32 nAngle = 0;
436 112 : sal_uInt32 nFillFocus = 0;
437 112 : sal_uInt32 nFillLR = 0;
438 112 : sal_uInt32 nFillTB = 0;
439 112 : sal_uInt32 nFirstColor = 0;// like the control var nChgColors in import logic
440 112 : bool bWriteFillTo = false;
441 :
442 : // Transparency gradient: Means the third setting in transparency page is set
443 336 : if (bTransparentGradient && EscherPropertyValueHelper::GetPropertyValue(
444 112 : aAny, rXPropSet, OUString( "FillTransparenceGradient" ), false ) )
445 : {
446 0 : pGradient = (::com::sun::star::awt::Gradient*)aAny.getValue();
447 :
448 0 : ::com::sun::star::uno::Any aAnyTemp;
449 0 : const rtl::OUString aPropName( "FillStyle" );
450 0 : if ( EscherPropertyValueHelper::GetPropertyValue(
451 : aAnyTemp, rXPropSet, aPropName, false ) )
452 : {
453 : ::com::sun::star::drawing::FillStyle eFS;
454 0 : if ( ! ( aAnyTemp >>= eFS ) )
455 0 : eFS = ::com::sun::star::drawing::FillStyle_SOLID;
456 : // solid and transparency
457 0 : if ( eFS == ::com::sun::star::drawing::FillStyle_SOLID)
458 : {
459 0 : if ( EscherPropertyValueHelper::GetPropertyValue(
460 0 : aAnyTemp, rXPropSet, OUString( "FillColor" ), false ) )
461 : {
462 0 : pGradient->StartColor = ImplGetColor( *((sal_uInt32*)aAnyTemp.getValue()), false );
463 0 : pGradient->EndColor = ImplGetColor( *((sal_uInt32*)aAnyTemp.getValue()), false );
464 : }
465 : }
466 : // gradient and transparency.
467 0 : else if( eFS == ::com::sun::star::drawing::FillStyle_GRADIENT )
468 : {
469 0 : if ( EscherPropertyValueHelper::GetPropertyValue(
470 0 : aAny, rXPropSet, OUString( "FillGradient" ), false ) )
471 0 : pGradient = (::com::sun::star::awt::Gradient*)aAny.getValue();
472 : }
473 0 : }
474 :
475 : }
476 : // Not transparency gradient
477 224 : else if ( EscherPropertyValueHelper::GetPropertyValue(
478 224 : aAny, rXPropSet, OUString( "FillGradient" ), false ) )
479 : {
480 112 : pGradient = (::com::sun::star::awt::Gradient*)aAny.getValue();
481 : }
482 :
483 112 : if ( pGradient )
484 : {
485 112 : switch ( pGradient->Style )
486 : {
487 : case ::com::sun::star::awt::GradientStyle_LINEAR :
488 : case ::com::sun::star::awt::GradientStyle_AXIAL :
489 : {
490 110 : nFillType = ESCHER_FillShadeScale;
491 110 : nAngle = pGradient->Angle;
492 110 : while ( nAngle > 0 ) nAngle -= 3600;
493 110 : while ( nAngle <= -3600 ) nAngle += 3600;
494 : // Value of the real number = Integral + (Fractional / 65536.0)
495 110 : nAngle = ( nAngle * 0x10000) / 10;
496 :
497 110 : nFillFocus = (pGradient->Style == ::com::sun::star::awt::GradientStyle_LINEAR) ?
498 110 : ( pGradient->XOffset + pGradient->YOffset )/2 : -50;
499 110 : if( !nFillFocus )
500 104 : nFirstColor=nFirstColor ^ 1;
501 110 : if ( !nAngle )
502 6 : nFirstColor=nFirstColor ^ 1;
503 : }
504 110 : break;
505 : case ::com::sun::star::awt::GradientStyle_RADIAL :
506 : case ::com::sun::star::awt::GradientStyle_ELLIPTICAL :
507 : case ::com::sun::star::awt::GradientStyle_SQUARE :
508 : case ::com::sun::star::awt::GradientStyle_RECT :
509 : {
510 : // according to the import logic and rect type fill** value
511 2 : nFillLR = (pGradient->XOffset * 0x10000) / 100;
512 2 : nFillTB = (pGradient->YOffset * 0x10000) / 100;
513 2 : if ( ((nFillLR > 0) && (nFillLR < 0x10000)) || ((nFillTB > 0) && (nFillTB < 0x10000)) )
514 2 : nFillType = ESCHER_FillShadeShape;
515 : else
516 0 : nFillType = ESCHER_FillShadeCenter;
517 2 : nFirstColor = 1;
518 2 : bWriteFillTo = true;
519 : }
520 2 : break;
521 0 : default: break;
522 : }
523 : }
524 :
525 112 : AddOpt( ESCHER_Prop_fillType, nFillType );
526 112 : AddOpt( ESCHER_Prop_fillAngle, nAngle );
527 112 : AddOpt( ESCHER_Prop_fillColor, GetGradientColor( pGradient, nFirstColor ) );
528 112 : AddOpt( ESCHER_Prop_fillBackColor, GetGradientColor( pGradient, nFirstColor ^ 1 ) );
529 112 : AddOpt( ESCHER_Prop_fillFocus, nFillFocus );
530 112 : if ( bWriteFillTo )
531 : {
532 : // according to rect type fillTo** value
533 2 : if(nFillLR)
534 : {
535 2 : AddOpt( ESCHER_Prop_fillToLeft, nFillLR );
536 2 : AddOpt( ESCHER_Prop_fillToRight, nFillLR );
537 : }
538 2 : if(nFillTB)
539 : {
540 2 : AddOpt( ESCHER_Prop_fillToTop, nFillTB );
541 2 : AddOpt( ESCHER_Prop_fillToBottom, nFillTB );
542 : }
543 : }
544 :
545 : // Transparency gradient
546 336 : if (bTransparentGradient && EscherPropertyValueHelper::GetPropertyValue(
547 112 : aAny, rXPropSet, OUString( "FillTransparenceGradient" ), false ) )
548 : {
549 0 : pGradient = (::com::sun::star::awt::Gradient*)aAny.getValue();
550 0 : if ( pGradient )
551 : {
552 0 : sal_uInt32 nBlue = GetGradientColor( pGradient, nFirstColor ) >> 16;
553 0 : AddOpt( ESCHER_Prop_fillOpacity,( ( 100 - ( nBlue * 100 / 255 ) ) << 16 ) / 100 );
554 0 : nBlue = GetGradientColor( pGradient, nFirstColor ^ 1 ) >>16 ;
555 0 : AddOpt( ESCHER_Prop_fillBackOpacity,( ( 100 - ( nBlue * 100 / 255 ) ) << 16 )/ 100 );
556 : }
557 112 : }
558 112 : }
559 :
560 0 : void EscherPropertyContainer::CreateFillProperties(
561 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet,
562 : bool bEdge , const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rXShape )
563 : {
564 0 : if ( rXShape.is() )
565 : {
566 0 : SdrObject* pObj = GetSdrObjectFromXShape( rXShape );
567 0 : if ( pObj )
568 : {
569 0 : SfxItemSet aAttr( pObj->GetMergedItemSet() );
570 : // tranparency with gradient. Means the third setting in transparency page is set
571 0 : bool bTransparentGradient = ( aAttr.GetItemState( XATTR_FILLFLOATTRANSPARENCE ) == SfxItemState::SET ) &&
572 0 : static_cast<const XFillFloatTransparenceItem&>( aAttr.Get( XATTR_FILLFLOATTRANSPARENCE ) ).IsEnabled();
573 0 : CreateFillProperties( rXPropSet, bEdge, bTransparentGradient );
574 : }
575 : }
576 0 : }
577 :
578 1540 : void EscherPropertyContainer::CreateFillProperties(
579 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet,
580 : bool bEdge , bool bTransparentGradient)
581 :
582 : {
583 1540 : ::com::sun::star::uno::Any aAny;
584 1540 : AddOpt( ESCHER_Prop_WrapText, ESCHER_WrapNone );
585 1540 : AddOpt( ESCHER_Prop_AnchorText, ESCHER_AnchorMiddle );
586 3080 : const OUString aPropName( "FillStyle" );
587 :
588 1540 : if ( EscherPropertyValueHelper::GetPropertyValue(
589 : aAny, rXPropSet, aPropName, false ) )
590 : {
591 : ::com::sun::star::drawing::FillStyle eFS;
592 1540 : if ( ! ( aAny >>= eFS ) )
593 0 : eFS = ::com::sun::star::drawing::FillStyle_SOLID;
594 1540 : sal_uInt32 nFillBackColor = 0;
595 1540 : switch( eFS )
596 : {
597 : case ::com::sun::star::drawing::FillStyle_GRADIENT :
598 : {
599 112 : CreateGradientProperties( rXPropSet , bTransparentGradient );
600 112 : AddOpt( ESCHER_Prop_fNoFillHitTest, 0x140014 );
601 : }
602 112 : break;
603 :
604 : case ::com::sun::star::drawing::FillStyle_BITMAP :
605 : {
606 6 : CreateGraphicProperties( rXPropSet, OUString( "FillBitmapURL" ), true );
607 6 : AddOpt( ESCHER_Prop_fNoFillHitTest, 0x140014 );
608 6 : AddOpt( ESCHER_Prop_fillBackColor, nFillBackColor );
609 : }
610 6 : break;
611 : case ::com::sun::star::drawing::FillStyle_HATCH :
612 : {
613 28 : CreateGraphicProperties( rXPropSet, OUString( "FillHatch" ), true );
614 : }
615 28 : break;
616 : case ::com::sun::star::drawing::FillStyle_SOLID :
617 : default:
618 : {
619 968 : if ( bTransparentGradient )
620 0 : CreateGradientProperties( rXPropSet , bTransparentGradient );
621 : else
622 : {
623 : ::com::sun::star::beans::PropertyState ePropState = EscherPropertyValueHelper::GetPropertyState(
624 968 : rXPropSet, aPropName );
625 968 : if ( ePropState == ::com::sun::star::beans::PropertyState_DIRECT_VALUE )
626 956 : AddOpt( ESCHER_Prop_fillType, ESCHER_FillSolid );
627 :
628 1936 : if ( EscherPropertyValueHelper::GetPropertyValue(
629 1936 : aAny, rXPropSet, OUString( "FillColor" ), false ) )
630 : {
631 968 : sal_uInt32 nFillColor = ImplGetColor( *((sal_uInt32*)aAny.getValue()) );
632 968 : nFillBackColor = nFillColor ^ 0xffffff;
633 968 : AddOpt( ESCHER_Prop_fillColor, nFillColor );
634 : }
635 968 : AddOpt( ESCHER_Prop_fNoFillHitTest, 0x100010 );
636 968 : AddOpt( ESCHER_Prop_fillBackColor, nFillBackColor );
637 : }
638 968 : break;
639 : }
640 : case ::com::sun::star::drawing::FillStyle_NONE :
641 426 : AddOpt( ESCHER_Prop_fNoFillHitTest, 0x100000 );
642 426 : break;
643 : }
644 1540 : if ( eFS != ::com::sun::star::drawing::FillStyle_NONE )
645 : {
646 : sal_uInt16 nTransparency = ( EscherPropertyValueHelper::GetPropertyValue(
647 2228 : aAny, rXPropSet, OUString( "FillTransparence" ), true ) )
648 1114 : ? *((sal_Int16*)aAny.getValue() ) : 0;
649 1114 : if ( nTransparency )
650 72 : AddOpt( ESCHER_Prop_fillOpacity, ( ( 100 - nTransparency ) << 16 ) / 100 );
651 : }
652 : }
653 3080 : CreateLineProperties( rXPropSet, bEdge );
654 1540 : }
655 :
656 458 : void EscherPropertyContainer::CreateTextProperties(
657 : const uno::Reference< beans::XPropertySet > & rXPropSet, sal_uInt32 nTextId,
658 : const bool bIsCustomShape, const bool bIsTextFrame )
659 : {
660 458 : uno::Any aAny;
661 458 : text::WritingMode eWM( text::WritingMode_LR_TB );
662 458 : drawing::TextVerticalAdjust eVA( drawing::TextVerticalAdjust_TOP );
663 458 : drawing::TextHorizontalAdjust eHA( drawing::TextHorizontalAdjust_LEFT );
664 :
665 458 : sal_Int32 nLeft ( 0 );
666 458 : sal_Int32 nTop ( 0 );
667 458 : sal_Int32 nRight ( 0 );
668 458 : sal_Int32 nBottom ( 0 );
669 :
670 : // used with normal shapes:
671 458 : bool bAutoGrowWidth ( false );
672 458 : const bool bAutoGrowHeight ( false ); //#ii63936 not setting autogrowheight, because minframeheight would be ignored
673 : // used with ashapes:
674 458 : bool bWordWrap ( false );
675 458 : bool bAutoGrowSize ( false );
676 :
677 458 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "TextWritingMode" ), true ) )
678 458 : aAny >>= eWM;
679 458 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "TextVerticalAdjust" ), true ) )
680 458 : aAny >>= eVA;
681 458 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "TextHorizontalAdjust" ), true ) )
682 458 : aAny >>= eHA;
683 458 : if ( bIsCustomShape )
684 : {
685 262 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "TextWordWrap" ), false ) )
686 262 : aAny >>= bWordWrap;
687 262 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "TextAutoGrowHeight" ), true ) )
688 262 : aAny >>= bAutoGrowSize;
689 : }
690 196 : else if ( bIsTextFrame )
691 : {
692 194 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "TextAutoGrowWidth" ), true ) )
693 194 : aAny >>= bAutoGrowWidth;
694 :
695 : // i63936 not setting autogrowheight, because otherwise
696 : // the minframeheight of the text will be ignored
697 : //
698 : // if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, "TextAutoGrowHeight", sal_True ) )
699 : // aAny >>= bAutoGrowHeight;
700 : }
701 458 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "TextLeftDistance" ) ) )
702 458 : aAny >>= nLeft;
703 458 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "TextUpperDistance" ) ) )
704 458 : aAny >>= nTop;
705 458 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "TextRightDistance" ) ) )
706 458 : aAny >>= nRight;
707 458 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "TextLowerDistance" ) ) )
708 458 : aAny >>= nBottom;
709 :
710 458 : ESCHER_AnchorText eAnchor = ESCHER_AnchorTop;
711 458 : ESCHER_WrapMode eWrapMode = ESCHER_WrapSquare;
712 458 : sal_uInt32 nTextAttr = 0x40004; // rotate text with shape
713 :
714 458 : if ( eWM == text::WritingMode_TB_RL )
715 : { // vertical writing
716 0 : switch ( eHA )
717 : {
718 : case drawing::TextHorizontalAdjust_LEFT :
719 0 : eAnchor = ESCHER_AnchorBottom;
720 0 : break;
721 : case drawing::TextHorizontalAdjust_CENTER :
722 0 : eAnchor = ESCHER_AnchorMiddle;
723 0 : break;
724 : default :
725 : case drawing::TextHorizontalAdjust_BLOCK :
726 : case drawing::TextHorizontalAdjust_RIGHT :
727 0 : eAnchor = ESCHER_AnchorTop;
728 0 : break;
729 : }
730 0 : if ( eVA == drawing::TextVerticalAdjust_CENTER )
731 : {
732 0 : switch ( eAnchor )
733 : {
734 : case ESCHER_AnchorMiddle :
735 0 : eAnchor = ESCHER_AnchorMiddleCentered;
736 0 : break;
737 : case ESCHER_AnchorBottom :
738 0 : eAnchor = ESCHER_AnchorBottomCentered;
739 0 : break;
740 : default :
741 : case ESCHER_AnchorTop :
742 0 : eAnchor = ESCHER_AnchorTopCentered;
743 0 : break;
744 : }
745 : }
746 0 : if ( bIsCustomShape )
747 : {
748 0 : if ( bWordWrap )
749 0 : eWrapMode = ESCHER_WrapSquare;
750 : else
751 0 : eWrapMode = ESCHER_WrapNone;
752 0 : if ( bAutoGrowSize )
753 0 : nTextAttr |= 0x20002;
754 : }
755 : else
756 : {
757 : if ( bAutoGrowHeight )
758 : eWrapMode = ESCHER_WrapNone;
759 0 : if ( bAutoGrowWidth )
760 0 : nTextAttr |= 0x20002;
761 : }
762 :
763 0 : AddOpt( ESCHER_Prop_txflTextFlow, ESCHER_txflTtoBA ); // rotate text within shape by 90
764 : }
765 : else
766 : { // normal from left to right
767 458 : switch ( eVA )
768 : {
769 : case drawing::TextVerticalAdjust_CENTER :
770 170 : eAnchor = ESCHER_AnchorMiddle;
771 170 : break;
772 :
773 : case drawing::TextVerticalAdjust_BOTTOM :
774 12 : eAnchor = ESCHER_AnchorBottom;
775 12 : break;
776 :
777 : default :
778 : case drawing::TextVerticalAdjust_TOP :
779 276 : eAnchor = ESCHER_AnchorTop;
780 276 : break;
781 : }
782 458 : if ( eHA == drawing::TextHorizontalAdjust_CENTER )
783 : {
784 2 : switch( eAnchor )
785 : {
786 : case ESCHER_AnchorMiddle :
787 2 : eAnchor = ESCHER_AnchorMiddleCentered;
788 2 : break;
789 : case ESCHER_AnchorBottom :
790 0 : eAnchor = ESCHER_AnchorBottomCentered;
791 0 : break;
792 : case ESCHER_AnchorTop :
793 0 : eAnchor = ESCHER_AnchorTopCentered;
794 0 : break;
795 0 : default: break;
796 : }
797 : }
798 458 : if ( bIsCustomShape )
799 : {
800 262 : if ( bWordWrap )
801 222 : eWrapMode = ESCHER_WrapSquare;
802 : else
803 40 : eWrapMode = ESCHER_WrapNone;
804 262 : if ( bAutoGrowSize )
805 24 : nTextAttr |= 0x20002;
806 : }
807 : else
808 : {
809 196 : if ( bAutoGrowWidth )
810 8 : eWrapMode = ESCHER_WrapNone;
811 : if ( bAutoGrowHeight )
812 : nTextAttr |= 0x20002;
813 : }
814 : }
815 458 : AddOpt( ESCHER_Prop_dxTextLeft, nLeft * 360 );
816 458 : AddOpt( ESCHER_Prop_dxTextRight, nRight * 360 );
817 458 : AddOpt( ESCHER_Prop_dyTextTop, nTop * 360 );
818 458 : AddOpt( ESCHER_Prop_dyTextBottom, nBottom * 360 );
819 :
820 458 : AddOpt( ESCHER_Prop_WrapText, eWrapMode );
821 458 : AddOpt( ESCHER_Prop_AnchorText, eAnchor );
822 458 : AddOpt( ESCHER_Prop_FitTextToShape, nTextAttr );
823 :
824 458 : if ( nTextId )
825 0 : AddOpt( ESCHER_Prop_lTxid, nTextId );
826 :
827 : // n#404221: In case of rotation we need to write the txtflTextFlow
828 : // attribute too.
829 : // fdo#58204: not custom shapes (TODO: other cases when it doesn't work?)
830 458 : if (bIsTextFrame && !bIsCustomShape)
831 : {
832 : sal_uInt16 nAngle = EscherPropertyValueHelper::GetPropertyValue(
833 388 : aAny, rXPropSet, OUString( "RotateAngle" ), true ) ?
834 194 : (sal_uInt16)( ( *((sal_Int32*)aAny.getValue() ) ) + 5 ) / 10 : 0;
835 194 : if (nAngle==900)
836 : {
837 0 : AddOpt( ESCHER_Prop_txflTextFlow, ESCHER_txflBtoT );
838 : }
839 194 : if (nAngle==2700)
840 : {
841 12 : AddOpt( ESCHER_Prop_txflTextFlow, ESCHER_txflTtoBA );
842 : }
843 458 : }
844 458 : }
845 :
846 5580 : bool EscherPropertyContainer::GetLineArrow( const bool bLineStart,
847 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet,
848 : ESCHER_LineEnd& reLineEnd, sal_Int32& rnArrowLength, sal_Int32& rnArrowWidth )
849 : {
850 5580 : static OUString sLineStart ( "LineStart" );
851 5580 : static OUString sLineStartName( "LineStartName" );
852 5580 : static OUString sLineEnd ( "LineEnd" );
853 5580 : static OUString sLineEndName ( "LineEndName" );
854 :
855 5580 : const OUString sLine ( bLineStart ? sLineStart : sLineEnd );
856 11160 : const OUString sLineName ( bLineStart ? sLineStartName : sLineEndName );
857 :
858 5580 : bool bIsArrow = false;
859 :
860 11160 : ::com::sun::star::uno::Any aAny;
861 5580 : if ( EscherPropertyValueHelper::GetPropertyValue(
862 : aAny, rXPropSet, sLine, false ) )
863 : {
864 4772 : tools::PolyPolygon aPolyPoly( EscherPropertyContainer::GetPolyPolygon( aAny ) );
865 4772 : if ( aPolyPoly.Count() && aPolyPoly[ 0 ].GetSize() )
866 : {
867 150 : bIsArrow = true;
868 :
869 150 : reLineEnd = ESCHER_LineArrowEnd;
870 150 : rnArrowLength = 1;
871 150 : rnArrowWidth = 1;
872 :
873 150 : if ( EscherPropertyValueHelper::GetPropertyValue(
874 : aAny, rXPropSet, sLineName, false ) )
875 : {
876 150 : OUString aArrowStartName = *(OUString*)aAny.getValue();
877 150 : sal_Int16 nWhich = bLineStart ? XATTR_LINESTART : XATTR_LINEEND;
878 :
879 300 : OUString aApiName = SvxUnogetApiNameForItem(nWhich, aArrowStartName);
880 150 : bool bIsMapped = true;
881 150 : if ( !aApiName.isEmpty() )
882 : {
883 :
884 : // TODO: calculate the best option for ArrowLength and ArrowWidth
885 150 : if ( aApiName == "Arrow concave" )
886 0 : reLineEnd = ESCHER_LineArrowStealthEnd;
887 150 : else if ( aApiName == "Square 45" )
888 0 : reLineEnd = ESCHER_LineArrowDiamondEnd;
889 150 : else if ( aApiName == "Small Arrow" )
890 0 : reLineEnd = ESCHER_LineArrowEnd;
891 150 : else if ( aApiName == "Dimension Lines" )
892 : {
893 0 : rnArrowLength = 0;
894 0 : rnArrowWidth = 2;
895 0 : reLineEnd = ESCHER_LineArrowOvalEnd;
896 : }
897 150 : else if ( aApiName == "Double Arrow" )
898 0 : reLineEnd = ESCHER_LineArrowEnd;
899 150 : else if ( aApiName == "Rounded short Arrow" )
900 0 : reLineEnd = ESCHER_LineArrowEnd;
901 150 : else if ( aApiName == "Symmetric Arrow" )
902 0 : reLineEnd = ESCHER_LineArrowEnd;
903 150 : else if ( aApiName == "Line Arrow" )
904 0 : reLineEnd = ESCHER_LineArrowOpenEnd;
905 150 : else if ( aApiName == "Rounded large Arrow" )
906 0 : reLineEnd = ESCHER_LineArrowEnd;
907 150 : else if ( aApiName == "Circle" )
908 0 : reLineEnd = ESCHER_LineArrowOvalEnd;
909 150 : else if ( aApiName == "Square" )
910 0 : reLineEnd = ESCHER_LineArrowDiamondEnd;
911 150 : else if ( aApiName == "Arrow" )
912 0 : reLineEnd = ESCHER_LineArrowEnd;
913 : else
914 150 : bIsMapped = false;
915 :
916 : }
917 150 : if ( !bIsMapped && comphelper::string::getTokenCount(aArrowStartName, ' ') == 2 )
918 : {
919 150 : bool b = true;
920 150 : OUString aArrowName( aArrowStartName.getToken( 0, ' ' ) );
921 150 : if ( aArrowName == "msArrowEnd" )
922 84 : reLineEnd = ESCHER_LineArrowEnd;
923 66 : else if ( aArrowName == "msArrowOpenEnd" )
924 12 : reLineEnd = ESCHER_LineArrowOpenEnd;
925 54 : else if ( aArrowName == "msArrowStealthEnd" )
926 40 : reLineEnd = ESCHER_LineArrowStealthEnd;
927 14 : else if ( aArrowName == "msArrowDiamondEnd" )
928 8 : reLineEnd = ESCHER_LineArrowDiamondEnd;
929 6 : else if ( aArrowName == "msArrowOvalEnd" )
930 0 : reLineEnd = ESCHER_LineArrowOvalEnd;
931 : else
932 6 : b = false;
933 :
934 : // now we have the arrow, and try to determine the arrow size;
935 150 : if ( b )
936 : {
937 144 : OUString aArrowSize( aArrowStartName.getToken( 1, ' ' ) );
938 144 : sal_Int32 nArrowSize = aArrowSize.toInt32();
939 144 : rnArrowWidth = ( nArrowSize - 1 ) / 3;
940 144 : rnArrowLength = nArrowSize - ( rnArrowWidth * 3 ) - 1;
941 150 : }
942 150 : }
943 : }
944 4772 : }
945 : }
946 11160 : return bIsArrow;
947 : }
948 :
949 1634 : void EscherPropertyContainer::CreateLineProperties(
950 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet,
951 : bool bEdge )
952 : {
953 1634 : ::com::sun::star::uno::Any aAny;
954 1634 : sal_uInt32 nLineFlags = 0x80008;
955 :
956 : ESCHER_LineEnd eLineEnd;
957 : sal_Int32 nArrowLength;
958 : sal_Int32 nArrowWidth;
959 :
960 1634 : bool bSwapLineEnds = false;
961 1634 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "CircleKind" ), true ) )
962 : {
963 : ::com::sun::star::drawing::CircleKind eCircleKind;
964 0 : if ( aAny >>= eCircleKind )
965 : {
966 0 : if ( eCircleKind == ::com::sun::star::drawing::CircleKind_ARC )
967 0 : bSwapLineEnds = true;
968 : }
969 : }
970 1634 : if ( GetLineArrow( bSwapLineEnds ? sal_False : sal_True, rXPropSet, eLineEnd, nArrowLength, nArrowWidth ) )
971 : {
972 36 : AddOpt( ESCHER_Prop_lineStartArrowLength, nArrowLength );
973 36 : AddOpt( ESCHER_Prop_lineStartArrowWidth, nArrowWidth );
974 36 : AddOpt( ESCHER_Prop_lineStartArrowhead, eLineEnd );
975 36 : nLineFlags |= 0x100010;
976 : }
977 1634 : if ( GetLineArrow( bSwapLineEnds ? sal_True : sal_False, rXPropSet, eLineEnd, nArrowLength, nArrowWidth ) )
978 : {
979 60 : AddOpt( ESCHER_Prop_lineEndArrowLength, nArrowLength );
980 60 : AddOpt( ESCHER_Prop_lineEndArrowWidth, nArrowWidth );
981 60 : AddOpt( ESCHER_Prop_lineEndArrowhead, eLineEnd );
982 60 : nLineFlags |= 0x100010;
983 : }
984 :
985 : // support LineCaps
986 1634 : if(EscherPropertyValueHelper::GetPropertyValue(aAny, rXPropSet, OUString( "LineCap" ), false))
987 : {
988 1634 : ::com::sun::star::drawing::LineCap aLineCap(com::sun::star::drawing::LineCap_BUTT);
989 :
990 1634 : if(aAny >>= aLineCap)
991 : {
992 1634 : switch (aLineCap)
993 : {
994 : default: /* com::sun::star::drawing::LineCap_BUTT */
995 : {
996 1524 : AddOpt(ESCHER_Prop_lineEndCapStyle, ESCHER_LineEndCapFlat);
997 1524 : break;
998 : }
999 : case com::sun::star::drawing::LineCap_ROUND:
1000 : {
1001 0 : AddOpt(ESCHER_Prop_lineEndCapStyle, ESCHER_LineEndCapRound);
1002 0 : break;
1003 : }
1004 : case com::sun::star::drawing::LineCap_SQUARE:
1005 : {
1006 110 : AddOpt(ESCHER_Prop_lineEndCapStyle, ESCHER_LineEndCapSquare);
1007 110 : break;
1008 : }
1009 : }
1010 : }
1011 : }
1012 :
1013 1634 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "LineStyle" ), false ) )
1014 : {
1015 : ::com::sun::star::drawing::LineStyle eLS;
1016 1634 : if ( aAny >>= eLS )
1017 : {
1018 1634 : switch ( eLS )
1019 : {
1020 : case ::com::sun::star::drawing::LineStyle_NONE :
1021 760 : AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x90000 ); // 80000
1022 760 : break;
1023 :
1024 : case ::com::sun::star::drawing::LineStyle_DASH :
1025 : {
1026 68 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "LineDash" ), false ) )
1027 : {
1028 68 : ESCHER_LineDashing eDash = ESCHER_LineSolid;
1029 68 : ::com::sun::star::drawing::LineDash* pLineDash = (::com::sun::star::drawing::LineDash*)aAny.getValue();
1030 68 : sal_Int32 nDistance = pLineDash->Distance << 1;
1031 68 : switch ( pLineDash->Style )
1032 : {
1033 : case ::com::sun::star::drawing::DashStyle_ROUND :
1034 : case ::com::sun::star::drawing::DashStyle_ROUNDRELATIVE :
1035 10 : AddOpt( ESCHER_Prop_lineEndCapStyle, 0 ); // set Style Round
1036 10 : break;
1037 58 : default : break;
1038 : }
1039 68 : if ( ((!(pLineDash->Dots )) || (!(pLineDash->Dashes )) ) || ( pLineDash->DotLen == pLineDash->DashLen ) )
1040 : {
1041 62 : sal_Int32 nLen = pLineDash->DotLen;
1042 62 : if ( pLineDash->Dashes )
1043 42 : nLen = pLineDash->DashLen;
1044 :
1045 62 : if ( nLen >= nDistance )
1046 8 : eDash = ESCHER_LineLongDashGEL;
1047 54 : else if ( pLineDash->Dots )
1048 20 : eDash = ESCHER_LineDotSys;
1049 : else
1050 34 : eDash = ESCHER_LineDashGEL;
1051 : }
1052 : else // X Y
1053 : {
1054 6 : if ( pLineDash->Dots != pLineDash->Dashes )
1055 : {
1056 6 : if ( ( pLineDash->DashLen > nDistance ) || ( pLineDash->DotLen > nDistance ) )
1057 6 : eDash = ESCHER_LineLongDashDotDotGEL;
1058 : else
1059 0 : eDash = ESCHER_LineDashDotDotSys;
1060 : }
1061 : else // X Y Y
1062 : {
1063 0 : if ( ( pLineDash->DashLen > nDistance ) || ( pLineDash->DotLen > nDistance ) )
1064 0 : eDash = ESCHER_LineLongDashDotGEL;
1065 : else
1066 0 : eDash = ESCHER_LineDashDotGEL;
1067 :
1068 : }
1069 : }
1070 68 : AddOpt( ESCHER_Prop_lineDashing, eDash );
1071 : }
1072 : }
1073 : case ::com::sun::star::drawing::LineStyle_SOLID :
1074 : default:
1075 : {
1076 874 : AddOpt( ESCHER_Prop_fNoLineDrawDash, nLineFlags );
1077 : }
1078 874 : break;
1079 : }
1080 : }
1081 1634 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "LineColor" ), false ) )
1082 : {
1083 1634 : sal_uInt32 nLineColor = ImplGetColor( *((sal_uInt32*)aAny.getValue()) );
1084 1634 : AddOpt( ESCHER_Prop_lineColor, nLineColor );
1085 1634 : AddOpt( ESCHER_Prop_lineBackColor, nLineColor ^ 0xffffff );
1086 : }
1087 : }
1088 :
1089 3268 : sal_uInt32 nLineSize = ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "LineWidth" ), false ) )
1090 1634 : ? *((sal_uInt32*)aAny.getValue()) : 0;
1091 1634 : if ( nLineSize > 1 )
1092 644 : AddOpt( ESCHER_Prop_lineWidth, nLineSize * 360 ); // 100TH MM -> PT , 1PT = 12700 EMU
1093 :
1094 1634 : ESCHER_LineJoin eLineJoin = ESCHER_LineJoinMiter;
1095 1634 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "LineJoint" ), true ) )
1096 : {
1097 : ::com::sun::star::drawing::LineJoint eLJ;
1098 1634 : if ( aAny >>= eLJ )
1099 : {
1100 1634 : switch ( eLJ )
1101 : {
1102 : case com::sun::star::drawing::LineJoint_NONE :
1103 : case com::sun::star::drawing::LineJoint_MIDDLE :
1104 : case com::sun::star::drawing::LineJoint_BEVEL :
1105 84 : eLineJoin = ESCHER_LineJoinBevel;
1106 84 : break;
1107 : default:
1108 : case com::sun::star::drawing::LineJoint_MITER :
1109 206 : eLineJoin = ESCHER_LineJoinMiter;
1110 206 : break;
1111 : case com::sun::star::drawing::LineJoint_ROUND :
1112 1344 : eLineJoin = ESCHER_LineJoinRound;
1113 1344 : break;
1114 : }
1115 : }
1116 : }
1117 1634 : AddOpt( ESCHER_Prop_lineJoinStyle, eLineJoin );
1118 :
1119 3268 : if ( EscherPropertyValueHelper::GetPropertyValue(
1120 3268 : aAny, rXPropSet, "LineTransparence", true ) )
1121 : {
1122 1634 : sal_Int16 nTransparency = 0;
1123 1634 : if ( aAny >>= nTransparency )
1124 1634 : AddOpt( ESCHER_Prop_lineOpacity, ( ( 100 - nTransparency ) << 16 ) / 100 );
1125 : }
1126 :
1127 :
1128 1634 : if ( !bEdge )
1129 : {
1130 94 : AddOpt( ESCHER_Prop_fFillOK, 0x1001 );
1131 94 : AddOpt( ESCHER_Prop_fNoFillHitTest, 0x100000 );
1132 1634 : }
1133 1634 : }
1134 :
1135 38 : static Size lcl_SizeToEmu(Size aPrefSize, MapMode aPrefMapMode)
1136 : {
1137 38 : Size aRetSize;
1138 38 : if (aPrefMapMode == MAP_PIXEL)
1139 0 : aRetSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_100TH_MM );
1140 : else
1141 38 : aRetSize = OutputDevice::LogicToLogic( aPrefSize, aPrefMapMode, MAP_100TH_MM );
1142 38 : return aRetSize;
1143 : }
1144 :
1145 8 : void EscherPropertyContainer::ImplCreateGraphicAttributes( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet,
1146 : sal_uInt32 nBlibId, bool bCreateCroppingAttributes )
1147 : {
1148 8 : ::com::sun::star::uno::Any aAny;
1149 :
1150 8 : sal_uInt32 nPicFlags = 0;
1151 8 : ::com::sun::star::drawing::ColorMode eColorMode( ::com::sun::star::drawing::ColorMode_STANDARD );
1152 8 : sal_Int16 nLuminance = 0;
1153 8 : sal_Int32 nContrast = 0;
1154 :
1155 8 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "GraphicColorMode" ) ) )
1156 8 : aAny >>= eColorMode;
1157 8 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "AdjustLuminance" ) ) )
1158 8 : aAny >>= nLuminance;
1159 8 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "AdjustContrast" ) ) )
1160 : {
1161 8 : sal_Int16 nC = sal_Int16();
1162 8 : aAny >>= nC;
1163 8 : nContrast = nC;
1164 : }
1165 :
1166 8 : if ( eColorMode == ::com::sun::star::drawing::ColorMode_WATERMARK )
1167 : {
1168 0 : eColorMode = ::com::sun::star::drawing::ColorMode_STANDARD;
1169 0 : nLuminance += 70;
1170 0 : if ( nLuminance > 100 )
1171 0 : nLuminance = 100;
1172 0 : nContrast -= 70;
1173 0 : if ( nContrast < -100 )
1174 0 : nContrast = -100;
1175 : }
1176 8 : if ( eColorMode == ::com::sun::star::drawing::ColorMode_GREYS )
1177 0 : nPicFlags |= 0x40004;
1178 8 : else if ( eColorMode == ::com::sun::star::drawing::ColorMode_MONO )
1179 0 : nPicFlags |= 0x60006;
1180 :
1181 8 : if ( nContrast )
1182 : {
1183 0 : nContrast += 100;
1184 0 : if ( nContrast == 100)
1185 0 : nContrast = 0x10000;
1186 0 : else if ( nContrast < 100 )
1187 : {
1188 0 : nContrast *= 0x10000;
1189 0 : nContrast /= 100;
1190 : }
1191 0 : else if ( nContrast < 200 )
1192 0 : nContrast = ( 100 * 0x10000 ) / ( 200 - nContrast );
1193 : else
1194 0 : nContrast = 0x7fffffff;
1195 0 : AddOpt( ESCHER_Prop_pictureContrast, nContrast );
1196 : }
1197 8 : if ( nLuminance )
1198 0 : AddOpt( ESCHER_Prop_pictureBrightness, nLuminance * 327 );
1199 8 : if ( nPicFlags )
1200 0 : AddOpt( ESCHER_Prop_pictureActive, nPicFlags );
1201 :
1202 8 : if ( bCreateCroppingAttributes && pGraphicProvider )
1203 : {
1204 8 : Size aPrefSize;
1205 8 : MapMode aPrefMapMode;
1206 8 : if ( pGraphicProvider->GetPrefSize( nBlibId, aPrefSize, aPrefMapMode ) )
1207 : {
1208 8 : Size aCropSize(lcl_SizeToEmu(aPrefSize, aPrefMapMode));
1209 8 : if ( aCropSize.Width() && aCropSize.Height() )
1210 : {
1211 8 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "GraphicCrop" ) ) )
1212 : {
1213 8 : ::com::sun::star::text::GraphicCrop aGraphCrop;
1214 8 : if ( aAny >>= aGraphCrop )
1215 : {
1216 8 : if ( aGraphCrop.Left )
1217 : {
1218 0 : sal_uInt32 nLeft = ( aGraphCrop.Left * 65536 ) / aCropSize.Width();
1219 0 : AddOpt( ESCHER_Prop_cropFromLeft, nLeft );
1220 : }
1221 8 : if ( aGraphCrop.Top )
1222 : {
1223 0 : sal_uInt32 nTop = ( aGraphCrop.Top * 65536 ) / aCropSize.Height();
1224 0 : AddOpt( ESCHER_Prop_cropFromTop, nTop );
1225 : }
1226 8 : if ( aGraphCrop.Right )
1227 : {
1228 0 : sal_uInt32 nRight = ( aGraphCrop.Right * 65536 ) / aCropSize.Width();
1229 0 : AddOpt( ESCHER_Prop_cropFromRight, nRight );
1230 : }
1231 8 : if ( aGraphCrop.Bottom )
1232 : {
1233 0 : sal_uInt32 nBottom = ( aGraphCrop.Bottom * 65536 ) / aCropSize.Height();
1234 0 : AddOpt( ESCHER_Prop_cropFromBottom, nBottom );
1235 : }
1236 : }
1237 : }
1238 : }
1239 8 : }
1240 8 : }
1241 8 : }
1242 :
1243 1628 : bool EscherPropertyContainer::CreateShapeProperties( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rXShape )
1244 : {
1245 1628 : uno::Reference< beans::XPropertySet > aXPropSet( rXShape, uno::UNO_QUERY );
1246 1628 : if ( aXPropSet.is() )
1247 : {
1248 1628 : bool bVal = false;
1249 1628 : ::com::sun::star::uno::Any aAny;
1250 1628 : sal_uInt32 nShapeAttr = 0;
1251 1628 : if (EscherPropertyValueHelper::GetPropertyValue(aAny, aXPropSet, OUString("Visible"), true) && (aAny >>= bVal))
1252 : {
1253 1628 : if ( !bVal )
1254 0 : nShapeAttr |= 0x20002; // set fHidden = true
1255 : }
1256 1628 : if (EscherPropertyValueHelper::GetPropertyValue(aAny, aXPropSet, OUString( "Printable"), true) && (aAny >>= bVal))
1257 : {
1258 1628 : if ( !bVal )
1259 0 : nShapeAttr |= 0x10000; // set fPrint = false;
1260 : }
1261 1628 : if ( nShapeAttr )
1262 0 : AddOpt( ESCHER_Prop_fPrint, nShapeAttr );
1263 : }
1264 1628 : return true;
1265 : }
1266 :
1267 0 : bool EscherPropertyContainer::CreateOLEGraphicProperties(
1268 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rXShape )
1269 : {
1270 0 : bool bRetValue = false;
1271 :
1272 0 : if ( rXShape.is() )
1273 : {
1274 0 : SdrObject* pSdrOLE2( GetSdrObjectFromXShape( rXShape ) ); // SJ: leaving unoapi, because currently there is
1275 0 : if ( pSdrOLE2 && pSdrOLE2->ISA( SdrOle2Obj ) ) // no access to the native graphic object
1276 : {
1277 0 : const Graphic* pGraphic = static_cast<SdrOle2Obj*>(pSdrOLE2)->GetGraphic();
1278 0 : if ( pGraphic )
1279 : {
1280 0 : GraphicObject aGraphicObject( *pGraphic );
1281 0 : bRetValue = CreateGraphicProperties( rXShape,aGraphicObject );
1282 : }
1283 : }
1284 : }
1285 0 : return bRetValue;
1286 : }
1287 :
1288 0 : bool EscherPropertyContainer::CreateGraphicProperties( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rXShape, const GraphicObject& rGraphicObj )
1289 : {
1290 0 : bool bRetValue = false;
1291 0 : OString aUniqueId( rGraphicObj.GetUniqueID() );
1292 0 : if ( !aUniqueId.isEmpty() )
1293 : {
1294 0 : AddOpt( ESCHER_Prop_fillType, ESCHER_FillPicture );
1295 0 : uno::Reference< beans::XPropertySet > aXPropSet( rXShape, uno::UNO_QUERY );
1296 :
1297 0 : if ( pGraphicProvider && pPicOutStrm && pShapeBoundRect && aXPropSet.is() )
1298 : {
1299 0 : ::com::sun::star::uno::Any aAny;
1300 0 : boost::scoped_ptr< ::com::sun::star::awt::Rectangle> pVisArea;
1301 0 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, OUString("VisibleArea" ) ) )
1302 : {
1303 0 : pVisArea.reset(new ::com::sun::star::awt::Rectangle);
1304 0 : aAny >>= (*pVisArea);
1305 : }
1306 0 : Rectangle aRect( Point( 0, 0 ), pShapeBoundRect->GetSize() );
1307 0 : sal_uInt32 nBlibId = pGraphicProvider->GetBlibID( *pPicOutStrm, aUniqueId, aRect, pVisArea.get(), NULL );
1308 0 : if ( nBlibId )
1309 : {
1310 0 : AddOpt( ESCHER_Prop_pib, nBlibId, true );
1311 0 : ImplCreateGraphicAttributes( aXPropSet, nBlibId, false );
1312 0 : bRetValue = true;
1313 0 : }
1314 0 : }
1315 : }
1316 0 : return bRetValue;
1317 : }
1318 :
1319 0 : bool EscherPropertyContainer::CreateMediaGraphicProperties(
1320 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rXShape )
1321 : {
1322 0 : bool bRetValue = false;
1323 0 : if ( rXShape.is() )
1324 : {
1325 0 : SdrObject* pSdrMedia( GetSdrObjectFromXShape( rXShape ) ); // SJ: leaving unoapi, because currently there is
1326 0 : if ( pSdrMedia && pSdrMedia->ISA( SdrMediaObj ) ) // no access to the native graphic object
1327 : {
1328 0 : GraphicObject aGraphicObject( static_cast<SdrMediaObj*>(pSdrMedia)->getSnapshot() );
1329 0 : bRetValue = CreateGraphicProperties( rXShape, aGraphicObject );
1330 : }
1331 : }
1332 0 : return bRetValue;
1333 : }
1334 :
1335 0 : bool EscherPropertyContainer::ImplCreateEmbeddedBmp( const OString& rUniqueId )
1336 : {
1337 0 : if( !rUniqueId.isEmpty() )
1338 : {
1339 0 : EscherGraphicProvider aProvider;
1340 0 : SvMemoryStream aMemStrm;
1341 0 : Rectangle aRect;
1342 0 : if ( aProvider.GetBlibID( aMemStrm, rUniqueId, aRect ) )
1343 : {
1344 : // grab BLIP from stream and insert directly as complex property
1345 : // ownership of stream memory goes to complex property
1346 0 : aMemStrm.ObjectOwnsMemory( false );
1347 0 : sal_uInt8* pBuf = (sal_uInt8*) aMemStrm.GetData();
1348 0 : sal_uInt32 nSize = aMemStrm.Seek( STREAM_SEEK_TO_END );
1349 0 : AddOpt( ESCHER_Prop_fillBlip, true, nSize, pBuf, nSize );
1350 0 : return true;
1351 0 : }
1352 : }
1353 0 : return false;
1354 : }
1355 :
1356 0 : bool EscherPropertyContainer::CreateEmbeddedBitmapProperties(
1357 : const OUString& rBitmapUrl, ::com::sun::star::drawing::BitmapMode eBitmapMode )
1358 : {
1359 0 : bool bRetValue = false;
1360 0 : OUString aVndUrl( "vnd.sun.star.GraphicObject:" );
1361 0 : OUString aBmpUrl( rBitmapUrl );
1362 0 : sal_Int32 nIndex = aBmpUrl.indexOf( aVndUrl, 0 );
1363 0 : if( nIndex != -1 )
1364 : {
1365 0 : nIndex += aVndUrl.getLength();
1366 0 : if( aBmpUrl.getLength() > nIndex )
1367 : {
1368 0 : OString aUniqueId(OUStringToOString(aBmpUrl.copy(nIndex, aBmpUrl.getLength() - nIndex), RTL_TEXTENCODING_UTF8));
1369 0 : bRetValue = ImplCreateEmbeddedBmp( aUniqueId );
1370 0 : if( bRetValue )
1371 : {
1372 : // bitmap mode property
1373 0 : bool bRepeat = eBitmapMode == ::com::sun::star::drawing::BitmapMode_REPEAT;
1374 0 : AddOpt( ESCHER_Prop_fillType, bRepeat ? ESCHER_FillTexture : ESCHER_FillPicture );
1375 0 : }
1376 : }
1377 : }
1378 0 : return bRetValue;
1379 : }
1380 :
1381 :
1382 : namespace {
1383 :
1384 28 : GraphicObject lclDrawHatch( const ::com::sun::star::drawing::Hatch& rHatch, const Color& rBackColor, bool bFillBackground, const Rectangle& rRect )
1385 : {
1386 : // #i121183# For hatch, do no longer create a bitmap with the fixed size of 28x28 pixels. Also
1387 : // do not create a bitmap in page size, that would explode file sizes (and have no good quality).
1388 : // Better use a MetaFile graphic in page size; thus we have good quality due to vector format and
1389 : // no bit file sizes.
1390 28 : VirtualDevice aOut;
1391 56 : GDIMetaFile aMtf;
1392 :
1393 28 : aOut.SetOutputSizePixel(Size(2, 2));
1394 28 : aOut.EnableOutput(false);
1395 28 : aOut.SetMapMode(MapMode(MAP_100TH_MM));
1396 28 : aMtf.Clear();
1397 28 : aMtf.Record(&aOut);
1398 28 : aOut.SetLineColor();
1399 28 : aOut.SetFillColor(bFillBackground ? rBackColor : Color(COL_TRANSPARENT));
1400 28 : aOut.DrawRect(rRect);
1401 28 : aOut.DrawHatch(tools::PolyPolygon(rRect), Hatch((HatchStyle)rHatch.Style, Color(rHatch.Color), rHatch.Distance, (sal_uInt16)rHatch.Angle));
1402 28 : aMtf.Stop();
1403 28 : aMtf.WindStart();
1404 28 : aMtf.SetPrefMapMode(MapMode(MAP_100TH_MM));
1405 28 : aMtf.SetPrefSize(rRect.GetSize());
1406 :
1407 56 : return GraphicObject(Graphic(aMtf));
1408 : }
1409 :
1410 : } // namespace
1411 :
1412 :
1413 0 : bool EscherPropertyContainer::CreateEmbeddedHatchProperties( const ::com::sun::star::drawing::Hatch& rHatch, const Color& rBackColor, bool bFillBackground )
1414 : {
1415 0 : const Rectangle aRect(pShapeBoundRect ? *pShapeBoundRect : Rectangle(Point(0,0), Size(28000, 21000)));
1416 0 : GraphicObject aGraphicObject = lclDrawHatch( rHatch, rBackColor, bFillBackground, aRect );
1417 0 : OString aUniqueId = aGraphicObject.GetUniqueID();
1418 0 : bool bRetValue = ImplCreateEmbeddedBmp( aUniqueId );
1419 0 : if ( bRetValue )
1420 0 : AddOpt( ESCHER_Prop_fillType, ESCHER_FillTexture );
1421 0 : return bRetValue;
1422 : }
1423 :
1424 :
1425 126 : bool EscherPropertyContainer::CreateGraphicProperties(
1426 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet,
1427 : const OUString& rSource, const bool bCreateFillBitmap, const bool bCreateCroppingAttributes,
1428 : const bool bFillBitmapModeAllowed, const bool bOOxmlExport )
1429 : {
1430 126 : bool bRetValue = false;
1431 126 : bool bCreateFillStyles = false;
1432 :
1433 126 : bool bMirrored = false;
1434 126 : bool bRotate = true;
1435 126 : boost::scoped_ptr<GraphicAttr> pGraphicAttr;
1436 252 : GraphicObject aGraphicObject;
1437 252 : OUString aGraphicUrl;
1438 252 : OString aUniqueId;
1439 126 : bool bIsGraphicMtf(false);
1440 : // #121074#
1441 126 : sal_Int16 nTransparency(0);
1442 126 : sal_Int16 nRed(0);
1443 126 : sal_Int16 nGreen(0);
1444 126 : sal_Int16 nBlue(0);
1445 126 : double fGamma(1.0);
1446 :
1447 126 : ::com::sun::star::drawing::BitmapMode eBitmapMode( ::com::sun::star::drawing::BitmapMode_NO_REPEAT );
1448 252 : ::com::sun::star::uno::Any aAny;
1449 :
1450 126 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, rSource ) )
1451 : {
1452 126 : sal_uInt16 nAngle = 0;
1453 126 : if ( rSource == "MetaFile" )
1454 : {
1455 0 : ::com::sun::star::uno::Sequence<sal_uInt8> aSeq = *(::com::sun::star::uno::Sequence<sal_uInt8>*)aAny.getValue();
1456 0 : const sal_uInt8* pAry = aSeq.getArray();
1457 0 : sal_uInt32 nAryLen = aSeq.getLength();
1458 :
1459 : // the metafile is already rotated
1460 0 : bRotate = false;
1461 :
1462 0 : if ( pAry && nAryLen )
1463 : {
1464 0 : Graphic aGraphic;
1465 0 : SvMemoryStream aTemp( (void*)pAry, nAryLen, STREAM_READ );
1466 0 : sal_uInt32 nErrCode = GraphicConverter::Import( aTemp, aGraphic, CVT_WMF );
1467 0 : if ( nErrCode == ERRCODE_NONE )
1468 : {
1469 0 : aGraphicObject = aGraphic;
1470 0 : aUniqueId = aGraphicObject.GetUniqueID();
1471 0 : bIsGraphicMtf = aGraphicObject.GetType() == GRAPHIC_GDIMETAFILE;
1472 0 : }
1473 0 : }
1474 : }
1475 126 : else if ( rSource == "Bitmap" )
1476 : {
1477 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap >xBitmap(
1478 0 : aAny, css::uno::UNO_QUERY);
1479 0 : if (xBitmap.is())
1480 : {
1481 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap > xBmp;
1482 0 : if ( aAny >>= xBmp )
1483 : {
1484 0 : BitmapEx aBitmapEx( VCLUnoHelper::GetBitmap( xBmp ) );
1485 0 : Graphic aGraphic( aBitmapEx );
1486 0 : aGraphicObject = aGraphic;
1487 0 : aUniqueId = aGraphicObject.GetUniqueID();
1488 0 : bIsGraphicMtf = aGraphicObject.GetType() == GRAPHIC_GDIMETAFILE;
1489 0 : }
1490 0 : }
1491 : }
1492 126 : else if ( rSource == "FillBitmapURL" )
1493 : {
1494 6 : aGraphicUrl = *(OUString*)aAny.getValue();
1495 : }
1496 120 : else if ( rSource == "GraphicURL" )
1497 : {
1498 92 : aGraphicUrl = *(OUString*)aAny.getValue();
1499 92 : bCreateFillStyles = true;
1500 : }
1501 28 : else if ( rSource == "FillHatch" )
1502 : {
1503 28 : ::com::sun::star::drawing::Hatch aHatch;
1504 28 : if ( aAny >>= aHatch )
1505 : {
1506 28 : Color aBackColor;
1507 28 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "FillColor" ), false ) )
1508 : {
1509 28 : aBackColor = ImplGetColor( *((sal_uInt32*)aAny.getValue()), false );
1510 : }
1511 28 : bool bFillBackground = false;
1512 28 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "FillBackground" ), true ) )
1513 : {
1514 28 : aAny >>= bFillBackground;
1515 : }
1516 :
1517 28 : const Rectangle aRect(Point(0, 0), pShapeBoundRect ? pShapeBoundRect->GetSize() : Size(28000, 21000));
1518 28 : aGraphicObject = lclDrawHatch( aHatch, aBackColor, bFillBackground, aRect );
1519 28 : aUniqueId = aGraphicObject.GetUniqueID();
1520 28 : eBitmapMode = ::com::sun::star::drawing::BitmapMode_REPEAT;
1521 28 : bIsGraphicMtf = aGraphicObject.GetType() == GRAPHIC_GDIMETAFILE;
1522 : }
1523 : }
1524 :
1525 126 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "IsMirrored" ), true ) )
1526 92 : aAny >>= bMirrored;
1527 :
1528 : // #121074# transparency of graphic is not supported in MS formats, get and apply it
1529 : // in the GetTransformedGraphic call in GetBlibID
1530 126 : if(EscherPropertyValueHelper::GetPropertyValue(aAny, rXPropSet, OUString("Transparency")))
1531 : {
1532 92 : aAny >>= nTransparency;
1533 : }
1534 :
1535 126 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString("AdjustRed") ) )
1536 : {
1537 92 : aAny >>= nRed;
1538 : }
1539 :
1540 126 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString("AdjustGreen" ) ) )
1541 : {
1542 92 : aAny >>= nGreen;
1543 : }
1544 :
1545 126 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString("AdjustBlue" ) ) )
1546 : {
1547 92 : aAny >>= nBlue;
1548 : }
1549 :
1550 126 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "Gamma" ) ) )
1551 : {
1552 92 : aAny >>= fGamma;
1553 : }
1554 :
1555 126 : if ( bCreateFillBitmap && bFillBitmapModeAllowed )
1556 : {
1557 68 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "FillBitmapMode" ), true ) )
1558 34 : aAny >>= eBitmapMode;
1559 : }
1560 : else
1561 : {
1562 276 : nAngle = bRotate && EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "RotateAngle" ), true )
1563 92 : ? (sal_uInt16)( ( *((sal_Int32*)aAny.getValue() ) ) + 5 ) / 10
1564 184 : : 0;
1565 : }
1566 :
1567 126 : if ( aGraphicUrl.getLength() )
1568 : {
1569 98 : OUString aVndUrl( "vnd.sun.star.GraphicObject:" );
1570 98 : sal_Int32 nIndex = aGraphicUrl.indexOf( aVndUrl, 0 );
1571 98 : if ( nIndex != -1 )
1572 : {
1573 98 : nIndex = nIndex + aVndUrl.getLength();
1574 98 : if ( aGraphicUrl.getLength() > nIndex )
1575 98 : aUniqueId = OUStringToOString(aGraphicUrl.copy(nIndex, aGraphicUrl.getLength() - nIndex), RTL_TEXTENCODING_UTF8);
1576 : }
1577 : else
1578 : {
1579 : // externally, linked graphic? convert to embedded
1580 : // one, if transformations are needed. this is because
1581 : // everything < msoxp cannot even handle rotated
1582 : // bitmaps.
1583 : // And check whether the graphic link target is
1584 : // actually supported by mso.
1585 0 : INetURLObject aTmp( aGraphicUrl );
1586 0 : GraphicDescriptor aDescriptor(aTmp);
1587 0 : aDescriptor.Detect();
1588 0 : const sal_uInt16 nFormat = aDescriptor.GetFileFormat();
1589 :
1590 : // can MSO handle it?
1591 0 : if ( bMirrored || nAngle || nTransparency || nRed || nGreen || nBlue || (1.0 != fGamma) ||
1592 0 : (nFormat != GFF_BMP &&
1593 0 : nFormat != GFF_GIF &&
1594 0 : nFormat != GFF_JPG &&
1595 0 : nFormat != GFF_PNG &&
1596 0 : nFormat != GFF_TIF &&
1597 0 : nFormat != GFF_PCT &&
1598 0 : nFormat != GFF_WMF &&
1599 : nFormat != GFF_EMF) )
1600 : {
1601 : boost::scoped_ptr<SvStream> pIn(::utl::UcbStreamHelper::CreateStream(
1602 0 : aTmp.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ ));
1603 0 : if ( pIn )
1604 : {
1605 0 : Graphic aGraphic;
1606 0 : sal_uInt32 nErrCode = GraphicConverter::Import( *pIn, aGraphic );
1607 :
1608 0 : if ( nErrCode == ERRCODE_NONE )
1609 : {
1610 : // no
1611 0 : aGraphicObject = aGraphic;
1612 0 : aUniqueId = aGraphicObject.GetUniqueID();
1613 0 : }
1614 : // else: simply keep the graphic link
1615 0 : }
1616 : }
1617 0 : if ( aUniqueId.isEmpty() )
1618 : {
1619 0 : if ( pGraphicProvider )
1620 : {
1621 0 : const OUString& rBaseURI( pGraphicProvider->GetBaseURI() );
1622 0 : INetURLObject aBaseURI( rBaseURI );
1623 0 : if( aBaseURI.GetProtocol() == aTmp.GetProtocol() )
1624 : {
1625 : OUString aRelUrl( INetURLObject::GetRelURL( rBaseURI, aGraphicUrl,
1626 0 : INetURLObject::WAS_ENCODED, INetURLObject::DECODE_TO_IURI, RTL_TEXTENCODING_UTF8, INetURLObject::FSYS_DETECT ) );
1627 0 : if ( !aRelUrl.isEmpty() )
1628 0 : aGraphicUrl = aRelUrl;
1629 0 : }
1630 : }
1631 0 : }
1632 98 : }
1633 : }
1634 :
1635 126 : if ( aGraphicUrl.getLength() || !aUniqueId.isEmpty() )
1636 : {
1637 126 : if(bMirrored || nTransparency || nRed || nGreen || nBlue || (1.0 != fGamma))
1638 : {
1639 0 : pGraphicAttr.reset(new GraphicAttr);
1640 :
1641 0 : if(bMirrored)
1642 : {
1643 0 : pGraphicAttr->SetMirrorFlags(BMP_MIRROR_HORZ);
1644 : }
1645 :
1646 : // #121074#
1647 0 : if(nTransparency)
1648 : {
1649 0 : pGraphicAttr->SetTransparency((nTransparency * 255) / 100);
1650 : }
1651 :
1652 0 : if(nRed)
1653 : {
1654 0 : pGraphicAttr->SetChannelR(nRed);
1655 : }
1656 :
1657 0 : if(nGreen)
1658 : {
1659 0 : pGraphicAttr->SetChannelG(nGreen);
1660 : }
1661 :
1662 0 : if(nBlue)
1663 : {
1664 0 : pGraphicAttr->SetChannelB(nBlue);
1665 : }
1666 :
1667 0 : if(1.0 != fGamma)
1668 : {
1669 0 : pGraphicAttr->SetGamma(fGamma);
1670 : }
1671 : }
1672 :
1673 126 : if(nAngle && bIsGraphicMtf)
1674 : {
1675 0 : AddOpt( ESCHER_Prop_Rotation, ( ( ((sal_Int32)nAngle << 16 ) / 10 ) + 0x8000 ) &~ 0xffff );
1676 : }
1677 :
1678 126 : if ( eBitmapMode == ::com::sun::star::drawing::BitmapMode_REPEAT )
1679 : {
1680 28 : sal_Int32 nSizeX = 0,nSizeY = 0,nOffsetX = 0,nOffsetY = 0,nPosOffsetX = 0,nPosOffsetY = 0;
1681 28 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, "FillBitmapSizeX", true ) )
1682 : {
1683 28 : aAny >>= nSizeX;
1684 : }
1685 28 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, "FillBitmapSizeY", true ) )
1686 : {
1687 28 : aAny >>= nSizeY;
1688 : }
1689 28 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, "FillBitmapOffsetX", true ) )
1690 : {
1691 28 : aAny >>= nOffsetX;
1692 : }
1693 28 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, "FillBitmapOffsetY", true ) )
1694 : {
1695 28 : aAny >>= nOffsetY;
1696 : }
1697 28 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, "FillBitmapPositionOffsetX", true ) )
1698 : {
1699 28 : aAny >>= nPosOffsetX;
1700 : }
1701 28 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, "FillBitmapPositionOffsetY", true ) )
1702 : {
1703 28 : aAny >>= nPosOffsetY;
1704 : }
1705 28 : if(nSizeX == -100 && nSizeY == -100 && nOffsetX == 0 && nOffsetY == 0 && nPosOffsetX == 0 && nPosOffsetY == 0)
1706 0 : AddOpt( ESCHER_Prop_fillType, ESCHER_FillPicture );
1707 : else
1708 28 : AddOpt( ESCHER_Prop_fillType, ESCHER_FillTexture );
1709 : }
1710 : else
1711 98 : AddOpt( ESCHER_Prop_fillType, ESCHER_FillPicture );
1712 :
1713 126 : if ( !aUniqueId.isEmpty() )
1714 : {
1715 : // write out embedded graphic
1716 126 : if ( pGraphicProvider && pPicOutStrm && pShapeBoundRect )
1717 : {
1718 8 : Rectangle aRect( Point( 0, 0 ), pShapeBoundRect->GetSize() );
1719 8 : const sal_uInt32 nBlibId(pGraphicProvider->GetBlibID(*pPicOutStrm, aUniqueId, aRect, NULL, pGraphicAttr.get()));
1720 :
1721 8 : if(nBlibId)
1722 : {
1723 8 : if(bCreateFillBitmap)
1724 : {
1725 0 : AddOpt(ESCHER_Prop_fillBlip, nBlibId, true);
1726 : }
1727 : else
1728 : {
1729 8 : AddOpt( ESCHER_Prop_pib, nBlibId, true );
1730 8 : ImplCreateGraphicAttributes( rXPropSet, nBlibId, bCreateCroppingAttributes );
1731 : }
1732 :
1733 8 : bRetValue = true;
1734 8 : }
1735 : }
1736 : else
1737 : {
1738 118 : EscherGraphicProvider aProvider;
1739 236 : SvMemoryStream aMemStrm;
1740 118 : Rectangle aRect;
1741 :
1742 118 : if ( aProvider.GetBlibID( aMemStrm, aUniqueId, aRect, NULL, pGraphicAttr.get(), bOOxmlExport ) )
1743 : {
1744 : // grab BLIP from stream and insert directly as complex property
1745 : // ownership of stream memory goes to complex property
1746 114 : aMemStrm.ObjectOwnsMemory( false );
1747 114 : sal_uInt8* pBuf = (sal_uInt8*) aMemStrm.GetData();
1748 114 : sal_uInt32 nSize = aMemStrm.Seek( STREAM_SEEK_TO_END );
1749 114 : AddOpt( ESCHER_Prop_fillBlip, true, nSize, pBuf, nSize );
1750 114 : bRetValue = true;
1751 118 : }
1752 : }
1753 : }
1754 : // write out link to graphic
1755 : else
1756 : {
1757 : OSL_ASSERT(aGraphicUrl.getLength());
1758 :
1759 0 : AddOpt( ESCHER_Prop_pibName, aGraphicUrl );
1760 0 : sal_uInt32 nPibFlags=0;
1761 0 : GetOpt( ESCHER_Prop_pibFlags, nPibFlags );
1762 : AddOpt( ESCHER_Prop_pibFlags,
1763 0 : ESCHER_BlipFlagLinkToFile|ESCHER_BlipFlagFile|ESCHER_BlipFlagDoNotSave | nPibFlags );
1764 : }
1765 : }
1766 : }
1767 126 : pGraphicAttr.reset();
1768 126 : if ( bCreateFillStyles )
1769 92 : CreateFillProperties( rXPropSet, true );
1770 :
1771 252 : return bRetValue;
1772 : }
1773 :
1774 154 : tools::PolyPolygon EscherPropertyContainer::GetPolyPolygon( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rXShape )
1775 : {
1776 154 : tools::PolyPolygon aRetPolyPoly;
1777 308 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > aXPropSet;
1778 154 : ::com::sun::star::uno::Any aAny( rXShape->queryInterface(
1779 308 : cppu::UnoType<com::sun::star::beans::XPropertySet>::get()));
1780 :
1781 308 : OUString sPolyPolygonBezier ( "PolyPolygonBezier" );
1782 308 : OUString sPolyPolygon ( "PolyPolygon" );
1783 308 : OUString sPolygon ( "Polygon" );
1784 308 : OUString sCustomShapeGeometry ( "CustomShapeGeometry" );
1785 :
1786 154 : if ( aAny >>= aXPropSet )
1787 : {
1788 154 : bool bHasProperty = EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, sPolyPolygonBezier, true );
1789 154 : if ( !bHasProperty )
1790 72 : bHasProperty = EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, sPolyPolygon, true );
1791 154 : if ( !bHasProperty )
1792 50 : bHasProperty = EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, sPolygon, true );
1793 154 : if ( !bHasProperty )
1794 50 : bHasProperty = EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, sCustomShapeGeometry, true );
1795 154 : if ( bHasProperty )
1796 154 : aRetPolyPoly = GetPolyPolygon( aAny );
1797 : }
1798 308 : return aRetPolyPoly;
1799 : }
1800 :
1801 5408 : tools::PolyPolygon EscherPropertyContainer::GetPolyPolygon( const ::com::sun::star::uno::Any& rAny )
1802 : {
1803 5408 : bool bNoError = true;
1804 :
1805 5408 : Polygon aPolygon;
1806 5408 : tools::PolyPolygon aPolyPolygon;
1807 :
1808 5408 : if ( rAny.getValueType() == cppu::UnoType<com::sun::star::drawing::PolyPolygonBezierCoords>::get())
1809 : {
1810 : ::com::sun::star::drawing::PolyPolygonBezierCoords* pSourcePolyPolygon
1811 5040 : = (::com::sun::star::drawing::PolyPolygonBezierCoords*)rAny.getValue();
1812 5040 : sal_uInt16 nOuterSequenceCount = (sal_uInt16)pSourcePolyPolygon->Coordinates.getLength();
1813 :
1814 : // get pointer of inner sequences
1815 5040 : ::com::sun::star::drawing::PointSequence* pOuterSequence = pSourcePolyPolygon->Coordinates.getArray();
1816 5040 : ::com::sun::star::drawing::FlagSequence* pOuterFlags = pSourcePolyPolygon->Flags.getArray();
1817 :
1818 5040 : bNoError = pOuterSequence && pOuterFlags;
1819 5040 : if ( bNoError )
1820 : {
1821 : sal_uInt16 a, b, nInnerSequenceCount;
1822 : ::com::sun::star::awt::Point* pArray;
1823 :
1824 : // this will be a polygon set
1825 5646 : for ( a = 0; a < nOuterSequenceCount; a++ )
1826 : {
1827 606 : ::com::sun::star::drawing::PointSequence* pInnerSequence = pOuterSequence++;
1828 606 : ::com::sun::star::drawing::FlagSequence* pInnerFlags = pOuterFlags++;
1829 :
1830 606 : bNoError = pInnerSequence && pInnerFlags;
1831 606 : if ( bNoError )
1832 : {
1833 : // get pointer to arrays
1834 606 : pArray = pInnerSequence->getArray();
1835 606 : ::com::sun::star::drawing::PolygonFlags* pFlags = pInnerFlags->getArray();
1836 :
1837 606 : if ( pArray && pFlags )
1838 : {
1839 606 : nInnerSequenceCount = (sal_uInt16)pInnerSequence->getLength();
1840 606 : aPolygon = Polygon( nInnerSequenceCount );
1841 10836 : for( b = 0; b < nInnerSequenceCount; b++)
1842 : {
1843 10230 : PolyFlags ePolyFlags( *( (PolyFlags*)pFlags++ ) );
1844 10230 : ::com::sun::star::awt::Point aPoint( *(pArray++) );
1845 10230 : aPolygon[ b ] = Point( aPoint.X, aPoint.Y );
1846 10230 : aPolygon.SetFlags( b, ePolyFlags );
1847 :
1848 10230 : if ( ePolyFlags == POLY_CONTROL )
1849 4824 : continue;
1850 : }
1851 606 : aPolyPolygon.Insert( aPolygon, POLYPOLY_APPEND );
1852 : }
1853 : }
1854 : }
1855 : }
1856 : }
1857 368 : else if ( rAny.getValueType() == ::getCppuType( ( const ::com::sun::star::drawing::PointSequenceSequence* ) 0 ) )
1858 : {
1859 : ::com::sun::star::drawing::PointSequenceSequence* pSourcePolyPolygon
1860 318 : = (::com::sun::star::drawing::PointSequenceSequence*)rAny.getValue();
1861 318 : sal_uInt16 nOuterSequenceCount = (sal_uInt16)pSourcePolyPolygon->getLength();
1862 :
1863 : // get pointer to inner sequences
1864 318 : ::com::sun::star::drawing::PointSequence* pOuterSequence = pSourcePolyPolygon->getArray();
1865 318 : bNoError = pOuterSequence != NULL;
1866 318 : if ( bNoError )
1867 : {
1868 : sal_uInt16 a, b, nInnerSequenceCount;
1869 :
1870 : // this will be a polygon set
1871 636 : for( a = 0; a < nOuterSequenceCount; a++ )
1872 : {
1873 318 : ::com::sun::star::drawing::PointSequence* pInnerSequence = pOuterSequence++;
1874 318 : bNoError = pInnerSequence != NULL;
1875 318 : if ( bNoError )
1876 : {
1877 : // get pointer to arrays
1878 : ::com::sun::star::awt::Point* pArray =
1879 318 : pInnerSequence->getArray();
1880 318 : if ( pArray != NULL )
1881 : {
1882 318 : nInnerSequenceCount = (sal_uInt16)pInnerSequence->getLength();
1883 318 : aPolygon = Polygon( nInnerSequenceCount );
1884 12380 : for( b = 0; b < nInnerSequenceCount; b++)
1885 : {
1886 12062 : aPolygon[ b ] = Point( pArray->X, pArray->Y );
1887 12062 : pArray++;
1888 : }
1889 318 : aPolyPolygon.Insert( aPolygon, POLYPOLY_APPEND );
1890 : }
1891 : }
1892 : }
1893 : }
1894 : }
1895 50 : else if ( rAny.getValueType() == ::getCppuType( ( const ::com::sun::star::drawing::PointSequence* ) 0 ) )
1896 : {
1897 : ::com::sun::star::drawing::PointSequence* pInnerSequence =
1898 0 : (::com::sun::star::drawing::PointSequence*)rAny.getValue();
1899 :
1900 0 : bNoError = pInnerSequence != NULL;
1901 0 : if ( bNoError )
1902 : {
1903 : sal_uInt16 a, nInnerSequenceCount;
1904 :
1905 : // get pointer to arrays
1906 0 : ::com::sun::star::awt::Point* pArray = pInnerSequence->getArray();
1907 0 : if ( pArray != NULL )
1908 : {
1909 0 : nInnerSequenceCount = (sal_uInt16)pInnerSequence->getLength();
1910 0 : aPolygon = Polygon( nInnerSequenceCount );
1911 0 : for( a = 0; a < nInnerSequenceCount; a++)
1912 : {
1913 0 : aPolygon[ a ] = Point( pArray->X, pArray->Y );
1914 0 : pArray++;
1915 : }
1916 0 : aPolyPolygon.Insert( aPolygon, POLYPOLY_APPEND );
1917 : }
1918 : }
1919 : }
1920 50 : else if ( rAny.getValueType() == ::getCppuType( ( const uno::Sequence< beans::PropertyValue >* ) 0 ) )
1921 : {
1922 : uno::Sequence< beans::PropertyValue >* pGeometrySeq =
1923 50 : (uno::Sequence< beans::PropertyValue >*)rAny.getValue();
1924 :
1925 50 : if ( pGeometrySeq )
1926 : {
1927 452 : for( int i = 0; i < pGeometrySeq->getLength(); ++i )
1928 : {
1929 402 : const beans::PropertyValue& rProp = (*pGeometrySeq)[ i ];
1930 402 : if ( rProp.Name == "Path" )
1931 : {
1932 50 : uno::Sequence<beans::PropertyValue> aPathProp;
1933 50 : rProp.Value >>= aPathProp;
1934 :
1935 100 : uno::Sequence<drawing::EnhancedCustomShapeParameterPair> aPairs;
1936 100 : uno::Sequence<drawing::EnhancedCustomShapeSegment> aSegments;
1937 250 : for (int j = 0; j < aPathProp.getLength(); ++j )
1938 : {
1939 200 : const beans::PropertyValue& rPathProp = aPathProp[j];
1940 200 : if (rPathProp.Name == "Coordinates")
1941 50 : rPathProp.Value >>= aPairs;
1942 150 : else if (rPathProp.Name == "Segments")
1943 50 : rPathProp.Value >>= aSegments;
1944 : }
1945 :
1946 50 : aPolygon = Polygon( aPairs.getLength() );
1947 638 : for( int j = 0; j < aPairs.getLength(); ++j )
1948 : {
1949 588 : aPolygon[j] = Point( aPairs[j].First.Value.get<sal_Int32>(), aPairs[j].Second.Value.get<sal_Int32>() );
1950 : }
1951 :
1952 50 : int nPointIndex = 0;
1953 204 : for( int j = 0; j < aSegments.getLength(); ++j )
1954 : {
1955 718 : for ( int k = 0; k < aSegments[j].Count; ++k )
1956 : {
1957 564 : switch( aSegments[ j ].Command )
1958 : {
1959 0 : case drawing::EnhancedCustomShapeSegmentCommand::UNKNOWN: break;
1960 : case drawing::EnhancedCustomShapeSegmentCommand::MOVETO :
1961 : case drawing::EnhancedCustomShapeSegmentCommand::LINETO :
1962 552 : nPointIndex++;
1963 552 : break;
1964 : case drawing::EnhancedCustomShapeSegmentCommand::CURVETO :
1965 : {
1966 12 : aPolygon.SetFlags( nPointIndex, POLY_CONTROL);
1967 12 : aPolygon.SetFlags( nPointIndex+1, POLY_CONTROL);
1968 12 : aPolygon.SetFlags( nPointIndex+2, POLY_NORMAL);
1969 12 : nPointIndex += 3;
1970 12 : break;
1971 : }
1972 : case drawing::EnhancedCustomShapeSegmentCommand::CLOSESUBPATH :
1973 : case drawing::EnhancedCustomShapeSegmentCommand::ENDSUBPATH :
1974 : case drawing::EnhancedCustomShapeSegmentCommand::NOFILL :
1975 : case drawing::EnhancedCustomShapeSegmentCommand::NOSTROKE :
1976 0 : break;
1977 : case drawing::EnhancedCustomShapeSegmentCommand::ANGLEELLIPSETO :
1978 : case drawing::EnhancedCustomShapeSegmentCommand::ANGLEELLIPSE :
1979 0 : nPointIndex += 3;
1980 0 : break;
1981 : case drawing::EnhancedCustomShapeSegmentCommand::ARCTO :
1982 : case drawing::EnhancedCustomShapeSegmentCommand::ARC :
1983 : case drawing::EnhancedCustomShapeSegmentCommand::CLOCKWISEARCTO :
1984 : case drawing::EnhancedCustomShapeSegmentCommand::CLOCKWISEARC :
1985 0 : nPointIndex += 4;
1986 0 : break;
1987 : case drawing::EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTX :
1988 : case drawing::EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTY :
1989 0 : nPointIndex++;
1990 0 : break;
1991 : case drawing::EnhancedCustomShapeSegmentCommand::QUADRATICCURVETO :
1992 : case drawing::EnhancedCustomShapeSegmentCommand::ARCANGLETO :
1993 0 : nPointIndex += 2;
1994 0 : break;
1995 : case drawing::EnhancedCustomShapeSegmentCommand::DARKEN :
1996 : case drawing::EnhancedCustomShapeSegmentCommand::DARKENLESS :
1997 : case drawing::EnhancedCustomShapeSegmentCommand::LIGHTEN :
1998 : case drawing::EnhancedCustomShapeSegmentCommand::LIGHTENLESS :
1999 0 : break;
2000 : }
2001 : }
2002 : }
2003 100 : aPolyPolygon.Insert( aPolygon, POLYPOLY_APPEND );
2004 : }
2005 : }
2006 : }
2007 : }
2008 5408 : return aPolyPolygon;
2009 : }
2010 :
2011 480 : bool EscherPropertyContainer::CreatePolygonProperties(
2012 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet,
2013 : sal_uInt32 nFlags,
2014 : bool bBezier,
2015 : ::com::sun::star::awt::Rectangle& rGeoRect,
2016 : Polygon* pPolygon )
2017 : {
2018 480 : static OUString sPolyPolygonBezier ( "PolyPolygonBezier" );
2019 480 : static OUString sPolyPolygon ( "PolyPolygon" );
2020 :
2021 480 : bool bRetValue = true;
2022 480 : bool bLine = ( nFlags & ESCHER_CREATEPOLYGON_LINE ) != 0;
2023 :
2024 480 : tools::PolyPolygon aPolyPolygon;
2025 :
2026 480 : if ( pPolygon )
2027 0 : aPolyPolygon.Insert( *pPolygon, POLYPOLY_APPEND );
2028 : else
2029 : {
2030 480 : ::com::sun::star::uno::Any aAny;
2031 : bRetValue = EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet,
2032 480 : ( bBezier ) ? sPolyPolygonBezier : sPolyPolygon, true );
2033 480 : if ( bRetValue )
2034 : {
2035 480 : aPolyPolygon = GetPolyPolygon( aAny );
2036 480 : bRetValue = aPolyPolygon.Count() != 0;
2037 480 : }
2038 : }
2039 480 : if ( bRetValue )
2040 : {
2041 480 : if ( bLine )
2042 : {
2043 34 : if ( ( aPolyPolygon.Count() == 1 ) && ( aPolyPolygon[ 0 ].GetSize() == 2 ) )
2044 : {
2045 34 : const Polygon& rPoly = aPolyPolygon[ 0 ];
2046 : rGeoRect = ::com::sun::star::awt::Rectangle(
2047 34 : rPoly[ 0 ].X(),
2048 34 : rPoly[ 0 ].Y(),
2049 68 : rPoly[ 1 ].X() - rPoly[ 0 ].X(),
2050 170 : rPoly[ 1 ].Y() - rPoly[ 0 ].Y() );
2051 : }
2052 : else
2053 0 : bRetValue = false;
2054 : }
2055 : else
2056 : {
2057 446 : Polygon aPolygon;
2058 :
2059 446 : sal_uInt16 i, j, k, nPoints, nBezPoints, nPolyCount = aPolyPolygon.Count();
2060 446 : Rectangle aRect( aPolyPolygon.GetBoundRect() );
2061 446 : rGeoRect = ::com::sun::star::awt::Rectangle( aRect.Left(), aRect.Top(), aRect.GetWidth(), aRect.GetHeight() );
2062 :
2063 1004 : for ( nBezPoints = nPoints = i = 0; i < nPolyCount; i++ )
2064 : {
2065 558 : k = aPolyPolygon[ i ].GetSize();
2066 558 : nPoints = nPoints + k;
2067 19778 : for ( j = 0; j < k; j++ )
2068 : {
2069 19220 : if ( aPolyPolygon[ i ].GetFlags( j ) != POLY_CONTROL )
2070 15188 : nBezPoints++;
2071 : }
2072 : }
2073 446 : sal_uInt32 nVerticesBufSize = ( nPoints << 2 ) + 6;
2074 446 : sal_uInt8* pVerticesBuf = new sal_uInt8[ nVerticesBufSize ];
2075 :
2076 :
2077 446 : sal_uInt32 nSegmentBufSize = ( ( nBezPoints << 2 ) + 8 );
2078 446 : if ( nPolyCount > 1 )
2079 112 : nSegmentBufSize += ( nPolyCount << 1 );
2080 446 : sal_uInt8* pSegmentBuf = new sal_uInt8[ nSegmentBufSize ];
2081 :
2082 446 : sal_uInt8* pPtr = pVerticesBuf;
2083 446 : *pPtr++ = (sal_uInt8)( nPoints ); // Little endian
2084 446 : *pPtr++ = (sal_uInt8)( nPoints >> 8 );
2085 446 : *pPtr++ = (sal_uInt8)( nPoints );
2086 446 : *pPtr++ = (sal_uInt8)( nPoints >> 8 );
2087 446 : *pPtr++ = (sal_uInt8)0xf0;
2088 446 : *pPtr++ = (sal_uInt8)0xff;
2089 :
2090 1004 : for ( j = 0; j < nPolyCount; j++ )
2091 : {
2092 558 : aPolygon = aPolyPolygon[ j ];
2093 558 : nPoints = aPolygon.GetSize();
2094 19778 : for ( i = 0; i < nPoints; i++ ) // write points from polygon to buffer
2095 : {
2096 19220 : Point aPoint = aPolygon[ i ];
2097 19220 : aPoint.X() -= rGeoRect.X;
2098 19220 : aPoint.Y() -= rGeoRect.Y;
2099 :
2100 19220 : *pPtr++ = (sal_uInt8)( aPoint.X() );
2101 19220 : *pPtr++ = (sal_uInt8)( aPoint.X() >> 8 );
2102 19220 : *pPtr++ = (sal_uInt8)( aPoint.Y() );
2103 19220 : *pPtr++ = (sal_uInt8)( aPoint.Y() >> 8 );
2104 : }
2105 : }
2106 :
2107 446 : pPtr = pSegmentBuf;
2108 446 : *pPtr++ = (sal_uInt8)( ( nSegmentBufSize - 6 ) >> 1 );
2109 446 : *pPtr++ = (sal_uInt8)( ( nSegmentBufSize - 6 ) >> 9 );
2110 446 : *pPtr++ = (sal_uInt8)( ( nSegmentBufSize - 6 ) >> 1 );
2111 446 : *pPtr++ = (sal_uInt8)( ( nSegmentBufSize - 6 ) >> 9 );
2112 446 : *pPtr++ = (sal_uInt8)2;
2113 446 : *pPtr++ = (sal_uInt8)0;
2114 :
2115 1004 : for ( j = 0; j < nPolyCount; j++ )
2116 : {
2117 558 : *pPtr++ = 0x0; // Polygon start
2118 558 : *pPtr++ = 0x40;
2119 558 : aPolygon = aPolyPolygon[ j ];
2120 558 : nPoints = aPolygon.GetSize();
2121 15746 : for ( i = 0; i < nPoints; i++ ) // write Polyflags to Buffer
2122 : {
2123 15188 : *pPtr++ = 0;
2124 15188 : if ( bBezier )
2125 3238 : *pPtr++ = 0xb3;
2126 : else
2127 11950 : *pPtr++ = 0xac;
2128 15188 : if ( ( i + 1 ) != nPoints )
2129 : {
2130 14630 : *pPtr++ = 1;
2131 14630 : if ( aPolygon.GetFlags( i + 1 ) == POLY_CONTROL )
2132 : {
2133 2016 : *pPtr++ = 0x20;
2134 2016 : i += 2;
2135 : }
2136 : else
2137 12614 : *pPtr++ = 0;
2138 : }
2139 : }
2140 558 : if ( nPolyCount > 1 )
2141 : {
2142 224 : *pPtr++ = 1; // end of polygon
2143 224 : *pPtr++ = 0x60;
2144 : }
2145 : }
2146 446 : *pPtr++ = 0;
2147 446 : *pPtr++ = 0x80;
2148 :
2149 446 : AddOpt( ESCHER_Prop_geoRight, rGeoRect.Width );
2150 446 : AddOpt( ESCHER_Prop_geoBottom, rGeoRect.Height );
2151 :
2152 446 : AddOpt( ESCHER_Prop_shapePath, ESCHER_ShapeComplex );
2153 446 : AddOpt( ESCHER_Prop_pVertices, true, nVerticesBufSize - 6, (sal_uInt8*)pVerticesBuf, nVerticesBufSize );
2154 446 : AddOpt( ESCHER_Prop_pSegmentInfo, true, nSegmentBufSize, (sal_uInt8*)pSegmentBuf, nSegmentBufSize );
2155 : }
2156 : }
2157 480 : return bRetValue;
2158 : }
2159 :
2160 :
2161 : /*
2162 : in MS,the connector including 9 types :
2163 : "straightConnector1",
2164 : "bentConnector2","bentConnector3","bentConnector4","bentConnector5"
2165 : "curvedConnector2","curvedConnector3","curvedConnector4","curvedConnector5"
2166 : in AOO,including 4 types:"standard","lines","line","curve"
2167 : when save as MS file, the connector must be convert to corresponding type.
2168 : "line" and "lines" <-> "straightConnector1"
2169 : "standard" <-> "bentConnector2-5"
2170 : "curve" <-> "curvedConnector2-5"
2171 : */
2172 2 : sal_Int32 lcl_GetAdjustValueCount( const XPolygon& rPoly )
2173 : {
2174 2 : int nRet = 0;
2175 2 : switch ( rPoly.GetSize() )
2176 : {
2177 : case 2 :
2178 : case 3:
2179 2 : nRet = 0;
2180 2 : break;
2181 : case 4:
2182 0 : nRet = 1;
2183 0 : break;
2184 : case 5:
2185 0 : nRet = 2;
2186 0 : break;
2187 : default:
2188 0 : if ( rPoly.GetSize()>=6 )
2189 0 : nRet = 3;
2190 0 : break;
2191 : }
2192 2 : return nRet;
2193 : }
2194 :
2195 : // Adjust value decide the position which connector should turn a corner
2196 0 : sal_Int32 lcl_GetConnectorAdjustValue ( const XPolygon& rPoly, sal_uInt16 nIndex )
2197 : {
2198 0 : sal_uInt16 k = rPoly.GetSize();
2199 : OSL_ASSERT ( k >= ( 3 + nIndex ) );
2200 :
2201 0 : Point aPt;
2202 0 : Point aStart = rPoly[0];
2203 0 : Point aEnd = rPoly[k-1];
2204 0 : if ( aEnd.Y() == aStart.Y() )
2205 0 : aEnd.Y() = aStart.Y() +4;
2206 0 : if ( aEnd.X() == aStart.X() )
2207 0 : aEnd.X() = aStart.X() +4;
2208 :
2209 0 : bool bVertical = ( rPoly[1].X()-aStart.X() ) == 0 ;
2210 : // vertical and horizon alternate
2211 0 : if ( nIndex%2 == 1 ) bVertical = !bVertical;
2212 0 : aPt = rPoly[ nIndex + 1];
2213 :
2214 : sal_Int32 nAdjustValue;
2215 0 : if ( bVertical )
2216 0 : nAdjustValue = ( aPt.Y()-aStart.Y())* 21600 /(aEnd.Y()-aStart.Y());
2217 : else
2218 0 : nAdjustValue = ( aPt.X()-aStart.X() )* 21600 /(aEnd.X()-aStart.X());
2219 :
2220 0 : return nAdjustValue;
2221 : }
2222 :
2223 :
2224 4 : void lcl_Rotate(sal_Int32 nAngle, Point center, Point& pt)
2225 : {
2226 12 : while ( nAngle<0)
2227 4 : nAngle +=36000;
2228 8 : while (nAngle>=36000)
2229 0 : nAngle -=36000;
2230 :
2231 : int cs, sn;
2232 4 : switch (nAngle)
2233 : {
2234 : case 0:
2235 0 : cs =1;
2236 0 : sn =0;
2237 0 : break;
2238 : case 9000:
2239 0 : cs =0;
2240 0 : sn =1;
2241 0 : break;
2242 : case 18000:
2243 0 : cs = -1;
2244 0 : sn = 0;
2245 0 : break;
2246 : case 27000:
2247 4 : cs = 0;
2248 4 : sn = -1;
2249 4 : break;
2250 : default:
2251 4 : return;
2252 : break;
2253 : }
2254 4 : sal_Int32 x0 =pt.X()-center.X();
2255 4 : sal_Int32 y0 =pt.Y()-center.Y();
2256 4 : pt.X()=center.X()+ x0*cs-y0*sn;
2257 4 : pt.Y()=center.Y()+ y0*cs+x0*sn;
2258 : }
2259 : /*
2260 : FlipV defines that the shape will be flipped vertically about the center of its bounding box.
2261 : Generally, draw the connector from top to bottom, from left to right when meet the adjust value,
2262 : but when (X1>X2 or Y1>Y2),the draw director must be reverse, FlipV or FlipH should be set to true.
2263 : */
2264 2 : bool lcl_GetAngle(Polygon &rPoly,sal_uInt16& rShapeFlags,sal_Int32& nAngle )
2265 : {
2266 2 : Point aStart = rPoly[0];
2267 2 : Point aEnd = rPoly[rPoly.GetSize()-1];
2268 2 : nAngle = ( rPoly[1].X() == aStart.X() ) ? 9000: 0 ;
2269 2 : Point p1(aStart.X(),aStart.Y());
2270 2 : Point p2(aEnd.X(),aEnd.Y());
2271 2 : if ( nAngle )
2272 : {
2273 2 : Point center((aEnd.X()+aStart.X())>>1,(aEnd.Y()+aStart.Y())>>1);
2274 2 : lcl_Rotate(-nAngle, center,p1);
2275 2 : lcl_Rotate(-nAngle, center,p2);
2276 : }
2277 2 : if ( p1.X() > p2.X() )
2278 : {
2279 0 : if ( nAngle )
2280 0 : rShapeFlags |= SHAPEFLAG_FLIPV;
2281 : else
2282 0 : rShapeFlags |= SHAPEFLAG_FLIPH;
2283 :
2284 : }
2285 2 : if ( p1.Y() > p2.Y() )
2286 : {
2287 0 : if ( nAngle )
2288 0 : rShapeFlags |= SHAPEFLAG_FLIPH;
2289 : else
2290 0 : rShapeFlags |= SHAPEFLAG_FLIPV;
2291 : }
2292 :
2293 2 : if ( (rShapeFlags&SHAPEFLAG_FLIPH) && (rShapeFlags&SHAPEFLAG_FLIPV) )
2294 : {
2295 0 : rShapeFlags &= ~( SHAPEFLAG_FLIPH | SHAPEFLAG_FLIPV );
2296 0 : nAngle +=18000;
2297 : }
2298 :
2299 2 : if ( nAngle )
2300 : {
2301 : // Set angle properties
2302 2 : nAngle *= 655;
2303 2 : nAngle += 0x8000;
2304 2 : nAngle &=~0xffff; // round nAngle to whole number of degrees
2305 2 : return true;
2306 : }
2307 0 : return false;
2308 : }
2309 54 : bool EscherPropertyContainer::CreateConnectorProperties(
2310 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rXShape,
2311 : EscherSolverContainer& rSolverContainer, ::com::sun::star::awt::Rectangle& rGeoRect,
2312 : sal_uInt16& rShapeType, sal_uInt16& rShapeFlags )
2313 : {
2314 54 : static OUString sEdgeKind ( "EdgeKind" );
2315 54 : static OUString sEdgeStartPoint ( "EdgeStartPoint" );
2316 54 : static OUString sEdgeEndPoint ( "EdgeEndPoint" );
2317 54 : static OUString sEdgeStartConnection ( "EdgeStartConnection" );
2318 54 : static OUString sEdgeEndConnection ( "EdgeEndConnection" );
2319 54 : static OUString sEdgePath ( "PolyPolygonBezier" );
2320 :
2321 54 : bool bRetValue = false;
2322 54 : rShapeType = rShapeFlags = 0;
2323 :
2324 54 : if ( rXShape.is() )
2325 : {
2326 54 : ::com::sun::star::awt::Point aStartPoint, aEndPoint;
2327 54 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > aXPropSet;
2328 108 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > aShapeA, aShapeB;
2329 108 : ::com::sun::star::uno::Any aAny( rXShape->queryInterface( cppu::UnoType<com::sun::star::beans::XPropertySet>::get()));
2330 54 : if ( aAny >>= aXPropSet )
2331 : {
2332 54 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, sEdgeKind, true ) )
2333 : {
2334 : ::com::sun::star::drawing::ConnectorType eCt;
2335 54 : aAny >>= eCt;
2336 54 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, sEdgeStartPoint ) )
2337 : {
2338 54 : aStartPoint = *(::com::sun::star::awt::Point*)aAny.getValue();
2339 54 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, sEdgeEndPoint ) )
2340 : {
2341 54 : aEndPoint = *(::com::sun::star::awt::Point*)aAny.getValue();
2342 :
2343 54 : rShapeFlags = SHAPEFLAG_HAVEANCHOR | SHAPEFLAG_HAVESPT | SHAPEFLAG_CONNECTOR;
2344 : rGeoRect = ::com::sun::star::awt::Rectangle( aStartPoint.X, aStartPoint.Y,
2345 54 : ( aEndPoint.X - aStartPoint.X ) + 1, ( aEndPoint.Y - aStartPoint.Y ) + 1 );
2346 : // set standard's FLIP in below code
2347 54 : if ( eCt != ::com::sun::star::drawing::ConnectorType_STANDARD)
2348 : {
2349 52 : if ( rGeoRect.Height < 0 ) // justify
2350 : {
2351 0 : rShapeFlags |= SHAPEFLAG_FLIPV;
2352 0 : rGeoRect.Y = aEndPoint.Y;
2353 0 : rGeoRect.Height = -rGeoRect.Height;
2354 : }
2355 52 : if ( rGeoRect.Width < 0 )
2356 : {
2357 0 : rShapeFlags |= SHAPEFLAG_FLIPH;
2358 0 : rGeoRect.X = aEndPoint.X;
2359 0 : rGeoRect.Width = -rGeoRect.Width;
2360 : }
2361 : }
2362 : sal_uInt32 nAdjustValue1, nAdjustValue2, nAdjustValue3;
2363 54 : nAdjustValue1 = nAdjustValue2 = nAdjustValue3 = 0x2a30;
2364 :
2365 54 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, sEdgeStartConnection ) )
2366 0 : aAny >>= aShapeA;
2367 54 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, sEdgeEndConnection ) )
2368 0 : aAny >>= aShapeB;
2369 54 : rSolverContainer.AddConnector( rXShape, aStartPoint, aShapeA, aEndPoint, aShapeB );
2370 54 : switch ( eCt )
2371 : {
2372 : case ::com::sun::star::drawing::ConnectorType_CURVE :
2373 : {
2374 0 : rShapeType = ESCHER_ShpInst_CurvedConnector3;
2375 0 : AddOpt( ESCHER_Prop_cxstyle, ESCHER_cxstyleCurved );
2376 0 : AddOpt( ESCHER_Prop_adjustValue, nAdjustValue1 );
2377 0 : AddOpt( ESCHER_Prop_adjust2Value, -(sal_Int32)nAdjustValue2 );
2378 : }
2379 0 : break;
2380 :
2381 : case ::com::sun::star::drawing::ConnectorType_STANDARD :// Connector 2->5
2382 : {
2383 2 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, sEdgePath ) )
2384 : {
2385 2 : tools::PolyPolygon aPolyPolygon = GetPolyPolygon( aAny );
2386 4 : Polygon aPoly;
2387 2 : if ( aPolyPolygon.Count() > 0 )
2388 : {
2389 2 : AddOpt( ESCHER_Prop_cxstyle, ESCHER_cxstyleBent );
2390 2 : aPoly = aPolyPolygon[ 0 ];
2391 2 : sal_Int32 nAdjCount = lcl_GetAdjustValueCount( aPoly );
2392 2 : rShapeType = ( sal_uInt16 )( ESCHER_ShpInst_BentConnector2 + nAdjCount);
2393 2 : for ( sal_Int32 i = 0 ; i < nAdjCount; ++ i)
2394 0 : AddOpt( (sal_uInt16) ( ESCHER_Prop_adjustValue+i) , lcl_GetConnectorAdjustValue( aPoly, i ) );
2395 2 : bRetValue = true;
2396 : }
2397 2 : sal_Int32 nAngle=0;
2398 2 : if (lcl_GetAngle(aPoly,rShapeFlags,nAngle ))
2399 : {
2400 2 : AddOpt( ESCHER_Prop_Rotation, nAngle );
2401 2 : }
2402 : }
2403 : else
2404 : {
2405 0 : rShapeType = ESCHER_ShpInst_BentConnector3;
2406 0 : AddOpt( ESCHER_Prop_cxstyle, ESCHER_cxstyleBent );
2407 : }
2408 : }
2409 2 : break;
2410 : default:
2411 : case ::com::sun::star::drawing::ConnectorType_LINE :
2412 : case ::com::sun::star::drawing::ConnectorType_LINES : // Connector 2->5
2413 : {
2414 52 : rShapeType = ESCHER_ShpInst_StraightConnector1;
2415 52 : AddOpt( ESCHER_Prop_cxstyle, ESCHER_cxstyleStraight );
2416 : }
2417 52 : break;
2418 : }
2419 54 : CreateLineProperties( aXPropSet, false );
2420 54 : bRetValue = true;
2421 : }
2422 : }
2423 : }
2424 54 : }
2425 : }
2426 54 : return bRetValue;
2427 : }
2428 :
2429 1628 : bool EscherPropertyContainer::CreateShadowProperties(
2430 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet )
2431 : {
2432 1628 : ::com::sun::star::uno::Any aAny;
2433 :
2434 1628 : bool bHasShadow = false; // shadow is possible only if at least a fillcolor, linecolor or graphic is set
2435 1628 : sal_uInt32 nLineFlags = 0; // default : shape has no line
2436 1628 : sal_uInt32 nFillFlags = 0x10; // shape is filled
2437 :
2438 1628 : GetOpt( ESCHER_Prop_fNoLineDrawDash, nLineFlags );
2439 1628 : GetOpt( ESCHER_Prop_fNoFillHitTest, nFillFlags );
2440 :
2441 : sal_uInt32 nDummy;
2442 1628 : bool bGraphic = GetOpt( DFF_Prop_pib, nDummy ) || GetOpt( DFF_Prop_pibName, nDummy ) || GetOpt( DFF_Prop_pibFlags, nDummy );
2443 :
2444 1628 : sal_uInt32 nShadowFlags = 0x20000;
2445 1628 : if ( ( nLineFlags & 8 ) || ( nFillFlags & 0x10 ) || bGraphic )
2446 : {
2447 1346 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "Shadow" ), true ) )
2448 : {
2449 1346 : if ( aAny >>= bHasShadow )
2450 : {
2451 1346 : if ( bHasShadow )
2452 : {
2453 98 : nShadowFlags |= 2;
2454 98 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "ShadowColor" ), false ) )
2455 98 : AddOpt( ESCHER_Prop_shadowColor, ImplGetColor( *((sal_uInt32*)aAny.getValue()) ) );
2456 98 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "ShadowXDistance" ), false ) )
2457 98 : AddOpt( ESCHER_Prop_shadowOffsetX, *((sal_Int32*)aAny.getValue()) * 360 );
2458 98 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "ShadowYDistance" ), false ) )
2459 98 : AddOpt( ESCHER_Prop_shadowOffsetY, *((sal_Int32*)aAny.getValue()) * 360 );
2460 98 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, OUString( "ShadowTransparence" ), false ) )
2461 98 : AddOpt( ESCHER_Prop_shadowOpacity, 0x10000 - (((sal_uInt32)*((sal_uInt16*)aAny.getValue())) * 655 ) );
2462 : }
2463 : }
2464 : }
2465 : }
2466 1628 : AddOpt( ESCHER_Prop_fshadowObscured, nShadowFlags );
2467 1628 : return bHasShadow;
2468 : }
2469 :
2470 10864 : sal_Int32 EscherPropertyContainer::GetValueForEnhancedCustomShapeParameter( const ::com::sun::star::drawing::EnhancedCustomShapeParameter& rParameter,
2471 : const std::vector< sal_Int32 >& rEquationOrder, bool bAdjustTrans )
2472 : {
2473 10864 : sal_Int32 nValue = 0;
2474 10864 : if ( rParameter.Value.getValueTypeClass() == uno::TypeClass_DOUBLE )
2475 : {
2476 0 : double fValue(0.0);
2477 0 : if ( rParameter.Value >>= fValue )
2478 0 : nValue = (sal_Int32)fValue;
2479 : }
2480 : else
2481 10864 : rParameter.Value >>= nValue;
2482 :
2483 10864 : switch( rParameter.Type )
2484 : {
2485 : case com::sun::star::drawing::EnhancedCustomShapeParameterType::EQUATION :
2486 : {
2487 7282 : size_t nIndex = (size_t) nValue;
2488 : OSL_ASSERT(nIndex < rEquationOrder.size());
2489 7282 : if ( nIndex < rEquationOrder.size() )
2490 : {
2491 7282 : nValue = (sal_uInt16)rEquationOrder[ nIndex ];
2492 7282 : nValue |= (sal_uInt32)0x80000000;
2493 : }
2494 : }
2495 7282 : break;
2496 : case com::sun::star::drawing::EnhancedCustomShapeParameterType::ADJUSTMENT:
2497 : {
2498 0 : if(bAdjustTrans)
2499 : {
2500 0 : sal_uInt32 nAdjustValue = 0;
2501 0 : bool bGot = GetOpt((sal_uInt16)( DFF_Prop_adjustValue + nValue ), nAdjustValue);
2502 0 : if(bGot) nValue = (sal_Int32)nAdjustValue;
2503 : }
2504 : }
2505 0 : break;
2506 : case com::sun::star::drawing::EnhancedCustomShapeParameterType::NORMAL :
2507 : default:
2508 3582 : break;
2509 : /* not sure if it is allowed to set following values
2510 : (but they are not yet used)
2511 : case com::sun::star::drawing::EnhancedCustomShapeParameterType::BOTTOM :
2512 : case com::sun::star::drawing::EnhancedCustomShapeParameterType::RIGHT :
2513 : case com::sun::star::drawing::EnhancedCustomShapeParameterType::TOP :
2514 : case com::sun::star::drawing::EnhancedCustomShapeParameterType::LEFT :
2515 : */
2516 : }
2517 10864 : return nValue;
2518 : }
2519 :
2520 872 : bool GetValueForEnhancedCustomShapeHandleParameter( sal_Int32& nRetValue, const com::sun::star::drawing::EnhancedCustomShapeParameter& rParameter )
2521 : {
2522 872 : bool bSpecial = false;
2523 872 : nRetValue = 0;
2524 872 : if ( rParameter.Value.getValueTypeClass() == uno::TypeClass_DOUBLE )
2525 : {
2526 0 : double fValue(0.0);
2527 0 : if ( rParameter.Value >>= fValue )
2528 0 : nRetValue = (sal_Int32)fValue;
2529 : }
2530 : else
2531 872 : rParameter.Value >>= nRetValue;
2532 :
2533 872 : switch( rParameter.Type )
2534 : {
2535 : case com::sun::star::drawing::EnhancedCustomShapeParameterType::EQUATION :
2536 : {
2537 262 : nRetValue += 3;
2538 262 : bSpecial = true;
2539 : }
2540 262 : break;
2541 : case com::sun::star::drawing::EnhancedCustomShapeParameterType::ADJUSTMENT :
2542 : {
2543 0 : nRetValue += 0x100;
2544 0 : bSpecial = true;
2545 : }
2546 0 : break;
2547 : case com::sun::star::drawing::EnhancedCustomShapeParameterType::TOP :
2548 : case com::sun::star::drawing::EnhancedCustomShapeParameterType::LEFT :
2549 : {
2550 0 : nRetValue = 0;
2551 0 : bSpecial = true;
2552 : }
2553 0 : break;
2554 : case com::sun::star::drawing::EnhancedCustomShapeParameterType::RIGHT :
2555 : case com::sun::star::drawing::EnhancedCustomShapeParameterType::BOTTOM :
2556 : {
2557 0 : nRetValue = 1;
2558 0 : bSpecial = true;
2559 : }
2560 0 : break;
2561 : case com::sun::star::drawing::EnhancedCustomShapeParameterType::NORMAL :
2562 : {
2563 :
2564 : }
2565 610 : break;
2566 : }
2567 872 : return bSpecial;
2568 : }
2569 :
2570 748 : void ConvertEnhancedCustomShapeEquation( SdrObjCustomShape* pCustoShape,
2571 : std::vector< EnhancedCustomShapeEquation >& rEquations, std::vector< sal_Int32 >& rEquationOrder )
2572 : {
2573 748 : if ( pCustoShape )
2574 : {
2575 748 : uno::Sequence< OUString > sEquationSource;
2576 1496 : const OUString sEquations( "Equations" );
2577 : const SdrCustomShapeGeometryItem& rGeometryItem = static_cast<const SdrCustomShapeGeometryItem&>(
2578 748 : pCustoShape->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ));
2579 748 : const uno::Any* pAny = rGeometryItem.GetPropertyValueByName( sEquations );
2580 748 : if ( pAny )
2581 598 : *pAny >>= sEquationSource;
2582 748 : sal_Int32 nEquationSourceCount = sEquationSource.getLength();
2583 748 : if ( nEquationSourceCount && (nEquationSourceCount <= 128) )
2584 : {
2585 : sal_Int32 i;
2586 6794 : for ( i = 0; i < nEquationSourceCount; i++ )
2587 : {
2588 6196 : EnhancedCustomShape2d aCustoShape2d( pCustoShape );
2589 : try
2590 : {
2591 : ::boost::shared_ptr< EnhancedCustomShape::ExpressionNode > aExpressNode(
2592 6196 : EnhancedCustomShape::FunctionParser::parseFunction( sEquationSource[ i ], aCustoShape2d ) );
2593 12392 : com::sun::star::drawing::EnhancedCustomShapeParameter aPara( aExpressNode->fillNode( rEquations, NULL, 0 ) );
2594 6196 : if ( aPara.Type != com::sun::star::drawing::EnhancedCustomShapeParameterType::EQUATION )
2595 : {
2596 2706 : EnhancedCustomShapeEquation aEquation;
2597 2706 : aEquation.nOperation = 0;
2598 2706 : EnhancedCustomShape::FillEquationParameter( aPara, 0, aEquation );
2599 2706 : rEquations.push_back( aEquation );
2600 6196 : }
2601 : }
2602 0 : catch ( const EnhancedCustomShape::ParseError& )
2603 : {
2604 0 : EnhancedCustomShapeEquation aEquation; // ups, we should not be here,
2605 0 : aEquation.nOperation = 0; // creating a default equation with value 1
2606 0 : aEquation.nPara[ 0 ] = 1; // hoping that this will not break anything
2607 0 : rEquations.push_back( aEquation );
2608 : }
2609 0 : catch ( ... )
2610 : {
2611 0 : EnhancedCustomShapeEquation aEquation; // #i112309# EnhancedCustomShape::Parse error
2612 0 : aEquation.nOperation = 0; // not catched on linux platform
2613 0 : aEquation.nPara[ 0 ] = 1;
2614 0 : rEquations.push_back( aEquation );
2615 : }
2616 6196 : rEquationOrder.push_back( rEquations.size() - 1 );
2617 6196 : }
2618 : // now updating our old equation indices, they are marked with a bit in the hiword of nOperation
2619 598 : std::vector< EnhancedCustomShapeEquation >::iterator aIter( rEquations.begin() );
2620 598 : std::vector< EnhancedCustomShapeEquation >::iterator aEnd ( rEquations.end() );
2621 9882 : while( aIter != aEnd )
2622 : {
2623 8686 : sal_uInt32 nMask = 0x20000000;
2624 34744 : for( i = 0; i < 3; i++ )
2625 : {
2626 26058 : if ( aIter->nOperation & nMask )
2627 : {
2628 2474 : aIter->nOperation ^= nMask;
2629 2474 : const size_t nIndex(aIter->nPara[ i ] & 0x3ff);
2630 :
2631 : // #i124661# check index access, there are cases where this is out of bound leading
2632 : // to errors up to crashes when executed
2633 2474 : if(nIndex < rEquationOrder.size())
2634 : {
2635 2474 : aIter->nPara[ i ] = rEquationOrder[ nIndex ] | 0x400;
2636 : }
2637 : else
2638 : {
2639 : OSL_ENSURE(false, "Attempted out of bound access to rEquationOrder of CustomShape (!)");
2640 : }
2641 : }
2642 26058 : nMask <<= 1;
2643 : }
2644 8686 : ++aIter;
2645 : }
2646 748 : }
2647 : }
2648 748 : }
2649 :
2650 1482 : bool EscherPropertyContainer::IsDefaultObject( SdrObjCustomShape* pCustoShape , const MSO_SPT eShapeType )
2651 : {
2652 1482 : bool bIsDefaultObject = false;
2653 1482 : switch(eShapeType)
2654 : {
2655 : // if the custom shape is not default shape of ppt, return sal_Fasle;
2656 : case mso_sptTearDrop:
2657 0 : return bIsDefaultObject;
2658 :
2659 : default:
2660 1482 : break;
2661 : }
2662 :
2663 1482 : if ( pCustoShape )
2664 : {
2665 2964 : if ( pCustoShape->IsDefaultGeometry( SdrObjCustomShape::DEFAULT_EQUATIONS )
2666 862 : && pCustoShape->IsDefaultGeometry( SdrObjCustomShape::DEFAULT_VIEWBOX )
2667 342 : && pCustoShape->IsDefaultGeometry( SdrObjCustomShape::DEFAULT_PATH )
2668 342 : && pCustoShape->IsDefaultGeometry( SdrObjCustomShape::DEFAULT_GLUEPOINTS )
2669 342 : && pCustoShape->IsDefaultGeometry( SdrObjCustomShape::DEFAULT_SEGMENTS )
2670 342 : && pCustoShape->IsDefaultGeometry( SdrObjCustomShape::DEFAULT_STRETCHX )
2671 342 : && pCustoShape->IsDefaultGeometry( SdrObjCustomShape::DEFAULT_STRETCHY )
2672 1824 : && pCustoShape->IsDefaultGeometry( SdrObjCustomShape::DEFAULT_TEXTFRAMES ) )
2673 342 : bIsDefaultObject = true;
2674 : }
2675 :
2676 1482 : return bIsDefaultObject;
2677 : }
2678 :
2679 332 : void EscherPropertyContainer::LookForPolarHandles( const MSO_SPT eShapeType, sal_Int32& nAdjustmentsWhichNeedsToBeConverted )
2680 : {
2681 332 : const mso_CustomShape* pDefCustomShape = GetCustomShapeContent( eShapeType );
2682 332 : if ( pDefCustomShape && pDefCustomShape->nHandles && pDefCustomShape->pHandles )
2683 : {
2684 76 : sal_Int32 k, nkCount = pDefCustomShape->nHandles;
2685 76 : const SvxMSDffHandle* pData = pDefCustomShape->pHandles;
2686 156 : for ( k = 0; k < nkCount; k++, pData++ )
2687 : {
2688 80 : if ( pData->nFlags & MSDFF_HANDLE_FLAGS_POLAR )
2689 : {
2690 4 : if ( ( pData->nPositionY >= 0x256 ) || ( pData->nPositionY <= 0x107 ) )
2691 4 : nAdjustmentsWhichNeedsToBeConverted |= ( 1 << k );
2692 : }
2693 : }
2694 : }
2695 332 : }
2696 :
2697 560 : bool EscherPropertyContainer::GetAdjustmentValue( const com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue & rkProp, sal_Int32 nIndex, sal_Int32 nAdjustmentsWhichNeedsToBeConverted, sal_Int32& nValue )
2698 : {
2699 560 : if ( rkProp.State != beans::PropertyState_DIRECT_VALUE )
2700 0 : return false;
2701 :
2702 560 : bool bUseFixedFloat = ( nAdjustmentsWhichNeedsToBeConverted & ( 1 << nIndex ) ) != 0;
2703 560 : if ( rkProp.Value.getValueTypeClass() == uno::TypeClass_DOUBLE )
2704 : {
2705 0 : double fValue(0.0);
2706 0 : rkProp.Value >>= fValue;
2707 0 : if ( bUseFixedFloat )
2708 0 : fValue *= 65536.0;
2709 0 : nValue = (sal_Int32)fValue;
2710 : }
2711 : else
2712 : {
2713 560 : rkProp.Value >>= nValue;
2714 560 : if ( bUseFixedFloat )
2715 4 : nValue <<= 16;
2716 : }
2717 :
2718 560 : return true;
2719 : }
2720 :
2721 748 : void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeType, const uno::Reference< drawing::XShape > & rXShape )
2722 : {
2723 748 : uno::Reference< beans::XPropertySet > aXPropSet( rXShape, uno::UNO_QUERY );
2724 748 : if ( aXPropSet.is() )
2725 : {
2726 748 : SdrObjCustomShape* pCustoShape = static_cast<SdrObjCustomShape*>(GetSdrObjectFromXShape( rXShape ));
2727 1496 : if ( !pCustoShape ) return;
2728 748 : const OUString sCustomShapeGeometry( "CustomShapeGeometry" );
2729 1496 : uno::Any aGeoPropSet = aXPropSet->getPropertyValue( sCustomShapeGeometry );
2730 1496 : uno::Sequence< beans::PropertyValue > aGeoPropSeq;
2731 748 : if ( aGeoPropSet >>= aGeoPropSeq )
2732 : {
2733 748 : const OUString sViewBox ( "ViewBox" );
2734 1496 : const OUString sTextRotateAngle ( "TextRotateAngle" );
2735 1496 : const OUString sExtrusion ( "Extrusion" );
2736 1496 : const OUString sEquations ( "Equations" );
2737 1496 : const OUString sPath ( "Path" );
2738 1496 : const OUString sTextPath ( "TextPath" );
2739 1496 : const OUString sHandles ( "Handles" );
2740 1496 : const OUString sAdjustmentValues ( "AdjustmentValues" );
2741 :
2742 748 : bool bAdjustmentValuesProp = false;
2743 1496 : uno::Any aAdjustmentValuesProp;
2744 748 : bool bPathCoordinatesProp = false;
2745 1496 : uno::Any aPathCoordinatesProp;
2746 :
2747 748 : sal_Int32 nAdjustmentsWhichNeedsToBeConverted = 0;
2748 1496 : uno::Sequence< beans::PropertyValues > aHandlesPropSeq;
2749 748 : bool bPredefinedHandlesUsed = true;
2750 748 : bool bIsDefaultObject = IsDefaultObject( pCustoShape , eShapeType);
2751 :
2752 : // convert property "Equations" into std::vector< EnhancedCustomShapeEquationEquation >
2753 1496 : std::vector< EnhancedCustomShapeEquation > aEquations;
2754 1496 : std::vector< sal_Int32 > aEquationOrder;
2755 748 : ConvertEnhancedCustomShapeEquation( pCustoShape, aEquations, aEquationOrder );
2756 :
2757 748 : sal_Int32 i, nCount = aGeoPropSeq.getLength();
2758 7516 : for ( i = 0; i < nCount; i++ )
2759 : {
2760 6768 : const beans::PropertyValue& rProp = aGeoPropSeq[ i ];
2761 6768 : if ( rProp.Name.equals( sViewBox ) )
2762 : {
2763 736 : if ( !bIsDefaultObject )
2764 : {
2765 548 : awt::Rectangle aViewBox;
2766 548 : if ( rProp.Value >>= aViewBox )
2767 : {
2768 548 : AddOpt( DFF_Prop_geoLeft, aViewBox.X );
2769 548 : AddOpt( DFF_Prop_geoTop, aViewBox.Y );
2770 548 : AddOpt( DFF_Prop_geoRight, aViewBox.X + aViewBox.Width );
2771 548 : AddOpt( DFF_Prop_geoBottom,aViewBox.Y + aViewBox.Height );
2772 : }
2773 : }
2774 : }
2775 6032 : else if ( rProp.Name.equals( sTextRotateAngle ) )
2776 : {
2777 0 : double f = 0;
2778 0 : if ( rProp.Value >>= f )
2779 : {
2780 0 : double fTextRotateAngle = fmod( f, 360.0 );
2781 0 : if ( fTextRotateAngle < 0 )
2782 0 : fTextRotateAngle = 360 + fTextRotateAngle;
2783 0 : if ( ( fTextRotateAngle < 271.0 ) && ( fTextRotateAngle > 269.0 ) )
2784 0 : AddOpt( DFF_Prop_cdirFont, mso_cdir90 );
2785 0 : else if ( ( fTextRotateAngle < 181.0 ) && ( fTextRotateAngle > 179.0 ) )
2786 0 : AddOpt( DFF_Prop_cdirFont, mso_cdir180 );
2787 0 : else if ( ( fTextRotateAngle < 91.0 ) && ( fTextRotateAngle > 79.0 ) )
2788 0 : AddOpt( DFF_Prop_cdirFont, mso_cdir270 );
2789 : }
2790 : }
2791 6032 : else if ( rProp.Name.equals( sExtrusion ) )
2792 : {
2793 0 : uno::Sequence< beans::PropertyValue > aExtrusionPropSeq;
2794 0 : if ( rProp.Value >>= aExtrusionPropSeq )
2795 : {
2796 : sal_uInt32 nLightFaceFlagsOrg, nLightFaceFlags;
2797 : sal_uInt32 nFillHarshFlagsOrg, nFillHarshFlags;
2798 0 : nLightFaceFlagsOrg = nLightFaceFlags = 0x000001;
2799 0 : nFillHarshFlagsOrg = nFillHarshFlags = 0x00001e;
2800 0 : if ( GetOpt( DFF_Prop_fc3DLightFace, nLightFaceFlags ) )
2801 0 : nLightFaceFlagsOrg = nLightFaceFlags;
2802 0 : if ( GetOpt( DFF_Prop_fc3DFillHarsh, nFillHarshFlags ) )
2803 0 : nFillHarshFlagsOrg = nFillHarshFlags;
2804 :
2805 0 : sal_Int32 r, nrCount = aExtrusionPropSeq.getLength();
2806 0 : for ( r = 0; r < nrCount; r++ )
2807 : {
2808 0 : const beans::PropertyValue& rrProp = aExtrusionPropSeq[ r ];
2809 0 : const OUString sExtrusionBrightness ( "Brightness" );
2810 0 : const OUString sExtrusionDepth ( "Depth" );
2811 0 : const OUString sExtrusionDiffusion ( "Diffusion" );
2812 0 : const OUString sExtrusionNumberOfLineSegments ( "NumberOfLineSegments" );
2813 0 : const OUString sExtrusionLightFace ( "LightFace" );
2814 0 : const OUString sExtrusionFirstLightHarsh ( "FirstLightHarsh" );
2815 0 : const OUString sExtrusionSecondLightHarsh ( "SecondLightHarsh" );
2816 0 : const OUString sExtrusionFirstLightLevel ( "FirstLightLevel" );
2817 0 : const OUString sExtrusionSecondLightLevel ( "SecondLightLevel" );
2818 0 : const OUString sExtrusionFirstLightDirection ( "FirstLightDirection" );
2819 0 : const OUString sExtrusionSecondLightDirection ( "SecondLightDirection" );
2820 0 : const OUString sExtrusionMetal ( "Metal" );
2821 0 : const OUString sExtrusionShadeMode ( "ShadeMode" );
2822 0 : const OUString sExtrusionRotateAngle ( "RotateAngle" );
2823 0 : const OUString sExtrusionRotationCenter ( "RotationCenter" );
2824 0 : const OUString sExtrusionShininess ( "Shininess" );
2825 0 : const OUString sExtrusionSkew ( "Skew" );
2826 0 : const OUString sExtrusionSpecularity ( "Specularity" );
2827 0 : const OUString sExtrusionProjectionMode ( "ProjectionMode" );
2828 0 : const OUString sExtrusionViewPoint ( "ViewPoint" );
2829 0 : const OUString sExtrusionOrigin ( "Origin" );
2830 0 : const OUString sExtrusionColor ( "Color" );
2831 :
2832 0 : if ( rrProp.Name.equals( sExtrusion ) )
2833 : {
2834 : bool bExtrusionOn;
2835 0 : if ( rrProp.Value >>= bExtrusionOn )
2836 : {
2837 0 : nLightFaceFlags |= 0x80000;
2838 0 : if ( bExtrusionOn )
2839 0 : nLightFaceFlags |= 8;
2840 : else
2841 0 : nLightFaceFlags &=~8;
2842 : }
2843 : }
2844 0 : else if ( rrProp.Name.equals( sExtrusionBrightness ) )
2845 : {
2846 0 : double fExtrusionBrightness = 0;
2847 0 : if ( rrProp.Value >>= fExtrusionBrightness )
2848 0 : AddOpt( DFF_Prop_c3DAmbientIntensity, (sal_Int32)( fExtrusionBrightness * 655.36 ) );
2849 : }
2850 0 : else if ( rrProp.Name.equals( sExtrusionDepth ) )
2851 : {
2852 0 : double fDepth = 0;
2853 0 : double fFraction = 0;
2854 0 : com::sun::star::drawing::EnhancedCustomShapeParameterPair aDepthParaPair;
2855 0 : if ( ( rrProp.Value >>= aDepthParaPair ) && ( aDepthParaPair.First.Value >>= fDepth ) && ( aDepthParaPair.Second.Value >>= fFraction ) )
2856 : {
2857 0 : double fForeDepth = fDepth * fFraction;
2858 0 : double fBackDepth = fDepth - fForeDepth;
2859 :
2860 0 : fBackDepth *= 360.0;
2861 0 : AddOpt( DFF_Prop_c3DExtrudeBackward, (sal_Int32)fBackDepth );
2862 :
2863 0 : if ( fForeDepth != 0.0 )
2864 : {
2865 0 : fForeDepth *= 360.0;
2866 0 : AddOpt( DFF_Prop_c3DExtrudeForward, (sal_Int32)fForeDepth );
2867 : }
2868 0 : }
2869 : }
2870 0 : else if ( rrProp.Name.equals( sExtrusionDiffusion ) )
2871 : {
2872 0 : double fExtrusionDiffusion = 0;
2873 0 : if ( rrProp.Value >>= fExtrusionDiffusion )
2874 0 : AddOpt( DFF_Prop_c3DDiffuseAmt, (sal_Int32)( fExtrusionDiffusion * 655.36 ) );
2875 : }
2876 0 : else if ( rrProp.Name.equals( sExtrusionNumberOfLineSegments ) )
2877 : {
2878 0 : sal_Int32 nExtrusionNumberOfLineSegments = 0;
2879 0 : if ( rrProp.Value >>= nExtrusionNumberOfLineSegments )
2880 0 : AddOpt( DFF_Prop_c3DTolerance, nExtrusionNumberOfLineSegments );
2881 : }
2882 0 : else if ( rrProp.Name.equals( sExtrusionLightFace ) )
2883 : {
2884 : bool bExtrusionLightFace;
2885 0 : if ( rrProp.Value >>= bExtrusionLightFace )
2886 : {
2887 0 : nLightFaceFlags |= 0x10000;
2888 0 : if ( bExtrusionLightFace )
2889 0 : nLightFaceFlags |= 1;
2890 : else
2891 0 : nLightFaceFlags &=~1;
2892 : }
2893 : }
2894 0 : else if ( rrProp.Name.equals( sExtrusionFirstLightHarsh ) )
2895 : {
2896 : bool bExtrusionFirstLightHarsh;
2897 0 : if ( rrProp.Value >>= bExtrusionFirstLightHarsh )
2898 : {
2899 0 : nFillHarshFlags |= 0x20000;
2900 0 : if ( bExtrusionFirstLightHarsh )
2901 0 : nFillHarshFlags |= 2;
2902 : else
2903 0 : nFillHarshFlags &=~2;
2904 : }
2905 : }
2906 0 : else if ( rrProp.Name.equals( sExtrusionSecondLightHarsh ) )
2907 : {
2908 : bool bExtrusionSecondLightHarsh;
2909 0 : if ( rrProp.Value >>= bExtrusionSecondLightHarsh )
2910 : {
2911 0 : nFillHarshFlags |= 0x10000;
2912 0 : if ( bExtrusionSecondLightHarsh )
2913 0 : nFillHarshFlags |= 1;
2914 : else
2915 0 : nFillHarshFlags &=~1;
2916 : }
2917 : }
2918 0 : else if ( rrProp.Name.equals( sExtrusionFirstLightLevel ) )
2919 : {
2920 0 : double fExtrusionFirstLightLevel = 0;
2921 0 : if ( rrProp.Value >>= fExtrusionFirstLightLevel )
2922 0 : AddOpt( DFF_Prop_c3DKeyIntensity, (sal_Int32)( fExtrusionFirstLightLevel * 655.36 ) );
2923 : }
2924 0 : else if ( rrProp.Name.equals( sExtrusionSecondLightLevel ) )
2925 : {
2926 0 : double fExtrusionSecondLightLevel = 0;
2927 0 : if ( rrProp.Value >>= fExtrusionSecondLightLevel )
2928 0 : AddOpt( DFF_Prop_c3DFillIntensity, (sal_Int32)( fExtrusionSecondLightLevel * 655.36 ) );
2929 : }
2930 0 : else if ( rrProp.Name.equals( sExtrusionFirstLightDirection ) )
2931 : {
2932 0 : drawing::Direction3D aExtrusionFirstLightDirection;
2933 0 : if ( rrProp.Value >>= aExtrusionFirstLightDirection )
2934 : {
2935 0 : AddOpt( DFF_Prop_c3DKeyX, (sal_Int32)aExtrusionFirstLightDirection.DirectionX );
2936 0 : AddOpt( DFF_Prop_c3DKeyY, (sal_Int32)aExtrusionFirstLightDirection.DirectionY );
2937 0 : AddOpt( DFF_Prop_c3DKeyZ, (sal_Int32)aExtrusionFirstLightDirection.DirectionZ );
2938 : }
2939 : }
2940 0 : else if ( rrProp.Name.equals( sExtrusionSecondLightDirection ) )
2941 : {
2942 0 : drawing::Direction3D aExtrusionSecondLightPosition;
2943 0 : if ( rrProp.Value >>= aExtrusionSecondLightPosition )
2944 : {
2945 0 : AddOpt( DFF_Prop_c3DFillX, (sal_Int32)aExtrusionSecondLightPosition.DirectionX );
2946 0 : AddOpt( DFF_Prop_c3DFillY, (sal_Int32)aExtrusionSecondLightPosition.DirectionY );
2947 0 : AddOpt( DFF_Prop_c3DFillZ, (sal_Int32)aExtrusionSecondLightPosition.DirectionZ );
2948 : }
2949 : }
2950 0 : else if ( rrProp.Name.equals( sExtrusionMetal ) )
2951 : {
2952 : bool bExtrusionMetal;
2953 0 : if ( rrProp.Value >>= bExtrusionMetal )
2954 : {
2955 0 : nLightFaceFlags |= 0x40000;
2956 0 : if ( bExtrusionMetal )
2957 0 : nLightFaceFlags |= 4;
2958 : else
2959 0 : nLightFaceFlags &=~4;
2960 : }
2961 : }
2962 0 : else if ( rrProp.Name.equals( sExtrusionShadeMode ) )
2963 : {
2964 : drawing::ShadeMode eExtrusionShadeMode;
2965 0 : if ( rrProp.Value >>= eExtrusionShadeMode )
2966 : {
2967 : sal_uInt32 nRenderMode;
2968 0 : switch( eExtrusionShadeMode )
2969 : {
2970 : default:
2971 : case drawing::ShadeMode_FLAT :
2972 : case drawing::ShadeMode_PHONG :
2973 : case drawing::ShadeMode_SMOOTH :
2974 0 : nRenderMode = mso_FullRender;
2975 0 : break;
2976 : case drawing::ShadeMode_DRAFT :
2977 : {
2978 0 : nRenderMode = mso_Wireframe;
2979 : }
2980 0 : break;
2981 : }
2982 0 : AddOpt( DFF_Prop_c3DRenderMode, nRenderMode );
2983 : }
2984 : }
2985 0 : else if ( rrProp.Name.equals( sExtrusionRotateAngle ) )
2986 : {
2987 0 : double fExtrusionAngleX = 0;
2988 0 : double fExtrusionAngleY = 0;
2989 0 : com::sun::star::drawing::EnhancedCustomShapeParameterPair aRotateAnglePair;
2990 0 : if ( ( rrProp.Value >>= aRotateAnglePair ) && ( aRotateAnglePair.First.Value >>= fExtrusionAngleX ) && ( aRotateAnglePair.Second.Value >>= fExtrusionAngleY ) )
2991 : {
2992 0 : fExtrusionAngleX *= 65536;
2993 0 : fExtrusionAngleY *= 65536;
2994 0 : AddOpt( DFF_Prop_c3DXRotationAngle, (sal_Int32)fExtrusionAngleX );
2995 0 : AddOpt( DFF_Prop_c3DYRotationAngle, (sal_Int32)fExtrusionAngleY );
2996 0 : }
2997 : }
2998 0 : else if ( rrProp.Name.equals( sExtrusionRotationCenter ) )
2999 : {
3000 0 : drawing::Direction3D aExtrusionRotationCenter;
3001 0 : if ( rrProp.Value >>= aExtrusionRotationCenter )
3002 : {
3003 0 : AddOpt( DFF_Prop_c3DRotationCenterX, (sal_Int32)( aExtrusionRotationCenter.DirectionX * 360.0 ) );
3004 0 : AddOpt( DFF_Prop_c3DRotationCenterY, (sal_Int32)( aExtrusionRotationCenter.DirectionY * 360.0 ) );
3005 0 : AddOpt( DFF_Prop_c3DRotationCenterZ, (sal_Int32)( aExtrusionRotationCenter.DirectionZ * 360.0 ) );
3006 0 : nFillHarshFlags &=~8; // don't use AutoRotationCenter;
3007 : }
3008 : }
3009 0 : else if ( rrProp.Name.equals( sExtrusionShininess ) )
3010 : {
3011 0 : double fExtrusionShininess = 0;
3012 0 : if ( rrProp.Value >>= fExtrusionShininess )
3013 0 : AddOpt( DFF_Prop_c3DShininess, (sal_Int32)( fExtrusionShininess * 655.36 ) );
3014 : }
3015 0 : else if ( rrProp.Name.equals( sExtrusionSkew ) )
3016 : {
3017 0 : double fSkewAmount = 0;
3018 0 : double fSkewAngle = 0;
3019 0 : com::sun::star::drawing::EnhancedCustomShapeParameterPair aSkewParaPair;
3020 0 : if ( ( rrProp.Value >>= aSkewParaPair ) && ( aSkewParaPair.First.Value >>= fSkewAmount ) && ( aSkewParaPair.Second.Value >>= fSkewAngle ) )
3021 : {
3022 0 : AddOpt( DFF_Prop_c3DSkewAmount, (sal_Int32)fSkewAmount );
3023 0 : AddOpt( DFF_Prop_c3DSkewAngle, (sal_Int32)( fSkewAngle * 65536 ) );
3024 0 : }
3025 : }
3026 0 : else if ( rrProp.Name.equals( sExtrusionSpecularity ) )
3027 : {
3028 0 : double fExtrusionSpecularity = 0;
3029 0 : if ( rrProp.Value >>= fExtrusionSpecularity )
3030 0 : AddOpt( DFF_Prop_c3DSpecularAmt, (sal_Int32)( fExtrusionSpecularity * 1333 ) );
3031 : }
3032 0 : else if ( rrProp.Name.equals( sExtrusionProjectionMode ) )
3033 : {
3034 : drawing::ProjectionMode eExtrusionProjectionMode;
3035 0 : if ( rrProp.Value >>= eExtrusionProjectionMode )
3036 : {
3037 0 : nFillHarshFlags |= 0x40000;
3038 0 : if ( eExtrusionProjectionMode == drawing::ProjectionMode_PARALLEL )
3039 0 : nFillHarshFlags |= 4;
3040 : else
3041 0 : nFillHarshFlags &=~4;
3042 : }
3043 : }
3044 0 : else if ( rrProp.Name.equals( sExtrusionViewPoint ) )
3045 : {
3046 0 : drawing::Position3D aExtrusionViewPoint;
3047 0 : if ( rrProp.Value >>= aExtrusionViewPoint )
3048 : {
3049 0 : aExtrusionViewPoint.PositionX *= 360.0;
3050 0 : aExtrusionViewPoint.PositionY *= 360.0;
3051 0 : aExtrusionViewPoint.PositionZ *= 360.0;
3052 0 : AddOpt( DFF_Prop_c3DXViewpoint, (sal_Int32)aExtrusionViewPoint.PositionX );
3053 0 : AddOpt( DFF_Prop_c3DYViewpoint, (sal_Int32)aExtrusionViewPoint.PositionY );
3054 0 : AddOpt( DFF_Prop_c3DZViewpoint, (sal_Int32)aExtrusionViewPoint.PositionZ );
3055 : }
3056 : }
3057 0 : else if ( rrProp.Name.equals( sExtrusionOrigin ) )
3058 : {
3059 0 : double fExtrusionOriginX = 0;
3060 0 : double fExtrusionOriginY = 0;
3061 0 : com::sun::star::drawing::EnhancedCustomShapeParameterPair aOriginPair;
3062 0 : if ( ( rrProp.Value >>= aOriginPair ) && ( aOriginPair.First.Value >>= fExtrusionOriginX ) && ( aOriginPair.Second.Value >>= fExtrusionOriginY ) )
3063 : {
3064 0 : AddOpt( DFF_Prop_c3DOriginX, (sal_Int32)( fExtrusionOriginX * 65536 ) );
3065 0 : AddOpt( DFF_Prop_c3DOriginY, (sal_Int32)( fExtrusionOriginY * 65536 ) );
3066 0 : }
3067 : }
3068 0 : else if ( rrProp.Name.equals( sExtrusionColor ) )
3069 : {
3070 : bool bExtrusionColor;
3071 0 : if ( rrProp.Value >>= bExtrusionColor )
3072 : {
3073 0 : nLightFaceFlags |= 0x20000;
3074 0 : if ( bExtrusionColor )
3075 : {
3076 0 : nLightFaceFlags |= 2;
3077 0 : uno::Any aFillColor2;
3078 0 : if ( EscherPropertyValueHelper::GetPropertyValue( aFillColor2, aXPropSet, OUString( "FillColor2" ), true ) )
3079 : {
3080 0 : sal_uInt32 nFillColor = ImplGetColor( *((sal_uInt32*)aFillColor2.getValue()) );
3081 0 : AddOpt( DFF_Prop_c3DExtrusionColor, nFillColor );
3082 0 : }
3083 : }
3084 : else
3085 0 : nLightFaceFlags &=~2;
3086 : }
3087 : }
3088 0 : }
3089 0 : if ( nLightFaceFlags != nLightFaceFlagsOrg )
3090 0 : AddOpt( DFF_Prop_fc3DLightFace, nLightFaceFlags );
3091 0 : if ( nFillHarshFlags != nFillHarshFlagsOrg )
3092 0 : AddOpt( DFF_Prop_fc3DFillHarsh, nFillHarshFlags );
3093 0 : }
3094 : }
3095 6032 : else if ( rProp.Name.equals( sEquations ) )
3096 : {
3097 598 : if ( !bIsDefaultObject )
3098 : {
3099 544 : sal_uInt16 nElements = (sal_uInt16)aEquations.size();
3100 544 : if ( nElements )
3101 : {
3102 544 : sal_uInt16 nElementSize = 8;
3103 544 : sal_uInt32 nStreamSize = nElementSize * nElements + 6;
3104 544 : SvMemoryStream aOut( nStreamSize );
3105 544 : aOut.WriteUInt16( nElements )
3106 1088 : .WriteUInt16( nElements )
3107 1088 : .WriteUInt16( nElementSize );
3108 :
3109 544 : std::vector< EnhancedCustomShapeEquation >::const_iterator aIter( aEquations.begin() );
3110 544 : std::vector< EnhancedCustomShapeEquation >::const_iterator aEnd ( aEquations.end() );
3111 8522 : while( aIter != aEnd )
3112 : {
3113 7434 : aOut.WriteUInt16( aIter->nOperation )
3114 14868 : .WriteInt16( aIter->nPara[ 0 ] )
3115 14868 : .WriteInt16( aIter->nPara[ 1 ] )
3116 14868 : .WriteInt16( aIter->nPara[ 2 ] );
3117 7434 : ++aIter;
3118 : }
3119 544 : sal_uInt8* pBuf = new sal_uInt8[ nStreamSize ];
3120 544 : memcpy( pBuf, aOut.GetData(), nStreamSize );
3121 544 : AddOpt( DFF_Prop_pFormulas, true, nStreamSize - 6, pBuf, nStreamSize );
3122 : }
3123 : else
3124 : {
3125 0 : sal_uInt8* pBuf = new sal_uInt8[ 1 ];
3126 0 : AddOpt( DFF_Prop_pFormulas, true, 0, pBuf, 0 );
3127 : }
3128 : }
3129 : }
3130 5434 : else if ( rProp.Name.equals( sPath ) )
3131 : {
3132 736 : uno::Sequence< beans::PropertyValue > aPathPropSeq;
3133 736 : if ( rProp.Value >>= aPathPropSeq )
3134 : {
3135 : sal_uInt32 nPathFlags, nPathFlagsOrg;
3136 736 : nPathFlagsOrg = nPathFlags = 0x39;
3137 736 : if ( GetOpt( DFF_Prop_fFillOK, nPathFlags ) )
3138 34 : nPathFlagsOrg = nPathFlags;
3139 :
3140 736 : sal_Int32 r, nrCount = aPathPropSeq.getLength();
3141 2868 : for ( r = 0; r < nrCount; r++ )
3142 : {
3143 2132 : const beans::PropertyValue& rrProp = aPathPropSeq[ r ];
3144 2132 : const OUString sPathExtrusionAllowed ( "ExtrusionAllowed" );
3145 4264 : const OUString sPathConcentricGradientFillAllowed ( "ConcentricGradientFillAllowed" );
3146 4264 : const OUString sPathTextPathAllowed ( "TextPathAllowed" );
3147 4264 : const OUString sPathCoordinates ( "Coordinates" );
3148 4264 : const OUString sPathGluePoints ( "GluePoints" );
3149 4264 : const OUString sPathGluePointType ( "GluePointType" );
3150 4264 : const OUString sPathSegments ( "Segments" );
3151 4264 : const OUString sPathStretchX ( "StretchX" );
3152 4264 : const OUString sPathStretchY ( "StretchY" );
3153 4264 : const OUString sPathTextFrames ( "TextFrames" );
3154 :
3155 2132 : if ( rrProp.Name.equals( sPathExtrusionAllowed ) )
3156 : {
3157 : bool bExtrusionAllowed;
3158 0 : if ( rrProp.Value >>= bExtrusionAllowed )
3159 : {
3160 0 : nPathFlags |= 0x100000;
3161 0 : if ( bExtrusionAllowed )
3162 0 : nPathFlags |= 16;
3163 : else
3164 0 : nPathFlags &=~16;
3165 : }
3166 : }
3167 2132 : else if ( rrProp.Name.equals( sPathConcentricGradientFillAllowed ) )
3168 : {
3169 : bool bConcentricGradientFillAllowed;
3170 0 : if ( rrProp.Value >>= bConcentricGradientFillAllowed )
3171 : {
3172 0 : nPathFlags |= 0x20000;
3173 0 : if ( bConcentricGradientFillAllowed )
3174 0 : nPathFlags |= 2;
3175 : else
3176 0 : nPathFlags &=~2;
3177 : }
3178 : }
3179 2132 : else if ( rrProp.Name.equals( sPathTextPathAllowed ) )
3180 : {
3181 : bool bTextPathAllowed;
3182 0 : if ( rrProp.Value >>= bTextPathAllowed )
3183 : {
3184 0 : nPathFlags |= 0x40000;
3185 0 : if ( bTextPathAllowed )
3186 0 : nPathFlags |= 4;
3187 : else
3188 0 : nPathFlags &=~4;
3189 : }
3190 : }
3191 2132 : else if ( rrProp.Name.equals( sPathCoordinates ) )
3192 : {
3193 736 : if ( !bIsDefaultObject )
3194 : {
3195 548 : aPathCoordinatesProp = rrProp.Value;
3196 548 : bPathCoordinatesProp = true;
3197 : }
3198 : }
3199 1396 : else if ( rrProp.Name.equals( sPathGluePoints ) )
3200 : {
3201 20 : if ( !bIsDefaultObject )
3202 : {
3203 0 : com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair> aGluePoints;
3204 0 : if ( rrProp.Value >>= aGluePoints )
3205 : {
3206 : // creating the vertices
3207 0 : sal_uInt16 nElements = (sal_uInt16)aGluePoints.getLength();
3208 0 : if ( nElements )
3209 : {
3210 0 : sal_uInt16 j, nElementSize = 8;
3211 0 : sal_uInt32 nStreamSize = nElementSize * nElements + 6;
3212 0 : SvMemoryStream aOut( nStreamSize );
3213 0 : aOut.WriteUInt16( nElements )
3214 0 : .WriteUInt16( nElements )
3215 0 : .WriteUInt16( nElementSize );
3216 0 : for( j = 0; j < nElements; j++ )
3217 : {
3218 0 : sal_Int32 X = GetValueForEnhancedCustomShapeParameter( aGluePoints[ j ].First, aEquationOrder );
3219 0 : sal_Int32 Y = GetValueForEnhancedCustomShapeParameter( aGluePoints[ j ].Second, aEquationOrder );
3220 0 : aOut.WriteInt32( X )
3221 0 : .WriteInt32( Y );
3222 : }
3223 0 : sal_uInt8* pBuf = new sal_uInt8[ nStreamSize ];
3224 0 : memcpy( pBuf, aOut.GetData(), nStreamSize );
3225 0 : AddOpt( DFF_Prop_connectorPoints, true, nStreamSize - 6, pBuf, nStreamSize ); // -6
3226 : }
3227 : else
3228 : {
3229 0 : sal_uInt8* pBuf = new sal_uInt8[ 1 ];
3230 0 : AddOpt( DFF_Prop_connectorPoints, true, 0, pBuf, 0 );
3231 : }
3232 0 : }
3233 : }
3234 : }
3235 1376 : else if ( rrProp.Name.equals( sPathGluePointType ) )
3236 : {
3237 0 : sal_Int16 nGluePointType = sal_Int16();
3238 0 : if ( rrProp.Value >>= nGluePointType )
3239 0 : AddOpt( DFF_Prop_connectorType, (sal_uInt16)nGluePointType );
3240 : }
3241 1376 : else if ( rrProp.Name.equals( sPathSegments ) )
3242 : {
3243 722 : if ( !bIsDefaultObject )
3244 : {
3245 548 : com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeSegment > aSegments;
3246 548 : if ( rrProp.Value >>= aSegments )
3247 : {
3248 : // creating seginfo
3249 548 : if ( (sal_uInt16)aSegments.getLength() )
3250 : {
3251 548 : sal_uInt16 j, nElements = (sal_uInt16)aSegments.getLength();
3252 548 : sal_uInt16 nElementSize = 2;
3253 548 : sal_uInt32 nStreamSize = nElementSize * nElements + 6;
3254 548 : SvMemoryStream aOut( nStreamSize );
3255 548 : aOut.WriteUInt16( nElements )
3256 1096 : .WriteUInt16( nElements )
3257 1096 : .WriteUInt16( nElementSize );
3258 3762 : for ( j = 0; j < nElements; j++ )
3259 : {
3260 3214 : sal_uInt16 nVal = (sal_uInt16)aSegments[ j ].Count;
3261 3214 : switch( aSegments[ j ].Command )
3262 : {
3263 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::UNKNOWN :
3264 868 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::LINETO : break;
3265 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::MOVETO :
3266 : {
3267 560 : nVal = 0x4000;
3268 : }
3269 560 : break;
3270 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::CURVETO :
3271 : {
3272 24 : nVal |= 0x2000;
3273 : }
3274 24 : break;
3275 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::CLOSESUBPATH :
3276 : {
3277 506 : nVal = 0x6001;
3278 : }
3279 506 : break;
3280 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ENDSUBPATH :
3281 : {
3282 552 : nVal = 0x8000;
3283 : }
3284 552 : break;
3285 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::NOFILL :
3286 : {
3287 4 : nVal = 0xaa00;
3288 : }
3289 4 : break;
3290 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::NOSTROKE :
3291 : {
3292 4 : nVal = 0xab00;
3293 : }
3294 4 : break;
3295 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ANGLEELLIPSETO :
3296 : {
3297 0 : nVal *= 3;
3298 0 : nVal |= 0xa100;
3299 : }
3300 0 : break;
3301 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ANGLEELLIPSE :
3302 : {
3303 0 : nVal *= 3;
3304 0 : nVal |= 0xa200;
3305 : }
3306 0 : break;
3307 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ARCTO :
3308 : {
3309 0 : nVal <<= 2;
3310 0 : nVal |= 0xa300;
3311 : }
3312 0 : break;
3313 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ARC :
3314 : {
3315 0 : nVal <<= 2;
3316 0 : nVal |= 0xa400;
3317 : }
3318 0 : break;
3319 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::CLOCKWISEARCTO :
3320 : {
3321 0 : nVal <<= 2;
3322 0 : nVal |= 0xa500;
3323 : }
3324 0 : break;
3325 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::CLOCKWISEARC :
3326 : {
3327 0 : nVal <<= 2;
3328 0 : nVal |= 0xa600;
3329 : }
3330 0 : break;
3331 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTX :
3332 : {
3333 0 : nVal |= 0xa700;
3334 : }
3335 0 : break;
3336 : case com::sun::star::drawing::EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTY :
3337 : {
3338 0 : nVal |= 0xa800;
3339 : }
3340 0 : break;
3341 : }
3342 3214 : aOut.WriteUInt16( nVal );
3343 : }
3344 548 : sal_uInt8* pBuf = new sal_uInt8[ nStreamSize ];
3345 548 : memcpy( pBuf, aOut.GetData(), nStreamSize );
3346 548 : AddOpt( DFF_Prop_pSegmentInfo, false, nStreamSize - 6, pBuf, nStreamSize );
3347 : }
3348 : else
3349 : {
3350 0 : sal_uInt8* pBuf = new sal_uInt8[ 1 ];
3351 0 : AddOpt( DFF_Prop_pSegmentInfo, true, 0, pBuf, 0 );
3352 : }
3353 548 : }
3354 : }
3355 : }
3356 654 : else if ( rrProp.Name.equals( sPathStretchX ) )
3357 : {
3358 0 : if ( !bIsDefaultObject )
3359 : {
3360 0 : sal_Int32 nStretchX = 0;
3361 0 : if ( rrProp.Value >>= nStretchX )
3362 0 : AddOpt( DFF_Prop_stretchPointX, nStretchX );
3363 : }
3364 : }
3365 654 : else if ( rrProp.Name.equals( sPathStretchY ) )
3366 : {
3367 0 : if ( !bIsDefaultObject )
3368 : {
3369 0 : sal_Int32 nStretchY = 0;
3370 0 : if ( rrProp.Value >>= nStretchY )
3371 0 : AddOpt( DFF_Prop_stretchPointY, nStretchY );
3372 : }
3373 : }
3374 654 : else if ( rrProp.Name.equals( sPathTextFrames ) )
3375 : {
3376 602 : if ( !bIsDefaultObject )
3377 : {
3378 544 : com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeTextFrame > aPathTextFrames;
3379 544 : if ( rrProp.Value >>= aPathTextFrames )
3380 : {
3381 544 : if ( (sal_uInt16)aPathTextFrames.getLength() )
3382 : {
3383 544 : sal_uInt16 j, nElements = (sal_uInt16)aPathTextFrames.getLength();
3384 544 : sal_uInt16 nElementSize = 16;
3385 544 : sal_uInt32 nStreamSize = nElementSize * nElements + 6;
3386 544 : SvMemoryStream aOut( nStreamSize );
3387 544 : aOut.WriteUInt16( nElements )
3388 1088 : .WriteUInt16( nElements )
3389 1088 : .WriteUInt16( nElementSize );
3390 1088 : for ( j = 0; j < nElements; j++ )
3391 : {
3392 544 : sal_Int32 nLeft = GetValueForEnhancedCustomShapeParameter( aPathTextFrames[ j ].TopLeft.First, aEquationOrder );
3393 544 : sal_Int32 nTop = GetValueForEnhancedCustomShapeParameter( aPathTextFrames[ j ].TopLeft.Second, aEquationOrder );
3394 544 : sal_Int32 nRight = GetValueForEnhancedCustomShapeParameter( aPathTextFrames[ j ].BottomRight.First, aEquationOrder );
3395 544 : sal_Int32 nBottom = GetValueForEnhancedCustomShapeParameter( aPathTextFrames[ j ].BottomRight.Second, aEquationOrder );
3396 :
3397 544 : aOut.WriteInt32( nLeft )
3398 544 : .WriteInt32( nTop )
3399 544 : .WriteInt32( nRight )
3400 544 : .WriteInt32( nBottom );
3401 : }
3402 544 : sal_uInt8* pBuf = new sal_uInt8[ nStreamSize ];
3403 544 : memcpy( pBuf, aOut.GetData(), nStreamSize );
3404 544 : AddOpt( DFF_Prop_textRectangles, true, nStreamSize - 6, pBuf, nStreamSize );
3405 : }
3406 : else
3407 : {
3408 0 : sal_uInt8* pBuf = new sal_uInt8[ 1 ];
3409 0 : AddOpt( DFF_Prop_textRectangles, true, 0, pBuf, 0 );
3410 : }
3411 544 : }
3412 : }
3413 : }
3414 2132 : }
3415 736 : if ( nPathFlags != nPathFlagsOrg )
3416 0 : AddOpt( DFF_Prop_fFillOK, nPathFlags );
3417 736 : }
3418 : }
3419 4698 : else if ( rProp.Name.equals( sTextPath ) )
3420 : {
3421 34 : uno::Sequence< beans::PropertyValue > aTextPathPropSeq;
3422 34 : if ( rProp.Value >>= aTextPathPropSeq )
3423 : {
3424 : sal_uInt32 nTextPathFlagsOrg, nTextPathFlags;
3425 34 : nTextPathFlagsOrg = nTextPathFlags = 0xffff1000; // default
3426 34 : if ( GetOpt( DFF_Prop_gtextFStrikethrough, nTextPathFlags ) )
3427 0 : nTextPathFlagsOrg = nTextPathFlags;
3428 :
3429 34 : sal_Int32 r, nrCount = aTextPathPropSeq.getLength();
3430 170 : for ( r = 0; r < nrCount; r++ )
3431 : {
3432 136 : const beans::PropertyValue& rrProp = aTextPathPropSeq[ r ];
3433 136 : const OUString sTextPathMode ( "TextPathMode" );
3434 272 : const OUString sTextPathScaleX ( "ScaleX" );
3435 272 : const OUString sSameLetterHeights ( "SameLetterHeights" );
3436 :
3437 136 : if ( rrProp.Name.equals( sTextPath ) )
3438 : {
3439 : bool bTextPathOn;
3440 34 : if ( rrProp.Value >>= bTextPathOn )
3441 : {
3442 34 : nTextPathFlags |= 0x40000000;
3443 34 : if ( bTextPathOn )
3444 : {
3445 34 : nTextPathFlags |= 0x4000;
3446 :
3447 34 : sal_uInt32 nPathFlags = 0x39;
3448 34 : GetOpt( DFF_Prop_fFillOK, nPathFlags ); // SJ: can be removed if we are supporting the TextPathAllowed property in XML
3449 34 : nPathFlags |= 0x40004;
3450 34 : AddOpt( DFF_Prop_fFillOK, nPathFlags );
3451 : }
3452 : else
3453 0 : nTextPathFlags &=~0x4000;
3454 : }
3455 : }
3456 102 : else if ( rrProp.Name.equals( sTextPathMode ) )
3457 : {
3458 : com::sun::star::drawing::EnhancedCustomShapeTextPathMode eTextPathMode;
3459 34 : if ( rrProp.Value >>= eTextPathMode )
3460 : {
3461 34 : nTextPathFlags |= 0x05000000;
3462 34 : nTextPathFlags &=~0x500; // TextPathMode_NORMAL
3463 34 : if ( eTextPathMode == com::sun::star::drawing::EnhancedCustomShapeTextPathMode_PATH )
3464 0 : nTextPathFlags |= 0x100;
3465 34 : else if ( eTextPathMode == com::sun::star::drawing::EnhancedCustomShapeTextPathMode_SHAPE )
3466 34 : nTextPathFlags |= 0x500;
3467 : }
3468 : }
3469 68 : else if ( rrProp.Name.equals( sTextPathScaleX ) )
3470 : {
3471 : bool bTextPathScaleX;
3472 34 : if ( rrProp.Value >>= bTextPathScaleX )
3473 : {
3474 34 : nTextPathFlags |= 0x00400000;
3475 34 : if ( bTextPathScaleX )
3476 0 : nTextPathFlags |= 0x40;
3477 : else
3478 34 : nTextPathFlags &=~0x40;
3479 : }
3480 : }
3481 34 : else if ( rrProp.Name.equals( sSameLetterHeights ) )
3482 : {
3483 : bool bSameLetterHeights;
3484 34 : if ( rrProp.Value >>= bSameLetterHeights )
3485 : {
3486 34 : nTextPathFlags |= 0x00800000;
3487 34 : if ( bSameLetterHeights )
3488 0 : nTextPathFlags |= 0x80;
3489 : else
3490 34 : nTextPathFlags &=~0x80;
3491 : }
3492 : }
3493 136 : }
3494 34 : if ( nTextPathFlags & 0x4000 ) // Is FontWork ?
3495 : {
3496 : // FontWork Text
3497 34 : OUString aText;
3498 68 : uno::Reference< text::XSimpleText > xText( rXShape, uno::UNO_QUERY );
3499 34 : if ( xText.is() )
3500 34 : aText = xText->getString();
3501 34 : if ( aText.isEmpty() )
3502 0 : aText = "your text"; // TODO: moving into a resource
3503 34 : AddOpt( DFF_Prop_gtextUNICODE, aText );
3504 :
3505 : // FontWork Font
3506 68 : OUString aFontName;
3507 68 : const OUString sCharFontName( "CharFontName" );
3508 68 : uno::Any aAny = aXPropSet->getPropertyValue( sCharFontName );
3509 34 : aAny >>= aFontName;
3510 34 : if ( aFontName.isEmpty() )
3511 0 : aFontName = "Arial Black";
3512 34 : AddOpt( DFF_Prop_gtextFont, aFontName );
3513 :
3514 34 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, OUString( "CharScaleWidth" ), true ) )
3515 : {
3516 34 : sal_Int16 nCharScaleWidth = 100;
3517 34 : if ( aAny >>= nCharScaleWidth )
3518 : {
3519 34 : if ( nCharScaleWidth != 100 )
3520 : {
3521 0 : sal_Int32 nVal = nCharScaleWidth * 655;
3522 0 : AddOpt( DFF_Prop_gtextSpacing, nVal );
3523 : }
3524 : }
3525 : }
3526 34 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, OUString( "CharHeight" ), true ) )
3527 : {
3528 34 : float fCharHeight = 0.0;
3529 34 : if ( aAny >>= fCharHeight )
3530 : {
3531 34 : sal_Int32 nTextSize = static_cast< sal_Int32 > ( fCharHeight * 65536 );
3532 34 : AddOpt(ESCHER_Prop_gtextSize, nTextSize);
3533 : }
3534 : }
3535 34 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, OUString( "CharKerning" ), true ) )
3536 : {
3537 34 : sal_Int16 nCharKerning = sal_Int16();
3538 34 : if ( aAny >>= nCharKerning )
3539 : {
3540 34 : nTextPathFlags |= 0x10000000;
3541 34 : if ( nCharKerning )
3542 0 : nTextPathFlags |= 0x1000;
3543 : else
3544 34 : nTextPathFlags &=~0x1000;
3545 : }
3546 : }
3547 34 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, OUString( "CharPosture" ), true ) )
3548 : {
3549 : awt::FontSlant eFontSlant;
3550 34 : if ( aAny >>= eFontSlant )
3551 : {
3552 34 : nTextPathFlags |= 0x100010;
3553 34 : if ( eFontSlant != awt::FontSlant_NONE )
3554 0 : nTextPathFlags |= 0x10;
3555 : else
3556 34 : nTextPathFlags &=~0x10;
3557 : }
3558 : }
3559 34 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, OUString( "CharWeight" ), true ) )
3560 : {
3561 34 : float fFontWidth = 0;
3562 34 : if ( aAny >>= fFontWidth )
3563 : {
3564 34 : nTextPathFlags |= 0x200020;
3565 34 : if ( fFontWidth > awt::FontWeight::NORMAL )
3566 0 : nTextPathFlags |= 0x20;
3567 : else
3568 34 : nTextPathFlags &=~0x20;
3569 : }
3570 : }
3571 : // export gTextAlign attr
3572 34 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aXPropSet, "TextHorizontalAdjust", true ) )
3573 : {
3574 34 : MSO_GeoTextAlign gTextAlign = mso_alignTextCenter;
3575 34 : drawing::TextHorizontalAdjust eHA( drawing::TextHorizontalAdjust_LEFT );
3576 34 : aAny >>= eHA;
3577 34 : switch( eHA )
3578 : {
3579 : case drawing::TextHorizontalAdjust_LEFT :
3580 0 : gTextAlign = mso_alignTextLeft;
3581 0 : break;
3582 : case drawing::TextHorizontalAdjust_CENTER:
3583 0 : gTextAlign = mso_alignTextCenter;
3584 0 : break;
3585 : case drawing::TextHorizontalAdjust_RIGHT:
3586 0 : gTextAlign = mso_alignTextRight;
3587 0 : break;
3588 : case drawing::TextHorizontalAdjust_BLOCK:
3589 : {
3590 34 : SdrFitToSizeType eFTS( static_cast<const SdrTextFitToSizeTypeItem&>(pCustoShape->GetMergedItem( SDRATTR_TEXT_FITTOSIZE )).GetValue() );
3591 34 : if ( eFTS == SDRTEXTFIT_ALLLINES)
3592 : {
3593 0 : gTextAlign = mso_alignTextStretch;
3594 : }
3595 : else
3596 : {
3597 34 : gTextAlign = mso_alignTextWordJust;
3598 : }
3599 34 : break;
3600 : }
3601 : default:
3602 0 : break;
3603 : }
3604 34 : AddOpt(DFF_Prop_gtextAlign,gTextAlign);
3605 34 : }
3606 : }
3607 34 : if((nTextPathFlags & 0x4000) != 0) // Is Font work
3608 : {
3609 34 : OutlinerParaObject* pOutlinerParaObject = pCustoShape->GetOutlinerParaObject();
3610 34 : if ( pOutlinerParaObject && pOutlinerParaObject->IsVertical() )
3611 0 : nTextPathFlags |= 0x2000;
3612 : }
3613 34 : if ( nTextPathFlags != nTextPathFlagsOrg )
3614 34 : AddOpt( DFF_Prop_gtextFStrikethrough, nTextPathFlags );
3615 34 : }
3616 : }
3617 4664 : else if ( rProp.Name.equals( sHandles ) )
3618 : {
3619 598 : if ( !bIsDefaultObject )
3620 : {
3621 544 : bPredefinedHandlesUsed = false;
3622 544 : if ( rProp.Value >>= aHandlesPropSeq )
3623 : {
3624 544 : sal_uInt16 nElements = (sal_uInt16)aHandlesPropSeq.getLength();
3625 544 : if ( nElements )
3626 : {
3627 200 : sal_uInt16 k, j, nElementSize = 36;
3628 200 : sal_uInt32 nStreamSize = nElementSize * nElements + 6;
3629 200 : SvMemoryStream aOut( nStreamSize );
3630 200 : aOut.WriteUInt16( nElements )
3631 400 : .WriteUInt16( nElements )
3632 400 : .WriteUInt16( nElementSize );
3633 :
3634 418 : for ( k = 0; k < nElements; k++ )
3635 : {
3636 218 : sal_uInt32 nFlags = 0;
3637 218 : sal_Int32 nXPosition = 0;
3638 218 : sal_Int32 nYPosition = 0;
3639 218 : sal_Int32 nXMap = 0;
3640 218 : sal_Int32 nYMap = 0;
3641 218 : sal_Int32 nXRangeMin = 0x80000000;
3642 218 : sal_Int32 nXRangeMax = 0x7fffffff;
3643 218 : sal_Int32 nYRangeMin = 0x80000000;
3644 218 : sal_Int32 nYRangeMax = 0x7fffffff;
3645 :
3646 218 : const uno::Sequence< beans::PropertyValue >& rPropSeq = aHandlesPropSeq[ k ];
3647 1090 : for ( j = 0; j < rPropSeq.getLength(); j++ )
3648 : {
3649 872 : const beans::PropertyValue& rPropVal = rPropSeq[ j ];
3650 :
3651 872 : const OUString sPosition ( "Position" );
3652 1744 : const OUString sMirroredX ( "MirroredX" );
3653 1744 : const OUString sMirroredY ( "MirroredY" );
3654 1744 : const OUString sSwitched ( "Switched" );
3655 1744 : const OUString sPolar ( "Polar" );
3656 1744 : const OUString sRadiusRangeMinimum ( "RadiusRangeMinimum" );
3657 1744 : const OUString sRadiusRangeMaximum ( "RadiusRangeMaximum" );
3658 1744 : const OUString sRangeXMinimum ( "RangeXMinimum" );
3659 1744 : const OUString sRangeXMaximum ( "RangeXMaximum" );
3660 1744 : const OUString sRangeYMinimum ( "RangeYMinimum" );
3661 1744 : const OUString sRangeYMaximum ( "RangeYMaximum" );
3662 :
3663 872 : if ( rPropVal.Name.equals( sPosition ) )
3664 : {
3665 218 : com::sun::star::drawing::EnhancedCustomShapeParameterPair aPosition;
3666 218 : if ( rPropVal.Value >>= aPosition )
3667 : {
3668 218 : GetValueForEnhancedCustomShapeHandleParameter( nXPosition, aPosition.First );
3669 218 : GetValueForEnhancedCustomShapeHandleParameter( nYPosition, aPosition.Second );
3670 218 : }
3671 : }
3672 654 : else if ( rPropVal.Name.equals( sMirroredX ) )
3673 : {
3674 : bool bMirroredX;
3675 0 : if ( rPropVal.Value >>= bMirroredX )
3676 : {
3677 0 : if ( bMirroredX )
3678 0 : nFlags |= 1;
3679 : }
3680 : }
3681 654 : else if ( rPropVal.Name.equals( sMirroredY ) )
3682 : {
3683 : bool bMirroredY;
3684 0 : if ( rPropVal.Value >>= bMirroredY )
3685 : {
3686 0 : if ( bMirroredY )
3687 0 : nFlags |= 2;
3688 : }
3689 : }
3690 654 : else if ( rPropVal.Name.equals( sSwitched ) )
3691 : {
3692 : bool bSwitched;
3693 0 : if ( rPropVal.Value >>= bSwitched )
3694 : {
3695 0 : if ( bSwitched )
3696 0 : nFlags |= 4;
3697 : }
3698 : }
3699 654 : else if ( rPropVal.Name.equals( sPolar ) )
3700 : {
3701 0 : com::sun::star::drawing::EnhancedCustomShapeParameterPair aPolar;
3702 0 : if ( rPropVal.Value >>= aPolar )
3703 : {
3704 0 : if ( GetValueForEnhancedCustomShapeHandleParameter( nXMap, aPolar.First ) )
3705 0 : nFlags |= 0x800;
3706 0 : if ( GetValueForEnhancedCustomShapeHandleParameter( nYMap, aPolar.Second ) )
3707 0 : nFlags |= 0x1000;
3708 0 : nFlags |= 8;
3709 0 : }
3710 : }
3711 654 : else if ( rPropVal.Name.equals( sRadiusRangeMinimum ) )
3712 : {
3713 0 : nYRangeMin = (sal_Int32)0xff4c0000; // the range of angles seems to be a not
3714 0 : nYRangeMax = (sal_Int32)0x00b40000; // used feature, so we are defaulting this
3715 :
3716 0 : com::sun::star::drawing::EnhancedCustomShapeParameter aRadiusRangeMinimum;
3717 0 : if ( rPropVal.Value >>= aRadiusRangeMinimum )
3718 : {
3719 0 : if ( GetValueForEnhancedCustomShapeHandleParameter( nXRangeMin, aRadiusRangeMinimum ) )
3720 0 : nFlags |= 0x80;
3721 0 : nFlags |= 0x2000;
3722 0 : }
3723 : }
3724 654 : else if ( rPropVal.Name.equals( sRadiusRangeMaximum ) )
3725 : {
3726 0 : nYRangeMin = (sal_Int32)0xff4c0000; // the range of angles seems to be a not
3727 0 : nYRangeMax = (sal_Int32)0x00b40000; // used feature, so we are defaulting this
3728 :
3729 0 : com::sun::star::drawing::EnhancedCustomShapeParameter aRadiusRangeMaximum;
3730 0 : if ( rPropVal.Value >>= aRadiusRangeMaximum )
3731 : {
3732 0 : if ( GetValueForEnhancedCustomShapeHandleParameter( nXRangeMax, aRadiusRangeMaximum ) )
3733 0 : nFlags |= 0x100;
3734 0 : nFlags |= 0x2000;
3735 0 : }
3736 : }
3737 654 : else if ( rPropVal.Name.equals( sRangeXMinimum ) )
3738 : {
3739 194 : com::sun::star::drawing::EnhancedCustomShapeParameter aXRangeMinimum;
3740 194 : if ( rPropVal.Value >>= aXRangeMinimum )
3741 : {
3742 194 : if ( GetValueForEnhancedCustomShapeHandleParameter( nXRangeMin, aXRangeMinimum ) )
3743 0 : nFlags |= 0x80;
3744 194 : nFlags |= 0x20;
3745 194 : }
3746 : }
3747 460 : else if ( rPropVal.Name.equals( sRangeXMaximum ) )
3748 : {
3749 194 : com::sun::star::drawing::EnhancedCustomShapeParameter aXRangeMaximum;
3750 194 : if ( rPropVal.Value >>= aXRangeMaximum )
3751 : {
3752 194 : if ( GetValueForEnhancedCustomShapeHandleParameter( nXRangeMax, aXRangeMaximum ) )
3753 14 : nFlags |= 0x100;
3754 194 : nFlags |= 0x20;
3755 194 : }
3756 : }
3757 266 : else if ( rPropVal.Name.equals( sRangeYMinimum ) )
3758 : {
3759 24 : com::sun::star::drawing::EnhancedCustomShapeParameter aYRangeMinimum;
3760 24 : if ( rPropVal.Value >>= aYRangeMinimum )
3761 : {
3762 24 : if ( GetValueForEnhancedCustomShapeHandleParameter( nYRangeMin, aYRangeMinimum ) )
3763 0 : nFlags |= 0x200;
3764 24 : nFlags |= 0x20;
3765 24 : }
3766 : }
3767 242 : else if ( rPropVal.Name.equals( sRangeYMaximum ) )
3768 : {
3769 24 : com::sun::star::drawing::EnhancedCustomShapeParameter aYRangeMaximum;
3770 24 : if ( rPropVal.Value >>= aYRangeMaximum )
3771 : {
3772 24 : if ( GetValueForEnhancedCustomShapeHandleParameter( nYRangeMax, aYRangeMaximum ) )
3773 6 : nFlags |= 0x400;
3774 24 : nFlags |= 0x20;
3775 24 : }
3776 : }
3777 872 : }
3778 218 : aOut.WriteUInt32( nFlags )
3779 218 : .WriteInt32( nXPosition )
3780 436 : .WriteInt32( nYPosition )
3781 436 : .WriteInt32( nXMap )
3782 436 : .WriteInt32( nYMap )
3783 436 : .WriteInt32( nXRangeMin )
3784 436 : .WriteInt32( nXRangeMax )
3785 436 : .WriteInt32( nYRangeMin )
3786 436 : .WriteInt32( nYRangeMax );
3787 :
3788 218 : if ( nFlags & 8 )
3789 0 : nAdjustmentsWhichNeedsToBeConverted |= ( 1 << ( nYPosition - 0x100 ) );
3790 : }
3791 200 : sal_uInt8* pBuf = new sal_uInt8[ nStreamSize ];
3792 200 : memcpy( pBuf, aOut.GetData(), nStreamSize );
3793 200 : AddOpt( DFF_Prop_Handles, true, nStreamSize - 6, pBuf, nStreamSize );
3794 : }
3795 : else
3796 : {
3797 344 : sal_uInt8* pBuf = new sal_uInt8[ 1 ];
3798 344 : AddOpt( DFF_Prop_Handles, true, 0, pBuf, 0 );
3799 : }
3800 : }
3801 : }
3802 : }
3803 4066 : else if ( rProp.Name.equals( sAdjustmentValues ) )
3804 : {
3805 : // it is required, that the information which handle is polar has already be read,
3806 : // so we are able to change the polar value to a fixed float
3807 748 : aAdjustmentValuesProp = rProp.Value;
3808 748 : bAdjustmentValuesProp = true;
3809 : }
3810 : }
3811 748 : if ( bAdjustmentValuesProp )
3812 : {
3813 748 : uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue > aAdjustmentSeq;
3814 748 : if ( aAdjustmentValuesProp >>= aAdjustmentSeq )
3815 : {
3816 748 : if ( bPredefinedHandlesUsed )
3817 204 : LookForPolarHandles( eShapeType, nAdjustmentsWhichNeedsToBeConverted );
3818 :
3819 748 : sal_Int32 k, nValue = 0, nAdjustmentValues = aAdjustmentSeq.getLength();
3820 1040 : for ( k = 0; k < nAdjustmentValues; k++ )
3821 292 : if( GetAdjustmentValue( aAdjustmentSeq[ k ], k, nAdjustmentsWhichNeedsToBeConverted, nValue ) )
3822 292 : AddOpt( (sal_uInt16)( DFF_Prop_adjustValue + k ), (sal_uInt32)nValue );
3823 748 : }
3824 : }
3825 748 : if( bPathCoordinatesProp )
3826 : {
3827 548 : com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair > aCoordinates;
3828 548 : if ( aPathCoordinatesProp >>= aCoordinates )
3829 : {
3830 : // creating the vertices
3831 548 : if ( (sal_uInt16)aCoordinates.getLength() )
3832 : {
3833 548 : sal_uInt16 j, nElements = (sal_uInt16)aCoordinates.getLength();
3834 548 : sal_uInt16 nElementSize = 8;
3835 548 : sal_uInt32 nStreamSize = nElementSize * nElements + 6;
3836 548 : SvMemoryStream aOut( nStreamSize );
3837 548 : aOut.WriteUInt16( nElements )
3838 1096 : .WriteUInt16( nElements )
3839 1096 : .WriteUInt16( nElementSize );
3840 4892 : for( j = 0; j < nElements; j++ )
3841 : {
3842 4344 : sal_Int32 X = GetValueForEnhancedCustomShapeParameter( aCoordinates[ j ].First, aEquationOrder, true );
3843 4344 : sal_Int32 Y = GetValueForEnhancedCustomShapeParameter( aCoordinates[ j ].Second, aEquationOrder, true );
3844 4344 : aOut.WriteInt32( X )
3845 4344 : .WriteInt32( Y );
3846 : }
3847 548 : sal_uInt8* pBuf = new sal_uInt8[ nStreamSize ];
3848 548 : memcpy( pBuf, aOut.GetData(), nStreamSize );
3849 548 : AddOpt( DFF_Prop_pVertices, true, nStreamSize - 6, pBuf, nStreamSize ); // -6
3850 : }
3851 : else
3852 : {
3853 0 : sal_uInt8* pBuf = new sal_uInt8[ 1 ];
3854 0 : AddOpt( DFF_Prop_pVertices, true, 0, pBuf, 0 );
3855 : }
3856 548 : }
3857 748 : }
3858 748 : }
3859 748 : }
3860 : }
3861 :
3862 2154 : MSO_SPT EscherPropertyContainer::GetCustomShapeType( const uno::Reference< drawing::XShape > & rXShape, sal_uInt32& nMirrorFlags, OUString& rShapeType, bool bOOXML )
3863 : {
3864 2154 : MSO_SPT eShapeType = mso_sptNil;
3865 2154 : nMirrorFlags = 0;
3866 2154 : uno::Reference< beans::XPropertySet > aXPropSet( rXShape, uno::UNO_QUERY );
3867 2154 : if ( aXPropSet.is() )
3868 : {
3869 : try
3870 : {
3871 2154 : const OUString sCustomShapeGeometry( "CustomShapeGeometry" );
3872 4140 : uno::Any aGeoPropSet = aXPropSet->getPropertyValue( sCustomShapeGeometry );
3873 3972 : uno::Sequence< beans::PropertyValue > aGeoPropSeq;
3874 1986 : if ( aGeoPropSet >>= aGeoPropSeq )
3875 : {
3876 1986 : sal_Int32 i, nCount = aGeoPropSeq.getLength();
3877 20250 : for ( i = 0; i < nCount; i++ )
3878 : {
3879 18264 : const beans::PropertyValue& rProp = aGeoPropSeq[ i ];
3880 18264 : if ( rProp.Name == "Type" )
3881 : {
3882 1986 : if ( rProp.Value >>= rShapeType )
3883 : {
3884 1986 : if (bOOXML)
3885 : {
3886 : // In case of VML export, try to handle the
3887 : // ooxml- prefix in rShapeType. If that fails,
3888 : // just do the same as the binary export.
3889 726 : OString aType = OUStringToOString(rShapeType, RTL_TEXTENCODING_UTF8);
3890 726 : eShapeType = msfilter::util::GETVMLShapeType(aType);
3891 726 : if (eShapeType == mso_sptNil)
3892 528 : eShapeType = EnhancedCustomShapeTypeNames::Get(rShapeType);
3893 : }
3894 : else
3895 1260 : eShapeType = EnhancedCustomShapeTypeNames::Get( rShapeType );
3896 : }
3897 : }
3898 16278 : else if ( rProp.Name == "MirroredX" )
3899 : {
3900 : bool bMirroredX;
3901 1782 : if ( ( rProp.Value >>= bMirroredX ) && bMirroredX )
3902 22 : nMirrorFlags |= SHAPEFLAG_FLIPH;
3903 : }
3904 14496 : else if ( rProp.Name == "MirroredY" )
3905 : {
3906 : bool bMirroredY;
3907 1792 : if ( ( rProp.Value >>= bMirroredY ) && bMirroredY )
3908 186 : nMirrorFlags |= SHAPEFLAG_FLIPV;
3909 : }
3910 : }
3911 2154 : }
3912 : }
3913 168 : catch( const ::com::sun::star::uno::Exception& )
3914 : {
3915 : }
3916 : }
3917 2154 : return eShapeType;
3918 : }
3919 :
3920 0 : MSO_SPT EscherPropertyContainer::GetCustomShapeType( const uno::Reference< drawing::XShape > & rXShape, sal_uInt32& nMirrorFlags )
3921 : {
3922 0 : OUString aShapeType;
3923 0 : return GetCustomShapeType( rXShape, nMirrorFlags, aShapeType );
3924 : }
3925 :
3926 : // Implement for form control export
3927 0 : bool EscherPropertyContainer::CreateBlipPropertiesforOLEControl(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet, const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rXShape)
3928 : {
3929 0 : SdrObject* pShape = GetSdrObjectFromXShape( rXShape );
3930 0 : if ( pShape )
3931 : {
3932 0 : SdrModel* pMod = pShape->GetModel();
3933 0 : Graphic aGraphic(SdrExchangeView::GetObjGraphic( pMod, pShape));
3934 :
3935 0 : GraphicObject aGraphicObject = aGraphic;
3936 0 : OString aUniqueId = aGraphicObject.GetUniqueID();
3937 0 : if ( aUniqueId.getLength() )
3938 : {
3939 0 : if ( pGraphicProvider && pPicOutStrm && pShapeBoundRect )
3940 : {
3941 0 : Rectangle aRect( Point( 0, 0 ), pShapeBoundRect->GetSize() );
3942 :
3943 0 : sal_uInt32 nBlibId = pGraphicProvider->GetBlibID( *pPicOutStrm, aUniqueId, aRect, NULL );
3944 0 : if ( nBlibId )
3945 : {
3946 0 : AddOpt( ESCHER_Prop_pib, nBlibId, true );
3947 0 : ImplCreateGraphicAttributes( rXPropSet, nBlibId, false );
3948 0 : return true;
3949 : }
3950 : }
3951 0 : }
3952 : }
3953 :
3954 0 : return false;
3955 : }
3956 :
3957 1072 : EscherPersistTable::EscherPersistTable()
3958 : {
3959 1072 : }
3960 :
3961 2144 : EscherPersistTable::~EscherPersistTable()
3962 : {
3963 1536 : for( size_t i = 0, n = maPersistTable.size(); i < n; ++i ) {
3964 464 : delete maPersistTable[ i ];
3965 : }
3966 1072 : }
3967 :
3968 0 : bool EscherPersistTable::PtIsID( sal_uInt32 nID )
3969 : {
3970 0 : for( size_t i = 0, n = maPersistTable.size(); i < n; ++i ) {
3971 0 : EscherPersistEntry* pPtr = maPersistTable[ i ];
3972 0 : if ( pPtr->mnID == nID ) {
3973 0 : return true;
3974 : }
3975 : }
3976 0 : return false;
3977 : }
3978 :
3979 670 : void EscherPersistTable::PtInsert( sal_uInt32 nID, sal_uInt32 nOfs )
3980 : {
3981 670 : maPersistTable.push_back( new EscherPersistEntry( nID, nOfs ) );
3982 670 : }
3983 :
3984 340 : sal_uInt32 EscherPersistTable::PtDelete( sal_uInt32 nID )
3985 : {
3986 340 : EscherPersistTable_impl::iterator it = maPersistTable.begin();
3987 2114 : for( ; it != maPersistTable.end() ; ++it )
3988 : {
3989 1980 : if ( (*it)->mnID == nID ) {
3990 206 : delete *it;
3991 206 : maPersistTable.erase( it );
3992 206 : break;
3993 : }
3994 : }
3995 340 : return 0;
3996 : }
3997 :
3998 566 : sal_uInt32 EscherPersistTable::PtGetOffsetByID( sal_uInt32 nID )
3999 : {
4000 2718 : for( size_t i = 0, n = maPersistTable.size(); i < n; ++i ) {
4001 2718 : EscherPersistEntry* pPtr = maPersistTable[ i ];
4002 2718 : if ( pPtr->mnID == nID ) {
4003 566 : return pPtr->mnOffset;
4004 : }
4005 : }
4006 0 : return 0;
4007 : };
4008 :
4009 224 : sal_uInt32 EscherPersistTable::PtReplace( sal_uInt32 nID, sal_uInt32 nOfs )
4010 : {
4011 1032 : for( size_t i = 0, n = maPersistTable.size(); i < n; ++i ) {
4012 1032 : EscherPersistEntry* pPtr = maPersistTable[ i ];
4013 1032 : if ( pPtr->mnID == nID ) {
4014 224 : sal_uInt32 nRetValue = pPtr->mnOffset;
4015 224 : pPtr->mnOffset = nOfs;
4016 224 : return nRetValue;
4017 : }
4018 : }
4019 0 : return 0;
4020 : }
4021 :
4022 412 : sal_uInt32 EscherPersistTable::PtReplaceOrInsert( sal_uInt32 nID, sal_uInt32 nOfs )
4023 : {
4024 2510 : for( size_t i = 0, n = maPersistTable.size(); i < n; ++i ) {
4025 2098 : EscherPersistEntry* pPtr = maPersistTable[ i ];
4026 2098 : if ( pPtr->mnID == nID ) {
4027 0 : sal_uInt32 nRetValue = pPtr->mnOffset;
4028 0 : pPtr->mnOffset = nOfs;
4029 0 : return nRetValue;
4030 : }
4031 : }
4032 412 : PtInsert( nID, nOfs );
4033 412 : return 0;
4034 : }
4035 :
4036 32628 : bool EscherPropertyValueHelper::GetPropertyValue(
4037 : ::com::sun::star::uno::Any& rAny,
4038 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet,
4039 : const OUString& rString,
4040 : bool bTestPropertyAvailability)
4041 : {
4042 32628 : bool bRetValue = true;
4043 32628 : if ( bTestPropertyAvailability )
4044 : {
4045 14154 : bRetValue = false;
4046 : try
4047 : {
4048 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
4049 14154 : aXPropSetInfo( rXPropSet->getPropertySetInfo() );
4050 14154 : if ( aXPropSetInfo.is() )
4051 14154 : bRetValue = aXPropSetInfo->hasPropertyByName( rString );
4052 : }
4053 0 : catch( const ::com::sun::star::uno::Exception& )
4054 : {
4055 0 : bRetValue = false;
4056 : }
4057 : }
4058 32628 : if ( bRetValue )
4059 : {
4060 : try
4061 : {
4062 30788 : rAny = rXPropSet->getPropertyValue( rString );
4063 29810 : if ( !rAny.hasValue() )
4064 108 : bRetValue = false;
4065 : }
4066 1956 : catch( const ::com::sun::star::uno::Exception& )
4067 : {
4068 978 : bRetValue = false;
4069 : }
4070 : }
4071 32628 : return bRetValue;
4072 : }
4073 :
4074 968 : ::com::sun::star::beans::PropertyState EscherPropertyValueHelper::GetPropertyState(
4075 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet,
4076 : const OUString& rPropertyName )
4077 : {
4078 968 : ::com::sun::star::beans::PropertyState eRetValue = ::com::sun::star::beans::PropertyState_AMBIGUOUS_VALUE;
4079 : try
4080 : {
4081 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState > aXPropState
4082 968 : ( rXPropSet, ::com::sun::star::uno::UNO_QUERY );
4083 968 : if ( aXPropState.is() )
4084 968 : eRetValue = aXPropState->getPropertyState( rPropertyName );
4085 : }
4086 0 : catch( const ::com::sun::star::uno::Exception& )
4087 : {
4088 : }
4089 968 : return eRetValue;
4090 : }
4091 :
4092 136 : EscherBlibEntry::EscherBlibEntry( sal_uInt32 nPictureOffset, const GraphicObject& rObject, const OString& rId,
4093 : const GraphicAttr* pGraphicAttr ) :
4094 : mnPictureOffset ( nPictureOffset ),
4095 : mnRefCount ( 1 ),
4096 : mnSizeExtra ( 0 ),
4097 136 : maPrefSize ( rObject.GetPrefSize() ),
4098 136 : maPrefMapMode ( rObject.GetPrefMapMode() ),
4099 408 : mbIsEmpty ( true )
4100 : {
4101 136 : mbIsNativeGraphicPossible = ( pGraphicAttr == NULL );
4102 136 : meBlibType = UNKNOWN;
4103 136 : mnSize = 0;
4104 :
4105 136 : sal_uInt32 nLen = static_cast<sal_uInt32>(rId.getLength());
4106 136 : const sal_Char* pData = rId.getStr();
4107 136 : GraphicType eType( rObject.GetType() );
4108 136 : if ( nLen && pData && ( eType != GRAPHIC_NONE ) )
4109 : {
4110 132 : mnIdentifier[ 0 ] = rtl_crc32( 0,pData, nLen );
4111 132 : mnIdentifier[ 1 ] = 0;
4112 :
4113 132 : if ( pGraphicAttr )
4114 : {
4115 0 : if ( pGraphicAttr->IsSpecialDrawMode()
4116 0 : || pGraphicAttr->IsMirrored()
4117 0 : || pGraphicAttr->IsCropped()
4118 0 : || pGraphicAttr->IsRotated()
4119 0 : || pGraphicAttr->IsTransparent()
4120 0 : || pGraphicAttr->IsAdjusted() )
4121 : {
4122 0 : SvMemoryStream aSt( sizeof( GraphicAttr ) );
4123 0 : aSt.WriteUInt16( pGraphicAttr->GetDrawMode() )
4124 0 : .WriteUInt32( pGraphicAttr->GetMirrorFlags() )
4125 0 : .WriteInt32( pGraphicAttr->GetLeftCrop() )
4126 0 : .WriteInt32( pGraphicAttr->GetTopCrop() )
4127 0 : .WriteInt32( pGraphicAttr->GetRightCrop() )
4128 0 : .WriteInt32( pGraphicAttr->GetBottomCrop() )
4129 0 : .WriteUInt16( pGraphicAttr->GetRotation() )
4130 0 : .WriteInt16( pGraphicAttr->GetLuminance() )
4131 0 : .WriteInt16( pGraphicAttr->GetContrast() )
4132 0 : .WriteInt16( pGraphicAttr->GetChannelR() )
4133 0 : .WriteInt16( pGraphicAttr->GetChannelG() )
4134 0 : .WriteInt16( pGraphicAttr->GetChannelB() )
4135 0 : .WriteDouble( pGraphicAttr->GetGamma() );
4136 0 : aSt.WriteUChar( pGraphicAttr->IsInvert() )
4137 0 : .WriteUChar( pGraphicAttr->GetTransparency() );
4138 0 : mnIdentifier[ 1 ] = rtl_crc32( 0, aSt.GetData(), aSt.Tell() );
4139 : }
4140 : else
4141 0 : mbIsNativeGraphicPossible = true;
4142 : }
4143 : sal_uInt32 i, nTmp, n1, n2;
4144 132 : n1 = n2 = 0;
4145 4356 : for ( i = 0; i < nLen; i++ )
4146 : {
4147 4224 : nTmp = n2 >> 28; // rotating 4 bit
4148 4224 : n2 <<= 4;
4149 4224 : n2 |= n1 >> 28;
4150 4224 : n1 <<= 4;
4151 4224 : n1 |= nTmp;
4152 4224 : n1 ^= *pData++ - '0';
4153 : }
4154 132 : mnIdentifier[ 2 ] = n1;
4155 132 : mnIdentifier[ 3 ] = n2;
4156 132 : mbIsEmpty = false;
4157 : }
4158 136 : };
4159 :
4160 16 : void EscherBlibEntry::WriteBlibEntry( SvStream& rSt, bool bWritePictureOffset, sal_uInt32 nResize )
4161 : {
4162 16 : sal_uInt32 nPictureOffset = ( bWritePictureOffset ) ? mnPictureOffset : 0;
4163 :
4164 16 : rSt.WriteUInt32( ( ( ESCHER_BSE << 16 ) | ( ( (sal_uInt16)meBlibType << 4 ) | 2 ) ) )
4165 32 : .WriteUInt32( ( 36 + nResize ) )
4166 32 : .WriteUChar( meBlibType );
4167 :
4168 16 : switch ( meBlibType )
4169 : {
4170 : case EMF :
4171 : case WMF : // converting EMF/WMF on OS2 to Pict
4172 2 : rSt.WriteUChar( PICT );
4173 2 : break;
4174 : default:
4175 14 : rSt.WriteUChar( meBlibType );
4176 : }
4177 :
4178 16 : rSt.Write( &mnIdentifier[ 0 ], 16 );
4179 16 : rSt.WriteUInt16( 0 )
4180 32 : .WriteUInt32( ( mnSize + mnSizeExtra ) )
4181 32 : .WriteUInt32( mnRefCount )
4182 16 : .WriteUInt32( nPictureOffset )
4183 16 : .WriteUInt32( 0 );
4184 16 : }
4185 :
4186 136 : EscherBlibEntry::~EscherBlibEntry()
4187 : {
4188 136 : };
4189 :
4190 6 : bool EscherBlibEntry::operator==( const EscherBlibEntry& rEscherBlibEntry ) const
4191 : {
4192 12 : for ( int i = 0; i < 3; i++ )
4193 : {
4194 10 : if ( mnIdentifier[ i ] != rEscherBlibEntry.mnIdentifier[ i ] )
4195 4 : return false;
4196 : }
4197 2 : return true;
4198 : }
4199 :
4200 1190 : EscherGraphicProvider::EscherGraphicProvider( sal_uInt32 nFlags ) :
4201 : mnFlags ( nFlags ),
4202 : mpBlibEntrys ( NULL ),
4203 : mnBlibBufSize ( 0 ),
4204 1190 : mnBlibEntrys ( 0 )
4205 : {
4206 1190 : }
4207 :
4208 2380 : EscherGraphicProvider::~EscherGraphicProvider()
4209 : {
4210 1190 : for ( sal_uInt32 i = 0; i < mnBlibEntrys; delete mpBlibEntrys[ i++ ] ) ;
4211 1190 : delete[] mpBlibEntrys;
4212 1190 : }
4213 :
4214 8 : void EscherGraphicProvider::SetNewBlipStreamOffset( sal_Int32 nOffset )
4215 : {
4216 14 : for( sal_uInt32 i = 0; i < mnBlibEntrys; i++ )
4217 : {
4218 6 : EscherBlibEntry* pBlibEntry = mpBlibEntrys[ i ];
4219 6 : pBlibEntry->mnPictureOffset += nOffset;
4220 : }
4221 8 : }
4222 :
4223 130 : sal_uInt32 EscherGraphicProvider::ImplInsertBlib( EscherBlibEntry* p_EscherBlibEntry )
4224 : {
4225 130 : if ( mnBlibBufSize == mnBlibEntrys )
4226 : {
4227 126 : mnBlibBufSize += 64;
4228 126 : EscherBlibEntry** pTemp = new EscherBlibEntry*[ mnBlibBufSize ];
4229 126 : for ( sal_uInt32 i = 0; i < mnBlibEntrys; i++ )
4230 : {
4231 0 : pTemp[ i ] = mpBlibEntrys[ i ];
4232 : }
4233 126 : delete[] mpBlibEntrys;
4234 126 : mpBlibEntrys = pTemp;
4235 : }
4236 130 : mpBlibEntrys[ mnBlibEntrys++ ] = p_EscherBlibEntry;
4237 130 : return mnBlibEntrys;
4238 : }
4239 :
4240 20 : sal_uInt32 EscherGraphicProvider::GetBlibStoreContainerSize( SvStream* pMergePicStreamBSE ) const
4241 : {
4242 20 : sal_uInt32 nSize = 44 * mnBlibEntrys + 8;
4243 20 : if ( pMergePicStreamBSE )
4244 : {
4245 24 : for ( sal_uInt32 i = 0; i < mnBlibEntrys; i++ )
4246 16 : nSize += mpBlibEntrys[ i ]->mnSize + mpBlibEntrys[ i ]->mnSizeExtra;
4247 : }
4248 20 : return nSize;
4249 : }
4250 :
4251 2 : bool EscherGraphicProvider::WriteBlibStoreEntry(SvStream& rSt,
4252 : sal_uInt32 nBlipId, bool bWritePictureOffSet, sal_uInt32 nResize)
4253 : {
4254 2 : if (nBlipId > mnBlibEntrys || nBlipId == 0)
4255 0 : return false;
4256 2 : mpBlibEntrys[nBlipId-1]->WriteBlibEntry(rSt, bWritePictureOffSet, nResize);
4257 2 : return true;
4258 : }
4259 :
4260 10 : void EscherGraphicProvider::WriteBlibStoreContainer( SvStream& rSt, SvStream* pMergePicStreamBSE )
4261 : {
4262 10 : sal_uInt32 nSize = GetBlibStoreContainerSize( pMergePicStreamBSE );
4263 10 : if ( nSize )
4264 : {
4265 10 : rSt.WriteUInt32( ( ( ESCHER_BstoreContainer << 16 ) | 0x1f ) )
4266 20 : .WriteUInt32( ( nSize - 8 ) );
4267 :
4268 10 : if ( pMergePicStreamBSE )
4269 : {
4270 4 : sal_uInt32 i, nBlipSize, nOldPos = pMergePicStreamBSE->Tell();
4271 4 : const sal_uInt32 nBuf = 0x40000; // 256KB buffer
4272 4 : boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8[ nBuf ]);
4273 :
4274 12 : for ( i = 0; i < mnBlibEntrys; i++ )
4275 : {
4276 8 : EscherBlibEntry* pBlibEntry = mpBlibEntrys[ i ];
4277 :
4278 8 : ESCHER_BlibType nBlibType = pBlibEntry->meBlibType;
4279 8 : nBlipSize = pBlibEntry->mnSize + pBlibEntry->mnSizeExtra;
4280 8 : pBlibEntry->WriteBlibEntry( rSt, false, nBlipSize );
4281 :
4282 : // BLIP
4283 8 : pMergePicStreamBSE->Seek( pBlibEntry->mnPictureOffset );
4284 : sal_uInt16 n16;
4285 : // record version and instance
4286 8 : pMergePicStreamBSE->ReadUInt16( n16 );
4287 8 : rSt.WriteUInt16( n16 );
4288 : // record type
4289 8 : pMergePicStreamBSE->ReadUInt16( n16 );
4290 8 : rSt.WriteUInt16( ESCHER_BlipFirst + nBlibType );
4291 : DBG_ASSERT( n16 == ESCHER_BlipFirst + nBlibType , "EscherGraphicProvider::WriteBlibStoreContainer: BLIP record types differ" );
4292 : sal_uInt32 n32;
4293 : // record size
4294 8 : pMergePicStreamBSE->ReadUInt32( n32 );
4295 8 : nBlipSize -= 8;
4296 8 : rSt.WriteUInt32( nBlipSize );
4297 : DBG_ASSERT( nBlipSize == n32, "EscherGraphicProvider::WriteBlibStoreContainer: BLIP sizes differ" );
4298 : // record
4299 24 : while ( nBlipSize )
4300 : {
4301 8 : sal_uInt32 nBytes = ( nBlipSize > nBuf ? nBuf : nBlipSize );
4302 8 : pMergePicStreamBSE->Read( pBuf.get(), nBytes );
4303 8 : rSt.Write( pBuf.get(), nBytes );
4304 8 : nBlipSize -= nBytes;
4305 : }
4306 : }
4307 4 : pMergePicStreamBSE->Seek( nOldPos );
4308 : }
4309 : else
4310 : {
4311 12 : for ( sal_uInt32 i = 0; i < mnBlibEntrys; i++ )
4312 6 : mpBlibEntrys[ i ]->WriteBlibEntry( rSt, true );
4313 : }
4314 : }
4315 10 : }
4316 :
4317 8 : bool EscherGraphicProvider::GetPrefSize( const sal_uInt32 nBlibId, Size& rPrefSize, MapMode& rPrefMapMode )
4318 : {
4319 8 : bool bInRange = nBlibId && ( ( nBlibId - 1 ) < mnBlibEntrys );
4320 8 : if ( bInRange )
4321 : {
4322 8 : EscherBlibEntry* pEntry = mpBlibEntrys[ nBlibId - 1 ];
4323 8 : rPrefSize = pEntry->maPrefSize;
4324 8 : rPrefMapMode = pEntry->maPrefMapMode;
4325 : }
4326 8 : return bInRange;
4327 : }
4328 :
4329 136 : sal_uInt32 EscherGraphicProvider::GetBlibID( SvStream& rPicOutStrm, const OString& rId,
4330 : const Rectangle& /* rBoundRect */, const com::sun::star::awt::Rectangle* pVisArea,
4331 : const GraphicAttr* pGraphicAttr, const bool bOOxmlExport )
4332 : {
4333 136 : sal_uInt32 nBlibId = 0;
4334 136 : GraphicObject aGraphicObject( rId );
4335 :
4336 136 : EscherBlibEntry* p_EscherBlibEntry = new EscherBlibEntry( rPicOutStrm.Tell(), aGraphicObject, rId, pGraphicAttr );
4337 136 : if ( !p_EscherBlibEntry->IsEmpty() )
4338 : {
4339 136 : for ( sal_uInt32 i = 0; i < mnBlibEntrys; i++ )
4340 : {
4341 6 : if ( *( mpBlibEntrys[ i ] ) == *p_EscherBlibEntry )
4342 : {
4343 2 : mpBlibEntrys[ i ]->mnRefCount++;
4344 2 : delete p_EscherBlibEntry;
4345 2 : return i + 1;
4346 : }
4347 : }
4348 :
4349 130 : bool bUseNativeGraphic( false );
4350 :
4351 130 : Graphic aGraphic( aGraphicObject.GetTransformedGraphic( pGraphicAttr ) );
4352 260 : GfxLink aGraphicLink;
4353 260 : SvMemoryStream aStream;
4354 :
4355 130 : const sal_uInt8* pGraphicAry = NULL;
4356 :
4357 130 : if ( p_EscherBlibEntry->mbIsNativeGraphicPossible && aGraphic.IsLink() )
4358 : {
4359 92 : aGraphicLink = aGraphic.GetLink();
4360 :
4361 92 : p_EscherBlibEntry->mnSize = aGraphicLink.GetDataSize();
4362 92 : pGraphicAry = aGraphicLink.GetData();
4363 :
4364 92 : if ( p_EscherBlibEntry->mnSize && pGraphicAry )
4365 : {
4366 92 : switch ( aGraphicLink.GetType() )
4367 : {
4368 20 : case GFX_LINK_TYPE_NATIVE_JPG : p_EscherBlibEntry->meBlibType = PEG; break;
4369 48 : case GFX_LINK_TYPE_NATIVE_PNG : p_EscherBlibEntry->meBlibType = PNG; break;
4370 :
4371 : // #i15508# added BMP type for better exports; need to check this
4372 : // checked - does not work that way, so keep out for now. It may
4373 : // work somehow with direct DIB data, but that would need to be checked
4374 : // carefully
4375 : // for more comments please check RtfAttributeOutput::FlyFrameGraphic
4376 : //
4377 : // case GFX_LINK_TYPE_NATIVE_BMP : p_EscherBlibEntry->meBlibType = DIB; break;
4378 :
4379 : case GFX_LINK_TYPE_NATIVE_WMF :
4380 : {
4381 22 : if ( pGraphicAry && ( p_EscherBlibEntry->mnSize > 0x2c ) )
4382 : {
4383 22 : if ( ( pGraphicAry[ 0x28 ] == 0x20 ) && ( pGraphicAry[ 0x29 ] == 0x45 ) // check the magic
4384 0 : && ( pGraphicAry[ 0x2a ] == 0x4d ) && ( pGraphicAry[ 0x2b ] == 0x46 ) ) // number ( emf detection )
4385 : {
4386 0 : p_EscherBlibEntry->meBlibType = EMF;
4387 : }
4388 : else
4389 : {
4390 22 : p_EscherBlibEntry->meBlibType = WMF;
4391 22 : if ( ( pGraphicAry[ 0 ] == 0xd7 ) && ( pGraphicAry[ 1 ] == 0xcd )
4392 22 : && ( pGraphicAry[ 2 ] == 0xc6 ) && ( pGraphicAry[ 3 ] == 0x9a ) )
4393 : { // we have to get rid of the metafileheader
4394 22 : pGraphicAry += 22;
4395 22 : p_EscherBlibEntry->mnSize -= 22;
4396 : }
4397 : }
4398 : }
4399 : }
4400 22 : break;
4401 2 : default: break;
4402 : }
4403 92 : if ( p_EscherBlibEntry->meBlibType != UNKNOWN )
4404 90 : bUseNativeGraphic = true;
4405 : }
4406 : }
4407 130 : if ( !bUseNativeGraphic )
4408 : {
4409 40 : GraphicType eGraphicType = aGraphic.GetType();
4410 40 : if ( ( eGraphicType == GRAPHIC_BITMAP ) || ( eGraphicType == GRAPHIC_GDIMETAFILE ) )
4411 : {
4412 : sal_uInt32 nErrCode;
4413 40 : if ( !aGraphic.IsAnimated() )
4414 40 : nErrCode = GraphicConverter::Export( aStream, aGraphic, ( eGraphicType == GRAPHIC_BITMAP ) ? CVT_PNG : CVT_EMF );
4415 : else
4416 : { // to store a animation, a gif has to be included into the msOG chunk of a png #I5583#
4417 0 : GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter();
4418 0 : SvMemoryStream aGIFStream;
4419 0 : const char* pString = "MSOFFICE9.0";
4420 0 : aGIFStream.Write( pString, strlen(pString) );
4421 : nErrCode = rFilter.ExportGraphic( aGraphic, OUString(), aGIFStream,
4422 0 : rFilter.GetExportFormatNumberForShortName( OUString( "GIF" ) ), NULL );
4423 0 : com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > aFilterData( 1 );
4424 0 : com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > aAdditionalChunkSequence( 1 );
4425 0 : sal_uInt32 nGIFSreamLen = aGIFStream.Tell();
4426 0 : com::sun::star::uno::Sequence< sal_Int8 > aGIFSeq( nGIFSreamLen );
4427 0 : sal_Int8* pSeq = aGIFSeq.getArray();
4428 0 : aGIFStream.Seek( STREAM_SEEK_TO_BEGIN );
4429 0 : aGIFStream.Read( pSeq, nGIFSreamLen );
4430 0 : com::sun::star::beans::PropertyValue aChunkProp, aFilterProp;
4431 0 : aChunkProp.Name = "msOG";
4432 0 : aChunkProp.Value <<= aGIFSeq;
4433 0 : aAdditionalChunkSequence[ 0 ] = aChunkProp;
4434 0 : aFilterProp.Name = "AdditionalChunks";
4435 0 : aFilterProp.Value <<= aAdditionalChunkSequence;
4436 0 : aFilterData[ 0 ] = aFilterProp;
4437 : nErrCode = rFilter.ExportGraphic( aGraphic, OUString(), aStream,
4438 0 : rFilter.GetExportFormatNumberForShortName( OUString( "PNG" ) ), &aFilterData );
4439 : }
4440 40 : if ( nErrCode == ERRCODE_NONE )
4441 : {
4442 40 : p_EscherBlibEntry->meBlibType = ( eGraphicType == GRAPHIC_BITMAP ) ? PNG : EMF;
4443 40 : aStream.Seek( STREAM_SEEK_TO_END );
4444 40 : p_EscherBlibEntry->mnSize = aStream.Tell();
4445 40 : pGraphicAry = (sal_uInt8*)aStream.GetData();
4446 : }
4447 : }
4448 : }
4449 :
4450 130 : ESCHER_BlibType eBlibType = p_EscherBlibEntry->meBlibType;
4451 130 : if ( p_EscherBlibEntry->mnSize && pGraphicAry && ( eBlibType != UNKNOWN ) )
4452 : {
4453 130 : sal_uInt32 nExtra, nAtomSize = 0;
4454 130 : sal_uInt32 nInstance, nUncompressedSize = p_EscherBlibEntry->mnSize;
4455 :
4456 130 : if ( mnFlags & _E_GRAPH_PROV_USE_INSTANCES )
4457 : {
4458 0 : rPicOutStrm.WriteUInt32( ( 0x7f90000 | (sal_uInt16)( mnBlibEntrys << 4 ) ) )
4459 0 : .WriteUInt32( 0 );
4460 0 : nAtomSize = rPicOutStrm.Tell();
4461 0 : if ( eBlibType == PNG )
4462 0 : rPicOutStrm.WriteUInt16( 0x0606 );
4463 0 : else if ( eBlibType == WMF )
4464 0 : rPicOutStrm.WriteUInt16( 0x0403 );
4465 0 : else if ( eBlibType == EMF )
4466 0 : rPicOutStrm.WriteUInt16( 0x0402 );
4467 0 : else if ( eBlibType == PEG )
4468 0 : rPicOutStrm.WriteUInt16( 0x0505 );
4469 : }
4470 :
4471 : // fdo#69607 do not compress WMF files if we are in OOXML export
4472 130 : if ( ( eBlibType == PEG ) || ( eBlibType == PNG ) // || ( eBlibType == DIB )) // #i15508#
4473 52 : || ( ( ( eBlibType == WMF ) || ( eBlibType == EMF ) ) && bOOxmlExport ) )
4474 : {
4475 100 : nExtra = 17;
4476 100 : p_EscherBlibEntry->mnSizeExtra = nExtra + 8;
4477 :
4478 : // #i15508# type see SvxMSDffManager::GetBLIPDirect (checked, does not work this way)
4479 : // see RtfAttributeOutput::FlyFrameGraphic for more comments
4480 : // maybe it would work with direct DIB data, but that would need thorough testing
4481 100 : if( eBlibType == PNG )
4482 : {
4483 58 : nInstance = 0xf01e6e00;
4484 : }
4485 : else // if( eBlibType == PEG )
4486 : {
4487 42 : nInstance = 0xf01d46a0;
4488 : }
4489 : //else // eBlibType == DIB
4490 : //{
4491 : // nInstance = 0xf01d7A80;
4492 : //}
4493 :
4494 : // #i15508#
4495 : //nInstance = ( eBlibType == PNG ) ? 0xf01e6e00 : 0xf01d46a0;
4496 :
4497 :
4498 100 : rPicOutStrm.WriteUInt32( nInstance ).WriteUInt32( ( p_EscherBlibEntry->mnSize + nExtra ) );
4499 100 : rPicOutStrm.Write( p_EscherBlibEntry->mnIdentifier, 16 );
4500 100 : rPicOutStrm.WriteUChar( 0xff );
4501 100 : rPicOutStrm.Write( pGraphicAry, p_EscherBlibEntry->mnSize );
4502 : }
4503 : else
4504 : {
4505 30 : ZCodec aZCodec( 0x8000, 0x8000 );
4506 30 : aZCodec.BeginCompression();
4507 60 : SvMemoryStream aDestStrm;
4508 30 : aZCodec.Write( aDestStrm, pGraphicAry, p_EscherBlibEntry->mnSize );
4509 30 : aZCodec.EndCompression();
4510 30 : aDestStrm.Seek( STREAM_SEEK_TO_END );
4511 30 : p_EscherBlibEntry->mnSize = aDestStrm.Tell();
4512 30 : pGraphicAry = (sal_uInt8*)aDestStrm.GetData();
4513 30 : if ( p_EscherBlibEntry->mnSize && pGraphicAry )
4514 : {
4515 30 : nExtra = eBlibType == WMF ? 0x42 : 0x32; // !EMF -> no change
4516 30 : p_EscherBlibEntry->mnSizeExtra = nExtra + 8;
4517 30 : nInstance = ( eBlibType == WMF ) ? 0xf01b2170 : 0xf01a3d40; // !EMF -> no change
4518 30 : rPicOutStrm.WriteUInt32( nInstance ).WriteUInt32( ( p_EscherBlibEntry->mnSize + nExtra ) );
4519 30 : if ( eBlibType == WMF ) // !EMF -> no change
4520 0 : rPicOutStrm.Write( p_EscherBlibEntry->mnIdentifier, 16 );
4521 30 : rPicOutStrm.Write( p_EscherBlibEntry->mnIdentifier, 16 );
4522 :
4523 : /*
4524 : ##913##
4525 : For Word the stored size of the graphic is critical the
4526 : metafile boundaries must match the actual graphics
4527 : boundaries, and the width and height must be in EMU's
4528 :
4529 : If you don't do it this way then objects edited in the
4530 : msoffice app may show strange behaviour as the size jumps
4531 : around, and the original size and scaling factor in word
4532 : will be a very strange figure
4533 : */
4534 30 : sal_uInt32 nPrefWidth = p_EscherBlibEntry->maPrefSize.Width();
4535 30 : sal_uInt32 nPrefHeight = p_EscherBlibEntry->maPrefSize.Height();
4536 : sal_uInt32 nWidth, nHeight;
4537 30 : if ( pVisArea )
4538 : {
4539 0 : nWidth = pVisArea->Width * 360;
4540 0 : nHeight = pVisArea->Height * 360;
4541 : }
4542 : else
4543 : {
4544 30 : Size aPrefSize(lcl_SizeToEmu(p_EscherBlibEntry->maPrefSize, p_EscherBlibEntry->maPrefMapMode));
4545 30 : nWidth = aPrefSize.Width() * 360;
4546 30 : nHeight = aPrefSize.Height() * 360;
4547 : }
4548 30 : rPicOutStrm.WriteUInt32( nUncompressedSize ) // WMFSize without FileHeader
4549 30 : .WriteInt32( 0 ) // since we can't find out anymore what the original size of
4550 30 : .WriteInt32( 0 ) // the WMF (without Fileheader) was we write 10cm / x
4551 30 : .WriteUInt32( nPrefWidth )
4552 30 : .WriteUInt32( nPrefHeight )
4553 30 : .WriteUInt32( nWidth )
4554 30 : .WriteUInt32( nHeight )
4555 60 : .WriteUInt32( p_EscherBlibEntry->mnSize )
4556 30 : .WriteUInt16( 0xfe00 ); // compression Flags
4557 30 : rPicOutStrm.Write( pGraphicAry, p_EscherBlibEntry->mnSize );
4558 30 : }
4559 : }
4560 130 : if ( nAtomSize )
4561 : {
4562 0 : sal_uInt32 nPos = rPicOutStrm.Tell();
4563 0 : rPicOutStrm.Seek( nAtomSize - 4 );
4564 0 : rPicOutStrm.WriteUInt32( ( nPos - nAtomSize ) );
4565 0 : rPicOutStrm.Seek( nPos );
4566 : }
4567 130 : nBlibId = ImplInsertBlib( p_EscherBlibEntry ), p_EscherBlibEntry = NULL;
4568 130 : }
4569 : }
4570 134 : if ( p_EscherBlibEntry )
4571 4 : delete p_EscherBlibEntry;
4572 134 : return nBlibId;
4573 : }
4574 :
4575 : struct EscherConnectorRule
4576 : {
4577 : sal_uInt32 nRuleId;
4578 : sal_uInt32 nShapeA; // SPID of shape A
4579 : sal_uInt32 nShapeB; // SPID of shape B
4580 : sal_uInt32 nShapeC; // SPID of connector shape
4581 : sal_uInt32 ncptiA; // Connection site Index of shape A
4582 : sal_uInt32 ncptiB; // Connection site Index of shape B
4583 : };
4584 :
4585 1628 : struct EscherShapeListEntry
4586 : {
4587 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > aXShape;
4588 : sal_uInt32 n_EscherId;
4589 :
4590 1628 : EscherShapeListEntry( const ::com::sun::star::uno::Reference
4591 : < ::com::sun::star::drawing::XShape > & rShape, sal_uInt32 nId ) :
4592 : aXShape ( rShape ),
4593 1628 : n_EscherId ( nId ) {}
4594 : };
4595 :
4596 0 : sal_uInt32 EscherConnectorListEntry::GetClosestPoint( const Polygon& rPoly, const ::com::sun::star::awt::Point& rPoint )
4597 : {
4598 0 : sal_uInt16 nCount = rPoly.GetSize();
4599 0 : sal_uInt16 nClosest = nCount;
4600 0 : double fDist = (sal_uInt32)0xffffffff;
4601 0 : while( nCount-- )
4602 : {
4603 0 : double fDistance = hypot( rPoint.X - rPoly[ nCount ].X(), rPoint.Y - rPoly[ nCount ].Y() );
4604 0 : if ( fDistance < fDist )
4605 : {
4606 0 : nClosest = nCount;
4607 0 : fDist = fDistance;
4608 : }
4609 : }
4610 0 : return nClosest;
4611 : };
4612 :
4613 :
4614 : // for rectangles for ellipses for polygons
4615 : //
4616 : // nRule = 0 ->Top 0 ->Top nRule = Index auf ein (Poly)Polygon Punkt
4617 : // 1 ->Left 2 ->Left
4618 : // 2 ->Bottom 4 ->Bottom
4619 : // 3 ->Right 6 ->Right
4620 :
4621 0 : sal_uInt32 EscherConnectorListEntry::GetConnectorRule( bool bFirst )
4622 : {
4623 0 : sal_uInt32 nRule = 0;
4624 :
4625 0 : ::com::sun::star::uno::Any aAny;
4626 0 : ::com::sun::star::awt::Point aRefPoint( ( bFirst ) ? maPointA : maPointB );
4627 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
4628 0 : aXShape( ( bFirst ) ? mXConnectToA : mXConnectToB );
4629 :
4630 0 : OUString aString(aXShape->getShapeType());
4631 0 : OStringBuffer aBuf(OUStringToOString(aString, RTL_TEXTENCODING_UTF8));
4632 0 : aBuf.remove( 0, 13 ); // removing "com.sun.star."
4633 0 : sal_Int16 nPos = aBuf.toString().indexOf("Shape");
4634 0 : aBuf.remove(nPos, 5);
4635 0 : OString aType = aBuf.makeStringAndClear();
4636 :
4637 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
4638 0 : aPropertySet( aXShape, ::com::sun::star::uno::UNO_QUERY );
4639 :
4640 0 : if ((aType == OString( "drawing.PolyPolygon" )) || (aType == OString( "drawing.PolyLine" )))
4641 : {
4642 0 : if ( aPropertySet.is() )
4643 : {
4644 0 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aPropertySet, "PolyPolygon" ) )
4645 : {
4646 : ::com::sun::star::drawing::PointSequenceSequence* pSourcePolyPolygon =
4647 0 : (::com::sun::star::drawing::PointSequenceSequence*)aAny.getValue();
4648 0 : sal_Int32 nOuterSequenceCount = pSourcePolyPolygon->getLength();
4649 0 : ::com::sun::star::drawing::PointSequence* pOuterSequence = pSourcePolyPolygon->getArray();
4650 :
4651 0 : if ( pOuterSequence )
4652 : {
4653 0 : sal_Int32 a, b, nIndex = 0;
4654 0 : sal_uInt32 nDistance = 0xffffffff;
4655 0 : for( a = 0; a < nOuterSequenceCount; a++ )
4656 : {
4657 0 : ::com::sun::star::drawing::PointSequence* pInnerSequence = pOuterSequence++;
4658 0 : if ( pInnerSequence )
4659 : {
4660 0 : ::com::sun::star::awt::Point* pArray = pInnerSequence->getArray();
4661 0 : if ( pArray )
4662 : {
4663 0 : for ( b = 0; b < pInnerSequence->getLength(); b++, nIndex++, pArray++ )
4664 : {
4665 0 : sal_uInt32 nDist = (sal_uInt32)hypot( aRefPoint.X - pArray->X, aRefPoint.Y - pArray->Y );
4666 0 : if ( nDist < nDistance )
4667 : {
4668 0 : nRule = nIndex;
4669 0 : nDistance = nDist;
4670 : }
4671 : }
4672 : }
4673 : }
4674 : }
4675 : }
4676 : }
4677 : }
4678 : }
4679 0 : else if ((aType == OString( "drawing.OpenBezier" )) || (aType == OString( "drawing.OpenFreeHand" )) || (aType == OString( "drawing.PolyLinePath" ))
4680 0 : || (aType == OString( "drawing.ClosedBezier" )) || ( aType == OString( "drawing.ClosedFreeHand" )) || (aType == OString( "drawing.PolyPolygonPath" )) )
4681 : {
4682 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
4683 0 : aPropertySet2( aXShape, ::com::sun::star::uno::UNO_QUERY );
4684 0 : if ( aPropertySet2.is() )
4685 : {
4686 0 : if ( EscherPropertyValueHelper::GetPropertyValue( aAny, aPropertySet2, "PolyPolygonBezier" ) )
4687 : {
4688 : ::com::sun::star::drawing::PolyPolygonBezierCoords* pSourcePolyPolygon =
4689 0 : (::com::sun::star::drawing::PolyPolygonBezierCoords*)aAny.getValue();
4690 0 : sal_Int32 nOuterSequenceCount = pSourcePolyPolygon->Coordinates.getLength();
4691 :
4692 : // Zeiger auf innere sequences holen
4693 : ::com::sun::star::drawing::PointSequence* pOuterSequence =
4694 0 : pSourcePolyPolygon->Coordinates.getArray();
4695 : ::com::sun::star::drawing::FlagSequence* pOuterFlags =
4696 0 : pSourcePolyPolygon->Flags.getArray();
4697 :
4698 0 : if ( pOuterSequence && pOuterFlags )
4699 : {
4700 0 : sal_Int32 a, b, nIndex = 0;
4701 0 : sal_uInt32 nDistance = 0xffffffff;
4702 :
4703 0 : for ( a = 0; a < nOuterSequenceCount; a++ )
4704 : {
4705 0 : ::com::sun::star::drawing::PointSequence* pInnerSequence = pOuterSequence++;
4706 0 : ::com::sun::star::drawing::FlagSequence* pInnerFlags = pOuterFlags++;
4707 0 : if ( pInnerSequence && pInnerFlags )
4708 : {
4709 0 : ::com::sun::star::awt::Point* pArray = pInnerSequence->getArray();
4710 0 : ::com::sun::star::drawing::PolygonFlags* pFlags = pInnerFlags->getArray();
4711 0 : if ( pArray && pFlags )
4712 : {
4713 0 : for ( b = 0; b < pInnerSequence->getLength(); b++, pArray++ )
4714 : {
4715 0 : PolyFlags ePolyFlags = *( (PolyFlags*)pFlags++ );
4716 0 : if ( ePolyFlags == POLY_CONTROL )
4717 0 : continue;
4718 0 : sal_uInt32 nDist = (sal_uInt32)hypot( aRefPoint.X - pArray->X, aRefPoint.Y - pArray->Y );
4719 0 : if ( nDist < nDistance )
4720 : {
4721 0 : nRule = nIndex;
4722 0 : nDistance = nDist;
4723 : }
4724 0 : nIndex++;
4725 : }
4726 : }
4727 : }
4728 : }
4729 : }
4730 : }
4731 0 : }
4732 : }
4733 : else
4734 : {
4735 0 : bool bRectangularConnection = true;
4736 :
4737 0 : if (aType == "drawing.Custom")
4738 : {
4739 0 : SdrObject* pCustoShape( GetSdrObjectFromXShape( aXShape ) );
4740 0 : if ( pCustoShape && pCustoShape->ISA( SdrObjCustomShape ) )
4741 : {
4742 : const SdrCustomShapeGeometryItem& rGeometryItem = static_cast<const SdrCustomShapeGeometryItem&>(
4743 0 : pCustoShape->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ));
4744 :
4745 0 : const OUString sPath( "Path" );
4746 0 : const OUString sType( "Type" );
4747 0 : const OUString sGluePointType( "GluePointType" );
4748 :
4749 0 : OUString sShapeType;
4750 0 : const uno::Any* pType = rGeometryItem.GetPropertyValueByName( sType );
4751 0 : if ( pType )
4752 0 : *pType >>= sShapeType;
4753 0 : MSO_SPT eSpType = EnhancedCustomShapeTypeNames::Get( sShapeType );
4754 :
4755 0 : uno::Any* pGluePointType = ((SdrCustomShapeGeometryItem&)rGeometryItem).GetPropertyValueByName( sPath, sGluePointType );
4756 :
4757 0 : sal_Int16 nGluePointType = sal_Int16();
4758 0 : if ( !( pGluePointType &&
4759 0 : ( *pGluePointType >>= nGluePointType ) ) )
4760 0 : nGluePointType = GetCustomShapeConnectionTypeDefault( eSpType );
4761 :
4762 0 : if ( nGluePointType == com::sun::star::drawing::EnhancedCustomShapeGluePointType::CUSTOM )
4763 : {
4764 0 : const SdrGluePointList* pList = pCustoShape->GetGluePointList();
4765 0 : if ( pList )
4766 : {
4767 0 : Polygon aPoly;
4768 0 : sal_uInt16 nNum, nAnz = pList->GetCount();
4769 0 : if ( nAnz )
4770 : {
4771 0 : for ( nNum = 0; nNum < nAnz; nNum++ )
4772 : {
4773 0 : const SdrGluePoint& rGP = (*pList)[ nNum ];
4774 0 : Point aPt( rGP.GetAbsolutePos( *pCustoShape ) );
4775 0 : aPoly.Insert( POLY_APPEND, aPt );
4776 : }
4777 0 : nRule = GetClosestPoint( aPoly, aRefPoint );
4778 0 : bRectangularConnection = false;
4779 0 : }
4780 : }
4781 : }
4782 0 : else if ( nGluePointType == com::sun::star::drawing::EnhancedCustomShapeGluePointType::SEGMENTS )
4783 : {
4784 0 : SdrObject* pPoly = pCustoShape->DoConvertToPolyObj( true, true );
4785 0 : if ( pPoly && pPoly->ISA( SdrPathObj ) )
4786 : {
4787 0 : sal_Int16 a, b, nIndex = 0;
4788 0 : sal_uInt32 nDistance = 0xffffffff;
4789 :
4790 : // #i74631# use explicit constructor here. Also XPolyPolygon is not necessary,
4791 : // reducing to PolyPolygon
4792 0 : const tools::PolyPolygon aPolyPoly(static_cast<SdrPathObj*>(pPoly)->GetPathPoly());
4793 :
4794 0 : for ( a = 0; a < aPolyPoly.Count(); a++ )
4795 : {
4796 0 : const Polygon& rPoly = aPolyPoly.GetObject( a );
4797 0 : for ( b = 0; b < rPoly.GetSize(); b++ )
4798 : {
4799 0 : if ( rPoly.GetFlags( b ) != POLY_NORMAL )
4800 0 : continue;
4801 0 : const Point& rPt = rPoly[ b ];
4802 0 : sal_uInt32 nDist = (sal_uInt32)hypot( aRefPoint.X - rPt.X(), aRefPoint.Y - rPt.Y() );
4803 0 : if ( nDist < nDistance )
4804 : {
4805 0 : nRule = nIndex;
4806 0 : nDistance = nDist;
4807 : }
4808 0 : nIndex++;
4809 : }
4810 : }
4811 0 : if ( nDistance != 0xffffffff )
4812 0 : bRectangularConnection = false;
4813 : }
4814 0 : }
4815 : }
4816 : }
4817 0 : if ( bRectangularConnection )
4818 : {
4819 0 : ::com::sun::star::awt::Point aPoint( aXShape->getPosition() );
4820 0 : ::com::sun::star::awt::Size aSize( aXShape->getSize() );
4821 :
4822 0 : Rectangle aRect( Point( aPoint.X, aPoint.Y ), Size( aSize.Width, aSize.Height ) );
4823 0 : Point aCenter( aRect.Center() );
4824 0 : Polygon aPoly( 4 );
4825 :
4826 0 : aPoly[ 0 ] = Point( aCenter.X(), aRect.Top() );
4827 0 : aPoly[ 1 ] = Point( aRect.Left(), aCenter.Y() );
4828 0 : aPoly[ 2 ] = Point( aCenter.X(), aRect.Bottom() );
4829 0 : aPoly[ 3 ] = Point( aRect.Right(), aCenter.Y() );
4830 :
4831 0 : sal_Int32 nAngle = ( EscherPropertyValueHelper::GetPropertyValue( aAny, aPropertySet, OUString( "RotateAngle" ), true ) )
4832 0 : ? *((sal_Int32*)aAny.getValue() ) : 0;
4833 0 : if ( nAngle )
4834 0 : aPoly.Rotate( aRect.TopLeft(), (sal_uInt16)( ( nAngle + 5 ) / 10 ) );
4835 0 : nRule = GetClosestPoint( aPoly, aRefPoint );
4836 :
4837 0 : if (aType == OString( "drawing.Ellipse" ))
4838 0 : nRule <<= 1; // In PPT an ellipse has 8 ways to connect
4839 : }
4840 : }
4841 0 : return nRule;
4842 : }
4843 :
4844 772 : EscherSolverContainer::~EscherSolverContainer()
4845 : {
4846 2014 : for( size_t i = 0, n = maShapeList.size(); i < n; ++i ) {
4847 1628 : delete maShapeList[ i ];
4848 : }
4849 440 : for( size_t i = 0, n = maConnectorList.size(); i < n; ++i ) {
4850 54 : delete maConnectorList[ i ];
4851 : }
4852 386 : }
4853 :
4854 1628 : void EscherSolverContainer::AddShape( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rXShape, sal_uInt32 nId )
4855 : {
4856 1628 : maShapeList.push_back( new EscherShapeListEntry( rXShape, nId ) );
4857 1628 : }
4858 :
4859 54 : void EscherSolverContainer::AddConnector(
4860 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rConnector,
4861 : const ::com::sun::star::awt::Point& rPA,
4862 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rConA,
4863 : const ::com::sun::star::awt::Point& rPB,
4864 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rConB
4865 : )
4866 : {
4867 54 : maConnectorList.push_back( new EscherConnectorListEntry( rConnector, rPA, rConA, rPB, rConB ) );
4868 54 : }
4869 :
4870 0 : sal_uInt32 EscherSolverContainer::GetShapeId( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rXShape ) const
4871 : {
4872 0 : for ( size_t i = 0, n = maShapeList.size(); i < n; ++i )
4873 : {
4874 0 : EscherShapeListEntry* pPtr = maShapeList[ i ];
4875 0 : if ( rXShape == pPtr->aXShape )
4876 0 : return ( pPtr->n_EscherId );
4877 : }
4878 0 : return 0;
4879 : }
4880 :
4881 122 : void EscherSolverContainer::WriteSolver( SvStream& rStrm )
4882 : {
4883 122 : sal_uInt32 nCount = maConnectorList.size();
4884 122 : if ( nCount )
4885 : {
4886 : sal_uInt32 nRecHdPos, nCurrentPos, nSize;
4887 0 : rStrm .WriteUInt16( ( ( nCount << 4 ) | 0xf ) ) // open an ESCHER_SolverContainer
4888 0 : .WriteUInt16( ESCHER_SolverContainer )
4889 0 : .WriteUInt32( 0 );
4890 :
4891 0 : nRecHdPos = rStrm.Tell() - 4;
4892 :
4893 : EscherConnectorRule aConnectorRule;
4894 0 : aConnectorRule.nRuleId = 2;
4895 0 : for ( size_t i = 0, n = maConnectorList.size(); i < n; ++i )
4896 : {
4897 0 : EscherConnectorListEntry* pPtr = maConnectorList[ i ];
4898 0 : aConnectorRule.ncptiA = aConnectorRule.ncptiB = 0xffffffff;
4899 0 : aConnectorRule.nShapeC = GetShapeId( pPtr->mXConnector );
4900 0 : aConnectorRule.nShapeA = GetShapeId( pPtr->mXConnectToA );
4901 0 : aConnectorRule.nShapeB = GetShapeId( pPtr->mXConnectToB );
4902 :
4903 0 : if ( aConnectorRule.nShapeC )
4904 : {
4905 0 : if ( aConnectorRule.nShapeA )
4906 0 : aConnectorRule.ncptiA = pPtr->GetConnectorRule( true );
4907 0 : if ( aConnectorRule.nShapeB )
4908 0 : aConnectorRule.ncptiB = pPtr->GetConnectorRule( false );
4909 : }
4910 0 : rStrm .WriteUInt32( ( ( ESCHER_ConnectorRule << 16 ) | 1 ) ) // atom hd
4911 0 : .WriteUInt32( 24 )
4912 0 : .WriteUInt32( aConnectorRule.nRuleId )
4913 0 : .WriteUInt32( aConnectorRule.nShapeA )
4914 0 : .WriteUInt32( aConnectorRule.nShapeB )
4915 0 : .WriteUInt32( aConnectorRule.nShapeC )
4916 0 : .WriteUInt32( aConnectorRule.ncptiA )
4917 0 : .WriteUInt32( aConnectorRule.ncptiB );
4918 :
4919 0 : aConnectorRule.nRuleId += 2;
4920 : }
4921 :
4922 0 : nCurrentPos = rStrm.Tell(); // close the ESCHER_SolverContainer
4923 0 : nSize = ( nCurrentPos - nRecHdPos ) - 4;
4924 0 : rStrm.Seek( nRecHdPos );
4925 0 : rStrm.WriteUInt32( nSize );
4926 0 : rStrm.Seek( nCurrentPos );
4927 : }
4928 122 : }
4929 :
4930 1072 : EscherExGlobal::EscherExGlobal( sal_uInt32 nGraphicProvFlags ) :
4931 : EscherGraphicProvider( nGraphicProvFlags ),
4932 : mpPicStrm( 0 ),
4933 : mbHasDggCont( false ),
4934 1072 : mbPicStrmQueried( false )
4935 : {
4936 1072 : }
4937 :
4938 2070 : EscherExGlobal::~EscherExGlobal()
4939 : {
4940 2070 : }
4941 :
4942 134 : sal_uInt32 EscherExGlobal::GenerateDrawingId()
4943 : {
4944 : // new drawing starts a new cluster in the cluster table (cluster identifiers are one-based)
4945 134 : sal_uInt32 nClusterId = static_cast< sal_uInt32 >( maClusterTable.size() + 1 );
4946 : // drawing identifiers are one-based
4947 134 : sal_uInt32 nDrawingId = static_cast< sal_uInt32 >( maDrawingInfos.size() + 1 );
4948 : // prepare new entries in the tables
4949 134 : maClusterTable.push_back( ClusterEntry( nDrawingId ) );
4950 134 : maDrawingInfos.push_back( DrawingInfo( nClusterId ) );
4951 : // return the new drawing identifier
4952 134 : return nDrawingId;
4953 : }
4954 :
4955 1878 : sal_uInt32 EscherExGlobal::GenerateShapeId( sal_uInt32 nDrawingId, bool bIsInSpgr )
4956 : {
4957 : // drawing identifier is one-based
4958 : // make sure the drawing is valid (bnc#656503)
4959 1878 : if ( nDrawingId == 0 )
4960 1684 : return 0;
4961 : // create index from the identifier
4962 194 : size_t nDrawingIdx = nDrawingId - 1;
4963 : OSL_ENSURE( nDrawingIdx < maDrawingInfos.size(), "EscherExGlobal::GenerateShapeId - invalid drawing ID" );
4964 194 : if( nDrawingIdx >= maDrawingInfos.size() )
4965 0 : return 0;
4966 194 : DrawingInfo& rDrawingInfo = maDrawingInfos[ nDrawingIdx ];
4967 :
4968 : // cluster identifier in drawing info struct is one-based
4969 194 : ClusterEntry* pClusterEntry = &maClusterTable[ rDrawingInfo.mnClusterId - 1 ];
4970 :
4971 : // check cluster overflow, create new cluster entry
4972 194 : if( pClusterEntry->mnNextShapeId == DFF_DGG_CLUSTER_SIZE )
4973 : {
4974 : // start a new cluster in the cluster table
4975 0 : maClusterTable.push_back( ClusterEntry( nDrawingId ) );
4976 0 : pClusterEntry = &maClusterTable.back();
4977 : // new size of maClusterTable is equal to one-based identifier of the new cluster
4978 0 : rDrawingInfo.mnClusterId = static_cast< sal_uInt32 >( maClusterTable.size() );
4979 : }
4980 :
4981 : // build shape identifier from cluster identifier and next free cluster shape identifier
4982 194 : rDrawingInfo.mnLastShapeId = static_cast< sal_uInt32 >( rDrawingInfo.mnClusterId * DFF_DGG_CLUSTER_SIZE + pClusterEntry->mnNextShapeId );
4983 : // update free shape identifier in cluster entry
4984 194 : ++pClusterEntry->mnNextShapeId;
4985 : /* Old code has counted the shapes only, if we are in a SPGRCONTAINER. Is
4986 : this really intended? Maybe it's always true... */
4987 194 : if( bIsInSpgr )
4988 194 : ++rDrawingInfo.mnShapeCount;
4989 :
4990 : // return the new shape identifier
4991 194 : return rDrawingInfo.mnLastShapeId;
4992 : }
4993 :
4994 134 : sal_uInt32 EscherExGlobal::GetDrawingShapeCount( sal_uInt32 nDrawingId ) const
4995 : {
4996 134 : size_t nDrawingIdx = nDrawingId - 1;
4997 : OSL_ENSURE( nDrawingIdx < maDrawingInfos.size(), "EscherExGlobal::GetDrawingShapeCount - invalid drawing ID" );
4998 134 : return (nDrawingIdx < maDrawingInfos.size()) ? maDrawingInfos[ nDrawingIdx ].mnShapeCount : 0;
4999 : }
5000 :
5001 134 : sal_uInt32 EscherExGlobal::GetLastShapeId( sal_uInt32 nDrawingId ) const
5002 : {
5003 134 : size_t nDrawingIdx = nDrawingId - 1;
5004 : OSL_ENSURE( nDrawingIdx < maDrawingInfos.size(), "EscherExGlobal::GetLastShapeId - invalid drawing ID" );
5005 134 : return (nDrawingIdx < maDrawingInfos.size()) ? maDrawingInfos[ nDrawingIdx ].mnLastShapeId : 0;
5006 : }
5007 :
5008 144 : sal_uInt32 EscherExGlobal::GetDggAtomSize() const
5009 : {
5010 : // 8 bytes header, 16 bytes fixed DGG data, 8 bytes for each cluster
5011 144 : return static_cast< sal_uInt32 >( 24 + 8 * maClusterTable.size() );
5012 : }
5013 :
5014 72 : void EscherExGlobal::WriteDggAtom( SvStream& rStrm ) const
5015 : {
5016 72 : sal_uInt32 nDggSize = GetDggAtomSize();
5017 :
5018 : // write the DGG record header (do not include the 8 bytes of the header in the data size)
5019 72 : rStrm.WriteUInt32( ESCHER_Dgg << 16 ).WriteUInt32( nDggSize - 8 );
5020 :
5021 : // claculate and write the fixed DGG data
5022 72 : sal_uInt32 nShapeCount = 0;
5023 72 : sal_uInt32 nLastShapeId = 0;
5024 206 : for( DrawingInfoVector::const_iterator aIt = maDrawingInfos.begin(), aEnd = maDrawingInfos.end(); aIt != aEnd; ++aIt )
5025 : {
5026 134 : nShapeCount += aIt->mnShapeCount;
5027 134 : nLastShapeId = ::std::max( nLastShapeId, aIt->mnLastShapeId );
5028 : }
5029 : // the non-existing cluster with index #0 is counted too
5030 72 : sal_uInt32 nClusterCount = static_cast< sal_uInt32 >( maClusterTable.size() + 1 );
5031 72 : sal_uInt32 nDrawingCount = static_cast< sal_uInt32 >( maDrawingInfos.size() );
5032 72 : rStrm.WriteUInt32( nLastShapeId ).WriteUInt32( nClusterCount ).WriteUInt32( nShapeCount ).WriteUInt32( nDrawingCount );
5033 :
5034 : // write the cluster table
5035 206 : for( ClusterTable::const_iterator aIt = maClusterTable.begin(), aEnd = maClusterTable.end(); aIt != aEnd; ++aIt )
5036 134 : rStrm.WriteUInt32( aIt->mnDrawingId ).WriteUInt32( aIt->mnNextShapeId );
5037 72 : }
5038 :
5039 1624 : SvStream* EscherExGlobal::QueryPictureStream()
5040 : {
5041 1624 : if( !mbPicStrmQueried )
5042 : {
5043 278 : mpPicStrm = ImplQueryPictureStream();
5044 278 : mbPicStrmQueried = true;
5045 : }
5046 1624 : return mpPicStrm;
5047 : }
5048 :
5049 264 : SvStream* EscherExGlobal::ImplQueryPictureStream()
5050 : {
5051 264 : return 0;
5052 : }
5053 :
5054 : // /Implementation of an empty stream that silently succeeds, but does nothing.
5055 : // /
5056 : // /In fact, this is a hack. The right solution is to abstract EscherEx to be
5057 : // /able to work without SvStream; but at the moment it is better to live with
5058 : // /this I guess.
5059 : class SvNullStream : public SvStream
5060 : {
5061 : protected:
5062 0 : virtual sal_Size GetData( void* pData, sal_Size nSize ) SAL_OVERRIDE { memset( pData, 0, nSize ); return nSize; }
5063 11724 : virtual sal_Size PutData( const void*, sal_Size nSize ) SAL_OVERRIDE { return nSize; }
5064 3216 : virtual sal_uInt64 SeekPos( sal_uInt64 nPos ) SAL_OVERRIDE { return nPos; }
5065 0 : virtual void SetSize( sal_uInt64 ) SAL_OVERRIDE {}
5066 0 : virtual void FlushData() SAL_OVERRIDE {}
5067 :
5068 : public:
5069 998 : SvNullStream() : SvStream() {}
5070 1996 : virtual ~SvNullStream() {}
5071 : };
5072 :
5073 1072 : EscherEx::EscherEx(const EscherExGlobalRef& rxGlobal, SvStream* pOutStrm, bool bOOXML)
5074 : : mxGlobal(rxGlobal)
5075 : , mpOutStrm(pOutStrm)
5076 : , mbOwnsStrm(false)
5077 : , mnCurrentDg(0)
5078 : , mnCountOfs(0)
5079 : , mnGroupLevel(0)
5080 : , mnHellLayerId(USHRT_MAX)
5081 : , mbEscherSpgr(false)
5082 : , mbEscherDg(false)
5083 : , mbOleEmf(false)
5084 1072 : , mbOOXML(bOOXML)
5085 : {
5086 1072 : if (!mpOutStrm)
5087 : {
5088 998 : mpOutStrm = new SvNullStream();
5089 998 : mbOwnsStrm = true;
5090 : }
5091 1072 : mnStrmStartOfs = mpOutStrm->Tell();
5092 1072 : mpImplEscherExSdr.reset( new ImplEscherExSdr( *this ) );
5093 1072 : }
5094 :
5095 2144 : EscherEx::~EscherEx()
5096 : {
5097 1072 : if (mbOwnsStrm)
5098 998 : delete mpOutStrm;
5099 1072 : }
5100 :
5101 72 : void EscherEx::Flush( SvStream* pPicStreamMergeBSE /* = NULL */ )
5102 : {
5103 72 : if ( mxGlobal->HasDggContainer() )
5104 : {
5105 : // store the current stream position at ESCHER_Persist_CurrentPosition key
5106 72 : PtReplaceOrInsert( ESCHER_Persist_CurrentPosition, mpOutStrm->Tell() );
5107 72 : if ( DoSeek( ESCHER_Persist_Dgg ) )
5108 : {
5109 : /* The DGG record is still not written. ESCHER_Persist_Dgg seeks
5110 : to the place where the complete record has to be inserted. */
5111 72 : InsertAtCurrentPos( mxGlobal->GetDggAtomSize(), false );
5112 72 : mxGlobal->WriteDggAtom( *mpOutStrm );
5113 :
5114 72 : if ( mxGlobal->HasGraphics() )
5115 : {
5116 : /* Calculate the total size of the BSTORECONTAINER including
5117 : all BSE records containing the picture data contained in
5118 : the passed in pPicStreamMergeBSE. */
5119 10 : sal_uInt32 nBSCSize = mxGlobal->GetBlibStoreContainerSize( pPicStreamMergeBSE );
5120 10 : if ( nBSCSize > 0 )
5121 : {
5122 10 : InsertAtCurrentPos( nBSCSize, false );
5123 10 : mxGlobal->WriteBlibStoreContainer( *mpOutStrm, pPicStreamMergeBSE );
5124 : }
5125 : }
5126 :
5127 : /* Forget the stream position stored for the DGG which is invalid
5128 : after the call to InsertAtCurrentPos() anyway. */
5129 72 : PtDelete( ESCHER_Persist_Dgg );
5130 : }
5131 : // seek to initial position (may be different due to inserted DGG and BLIPs)
5132 72 : mpOutStrm->Seek( PtGetOffsetByID( ESCHER_Persist_CurrentPosition ) );
5133 : }
5134 72 : }
5135 :
5136 82 : void EscherEx::InsertAtCurrentPos( sal_uInt32 nBytes, bool bExpandEndOfAtom )
5137 : {
5138 82 : sal_uInt32 nSize, nType, nSource, nBufSize, nToCopy, nCurPos = mpOutStrm->Tell();
5139 :
5140 : // adjust persist table
5141 682 : for( size_t i = 0, n = maPersistTable.size(); i < n; ++i ) {
5142 600 : EscherPersistEntry* pPtr = maPersistTable[ i ];
5143 600 : sal_uInt32 nOfs = pPtr->mnOffset;
5144 600 : if ( nOfs >= nCurPos ) {
5145 532 : pPtr->mnOffset += nBytes;
5146 : }
5147 : }
5148 :
5149 : // adapt container and atom sizes
5150 82 : mpOutStrm->Seek( mnStrmStartOfs );
5151 256 : while ( mpOutStrm->Tell() < nCurPos )
5152 : {
5153 92 : mpOutStrm->ReadUInt32( nType ).ReadUInt32( nSize );
5154 92 : sal_uInt32 nEndOfRecord = mpOutStrm->Tell() + nSize;
5155 92 : bool bContainer = (nType & 0x0F) == 0x0F;
5156 : /* Expand the record, if the insertion position is inside, or if the
5157 : position is at the end of a container (expands always), or at the
5158 : end of an atom and bExpandEndOfAtom is set. */
5159 92 : if ( (nCurPos < nEndOfRecord) || ((nCurPos == nEndOfRecord) && (bContainer || bExpandEndOfAtom)) )
5160 : {
5161 82 : mpOutStrm->SeekRel( -4 );
5162 82 : mpOutStrm->WriteUInt32( ( nSize + nBytes ) );
5163 164 : if ( !bContainer )
5164 0 : mpOutStrm->SeekRel( nSize );
5165 : }
5166 : else
5167 10 : mpOutStrm->SeekRel( nSize );
5168 : }
5169 82 : for (std::vector< sal_uInt32 >::iterator aIter( mOffsets.begin() ), aEnd( mOffsets.end() ); aIter != aEnd ; ++aIter)
5170 : {
5171 0 : if ( *aIter > nCurPos )
5172 0 : *aIter += nBytes;
5173 : }
5174 82 : mpOutStrm->Seek( STREAM_SEEK_TO_END );
5175 82 : nSource = mpOutStrm->Tell();
5176 82 : nToCopy = nSource - nCurPos; // increase the size of the tream by nBytes
5177 82 : boost::scoped_array<sal_uInt8> pBuf(new sal_uInt8[ 0x40000 ]); // 256KB Buffer
5178 246 : while ( nToCopy )
5179 : {
5180 82 : nBufSize = ( nToCopy >= 0x40000 ) ? 0x40000 : nToCopy;
5181 82 : nToCopy -= nBufSize;
5182 82 : nSource -= nBufSize;
5183 82 : mpOutStrm->Seek( nSource );
5184 82 : mpOutStrm->Read( pBuf.get(), nBufSize );
5185 82 : mpOutStrm->Seek( nSource + nBytes );
5186 82 : mpOutStrm->Write( pBuf.get(), nBufSize );
5187 : }
5188 82 : mpOutStrm->Seek( nCurPos );
5189 82 : }
5190 :
5191 258 : void EscherEx::InsertPersistOffset( sal_uInt32 nKey, sal_uInt32 nOffset )
5192 : {
5193 258 : PtInsert( ESCHER_Persist_PrivateEntry | nKey, nOffset );
5194 258 : }
5195 :
5196 224 : void EscherEx::ReplacePersistOffset( sal_uInt32 nKey, sal_uInt32 nOffset )
5197 : {
5198 224 : PtReplace( ESCHER_Persist_PrivateEntry | nKey, nOffset );
5199 224 : }
5200 :
5201 8 : void EscherEx::SetEditAs( const OUString& rEditAs )
5202 : {
5203 8 : mEditAs = rEditAs;
5204 8 : }
5205 :
5206 288 : sal_uInt32 EscherEx::GetPersistOffset( sal_uInt32 nKey )
5207 : {
5208 288 : return PtGetOffsetByID( ESCHER_Persist_PrivateEntry | nKey );
5209 : }
5210 :
5211 206 : bool EscherEx::DoSeek( sal_uInt32 nKey )
5212 : {
5213 206 : sal_uInt32 nPos = PtGetOffsetByID( nKey );
5214 206 : if ( nPos )
5215 206 : mpOutStrm->Seek( nPos );
5216 : else
5217 : {
5218 0 : if (! PtIsID( nKey ) )
5219 0 : return false;
5220 0 : mpOutStrm->Seek( 0 );
5221 : }
5222 206 : return true;
5223 : }
5224 :
5225 0 : bool EscherEx::SeekToPersistOffset( sal_uInt32 nKey )
5226 : {
5227 0 : return DoSeek( ESCHER_Persist_PrivateEntry | nKey );
5228 : }
5229 :
5230 0 : bool EscherEx::InsertAtPersistOffset( sal_uInt32 nKey, sal_uInt32 nValue )
5231 : {
5232 0 : sal_uInt32 nOldPos = mpOutStrm->Tell();
5233 0 : bool bRetValue = SeekToPersistOffset( nKey );
5234 0 : if ( bRetValue )
5235 : {
5236 0 : mpOutStrm->WriteUInt32( nValue );
5237 0 : mpOutStrm->Seek( nOldPos );
5238 : }
5239 0 : return bRetValue;
5240 : }
5241 :
5242 2144 : void EscherEx::OpenContainer( sal_uInt16 nEscherContainer, int nRecInstance )
5243 : {
5244 2144 : mpOutStrm->WriteUInt16( ( ( nRecInstance << 4 ) | 0xf ) ).WriteUInt16( nEscherContainer ).WriteUInt32( 0 );
5245 2144 : mOffsets.push_back( mpOutStrm->Tell() - 4 );
5246 2144 : mRecTypes.push_back( nEscherContainer );
5247 2144 : switch( nEscherContainer )
5248 : {
5249 : case ESCHER_DggContainer :
5250 : {
5251 72 : mxGlobal->SetDggContainer();
5252 72 : mnCurrentDg = 0;
5253 : /* Remember the current position as start position of the DGG
5254 : record and BSTORECONTAINER, but do not write them actually.
5255 : This will be done later in Flush() when the number of drawings,
5256 : the size and contents of the FIDCL cluster table, and the size
5257 : of the BLIP container are known. */
5258 72 : PtReplaceOrInsert( ESCHER_Persist_Dgg, mpOutStrm->Tell() );
5259 : }
5260 72 : break;
5261 :
5262 : case ESCHER_DgContainer :
5263 : {
5264 134 : if ( mxGlobal->HasDggContainer() )
5265 : {
5266 134 : if ( !mbEscherDg )
5267 : {
5268 134 : mbEscherDg = true;
5269 134 : mnCurrentDg = mxGlobal->GenerateDrawingId();
5270 134 : AddAtom( 8, ESCHER_Dg, 0, mnCurrentDg );
5271 134 : PtReplaceOrInsert( ESCHER_Persist_Dg | mnCurrentDg, mpOutStrm->Tell() );
5272 134 : mpOutStrm->WriteUInt32( 0 ) // The number of shapes in this drawing
5273 134 : .WriteUInt32( 0 ); // The last MSOSPID given to an SP in this DG
5274 : }
5275 : }
5276 : }
5277 134 : break;
5278 :
5279 : case ESCHER_SpgrContainer :
5280 : {
5281 134 : if ( mbEscherDg )
5282 : {
5283 134 : mbEscherSpgr = true;
5284 : }
5285 : }
5286 134 : break;
5287 :
5288 : case ESCHER_SpContainer :
5289 : {
5290 : }
5291 1804 : break;
5292 :
5293 : default:
5294 0 : break;
5295 : }
5296 2144 : }
5297 :
5298 2144 : void EscherEx::CloseContainer()
5299 : {
5300 2144 : sal_uInt32 nSize, nPos = mpOutStrm->Tell();
5301 2144 : nSize = ( nPos - mOffsets.back() ) - 4;
5302 2144 : mpOutStrm->Seek( mOffsets.back() );
5303 2144 : mpOutStrm->WriteUInt32( nSize );
5304 :
5305 2144 : switch( mRecTypes.back() )
5306 : {
5307 : case ESCHER_DgContainer :
5308 : {
5309 134 : if ( mbEscherDg )
5310 : {
5311 134 : mbEscherDg = false;
5312 134 : if ( DoSeek( ESCHER_Persist_Dg | mnCurrentDg ) )
5313 134 : mpOutStrm->WriteUInt32( mxGlobal->GetDrawingShapeCount( mnCurrentDg ) ).WriteUInt32( mxGlobal->GetLastShapeId( mnCurrentDg ) );
5314 : }
5315 : }
5316 134 : break;
5317 :
5318 : case ESCHER_SpgrContainer :
5319 : {
5320 134 : if ( mbEscherSpgr )
5321 : {
5322 134 : mbEscherSpgr = false;
5323 :
5324 : }
5325 : }
5326 134 : break;
5327 :
5328 : default:
5329 1876 : break;
5330 : }
5331 2144 : mOffsets.pop_back();
5332 2144 : mRecTypes.pop_back();
5333 2144 : mpOutStrm->Seek( nPos );
5334 2144 : }
5335 :
5336 0 : void EscherEx::BeginAtom()
5337 : {
5338 0 : mnCountOfs = mpOutStrm->Tell();
5339 0 : mpOutStrm->WriteUInt32( 0 ).WriteUInt32( 0 ); // record header wird spaeter geschrieben
5340 0 : }
5341 :
5342 0 : void EscherEx::EndAtom( sal_uInt16 nRecType, int nRecVersion, int nRecInstance )
5343 : {
5344 0 : sal_uInt32 nOldPos = mpOutStrm->Tell();
5345 0 : mpOutStrm->Seek( mnCountOfs );
5346 0 : sal_uInt32 nSize = nOldPos - mnCountOfs;
5347 0 : mpOutStrm->WriteUInt16( ( ( nRecInstance << 4 ) | ( nRecVersion & 0xf ) ) ).WriteUInt16( nRecType ).WriteUInt32( ( nSize - 8 ) );
5348 0 : mpOutStrm->Seek( nOldPos );
5349 0 : }
5350 :
5351 1468 : void EscherEx::AddAtom( sal_uInt32 nAtomSize, sal_uInt16 nRecType, int nRecVersion, int nRecInstance )
5352 : {
5353 1468 : mpOutStrm->WriteUInt16( ( ( nRecInstance << 4 ) | ( nRecVersion & 0xf ) ) ).WriteUInt16( nRecType ).WriteUInt32( nAtomSize );
5354 1468 : }
5355 :
5356 756 : void EscherEx::AddChildAnchor( const Rectangle& rRect )
5357 : {
5358 756 : AddAtom( 16, ESCHER_ChildAnchor );
5359 756 : mpOutStrm ->WriteInt32( rRect.Left() )
5360 1512 : .WriteInt32( rRect.Top() )
5361 1512 : .WriteInt32( rRect.Right() )
5362 1512 : .WriteInt32( rRect.Bottom() );
5363 756 : }
5364 :
5365 0 : void EscherEx::AddClientAnchor( const Rectangle& rRect )
5366 : {
5367 0 : AddAtom( 8, ESCHER_ClientAnchor );
5368 0 : mpOutStrm->WriteInt16( rRect.Top() )
5369 0 : .WriteInt16( rRect.Left() )
5370 0 : .WriteInt16( ( rRect.GetWidth() + rRect.Left() ) )
5371 0 : .WriteInt16( ( rRect.GetHeight() + rRect.Top() ) );
5372 0 : }
5373 :
5374 0 : EscherExHostAppData* EscherEx::EnterAdditionalTextGroup()
5375 : {
5376 0 : return NULL;
5377 : }
5378 :
5379 134 : sal_uInt32 EscherEx::EnterGroup( const OUString& rShapeName, const Rectangle* pBoundRect )
5380 : {
5381 134 : Rectangle aRect;
5382 134 : if( pBoundRect )
5383 124 : aRect = *pBoundRect;
5384 :
5385 134 : OpenContainer( ESCHER_SpgrContainer );
5386 134 : OpenContainer( ESCHER_SpContainer );
5387 134 : AddAtom( 16, ESCHER_Spgr, 1 );
5388 : PtReplaceOrInsert( ESCHER_Persist_Grouping_Snap | mnGroupLevel,
5389 134 : mpOutStrm->Tell() );
5390 134 : mpOutStrm ->WriteInt32( aRect.Left() ) // Bounding box for the grouped shapes to which they will be attached
5391 268 : .WriteInt32( aRect.Top() )
5392 268 : .WriteInt32( aRect.Right() )
5393 268 : .WriteInt32( aRect.Bottom() );
5394 :
5395 134 : sal_uInt32 nShapeId = GenerateShapeId();
5396 134 : if ( !mnGroupLevel )
5397 134 : AddShape( ESCHER_ShpInst_Min, 5, nShapeId ); // Flags: Group | Patriarch
5398 : else
5399 : {
5400 0 : AddShape( ESCHER_ShpInst_Min, 0x201, nShapeId ); // Flags: Group | HaveAnchor
5401 0 : EscherPropertyContainer aPropOpt;
5402 0 : aPropOpt.AddOpt( ESCHER_Prop_LockAgainstGrouping, 0x00040004 );
5403 0 : aPropOpt.AddOpt( ESCHER_Prop_dxWrapDistLeft, 0 );
5404 0 : aPropOpt.AddOpt( ESCHER_Prop_dxWrapDistRight, 0 );
5405 :
5406 : // #i51348# shape name
5407 0 : if( rShapeName.getLength() > 0 )
5408 0 : aPropOpt.AddOpt( ESCHER_Prop_wzName, rShapeName );
5409 :
5410 0 : Commit( aPropOpt, aRect );
5411 0 : if ( mnGroupLevel > 1 )
5412 0 : AddChildAnchor( aRect );
5413 :
5414 0 : EscherExHostAppData* pAppData = mpImplEscherExSdr->ImplGetHostData();
5415 0 : if( pAppData )
5416 : {
5417 0 : if ( mnGroupLevel <= 1 )
5418 0 : pAppData->WriteClientAnchor( *this, aRect );
5419 0 : pAppData->WriteClientData( *this );
5420 0 : }
5421 : }
5422 134 : CloseContainer(); // ESCHER_SpContainer
5423 134 : mnGroupLevel++;
5424 134 : return nShapeId;
5425 : }
5426 :
5427 134 : sal_uInt32 EscherEx::EnterGroup( const Rectangle* pBoundRect )
5428 : {
5429 134 : return EnterGroup( OUString(), pBoundRect );
5430 : }
5431 :
5432 0 : bool EscherEx::SetGroupSnapRect( sal_uInt32 nGroupLevel, const Rectangle& rRect )
5433 : {
5434 0 : bool bRetValue = false;
5435 0 : if ( nGroupLevel )
5436 : {
5437 0 : sal_uInt32 nCurrentPos = mpOutStrm->Tell();
5438 0 : if ( DoSeek( ESCHER_Persist_Grouping_Snap | ( nGroupLevel - 1 ) ) )
5439 : {
5440 0 : mpOutStrm ->WriteInt32( rRect.Left() ) // Bounding box for the grouped shapes to which they will be attached
5441 0 : .WriteInt32( rRect.Top() )
5442 0 : .WriteInt32( rRect.Right() )
5443 0 : .WriteInt32( rRect.Bottom() );
5444 0 : mpOutStrm->Seek( nCurrentPos );
5445 : }
5446 : }
5447 0 : return bRetValue;
5448 : }
5449 :
5450 0 : bool EscherEx::SetGroupLogicRect( sal_uInt32 nGroupLevel, const Rectangle& rRect )
5451 : {
5452 0 : bool bRetValue = false;
5453 0 : if ( nGroupLevel )
5454 : {
5455 0 : sal_uInt32 nCurrentPos = mpOutStrm->Tell();
5456 0 : if ( DoSeek( ESCHER_Persist_Grouping_Logic | ( nGroupLevel - 1 ) ) )
5457 : {
5458 0 : mpOutStrm->WriteInt16( rRect.Top() ).WriteInt16( rRect.Left() ).WriteInt16( rRect.Right() ).WriteInt16( rRect.Bottom() );
5459 0 : mpOutStrm->Seek( nCurrentPos );
5460 : }
5461 : }
5462 0 : return bRetValue;
5463 : }
5464 :
5465 134 : void EscherEx::LeaveGroup()
5466 : {
5467 134 : --mnGroupLevel;
5468 134 : PtDelete( ESCHER_Persist_Grouping_Snap | mnGroupLevel );
5469 134 : PtDelete( ESCHER_Persist_Grouping_Logic | mnGroupLevel );
5470 134 : CloseContainer();
5471 134 : }
5472 :
5473 196 : void EscherEx::AddShape( sal_uInt32 nShpInstance, sal_uInt32 nFlags, sal_uInt32 nShapeID )
5474 : {
5475 196 : AddAtom( 8, ESCHER_Sp, 2, nShpInstance );
5476 :
5477 196 : if ( !nShapeID )
5478 22 : nShapeID = GenerateShapeId();
5479 :
5480 196 : if ( nFlags ^ 1 ) // is this a group shape ?
5481 : { // if not
5482 196 : if ( mnGroupLevel > 1 )
5483 0 : nFlags |= 2; // this not a topmost shape
5484 : }
5485 196 : mpOutStrm->WriteUInt32( nShapeID ).WriteUInt32( nFlags );
5486 196 : }
5487 :
5488 20 : void EscherEx::Commit( EscherPropertyContainer& rProps, const Rectangle& )
5489 : {
5490 20 : rProps.Commit( GetStream() );
5491 20 : }
5492 :
5493 18 : sal_uInt32 EscherEx::GetColor( const sal_uInt32 nSOColor, bool bSwap )
5494 : {
5495 18 : if ( bSwap )
5496 : {
5497 18 : sal_uInt32 nColor = nSOColor & 0xff00; // Green
5498 18 : nColor |= (sal_uInt8)( nSOColor ) << 16; // Red
5499 18 : nColor |= (sal_uInt8)( nSOColor >> 16 ); // Blue
5500 18 : return nColor;
5501 : }
5502 : else
5503 0 : return nSOColor & 0xffffff;
5504 : }
5505 :
5506 18 : sal_uInt32 EscherEx::GetColor( const Color& rSOColor, bool bSwap )
5507 : {
5508 18 : sal_uInt32 nColor = ( rSOColor.GetRed() << 16 );
5509 18 : nColor |= ( rSOColor.GetGreen() << 8 );
5510 18 : nColor |= rSOColor.GetBlue();
5511 :
5512 18 : if ( !bSwap )
5513 18 : nColor = GetColor( nColor, true );
5514 :
5515 18 : return nColor;
5516 570 : }
5517 :
5518 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|