bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / filter / eppt / pptx-epptbase.cxx
blob1d58016ab18ddd0de931a6b5f1dfc6488595ae8a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "eppt.hxx"
21 #include "epptdef.hxx"
23 #include <tools/globname.hxx>
24 #include <tools/datetime.hxx>
25 #include <tools/poly.hxx>
26 #include <tools/stream.hxx>
27 #include <vcl/graph.hxx>
28 #include <vcl/bmpacc.hxx>
29 #include <vcl/gradient.hxx>
30 #include <vcl/virdev.hxx>
31 #include <rtl/ustring.hxx>
32 #include <rtl/strbuf.hxx>
33 #include <vcl/fltcall.hxx>
34 #include <vcl/wmf.hxx>
35 #include <sfx2/docfile.hxx>
36 #include <sfx2/docinf.hxx>
37 #include <svx/unoapi.hxx>
38 #include <svx/svdobj.hxx>
39 #include <svx/svdoole2.hxx>
40 #include <svx/svdmodel.hxx>
41 #include <svx/svdpage.hxx>
42 #include <com/sun/star/view/PaperOrientation.hpp>
43 #include <com/sun/star/view/PaperFormat.hpp>
44 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
45 #include <com/sun/star/office/XAnnotation.hpp>
46 #include <com/sun/star/office/XAnnotationAccess.hpp>
47 #include <com/sun/star/office/XAnnotationEnumeration.hpp>
48 #include <com/sun/star/geometry/RealPoint2D.hpp>
49 #include <com/sun/star/util/DateTime.hpp>
50 #include <com/sun/star/animations/TransitionType.hpp>
51 #include <com/sun/star/animations/TransitionSubType.hpp>
52 #include <com/sun/star/awt/FontDescriptor.hpp>
53 #include <com/sun/star/awt/FontFamily.hpp>
54 #include <com/sun/star/awt/FontPitch.hpp>
55 #include <com/sun/star/container/XNamed.hpp>
56 #include <com/sun/star/container/XNameAccess.hpp>
57 #include <com/sun/star/presentation/XPresentationPage.hpp>
58 #include <com/sun/star/text/XSimpleText.hpp>
59 #include <com/sun/star/style/XStyle.hpp>
60 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
61 #include <editeng/svxenum.hxx>
62 #include <editeng/flditem.hxx>
63 #include <sot/storinfo.hxx>
64 #include <filter/msfilter/msoleexp.hxx>
65 #include <filter/msfilter/msdffimp.hxx>
66 #include <filter/msfilter/svxmsbas.hxx>
68 #ifdef DEBUG
69 #define DBG(x) x
70 #include <stdio.h>
71 #else
72 #define DBG(x)
73 #endif
75 using namespace com::sun::star;
77 using namespace ::com::sun::star::animations;
78 using namespace ::com::sun::star::awt::FontFamily;
79 using namespace ::com::sun::star::awt::FontPitch;
80 using namespace ::com::sun::star::presentation;
82 using ::com::sun::star::awt::FontDescriptor;
83 using ::com::sun::star::beans::XPropertySet;
84 using ::com::sun::star::container::XNameAccess;
85 using ::com::sun::star::container::XNamed;
86 using ::com::sun::star::drawing::XDrawPagesSupplier;
87 using ::com::sun::star::drawing::XMasterPagesSupplier;
88 using ::com::sun::star::drawing::XShapes;
89 using ::com::sun::star::drawing::XMasterPageTarget;
90 using ::com::sun::star::drawing::XDrawPage;
91 using ::com::sun::star::frame::XModel;
92 using ::com::sun::star::style::XStyleFamiliesSupplier;
93 using ::com::sun::star::style::XStyle;
94 using ::com::sun::star::task::XStatusIndicator;
95 using ::com::sun::star::text::XSimpleText;
96 using ::com::sun::star::uno::Any;
97 using ::com::sun::star::uno::Exception;
98 using ::com::sun::star::uno::Reference;
99 using ::com::sun::star::uno::UNO_QUERY;
101 static PHLayout pPHLayout[] =
103 { EppLayout::TITLESLIDE, { 0x0d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x10, true, true, false },
104 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, true, true, false },
105 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x0d, 0x0e, true, true, false },
106 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, true, true, true },
107 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x0d, 0x0e, true, true, false },
108 { EppLayout::BLANCSLIDE, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, false, false, false },
109 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x0e, true, true, false },
110 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x14, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x0d, 0x0e, true, true, false },
111 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x15, 0x0d, 0x0e, true, false, false },
112 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x16, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x0e, true, true, false },
113 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
114 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, false, false },
115 { EppLayout::RIGHTCOLUMN2ROWS, { 0x0d, 0x0e, 0x13, 0x13, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
116 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
117 { EppLayout::TWOROWSANDTITLE, { 0x0d, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
118 { EppLayout::LEFTCOLUMN2ROWS, { 0x0d, 0x13, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
119 { EppLayout::TOPROW2COLUMN, { 0x0d, 0x13, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
120 { EppLayout::TWOROWSANDTITLE, { 0x0d, 0x0e, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
121 { EppLayout::FOUROBJECTS, { 0x0d, 0x13, 0x13, 0x13, 0x13, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, false, false },
122 { EppLayout::ONLYTITLE, { 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, true, false, false },
123 { EppLayout::BLANCSLIDE, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, false, false, false },
124 { EppLayout::TITLERIGHT2BODIESLEFT, { 0x11, 0x12, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x11, 0x12, true, true, false },
125 { EppLayout::TITLERIGHTBODYLEFT, { 0x11, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x11, 0x12, true, true, false },
126 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x12, true, true, false },
127 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x16, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x12, true, true, false }
130 PPTWriterBase::PPTWriterBase()
131 : mXModel(0)
132 , mXStatusIndicator(0)
133 , mbStatusIndicator(false)
134 , mbPresObj(false)
135 , mbEmptyPresObj(false)
136 , mbIsBackgroundDark(false)
137 , mnAngle(0)
138 , mnPages(0)
139 , mnMasterPages(0)
140 , maFraction(1, 576)
141 , maMapModeSrc(MAP_100TH_MM)
142 , maMapModeDest(MAP_INCH, Point(), maFraction, maFraction)
143 , meLatestPageType(NORMAL)
144 , mpStyleSheet(0)
146 DBG(printf ("PPTWriterBase::PPTWriterBase()\n"));
149 PPTWriterBase::PPTWriterBase( const Reference< XModel > & rXModel,
150 const Reference< XStatusIndicator > & rXStatInd )
151 : mXModel(rXModel)
152 , mXStatusIndicator(rXStatInd)
153 , mbStatusIndicator(false)
154 , mbPresObj(false)
155 , mbEmptyPresObj(false)
156 , mnAngle(0)
157 , mnPages(0)
158 , mnMasterPages(0)
159 , maFraction(1, 576)
160 , maMapModeSrc(MAP_100TH_MM)
161 , maMapModeDest(MAP_INCH, Point(), maFraction, maFraction)
162 , meLatestPageType (NORMAL)
163 , mpStyleSheet(0)
167 PPTWriterBase::~PPTWriterBase()
169 // Possibly unnecessary sanity check for mXStatusIndicator.is().
170 // In 3.3 we had a bug report of a crash where it was null,
171 // https://bugzilla.novell.com/show_bug.cgi?id=694119 (non-public,
172 // bug report, sorry).
173 if ( mbStatusIndicator && mXStatusIndicator.is() )
174 mXStatusIndicator->end();
177 void PPTWriterBase::exportPPT( const std::vector< com::sun::star::beans::PropertyValue >& rMediaData )
179 if ( !InitSOIface() )
180 return;
182 FontCollectionEntry aDefaultFontDesc( OUString( "Times New Roman" ),
183 ROMAN,
184 awt::FontPitch::VARIABLE,
185 RTL_TEXTENCODING_MS_1252 );
186 maFontCollection.GetId( aDefaultFontDesc ); // default is always times new roman
188 if ( !GetPageByIndex( 0, NOTICE ) )
189 return;
191 sal_Int32 nWidth = 21000;
192 if ( ImplGetPropertyValue( mXPagePropSet, OUString( "Width" ) ) )
193 mAny >>= nWidth;
194 sal_Int32 nHeight = 29700;
195 if ( ImplGetPropertyValue( mXPagePropSet, OUString( "Height" ) ) )
196 mAny >>= nHeight;
198 maNotesPageSize = MapSize( awt::Size( nWidth, nHeight ) );
200 if ( !GetPageByIndex( 0, MASTER ) )
201 return;
203 nWidth = 28000;
204 if ( ImplGetPropertyValue( mXPagePropSet, OUString( "Width" ) ) )
205 mAny >>= nWidth;
206 nHeight = 21000;
207 if ( ImplGetPropertyValue( mXPagePropSet, OUString( "Height" ) ) )
208 mAny >>= nHeight;
209 maDestPageSize = MapSize( awt::Size( nWidth, nHeight ) );
210 maPageSize = awt::Size(nWidth, nHeight);
212 DBG(printf( "call exportDocumentPre()\n"));
213 exportPPTPre(rMediaData);
215 if ( !GetStyleSheets() )
216 return;
218 if ( !ImplCreateDocument() )
219 return;
221 sal_uInt32 i;
223 for ( i = 0; i < mnPages; i++ )
225 if ( GetPageByIndex( i, NORMAL ) ) {
226 sal_uInt32 nMasterNum = GetMasterIndex( NORMAL );
227 ImplWriteLayout( GetLayoutOffset( mXPagePropSet ), nMasterNum );
231 for ( i = 0; i < mnMasterPages; i++ )
233 if ( !CreateSlideMaster( i ) )
234 return;
236 if ( !CreateMainNotes() )
237 return;
239 for ( i = 0; i < mnPages; i++ )
241 DBG(printf( "call ImplCreateSlide( %" SAL_PRIuUINT32 " )\n", i));
242 if ( !CreateSlide( i ) )
243 return;
246 for ( i = 0; i < mnPages; i++ )
248 if ( !CreateNotes( i ) )
249 return;
252 DBG(printf( "call exportDocumentPost()\n"));
253 exportPPTPost();
256 bool PPTWriterBase::InitSOIface()
258 while( true )
260 mXDrawPagesSupplier = Reference< XDrawPagesSupplier >( mXModel, UNO_QUERY );
261 if ( !mXDrawPagesSupplier.is() )
262 break;
264 mXMasterPagesSupplier = Reference< XMasterPagesSupplier >( mXModel, UNO_QUERY );
265 if ( !mXMasterPagesSupplier.is() )
266 break;
267 mXDrawPages = mXMasterPagesSupplier->getMasterPages();
268 if ( !mXDrawPages.is() )
269 break;
270 mnMasterPages = mXDrawPages->getCount();
271 mXDrawPages = mXDrawPagesSupplier->getDrawPages();
272 if( !mXDrawPages.is() )
273 break;
274 mnPages = mXDrawPages->getCount();
275 if ( !GetPageByIndex( 0, NORMAL ) )
276 break;
278 return true;
280 return false;
283 bool PPTWriterBase::GetPageByIndex( sal_uInt32 nIndex, PageType ePageType )
285 while( true )
287 if ( ePageType != meLatestPageType )
289 switch( ePageType )
291 case NORMAL :
292 case NOTICE :
294 mXDrawPages = mXDrawPagesSupplier->getDrawPages();
295 if( !mXDrawPages.is() )
296 return false;
298 break;
300 case MASTER :
302 mXDrawPages = mXMasterPagesSupplier->getMasterPages();
303 if( !mXDrawPages.is() )
304 return false;
306 break;
307 default:
308 break;
310 meLatestPageType = ePageType;
312 Any aAny( mXDrawPages->getByIndex( nIndex ) );
313 aAny >>= mXDrawPage;
314 if ( !mXDrawPage.is() )
315 break;
316 if ( ePageType == NOTICE )
318 Reference< XPresentationPage > aXPresentationPage( mXDrawPage, UNO_QUERY );
319 if ( !aXPresentationPage.is() )
320 break;
321 mXDrawPage = aXPresentationPage->getNotesPage();
322 if ( !mXDrawPage.is() )
323 break;
325 mXPagePropSet = Reference< XPropertySet >( mXDrawPage, UNO_QUERY );
326 if ( !mXPagePropSet.is() )
327 break;
329 if (GetPropertyValue( aAny, mXPagePropSet, OUString("IsBackgroundDark") ) )
330 aAny >>= mbIsBackgroundDark;
332 mXShapes = Reference< XShapes >( mXDrawPage, UNO_QUERY );
333 if ( !mXShapes.is() )
334 break;
336 /* try to get the "real" background PropertySet. If the normal page is not supporting this property, it is
337 taken the property from the master */
338 bool bHasBackground = GetPropertyValue( aAny, mXPagePropSet, OUString( "Background" ), true );
339 if ( bHasBackground )
340 bHasBackground = ( aAny >>= mXBackgroundPropSet );
341 if ( !bHasBackground )
343 Reference< XMasterPageTarget > aXMasterPageTarget( mXDrawPage, UNO_QUERY );
344 if ( aXMasterPageTarget.is() )
346 Reference< XDrawPage > aXMasterDrawPage;
347 aXMasterDrawPage = aXMasterPageTarget->getMasterPage();
348 if ( aXMasterDrawPage.is() )
350 Reference< XPropertySet > aXMasterPagePropSet;
351 aXMasterPagePropSet = Reference< XPropertySet >
352 ( aXMasterDrawPage, UNO_QUERY );
353 if ( aXMasterPagePropSet.is() )
355 bool bBackground = GetPropertyValue( aAny, aXMasterPagePropSet, OUString( "Background" ) );
356 if ( bBackground )
358 aAny >>= mXBackgroundPropSet;
364 return true;
366 return false;
369 bool PPTWriterBase::CreateSlide( sal_uInt32 nPageNum )
371 Any aAny;
373 if ( !GetPageByIndex( nPageNum, NORMAL ) )
374 return false;
376 sal_uInt32 nMasterNum = GetMasterIndex( NORMAL );
377 SetCurrentStyleSheet( nMasterNum );
379 Reference< XPropertySet > aXBackgroundPropSet;
380 bool bHasBackground = GetPropertyValue( aAny, mXPagePropSet, OUString( "Background" ) );
381 if ( bHasBackground )
382 bHasBackground = ( aAny >>= aXBackgroundPropSet );
384 sal_uInt16 nMode = 7; // Bit 1: Follow master objects, Bit 2: Follow master scheme, Bit 3: Follow master background
385 if ( bHasBackground )
386 nMode &=~4;
388 /* sj: Don't know what's IsBackgroundVisible for, have to ask cl
389 if ( GetPropertyValue( aAny, mXPagePropSet, OUString( "IsBackgroundVisible" ) ) )
391 bool bBackgroundVisible;
392 if ( aAny >>= bBackgroundVisible )
394 if ( bBackgroundVisible )
395 nMode &= ~4;
399 if ( GetPropertyValue( aAny, mXPagePropSet, OUString( "IsBackgroundObjectsVisible" ) ) )
401 bool bBackgroundObjectsVisible = false;
402 if ( aAny >>= bBackgroundObjectsVisible )
404 if ( !bBackgroundObjectsVisible )
405 nMode &= ~1;
409 ImplWriteSlide( nPageNum, nMasterNum, nMode, bHasBackground, aXBackgroundPropSet );
411 return true;
414 bool PPTWriterBase::CreateNotes( sal_uInt32 nPageNum )
416 if ( !GetPageByIndex( nPageNum, NOTICE ) )
417 return false;
418 SetCurrentStyleSheet( GetMasterIndex( NORMAL ) );
420 ImplWriteNotes( nPageNum );
422 return true;
425 bool PPTWriterBase::CreateSlideMaster( sal_uInt32 nPageNum )
427 if ( !GetPageByIndex( nPageNum, MASTER ) )
428 return false;
429 SetCurrentStyleSheet( nPageNum );
431 if ( !ImplGetPropertyValue( mXPagePropSet, OUString( "Background" ) ) ) // load background shape
432 return false;
433 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > aXBackgroundPropSet;
434 if ( !( mAny >>= aXBackgroundPropSet ) )
435 return false;
437 ImplWriteSlideMaster( nPageNum, aXBackgroundPropSet );
439 return true;
442 sal_Int32 PPTWriterBase::GetLayoutOffset( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rXPropSet )
444 ::com::sun::star::uno::Any aAny;
445 sal_Int32 nLayout = 20;
446 if ( GetPropertyValue( aAny, rXPropSet, OUString( "Layout" ), true ) )
447 aAny >>= nLayout;
449 DBG(printf("GetLayoutOffset %" SAL_PRIdINT32 "\n", nLayout));
451 return nLayout;
454 sal_Int32 PPTWriterBase::GetLayoutOffsetFixed( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rXPropSet )
456 sal_Int32 nLayout = GetLayoutOffset( rXPropSet );
458 if ( ( nLayout >= 21 ) && ( nLayout <= 26 ) ) // NOTES _> HANDOUT6
459 nLayout = 20;
460 if ( ( nLayout >= 27 ) && ( nLayout <= 30 ) ) // VERTICAL LAYOUT
461 nLayout -= 6;
462 else if ( nLayout > 30 )
463 nLayout = 20;
465 return nLayout;
468 PHLayout& PPTWriterBase::GetLayout( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rXPropSet )
470 return pPHLayout[ GetLayoutOffsetFixed( rXPropSet ) ];
473 PHLayout& PPTWriterBase::GetLayout( sal_Int32 nOffset )
475 if( nOffset >= 0 && nOffset < EPP_LAYOUT_SIZE )
476 return pPHLayout[ nOffset ];
478 DBG(printf("asked %" SAL_PRIdINT32 " for layout outside of 0,%d array scope\n", nOffset, EPP_LAYOUT_SIZE ));
480 return pPHLayout[ 0 ];
483 sal_uInt32 PPTWriterBase::GetMasterIndex( PageType ePageType )
485 sal_uInt32 nRetValue = 0;
486 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XMasterPageTarget >
487 aXMasterPageTarget( mXDrawPage, ::com::sun::star::uno::UNO_QUERY );
489 if ( aXMasterPageTarget.is() )
491 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >
492 aXDrawPage = aXMasterPageTarget->getMasterPage();
493 if ( aXDrawPage.is() )
495 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
496 aXPropertySet( aXDrawPage, ::com::sun::star::uno::UNO_QUERY );
498 if ( aXPropertySet.is() )
500 if ( ImplGetPropertyValue( aXPropertySet, OUString( "Number" ) ) )
501 nRetValue |= *static_cast<sal_Int16 const *>(mAny.getValue());
502 if ( nRetValue & 0xffff ) // avoid overflow
503 nRetValue--;
507 if ( ePageType == NOTICE )
508 nRetValue += mnMasterPages;
509 return nRetValue;
512 bool PPTWriterBase::SetCurrentStyleSheet( sal_uInt32 nPageNum )
514 bool bRet = false;
515 if ( nPageNum >= maStyleSheetList.size() )
516 nPageNum = 0;
517 else
518 bRet = true;
519 mpStyleSheet = maStyleSheetList[ nPageNum ];
520 return bRet;
523 bool PPTWriterBase::GetStyleSheets()
525 int nInstance, nLevel;
526 bool bRetValue = false;
527 sal_uInt32 nPageNum;
529 for ( nPageNum = 0; nPageNum < mnMasterPages; nPageNum++ )
531 Reference< XNamed >
532 aXNamed;
534 Reference< XNameAccess >
535 aXNameAccess;
537 Reference< XStyleFamiliesSupplier >
538 aXStyleFamiliesSupplier( mXModel, UNO_QUERY );
540 Reference< XPropertySet >
541 aXPropSet( mXModel, UNO_QUERY );
543 sal_uInt16 nDefaultTab = ( aXPropSet.is() && ImplGetPropertyValue( aXPropSet, OUString( "TabStop" ) ) )
544 ? (sal_uInt16)( *static_cast<sal_Int32 const *>(mAny.getValue()) / 4.40972 )
545 : 1250;
547 maStyleSheetList.push_back( new PPTExStyleSheet( nDefaultTab, dynamic_cast<PPTExBulletProvider*>(this) ) );
548 SetCurrentStyleSheet( nPageNum );
549 if ( GetPageByIndex( nPageNum, MASTER ) )
550 aXNamed = Reference< XNamed >
551 ( mXDrawPage, UNO_QUERY );
553 if ( aXStyleFamiliesSupplier.is() )
554 aXNameAccess = aXStyleFamiliesSupplier->getStyleFamilies();
556 bRetValue = aXNamed.is() && aXNameAccess.is() && aXStyleFamiliesSupplier.is();
557 if ( bRetValue )
559 for ( nInstance = EPP_TEXTTYPE_Title; nInstance <= EPP_TEXTTYPE_CenterTitle; nInstance++ )
561 OUString aStyle;
562 OUString aFamily;
563 switch ( nInstance )
565 case EPP_TEXTTYPE_CenterTitle :
566 case EPP_TEXTTYPE_Title :
568 aStyle = "title";
569 aFamily = aXNamed->getName();
571 break;
572 case EPP_TEXTTYPE_Body :
574 aStyle = "outline1"; // SD_LT_SEPARATOR
575 aFamily = aXNamed->getName();
577 break;
578 case EPP_TEXTTYPE_Other :
580 aStyle = "standard";
581 aFamily = "graphics";
583 break;
584 case EPP_TEXTTYPE_CenterBody :
586 aStyle = "subtitle";
587 aFamily = aXNamed->getName();
589 break;
591 if ( !aStyle.isEmpty() && !aFamily.isEmpty() )
595 Reference< XNameAccess >xNameAccess;
596 if ( aXNameAccess->hasByName( aFamily ) )
598 Any aAny( aXNameAccess->getByName( aFamily ) );
599 xNameAccess.set(aAny, css::uno::UNO_QUERY);
600 if( xNameAccess.is() )
602 Reference< XNameAccess > aXFamily;
603 if ( aAny >>= aXFamily )
605 if ( aXFamily->hasByName( aStyle ) )
607 aAny = aXFamily->getByName( aStyle );
608 Reference< XStyle > xStyle(
609 aAny, css::uno::UNO_QUERY);
610 if( xStyle.is() )
612 Reference< XStyle > aXStyle;
613 aAny >>= aXStyle;
614 Reference< XPropertySet >
615 xPropSet( aXStyle, UNO_QUERY );
616 if( xPropSet.is() )
617 mpStyleSheet->SetStyleSheet( xPropSet, maFontCollection, nInstance, 0 );
618 for ( nLevel = 1; nLevel < 5; nLevel++ )
620 if ( nInstance == EPP_TEXTTYPE_Body )
622 sal_Unicode cTemp = aStyle[aStyle.getLength() - 1];
623 aStyle = aStyle.copy(0, aStyle.getLength() - 1) + OUString(++cTemp);
624 if ( aXFamily->hasByName( aStyle ) )
626 aXFamily->getByName( aStyle ) >>= xStyle;
627 if( xStyle.is() )
629 Reference< XPropertySet >
630 xPropertySet( xStyle, UNO_QUERY );
631 if ( xPropertySet.is() )
632 mpStyleSheet->SetStyleSheet( xPropertySet, maFontCollection, nInstance, nLevel );
636 else
637 mpStyleSheet->SetStyleSheet( xPropSet, maFontCollection, nInstance, nLevel );
645 catch( Exception& )
651 for ( ; nInstance <= EPP_TEXTTYPE_QuarterBody; nInstance++ )
657 return bRetValue;
660 bool PPTWriterBase::CreateMainNotes()
662 if ( !GetPageByIndex( 0, NOTICE ) )
663 return false;
664 SetCurrentStyleSheet( 0 );
666 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XMasterPageTarget >
667 aXMasterPageTarget( mXDrawPage, ::com::sun::star::uno::UNO_QUERY );
669 if ( !aXMasterPageTarget.is() )
670 return false;
672 mXDrawPage = aXMasterPageTarget->getMasterPage();
673 if ( !mXDrawPage.is() )
674 return false;
676 mXPropSet = ::com::sun::star::uno::Reference<
677 ::com::sun::star::beans::XPropertySet >
678 ( mXDrawPage, ::com::sun::star::uno::UNO_QUERY );
679 if ( !mXPropSet.is() )
680 return false;
682 mXShapes = ::com::sun::star::uno::Reference<
683 ::com::sun::star::drawing::XShapes >
684 ( mXDrawPage, ::com::sun::star::uno::UNO_QUERY );
685 if ( !mXShapes.is() )
686 return false;
688 return ImplCreateMainNotes();
691 awt::Size PPTWriterBase::MapSize( const awt::Size& rSize )
693 Size aRetSize( OutputDevice::LogicToLogic( Size( rSize.Width, rSize.Height ), maMapModeSrc, maMapModeDest ) );
695 if ( !aRetSize.Width() )
696 aRetSize.Width()++;
697 if ( !aRetSize.Height() )
698 aRetSize.Height()++;
699 return awt::Size( aRetSize.Width(), aRetSize.Height() );
702 awt::Point PPTWriterBase::MapPoint( const awt::Point& rPoint )
704 Point aRet( OutputDevice::LogicToLogic( Point( rPoint.X, rPoint.Y ), maMapModeSrc, maMapModeDest ) );
705 return awt::Point( aRet.X(), aRet.Y() );
708 Rectangle PPTWriterBase::MapRectangle( const awt::Rectangle& rRect )
710 ::com::sun::star::awt::Point aPoint( rRect.X, rRect.Y );
711 ::com::sun::star::awt::Size aSize( rRect.Width, rRect.Height );
712 ::com::sun::star::awt::Point aP( MapPoint( aPoint ) );
713 ::com::sun::star::awt::Size aS( MapSize( aSize ) );
714 return Rectangle( Point( aP.X, aP.Y ), Size( aS.Width, aS.Height ) );
717 bool PPTWriterBase::GetShapeByIndex( sal_uInt32 nIndex, bool bGroup )
719 while(true)
721 if ( !bGroup || ( GetCurrentGroupLevel() == 0 ) )
723 Any aAny( mXShapes->getByIndex( nIndex ) );
724 aAny >>= mXShape;
726 else
728 Any aAny( GetCurrentGroupAccess()->getByIndex( GetCurrentGroupIndex() ) );
729 aAny >>= mXShape;
731 if ( !mXShape.is() )
732 break;
734 Any aAny( mXShape->queryInterface( cppu::UnoType<XPropertySet>::get()));
735 aAny >>= mXPropSet;
737 if ( !mXPropSet.is() )
738 break;
739 maPosition = MapPoint( mXShape->getPosition() );
740 maSize = MapSize( mXShape->getSize() );
741 maRect = Rectangle( Point( maPosition.X, maPosition.Y ), Size( maSize.Width, maSize.Height ) );
743 OStringBuffer aTypeBuffer(OUStringToOString(
744 mXShape->getShapeType(), RTL_TEXTENCODING_UTF8));
745 // remove "com.sun.star."
746 aTypeBuffer.remove(0, RTL_CONSTASCII_LENGTH("com.sun.star."));
748 sal_Int32 nPos = aTypeBuffer.toString().indexOf("Shape");
749 aTypeBuffer.remove(nPos, RTL_CONSTASCII_LENGTH("Shape"));
750 mType = aTypeBuffer.makeStringAndClear();
752 mbPresObj = mbEmptyPresObj = false;
753 if ( ImplGetPropertyValue( OUString( "IsPresentationObject" ) ) )
754 mAny >>= mbPresObj;
756 if ( mbPresObj && ImplGetPropertyValue( OUString( "IsEmptyPresentationObject" ) ) )
757 mAny >>= mbEmptyPresObj;
759 mnAngle = ( PropValue::GetPropertyValue( aAny,
760 mXPropSet, OUString( "RotateAngle" ), true ) )
761 ? *static_cast<sal_Int32 const *>(aAny.getValue())
762 : 0;
764 return true;
766 return false;
769 sal_Int8 PPTWriterBase::GetTransition( sal_Int16 nTransitionType, sal_Int16 nTransitionSubtype, FadeEffect eEffect, sal_uInt8& nDirection )
771 sal_Int8 nPPTTransitionType = 0;
772 nDirection = 0;
774 switch( nTransitionType )
776 case TransitionType::FADE :
778 if ( nTransitionSubtype == TransitionSubType::CROSSFADE )
779 nPPTTransitionType = PPT_TRANSITION_TYPE_SMOOTHFADE;
780 else if ( nTransitionSubtype == TransitionSubType::FADEOVERCOLOR )
781 nPPTTransitionType = PPT_TRANSITION_TYPE_FADE;
783 break;
784 case PPT_TRANSITION_TYPE_COMB :
786 nPPTTransitionType = PPT_TRANSITION_TYPE_COMB;
787 if ( nTransitionSubtype == TransitionSubType::COMBVERTICAL )
788 nDirection++;
790 break;
791 case TransitionType::PUSHWIPE :
793 nPPTTransitionType = PPT_TRANSITION_TYPE_PUSH;
794 switch( nTransitionSubtype )
796 case TransitionSubType::FROMRIGHT: nDirection = 0; break;
797 case TransitionSubType::FROMBOTTOM: nDirection = 1; break;
798 case TransitionSubType::FROMLEFT: nDirection = 2; break;
799 case TransitionSubType::FROMTOP: nDirection = 3; break;
802 break;
803 case TransitionType::PINWHEELWIPE :
805 nPPTTransitionType = PPT_TRANSITION_TYPE_WHEEL;
806 switch( nTransitionSubtype )
808 case TransitionSubType::ONEBLADE: nDirection = 1; break;
809 case TransitionSubType::TWOBLADEVERTICAL : nDirection = 2; break;
810 case TransitionSubType::THREEBLADE : nDirection = 3; break;
811 case TransitionSubType::FOURBLADE: nDirection = 4; break;
812 case TransitionSubType::EIGHTBLADE: nDirection = 8; break;
815 break;
816 case TransitionType::FANWIPE :
818 nPPTTransitionType = PPT_TRANSITION_TYPE_WEDGE;
820 break;
821 case TransitionType::ELLIPSEWIPE :
823 nPPTTransitionType = PPT_TRANSITION_TYPE_CIRCLE;
825 break;
826 case TransitionType::FOURBOXWIPE :
828 nPPTTransitionType = PPT_TRANSITION_TYPE_PLUS;
830 break;
831 case TransitionType::IRISWIPE :
833 switch( nTransitionSubtype ) {
834 case TransitionSubType::RECTANGLE:
835 nPPTTransitionType = PPT_TRANSITION_TYPE_ZOOM;
836 nDirection = (eEffect == FadeEffect_FADE_FROM_CENTER) ? 0 : 1;
837 break;
838 default:
839 nPPTTransitionType = PPT_TRANSITION_TYPE_DIAMOND;
840 break;
843 break;
846 return nPPTTransitionType;
849 sal_Int8 PPTWriterBase::GetTransition( FadeEffect eEffect, sal_uInt8& nDirection )
851 sal_Int8 nPPTTransitionType = 0;
853 switch ( eEffect )
855 default :
856 case FadeEffect_RANDOM :
857 nPPTTransitionType = PPT_TRANSITION_TYPE_RANDOM;
858 break;
860 case FadeEffect_HORIZONTAL_STRIPES :
861 nDirection++;
862 case FadeEffect_VERTICAL_STRIPES :
863 nPPTTransitionType = PPT_TRANSITION_TYPE_BLINDS;
864 break;
866 case FadeEffect_VERTICAL_CHECKERBOARD :
867 nDirection++;
868 case FadeEffect_HORIZONTAL_CHECKERBOARD :
869 nPPTTransitionType = PPT_TRANSITION_TYPE_CHECKER;
870 break;
872 case FadeEffect_MOVE_FROM_UPPERLEFT :
873 nDirection++;
874 case FadeEffect_MOVE_FROM_UPPERRIGHT :
875 nDirection++;
876 case FadeEffect_MOVE_FROM_LOWERLEFT :
877 nDirection++;
878 case FadeEffect_MOVE_FROM_LOWERRIGHT :
879 nDirection++;
880 case FadeEffect_MOVE_FROM_TOP :
881 nDirection++;
882 case FadeEffect_MOVE_FROM_LEFT :
883 nDirection++;
884 case FadeEffect_MOVE_FROM_BOTTOM :
885 nDirection++;
886 case FadeEffect_MOVE_FROM_RIGHT :
887 nPPTTransitionType = PPT_TRANSITION_TYPE_COVER;
888 break;
890 case FadeEffect_DISSOLVE :
891 nPPTTransitionType = PPT_TRANSITION_TYPE_DISSOLVE;
892 break;
894 case FadeEffect_VERTICAL_LINES :
895 nDirection++;
896 case FadeEffect_HORIZONTAL_LINES :
897 nPPTTransitionType = PPT_TRANSITION_TYPE_RANDOM_BARS;
898 break;
900 case FadeEffect_CLOSE_HORIZONTAL :
901 nDirection++;
902 case FadeEffect_OPEN_HORIZONTAL :
903 nDirection++;
904 case FadeEffect_CLOSE_VERTICAL :
905 nDirection++;
906 case FadeEffect_OPEN_VERTICAL :
907 nPPTTransitionType = PPT_TRANSITION_TYPE_SPLIT;
908 break;
910 case FadeEffect_FADE_FROM_UPPERLEFT :
911 nDirection++;
912 case FadeEffect_FADE_FROM_UPPERRIGHT :
913 nDirection++;
914 case FadeEffect_FADE_FROM_LOWERLEFT :
915 nDirection++;
916 case FadeEffect_FADE_FROM_LOWERRIGHT :
917 nDirection += 4;
918 nPPTTransitionType = PPT_TRANSITION_TYPE_STRIPS;
919 break;
921 case FadeEffect_UNCOVER_TO_LOWERRIGHT :
922 nDirection++;
923 case FadeEffect_UNCOVER_TO_LOWERLEFT :
924 nDirection++;
925 case FadeEffect_UNCOVER_TO_UPPERRIGHT :
926 nDirection++;
927 case FadeEffect_UNCOVER_TO_UPPERLEFT :
928 nDirection++;
929 case FadeEffect_UNCOVER_TO_BOTTOM :
930 nDirection++;
931 case FadeEffect_UNCOVER_TO_RIGHT :
932 nDirection++;
933 case FadeEffect_UNCOVER_TO_TOP :
934 nDirection++;
935 case FadeEffect_UNCOVER_TO_LEFT :
936 nPPTTransitionType = PPT_TRANSITION_TYPE_PULL;
937 break;
939 case FadeEffect_FADE_FROM_TOP :
940 nDirection++;
941 case FadeEffect_FADE_FROM_LEFT :
942 nDirection++;
943 case FadeEffect_FADE_FROM_BOTTOM :
944 nDirection++;
945 case FadeEffect_FADE_FROM_RIGHT :
946 nPPTTransitionType = PPT_TRANSITION_TYPE_WIPE;
947 break;
949 case FadeEffect_ROLL_FROM_TOP :
950 nDirection++;
951 case FadeEffect_ROLL_FROM_LEFT :
952 nDirection++;
953 case FadeEffect_ROLL_FROM_BOTTOM :
954 nDirection++;
955 case FadeEffect_ROLL_FROM_RIGHT :
956 nPPTTransitionType = PPT_TRANSITION_TYPE_WIPE;
957 break;
959 case FadeEffect_FADE_TO_CENTER :
960 nDirection++;
961 case FadeEffect_FADE_FROM_CENTER :
962 nPPTTransitionType = PPT_TRANSITION_TYPE_ZOOM;
963 break;
965 case FadeEffect_NONE :
966 nDirection = 2;
967 break;
970 return nPPTTransitionType;
973 bool PPTWriterBase::ContainsOtherShapeThanPlaceholders( bool bForOOMLX )
975 sal_uInt32 nShapes = mXShapes->getCount();
976 bool bOtherThanPlaceHolders = false;
978 if ( nShapes )
979 for ( sal_uInt32 nIndex = 0; ( nIndex < nShapes ) && !bOtherThanPlaceHolders; nIndex++ )
981 if ( GetShapeByIndex( nIndex ) && mType != "drawing.Page" )
983 if( bForOOMLX &&
984 ( mType == "presentation.Page" ||
985 mType == "presentation.Notes" ) ) {
986 Reference< XSimpleText > rXText( mXShape, UNO_QUERY );
988 if( rXText.is() && !rXText->getString().isEmpty() )
989 bOtherThanPlaceHolders = true;
991 else
992 bOtherThanPlaceHolders = true;
994 DBG(printf("mType == %s\n", mType.getStr()));
997 return bOtherThanPlaceHolders;
1000 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */