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/svdobj.hxx>
22 : #include <svx/unoapi.hxx>
23 : #include <svx/svdoashp.hxx>
24 : #include <svx/unoshape.hxx>
25 : #include <vcl/outdev.hxx>
26 : #include <tools/poly.hxx>
27 : #include <vcl/bitmapex.hxx>
28 : #include <vcl/graph.hxx>
29 : #include <tools/debug.hxx>
30 : #include <svx/fmdpage.hxx>
31 : #include <toolkit/helper/vclunohelper.hxx>
32 : #include <com/sun/star/style/VerticalAlignment.hpp>
33 : #include <com/sun/star/awt/Gradient.hpp>
34 : #include <com/sun/star/drawing/PointSequence.hpp>
35 : #include <com/sun/star/drawing/PointSequenceSequence.hpp>
36 : #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
37 : #include <com/sun/star/drawing/FlagSequence.hpp>
38 : #include <com/sun/star/drawing/TextAdjust.hpp>
39 : #include <com/sun/star/drawing/LineDash.hpp>
40 : #include <com/sun/star/text/XText.hpp>
41 : #include <com/sun/star/drawing/CircleKind.hpp>
42 : #include <com/sun/star/drawing/FillStyle.hpp>
43 : #include <com/sun/star/task/XStatusIndicator.hpp>
44 : #include <comphelper/extract.hxx>
45 : #include <vcl/fltcall.hxx>
46 : #include <vcl/cvtgrf.hxx>
47 : #include <com/sun/star/drawing/HomogenMatrix3.hpp>
48 : #include <basegfx/matrix/b2dhommatrix.hxx>
49 : #include <basegfx/polygon/b2dpolygontools.hxx>
50 : #include <basegfx/polygon/b2dpolygon.hxx>
51 :
52 : using namespace ::com::sun::star;
53 : using namespace ::com::sun::star::beans;
54 : using namespace ::com::sun::star::container;
55 : using namespace ::com::sun::star::uno;
56 : using namespace ::com::sun::star::drawing;
57 : using namespace ::com::sun::star::text;
58 : using namespace ::com::sun::star::task;
59 : using namespace ::com::sun::star::style;
60 :
61 : #define EES_MAP_FRACTION 1440 // 1440 dpi
62 :
63 0 : ImplEESdrWriter::ImplEESdrWriter( EscherEx& rEx )
64 : : mpEscherEx(&rEx)
65 : , maMapModeSrc(MAP_100TH_MM)
66 : // PowerPoint: 576 dpi, WinWord: 1440 dpi, Excel: 1440 dpi
67 : , maMapModeDest( MAP_INCH, Point(), Fraction( 1, EES_MAP_FRACTION ), Fraction( 1, EES_MAP_FRACTION ) )
68 : , mpPicStrm(NULL)
69 : , mpHostAppData(NULL)
70 : , mnPagesWritten(0)
71 : , mnShapeMasterTitle(0)
72 : , mnShapeMasterBody(0)
73 : , mnIndices(0)
74 : , mnOutlinerCount(0)
75 : , mnPrevTextStyle(0)
76 : , mnStatMaxValue(0)
77 : , mnEffectCount(0)
78 : , mbIsTitlePossible(false)
79 : , mbStatusIndicator(false)
80 0 : , mbStatus(false)
81 : {
82 0 : }
83 :
84 0 : Point ImplEESdrWriter::ImplMapPoint( const Point& rPoint )
85 : {
86 0 : return OutputDevice::LogicToLogic( rPoint, maMapModeSrc, maMapModeDest );
87 : }
88 :
89 0 : Size ImplEESdrWriter::ImplMapSize( const Size& rSize )
90 : {
91 0 : Size aRetSize( OutputDevice::LogicToLogic( rSize, maMapModeSrc, maMapModeDest ) );
92 :
93 0 : if ( !aRetSize.Width() )
94 0 : aRetSize.Width()++;
95 0 : if ( !aRetSize.Height() )
96 0 : aRetSize.Height()++;
97 0 : return aRetSize;
98 : }
99 :
100 0 : void ImplEESdrWriter::ImplFlipBoundingBox( ImplEESdrObject& rObj, EscherPropertyContainer& rPropOpt )
101 : {
102 0 : sal_Int32 nAngle = rObj.GetAngle();
103 0 : Rectangle aRect( rObj.GetRect() );
104 :
105 : // for position calculations, we normalize the angle between 0 and 90 degrees
106 0 : if ( nAngle < 0 )
107 0 : nAngle = ( 36000 + nAngle ) % 36000;
108 0 : if ( nAngle % 18000 == 0 )
109 0 : nAngle = 0;
110 0 : while ( nAngle > 9000 )
111 0 : nAngle = ( 18000 - ( nAngle % 18000 ) );
112 :
113 0 : double fVal = (double)nAngle * F_PI18000;
114 0 : double fCos = cos( fVal );
115 0 : double fSin = sin( fVal );
116 :
117 0 : double nWidthHalf = (double) aRect.GetWidth() / 2;
118 0 : double nHeightHalf = (double) aRect.GetHeight() / 2;
119 :
120 : // fdo#70838:
121 : // when you rotate an object, the top-left corner of its bounding box is moved
122 : // nXDiff and nYDiff pixels. To get their values we use these equations:
123 : //
124 : // fSin * nHeightHalf + fCos * nWidthHalf == nXDiff + nWidthHalf
125 : // fSin * nWidthHalf + fCos * nHeightHalf == nYDiff + nHeightHalf
126 :
127 0 : double nXDiff = fSin * nHeightHalf + fCos * nWidthHalf - nWidthHalf;
128 0 : double nYDiff = fSin * nWidthHalf + fCos * nHeightHalf - nHeightHalf;
129 :
130 0 : aRect.Move( (sal_Int32) nXDiff, (sal_Int32) nYDiff );
131 :
132 : // calculate the proper angle value to be saved
133 0 : nAngle = rObj.GetAngle();
134 0 : if ( nAngle < 0 )
135 0 : nAngle = ( 36000 + nAngle ) % 36000;
136 : else
137 0 : nAngle = ( 36000 - ( nAngle % 36000 ) );
138 :
139 0 : nAngle *= 655;
140 0 : nAngle += 0x8000;
141 0 : nAngle &=~0xffff; // nAngle round to full degrees
142 0 : rPropOpt.AddOpt( ESCHER_Prop_Rotation, nAngle );
143 :
144 0 : rObj.SetAngle( nAngle );
145 0 : rObj.SetRect( aRect );
146 0 : }
147 :
148 :
149 :
150 : #define ADD_SHAPE( nType, nFlags ) \
151 : { \
152 : nShapeType = nType; \
153 : nShapeID = mpEscherEx->GenerateShapeId(); \
154 : rObj.SetShapeId( nShapeID ); \
155 : mpEscherEx->AddShape( (sal_uInt32)nType, (sal_uInt32)nFlags, nShapeID ); \
156 : rSolverContainer.AddShape( rObj.GetShapeRef(), nShapeID ); \
157 : }
158 :
159 : #define SHAPE_TEXT( bFill ) \
160 : { \
161 : mpEscherEx->OpenContainer( ESCHER_SpContainer ); \
162 : ADD_SHAPE( ESCHER_ShpInst_TextBox, 0xa00 ); \
163 : if ( bFill ) \
164 : aPropOpt.CreateFillProperties( rObj.mXPropSet, true ); \
165 : if( rObj.ImplGetText() ) \
166 : aPropOpt.CreateTextProperties( rObj.mXPropSet, \
167 : mpEscherEx->QueryTextID( rObj.GetShapeRef(), \
168 : rObj.GetShapeId() ) ); \
169 : }
170 :
171 : //Map from twips to export units, generally twips as well, only excel and word
172 : //export is happening here, so native units are export units, leave as
173 : //placeholder if required in future
174 0 : void ImplEESdrWriter::MapRect(ImplEESdrObject& /* rObj */ )
175 : {
176 0 : }
177 :
178 0 : sal_uInt32 ImplEESdrWriter::ImplWriteShape( ImplEESdrObject& rObj,
179 : EscherSolverContainer& rSolverContainer,
180 : ImplEESdrPageType ePageType, const sal_Bool bOOxmlExport )
181 : {
182 0 : sal_uInt32 nShapeID = 0;
183 0 : sal_uInt16 nShapeType = 0;
184 0 : sal_Bool bDontWriteText = sal_False; // if a metafile is written as shape replacement, then the text is already part of the metafile
185 0 : sal_Bool bAdditionalText = sal_False;
186 0 : sal_uInt32 nGrpShapeID = 0;
187 :
188 : do {
189 0 : mpHostAppData = mpEscherEx->StartShape( rObj.GetShapeRef(), (mpEscherEx->GetGroupLevel() > 1) ? &rObj.GetRect() : 0 );
190 0 : if ( mpHostAppData && mpHostAppData->DontWriteShape() )
191 0 : break;
192 :
193 : // #i51348# get shape name
194 0 : OUString aShapeName;
195 0 : if( const SdrObject* pSdrObj = rObj.GetSdrObject() )
196 0 : if (!pSdrObj->GetName().isEmpty())
197 0 : aShapeName = pSdrObj->GetName();
198 0 : uno::Reference< drawing::XShape> mXShape(rObj.GetShapeRef(), uno::UNO_QUERY);
199 0 : if (mXShape.is())
200 : {
201 0 : uno::Reference<beans::XPropertySet> xPropertySet(mXShape, uno::UNO_QUERY);
202 0 : if (xPropertySet.is())
203 : {
204 0 : uno::Sequence<beans::PropertyValue> aGrabBag;
205 0 : uno::Reference< XPropertySetInfo > xPropInfo = xPropertySet->getPropertySetInfo();
206 0 : if ( xPropInfo.is() && xPropInfo->hasPropertyByName( "InteropGrabBag" ) )
207 : {
208 0 : xPropertySet->getPropertyValue( "InteropGrabBag" ) >>= aGrabBag;
209 0 : for (int i=0; i< aGrabBag.getLength(); i++)
210 : {
211 0 : if (aGrabBag[i].Name == "mso-edit-as")
212 : {
213 0 : OUString rEditAs;
214 0 : aGrabBag[i].Value >>= rEditAs;
215 0 : mpEscherEx->SetEditAs(rEditAs);
216 0 : break;
217 : }
218 : }
219 0 : }
220 0 : }
221 : }
222 :
223 0 : Point aTextRefPoint;
224 :
225 0 : if( rObj.GetType() == "drawing.Group" )
226 : {
227 0 : Reference< XIndexAccess > xXIndexAccess( rObj.GetShapeRef(), UNO_QUERY );
228 :
229 0 : if( xXIndexAccess.is() && 0 != xXIndexAccess->getCount() )
230 : {
231 0 : nShapeID = mpEscherEx->EnterGroup( aShapeName, &rObj.GetRect() );
232 0 : nShapeType = ESCHER_ShpInst_Min;
233 :
234 0 : for( sal_uInt32 n = 0, nCnt = xXIndexAccess->getCount();
235 : n < nCnt; ++n )
236 : {
237 : ImplEESdrObject aObj( *this, *(Reference< XShape >*)
238 0 : xXIndexAccess->getByIndex( n ).getValue() );
239 0 : if( aObj.IsValid() )
240 : {
241 0 : aObj.SetOOXML(bOOxmlExport);
242 0 : ImplWriteShape( aObj, rSolverContainer, ePageType, bOOxmlExport );
243 : }
244 0 : }
245 0 : mpEscherEx->LeaveGroup();
246 : }
247 0 : break;
248 : }
249 0 : rObj.SetAngle( rObj.ImplGetInt32PropertyValue( OUString( "RotateAngle" ) ));
250 :
251 0 : if( ( rObj.ImplGetPropertyValue( OUString( "IsFontwork" ) ) &&
252 0 : ::cppu::any2bool( rObj.GetUsrAny() ) ) ||
253 0 : rObj.GetType() == "drawing.Measure" )
254 : {
255 0 : rObj.SetType("drawing.dontknow");
256 : }
257 :
258 0 : const ::com::sun::star::awt::Size aSize100thmm( rObj.GetShapeRef()->getSize() );
259 0 : const ::com::sun::star::awt::Point aPoint100thmm( rObj.GetShapeRef()->getPosition() );
260 0 : Rectangle aRect100thmm( Point( aPoint100thmm.X, aPoint100thmm.Y ), Size( aSize100thmm.Width, aSize100thmm.Height ) );
261 0 : if ( !mpPicStrm )
262 0 : mpPicStrm = mpEscherEx->QueryPictureStream();
263 0 : EscherPropertyContainer aPropOpt( mpEscherEx->GetGraphicProvider(), mpPicStrm, aRect100thmm );
264 :
265 : // #i51348# shape name
266 0 : if (!aShapeName.isEmpty())
267 0 : aPropOpt.AddOpt( ESCHER_Prop_wzName, aShapeName );
268 0 : if ( InteractionInfo* pInteraction = mpHostAppData ? mpHostAppData->GetInteractionInfo():NULL )
269 : {
270 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
271 0 : const std::auto_ptr< SvMemoryStream >& pMemStrm = pInteraction->getHyperlinkRecord();
272 : SAL_WNODEPRECATED_DECLARATIONS_POP
273 0 : if ( pMemStrm.get() )
274 : {
275 0 : pMemStrm->ObjectOwnsMemory( false );
276 0 : sal_uInt8* pBuf = (sal_uInt8*) pMemStrm->GetData();
277 0 : sal_uInt32 nSize = pMemStrm->Seek( STREAM_SEEK_TO_END );
278 0 : aPropOpt.AddOpt( ESCHER_Prop_pihlShape, false, nSize, pBuf, nSize );
279 : }
280 0 : if ( pInteraction->hasInteraction() )
281 0 : aPropOpt.AddOpt( ESCHER_Prop_fPrint, 0x00080008 );
282 : }
283 :
284 0 : if ( rObj.GetType() == "drawing.Custom" )
285 : {
286 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
287 : sal_uInt32 nMirrorFlags;
288 :
289 0 : OUString sCustomShapeType;
290 0 : MSO_SPT eShapeType = aPropOpt.GetCustomShapeType( rObj.GetShapeRef(), nMirrorFlags, sCustomShapeType, rObj.GetOOXML() );
291 0 : if ( sCustomShapeType == "col-502ad400" || sCustomShapeType == "col-60da8460" )
292 : {
293 0 : ADD_SHAPE( ESCHER_ShpInst_PictureFrame, 0xa00 );
294 0 : if ( aPropOpt.CreateGraphicProperties( rObj.mXPropSet, "MetaFile", false ) )
295 : {
296 0 : aPropOpt.AddOpt( ESCHER_Prop_LockAgainstGrouping, 0x800080 );
297 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x100000 ); // no fill
298 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x90000 ); // no linestyle
299 0 : SdrObject* pObj = GetSdrObjectFromXShape( rObj.GetShapeRef() );
300 0 : if ( pObj )
301 : {
302 0 : Rectangle aBound = pObj->GetCurrentBoundRect();
303 0 : Point aPosition( ImplMapPoint( aBound.TopLeft() ) );
304 0 : Size aSize( ImplMapSize( aBound.GetSize() ) );
305 0 : rObj.SetRect( Rectangle( aPosition, aSize ) );
306 0 : rObj.SetAngle( 0 );
307 0 : bDontWriteText = sal_True;
308 : }
309 : }
310 : }
311 : else
312 : {
313 0 : ADD_SHAPE(
314 : sal::static_int_cast< sal_uInt16 >(eShapeType),
315 : nMirrorFlags | 0xa00 );
316 0 : aPropOpt.CreateCustomShapeProperties( eShapeType, rObj.GetShapeRef() );
317 0 : aPropOpt.CreateFillProperties( rObj.mXPropSet, true );
318 0 : if ( rObj.ImplGetText() )
319 : {
320 0 : if ( !aPropOpt.IsFontWork() )
321 : aPropOpt.CreateTextProperties( rObj.mXPropSet, mpEscherEx->QueryTextID(
322 0 : rObj.GetShapeRef(), rObj.GetShapeId() ), true, false );
323 : }
324 0 : }
325 : }
326 0 : else if ( rObj.GetType() == "drawing.Rectangle" )
327 : {
328 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
329 : sal_Int32 nRadius = (sal_Int32)rObj.ImplGetInt32PropertyValue(
330 0 : OUString( "CornerRadius" ));
331 0 : if( nRadius )
332 : {
333 0 : nRadius = ImplMapSize( Size( nRadius, 0 )).Width();
334 0 : ADD_SHAPE( ESCHER_ShpInst_RoundRectangle, 0xa00 ); // Flags: Connector | HasSpt
335 0 : sal_Int32 nLength = rObj.GetRect().GetWidth();
336 0 : if ( nLength > rObj.GetRect().GetHeight() )
337 0 : nLength = rObj.GetRect().GetHeight();
338 0 : nLength >>= 1;
339 0 : if ( nRadius >= nLength || nLength == 0 )
340 0 : nRadius = 0x2a30; // 0x2a30 is PPTs maximum radius
341 : else
342 0 : nRadius = ( 0x2a30 * nRadius ) / nLength;
343 0 : aPropOpt.AddOpt( ESCHER_Prop_adjustValue, nRadius );
344 : }
345 : else
346 : {
347 0 : ADD_SHAPE( ESCHER_ShpInst_Rectangle, 0xa00 ); // Flags: Connector | HasSpt
348 : }
349 0 : aPropOpt.CreateFillProperties( rObj.mXPropSet, true );
350 0 : if( rObj.ImplGetText() )
351 : aPropOpt.CreateTextProperties( rObj.mXPropSet,
352 0 : mpEscherEx->QueryTextID( rObj.GetShapeRef(),
353 0 : rObj.GetShapeId() ), false, false );
354 : }
355 0 : else if ( rObj.GetType() == "drawing.Ellipse" )
356 : {
357 0 : CircleKind eCircleKind = CircleKind_FULL;
358 0 : PolyStyle ePolyKind = PolyStyle();
359 0 : if ( rObj.ImplGetPropertyValue( OUString( "CircleKind" ) ) )
360 : {
361 0 : eCircleKind = *( (CircleKind*)rObj.GetUsrAny().getValue() );
362 0 : switch ( eCircleKind )
363 : {
364 : case CircleKind_SECTION :
365 : {
366 0 : ePolyKind = POLY_PIE;
367 : }
368 0 : break;
369 : case CircleKind_ARC :
370 : {
371 0 : ePolyKind = POLY_ARC;
372 : }
373 0 : break;
374 :
375 : case CircleKind_CUT :
376 : {
377 0 : ePolyKind = POLY_CHORD;
378 : }
379 0 : break;
380 :
381 : default:
382 0 : eCircleKind = CircleKind_FULL;
383 : }
384 : }
385 0 : if ( eCircleKind == CircleKind_FULL )
386 : {
387 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
388 0 : ADD_SHAPE( ESCHER_ShpInst_Ellipse, 0xa00 ); // Flags: Connector | HasSpt
389 0 : aPropOpt.CreateFillProperties( rObj.mXPropSet, true );
390 : }
391 : else
392 : {
393 : sal_Int32 nStartAngle, nEndAngle;
394 0 : if ( !rObj.ImplGetPropertyValue( OUString( "CircleStartAngle" ) ) )
395 0 : break;
396 0 : nStartAngle = *( (sal_Int32*)rObj.GetUsrAny().getValue() );
397 0 : if( !rObj.ImplGetPropertyValue( OUString( "CircleEndAngle" ) ) )
398 0 : break;
399 0 : nEndAngle = *( (sal_Int32*)rObj.GetUsrAny().getValue() );
400 :
401 0 : Point aStart, aEnd, aCenter;
402 0 : aStart.X() = (sal_Int32)( ( cos( (double)( nStartAngle *
403 0 : F_PI18000 ) ) * 100.0 ) );
404 0 : aStart.Y() = - (sal_Int32)( ( sin( (double)( nStartAngle *
405 0 : F_PI18000 ) ) * 100.0 ) );
406 0 : aEnd.X() = (sal_Int32)( ( cos( (double)( nEndAngle *
407 0 : F_PI18000 ) ) * 100.0 ) );
408 0 : aEnd.Y() = - (sal_Int32)( ( sin( (double)( nEndAngle *
409 0 : F_PI18000 ) ) * 100.0 ) );
410 0 : const Rectangle& rRect = aRect100thmm;
411 0 : aCenter.X() = rRect.Left() + ( rRect.GetWidth() / 2 );
412 0 : aCenter.Y() = rRect.Top() + ( rRect.GetHeight() / 2 );
413 0 : aStart.X() += aCenter.X();
414 0 : aStart.Y() += aCenter.Y();
415 0 : aEnd.X() += aCenter.X();
416 0 : aEnd.Y() += aCenter.Y();
417 0 : Polygon aPolygon( rRect, aStart, aEnd, ePolyKind );
418 0 : if( rObj.GetAngle() )
419 : {
420 0 : aPolygon.Rotate( rRect.TopLeft(), (sal_uInt16)( rObj.GetAngle() / 10 ) );
421 0 : rObj.SetAngle( 0 );
422 : }
423 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
424 0 : ADD_SHAPE( ESCHER_ShpInst_NotPrimitive, 0xa00 ); // Flags: Connector | HasSpt
425 0 : ::com::sun::star::awt::Rectangle aNewRect;
426 0 : switch ( ePolyKind )
427 : {
428 : case POLY_PIE :
429 : case POLY_CHORD :
430 : {
431 0 : aPropOpt.CreatePolygonProperties( rObj.mXPropSet, ESCHER_CREATEPOLYGON_POLYPOLYGON, false, aNewRect, &aPolygon );
432 0 : aPropOpt.CreateFillProperties( rObj.mXPropSet, true );
433 : }
434 0 : break;
435 :
436 : case POLY_ARC :
437 : {
438 0 : aPropOpt.CreatePolygonProperties( rObj.mXPropSet, ESCHER_CREATEPOLYGON_POLYLINE, false, aNewRect, &aPolygon );
439 0 : aPropOpt.CreateLineProperties( rObj.mXPropSet, false );
440 : }
441 0 : break;
442 : }
443 0 : rObj.SetRect( Rectangle( ImplMapPoint( Point( aNewRect.X, aNewRect.Y ) ),
444 0 : ImplMapSize( Size( aNewRect.Width, aNewRect.Height ) ) ) );
445 : }
446 0 : if ( rObj.ImplGetText() )
447 : aPropOpt.CreateTextProperties( rObj.mXPropSet,
448 0 : mpEscherEx->QueryTextID( rObj.GetShapeRef(),
449 0 : rObj.GetShapeId() ), false, false );
450 :
451 : }
452 0 : else if ( rObj.GetType() == "drawing.Control" )
453 : {
454 0 : break;
455 : }
456 0 : else if ( rObj.GetType() == "drawing.Connector" )
457 : {
458 : sal_uInt16 nSpType, nSpFlags;
459 0 : ::com::sun::star::awt::Rectangle aNewRect;
460 0 : if ( ! aPropOpt.CreateConnectorProperties( rObj.GetShapeRef(),
461 0 : rSolverContainer, aNewRect, nSpType, nSpFlags ) )
462 0 : break;
463 0 : rObj.SetRect( Rectangle( ImplMapPoint( Point( aNewRect.X, aNewRect.Y ) ),
464 0 : ImplMapSize( Size( aNewRect.Width, aNewRect.Height ) ) ) );
465 :
466 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
467 0 : ADD_SHAPE( nSpType, nSpFlags );
468 : }
469 0 : else if ( rObj.GetType() == "drawing.Measure" )
470 : {
471 0 : break;
472 : }
473 0 : else if ( rObj.GetType() == "drawing.Line" )
474 : {
475 0 : ::com::sun::star::awt::Rectangle aNewRect;
476 0 : aPropOpt.CreatePolygonProperties( rObj.mXPropSet, ESCHER_CREATEPOLYGON_LINE, false, aNewRect, NULL );
477 0 : MapRect(rObj);
478 : //i27942: Poly/Lines/Bezier do not support text.
479 :
480 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
481 0 : sal_uInt32 nFlags = 0xa00; // Flags: Connector | HasSpt
482 0 : if( aNewRect.Height < 0 )
483 0 : nFlags |= 0x80; // Flags: VertMirror
484 0 : if( aNewRect.Width < 0 )
485 0 : nFlags |= 0x40; // Flags: HorzMirror
486 :
487 0 : ADD_SHAPE( ESCHER_ShpInst_Line, nFlags );
488 0 : aPropOpt.AddOpt( ESCHER_Prop_shapePath, ESCHER_ShapeComplex );
489 0 : aPropOpt.CreateLineProperties( rObj.mXPropSet, false );
490 0 : rObj.SetAngle( 0 );
491 : }
492 0 : else if ( rObj.GetType() == "drawing.PolyPolygon" )
493 : {
494 0 : if( rObj.ImplHasText() )
495 : {
496 0 : nGrpShapeID = ImplEnterAdditionalTextGroup( rObj.GetShapeRef(), &rObj.GetRect() );
497 0 : bAdditionalText = sal_True;
498 : }
499 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
500 0 : ADD_SHAPE( ESCHER_ShpInst_NotPrimitive, 0xa00 ); // Flags: Connector | HasSpt
501 0 : ::com::sun::star::awt::Rectangle aNewRect;
502 0 : aPropOpt.CreatePolygonProperties( rObj.mXPropSet, ESCHER_CREATEPOLYGON_POLYPOLYGON, false, aNewRect, NULL );
503 0 : MapRect(rObj);
504 0 : aPropOpt.CreateFillProperties( rObj.mXPropSet, true );
505 0 : rObj.SetAngle( 0 );
506 : }
507 0 : else if ( rObj.GetType() == "drawing.PolyLine" )
508 : {
509 : //i27942: Poly/Lines/Bezier do not support text.
510 :
511 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
512 0 : ADD_SHAPE( ESCHER_ShpInst_NotPrimitive, 0xa00 ); // Flags: Connector | HasSpt
513 0 : ::com::sun::star::awt::Rectangle aNewRect;
514 0 : aPropOpt.CreatePolygonProperties( rObj.mXPropSet, ESCHER_CREATEPOLYGON_POLYLINE, false, aNewRect, NULL );
515 0 : MapRect(rObj);
516 0 : aPropOpt.CreateLineProperties( rObj.mXPropSet, false );
517 0 : rObj.SetAngle( 0 );
518 : }
519 0 : else if ( rObj.GetType() == "drawing.OpenBezier" )
520 : {
521 : //i27942: Poly/Lines/Bezier do not support text.
522 :
523 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
524 0 : ADD_SHAPE( ESCHER_ShpInst_NotPrimitive, 0xa00 ); // Flags: Connector | HasSpt
525 0 : ::com::sun::star::awt::Rectangle aNewRect;
526 0 : aPropOpt.CreatePolygonProperties( rObj.mXPropSet, ESCHER_CREATEPOLYGON_POLYLINE, true, aNewRect, NULL );
527 0 : MapRect(rObj);
528 0 : aPropOpt.CreateLineProperties( rObj.mXPropSet, false );
529 0 : rObj.SetAngle( 0 );
530 : }
531 0 : else if ( rObj.GetType() == "drawing.ClosedBezier" )
532 : {
533 0 : if ( rObj.ImplHasText() )
534 : {
535 0 : nGrpShapeID = ImplEnterAdditionalTextGroup( rObj.GetShapeRef(), &rObj.GetRect() );
536 0 : bAdditionalText = sal_True;
537 : }
538 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
539 0 : ADD_SHAPE( ESCHER_ShpInst_NotPrimitive, 0xa00 ); // Flags: Connector | HasSpt
540 0 : ::com::sun::star::awt::Rectangle aNewRect;
541 0 : aPropOpt.CreatePolygonProperties( rObj.mXPropSet, ESCHER_CREATEPOLYGON_POLYPOLYGON, true, aNewRect, NULL );
542 0 : MapRect(rObj);
543 0 : aPropOpt.CreateFillProperties( rObj.mXPropSet, true );
544 0 : rObj.SetAngle( 0 );
545 : }
546 0 : else if ( rObj.GetType() == "drawing.GraphicObject" )
547 : {
548 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
549 :
550 : // a GraphicObject can also be a ClickMe element
551 0 : if( rObj.IsEmptyPresObj() && ( ePageType == NORMAL ) )
552 : {
553 0 : ADD_SHAPE( ESCHER_ShpInst_Rectangle, 0x220 ); // Flags: HaveAnchor | HaveMaster
554 0 : sal_uInt32 nTxtBxId = mpEscherEx->QueryTextID( rObj.GetShapeRef(),
555 0 : rObj.GetShapeId() );
556 0 : aPropOpt.AddOpt( ESCHER_Prop_lTxid, nTxtBxId );
557 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x10001 );
558 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x10001 );
559 0 : aPropOpt.AddOpt( ESCHER_Prop_hspMaster, mnShapeMasterBody );
560 : }
561 : else
562 : {
563 0 : if( rObj.ImplGetText() )
564 : {
565 : /* SJ #i34951#: because M. documents are not allowing GraphicObjects containing text, we
566 : have to create a simpe Rectangle with fill bitmap instead (while not allowing BitmapMode_Repeat).
567 : */
568 0 : ADD_SHAPE( ESCHER_ShpInst_Rectangle, 0xa00 ); // Flags: Connector | HasSpt
569 0 : if ( aPropOpt.CreateGraphicProperties( rObj.mXPropSet, "GraphicURL", true, true, false ) )
570 : {
571 0 : aPropOpt.AddOpt( ESCHER_Prop_WrapText, ESCHER_WrapNone );
572 0 : aPropOpt.AddOpt( ESCHER_Prop_AnchorText, ESCHER_AnchorMiddle );
573 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x140014 );
574 0 : aPropOpt.AddOpt( ESCHER_Prop_fillBackColor, 0x8000000 );
575 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x80000 );
576 0 : if ( rObj.ImplGetText() )
577 : aPropOpt.CreateTextProperties( rObj.mXPropSet,
578 0 : mpEscherEx->QueryTextID( rObj.GetShapeRef(),
579 0 : rObj.GetShapeId() ), false, false );
580 : }
581 : }
582 : else
583 : {
584 0 : ADD_SHAPE( ESCHER_ShpInst_PictureFrame, 0xa00 );
585 0 : if ( aPropOpt.CreateGraphicProperties( rObj.mXPropSet, "GraphicURL", false, true, true, bOOxmlExport ) )
586 0 : aPropOpt.AddOpt( ESCHER_Prop_LockAgainstGrouping, 0x800080 );
587 : }
588 : }
589 : }
590 0 : else if ( rObj.GetType() == "drawing.Text" )
591 : {
592 0 : SHAPE_TEXT( true );
593 : }
594 0 : else if ( rObj.GetType() == "drawing.Page" )
595 : {
596 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
597 0 : ADD_SHAPE( ESCHER_ShpInst_Rectangle, 0xa00 );
598 0 : aPropOpt.AddOpt( ESCHER_Prop_LockAgainstGrouping, 0x40004 );
599 0 : aPropOpt.AddOpt( ESCHER_Prop_fFillOK, 0x100001 );
600 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x110011 );
601 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x90008 );
602 0 : aPropOpt.AddOpt( ESCHER_Prop_fshadowObscured, 0x10001 );
603 : }
604 0 : else if ( rObj.GetType() == "drawing.Frame" )
605 : {
606 0 : break;
607 : }
608 0 : else if ( rObj.GetType() == "drawing.OLE2" )
609 : {
610 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
611 0 : if( rObj.IsEmptyPresObj() && ( ePageType == NORMAL ) )
612 : {
613 0 : ADD_SHAPE( ESCHER_ShpInst_Rectangle, 0x220 ); // Flags: HaveAnchor | HaveMaster
614 0 : sal_uInt32 nTxtBxId = mpEscherEx->QueryTextID( rObj.GetShapeRef(),
615 0 : rObj.GetShapeId() );
616 0 : aPropOpt.AddOpt( ESCHER_Prop_lTxid, nTxtBxId );
617 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x10001 );
618 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x10001 );
619 0 : aPropOpt.AddOpt( ESCHER_Prop_hspMaster, mnShapeMasterBody );
620 : }
621 : else
622 : {
623 : //2do: could be made an option in HostAppData whether OLE object should be written or not
624 0 : sal_Bool bAppOLE = sal_True;
625 0 : ADD_SHAPE( ESCHER_ShpInst_PictureFrame,
626 : 0xa00 | (bAppOLE ? SHAPEFLAG_OLESHAPE : 0) );
627 0 : if ( aPropOpt.CreateOLEGraphicProperties( rObj.GetShapeRef() ) )
628 : {
629 0 : if ( bAppOLE )
630 : { // snooped from Xcl hex dump, nobody knows the trouble I have seen
631 0 : aPropOpt.AddOpt( ESCHER_Prop_FitTextToShape, 0x00080008 );
632 0 : aPropOpt.AddOpt( ESCHER_Prop_pictureId, 0x00000001 );
633 0 : aPropOpt.AddOpt( ESCHER_Prop_fillColor, 0x08000041 );
634 0 : aPropOpt.AddOpt( ESCHER_Prop_fillBackColor, 0x08000041 );
635 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x00110010 );
636 0 : aPropOpt.AddOpt( ESCHER_Prop_lineColor, 0x08000040 );
637 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash,0x00080008 );
638 0 : aPropOpt.AddOpt( ESCHER_Prop_fPrint, 0x00080000 );
639 : }
640 0 : aPropOpt.AddOpt( ESCHER_Prop_LockAgainstGrouping, 0x800080 );
641 : }
642 : }
643 : }
644 0 : else if( '3' == rObj.GetType()[8] &&
645 0 : 'D' == rObj.GetType()[9] ) // drawing.3D
646 : {
647 : // SceneObject, CubeObject, SphereObject, LatheObject, ExtrudeObject, PolygonObject
648 0 : if ( !rObj.ImplGetPropertyValue( OUString( "Bitmap" ) ) )
649 0 : break;
650 :
651 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
652 0 : ADD_SHAPE( ESCHER_ShpInst_PictureFrame, 0xa00 );
653 :
654 0 : if ( aPropOpt.CreateGraphicProperties( rObj.mXPropSet, "Bitmap", false ) )
655 0 : aPropOpt.AddOpt( ESCHER_Prop_LockAgainstGrouping, 0x800080 );
656 : }
657 0 : else if ( rObj.GetType() == "drawing.Caption" )
658 : {
659 0 : rObj.SetAngle( 0 );
660 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
661 0 : ADD_SHAPE( ESCHER_ShpInst_TextBox, 0xa00 );
662 0 : if ( aPropOpt.CreateGraphicProperties( rObj.mXPropSet, "MetaFile", false ) )
663 0 : aPropOpt.AddOpt( ESCHER_Prop_LockAgainstGrouping, 0x800080 );
664 : }
665 0 : else if ( rObj.GetType() == "drawing.dontknow" )
666 : {
667 0 : rObj.SetAngle( 0 );
668 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
669 0 : ADD_SHAPE( ESCHER_ShpInst_PictureFrame, 0xa00 );
670 0 : if ( aPropOpt.CreateGraphicProperties( rObj.mXPropSet, "MetaFile", false ) )
671 0 : aPropOpt.AddOpt( ESCHER_Prop_LockAgainstGrouping, 0x800080 );
672 : }
673 : else
674 : {
675 0 : break;
676 : }
677 0 : aPropOpt.CreateShadowProperties( rObj.mXPropSet );
678 :
679 0 : if( USHRT_MAX != mpEscherEx->GetHellLayerId() &&
680 0 : rObj.ImplGetPropertyValue( OUString( "LayerID" ) ) &&
681 0 : (*((sal_uInt16*)rObj.GetUsrAny().getValue()) ) == mpEscherEx->GetHellLayerId() )
682 : {
683 0 : aPropOpt.AddOpt( ESCHER_Prop_fPrint, 0x200020 );
684 : }
685 :
686 : {
687 0 : Rectangle aRect( rObj.GetRect() );
688 0 : aRect.Justify();
689 0 : rObj.SetRect( aRect );
690 : }
691 :
692 0 : if( rObj.GetAngle() )
693 0 : ImplFlipBoundingBox( rObj, aPropOpt );
694 :
695 0 : aPropOpt.CreateShapeProperties( rObj.GetShapeRef() );
696 0 : const SdrObject* sdrObj = rObj.GetSdrObject();
697 0 : mpEscherEx->AddSdrObjectVMLObject(*sdrObj );
698 0 : mpEscherEx->Commit( aPropOpt, rObj.GetRect());
699 0 : if( mpEscherEx->GetGroupLevel() > 1 )
700 0 : mpEscherEx->AddChildAnchor( rObj.GetRect() );
701 :
702 0 : if ( mpHostAppData )
703 : { //! with AdditionalText the App has to control whether these are written or not
704 0 : mpHostAppData->WriteClientAnchor( *mpEscherEx, rObj.GetRect() );
705 0 : mpHostAppData->WriteClientData( *mpEscherEx );
706 0 : if ( !bDontWriteText )
707 0 : mpHostAppData->WriteClientTextbox( *mpEscherEx );
708 : }
709 0 : mpEscherEx->CloseContainer(); // ESCHER_SpContainer
710 :
711 0 : if( bAdditionalText )
712 : {
713 0 : mpEscherEx->EndShape( nShapeType, nShapeID );
714 0 : ImplWriteAdditionalText( rObj, aTextRefPoint );
715 0 : }
716 :
717 : } while ( false );
718 :
719 0 : if ( bAdditionalText )
720 0 : mpEscherEx->EndShape( ESCHER_ShpInst_Min, nGrpShapeID );
721 : else
722 0 : mpEscherEx->EndShape( nShapeType, nShapeID );
723 0 : return nShapeID;
724 : }
725 :
726 0 : void ImplEESdrWriter::ImplWriteAdditionalText( ImplEESdrObject& rObj,
727 : const Point& rTextRefPoint )
728 : {
729 0 : sal_uInt32 nShapeID = 0;
730 0 : sal_uInt16 nShapeType = 0;
731 : do
732 : {
733 0 : mpHostAppData = mpEscherEx->StartShape( rObj.GetShapeRef(), (mpEscherEx->GetGroupLevel() > 1) ? &rObj.GetRect() : 0 );
734 0 : if ( mpHostAppData && mpHostAppData->DontWriteShape() )
735 0 : break;
736 :
737 0 : const ::com::sun::star::awt::Size aSize100thmm( rObj.GetShapeRef()->getSize() );
738 0 : const ::com::sun::star::awt::Point aPoint100thmm( rObj.GetShapeRef()->getPosition() );
739 0 : Rectangle aRect100thmm( Point( aPoint100thmm.X, aPoint100thmm.Y ), Size( aSize100thmm.Width, aSize100thmm.Height ) );
740 0 : if ( !mpPicStrm )
741 0 : mpPicStrm = mpEscherEx->QueryPictureStream();
742 0 : EscherPropertyContainer aPropOpt( mpEscherEx->GetGraphicProvider(), mpPicStrm, aRect100thmm );
743 0 : rObj.SetAngle( rObj.ImplGetInt32PropertyValue( OUString( "RotateAngle" )));
744 0 : sal_Int32 nAngle = rObj.GetAngle();
745 0 : if( rObj.GetType() == "drawing.Line" )
746 : {
747 : //2do: this does not work right
748 0 : double fDist = hypot( rObj.GetRect().GetWidth(),
749 0 : rObj.GetRect().GetHeight() );
750 : rObj.SetRect( Rectangle( rTextRefPoint,
751 0 : Point( (sal_Int32)( rTextRefPoint.X() + fDist ), rTextRefPoint.Y() - 1 ) ) );
752 :
753 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
754 0 : mpEscherEx->AddShape( ESCHER_ShpInst_TextBox, 0xa00 );
755 0 : if ( rObj.ImplGetText() )
756 : aPropOpt.CreateTextProperties( rObj.mXPropSet,
757 0 : mpEscherEx->QueryTextID( rObj.GetShapeRef(),
758 0 : rObj.GetShapeId() ) );
759 :
760 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x90000 );
761 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x100000 );
762 0 : aPropOpt.AddOpt( ESCHER_Prop_FitTextToShape, 0x60006 ); // Size Shape To Fit Text
763 0 : if ( nAngle < 0 )
764 0 : nAngle = ( 36000 + nAngle ) % 36000;
765 0 : if ( nAngle )
766 0 : ImplFlipBoundingBox( rObj, aPropOpt );
767 : }
768 : else
769 : {
770 0 : mpEscherEx->OpenContainer( ESCHER_SpContainer );
771 0 : nShapeID = mpEscherEx->GenerateShapeId();
772 0 : mpEscherEx->AddShape( nShapeType = ESCHER_ShpInst_TextBox, 0xa00, nShapeID );
773 0 : if ( rObj.ImplGetText() )
774 : aPropOpt.CreateTextProperties( rObj.mXPropSet,
775 0 : mpEscherEx->QueryTextID( rObj.GetShapeRef(),
776 0 : rObj.GetShapeId() ) );
777 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x90000 );
778 0 : aPropOpt.AddOpt( ESCHER_Prop_fNoFillHitTest, 0x100000 );
779 :
780 0 : if( nAngle < 0 )
781 0 : nAngle = ( 36000 + nAngle ) % 36000;
782 : else
783 0 : nAngle = ( 36000 - ( nAngle % 36000 ) );
784 :
785 0 : nAngle *= 655;
786 0 : nAngle += 0x8000;
787 0 : nAngle &=~0xffff; // nAngle round to full degrees
788 0 : aPropOpt.AddOpt( ESCHER_Prop_Rotation, nAngle );
789 : mpEscherEx->SetGroupSnapRect( mpEscherEx->GetGroupLevel(),
790 0 : rObj.GetRect() );
791 : mpEscherEx->SetGroupLogicRect( mpEscherEx->GetGroupLevel(),
792 0 : rObj.GetRect() );
793 : }
794 0 : rObj.SetAngle( nAngle );
795 0 : aPropOpt.CreateShapeProperties( rObj.GetShapeRef() );
796 0 : const SdrObject* sdrObj = rObj.GetSdrObject();
797 0 : mpEscherEx->AddSdrObjectVMLObject(*sdrObj );
798 0 : mpEscherEx->Commit( aPropOpt, rObj.GetRect());
799 :
800 : // write the childanchor
801 0 : mpEscherEx->AddChildAnchor( rObj.GetRect() );
802 :
803 : #if defined EES_WRITE_EPP
804 : // ClientAnchor
805 : mpEscherEx->AddClientAnchor( maRect );
806 : // ClientTextbox
807 : mpEscherEx->OpenContainer( ESCHER_ClientTextbox );
808 : mpEscherEx->AddAtom( 4, EPP_TextHeaderAtom );
809 : *mpStrm << (sal_uInt32)EPP_TEXTTYPE_Other; // Text in a Shape
810 : ImplWriteTextStyleAtom();
811 : mpEscherEx->CloseContainer(); // ESCHER_ClientTextBox
812 : #else // !EES_WRITE_EPP
813 0 : if ( mpHostAppData )
814 : { //! the App has to control whether these are written or not
815 0 : mpHostAppData->WriteClientAnchor( *mpEscherEx, rObj.GetRect() );
816 0 : mpHostAppData->WriteClientData( *mpEscherEx );
817 0 : mpHostAppData->WriteClientTextbox( *mpEscherEx );
818 : }
819 : #endif // EES_WRITE_EPP
820 0 : mpEscherEx->CloseContainer(); // ESCHER_SpContainer
821 : } while ( false );
822 0 : mpEscherEx->LeaveGroup();
823 0 : mpEscherEx->EndShape( nShapeType, nShapeID );
824 0 : }
825 :
826 :
827 0 : sal_uInt32 ImplEESdrWriter::ImplEnterAdditionalTextGroup( const Reference< XShape >& rShape,
828 : const Rectangle* pBoundRect )
829 : {
830 0 : mpHostAppData = mpEscherEx->EnterAdditionalTextGroup();
831 0 : sal_uInt32 nGrpId = mpEscherEx->EnterGroup( pBoundRect );
832 0 : mpHostAppData = mpEscherEx->StartShape( rShape, pBoundRect );
833 0 : return nGrpId;
834 : }
835 :
836 :
837 0 : sal_Bool ImplEESdrWriter::ImplInitPageValues()
838 : {
839 0 : mnIndices = 0;
840 0 : mnOutlinerCount = 0; // die outline objects must be in accordance with the layout.
841 0 : mnEffectCount = 0;
842 0 : mbIsTitlePossible = sal_True; // With more than one title PowerPoint will fail.
843 :
844 0 : return sal_True;
845 : }
846 :
847 0 : void ImplEESdrWriter::ImplWritePage(
848 : EscherSolverContainer& rSolverContainer,
849 : ImplEESdrPageType ePageType, sal_Bool /* bBackGround */ )
850 : {
851 0 : ImplInitPageValues();
852 :
853 0 : sal_uInt32 nLastPer = 0, nShapes = mXShapes->getCount();
854 0 : for( sal_uInt32 n = 0; n < nShapes; ++n )
855 : {
856 0 : sal_uInt32 nPer = ( 5 * n ) / nShapes;
857 0 : if( nPer != nLastPer )
858 : {
859 0 : nLastPer = nPer;
860 0 : sal_uInt32 nValue = mnPagesWritten * 5 + nPer;
861 0 : if( nValue > mnStatMaxValue )
862 0 : nValue = mnStatMaxValue;
863 0 : if( mbStatusIndicator )
864 0 : mXStatusIndicator->setValue( nValue );
865 : }
866 :
867 : ImplEESdrObject aObj( *this, *(Reference< XShape >*)
868 0 : mXShapes->getByIndex( n ).getValue() );
869 0 : if( aObj.IsValid() )
870 : {
871 0 : ImplWriteShape( aObj, rSolverContainer, ePageType );
872 : }
873 0 : }
874 0 : mnPagesWritten++;
875 0 : }
876 :
877 0 : ImplEscherExSdr::ImplEscherExSdr( EscherEx& rEx )
878 : :
879 : ImplEESdrWriter( rEx ),
880 : mpSdrPage( NULL ),
881 0 : mpSolverContainer( NULL )
882 : {
883 0 : }
884 :
885 :
886 0 : ImplEscherExSdr::~ImplEscherExSdr()
887 : {
888 : DBG_ASSERT( !mpSolverContainer, "ImplEscherExSdr::~ImplEscherExSdr: unwritten SolverContainer" );
889 0 : delete mpSolverContainer;
890 0 : }
891 :
892 :
893 0 : bool ImplEscherExSdr::ImplInitPage( const SdrPage& rPage )
894 : {
895 : do
896 : {
897 : SvxDrawPage* pSvxDrawPage;
898 0 : if ( mpSdrPage != &rPage || !mXDrawPage.is() )
899 : {
900 : // eventually write SolverContainer of current page, deletes the Solver
901 0 : ImplFlushSolverContainer();
902 :
903 0 : mpSdrPage = NULL;
904 0 : mXDrawPage = pSvxDrawPage = new SvxFmDrawPage( (SdrPage*) &rPage );
905 0 : mXShapes = Reference< XShapes >::query( mXDrawPage );
906 0 : if ( !mXShapes.is() )
907 0 : break;
908 0 : if ( !ImplInitPageValues() ) // ImplEESdrWriter
909 0 : break;
910 0 : mpSdrPage = &rPage;
911 :
912 0 : mpSolverContainer = new EscherSolverContainer;
913 : }
914 : else
915 0 : pSvxDrawPage = SvxDrawPage::getImplementation(mXDrawPage);
916 :
917 0 : return pSvxDrawPage != 0;
918 : } while ( false );
919 :
920 0 : return false;
921 : }
922 :
923 0 : bool ImplEscherExSdr::ImplInitUnoShapes( const Reference< XShapes >& rxShapes )
924 : {
925 : // eventually write SolverContainer of current page, deletes the Solver
926 0 : ImplFlushSolverContainer();
927 :
928 0 : if( !rxShapes.is() )
929 0 : return false;
930 :
931 0 : mpSdrPage = 0;
932 0 : mXDrawPage.clear();
933 0 : mXShapes = rxShapes;
934 :
935 0 : if( !ImplInitPageValues() ) // ImplEESdrWriter
936 0 : return false;
937 :
938 0 : mpSolverContainer = new EscherSolverContainer;
939 0 : return true;
940 : }
941 :
942 0 : void ImplEscherExSdr::ImplExitPage()
943 : {
944 : // close all groups before the solver container is written
945 0 : while( mpEscherEx->GetGroupLevel() )
946 0 : mpEscherEx->LeaveGroup();
947 :
948 0 : ImplFlushSolverContainer();
949 0 : mpSdrPage = NULL; // reset page for next init
950 0 : }
951 :
952 :
953 0 : void ImplEscherExSdr::ImplFlushSolverContainer()
954 : {
955 0 : if ( mpSolverContainer )
956 : {
957 0 : mpSolverContainer->WriteSolver( mpEscherEx->GetStream() );
958 0 : delete mpSolverContainer;
959 0 : mpSolverContainer = NULL;
960 : }
961 0 : }
962 :
963 :
964 0 : void ImplEscherExSdr::ImplWriteCurrentPage()
965 : {
966 : DBG_ASSERT( mpSolverContainer, "ImplEscherExSdr::ImplWriteCurrentPage: no SolverContainer" );
967 0 : ImplWritePage( *mpSolverContainer, NORMAL );
968 0 : ImplExitPage();
969 0 : }
970 :
971 :
972 0 : sal_uInt32 ImplEscherExSdr::ImplWriteTheShape( ImplEESdrObject& rObj , bool ooxmlExport )
973 : {
974 : DBG_ASSERT( mpSolverContainer, "ImplEscherExSdr::ImplWriteShape: no SolverContainer" );
975 0 : return ImplWriteShape( rObj, *mpSolverContainer, NORMAL, ooxmlExport );
976 : }
977 :
978 :
979 0 : void EscherEx::AddSdrPage( const SdrPage& rPage )
980 : {
981 0 : if ( mpImplEscherExSdr->ImplInitPage( rPage ) )
982 0 : mpImplEscherExSdr->ImplWriteCurrentPage();
983 0 : }
984 :
985 0 : void EscherEx::AddUnoShapes( const Reference< XShapes >& rxShapes )
986 : {
987 0 : if ( mpImplEscherExSdr->ImplInitUnoShapes( rxShapes ) )
988 0 : mpImplEscherExSdr->ImplWriteCurrentPage();
989 0 : }
990 :
991 0 : sal_uInt32 EscherEx::AddSdrObject( const SdrObject& rObj, bool ooxmlExport )
992 : {
993 0 : ImplEESdrObject aObj( *mpImplEscherExSdr, rObj, mbOOXML );
994 0 : if( aObj.IsValid() )
995 0 : return mpImplEscherExSdr->ImplWriteTheShape( aObj, ooxmlExport );
996 0 : return 0;
997 : }
998 :
999 :
1000 0 : void EscherEx::EndSdrObjectPage()
1001 : {
1002 0 : mpImplEscherExSdr->ImplExitPage();
1003 0 : }
1004 :
1005 0 : EscherExHostAppData* EscherEx::StartShape( const Reference< XShape >& /* rShape */, const Rectangle* /*pChildAnchor*/ )
1006 : {
1007 0 : return NULL;
1008 : }
1009 :
1010 0 : void EscherEx::EndShape( sal_uInt16 /* nShapeType */, sal_uInt32 /* nShapeID */ )
1011 : {
1012 0 : }
1013 :
1014 0 : sal_uInt32 EscherEx::QueryTextID( const Reference< XShape >&, sal_uInt32 )
1015 : {
1016 0 : return 0;
1017 : }
1018 :
1019 : // add an dummy rectangle shape into the escher stream
1020 0 : sal_uInt32 EscherEx::AddDummyShape()
1021 : {
1022 0 : OpenContainer( ESCHER_SpContainer );
1023 0 : sal_uInt32 nShapeID = GenerateShapeId();
1024 0 : AddShape( ESCHER_ShpInst_Rectangle, 0xa00, nShapeID );
1025 0 : CloseContainer();
1026 :
1027 0 : return nShapeID;
1028 : }
1029 :
1030 : // static
1031 0 : const SdrObject* EscherEx::GetSdrObject( const Reference< XShape >& rShape )
1032 : {
1033 0 : const SdrObject* pRet = 0;
1034 0 : const SvxShape* pSvxShape = SvxShape::getImplementation( rShape );
1035 : DBG_ASSERT( pSvxShape, "EscherEx::GetSdrObject: no SvxShape" );
1036 0 : if( pSvxShape )
1037 : {
1038 0 : pRet = pSvxShape->GetSdrObject();
1039 : DBG_ASSERT( pRet, "EscherEx::GetSdrObject: no SdrObj" );
1040 : }
1041 0 : return pRet;
1042 : }
1043 :
1044 :
1045 0 : ImplEESdrObject::ImplEESdrObject( ImplEscherExSdr& rEx,
1046 : const SdrObject& rObj, bool bOOXML ) :
1047 : mnShapeId( 0 ),
1048 : mnTextSize( 0 ),
1049 : mnAngle( 0 ),
1050 : mbValid( sal_False ),
1051 : mbPresObj( sal_False ),
1052 : mbEmptyPresObj( sal_False ),
1053 0 : mbOOXML(bOOXML)
1054 : {
1055 0 : SdrPage* pPage = rObj.GetPage();
1056 : DBG_ASSERT( pPage, "ImplEESdrObject::ImplEESdrObject: no SdrPage" );
1057 0 : if( pPage && rEx.ImplInitPage( *pPage ) )
1058 : {
1059 : // why not declare a const parameter if the object will
1060 : // not be modified?
1061 0 : mXShape = uno::Reference< drawing::XShape >::query( ((SdrObject*)&rObj)->getUnoShape() );
1062 0 : Init( rEx );
1063 : }
1064 0 : }
1065 :
1066 0 : ImplEESdrObject::ImplEESdrObject( ImplEESdrWriter& rEx,
1067 : const Reference< XShape >& rShape ) :
1068 : mXShape( rShape ),
1069 : mnShapeId( 0 ),
1070 : mnTextSize( 0 ),
1071 : mnAngle( 0 ),
1072 : mbValid( sal_False ),
1073 : mbPresObj( sal_False ),
1074 : mbEmptyPresObj( sal_False ),
1075 0 : mbOOXML(false)
1076 : {
1077 0 : Init( rEx );
1078 0 : }
1079 :
1080 :
1081 0 : ImplEESdrObject::~ImplEESdrObject()
1082 : {
1083 0 : }
1084 :
1085 0 : basegfx::B2DRange getUnrotatedGroupBoundRange(const Reference< XShape >& rxShape)
1086 : {
1087 0 : basegfx::B2DRange aRetval;
1088 :
1089 : try
1090 : {
1091 0 : if(rxShape.is())
1092 : {
1093 0 : if(rxShape->getShapeType() == "com.sun.star.drawing.GroupShape")
1094 : {
1095 : // it's a group shape, iterate over children
1096 0 : const Reference< XIndexAccess > xXIndexAccess(rxShape, UNO_QUERY);
1097 :
1098 0 : if(xXIndexAccess.is())
1099 : {
1100 0 : for(sal_uInt32 n(0), nCnt = xXIndexAccess->getCount(); n < nCnt; ++n)
1101 : {
1102 0 : const Reference< XShape > axShape(xXIndexAccess->getByIndex(n), UNO_QUERY);
1103 :
1104 0 : if(axShape.is())
1105 : {
1106 : // we are calculating the bound for a group, correct rotation for sub-objects
1107 : // to get the unrotated bounds for the group
1108 0 : const basegfx::B2DRange aExtend(getUnrotatedGroupBoundRange(axShape));
1109 :
1110 0 : aRetval.expand(aExtend);
1111 : }
1112 0 : }
1113 0 : }
1114 : }
1115 : else
1116 : {
1117 : // iT#s a xShape, get its transformation
1118 0 : const Reference< XPropertySet > mXPropSet(rxShape, UNO_QUERY);
1119 :
1120 0 : if(mXPropSet.is())
1121 : {
1122 0 : const Any aAny = mXPropSet->getPropertyValue(OUString("Transformation"));
1123 :
1124 0 : if(aAny.hasValue())
1125 : {
1126 0 : HomogenMatrix3 aMatrix;
1127 :
1128 0 : if(aAny >>= aMatrix)
1129 : {
1130 0 : basegfx::B2DHomMatrix aHomogenMatrix;
1131 :
1132 0 : aHomogenMatrix.set(0, 0, aMatrix.Line1.Column1);
1133 0 : aHomogenMatrix.set(0, 1, aMatrix.Line1.Column2);
1134 0 : aHomogenMatrix.set(0, 2, aMatrix.Line1.Column3);
1135 0 : aHomogenMatrix.set(1, 0, aMatrix.Line2.Column1);
1136 0 : aHomogenMatrix.set(1, 1, aMatrix.Line2.Column2);
1137 0 : aHomogenMatrix.set(1, 2, aMatrix.Line2.Column3);
1138 0 : aHomogenMatrix.set(2, 0, aMatrix.Line3.Column1);
1139 0 : aHomogenMatrix.set(2, 1, aMatrix.Line3.Column2);
1140 0 : aHomogenMatrix.set(2, 2, aMatrix.Line3.Column3);
1141 :
1142 0 : basegfx::B2DVector aScale, aTranslate;
1143 : double fRotate, fShearX;
1144 :
1145 : // decopose transformation
1146 0 : aHomogenMatrix.decompose(aScale, aTranslate, fRotate, fShearX);
1147 :
1148 : // check if rotation needs to be corrected
1149 0 : if(!basegfx::fTools::equalZero(fRotate))
1150 : {
1151 : // to correct, keep in mind that ppt graphics are rotated around their center
1152 0 : const basegfx::B2DPoint aCenter(aHomogenMatrix * basegfx::B2DPoint(0.5, 0.5));
1153 :
1154 0 : aHomogenMatrix.translate(-aCenter.getX(), -aCenter.getY());
1155 0 : aHomogenMatrix.rotate(-fRotate);
1156 0 : aHomogenMatrix.translate(aCenter.getX(), aCenter.getY());
1157 : }
1158 :
1159 :
1160 : // check if shear needs to be corrected (always correct shear,
1161 : // ppt does not know about it)
1162 0 : if(!basegfx::fTools::equalZero(fShearX))
1163 : {
1164 0 : const basegfx::B2DPoint aMinimum(aHomogenMatrix * basegfx::B2DPoint(0.0, 0.0));
1165 :
1166 0 : aHomogenMatrix.translate(-aMinimum.getX(), -aMinimum.getY());
1167 0 : aHomogenMatrix.shearX(-fShearX);
1168 0 : aHomogenMatrix.translate(aMinimum.getX(), aMinimum.getY());
1169 : }
1170 :
1171 : // create range. It's no longer rotated (or sheared), so use
1172 : // minimum and maximum values
1173 0 : aRetval.expand(aHomogenMatrix * basegfx::B2DPoint(0.0, 0.0));
1174 0 : aRetval.expand(aHomogenMatrix * basegfx::B2DPoint(1.0, 1.0));
1175 : }
1176 0 : }
1177 0 : }
1178 : }
1179 : }
1180 : }
1181 0 : catch(::com::sun::star::uno::Exception&)
1182 : {
1183 : }
1184 :
1185 0 : return aRetval;
1186 : }
1187 :
1188 0 : void ImplEESdrObject::Init( ImplEESdrWriter& rEx )
1189 : {
1190 0 : mXPropSet = Reference< XPropertySet >::query( mXShape );
1191 0 : if( mXPropSet.is() )
1192 : {
1193 : // detect name first to make below test (is group) work
1194 0 : mType = OUString( mXShape->getShapeType() );
1195 0 : (void)mType.startsWith( "com.sun.star.", &mType ); // strip "com.sun.star."
1196 0 : (void)mType.endsWith( "Shape", &mType ); // strip "Shape"
1197 :
1198 0 : if(GetType() == "drawing.Group")
1199 : {
1200 : // if it's a group, the unrotated range is needed for that group
1201 0 : const basegfx::B2DRange aUnroatedRange(getUnrotatedGroupBoundRange(mXShape));
1202 0 : const Point aNewP(basegfx::fround(aUnroatedRange.getMinX()), basegfx::fround(aUnroatedRange.getMinY()));
1203 0 : const Size aNewS(basegfx::fround(aUnroatedRange.getWidth()), basegfx::fround(aUnroatedRange.getHeight()));
1204 :
1205 0 : SetRect(rEx.ImplMapPoint(aNewP), rEx.ImplMapSize(aNewS));
1206 : }
1207 : else
1208 : {
1209 : // if it's no group, use position and size directly, roated/sheared or not
1210 0 : const Point aOldP(mXShape->getPosition().X, mXShape->getPosition().Y);
1211 0 : const Size aOldS(mXShape->getSize().Width, mXShape->getSize().Height);
1212 :
1213 0 : SetRect(rEx.ImplMapPoint(aOldP), rEx.ImplMapSize(aOldS));
1214 : }
1215 :
1216 0 : if( ImplGetPropertyValue( OUString("IsPresentationObject")) )
1217 0 : mbPresObj = ::cppu::any2bool( mAny );
1218 :
1219 0 : if( mbPresObj && ImplGetPropertyValue( OUString("IsEmptyPresentationObject") ) )
1220 0 : mbEmptyPresObj = ::cppu::any2bool( mAny );
1221 :
1222 0 : mbValid = sal_True;
1223 : }
1224 0 : }
1225 :
1226 0 : sal_Bool ImplEESdrObject::ImplGetPropertyValue( const sal_Unicode* rString )
1227 : {
1228 0 : sal_Bool bRetValue = sal_False;
1229 0 : if( mbValid )
1230 : {
1231 : try
1232 : {
1233 0 : mAny = mXPropSet->getPropertyValue( rString );
1234 0 : if( mAny.hasValue() )
1235 0 : bRetValue = sal_True;
1236 : }
1237 0 : catch( const ::com::sun::star::uno::Exception& )
1238 : {
1239 0 : bRetValue = sal_False;
1240 : }
1241 : }
1242 0 : return bRetValue;
1243 : }
1244 :
1245 : #ifdef USED
1246 : sal_Bool ImplEESdrObject::ImplGetPropertyValue( const Reference< XPropertySet >& rXPropSet,
1247 : const OUString& rString )
1248 : {
1249 : sal_Bool bRetValue = sal_False;
1250 : if( mbValid )
1251 : {
1252 : try
1253 : {
1254 : mAny = rXPropSet->getPropertyValue( rString );
1255 : if( 0 != mAny.get() )
1256 : bRetValue = sal_True;
1257 : }
1258 : catch( const ::com::sun::star::uno::Exception& )
1259 : {
1260 : bRetValue = sal_False;
1261 : }
1262 : }
1263 : return bRetValue;
1264 : }
1265 : #endif
1266 :
1267 0 : void ImplEESdrObject::SetRect( const Point& rPos, const Size& rSz )
1268 : {
1269 0 : maRect = Rectangle( rPos, rSz );
1270 0 : }
1271 :
1272 0 : const SdrObject* ImplEESdrObject::GetSdrObject() const
1273 : {
1274 0 : return EscherEx::GetSdrObject( mXShape );
1275 : }
1276 :
1277 : // loads and converts text from shape, result is being saved in mnTextSize respeichert
1278 0 : sal_uInt32 ImplEESdrObject::ImplGetText()
1279 : {
1280 0 : Reference< XText > xXText( mXShape, UNO_QUERY );
1281 0 : mnTextSize = 0;
1282 0 : if( xXText.is() )
1283 0 : mnTextSize = xXText->getString().getLength();
1284 0 : return mnTextSize;
1285 : }
1286 :
1287 0 : sal_Bool ImplEESdrObject::ImplHasText() const
1288 : {
1289 0 : Reference< XText > xXText( mXShape, UNO_QUERY );
1290 0 : return xXText.is() && !xXText->getString().isEmpty();
1291 : }
1292 :
1293 0 : bool ImplEESdrObject::GetOOXML() const
1294 : {
1295 0 : return mbOOXML;
1296 : }
1297 :
1298 0 : void ImplEESdrObject::SetOOXML(bool bOOXML)
1299 : {
1300 0 : mbOOXML = bOOXML;
1301 0 : }
1302 :
1303 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|