bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / filter / eppt / pptx-epptbase.cxx
blob0c10c2bada545e8ec00fe3aba2263ad87f460e9e
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 "epptbase.hxx"
21 #include "epptdef.hxx"
22 #include "../ppt/pptanimations.hxx"
24 #include <o3tl/any.hxx>
25 #include <vcl/outdev.hxx>
26 #include <rtl/ustring.hxx>
27 #include <rtl/strbuf.hxx>
28 #include <sal/log.hxx>
29 #include <com/sun/star/awt/Rectangle.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
32 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
33 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
34 #include <com/sun/star/drawing/XDrawPages.hpp>
35 #include <com/sun/star/animations/TransitionType.hpp>
36 #include <com/sun/star/animations/TransitionSubType.hpp>
37 #include <com/sun/star/awt/FontFamily.hpp>
38 #include <com/sun/star/awt/FontPitch.hpp>
39 #include <com/sun/star/container/XNamed.hpp>
40 #include <com/sun/star/container/XNameAccess.hpp>
41 #include <com/sun/star/presentation/XPresentationPage.hpp>
42 #include <com/sun/star/text/XSimpleText.hpp>
43 #include <com/sun/star/style/XStyle.hpp>
44 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
45 #include <com/sun/star/task/XStatusIndicator.hpp>
48 using namespace com::sun::star;
50 using namespace ::com::sun::star::animations;
51 using namespace ::com::sun::star::awt::FontFamily;
52 using namespace ::com::sun::star::awt::FontPitch;
53 using namespace ::com::sun::star::presentation;
55 using ::com::sun::star::beans::XPropertySet;
56 using ::com::sun::star::container::XNameAccess;
57 using ::com::sun::star::container::XNamed;
58 using ::com::sun::star::drawing::XMasterPageTarget;
59 using ::com::sun::star::drawing::XDrawPage;
60 using ::com::sun::star::frame::XModel;
61 using ::com::sun::star::style::XStyleFamiliesSupplier;
62 using ::com::sun::star::style::XStyle;
63 using ::com::sun::star::task::XStatusIndicator;
64 using ::com::sun::star::text::XSimpleText;
65 using ::com::sun::star::uno::Any;
66 using ::com::sun::star::uno::Exception;
67 using ::com::sun::star::uno::Reference;
68 using ::com::sun::star::uno::UNO_QUERY;
70 static PHLayout const pPHLayout[] =
72 { EppLayout::TITLESLIDE, { 0x0d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x10, true, true, false },
73 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, true, true, false },
74 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x0d, 0x0e, true, true, false },
75 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, true, true, true },
76 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x0d, 0x0e, true, true, false },
77 { EppLayout::BLANKSLIDE, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, false, false, false },
78 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x0e, true, true, false },
79 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x14, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x0d, 0x0e, true, true, false },
80 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x15, 0x0d, 0x0e, true, false, false },
81 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x16, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x0e, true, true, false },
82 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
83 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, false, false },
84 { EppLayout::RIGHTCOLUMN2ROWS, { 0x0d, 0x0e, 0x13, 0x13, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
85 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
86 { EppLayout::TWOROWSANDTITLE, { 0x0d, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
87 { EppLayout::LEFTCOLUMN2ROWS, { 0x0d, 0x13, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
88 { EppLayout::TOPROW2COLUMN, { 0x0d, 0x13, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
89 { EppLayout::TWOROWSANDTITLE, { 0x0d, 0x0e, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
90 { EppLayout::FOUROBJECTS, { 0x0d, 0x13, 0x13, 0x13, 0x13, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, false, false },
91 { EppLayout::ONLYTITLE, { 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, true, false, false },
92 { EppLayout::BLANKSLIDE, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, false, false, false },
93 { EppLayout::TITLERIGHT2BODIESLEFT, { 0x11, 0x12, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x11, 0x12, true, true, false },
94 { EppLayout::TITLERIGHTBODYLEFT, { 0x11, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x11, 0x12, true, true, false },
95 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x12, true, true, false },
96 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x16, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x12, true, true, false }
99 PPTWriterBase::PPTWriterBase()
100 : mbStatusIndicator(false)
101 , mbPresObj(false)
102 , mbEmptyPresObj(false)
103 , mbIsBackgroundDark(false)
104 , mnAngle(0)
105 , mnPages(0)
106 , mnMasterPages(0)
107 , maFraction(1, 576)
108 , maMapModeSrc(MapUnit::Map100thMM)
109 , maMapModeDest(MapUnit::MapInch, Point(), maFraction, maFraction)
110 , meLatestPageType(NORMAL)
111 , mpStyleSheet(nullptr)
113 SAL_INFO("sd.eppt", "PPTWriterBase::PPTWriterBase()");
116 PPTWriterBase::PPTWriterBase( const Reference< XModel > & rXModel,
117 const Reference< XStatusIndicator > & rXStatInd )
118 : mXModel(rXModel)
119 , mXStatusIndicator(rXStatInd)
120 , mbStatusIndicator(false)
121 , mbPresObj(false)
122 , mbEmptyPresObj(false)
123 , mbIsBackgroundDark(false)
124 , mnAngle(0)
125 , mnPages(0)
126 , mnMasterPages(0)
127 , maFraction(1, 576)
128 , maMapModeSrc(MapUnit::Map100thMM)
129 , maMapModeDest(MapUnit::MapInch, Point(), maFraction, maFraction)
130 , meLatestPageType (NORMAL)
131 , mpStyleSheet(nullptr)
135 PPTWriterBase::~PPTWriterBase()
137 // Possibly unnecessary sanity check for mXStatusIndicator.is().
138 // In 3.3 we had a bug report of a crash where it was null,
139 // https://bugzilla.novell.com/show_bug.cgi?id=694119 (non-public,
140 // bug report, sorry).
141 if ( mbStatusIndicator && mXStatusIndicator.is() )
142 mXStatusIndicator->end();
145 void PPTWriterBase::exportPPT( const std::vector< css::beans::PropertyValue >& rMediaData )
147 if ( !InitSOIface() )
148 return;
150 FontCollectionEntry aDefaultFontDesc( "Times New Roman",
151 ROMAN,
152 awt::FontPitch::VARIABLE,
153 RTL_TEXTENCODING_MS_1252 );
154 maFontCollection.GetId( aDefaultFontDesc ); // default is always times new roman
156 if ( !GetPageByIndex( 0, NOTICE ) )
157 return;
159 sal_Int32 nWidth = 21000;
160 if ( ImplGetPropertyValue( mXPagePropSet, "Width" ) )
161 mAny >>= nWidth;
162 sal_Int32 nHeight = 29700;
163 if ( ImplGetPropertyValue( mXPagePropSet, "Height" ) )
164 mAny >>= nHeight;
166 maNotesPageSize = MapSize( awt::Size( nWidth, nHeight ) );
168 if ( !GetPageByIndex( 0, MASTER ) )
169 return;
171 nWidth = 28000;
172 if ( ImplGetPropertyValue( mXPagePropSet, "Width" ) )
173 mAny >>= nWidth;
174 nHeight = 21000;
175 if ( ImplGetPropertyValue( mXPagePropSet, "Height" ) )
176 mAny >>= nHeight;
177 maDestPageSize = MapSize( awt::Size( nWidth, nHeight ) );
178 maPageSize = awt::Size(nWidth, nHeight);
180 SAL_INFO("sd.eppt", "call exportDocumentPre()");
181 exportPPTPre(rMediaData);
183 if ( !GetStyleSheets() )
184 return;
186 if ( !ImplCreateDocument() )
187 return;
189 sal_uInt32 i;
191 for ( i = 0; i < mnMasterPages; i++ )
193 if ( !CreateSlideMaster( i ) )
194 return;
196 if ( !CreateMainNotes() )
197 return;
199 for ( i = 0; i < mnPages; i++ )
201 SAL_INFO("sd.eppt", "call ImplCreateSlide( " << i << " )");
202 if ( !CreateSlide( i ) )
203 return;
206 for ( i = 0; i < mnPages; i++ )
208 if ( !CreateNotes( i ) )
209 return;
212 SAL_INFO("sd.eppt", "call exportDocumentPost()");
213 exportPPTPost();
216 bool PPTWriterBase::InitSOIface()
218 while( true )
220 mXDrawPagesSupplier.set( mXModel, UNO_QUERY );
221 if ( !mXDrawPagesSupplier.is() )
222 break;
224 mXMasterPagesSupplier.set( mXModel, UNO_QUERY );
225 if ( !mXMasterPagesSupplier.is() )
226 break;
227 mXDrawPages = mXMasterPagesSupplier->getMasterPages();
228 if ( !mXDrawPages.is() )
229 break;
230 mnMasterPages = mXDrawPages->getCount();
231 mXDrawPages = mXDrawPagesSupplier->getDrawPages();
232 if( !mXDrawPages.is() )
233 break;
234 mnPages = mXDrawPages->getCount();
235 if ( !GetPageByIndex( 0, NORMAL ) )
236 break;
238 return true;
240 return false;
243 bool PPTWriterBase::GetPageByIndex( sal_uInt32 nIndex, PageType ePageType )
245 while( true )
247 if ( ePageType != meLatestPageType )
249 switch( ePageType )
251 case NORMAL :
252 case NOTICE :
254 mXDrawPages = mXDrawPagesSupplier->getDrawPages();
255 if( !mXDrawPages.is() )
256 return false;
258 break;
260 case MASTER :
262 mXDrawPages = mXMasterPagesSupplier->getMasterPages();
263 if( !mXDrawPages.is() )
264 return false;
266 break;
267 default:
268 break;
270 meLatestPageType = ePageType;
272 Any aAny( mXDrawPages->getByIndex( nIndex ) );
273 aAny >>= mXDrawPage;
274 if ( !mXDrawPage.is() )
275 break;
276 if ( ePageType == NOTICE )
278 Reference< XPresentationPage > aXPresentationPage( mXDrawPage, UNO_QUERY );
279 if ( !aXPresentationPage.is() )
280 break;
281 mXDrawPage = aXPresentationPage->getNotesPage();
282 if ( !mXDrawPage.is() )
283 break;
285 mXPagePropSet.set( mXDrawPage, UNO_QUERY );
286 if ( !mXPagePropSet.is() )
287 break;
289 if (GetPropertyValue( aAny, mXPagePropSet, "IsBackgroundDark" ) )
290 aAny >>= mbIsBackgroundDark;
292 mXShapes.set( mXDrawPage, UNO_QUERY );
293 if ( !mXShapes.is() )
294 break;
296 /* try to get the "real" background PropertySet. If the normal page is not supporting this property, it is
297 taken the property from the master */
298 bool bHasBackground = GetPropertyValue( aAny, mXPagePropSet, "Background", true );
299 if ( bHasBackground )
300 bHasBackground = ( aAny >>= mXBackgroundPropSet );
301 if ( !bHasBackground )
303 Reference< XMasterPageTarget > aXMasterPageTarget( mXDrawPage, UNO_QUERY );
304 if ( aXMasterPageTarget.is() )
306 Reference< XDrawPage > aXMasterDrawPage = aXMasterPageTarget->getMasterPage();
307 if ( aXMasterDrawPage.is() )
309 Reference< XPropertySet > aXMasterPagePropSet;
310 aXMasterPagePropSet.set( aXMasterDrawPage, UNO_QUERY );
311 if ( aXMasterPagePropSet.is() )
313 bool bBackground = GetPropertyValue( aAny, aXMasterPagePropSet, "Background" );
314 if ( bBackground )
316 aAny >>= mXBackgroundPropSet;
322 return true;
324 return false;
327 bool PPTWriterBase::CreateSlide( sal_uInt32 nPageNum )
329 Any aAny;
331 if ( !GetPageByIndex( nPageNum, NORMAL ) )
332 return false;
334 sal_uInt32 nMasterNum = GetMasterIndex( NORMAL );
335 SetCurrentStyleSheet( nMasterNum );
337 Reference< XPropertySet > aXBackgroundPropSet;
338 bool bHasBackground = GetPropertyValue( aAny, mXPagePropSet, "Background" );
339 if ( bHasBackground )
340 bHasBackground = ( aAny >>= aXBackgroundPropSet );
342 sal_uInt16 nMode = 7; // Bit 1: Follow master objects, Bit 2: Follow master scheme, Bit 3: Follow master background
343 if ( bHasBackground )
344 nMode &=~4;
346 /* sj: Don't know what's IsBackgroundVisible for, have to ask cl
347 if ( GetPropertyValue( aAny, mXPagePropSet, OUString( "IsBackgroundVisible" ) ) )
349 bool bBackgroundVisible;
350 if ( aAny >>= bBackgroundVisible )
352 if ( bBackgroundVisible )
353 nMode &= ~4;
357 if ( GetPropertyValue( aAny, mXPagePropSet, "IsBackgroundObjectsVisible" ) )
359 bool bBackgroundObjectsVisible = false;
360 if ( aAny >>= bBackgroundObjectsVisible )
362 if ( !bBackgroundObjectsVisible )
363 nMode &= ~1;
367 ImplWriteSlide( nPageNum, nMasterNum, nMode, bHasBackground, aXBackgroundPropSet );
369 return true;
372 bool PPTWriterBase::CreateNotes( sal_uInt32 nPageNum )
374 if ( !GetPageByIndex( nPageNum, NOTICE ) )
375 return false;
376 SetCurrentStyleSheet( GetMasterIndex( NORMAL ) );
378 ImplWriteNotes( nPageNum );
380 return true;
383 bool PPTWriterBase::CreateSlideMaster( sal_uInt32 nPageNum )
385 if ( !GetPageByIndex( nPageNum, MASTER ) )
386 return false;
387 SetCurrentStyleSheet( nPageNum );
389 if ( !ImplGetPropertyValue( mXPagePropSet, "Background" ) ) // load background shape
390 return false;
391 css::uno::Reference< css::beans::XPropertySet > aXBackgroundPropSet;
392 if ( !( mAny >>= aXBackgroundPropSet ) )
393 return false;
395 ImplWriteSlideMaster( nPageNum, aXBackgroundPropSet );
397 return true;
400 sal_Int32 PPTWriterBase::GetLayoutOffset( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet )
402 css::uno::Any aAny;
403 sal_Int32 nLayout = 20;
404 if ( GetPropertyValue( aAny, rXPropSet, "Layout", true ) )
405 aAny >>= nLayout;
407 SAL_INFO("sd.eppt", "GetLayoutOffset " << nLayout);
409 return nLayout;
412 sal_Int32 PPTWriterBase::GetLayoutOffsetFixed( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet )
414 sal_Int32 nLayout = GetLayoutOffset( rXPropSet );
416 if ( ( nLayout >= 21 ) && ( nLayout <= 26 ) ) // NOTES _> HANDOUT6
417 nLayout = 20;
418 if ( ( nLayout >= 27 ) && ( nLayout <= 30 ) ) // VERTICAL LAYOUT
419 nLayout -= 6;
420 else if ( nLayout > 30 )
421 nLayout = 20;
423 return nLayout;
426 PHLayout const & PPTWriterBase::GetLayout( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet )
428 return pPHLayout[ GetLayoutOffsetFixed( rXPropSet ) ];
431 PHLayout const & PPTWriterBase::GetLayout( sal_Int32 nOffset )
433 if( nOffset >= 0 && nOffset < EPP_LAYOUT_SIZE )
434 return pPHLayout[ nOffset ];
436 SAL_INFO("sd.eppt", "asked " << nOffset << " for layout outside of 0, " << EPP_LAYOUT_SIZE << " array scope");
438 return pPHLayout[ 0 ];
441 sal_uInt32 PPTWriterBase::GetMasterIndex( PageType ePageType )
443 sal_uInt32 nRetValue = 0;
444 css::uno::Reference< css::drawing::XMasterPageTarget >aXMasterPageTarget( mXDrawPage, css::uno::UNO_QUERY );
446 if ( aXMasterPageTarget.is() )
448 css::uno::Reference< css::drawing::XDrawPage >aXDrawPage = aXMasterPageTarget->getMasterPage();
449 if ( aXDrawPage.is() )
451 css::uno::Reference< css::beans::XPropertySet > aXPropertySet( aXDrawPage, css::uno::UNO_QUERY );
452 if ( aXPropertySet.is() )
454 if ( ImplGetPropertyValue( aXPropertySet, "Number" ) )
455 nRetValue |= *o3tl::doAccess<sal_Int16>(mAny);
456 if ( nRetValue & 0xffff ) // avoid overflow
457 nRetValue--;
461 if ( ePageType == NOTICE )
462 nRetValue += mnMasterPages;
463 return nRetValue;
466 void PPTWriterBase::SetCurrentStyleSheet( sal_uInt32 nPageNum )
468 if ( nPageNum >= maStyleSheetList.size() )
469 nPageNum = 0;
470 mpStyleSheet = maStyleSheetList[ nPageNum ].get();
473 bool PPTWriterBase::GetStyleSheets()
475 int nInstance, nLevel;
476 bool bRetValue = false;
477 sal_uInt32 nPageNum;
479 for ( nPageNum = 0; nPageNum < mnMasterPages; nPageNum++ )
481 Reference< XNamed >
482 aXNamed;
484 Reference< XNameAccess >
485 aXNameAccess;
487 Reference< XStyleFamiliesSupplier >
488 aXStyleFamiliesSupplier( mXModel, UNO_QUERY );
490 Reference< XPropertySet >
491 aXPropSet( mXModel, UNO_QUERY );
493 sal_uInt16 nDefaultTab = ( aXPropSet.is() && ImplGetPropertyValue( aXPropSet, "TabStop" ) )
494 ? static_cast<sal_uInt16>( *o3tl::doAccess<sal_Int32>(mAny) / 4.40972 )
495 : 1250;
497 maStyleSheetList.emplace_back( new PPTExStyleSheet( nDefaultTab, dynamic_cast<PPTExBulletProvider*>(this) ) );
498 SetCurrentStyleSheet( nPageNum );
499 if ( GetPageByIndex( nPageNum, MASTER ) )
500 aXNamed.set( mXDrawPage, UNO_QUERY );
502 if ( aXStyleFamiliesSupplier.is() )
503 aXNameAccess = aXStyleFamiliesSupplier->getStyleFamilies();
505 bRetValue = aXNamed.is() && aXNameAccess.is() && aXStyleFamiliesSupplier.is();
506 if ( bRetValue )
508 for ( nInstance = EPP_TEXTTYPE_Title; nInstance <= EPP_TEXTTYPE_CenterTitle; nInstance++ )
510 OUString aStyle;
511 OUString aFamily;
512 switch ( nInstance )
514 case EPP_TEXTTYPE_CenterTitle :
515 case EPP_TEXTTYPE_Title :
517 aStyle = "title";
518 aFamily = aXNamed->getName();
520 break;
521 case EPP_TEXTTYPE_Body :
523 aStyle = "outline1"; // SD_LT_SEPARATOR
524 aFamily = aXNamed->getName();
526 break;
527 case EPP_TEXTTYPE_Other :
529 aStyle = "standard";
530 aFamily = "graphics";
532 break;
533 case EPP_TEXTTYPE_CenterBody :
535 aStyle = "subtitle";
536 aFamily = aXNamed->getName();
538 break;
540 if ( !aStyle.isEmpty() && !aFamily.isEmpty() )
544 Reference< XNameAccess >xNameAccess;
545 if ( aXNameAccess->hasByName( aFamily ) )
547 Any aAny( aXNameAccess->getByName( aFamily ) );
548 xNameAccess.set(aAny, css::uno::UNO_QUERY);
549 if( xNameAccess.is() )
551 Reference< XNameAccess > aXFamily;
552 if ( aAny >>= aXFamily )
554 if ( aXFamily->hasByName( aStyle ) )
556 aAny = aXFamily->getByName( aStyle );
557 Reference< XStyle > xStyle(
558 aAny, css::uno::UNO_QUERY);
559 if( xStyle.is() )
561 Reference< XStyle > aXStyle;
562 aAny >>= aXStyle;
563 Reference< XPropertySet >
564 xPropSet( aXStyle, UNO_QUERY );
565 if( xPropSet.is() )
566 mpStyleSheet->SetStyleSheet( xPropSet, maFontCollection, nInstance, 0 );
567 for ( nLevel = 1; nLevel < 5; nLevel++ )
569 if ( nInstance == EPP_TEXTTYPE_Body )
571 sal_Unicode cTemp = aStyle[aStyle.getLength() - 1];
572 aStyle = aStyle.copy(0, aStyle.getLength() - 1) + OUStringLiteral1(++cTemp);
573 if ( aXFamily->hasByName( aStyle ) )
575 aXFamily->getByName( aStyle ) >>= xStyle;
576 if( xStyle.is() )
578 Reference< XPropertySet >
579 xPropertySet( xStyle, UNO_QUERY );
580 if ( xPropertySet.is() )
581 mpStyleSheet->SetStyleSheet( xPropertySet, maFontCollection, nInstance, nLevel );
585 else
586 mpStyleSheet->SetStyleSheet( xPropSet, maFontCollection, nInstance, nLevel );
594 catch( Exception& )
600 for ( ; nInstance <= EPP_TEXTTYPE_QuarterBody; nInstance++ )
606 return bRetValue;
609 bool PPTWriterBase::CreateMainNotes()
611 if ( !GetPageByIndex( 0, NOTICE ) )
612 return false;
613 SetCurrentStyleSheet( 0 );
615 css::uno::Reference< css::drawing::XMasterPageTarget > aXMasterPageTarget( mXDrawPage, css::uno::UNO_QUERY );
617 if ( !aXMasterPageTarget.is() )
618 return false;
620 mXDrawPage = aXMasterPageTarget->getMasterPage();
621 if ( !mXDrawPage.is() )
622 return false;
624 mXPropSet.set( mXDrawPage, css::uno::UNO_QUERY );
625 if ( !mXPropSet.is() )
626 return false;
628 mXShapes.set( mXDrawPage, css::uno::UNO_QUERY );
629 if ( !mXShapes.is() )
630 return false;
632 return ImplCreateMainNotes();
635 awt::Size PPTWriterBase::MapSize( const awt::Size& rSize )
637 Size aRetSize( OutputDevice::LogicToLogic( Size( rSize.Width, rSize.Height ), maMapModeSrc, maMapModeDest ) );
639 if ( !aRetSize.Width() )
640 aRetSize.AdjustWidth( 1 );
641 if ( !aRetSize.Height() )
642 aRetSize.AdjustHeight( 1 );
643 return awt::Size( aRetSize.Width(), aRetSize.Height() );
646 awt::Point PPTWriterBase::MapPoint( const awt::Point& rPoint )
648 Point aRet( OutputDevice::LogicToLogic( Point( rPoint.X, rPoint.Y ), maMapModeSrc, maMapModeDest ) );
649 return awt::Point( aRet.X(), aRet.Y() );
652 ::tools::Rectangle PPTWriterBase::MapRectangle( const awt::Rectangle& rRect )
654 css::awt::Point aPoint( rRect.X, rRect.Y );
655 css::awt::Size aSize( rRect.Width, rRect.Height );
656 css::awt::Point aP( MapPoint( aPoint ) );
657 css::awt::Size aS( MapSize( aSize ) );
658 return ::tools::Rectangle( Point( aP.X, aP.Y ), Size( aS.Width, aS.Height ) );
661 bool PPTWriterBase::GetShapeByIndex( sal_uInt32 nIndex, bool bGroup )
663 while(true)
665 if ( !bGroup || ( GetCurrentGroupLevel() == 0 ) )
667 Any aAny( mXShapes->getByIndex( nIndex ) );
668 aAny >>= mXShape;
670 else
672 Any aAny( GetCurrentGroupAccess()->getByIndex( GetCurrentGroupIndex() ) );
673 aAny >>= mXShape;
675 if ( !mXShape.is() )
676 break;
678 Any aAny( mXShape->queryInterface( cppu::UnoType<XPropertySet>::get()));
679 aAny >>= mXPropSet;
681 if ( !mXPropSet.is() )
682 break;
683 maPosition = MapPoint( mXShape->getPosition() );
684 maSize = MapSize( mXShape->getSize() );
685 maRect = ::tools::Rectangle( Point( maPosition.X, maPosition.Y ), Size( maSize.Width, maSize.Height ) );
687 OStringBuffer aTypeBuffer(OUStringToOString(
688 mXShape->getShapeType(), RTL_TEXTENCODING_UTF8));
689 // remove "com.sun.star."
690 aTypeBuffer.remove(0, RTL_CONSTASCII_LENGTH("com.sun.star."));
692 sal_Int32 nPos = aTypeBuffer.toString().indexOf("Shape");
693 aTypeBuffer.remove(nPos, RTL_CONSTASCII_LENGTH("Shape"));
694 mType = aTypeBuffer.makeStringAndClear();
696 mbPresObj = mbEmptyPresObj = false;
697 if ( ImplGetPropertyValue( "IsPresentationObject" ) )
698 mAny >>= mbPresObj;
700 if ( mbPresObj && ImplGetPropertyValue( "IsEmptyPresentationObject" ) )
701 mAny >>= mbEmptyPresObj;
703 mnAngle = ( PropValue::GetPropertyValue( aAny,
704 mXPropSet, "RotateAngle", true ) )
705 ? *o3tl::doAccess<sal_Int32>(aAny)
706 : 0;
708 return true;
710 return false;
713 sal_Int8 PPTWriterBase::GetTransition( sal_Int16 nTransitionType, sal_Int16 nTransitionSubtype, FadeEffect eEffect, sal_uInt8& nDirection )
715 sal_Int8 nPPTTransitionType = 0;
716 nDirection = 0;
718 switch( nTransitionType )
720 case TransitionType::FADE :
722 if ( nTransitionSubtype == TransitionSubType::CROSSFADE )
723 nPPTTransitionType = PPT_TRANSITION_TYPE_SMOOTHFADE;
724 else if ( nTransitionSubtype == TransitionSubType::FADEOVERCOLOR )
725 nPPTTransitionType = PPT_TRANSITION_TYPE_FADE;
727 break;
728 case TransitionType::PUSHWIPE :
730 if (nTransitionSubtype == TransitionSubType::COMBVERTICAL ||
731 nTransitionSubtype == TransitionSubType::COMBHORIZONTAL)
733 nPPTTransitionType = PPT_TRANSITION_TYPE_COMB;
735 else
737 nPPTTransitionType = PPT_TRANSITION_TYPE_PUSH;
739 switch (nTransitionSubtype)
741 case TransitionSubType::FROMRIGHT: nDirection = 0; break;
742 case TransitionSubType::FROMBOTTOM: nDirection = 1; break;
743 case TransitionSubType::FROMLEFT: nDirection = 2; break;
744 case TransitionSubType::FROMTOP: nDirection = 3; break;
745 case TransitionSubType::COMBHORIZONTAL: nDirection = 0; break;
746 case TransitionSubType::COMBVERTICAL: nDirection = 1; break;
749 break;
750 case TransitionType::PINWHEELWIPE :
752 nPPTTransitionType = PPT_TRANSITION_TYPE_WHEEL;
753 switch( nTransitionSubtype )
755 case TransitionSubType::ONEBLADE: nDirection = 1; break;
756 case TransitionSubType::TWOBLADEVERTICAL : nDirection = 2; break;
757 case TransitionSubType::THREEBLADE : nDirection = 3; break;
758 case TransitionSubType::FOURBLADE: nDirection = 4; break;
759 case TransitionSubType::EIGHTBLADE: nDirection = 8; break;
762 break;
763 case TransitionType::FANWIPE :
765 nPPTTransitionType = PPT_TRANSITION_TYPE_WEDGE;
767 break;
768 case TransitionType::ELLIPSEWIPE :
770 switch( nTransitionSubtype ) {
771 case TransitionSubType::VERTICAL:
772 case TransitionSubType::HORIZONTAL:
773 // no ellipse or oval in PPT or OOXML, fallback to circle
774 default:
775 nPPTTransitionType = PPT_TRANSITION_TYPE_CIRCLE;
778 break;
779 case TransitionType::FOURBOXWIPE :
781 nPPTTransitionType = PPT_TRANSITION_TYPE_PLUS;
783 break;
784 case TransitionType::IRISWIPE :
786 switch( nTransitionSubtype ) {
787 case TransitionSubType::RECTANGLE:
788 nPPTTransitionType = PPT_TRANSITION_TYPE_ZOOM;
789 nDirection = (eEffect == FadeEffect_FADE_FROM_CENTER) ? 0 : 1;
790 break;
791 default:
792 nPPTTransitionType = PPT_TRANSITION_TYPE_DIAMOND;
793 break;
796 break;
797 case TransitionType::ZOOM:
799 switch(nTransitionSubtype)
801 case TransitionSubType::ROTATEIN:
802 nPPTTransitionType = PPT_TRANSITION_TYPE_NEWSFLASH;
803 break;
804 default:
805 break;
808 break;
811 return nPPTTransitionType;
814 sal_Int8 PPTWriterBase::GetTransition( FadeEffect eEffect, sal_uInt8& nDirection )
816 sal_Int8 nPPTTransitionType = 0;
818 switch ( eEffect )
820 default :
821 case FadeEffect_RANDOM :
822 nPPTTransitionType = PPT_TRANSITION_TYPE_RANDOM;
823 break;
825 case FadeEffect_HORIZONTAL_STRIPES :
826 nDirection++;
827 [[fallthrough]];
828 case FadeEffect_VERTICAL_STRIPES :
829 nPPTTransitionType = PPT_TRANSITION_TYPE_BLINDS;
830 break;
832 case FadeEffect_VERTICAL_CHECKERBOARD :
833 nDirection++;
834 [[fallthrough]];
835 case FadeEffect_HORIZONTAL_CHECKERBOARD :
836 nPPTTransitionType = PPT_TRANSITION_TYPE_CHECKER;
837 break;
839 case FadeEffect_MOVE_FROM_UPPERLEFT :
840 nDirection++;
841 [[fallthrough]];
842 case FadeEffect_MOVE_FROM_UPPERRIGHT :
843 nDirection++;
844 [[fallthrough]];
845 case FadeEffect_MOVE_FROM_LOWERLEFT :
846 nDirection++;
847 [[fallthrough]];
848 case FadeEffect_MOVE_FROM_LOWERRIGHT :
849 nDirection++;
850 [[fallthrough]];
851 case FadeEffect_MOVE_FROM_TOP :
852 nDirection++;
853 [[fallthrough]];
854 case FadeEffect_MOVE_FROM_LEFT :
855 nDirection++;
856 [[fallthrough]];
857 case FadeEffect_MOVE_FROM_BOTTOM :
858 nDirection++;
859 [[fallthrough]];
860 case FadeEffect_MOVE_FROM_RIGHT :
861 nPPTTransitionType = PPT_TRANSITION_TYPE_COVER;
862 break;
864 case FadeEffect_DISSOLVE :
865 nPPTTransitionType = PPT_TRANSITION_TYPE_DISSOLVE;
866 break;
868 case FadeEffect_VERTICAL_LINES :
869 nDirection++;
870 [[fallthrough]];
871 case FadeEffect_HORIZONTAL_LINES :
872 nPPTTransitionType = PPT_TRANSITION_TYPE_RANDOM_BARS;
873 break;
875 case FadeEffect_CLOSE_HORIZONTAL :
876 nDirection++;
877 [[fallthrough]];
878 case FadeEffect_OPEN_HORIZONTAL :
879 nDirection++;
880 [[fallthrough]];
881 case FadeEffect_CLOSE_VERTICAL :
882 nDirection++;
883 [[fallthrough]];
884 case FadeEffect_OPEN_VERTICAL :
885 nPPTTransitionType = PPT_TRANSITION_TYPE_SPLIT;
886 break;
888 case FadeEffect_FADE_FROM_UPPERLEFT :
889 nDirection++;
890 [[fallthrough]];
891 case FadeEffect_FADE_FROM_UPPERRIGHT :
892 nDirection++;
893 [[fallthrough]];
894 case FadeEffect_FADE_FROM_LOWERLEFT :
895 nDirection++;
896 [[fallthrough]];
897 case FadeEffect_FADE_FROM_LOWERRIGHT :
898 nDirection += 4;
899 nPPTTransitionType = PPT_TRANSITION_TYPE_STRIPS;
900 break;
902 case FadeEffect_UNCOVER_TO_LOWERRIGHT :
903 nDirection++;
904 [[fallthrough]];
905 case FadeEffect_UNCOVER_TO_LOWERLEFT :
906 nDirection++;
907 [[fallthrough]];
908 case FadeEffect_UNCOVER_TO_UPPERRIGHT :
909 nDirection++;
910 [[fallthrough]];
911 case FadeEffect_UNCOVER_TO_UPPERLEFT :
912 nDirection++;
913 [[fallthrough]];
914 case FadeEffect_UNCOVER_TO_BOTTOM :
915 nDirection++;
916 [[fallthrough]];
917 case FadeEffect_UNCOVER_TO_RIGHT :
918 nDirection++;
919 [[fallthrough]];
920 case FadeEffect_UNCOVER_TO_TOP :
921 nDirection++;
922 [[fallthrough]];
923 case FadeEffect_UNCOVER_TO_LEFT :
924 nPPTTransitionType = PPT_TRANSITION_TYPE_PULL;
925 break;
927 case FadeEffect_FADE_FROM_TOP :
928 nDirection++;
929 [[fallthrough]];
930 case FadeEffect_FADE_FROM_LEFT :
931 nDirection++;
932 [[fallthrough]];
933 case FadeEffect_FADE_FROM_BOTTOM :
934 nDirection++;
935 [[fallthrough]];
936 case FadeEffect_FADE_FROM_RIGHT :
937 nPPTTransitionType = PPT_TRANSITION_TYPE_WIPE;
938 break;
940 case FadeEffect_ROLL_FROM_TOP :
941 nDirection++;
942 [[fallthrough]];
943 case FadeEffect_ROLL_FROM_LEFT :
944 nDirection++;
945 [[fallthrough]];
946 case FadeEffect_ROLL_FROM_BOTTOM :
947 nDirection++;
948 [[fallthrough]];
949 case FadeEffect_ROLL_FROM_RIGHT :
950 nPPTTransitionType = PPT_TRANSITION_TYPE_WIPE;
951 break;
953 case FadeEffect_FADE_TO_CENTER :
954 nDirection++;
955 [[fallthrough]];
956 case FadeEffect_FADE_FROM_CENTER :
957 nPPTTransitionType = PPT_TRANSITION_TYPE_ZOOM;
958 break;
960 case FadeEffect_NONE :
961 nDirection = 2;
962 break;
965 return nPPTTransitionType;
968 bool PPTWriterBase::ContainsOtherShapeThanPlaceholders()
970 sal_uInt32 nShapes = mXShapes->getCount();
971 bool bOtherThanPlaceHolders = false;
973 if ( nShapes )
974 for ( sal_uInt32 nIndex = 0; ( nIndex < nShapes ) && !bOtherThanPlaceHolders; nIndex++ )
976 if ( GetShapeByIndex( nIndex, false ) && mType != "drawing.Page" )
978 if( mType == "presentation.Page" || mType == "presentation.Notes" )
980 Reference< XSimpleText > rXText( mXShape, UNO_QUERY );
982 if( rXText.is() && !rXText->getString().isEmpty() )
983 bOtherThanPlaceHolders = true;
985 else
986 bOtherThanPlaceHolders = true;
988 SAL_INFO("sd.eppt", "mType == " << mType);
991 return bOtherThanPlaceHolders;
994 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */