cid#1607171 Data race condition
[LibreOffice.git] / sd / source / filter / eppt / pptx-epptbase.cxx
blobc548ff09f1d91eff99611c310ed1544899343f63
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 <rtl/ustrbuf.hxx>
29 #include <sal/log.hxx>
30 #include <tools/UnitConversion.hxx>
31 #include <com/sun/star/awt/Rectangle.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
34 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
35 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
36 #include <com/sun/star/drawing/XDrawPages.hpp>
37 #include <com/sun/star/animations/TransitionType.hpp>
38 #include <com/sun/star/animations/TransitionSubType.hpp>
39 #include <com/sun/star/awt/FontFamily.hpp>
40 #include <com/sun/star/awt/FontPitch.hpp>
41 #include <com/sun/star/container/XNamed.hpp>
42 #include <com/sun/star/container/XNameAccess.hpp>
43 #include <com/sun/star/frame/XModel.hpp>
44 #include <com/sun/star/presentation/XPresentationPage.hpp>
45 #include <com/sun/star/text/XSimpleText.hpp>
46 #include <com/sun/star/style/XStyle.hpp>
47 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
48 #include <com/sun/star/task/XStatusIndicator.hpp>
51 using namespace com::sun::star;
53 using namespace ::com::sun::star::animations;
54 using namespace ::com::sun::star::awt::FontFamily;
55 using namespace ::com::sun::star::awt::FontPitch;
56 using namespace ::com::sun::star::presentation;
58 using ::com::sun::star::beans::XPropertySet;
59 using ::com::sun::star::container::XNameAccess;
60 using ::com::sun::star::container::XNamed;
61 using ::com::sun::star::drawing::XMasterPageTarget;
62 using ::com::sun::star::drawing::XDrawPage;
63 using ::com::sun::star::frame::XModel;
64 using ::com::sun::star::style::XStyleFamiliesSupplier;
65 using ::com::sun::star::style::XStyle;
66 using ::com::sun::star::task::XStatusIndicator;
67 using ::com::sun::star::text::XSimpleText;
68 using ::com::sun::star::uno::Any;
69 using ::com::sun::star::uno::Exception;
70 using ::com::sun::star::uno::Reference;
71 using ::com::sun::star::uno::UNO_QUERY;
73 PHLayout const pPHLayout[] =
75 { EppLayout::TITLESLIDE, { 0x0d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x10, true, true, false },
76 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, true, true, false },
77 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x0d, 0x0e, true, true, false },
78 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, true, true, true },
79 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x0d, 0x0e, true, true, false },
80 { EppLayout::BLANKSLIDE, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, false, false, false },
81 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x0e, true, true, false },
82 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x14, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x0d, 0x0e, true, true, false },
83 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x15, 0x0d, 0x0e, true, false, false },
84 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x16, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x0e, true, true, false },
85 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
86 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, false, false },
87 { EppLayout::RIGHTCOLUMN2ROWS, { 0x0d, 0x0e, 0x13, 0x13, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
88 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
89 { EppLayout::TWOROWSANDTITLE, { 0x0d, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
90 { EppLayout::LEFTCOLUMN2ROWS, { 0x0d, 0x13, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
91 { EppLayout::TOPROW2COLUMN, { 0x0d, 0x13, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
92 { EppLayout::TWOROWSANDTITLE, { 0x0d, 0x0e, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
93 { EppLayout::FOUROBJECTS, { 0x0d, 0x13, 0x13, 0x13, 0x13, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, false, false },
94 { EppLayout::ONLYTITLE, { 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, true, false, false },
95 { EppLayout::BLANKSLIDE, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, false, false, false },
96 { EppLayout::TITLERIGHT2BODIESLEFT, { 0x11, 0x12, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x11, 0x12, true, true, false },
97 { EppLayout::TITLERIGHTBODYLEFT, { 0x11, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x11, 0x12, true, true, false },
98 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x12, true, true, false },
99 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x16, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x12, true, true, false }
102 PPTWriterBase::PPTWriterBase()
103 : mbStatusIndicator(false)
104 , mbPresObj(false)
105 , mbEmptyPresObj(false)
106 , mbIsBackgroundDark(false)
107 , mnAngle(0)
108 , mnPages(0)
109 , mnMasterPages(0)
110 , maFraction(1, 576)
111 , maMapModeSrc(MapUnit::Map100thMM)
112 , maMapModeDest(MapUnit::MapInch, Point(), maFraction, maFraction)
113 , meLatestPageType(NORMAL)
114 , mpStyleSheet(nullptr)
116 SAL_INFO("sd.eppt", "PPTWriterBase::PPTWriterBase()");
119 PPTWriterBase::PPTWriterBase( const Reference< XModel > & rXModel,
120 const Reference< XStatusIndicator > & rXStatInd )
121 : mXModel(rXModel)
122 , mXStatusIndicator(rXStatInd)
123 , mbStatusIndicator(false)
124 , mbPresObj(false)
125 , mbEmptyPresObj(false)
126 , mbIsBackgroundDark(false)
127 , mnAngle(0)
128 , mnPages(0)
129 , mnMasterPages(0)
130 , maFraction(1, 576)
131 , maMapModeSrc(MapUnit::Map100thMM)
132 , maMapModeDest(MapUnit::MapInch, Point(), maFraction, maFraction)
133 , meLatestPageType (NORMAL)
134 , mpStyleSheet(nullptr)
138 PPTWriterBase::~PPTWriterBase()
140 // Possibly unnecessary sanity check for mXStatusIndicator.is().
141 // In 3.3 we had a bug report of a crash where it was null,
142 // https://bugzilla.novell.com/show_bug.cgi?id=694119 (non-public,
143 // bug report, sorry).
144 if ( mbStatusIndicator && mXStatusIndicator.is() )
145 mXStatusIndicator->end();
148 void PPTWriterBase::exportPPT( const std::vector< css::beans::PropertyValue >& rMediaData )
150 if ( !InitSOIface() )
151 return;
153 FontCollectionEntry aDefaultFontDesc( u"Times New Roman"_ustr,
154 ROMAN,
155 awt::FontPitch::VARIABLE,
156 RTL_TEXTENCODING_MS_1252 );
157 maFontCollection.GetId( aDefaultFontDesc ); // default is always times new roman
159 if ( !GetPageByIndex( 0, NOTICE ) )
160 return;
162 sal_Int32 nWidth = 21000;
163 if ( ImplGetPropertyValue( mXPagePropSet, u"Width"_ustr ) )
164 mAny >>= nWidth;
165 sal_Int32 nHeight = 29700;
166 if ( ImplGetPropertyValue( mXPagePropSet, u"Height"_ustr ) )
167 mAny >>= nHeight;
169 maNotesPageSize = MapSize( awt::Size( nWidth, nHeight ) );
171 if ( !GetPageByIndex( 0, MASTER ) )
172 return;
174 nWidth = 28000;
175 if ( ImplGetPropertyValue( mXPagePropSet, u"Width"_ustr ) )
176 mAny >>= nWidth;
177 nHeight = 21000;
178 if ( ImplGetPropertyValue( mXPagePropSet, u"Height"_ustr ) )
179 mAny >>= nHeight;
180 maDestPageSize = MapSize( awt::Size( nWidth, nHeight ) );
181 maPageSize = awt::Size(nWidth, nHeight);
183 SAL_INFO("sd.eppt", "call exportDocumentPre()");
184 exportPPTPre(rMediaData);
186 if ( !GetStyleSheets() )
187 return;
189 if ( !ImplCreateDocument() )
190 return;
192 sal_uInt32 i;
194 for ( i = 0; i < mnMasterPages; i++ )
196 if ( !CreateSlideMaster( i ) )
197 return;
199 if ( !CreateMainNotes() )
200 return;
202 for ( i = 0; i < mnPages; i++ )
204 SAL_INFO("sd.eppt", "call ImplCreateSlide( " << i << " )");
205 if ( !CreateSlide( i ) )
206 return;
209 for ( i = 0; i < mnPages; i++ )
211 if ( !CreateNotes( i ) )
212 return;
215 SAL_INFO("sd.eppt", "call exportDocumentPost()");
216 exportPPTPost();
219 bool PPTWriterBase::InitSOIface()
221 while( true )
223 mXDrawPagesSupplier.set( mXModel, UNO_QUERY );
224 if ( !mXDrawPagesSupplier.is() )
225 break;
227 mXMasterPagesSupplier.set( mXModel, UNO_QUERY );
228 if ( !mXMasterPagesSupplier.is() )
229 break;
230 mXDrawPages = mXMasterPagesSupplier->getMasterPages();
231 if ( !mXDrawPages.is() )
232 break;
233 mnMasterPages = mXDrawPages->getCount();
234 mXDrawPages = mXDrawPagesSupplier->getDrawPages();
235 if( !mXDrawPages.is() )
236 break;
237 mnPages = mXDrawPages->getCount();
238 if ( !GetPageByIndex( 0, NORMAL ) )
239 break;
241 return true;
243 return false;
246 bool PPTWriterBase::GetPageByIndex( sal_uInt32 nIndex, PageType ePageType )
248 while( true )
250 if ( ePageType != meLatestPageType )
252 switch( ePageType )
254 case NORMAL :
255 case NOTICE :
257 mXDrawPages = mXDrawPagesSupplier->getDrawPages();
258 if( !mXDrawPages.is() )
259 return false;
261 break;
263 case MASTER :
265 mXDrawPages = mXMasterPagesSupplier->getMasterPages();
266 if( !mXDrawPages.is() )
267 return false;
269 break;
270 default:
271 break;
273 meLatestPageType = ePageType;
275 Any aAny( mXDrawPages->getByIndex( nIndex ) );
276 aAny >>= mXDrawPage;
277 if ( !mXDrawPage.is() )
278 break;
279 if ( ePageType == NOTICE )
281 Reference< XPresentationPage > aXPresentationPage( mXDrawPage, UNO_QUERY );
282 if ( !aXPresentationPage.is() )
283 break;
284 mXDrawPage = aXPresentationPage->getNotesPage();
285 if ( !mXDrawPage.is() )
286 break;
288 mXPagePropSet.set( mXDrawPage, UNO_QUERY );
289 if ( !mXPagePropSet.is() )
290 break;
292 if (GetPropertyValue( aAny, mXPagePropSet, u"IsBackgroundDark"_ustr ) )
293 aAny >>= mbIsBackgroundDark;
295 mXShapes = mXDrawPage;
296 if ( !mXShapes.is() )
297 break;
299 /* try to get the "real" background PropertySet. If the normal page is not supporting this property, it is
300 taken the property from the master */
301 bool bHasBackground = GetPropertyValue( aAny, mXPagePropSet, u"Background"_ustr, true );
302 if ( bHasBackground )
303 bHasBackground = ( aAny >>= mXBackgroundPropSet );
304 if ( !bHasBackground )
306 Reference< XMasterPageTarget > aXMasterPageTarget( mXDrawPage, UNO_QUERY );
307 if ( aXMasterPageTarget.is() )
309 Reference< XDrawPage > aXMasterDrawPage = aXMasterPageTarget->getMasterPage();
310 if ( aXMasterDrawPage.is() )
312 Reference< XPropertySet > aXMasterPagePropSet;
313 aXMasterPagePropSet.set( aXMasterDrawPage, UNO_QUERY );
314 if ( aXMasterPagePropSet.is() )
316 bool bBackground = GetPropertyValue( aAny, aXMasterPagePropSet, u"Background"_ustr );
317 if ( bBackground )
319 aAny >>= mXBackgroundPropSet;
325 return true;
327 return false;
330 bool PPTWriterBase::CreateSlide( sal_uInt32 nPageNum )
332 Any aAny;
334 if ( !GetPageByIndex( nPageNum, NORMAL ) )
335 return false;
337 sal_uInt32 nMasterNum = GetMasterIndex( NORMAL );
338 SetCurrentStyleSheet( nMasterNum );
340 Reference< XPropertySet > aXBackgroundPropSet;
341 bool bHasBackground = GetPropertyValue( aAny, mXPagePropSet, u"Background"_ustr );
342 if ( bHasBackground )
343 bHasBackground = ( aAny >>= aXBackgroundPropSet );
345 sal_uInt16 nMode = 7; // Bit 1: Follow master objects, Bit 2: Follow master scheme, Bit 3: Follow master background
346 if ( bHasBackground )
347 nMode &=~4;
349 /* sj: Don't know what's IsBackgroundVisible for, have to ask cl
350 if ( GetPropertyValue( aAny, mXPagePropSet, OUString( "IsBackgroundVisible" ) ) )
352 bool bBackgroundVisible;
353 if ( aAny >>= bBackgroundVisible )
355 if ( bBackgroundVisible )
356 nMode &= ~4;
360 if ( GetPropertyValue( aAny, mXPagePropSet, u"IsBackgroundObjectsVisible"_ustr ) )
362 bool bBackgroundObjectsVisible = false;
363 if ( aAny >>= bBackgroundObjectsVisible )
365 if ( !bBackgroundObjectsVisible )
366 nMode &= ~1;
370 ImplWriteSlide( nPageNum, nMasterNum, nMode, bHasBackground, aXBackgroundPropSet );
372 return true;
375 bool PPTWriterBase::CreateNotes( sal_uInt32 nPageNum )
377 if ( !GetPageByIndex( nPageNum, NOTICE ) )
378 return false;
379 SetCurrentStyleSheet( GetMasterIndex( NORMAL ) );
381 ImplWriteNotes( nPageNum );
383 return true;
386 bool PPTWriterBase::CreateSlideMaster( sal_uInt32 nPageNum )
388 if ( !GetPageByIndex( nPageNum, MASTER ) )
389 return false;
390 SetCurrentStyleSheet( nPageNum );
392 css::uno::Reference< css::beans::XPropertySet > aXBackgroundPropSet;
393 if (ImplGetPropertyValue(mXPagePropSet, u"Background"_ustr)) // load background shape
394 mAny >>= aXBackgroundPropSet;
396 ImplWriteSlideMaster( nPageNum, aXBackgroundPropSet );
398 return true;
401 sal_Int32 PPTWriterBase::GetLayoutOffset( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet )
403 css::uno::Any aAny;
404 sal_Int32 nLayout = 20;
405 if ( GetPropertyValue( aAny, rXPropSet, u"Layout"_ustr, true ) )
406 aAny >>= nLayout;
408 SAL_INFO("sd.eppt", "GetLayoutOffset " << nLayout);
410 return nLayout;
413 sal_Int32 PPTWriterBase::GetLayoutOffsetFixed( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet )
415 sal_Int32 nLayout = GetLayoutOffset( rXPropSet );
417 if ( ( nLayout >= 21 ) && ( nLayout <= 26 ) ) // NOTES _> HANDOUT6
418 nLayout = 20;
419 if ( ( nLayout >= 27 ) && ( nLayout <= 30 ) ) // VERTICAL LAYOUT
420 nLayout -= 6;
421 else if ( nLayout > 30 )
422 nLayout = 20;
424 return nLayout;
427 PHLayout const & PPTWriterBase::GetLayout( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet )
429 return pPHLayout[ GetLayoutOffsetFixed( rXPropSet ) ];
432 PHLayout const & PPTWriterBase::GetLayout( sal_Int32 nOffset )
434 if( nOffset >= 0 && nOffset < EPP_LAYOUT_SIZE )
435 return pPHLayout[ nOffset ];
437 SAL_INFO("sd.eppt", "asked " << nOffset << " for layout outside of 0, " << EPP_LAYOUT_SIZE << " array scope");
439 return pPHLayout[ 0 ];
442 sal_uInt32 PPTWriterBase::GetMasterIndex( PageType ePageType )
444 sal_uInt32 nRetValue = 0;
445 css::uno::Reference< css::drawing::XMasterPageTarget >aXMasterPageTarget( mXDrawPage, css::uno::UNO_QUERY );
447 if ( aXMasterPageTarget.is() )
449 css::uno::Reference< css::drawing::XDrawPage >aXDrawPage = aXMasterPageTarget->getMasterPage();
450 if ( aXDrawPage.is() )
452 css::uno::Reference< css::beans::XPropertySet > aXPropertySet( aXDrawPage, css::uno::UNO_QUERY );
453 if ( aXPropertySet.is() )
455 if ( ImplGetPropertyValue( aXPropertySet, u"Number"_ustr ) )
456 nRetValue |= *o3tl::doAccess<sal_Int16>(mAny);
457 if ( nRetValue & 0xffff ) // avoid overflow
458 nRetValue--;
462 if ( ePageType == NOTICE )
463 nRetValue += mnMasterPages;
464 return nRetValue;
467 void PPTWriterBase::SetCurrentStyleSheet( sal_uInt32 nPageNum )
469 if ( nPageNum >= maStyleSheetList.size() )
470 nPageNum = 0;
471 mpStyleSheet = maStyleSheetList[ nPageNum ].get();
474 bool PPTWriterBase::GetStyleSheets()
476 int nInstance, nLevel;
477 bool bRetValue = false;
478 sal_uInt32 nPageNum;
480 for ( nPageNum = 0; nPageNum < mnMasterPages; nPageNum++ )
482 Reference< XNamed >
483 aXNamed;
485 Reference< XNameAccess >
486 aXNameAccess;
488 Reference< XStyleFamiliesSupplier >
489 aXStyleFamiliesSupplier( mXModel, UNO_QUERY );
491 Reference< XPropertySet >
492 aXPropSet( mXModel, UNO_QUERY );
494 sal_uInt16 nDefaultTab = ( aXPropSet.is() && ImplGetPropertyValue( aXPropSet, u"TabStop"_ustr ) )
495 ? static_cast<sal_uInt16>( convertMm100ToMasterUnit(*o3tl::doAccess<sal_Int32>(mAny)) )
496 : 1250;
498 maStyleSheetList.emplace_back( new PPTExStyleSheet( nDefaultTab, dynamic_cast<PPTExBulletProvider*>(this) ) );
499 SetCurrentStyleSheet( nPageNum );
500 if ( GetPageByIndex( nPageNum, MASTER ) )
501 aXNamed.set( mXDrawPage, UNO_QUERY );
503 if ( aXStyleFamiliesSupplier.is() )
504 aXNameAccess = aXStyleFamiliesSupplier->getStyleFamilies();
506 bRetValue = aXNamed.is() && aXNameAccess.is() && aXStyleFamiliesSupplier.is();
507 if ( bRetValue )
509 for ( nInstance = EPP_TEXTTYPE_Title; nInstance <= EPP_TEXTTYPE_CenterTitle; nInstance++ )
511 OUString aStyle;
512 OUString aFamily;
513 switch ( nInstance )
515 case EPP_TEXTTYPE_CenterTitle :
516 case EPP_TEXTTYPE_Title :
518 aStyle = "title";
519 aFamily = aXNamed->getName();
521 break;
522 case EPP_TEXTTYPE_Body :
524 aStyle = "outline1"; // SD_LT_SEPARATOR
525 aFamily = aXNamed->getName();
527 break;
528 case EPP_TEXTTYPE_Other :
530 aStyle = "standard";
531 aFamily = "graphics";
533 break;
534 case EPP_TEXTTYPE_CenterBody :
536 aStyle = "subtitle";
537 aFamily = aXNamed->getName();
539 break;
541 if ( !aStyle.isEmpty() && !aFamily.isEmpty() )
545 Reference< XNameAccess >xNameAccess;
546 if ( aXNameAccess->hasByName( aFamily ) )
548 Any aAny( aXNameAccess->getByName( aFamily ) );
549 xNameAccess.set(aAny, css::uno::UNO_QUERY);
550 if( xNameAccess.is() )
552 Reference< XNameAccess > aXFamily;
553 if ( aAny >>= aXFamily )
555 if ( aXFamily->hasByName( aStyle ) )
557 aAny = aXFamily->getByName( aStyle );
558 Reference< XStyle > xStyle(
559 aAny, css::uno::UNO_QUERY);
560 if( xStyle.is() )
562 Reference< XStyle > aXStyle;
563 aAny >>= aXStyle;
564 Reference< XPropertySet >
565 xPropSet( aXStyle, UNO_QUERY );
566 if( xPropSet.is() )
567 mpStyleSheet->SetStyleSheet( xPropSet, maFontCollection, nInstance, 0 );
568 for ( nLevel = 1; nLevel < 5; nLevel++ )
570 if ( nInstance == EPP_TEXTTYPE_Body )
572 sal_Unicode cTemp = aStyle[aStyle.getLength() - 1];
573 aStyle = aStyle.subView(0, aStyle.getLength() - 1) + OUStringChar(++cTemp);
574 if ( aXFamily->hasByName( aStyle ) )
576 aXFamily->getByName( aStyle ) >>= xStyle;
577 if( xStyle.is() )
579 Reference< XPropertySet >
580 xPropertySet( xStyle, UNO_QUERY );
581 if ( xPropertySet.is() )
582 mpStyleSheet->SetStyleSheet( xPropertySet, maFontCollection, nInstance, nLevel );
586 else
587 mpStyleSheet->SetStyleSheet( xPropSet, maFontCollection, nInstance, nLevel );
595 catch( Exception& )
601 for ( ; nInstance <= EPP_TEXTTYPE_QuarterBody; nInstance++ )
607 return bRetValue;
610 bool PPTWriterBase::CreateMainNotes()
612 if ( !GetPageByIndex( 0, NOTICE ) )
613 return false;
614 SetCurrentStyleSheet( 0 );
616 css::uno::Reference< css::drawing::XMasterPageTarget > aXMasterPageTarget( mXDrawPage, css::uno::UNO_QUERY );
618 if ( !aXMasterPageTarget.is() )
619 return false;
621 mXDrawPage = aXMasterPageTarget->getMasterPage();
622 if ( !mXDrawPage.is() )
623 return false;
625 mXPropSet.set( mXDrawPage, css::uno::UNO_QUERY );
626 if ( !mXPropSet.is() )
627 return false;
629 mXShapes = mXDrawPage;
630 if ( !mXShapes.is() )
631 return false;
633 return ImplCreateMainNotes();
636 awt::Size PPTWriterBase::MapSize( const awt::Size& rSize )
638 Size aRetSize( OutputDevice::LogicToLogic( Size( rSize.Width, rSize.Height ), maMapModeSrc, maMapModeDest ) );
640 if ( !aRetSize.Width() )
641 aRetSize.AdjustWidth( 1 );
642 if ( !aRetSize.Height() )
643 aRetSize.AdjustHeight( 1 );
644 return awt::Size( aRetSize.Width(), aRetSize.Height() );
647 awt::Point PPTWriterBase::MapPoint( const awt::Point& rPoint )
649 Point aRet( OutputDevice::LogicToLogic( Point( rPoint.X, rPoint.Y ), maMapModeSrc, maMapModeDest ) );
650 return awt::Point( aRet.X(), aRet.Y() );
653 ::tools::Rectangle PPTWriterBase::MapRectangle( const awt::Rectangle& rRect )
655 css::awt::Point aPoint( rRect.X, rRect.Y );
656 css::awt::Size aSize( rRect.Width, rRect.Height );
657 css::awt::Point aP( MapPoint( aPoint ) );
658 css::awt::Size aS( MapSize( aSize ) );
659 return ::tools::Rectangle( Point( aP.X, aP.Y ), Size( aS.Width, aS.Height ) );
662 bool PPTWriterBase::GetShapeByIndex( sal_uInt32 nIndex, bool bGroup )
664 while(true)
666 if ( !bGroup || ( GetCurrentGroupLevel() == 0 ) )
668 Any aAny( mXShapes->getByIndex( nIndex ) );
669 aAny >>= mXShape;
671 else
673 Any aAny( GetCurrentGroupAccess()->getByIndex( GetCurrentGroupIndex() ) );
674 aAny >>= mXShape;
676 if ( !mXShape.is() )
677 break;
679 Any aAny( mXShape->queryInterface( cppu::UnoType<XPropertySet>::get()));
680 aAny >>= mXPropSet;
682 if ( !mXPropSet.is() )
683 break;
684 maPosition = MapPoint( mXShape->getPosition() );
685 maSize = MapSize( mXShape->getSize() );
686 maRect = ::tools::Rectangle( Point( maPosition.X, maPosition.Y ), Size( maSize.Width, maSize.Height ) );
688 OStringBuffer aTypeBuffer(OUStringToOString(
689 mXShape->getShapeType(), RTL_TEXTENCODING_UTF8));
690 // remove "com.sun.star."
691 aTypeBuffer.remove(0, RTL_CONSTASCII_LENGTH("com.sun.star."));
693 sal_Int32 nPos = aTypeBuffer.toString().indexOf("Shape");
694 aTypeBuffer.remove(nPos, RTL_CONSTASCII_LENGTH("Shape"));
695 mType = aTypeBuffer.makeStringAndClear();
697 mbPresObj = mbEmptyPresObj = false;
698 if ( ImplGetPropertyValue( u"IsPresentationObject"_ustr ) )
699 mAny >>= mbPresObj;
701 if ( mbPresObj && ImplGetPropertyValue( u"IsEmptyPresentationObject"_ustr ) )
702 mAny >>= mbEmptyPresObj;
704 mnAngle = ( PropValue::GetPropertyValue( aAny,
705 mXPropSet, u"RotateAngle"_ustr, true ) )
706 ? *o3tl::doAccess<sal_Int32>(aAny)
707 : 0;
709 return true;
711 return false;
714 sal_Int8 PPTWriterBase::GetTransition( sal_Int16 nTransitionType, sal_Int16 nTransitionSubtype, FadeEffect eEffect,
715 sal_Int32 nTransitionFadeColor, sal_uInt8& nDirection )
717 sal_Int8 nPPTTransitionType = 0;
718 nDirection = 0;
720 switch( nTransitionType )
722 case TransitionType::FADE :
724 if ( nTransitionSubtype == TransitionSubType::CROSSFADE )
725 nPPTTransitionType = PPT_TRANSITION_TYPE_SMOOTHFADE;
726 else if ( nTransitionSubtype == TransitionSubType::FADEOVERCOLOR )
728 if( nTransitionFadeColor == static_cast<sal_Int32>(COL_WHITE) )
729 nPPTTransitionType = PPT_TRANSITION_TYPE_FLASH;
730 else
731 nPPTTransitionType = PPT_TRANSITION_TYPE_FADE;
734 break;
735 case TransitionType::PUSHWIPE :
737 if (nTransitionSubtype == TransitionSubType::COMBVERTICAL ||
738 nTransitionSubtype == TransitionSubType::COMBHORIZONTAL)
740 nPPTTransitionType = PPT_TRANSITION_TYPE_COMB;
742 else
744 nPPTTransitionType = PPT_TRANSITION_TYPE_PUSH;
746 switch (nTransitionSubtype)
748 case TransitionSubType::FROMRIGHT: nDirection = 0; break;
749 case TransitionSubType::FROMBOTTOM: nDirection = 1; break;
750 case TransitionSubType::FROMLEFT: nDirection = 2; break;
751 case TransitionSubType::FROMTOP: nDirection = 3; break;
752 case TransitionSubType::COMBHORIZONTAL: nDirection = 0; break;
753 case TransitionSubType::COMBVERTICAL: nDirection = 1; break;
756 break;
757 case TransitionType::PINWHEELWIPE :
759 nPPTTransitionType = PPT_TRANSITION_TYPE_WHEEL;
760 switch( nTransitionSubtype )
762 case TransitionSubType::ONEBLADE: nDirection = 1; break;
763 case TransitionSubType::TWOBLADEVERTICAL : nDirection = 2; break;
764 case TransitionSubType::THREEBLADE : nDirection = 3; break;
765 case TransitionSubType::FOURBLADE: nDirection = 4; break;
766 case TransitionSubType::EIGHTBLADE: nDirection = 8; break;
769 break;
770 case TransitionType::FANWIPE :
772 nPPTTransitionType = PPT_TRANSITION_TYPE_WEDGE;
774 break;
775 case TransitionType::ELLIPSEWIPE :
777 switch( nTransitionSubtype ) {
778 case TransitionSubType::VERTICAL:
779 case TransitionSubType::HORIZONTAL:
780 // no ellipse or oval in PPT or OOXML, fallback to circle
781 default:
782 nPPTTransitionType = PPT_TRANSITION_TYPE_CIRCLE;
785 break;
786 case TransitionType::FOURBOXWIPE :
788 nPPTTransitionType = PPT_TRANSITION_TYPE_PLUS;
790 break;
791 case TransitionType::IRISWIPE :
793 switch( nTransitionSubtype ) {
794 case TransitionSubType::RECTANGLE:
795 nPPTTransitionType = PPT_TRANSITION_TYPE_ZOOM;
796 nDirection = (eEffect == FadeEffect_FADE_FROM_CENTER) ? 0 : 1;
797 break;
798 default:
799 nPPTTransitionType = PPT_TRANSITION_TYPE_DIAMOND;
800 break;
803 break;
804 case TransitionType::ZOOM:
806 switch(nTransitionSubtype)
808 case TransitionSubType::ROTATEIN:
809 nPPTTransitionType = PPT_TRANSITION_TYPE_NEWSFLASH;
810 break;
811 default:
812 break;
815 break;
818 return nPPTTransitionType;
821 sal_Int8 PPTWriterBase::GetTransition( FadeEffect eEffect, sal_uInt8& nDirection )
823 sal_Int8 nPPTTransitionType = 0;
825 switch ( eEffect )
827 default :
828 case FadeEffect_RANDOM :
829 nPPTTransitionType = PPT_TRANSITION_TYPE_RANDOM;
830 break;
832 case FadeEffect_HORIZONTAL_STRIPES :
833 nDirection++;
834 [[fallthrough]];
835 case FadeEffect_VERTICAL_STRIPES :
836 nPPTTransitionType = PPT_TRANSITION_TYPE_BLINDS;
837 break;
839 case FadeEffect_VERTICAL_CHECKERBOARD :
840 nDirection++;
841 [[fallthrough]];
842 case FadeEffect_HORIZONTAL_CHECKERBOARD :
843 nPPTTransitionType = PPT_TRANSITION_TYPE_CHECKER;
844 break;
846 case FadeEffect_MOVE_FROM_UPPERLEFT :
847 nDirection++;
848 [[fallthrough]];
849 case FadeEffect_MOVE_FROM_UPPERRIGHT :
850 nDirection++;
851 [[fallthrough]];
852 case FadeEffect_MOVE_FROM_LOWERLEFT :
853 nDirection++;
854 [[fallthrough]];
855 case FadeEffect_MOVE_FROM_LOWERRIGHT :
856 nDirection++;
857 [[fallthrough]];
858 case FadeEffect_MOVE_FROM_TOP :
859 nDirection++;
860 [[fallthrough]];
861 case FadeEffect_MOVE_FROM_LEFT :
862 nDirection++;
863 [[fallthrough]];
864 case FadeEffect_MOVE_FROM_BOTTOM :
865 nDirection++;
866 [[fallthrough]];
867 case FadeEffect_MOVE_FROM_RIGHT :
868 nPPTTransitionType = PPT_TRANSITION_TYPE_COVER;
869 break;
871 case FadeEffect_DISSOLVE :
872 nPPTTransitionType = PPT_TRANSITION_TYPE_DISSOLVE;
873 break;
875 case FadeEffect_VERTICAL_LINES :
876 nDirection++;
877 [[fallthrough]];
878 case FadeEffect_HORIZONTAL_LINES :
879 nPPTTransitionType = PPT_TRANSITION_TYPE_RANDOM_BARS;
880 break;
882 case FadeEffect_CLOSE_HORIZONTAL :
883 nDirection++;
884 [[fallthrough]];
885 case FadeEffect_OPEN_HORIZONTAL :
886 nDirection++;
887 [[fallthrough]];
888 case FadeEffect_CLOSE_VERTICAL :
889 nDirection++;
890 [[fallthrough]];
891 case FadeEffect_OPEN_VERTICAL :
892 nPPTTransitionType = PPT_TRANSITION_TYPE_SPLIT;
893 break;
895 case FadeEffect_FADE_FROM_UPPERLEFT :
896 nDirection++;
897 [[fallthrough]];
898 case FadeEffect_FADE_FROM_UPPERRIGHT :
899 nDirection++;
900 [[fallthrough]];
901 case FadeEffect_FADE_FROM_LOWERLEFT :
902 nDirection++;
903 [[fallthrough]];
904 case FadeEffect_FADE_FROM_LOWERRIGHT :
905 nDirection += 4;
906 nPPTTransitionType = PPT_TRANSITION_TYPE_STRIPS;
907 break;
909 case FadeEffect_UNCOVER_TO_LOWERRIGHT :
910 nDirection++;
911 [[fallthrough]];
912 case FadeEffect_UNCOVER_TO_LOWERLEFT :
913 nDirection++;
914 [[fallthrough]];
915 case FadeEffect_UNCOVER_TO_UPPERRIGHT :
916 nDirection++;
917 [[fallthrough]];
918 case FadeEffect_UNCOVER_TO_UPPERLEFT :
919 nDirection++;
920 [[fallthrough]];
921 case FadeEffect_UNCOVER_TO_BOTTOM :
922 nDirection++;
923 [[fallthrough]];
924 case FadeEffect_UNCOVER_TO_RIGHT :
925 nDirection++;
926 [[fallthrough]];
927 case FadeEffect_UNCOVER_TO_TOP :
928 nDirection++;
929 [[fallthrough]];
930 case FadeEffect_UNCOVER_TO_LEFT :
931 nPPTTransitionType = PPT_TRANSITION_TYPE_PULL;
932 break;
934 case FadeEffect_FADE_FROM_TOP :
935 nDirection++;
936 [[fallthrough]];
937 case FadeEffect_FADE_FROM_LEFT :
938 nDirection++;
939 [[fallthrough]];
940 case FadeEffect_FADE_FROM_BOTTOM :
941 nDirection++;
942 [[fallthrough]];
943 case FadeEffect_FADE_FROM_RIGHT :
944 case FadeEffect_ROLL_FROM_RIGHT :
945 nPPTTransitionType = PPT_TRANSITION_TYPE_WIPE;
946 break;
948 case FadeEffect_ROLL_FROM_TOP :
949 nDirection++;
950 [[fallthrough]];
951 case FadeEffect_ROLL_FROM_LEFT :
952 nDirection++;
953 [[fallthrough]];
954 case FadeEffect_ROLL_FROM_BOTTOM :
955 nDirection++;
956 [[fallthrough]];
958 case FadeEffect_FADE_TO_CENTER :
959 nDirection++;
960 [[fallthrough]];
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()
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, false ) && mType != "drawing.Page" )
983 if( mType == "presentation.Page" || mType == "presentation.Notes" )
985 Reference< XSimpleText > rXText( mXShape, UNO_QUERY );
987 if( rXText.is() && !rXText->getString().isEmpty() )
988 bOtherThanPlaceHolders = true;
990 else
991 bOtherThanPlaceHolders = true;
993 SAL_INFO("sd.eppt", "mType == " << mType);
996 return bOtherThanPlaceHolders;
999 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */