nss: upgrade to release 3.73
[LibreOffice.git] / sd / source / filter / eppt / pptx-epptbase.cxx
blob6907389968d74d3f8e0dede15dc1d93074b28091
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 <tools/UnitConversion.hxx>
30 #include <com/sun/star/awt/Rectangle.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
33 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
34 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
35 #include <com/sun/star/drawing/XDrawPages.hpp>
36 #include <com/sun/star/animations/TransitionType.hpp>
37 #include <com/sun/star/animations/TransitionSubType.hpp>
38 #include <com/sun/star/awt/FontFamily.hpp>
39 #include <com/sun/star/awt/FontPitch.hpp>
40 #include <com/sun/star/container/XNamed.hpp>
41 #include <com/sun/star/container/XNameAccess.hpp>
42 #include <com/sun/star/frame/XModel.hpp>
43 #include <com/sun/star/presentation/XPresentationPage.hpp>
44 #include <com/sun/star/text/XSimpleText.hpp>
45 #include <com/sun/star/style/XStyle.hpp>
46 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
47 #include <com/sun/star/task/XStatusIndicator.hpp>
50 using namespace com::sun::star;
52 using namespace ::com::sun::star::animations;
53 using namespace ::com::sun::star::awt::FontFamily;
54 using namespace ::com::sun::star::awt::FontPitch;
55 using namespace ::com::sun::star::presentation;
57 using ::com::sun::star::beans::XPropertySet;
58 using ::com::sun::star::container::XNameAccess;
59 using ::com::sun::star::container::XNamed;
60 using ::com::sun::star::drawing::XMasterPageTarget;
61 using ::com::sun::star::drawing::XDrawPage;
62 using ::com::sun::star::frame::XModel;
63 using ::com::sun::star::style::XStyleFamiliesSupplier;
64 using ::com::sun::star::style::XStyle;
65 using ::com::sun::star::task::XStatusIndicator;
66 using ::com::sun::star::text::XSimpleText;
67 using ::com::sun::star::uno::Any;
68 using ::com::sun::star::uno::Exception;
69 using ::com::sun::star::uno::Reference;
70 using ::com::sun::star::uno::UNO_QUERY;
72 PHLayout const pPHLayout[] =
74 { EppLayout::TITLESLIDE, { 0x0d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x10, true, true, false },
75 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, true, true, false },
76 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x0d, 0x0e, true, true, false },
77 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, true, true, true },
78 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x0d, 0x0e, true, true, false },
79 { EppLayout::BLANKSLIDE, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, false, false, false },
80 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x0e, true, true, false },
81 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x14, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x0d, 0x0e, true, true, false },
82 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x15, 0x0d, 0x0e, true, false, false },
83 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x16, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x0e, true, true, false },
84 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x0e, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
85 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, false, false },
86 { EppLayout::RIGHTCOLUMN2ROWS, { 0x0d, 0x0e, 0x13, 0x13, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
87 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
88 { EppLayout::TWOROWSANDTITLE, { 0x0d, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
89 { EppLayout::LEFTCOLUMN2ROWS, { 0x0d, 0x13, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
90 { EppLayout::TOPROW2COLUMN, { 0x0d, 0x13, 0x13, 0x0e, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
91 { EppLayout::TWOROWSANDTITLE, { 0x0d, 0x0e, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, true, false },
92 { EppLayout::FOUROBJECTS, { 0x0d, 0x13, 0x13, 0x13, 0x13, 0x00, 0x00, 0x00 }, 0x13, 0x0d, 0x0e, true, false, false },
93 { EppLayout::ONLYTITLE, { 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, true, false, false },
94 { EppLayout::BLANKSLIDE, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x0e, false, false, false },
95 { EppLayout::TITLERIGHT2BODIESLEFT, { 0x11, 0x12, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x14, 0x11, 0x12, true, true, false },
96 { EppLayout::TITLERIGHTBODYLEFT, { 0x11, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x11, 0x12, true, true, false },
97 { EppLayout::TITLEANDBODYSLIDE, { 0x0d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x00, 0x0d, 0x12, true, true, false },
98 { EppLayout::TWOCOLUMNSANDTITLE, { 0x0d, 0x16, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0x16, 0x0d, 0x12, true, true, false }
101 PPTWriterBase::PPTWriterBase()
102 : mbStatusIndicator(false)
103 , mbPresObj(false)
104 , mbEmptyPresObj(false)
105 , mbIsBackgroundDark(false)
106 , mnAngle(0)
107 , mnPages(0)
108 , mnMasterPages(0)
109 , maFraction(1, 576)
110 , maMapModeSrc(MapUnit::Map100thMM)
111 , maMapModeDest(MapUnit::MapInch, Point(), maFraction, maFraction)
112 , meLatestPageType(NORMAL)
113 , mpStyleSheet(nullptr)
115 SAL_INFO("sd.eppt", "PPTWriterBase::PPTWriterBase()");
118 PPTWriterBase::PPTWriterBase( const Reference< XModel > & rXModel,
119 const Reference< XStatusIndicator > & rXStatInd )
120 : mXModel(rXModel)
121 , mXStatusIndicator(rXStatInd)
122 , mbStatusIndicator(false)
123 , mbPresObj(false)
124 , mbEmptyPresObj(false)
125 , mbIsBackgroundDark(false)
126 , mnAngle(0)
127 , mnPages(0)
128 , mnMasterPages(0)
129 , maFraction(1, 576)
130 , maMapModeSrc(MapUnit::Map100thMM)
131 , maMapModeDest(MapUnit::MapInch, Point(), maFraction, maFraction)
132 , meLatestPageType (NORMAL)
133 , mpStyleSheet(nullptr)
137 PPTWriterBase::~PPTWriterBase()
139 // Possibly unnecessary sanity check for mXStatusIndicator.is().
140 // In 3.3 we had a bug report of a crash where it was null,
141 // https://bugzilla.novell.com/show_bug.cgi?id=694119 (non-public,
142 // bug report, sorry).
143 if ( mbStatusIndicator && mXStatusIndicator.is() )
144 mXStatusIndicator->end();
147 void PPTWriterBase::exportPPT( const std::vector< css::beans::PropertyValue >& rMediaData )
149 if ( !InitSOIface() )
150 return;
152 FontCollectionEntry aDefaultFontDesc( "Times New Roman",
153 ROMAN,
154 awt::FontPitch::VARIABLE,
155 RTL_TEXTENCODING_MS_1252 );
156 maFontCollection.GetId( aDefaultFontDesc ); // default is always times new roman
158 if ( !GetPageByIndex( 0, NOTICE ) )
159 return;
161 sal_Int32 nWidth = 21000;
162 if ( ImplGetPropertyValue( mXPagePropSet, "Width" ) )
163 mAny >>= nWidth;
164 sal_Int32 nHeight = 29700;
165 if ( ImplGetPropertyValue( mXPagePropSet, "Height" ) )
166 mAny >>= nHeight;
168 maNotesPageSize = MapSize( awt::Size( nWidth, nHeight ) );
170 if ( !GetPageByIndex( 0, MASTER ) )
171 return;
173 nWidth = 28000;
174 if ( ImplGetPropertyValue( mXPagePropSet, "Width" ) )
175 mAny >>= nWidth;
176 nHeight = 21000;
177 if ( ImplGetPropertyValue( mXPagePropSet, "Height" ) )
178 mAny >>= nHeight;
179 maDestPageSize = MapSize( awt::Size( nWidth, nHeight ) );
180 maPageSize = awt::Size(nWidth, nHeight);
182 SAL_INFO("sd.eppt", "call exportDocumentPre()");
183 exportPPTPre(rMediaData);
185 if ( !GetStyleSheets() )
186 return;
188 if ( !ImplCreateDocument() )
189 return;
191 sal_uInt32 i;
193 for ( i = 0; i < mnMasterPages; i++ )
195 if ( !CreateSlideMaster( i ) )
196 return;
198 if ( !CreateMainNotes() )
199 return;
201 for ( i = 0; i < mnPages; i++ )
203 SAL_INFO("sd.eppt", "call ImplCreateSlide( " << i << " )");
204 if ( !CreateSlide( i ) )
205 return;
208 for ( i = 0; i < mnPages; i++ )
210 if ( !CreateNotes( i ) )
211 return;
214 SAL_INFO("sd.eppt", "call exportDocumentPost()");
215 exportPPTPost();
218 bool PPTWriterBase::InitSOIface()
220 while( true )
222 mXDrawPagesSupplier.set( mXModel, UNO_QUERY );
223 if ( !mXDrawPagesSupplier.is() )
224 break;
226 mXMasterPagesSupplier.set( mXModel, UNO_QUERY );
227 if ( !mXMasterPagesSupplier.is() )
228 break;
229 mXDrawPages = mXMasterPagesSupplier->getMasterPages();
230 if ( !mXDrawPages.is() )
231 break;
232 mnMasterPages = mXDrawPages->getCount();
233 mXDrawPages = mXDrawPagesSupplier->getDrawPages();
234 if( !mXDrawPages.is() )
235 break;
236 mnPages = mXDrawPages->getCount();
237 if ( !GetPageByIndex( 0, NORMAL ) )
238 break;
240 return true;
242 return false;
245 bool PPTWriterBase::GetPageByIndex( sal_uInt32 nIndex, PageType ePageType )
247 while( true )
249 if ( ePageType != meLatestPageType )
251 switch( ePageType )
253 case NORMAL :
254 case NOTICE :
256 mXDrawPages = mXDrawPagesSupplier->getDrawPages();
257 if( !mXDrawPages.is() )
258 return false;
260 break;
262 case MASTER :
264 mXDrawPages = mXMasterPagesSupplier->getMasterPages();
265 if( !mXDrawPages.is() )
266 return false;
268 break;
269 default:
270 break;
272 meLatestPageType = ePageType;
274 Any aAny( mXDrawPages->getByIndex( nIndex ) );
275 aAny >>= mXDrawPage;
276 if ( !mXDrawPage.is() )
277 break;
278 if ( ePageType == NOTICE )
280 Reference< XPresentationPage > aXPresentationPage( mXDrawPage, UNO_QUERY );
281 if ( !aXPresentationPage.is() )
282 break;
283 mXDrawPage = aXPresentationPage->getNotesPage();
284 if ( !mXDrawPage.is() )
285 break;
287 mXPagePropSet.set( mXDrawPage, UNO_QUERY );
288 if ( !mXPagePropSet.is() )
289 break;
291 if (GetPropertyValue( aAny, mXPagePropSet, "IsBackgroundDark" ) )
292 aAny >>= mbIsBackgroundDark;
294 mXShapes = mXDrawPage;
295 if ( !mXShapes.is() )
296 break;
298 /* try to get the "real" background PropertySet. If the normal page is not supporting this property, it is
299 taken the property from the master */
300 bool bHasBackground = GetPropertyValue( aAny, mXPagePropSet, "Background", true );
301 if ( bHasBackground )
302 bHasBackground = ( aAny >>= mXBackgroundPropSet );
303 if ( !bHasBackground )
305 Reference< XMasterPageTarget > aXMasterPageTarget( mXDrawPage, UNO_QUERY );
306 if ( aXMasterPageTarget.is() )
308 Reference< XDrawPage > aXMasterDrawPage = aXMasterPageTarget->getMasterPage();
309 if ( aXMasterDrawPage.is() )
311 Reference< XPropertySet > aXMasterPagePropSet;
312 aXMasterPagePropSet.set( aXMasterDrawPage, UNO_QUERY );
313 if ( aXMasterPagePropSet.is() )
315 bool bBackground = GetPropertyValue( aAny, aXMasterPagePropSet, "Background" );
316 if ( bBackground )
318 aAny >>= mXBackgroundPropSet;
324 return true;
326 return false;
329 bool PPTWriterBase::CreateSlide( sal_uInt32 nPageNum )
331 Any aAny;
333 if ( !GetPageByIndex( nPageNum, NORMAL ) )
334 return false;
336 sal_uInt32 nMasterNum = GetMasterIndex( NORMAL );
337 SetCurrentStyleSheet( nMasterNum );
339 Reference< XPropertySet > aXBackgroundPropSet;
340 bool bHasBackground = GetPropertyValue( aAny, mXPagePropSet, "Background" );
341 if ( bHasBackground )
342 bHasBackground = ( aAny >>= aXBackgroundPropSet );
344 sal_uInt16 nMode = 7; // Bit 1: Follow master objects, Bit 2: Follow master scheme, Bit 3: Follow master background
345 if ( bHasBackground )
346 nMode &=~4;
348 /* sj: Don't know what's IsBackgroundVisible for, have to ask cl
349 if ( GetPropertyValue( aAny, mXPagePropSet, OUString( "IsBackgroundVisible" ) ) )
351 bool bBackgroundVisible;
352 if ( aAny >>= bBackgroundVisible )
354 if ( bBackgroundVisible )
355 nMode &= ~4;
359 if ( GetPropertyValue( aAny, mXPagePropSet, "IsBackgroundObjectsVisible" ) )
361 bool bBackgroundObjectsVisible = false;
362 if ( aAny >>= bBackgroundObjectsVisible )
364 if ( !bBackgroundObjectsVisible )
365 nMode &= ~1;
369 ImplWriteSlide( nPageNum, nMasterNum, nMode, bHasBackground, aXBackgroundPropSet );
371 return true;
374 bool PPTWriterBase::CreateNotes( sal_uInt32 nPageNum )
376 if ( !GetPageByIndex( nPageNum, NOTICE ) )
377 return false;
378 SetCurrentStyleSheet( GetMasterIndex( NORMAL ) );
380 ImplWriteNotes( nPageNum );
382 return true;
385 bool PPTWriterBase::CreateSlideMaster( sal_uInt32 nPageNum )
387 if ( !GetPageByIndex( nPageNum, MASTER ) )
388 return false;
389 SetCurrentStyleSheet( nPageNum );
391 css::uno::Reference< css::beans::XPropertySet > aXBackgroundPropSet;
392 if (ImplGetPropertyValue(mXPagePropSet, "Background")) // load background shape
393 mAny >>= aXBackgroundPropSet;
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>( convertMm100ToMasterUnit(*o3tl::doAccess<sal_Int32>(mAny)) )
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.subView(0, aStyle.getLength() - 1) + OUStringChar(++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 = mXDrawPage;
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,
714 sal_Int32 nTransitionFadeColor, sal_uInt8& nDirection )
716 sal_Int8 nPPTTransitionType = 0;
717 nDirection = 0;
719 switch( nTransitionType )
721 case TransitionType::FADE :
723 if ( nTransitionSubtype == TransitionSubType::CROSSFADE )
724 nPPTTransitionType = PPT_TRANSITION_TYPE_SMOOTHFADE;
725 else if ( nTransitionSubtype == TransitionSubType::FADEOVERCOLOR )
727 if( nTransitionFadeColor == static_cast<sal_Int32>(COL_WHITE) )
728 nPPTTransitionType = PPT_TRANSITION_TYPE_FLASH;
729 else
730 nPPTTransitionType = PPT_TRANSITION_TYPE_FADE;
733 break;
734 case TransitionType::PUSHWIPE :
736 if (nTransitionSubtype == TransitionSubType::COMBVERTICAL ||
737 nTransitionSubtype == TransitionSubType::COMBHORIZONTAL)
739 nPPTTransitionType = PPT_TRANSITION_TYPE_COMB;
741 else
743 nPPTTransitionType = PPT_TRANSITION_TYPE_PUSH;
745 switch (nTransitionSubtype)
747 case TransitionSubType::FROMRIGHT: nDirection = 0; break;
748 case TransitionSubType::FROMBOTTOM: nDirection = 1; break;
749 case TransitionSubType::FROMLEFT: nDirection = 2; break;
750 case TransitionSubType::FROMTOP: nDirection = 3; break;
751 case TransitionSubType::COMBHORIZONTAL: nDirection = 0; break;
752 case TransitionSubType::COMBVERTICAL: nDirection = 1; break;
755 break;
756 case TransitionType::PINWHEELWIPE :
758 nPPTTransitionType = PPT_TRANSITION_TYPE_WHEEL;
759 switch( nTransitionSubtype )
761 case TransitionSubType::ONEBLADE: nDirection = 1; break;
762 case TransitionSubType::TWOBLADEVERTICAL : nDirection = 2; break;
763 case TransitionSubType::THREEBLADE : nDirection = 3; break;
764 case TransitionSubType::FOURBLADE: nDirection = 4; break;
765 case TransitionSubType::EIGHTBLADE: nDirection = 8; break;
768 break;
769 case TransitionType::FANWIPE :
771 nPPTTransitionType = PPT_TRANSITION_TYPE_WEDGE;
773 break;
774 case TransitionType::ELLIPSEWIPE :
776 switch( nTransitionSubtype ) {
777 case TransitionSubType::VERTICAL:
778 case TransitionSubType::HORIZONTAL:
779 // no ellipse or oval in PPT or OOXML, fallback to circle
780 default:
781 nPPTTransitionType = PPT_TRANSITION_TYPE_CIRCLE;
784 break;
785 case TransitionType::FOURBOXWIPE :
787 nPPTTransitionType = PPT_TRANSITION_TYPE_PLUS;
789 break;
790 case TransitionType::IRISWIPE :
792 switch( nTransitionSubtype ) {
793 case TransitionSubType::RECTANGLE:
794 nPPTTransitionType = PPT_TRANSITION_TYPE_ZOOM;
795 nDirection = (eEffect == FadeEffect_FADE_FROM_CENTER) ? 0 : 1;
796 break;
797 default:
798 nPPTTransitionType = PPT_TRANSITION_TYPE_DIAMOND;
799 break;
802 break;
803 case TransitionType::ZOOM:
805 switch(nTransitionSubtype)
807 case TransitionSubType::ROTATEIN:
808 nPPTTransitionType = PPT_TRANSITION_TYPE_NEWSFLASH;
809 break;
810 default:
811 break;
814 break;
817 return nPPTTransitionType;
820 sal_Int8 PPTWriterBase::GetTransition( FadeEffect eEffect, sal_uInt8& nDirection )
822 sal_Int8 nPPTTransitionType = 0;
824 switch ( eEffect )
826 default :
827 case FadeEffect_RANDOM :
828 nPPTTransitionType = PPT_TRANSITION_TYPE_RANDOM;
829 break;
831 case FadeEffect_HORIZONTAL_STRIPES :
832 nDirection++;
833 [[fallthrough]];
834 case FadeEffect_VERTICAL_STRIPES :
835 nPPTTransitionType = PPT_TRANSITION_TYPE_BLINDS;
836 break;
838 case FadeEffect_VERTICAL_CHECKERBOARD :
839 nDirection++;
840 [[fallthrough]];
841 case FadeEffect_HORIZONTAL_CHECKERBOARD :
842 nPPTTransitionType = PPT_TRANSITION_TYPE_CHECKER;
843 break;
845 case FadeEffect_MOVE_FROM_UPPERLEFT :
846 nDirection++;
847 [[fallthrough]];
848 case FadeEffect_MOVE_FROM_UPPERRIGHT :
849 nDirection++;
850 [[fallthrough]];
851 case FadeEffect_MOVE_FROM_LOWERLEFT :
852 nDirection++;
853 [[fallthrough]];
854 case FadeEffect_MOVE_FROM_LOWERRIGHT :
855 nDirection++;
856 [[fallthrough]];
857 case FadeEffect_MOVE_FROM_TOP :
858 nDirection++;
859 [[fallthrough]];
860 case FadeEffect_MOVE_FROM_LEFT :
861 nDirection++;
862 [[fallthrough]];
863 case FadeEffect_MOVE_FROM_BOTTOM :
864 nDirection++;
865 [[fallthrough]];
866 case FadeEffect_MOVE_FROM_RIGHT :
867 nPPTTransitionType = PPT_TRANSITION_TYPE_COVER;
868 break;
870 case FadeEffect_DISSOLVE :
871 nPPTTransitionType = PPT_TRANSITION_TYPE_DISSOLVE;
872 break;
874 case FadeEffect_VERTICAL_LINES :
875 nDirection++;
876 [[fallthrough]];
877 case FadeEffect_HORIZONTAL_LINES :
878 nPPTTransitionType = PPT_TRANSITION_TYPE_RANDOM_BARS;
879 break;
881 case FadeEffect_CLOSE_HORIZONTAL :
882 nDirection++;
883 [[fallthrough]];
884 case FadeEffect_OPEN_HORIZONTAL :
885 nDirection++;
886 [[fallthrough]];
887 case FadeEffect_CLOSE_VERTICAL :
888 nDirection++;
889 [[fallthrough]];
890 case FadeEffect_OPEN_VERTICAL :
891 nPPTTransitionType = PPT_TRANSITION_TYPE_SPLIT;
892 break;
894 case FadeEffect_FADE_FROM_UPPERLEFT :
895 nDirection++;
896 [[fallthrough]];
897 case FadeEffect_FADE_FROM_UPPERRIGHT :
898 nDirection++;
899 [[fallthrough]];
900 case FadeEffect_FADE_FROM_LOWERLEFT :
901 nDirection++;
902 [[fallthrough]];
903 case FadeEffect_FADE_FROM_LOWERRIGHT :
904 nDirection += 4;
905 nPPTTransitionType = PPT_TRANSITION_TYPE_STRIPS;
906 break;
908 case FadeEffect_UNCOVER_TO_LOWERRIGHT :
909 nDirection++;
910 [[fallthrough]];
911 case FadeEffect_UNCOVER_TO_LOWERLEFT :
912 nDirection++;
913 [[fallthrough]];
914 case FadeEffect_UNCOVER_TO_UPPERRIGHT :
915 nDirection++;
916 [[fallthrough]];
917 case FadeEffect_UNCOVER_TO_UPPERLEFT :
918 nDirection++;
919 [[fallthrough]];
920 case FadeEffect_UNCOVER_TO_BOTTOM :
921 nDirection++;
922 [[fallthrough]];
923 case FadeEffect_UNCOVER_TO_RIGHT :
924 nDirection++;
925 [[fallthrough]];
926 case FadeEffect_UNCOVER_TO_TOP :
927 nDirection++;
928 [[fallthrough]];
929 case FadeEffect_UNCOVER_TO_LEFT :
930 nPPTTransitionType = PPT_TRANSITION_TYPE_PULL;
931 break;
933 case FadeEffect_FADE_FROM_TOP :
934 nDirection++;
935 [[fallthrough]];
936 case FadeEffect_FADE_FROM_LEFT :
937 nDirection++;
938 [[fallthrough]];
939 case FadeEffect_FADE_FROM_BOTTOM :
940 nDirection++;
941 [[fallthrough]];
942 case FadeEffect_FADE_FROM_RIGHT :
943 nPPTTransitionType = PPT_TRANSITION_TYPE_WIPE;
944 break;
946 case FadeEffect_ROLL_FROM_TOP :
947 nDirection++;
948 [[fallthrough]];
949 case FadeEffect_ROLL_FROM_LEFT :
950 nDirection++;
951 [[fallthrough]];
952 case FadeEffect_ROLL_FROM_BOTTOM :
953 nDirection++;
954 [[fallthrough]];
955 case FadeEffect_ROLL_FROM_RIGHT :
956 nPPTTransitionType = PPT_TRANSITION_TYPE_WIPE;
957 break;
959 case FadeEffect_FADE_TO_CENTER :
960 nDirection++;
961 [[fallthrough]];
962 case FadeEffect_FADE_FROM_CENTER :
963 nPPTTransitionType = PPT_TRANSITION_TYPE_ZOOM;
964 break;
966 case FadeEffect_NONE :
967 nDirection = 2;
968 break;
971 return nPPTTransitionType;
974 bool PPTWriterBase::ContainsOtherShapeThanPlaceholders()
976 sal_uInt32 nShapes = mXShapes->getCount();
977 bool bOtherThanPlaceHolders = false;
979 if ( nShapes )
980 for ( sal_uInt32 nIndex = 0; ( nIndex < nShapes ) && !bOtherThanPlaceHolders; nIndex++ )
982 if ( GetShapeByIndex( nIndex, false ) && mType != "drawing.Page" )
984 if( mType == "presentation.Page" || 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 SAL_INFO("sd.eppt", "mType == " << mType);
997 return bOtherThanPlaceHolders;
1000 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */