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