1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include "epptdef.hxx"
22 #include "pptexanimations.hxx"
23 #include <o3tl/any.hxx>
24 #include <tools/globname.hxx>
25 #include <rtl/ustring.hxx>
26 #include <tools/stream.hxx>
27 #include <svx/unoapi.hxx>
28 #include <svx/svdobj.hxx>
29 #include <svx/svdoole2.hxx>
30 #include <com/sun/star/container/XIndexContainer.hpp>
31 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
32 #include <com/sun/star/office/XAnnotation.hpp>
33 #include <com/sun/star/office/XAnnotationAccess.hpp>
34 #include <com/sun/star/office/XAnnotationEnumeration.hpp>
35 #include <com/sun/star/presentation/AnimationSpeed.hpp>
36 #include <com/sun/star/presentation/XPresentationSupplier.hpp>
37 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
38 #include <com/sun/star/geometry/RealPoint2D.hpp>
39 #include <com/sun/star/util/DateTime.hpp>
40 #include <com/sun/star/task/XStatusIndicator.hpp>
41 #include <tools/zcodec.hxx>
42 #include <filter/msfilter/classids.hxx>
43 #include <filter/msfilter/msoleexp.hxx>
44 #include <filter/msfilter/msdffimp.hxx>
45 #include <filter/msfilter/svxmsbas.hxx>
46 #include <editeng/flditem.hxx>
47 #include <sfx2/docinf.hxx>
48 #include <oox/export/utils.hxx>
49 #include <oox/ole/olehelper.hxx>
50 #include <rtl/math.hxx>
54 // complete SfxObjectShell for SaveVBA under -fsanitize=function
56 using namespace com::sun::star
;
57 using namespace ::com::sun::star::uno
;
58 using namespace ::com::sun::star::presentation
;
60 using ::com::sun::star::beans::XPropertySet
;
62 //============================ PPTWriter ==================================
64 PPTWriter::PPTWriter( tools::SvRef
<SotStorage
> const & rSvStorage
,
65 css::uno::Reference
< css::frame::XModel
> const & rXModel
,
66 css::uno::Reference
< css::task::XStatusIndicator
> const & rXStatInd
,
67 SvMemoryStream
* pVBA
, sal_uInt32 nCnvrtFlags
) :
68 PPTWriterBase ( rXModel
, rXStatInd
),
69 mnCnvrtFlags ( nCnvrtFlags
),
72 mnLatestStatValue ( 0 ),
74 mbFontIndependentLineSpacing( false ),
80 mpExEmbed ( new SvMemoryStream
),
84 mnShapeMasterTitle ( 0 ),
85 mnShapeMasterBody ( 0 )
89 void PPTWriter::exportPPTPre( const std::vector
< css::beans::PropertyValue
>& rMediaData
)
94 if ( mXStatusIndicator
.is() )
96 mbStatusIndicator
= true;
97 mnStatMaxValue
= ( mnPages
+ mnMasterPages
) * 5;
98 mXStatusIndicator
->start( "PowerPoint Export", mnStatMaxValue
+ ( mnStatMaxValue
>> 3 ) );
101 SvGlobalName
aGName(MSO_PPT8_CLASSID
);
102 mrStg
->SetClass( aGName
, SotClipboardFormatId::NONE
, "MS PowerPoint 97" );
104 if ( !ImplCreateCurrentUserStream() )
107 mpStrm
.reset( mrStg
->OpenSotStream( "PowerPoint Document" ) );
112 mpPicStrm
.reset( mrStg
->OpenSotStream( "Pictures" ) );
114 auto aIter
= std::find_if(rMediaData
.begin(), rMediaData
.end(),
115 [](const css::beans::PropertyValue
& rProp
) { return rProp
.Name
== "BaseURI"; });
116 if (aIter
!= rMediaData
.end())
117 (*aIter
).Value
>>= maBaseURI
;
118 mpPptEscherEx
.reset( new PptEscherEx( *mpStrm
, maBaseURI
) );
121 void PPTWriter::exportPPTPost( )
123 if ( !ImplCloseDocument() )
126 if ( mbStatusIndicator
)
128 mXStatusIndicator
->setText( "PowerPoint Export" );
129 sal_uInt32 nValue
= mnStatMaxValue
+ ( mnStatMaxValue
>> 3 );
130 if ( nValue
> mnLatestStatValue
)
132 mXStatusIndicator
->setValue( nValue
);
133 mnLatestStatValue
= nValue
;
141 ImplWriteAtomEnding();
143 ImplCreateDocumentSummaryInformation();
148 static void ImplExportComments( const uno::Reference
< drawing::XDrawPage
>& xPage
, SvMemoryStream
& rBinaryTagData10Atom
);
150 void PPTWriter::ImplWriteSlide( sal_uInt32 nPageNum
, sal_uInt32 nMasterNum
, sal_uInt16 nMode
,
151 bool bHasBackground
, Reference
< XPropertySet
> const & aXBackgroundPropSet
)
155 const PHLayout
& rLayout
= GetLayout( mXPagePropSet
);
156 mpPptEscherEx
->PtReplaceOrInsert( EPP_Persist_Slide
| nPageNum
, mpStrm
->Tell() );
157 mpPptEscherEx
->OpenContainer( EPP_Slide
);
158 mpPptEscherEx
->AddAtom( 24, EPP_SlideAtom
, 2 );
159 mpStrm
->WriteInt32( static_cast<sal_Int32
>(rLayout
.nLayout
) );
160 mpStrm
->WriteBytes(rLayout
.nPlaceHolder
, 8); // placeholderIDs (8 parts)
161 mpStrm
->WriteUInt32( nMasterNum
| 0x80000000 ) // master ID (equals 0x80000000 on a master page)
162 .WriteUInt32( nPageNum
+ 0x100 ) // notes ID (equals null if no notes are present)
163 .WriteUInt16( nMode
)
164 .WriteUInt16( 0 ); // padword
167 bool bVisible
= true;
168 css::presentation::FadeEffect eFe
= css::presentation::FadeEffect_NONE
;
170 if ( GetPropertyValue( aAny
, mXPagePropSet
, "Visible" ) )
172 if ( GetPropertyValue( aAny
, mXPagePropSet
, "Change" ) )
174 switch ( *o3tl::doAccess
<sal_Int32
>(aAny
) )
176 case 1 : // automatic
179 case 2 : // semi-automatic
187 if ( GetPropertyValue( aAny
, mXPagePropSet
, "Effect" ) )
190 sal_uInt32 nSoundRef
= 0;
191 bool bIsSound
= false;
192 bool bStopSound
= false;
193 bool bLoopSound
= false;
195 if ( GetPropertyValue( aAny
, mXPagePropSet
, "Sound" ) )
198 if ( aAny
>>= aSoundURL
)
200 nSoundRef
= maSoundCollection
.GetId( aSoundURL
);
206 if ( GetPropertyValue( aAny
, mXPagePropSet
, "LoopSound" ) )
209 bool bNeedsSSSlideInfoAtom
= !bVisible
210 || ( mnDiaMode
== 2 )
213 || ( eFe
!= css::presentation::FadeEffect_NONE
);
214 if ( bNeedsSSSlideInfoAtom
)
216 sal_uInt8 nDirection
= 0;
217 sal_uInt8 nTransitionType
= 0;
218 sal_uInt16 nBuildFlags
= 1; // advance by mouseclick
219 sal_Int32 nSlideTime
= 0; // still has to !!!
220 sal_uInt8 nSpeed
= 1;
222 if ( GetPropertyValue( aAny
, mXPagePropSet
, "TransitionDuration" ) )
224 css::presentation::AnimationSpeed aAs
;
225 double fTransitionDuration
= -1.0;
226 aAny
>>= fTransitionDuration
;
228 if (fTransitionDuration
>= 0)
230 if (fTransitionDuration
<= 0.5)
232 aAs
= css::presentation::AnimationSpeed::AnimationSpeed_FAST
;
234 else if (fTransitionDuration
>= 1.0)
236 aAs
= css::presentation::AnimationSpeed::AnimationSpeed_SLOW
;
240 aAs
= css::presentation::AnimationSpeed::AnimationSpeed_MEDIUM
;
244 aAs
= css::presentation::AnimationSpeed::AnimationSpeed_MEDIUM
;
246 nSpeed
= static_cast<sal_uInt8
>(aAs
);
249 if ( GetPropertyValue( aAny
, mXPagePropSet
, "TransitionType" )
250 && ( aAny
>>= nTT
) )
253 if ( GetPropertyValue( aAny
, mXPagePropSet
, "TransitionSubtype" )
254 && ( aAny
>>= nTST
) )
255 nTransitionType
= GetTransition( nTT
, nTST
, eFe
, nDirection
);
258 if ( !nTransitionType
)
259 nTransitionType
= GetTransition( eFe
, nDirection
);
260 if ( mnDiaMode
== 2 ) // automatic ?
261 nBuildFlags
|= 0x400;
271 if ( GetPropertyValue( aAny
, mXPagePropSet
, "Duration" ) )// duration of this slide
272 nSlideTime
= *o3tl::doAccess
<sal_Int32
>(aAny
) << 10; // in ticks
274 mpPptEscherEx
->AddAtom( 16, EPP_SSSlideInfoAtom
);
275 mpStrm
->WriteInt32( nSlideTime
) // standtime in ticks
276 .WriteUInt32( nSoundRef
)
277 .WriteUChar( nDirection
)
278 .WriteUChar( nTransitionType
)
279 .WriteUInt16( nBuildFlags
)
280 .WriteUChar( nSpeed
)
281 .WriteUChar( 0 ).WriteUChar( 0 ).WriteUChar( 0 );
284 ImplCreateHeaderFooters( mXPagePropSet
);
286 EscherSolverContainer aSolverContainer
;
287 mpPptEscherEx
->OpenContainer( EPP_PPDrawing
);
288 mpPptEscherEx
->OpenContainer( ESCHER_DgContainer
);
289 mpPptEscherEx
->EnterGroup(nullptr,nullptr);
290 ImplWritePage( rLayout
, aSolverContainer
, NORMAL
, false, nPageNum
); // the shapes of the pages are created in the PPT document
291 mpPptEscherEx
->LeaveGroup();
293 if ( bHasBackground
)
294 ImplWriteBackground( aXBackgroundPropSet
);
297 mpPptEscherEx
->OpenContainer( ESCHER_SpContainer
);
298 mpPptEscherEx
->AddShape( ESCHER_ShpInst_Rectangle
,
299 ShapeFlag::Background
| ShapeFlag::HaveShapeProperty
);
300 EscherPropertyContainer aPropOpt
;
301 aPropOpt
.AddOpt( ESCHER_Prop_fillRectRight
, PPTtoEMU( maDestPageSize
.Width
) );
302 aPropOpt
.AddOpt( ESCHER_Prop_fillRectBottom
, PPTtoEMU( maDestPageSize
.Width
) );
303 aPropOpt
.AddOpt( ESCHER_Prop_fNoFillHitTest
, 0x120012 );
304 aPropOpt
.AddOpt( ESCHER_Prop_fNoLineDrawDash
, 0x80000 );
305 aPropOpt
.AddOpt( ESCHER_Prop_bWMode
, ESCHER_wDontShow
);
306 aPropOpt
.AddOpt( ESCHER_Prop_fBackground
, 0x10001 ); // if true, this is the background shape
307 aPropOpt
.Commit( *mpStrm
);
308 mpPptEscherEx
->CloseContainer(); // ESCHER_SpContainer
311 aSolverContainer
.WriteSolver( *mpStrm
);
313 mpPptEscherEx
->CloseContainer(); // ESCHER_DgContainer
314 mpPptEscherEx
->CloseContainer(); // EPP_Drawing
315 mpPptEscherEx
->AddAtom( 32, EPP_ColorSchemeAtom
, 0, 1 );
316 mpStrm
->WriteUInt32( 0xffffff ).WriteUInt32( 0x000000 ).WriteUInt32( 0x808080 ).WriteUInt32( 0x000000 ).WriteUInt32( 0x99cc00 ).WriteUInt32( 0xcc3333 ).WriteUInt32( 0xffcccc ).WriteUInt32( 0xb2b2b2 );
318 SvMemoryStream aBinaryTagData10Atom
;
319 ImplExportComments( mXDrawPage
, aBinaryTagData10Atom
);
320 SvMemoryStream amsofbtAnimGroup
;
321 ppt::AnimationExporter
aExporter( aSolverContainer
, maSoundCollection
);
322 aExporter
.doexport( mXDrawPage
, amsofbtAnimGroup
);
323 sal_uInt32 nmsofbtAnimGroupSize
= amsofbtAnimGroup
.Tell();
324 if ( nmsofbtAnimGroupSize
)
327 EscherExAtom
aMagic2( aBinaryTagData10Atom
, 0x2eeb );
328 aBinaryTagData10Atom
.WriteUInt32( 0x01c45df9 )
329 .WriteUInt32( 0xe1471b30 );
332 EscherExAtom
aMagic( aBinaryTagData10Atom
, 0x2b00 );
333 aBinaryTagData10Atom
.WriteUInt32( 0 );
335 aBinaryTagData10Atom
.WriteBytes(amsofbtAnimGroup
.GetData(), amsofbtAnimGroup
.Tell());
337 EscherExContainer
aMagic2( aBinaryTagData10Atom
, 0x2b02 );
340 if ( aBinaryTagData10Atom
.Tell() )
342 EscherExContainer
aProgTags ( *mpStrm
, EPP_ProgTags
);
343 EscherExContainer
aProgBinaryTag( *mpStrm
, EPP_ProgBinaryTag
);
345 EscherExAtom
aCString( *mpStrm
, EPP_CString
);
346 mpStrm
->WriteUInt32( 0x5f005f )
347 .WriteUInt32( 0x50005f )
348 .WriteUInt32( 0x540050 )
350 .WriteUInt16( 0x30 );
353 EscherExAtom
aBinaryTagData( *mpStrm
, EPP_BinaryTagData
);
354 mpStrm
->WriteBytes(aBinaryTagData10Atom
.GetData(), aBinaryTagData10Atom
.Tell());
357 mpPptEscherEx
->CloseContainer(); // EPP_Slide
360 void PPTWriter::ImplWriteSlideMaster( sal_uInt32 nPageNum
, Reference
< XPropertySet
> const & aXBackgroundPropSet
)
362 mpPptEscherEx
->PtReplaceOrInsert( EPP_Persist_MainMaster
| nPageNum
, mpStrm
->Tell() );
363 mpPptEscherEx
->OpenContainer( EPP_MainMaster
);
364 mpPptEscherEx
->AddAtom( 24, EPP_SlideAtom
, 2 );
365 mpStrm
->WriteInt32( static_cast<sal_Int32
>(EppLayout::TITLEANDBODYSLIDE
) ) // slide layout -> title and body slide
366 .WriteUChar( 1 ).WriteUChar( 2 ).WriteUChar( 0 ).WriteUChar( 0 ).WriteUChar( 0 ).WriteUChar( 0 ).WriteUChar( 0 ).WriteUChar( 0 ) // placeholderID
367 .WriteUInt32( 0 ) // master ID (equals null at a master page)
368 .WriteUInt32( 0 ) // notes ID (equals null if no notes are present)
369 .WriteUInt16( 0 ) // Bit 1: Follow master objects, Bit 2: Follow master scheme, Bit 3: Follow master background
370 .WriteUInt16( 0 ); // padword
372 mpPptEscherEx
->AddAtom( 32, EPP_ColorSchemeAtom
, 0, 6 );
373 mpStrm
->WriteUInt32( 0xffffff ).WriteUInt32( 0x000000 ).WriteUInt32( 0x808080 ).WriteUInt32( 0x000000 ).WriteUInt32( 0x99cc00 ).WriteUInt32( 0xcc3333 ).WriteUInt32( 0xffcccc ).WriteUInt32( 0xb2b2b2 );
374 mpPptEscherEx
->AddAtom( 32, EPP_ColorSchemeAtom
, 0, 6 );
375 mpStrm
->WriteUInt32( 0xff0000 ).WriteUInt32( 0xffffff ).WriteUInt32( 0x000000 ).WriteUInt32( 0x00ffff ).WriteUInt32( 0x0099ff ).WriteUInt32( 0xffff00 ).WriteUInt32( 0x0000ff ).WriteUInt32( 0x969696 );
376 mpPptEscherEx
->AddAtom( 32, EPP_ColorSchemeAtom
, 0, 6 );
377 mpStrm
->WriteUInt32( 0xccffff ).WriteUInt32( 0x000000 ).WriteUInt32( 0x336666 ).WriteUInt32( 0x008080 ).WriteUInt32( 0x339933 ).WriteUInt32( 0x000080 ).WriteUInt32( 0xcc3300 ).WriteUInt32( 0x66ccff );
378 mpPptEscherEx
->AddAtom( 32, EPP_ColorSchemeAtom
, 0, 6 );
379 mpStrm
->WriteUInt32( 0xffffff ).WriteUInt32( 0x000000 ).WriteUInt32( 0x333333 ).WriteUInt32( 0x000000 ).WriteUInt32( 0xdddddd ).WriteUInt32( 0x808080 ).WriteUInt32( 0x4d4d4d ).WriteUInt32( 0xeaeaea );
380 mpPptEscherEx
->AddAtom( 32, EPP_ColorSchemeAtom
, 0, 6 );
381 mpStrm
->WriteUInt32( 0xffffff ).WriteUInt32( 0x000000 ).WriteUInt32( 0x808080 ).WriteUInt32( 0x000000 ).WriteUInt32( 0x66ccff ).WriteUInt32( 0xff0000 ).WriteUInt32( 0xcc00cc ).WriteUInt32( 0xc0c0c0 );
382 mpPptEscherEx
->AddAtom( 32, EPP_ColorSchemeAtom
, 0, 6 );
383 mpStrm
->WriteUInt32( 0xffffff ).WriteUInt32( 0x000000 ).WriteUInt32( 0x808080 ).WriteUInt32( 0x000000 ).WriteUInt32( 0xc0c0c0 ).WriteUInt32( 0xff6600 ).WriteUInt32( 0x0000ff ).WriteUInt32( 0x009900 );
384 mpPptEscherEx
->AddAtom( 32, EPP_ColorSchemeAtom
, 0, 6 );
385 mpStrm
->WriteUInt32( 0xffffff ).WriteUInt32( 0x000000 ).WriteUInt32( 0x808080 ).WriteUInt32( 0x000000 ).WriteUInt32( 0xff9933 ).WriteUInt32( 0xccff99 ).WriteUInt32( 0xcc00cc ).WriteUInt32( 0xb2b2b2 );
387 for ( int nInstance
= EPP_TEXTTYPE_Title
; nInstance
<= EPP_TEXTTYPE_QuarterBody
; nInstance
++ )
389 if ( nInstance
== EPP_TEXTTYPE_notUsed
)
392 // the auto color is dependent to the page background,so we have to set a page that is in the right context
393 if ( nInstance
== EPP_TEXTTYPE_Notes
)
394 (void)GetPageByIndex(0, NOTICE
);
396 (void)GetPageByIndex(0, MASTER
);
398 mpPptEscherEx
->BeginAtom();
400 bool bSimpleText
= false;
402 mpStrm
->WriteUInt16( 5 ); // paragraph count
404 for ( sal_uInt16 nLev
= 0; nLev
< 5; nLev
++ )
406 if ( nInstance
>= EPP_TEXTTYPE_CenterBody
)
409 mpStrm
->WriteUInt16( nLev
);
411 mpStyleSheet
->mpParaSheet
[ nInstance
]->Write( *mpStrm
, nLev
, bSimpleText
, mXPagePropSet
);
412 mpStyleSheet
->mpCharSheet
[ nInstance
]->Write( *mpStrm
, nLev
, bSimpleText
, mXPagePropSet
);
414 mpPptEscherEx
->EndAtom( EPP_TxMasterStyleAtom
, 0, nInstance
);
416 GetPageByIndex( nPageNum
, MASTER
);
418 EscherSolverContainer aSolverContainer
;
420 mpPptEscherEx
->OpenContainer( EPP_PPDrawing
);
421 mpPptEscherEx
->OpenContainer( ESCHER_DgContainer
);
423 mpPptEscherEx
->EnterGroup(nullptr,nullptr);
424 ImplWritePage( GetLayout( 0 ), aSolverContainer
, MASTER
, true ); // the shapes of the pages are created in the PPT document
425 mpPptEscherEx
->LeaveGroup();
427 ImplWriteBackground( aXBackgroundPropSet
);
429 aSolverContainer
.WriteSolver( *mpStrm
);
431 mpPptEscherEx
->CloseContainer(); // ESCHER_DgContainer
432 mpPptEscherEx
->CloseContainer(); // EPP_Drawing
433 mpPptEscherEx
->AddAtom( 32, EPP_ColorSchemeAtom
, 0, 1 );
434 mpStrm
->WriteUInt32( 0xffffff ).WriteUInt32( 0x000000 ).WriteUInt32( 0x808080 ).WriteUInt32( 0x000000 ).WriteUInt32( 0x99cc00 ).WriteUInt32( 0xcc3333 ).WriteUInt32( 0xffcccc ).WriteUInt32( 0xb2b2b2 );
436 if ( aBuExMasterStream
.Tell() )
438 ImplProgTagContainer( mpStrm
.get(), &aBuExMasterStream
);
440 mpPptEscherEx
->CloseContainer(); // EPP_MainMaster
443 PPTWriter::~PPTWriter()
446 mpPptEscherEx
.reset();
447 mpCurUserStrm
.reset();
450 maStyleSheetList
.clear();
452 if ( mbStatusIndicator
)
453 mXStatusIndicator
->end();
456 bool PPTWriter::ImplCreateCurrentUserStream()
458 mpCurUserStrm
.reset( mrStg
->OpenSotStream( "Current User" ) );
459 if ( !mpCurUserStrm
)
461 char pUserName
[] = "Current User";
462 sal_uInt32 nLenOfUserName
= strlen( pUserName
);
463 sal_uInt32 nSizeOfRecord
= 0x14 + ( ( nLenOfUserName
+ 4 ) & ~ 3 );
465 mpCurUserStrm
->WriteUInt16( 0 ).WriteUInt16( EPP_CurrentUserAtom
).WriteUInt32( nSizeOfRecord
);
466 mpCurUserStrm
->WriteUInt32( 0x14 ) // Len
467 .WriteUInt32( 0xe391c05f ); // Magic
469 sal_uInt32 nEditPos
= mpCurUserStrm
->Tell();
470 mpCurUserStrm
->WriteUInt32( 0x0 ) // OffsetToCurrentEdit;
471 .WriteUInt16( nLenOfUserName
)
472 .WriteUInt16( 0x3f4 ) // DocFileVersion
473 .WriteUChar( 3 ) // MajorVersion
474 .WriteUChar( 0 ) // MinorVersion
475 .WriteUInt16( 0 ); // Pad Word
476 pUserName
[ nLenOfUserName
] = 8;
477 mpCurUserStrm
->WriteBytes(pUserName
, nLenOfUserName
+ 1);
478 for ( sal_uInt32 i
= 0x15 + nLenOfUserName
; i
< nSizeOfRecord
; i
++ )
480 mpCurUserStrm
->WriteUChar( 0 ); // pad bytes
482 mpCurUserStrm
->Seek( nEditPos
);
486 void PPTWriter::ImplCreateDocumentSummaryInformation()
488 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
489 mXModel
, uno::UNO_QUERY_THROW
);
490 uno::Reference
<document::XDocumentProperties
> xDocProps(
491 xDPS
->getDocumentProperties());
496 // no idea what this is...
497 static const sal_Int8 aGuid
[ 0x52 ] =
499 0x4e, 0x00, 0x00, 0x00,
500 '{',0,'D',0,'B',0,'1',0,'A',0,'C',0,'9',0,'6',0,'4',0,'-',0,
501 'E',0,'3',0,'9',0,'C',0,'-',0,'1',0,'1',0,'D',0,'2',0,'-',0,
502 'A',0,'1',0,'E',0,'F',0,'-',0,'0',0,'0',0,'6',0,'0',0,'9',0,
503 '7',0,'D',0,'A',0,'5',0,'6',0,'8',0,'9',0,'}',0
505 uno::Sequence
<sal_Int8
> aGuidSeq(aGuid
, 0x52);
507 SvMemoryStream aHyperBlob
;
508 ImplCreateHyperBlob( aHyperBlob
);
510 uno::Sequence
<sal_Int8
> aHyperSeq(aHyperBlob
.Tell());
511 const sal_Int8
* pBlob(
512 static_cast<const sal_Int8
*>(aHyperBlob
.GetData()));
513 for (sal_Int32 j
= 0; j
< aHyperSeq
.getLength(); ++j
) {
514 aHyperSeq
[j
] = pBlob
[j
];
517 if ( mnCnvrtFlags
& 0x8000 )
519 uno::Sequence
<sal_Int8
> aThumbSeq
;
520 if ( GetPageByIndex( 0, NORMAL
) && ImplGetPropertyValue( mXPagePropSet
, "PreviewBitmap" ) )
522 aThumbSeq
= *o3tl::doAccess
<uno::Sequence
<sal_Int8
>>(mAny
);
524 sfx2::SaveOlePropertySet( xDocProps
, mrStg
.get(),
525 &aThumbSeq
, &aGuidSeq
, &aHyperSeq
);
529 sfx2::SaveOlePropertySet( xDocProps
, mrStg
.get(),
530 nullptr, &aGuidSeq
, &aHyperSeq
);
534 void PPTWriter::ImplWriteExtParaHeader( SvMemoryStream
& rSt
, sal_uInt32 nRef
, sal_uInt32 nInstance
, sal_uInt32 nSlideId
)
538 aBuExOutlineStream
.WriteUInt32( ( EPP_PST_ExtendedParagraphHeaderAtom
<< 16 )
541 .WriteUInt32( nSlideId
)
542 .WriteUInt32( nInstance
);
543 aBuExOutlineStream
.WriteBytes(rSt
.GetData(), rSt
.Tell());
547 void PPTWriter::ImplCreateHeaderFooterStrings( SvStream
& rStrm
, css::uno::Reference
< css::beans::XPropertySet
> const & rXPagePropSet
)
549 if ( !rXPagePropSet
.is() )
554 if ( PropValue::GetPropertyValue( aAny
, rXPagePropSet
, "HeaderText", true ) )
556 if ( aAny
>>= aString
)
557 PPTWriter::WriteCString( rStrm
, aString
, 1 );
559 if ( PropValue::GetPropertyValue( aAny
, rXPagePropSet
, "FooterText", true ) )
561 if ( aAny
>>= aString
)
562 PPTWriter::WriteCString( rStrm
, aString
, 2 );
564 if ( PropValue::GetPropertyValue( aAny
, rXPagePropSet
, "DateTimeText", true ) )
566 if ( aAny
>>= aString
)
567 PPTWriter::WriteCString( rStrm
, aString
);
571 void PPTWriter::ImplCreateHeaderFooters( css::uno::Reference
< css::beans::XPropertySet
> const & rXPagePropSet
)
573 if ( !rXPagePropSet
.is() )
579 if ( PropValue::GetPropertyValue( aAny
, rXPagePropSet
, "IsHeaderVisible", true ) )
581 if ( ( aAny
>>= bVal
) && bVal
)
584 if ( PropValue::GetPropertyValue( aAny
, rXPagePropSet
, "IsFooterVisible", true ) )
586 if ( ( aAny
>>= bVal
) && bVal
)
589 if ( PropValue::GetPropertyValue( aAny
, rXPagePropSet
, "IsDateTimeVisible", true ) )
591 if ( ( aAny
>>= bVal
) && bVal
)
594 if ( PropValue::GetPropertyValue( aAny
, rXPagePropSet
, "IsPageNumberVisible", true ) )
596 if ( ( aAny
>>= bVal
) && bVal
)
599 if ( PropValue::GetPropertyValue( aAny
, rXPagePropSet
, "IsDateTimeFixed", true ) )
601 if ( ( aAny
>>= bVal
) && !bVal
)
606 if ( PropValue::GetPropertyValue( aAny
, rXPagePropSet
, "DateTimeFormat", true ) )
608 sal_Int32 nFormat
= *o3tl::doAccess
<sal_Int32
>(aAny
);
609 SvxDateFormat eDateFormat
= static_cast<SvxDateFormat
>( nFormat
& 0xf );
610 SvxTimeFormat eTimeFormat
= static_cast<SvxTimeFormat
>( ( nFormat
>> 4 ) & 0xf );
611 switch( eDateFormat
)
613 case SvxDateFormat::F
:
616 case SvxDateFormat::D
:
619 case SvxDateFormat::C
:
623 case SvxDateFormat::A
:
626 switch( eTimeFormat
)
628 case SvxTimeFormat::HH24_MM
:
631 case SvxTimeFormat::HH12_MM
:
634 case SvxTimeFormat::HH24_MM_SS
:
637 case SvxTimeFormat::HH12_MM_SS
:
646 mpPptEscherEx
->OpenContainer( EPP_HeadersFooters
);
647 mpPptEscherEx
->AddAtom( 4, EPP_HeadersFootersAtom
);
648 mpStrm
->WriteUInt32( nVal
);
649 ImplCreateHeaderFooterStrings( *mpStrm
, rXPagePropSet
);
650 mpPptEscherEx
->CloseContainer();
653 bool PPTWriter::ImplCreateDocument()
656 sal_uInt16 nSlideType
= EPP_SLIDESIZE_TYPECUSTOM
;
658 sal_uInt32 nWidth
= maDestPageSize
.Width
;
659 sal_uInt32 nHeight
= maDestPageSize
.Height
;
661 if ( ( nWidth
== 0x1680 ) && ( nHeight
== 0x10e0 ) )
662 nSlideType
= EPP_SLIDESIZE_TYPEONSCREEN
;
663 else if ( ( nWidth
== 0x1200 ) && ( nHeight
== 0x240 ) )
664 nSlideType
= EPP_SLIDESIZE_TYPEBANNER
;
665 else if ( ( nWidth
== 0x1950 ) && ( nHeight
== 0x10e0 ) )
666 nSlideType
= EPP_SLIDESIZE_TYPE35MM
;
667 else if ( ( nWidth
== 0x1860 ) && ( nHeight
== 0x10e0 ) )
668 nSlideType
= EPP_SLIDESIZE_TYPEA4PAPER
;
670 mpPptEscherEx
->OpenContainer( EPP_Document
);
671 // CREATE DOCUMENT ATOM
672 mpPptEscherEx
->AddAtom( 40, EPP_DocumentAtom
, 1 );
673 mpStrm
->WriteUInt32( nWidth
) // Slide Size in Master coordinates X
674 .WriteUInt32( nHeight
) // " " " " " Y
675 .WriteInt32( maNotesPageSize
.Width
) // Notes Page Size X
676 .WriteInt32( maNotesPageSize
.Height
) // " " " Y
677 .WriteInt32( 1 ).WriteInt32( 2 ); // the scale used when the Powerpoint document is embedded. the default is 1:2
678 mpPptEscherEx
->InsertPersistOffset( EPP_MAINNOTESMASTER_PERSIST_KEY
, mpStrm
->Tell() );
679 mpStrm
->WriteUInt32( 0 ) // Reference to NotesMaster ( 0 if none );
680 .WriteUInt32( 0 ) // Reference to HandoutMaster ( 0 if none );
681 .WriteInt16( 1 ) // Number of the first slide;
682 .WriteUInt16( nSlideType
) // Size of the document slides ( default: EPP_SLIDESIZETYPEONSCREEN )
683 .WriteUChar( 0 ) // bool1 indicates if document was saved with embedded true type fonts
684 .WriteUChar( 0 ) // bool1 indicates if the placeholders on the title slide are omitted
685 .WriteUChar( 0 ) // bool1 right to left ( flag for Bidi version )
686 .WriteUChar( 1 ); // bool1 visibility of comments shapes
688 mpPptEscherEx
->PtInsert( EPP_Persist_Document
, mpStrm
->Tell() );
690 mpPptEscherEx
->OpenContainer( EPP_HeadersFooters
, 3 ); //Master footer (default)
691 mpPptEscherEx
->AddAtom( 4, EPP_HeadersFootersAtom
);
692 mpStrm
->WriteUInt32( 0x25000d );
693 if ( GetPageByIndex( 0, MASTER
) )
694 ImplCreateHeaderFooterStrings( *mpStrm
, mXPagePropSet
);
695 mpPptEscherEx
->CloseContainer();
696 mpPptEscherEx
->OpenContainer( EPP_HeadersFooters
, 4 ); //NotesMaster footer (default)
697 mpPptEscherEx
->AddAtom( 4, EPP_HeadersFootersAtom
);
698 mpStrm
->WriteUInt32( 0x3d000d );
699 if ( GetPageByIndex( 0, NOTICE
) )
700 ImplCreateHeaderFooterStrings( *mpStrm
, mXPagePropSet
);
701 mpPptEscherEx
->CloseContainer();
703 mpPptEscherEx
->OpenContainer( EPP_SlideListWithText
); // animation information for the slides
705 for ( i
= 0; i
< mnPages
; i
++ )
707 mpPptEscherEx
->AddAtom( 20, EPP_SlidePersistAtom
);
708 mpPptEscherEx
->InsertPersistOffset( EPP_MAINSLIDE_PERSIST_KEY
| i
, mpStrm
->Tell() );
709 mpStrm
->WriteUInt32( 0 ) // psrReference - logical reference to the slide persist object ( EPP_MAINSLIDE_PERSIST_KEY )
710 .WriteUInt32( 4 ) // flags - only bit 3 used, if set then slide contains shapes other than placeholders
711 .WriteInt32( 0 ) // numberTexts - number of placeholder texts stored with the persist object. Allows to display outline view without loading the slide persist objects
712 .WriteInt32( i
+ 0x100 ) // slideId - Unique slide identifier, used for OLE link monikers for example
713 .WriteUInt32( 0 ); // reserved, usually 0
715 if ( !GetPageByIndex( i
, NORMAL
) ) // very exciting: once again through all pages
717 SetCurrentStyleSheet( GetMasterIndex( NORMAL
) );
719 css::uno::Reference
< css::container::XNamed
>
720 aXName( mXDrawPage
, css::uno::UNO_QUERY
);
723 maSlideNameList
.push_back( aXName
->getName() );
725 maSlideNameList
.emplace_back( );
727 mpPptEscherEx
->CloseContainer(); // EPP_SlideListWithText
729 mpPptEscherEx
->OpenContainer( EPP_SlideListWithText
, 2 ); // animation information for the notes
730 for( i
= 0; i
< mnPages
; i
++ )
732 mpPptEscherEx
->AddAtom( 20, EPP_SlidePersistAtom
);
733 mpPptEscherEx
->InsertPersistOffset( EPP_MAINNOTES_PERSIST_KEY
| i
, mpStrm
->Tell() );
734 mpStrm
->WriteUInt32( 0 )
737 .WriteInt32( i
+ 0x100 )
740 mpPptEscherEx
->CloseContainer(); // EPP_SlideListWithText
742 css::uno::Reference
< css::presentation::XPresentationSupplier
>
743 aXPresSupplier( mXModel
, css::uno::UNO_QUERY
);
744 if ( aXPresSupplier
.is() )
746 css::uno::Reference
< css::presentation::XPresentation
> aXPresentation( aXPresSupplier
->getPresentation() );
747 if ( aXPresentation
.is() )
749 mXPropSet
.set( aXPresentation
, css::uno::UNO_QUERY
);
750 if ( mXPropSet
.is() )
752 OUString aCustomShow
;
753 sal_uInt32
const nPenColor
= 0x1000000;
754 sal_Int32
const nRestartTime
= 0x7fffffff;
755 sal_Int16 nStartSlide
= 0;
756 sal_Int16 nEndSlide
= 0;
757 sal_uInt32 nFlags
= 0; // Bit 0: Auto advance
758 // Bit 1 Skip builds ( do not allow slide effects )
759 // Bit 2 Use slide range
760 // Bit 3 Use named show
761 // Bit 4 Browse mode on
762 // Bit 5 Kiosk mode on
763 // Bit 7 loop continuously
764 // Bit ? show scrollbar
766 if ( ImplGetPropertyValue( "CustomShow" ) )
768 aCustomShow
= *o3tl::doAccess
<OUString
>(mAny
);
769 if ( !aCustomShow
.isEmpty() )
774 if ( ( nFlags
& 8 ) == 0 )
776 if ( ImplGetPropertyValue( "FirstPage" ) )
778 auto aSlideName
= o3tl::doAccess
<OUString
>(mAny
);
780 std::vector
<OUString
>::const_iterator pIter
= std::find(
781 maSlideNameList
.begin(),maSlideNameList
.end(), *aSlideName
);
783 if (pIter
!= maSlideNameList
.end())
785 nStartSlide
= pIter
- maSlideNameList
.begin() + 1;
787 nEndSlide
= static_cast<sal_uInt16
>(mnPages
);
792 if ( ImplGetPropertyValue( "IsAutomatic" ) )
800 if ( ImplGetPropertyValue( "IsEndless" ) ) // the correct name would be IsNotEndless: WTF?
807 if ( ImplGetPropertyValue( "IsFullScreen" ) )
815 mpPptEscherEx
->AddAtom( 80, EPP_SSDocInfoAtom
, 1 );
816 mpStrm
->WriteUInt32( nPenColor
).WriteInt32( nRestartTime
).WriteInt16( nStartSlide
).WriteInt16( nEndSlide
);
818 sal_uInt32 nCustomShowNameLen
= aCustomShow
.getLength();
819 if ( nCustomShowNameLen
> 31 )
820 nCustomShowNameLen
= 31;
821 if ( nCustomShowNameLen
) // named show identifier
823 const sal_Unicode
* pCustomShow
= aCustomShow
.getStr();
824 for ( i
= 0; i
< nCustomShowNameLen
; i
++ )
826 mpStrm
->WriteUInt16( pCustomShow
[ i
] );
829 for ( i
= nCustomShowNameLen
; i
< 32; i
++, mpStrm
->WriteUInt16( 0 ) ) ;
831 mpStrm
->WriteUInt32( nFlags
);
832 css::uno::Reference
< css::presentation::XCustomPresentationSupplier
> aXCPSup( mXModel
, css::uno::UNO_QUERY
);
835 css::uno::Reference
< css::container::XNameContainer
> aXCont( aXCPSup
->getCustomPresentations() );
838 css::uno::Sequence
< OUString
> aNameSeq( aXCont
->getElementNames() );
839 if ( aNameSeq
.hasElements() )
841 mpPptEscherEx
->OpenContainer( EPP_NamedShows
);
842 sal_uInt32 nCustomShowIndex
= 0;
843 for( OUString
const & customShowName
: aNameSeq
)
845 if ( !customShowName
.isEmpty() )
847 mpPptEscherEx
->OpenContainer( EPP_NamedShow
, nCustomShowIndex
++ );
849 sal_uInt32 nNamedShowLen
= customShowName
.getLength();
850 if ( nNamedShowLen
> 31 )
852 mpPptEscherEx
->AddAtom( nNamedShowLen
<< 1, EPP_CString
);
853 const sal_Unicode
* pCustomShowName
= customShowName
.getStr();
854 for ( sal_uInt32 k
= 0; k
< nNamedShowLen
; ++k
)
855 mpStrm
->WriteUInt16( pCustomShowName
[ k
] );
856 mAny
= aXCont
->getByName( customShowName
);
857 css::uno::Reference
< css::container::XIndexContainer
> aXIC
;
860 mpPptEscherEx
->BeginAtom();
862 sal_Int32 nSlideCount
= aXIC
->getCount();
863 for ( sal_Int32 j
= 0; j
< nSlideCount
; j
++ ) // number of slides
865 mAny
= aXIC
->getByIndex( j
);
866 css::uno::Reference
< css::drawing::XDrawPage
> aXDrawPage
;
867 if ( mAny
>>= aXDrawPage
)
869 css::uno::Reference
< css::container::XNamed
> aXName( aXDrawPage
, css::uno::UNO_QUERY
);
872 OUString
aSlideName( aXName
->getName() );
873 std::vector
<OUString
>::const_iterator pIter
= std::find(
874 maSlideNameList
.begin(),maSlideNameList
.end(),aSlideName
);
876 if (pIter
!= maSlideNameList
.end())
878 sal_uInt32 nPageNumber
= pIter
- maSlideNameList
.begin();
879 mpStrm
->WriteUInt32( nPageNumber
+ 0x100 ); // unique slide id
884 mpPptEscherEx
->EndAtom( EPP_NamedShowSlides
);
886 mpPptEscherEx
->CloseContainer(); // EPP_NamedShow
889 mpPptEscherEx
->CloseContainer(); // EPP_NamedShows
896 mpPptEscherEx
->AddAtom( 0, EPP_EndDocument
);
897 mpPptEscherEx
->CloseContainer(); // EPP_Document
901 void PPTWriter::ImplCreateHyperBlob( SvMemoryStream
& rStrm
)
903 sal_uInt32 nCurrentOfs
, nParaOfs
, nParaCount
= 0;
905 nParaOfs
= rStrm
.Tell();
906 rStrm
.WriteUInt32( 0 ); // property size
907 rStrm
.WriteUInt32( 0 ); // property count
909 for ( const auto& rHyperlink
: maHyperlink
)
912 rStrm
.WriteUInt32( 3 ) // Type VT_I4
913 .WriteUInt32( 7 ) // (VTI4 - Private1)
914 .WriteUInt32( 3 ) // Type VT_I4
915 .WriteUInt32( 6 ) // (VTI4 - Private2)
916 .WriteUInt32( 3 ) // Type VT_I4
917 .WriteUInt32( 0 ); // (VTI4 - Private3)
920 // HIWORD: = 0 : do not change anything
921 // = 1 : replace the hyperlink with the target and subaddress in the following two VTLPWSTR
922 // = 2 : delete the hyperlink
923 // LOWORD: = 0 : graphic shown as background (link)
924 // = 1 : graphic shown as shape (link)
925 // = 2 : graphic is used to fill a shape
926 // = 3 : graphic used to fill a shape outline (future use)
927 // = 4 : hyperlink attached to a shape
928 // = 5 : " " " " (Word) field
929 // = 6 : " " " " (Excel) range
930 // = 7 : " " " " (PPT) text range
931 // = 8 : " " " " (Project) task
933 sal_Int32 nUrlLen
= rHyperlink
.aURL
.getLength();
934 const OUString
& rUrl
= rHyperlink
.aURL
;
936 sal_uInt32
const nInfo
= 7;
938 rStrm
.WriteUInt32( 3 ) // Type VT_I4
939 .WriteUInt32( nInfo
); // Info
941 switch( rHyperlink
.nType
& 0xff )
943 case 1 : // click action to slidenumber
945 rStrm
.WriteUInt32( 0x1f ).WriteUInt32( 1 ).WriteUInt32( 0 ); // path
946 rStrm
.WriteUInt32( 0x1f ).WriteUInt32( nUrlLen
+ 1 );
947 for ( sal_Int32 i
= 0; i
< nUrlLen
; i
++ )
949 rStrm
.WriteUInt16( rUrl
[ i
] );
951 rStrm
.WriteUInt16( 0 );
958 rStrm
.WriteUInt32( 0x1f )
959 .WriteUInt32( nUrlLen
+ 1 );
960 for ( i
= 0; i
< nUrlLen
; i
++ )
962 rStrm
.WriteUInt16( rUrl
[ i
] );
965 rStrm
.WriteUInt16( 0 );
966 rStrm
.WriteUInt16( 0 )
974 nCurrentOfs
= rStrm
.Tell();
975 rStrm
.Seek( nParaOfs
);
976 rStrm
.WriteUInt32( nCurrentOfs
- ( nParaOfs
+ 4 ) );
977 rStrm
.WriteUInt32( nParaCount
);
978 rStrm
.Seek( nCurrentOfs
);
981 bool PPTWriter::ImplCreateMainNotes()
983 EscherSolverContainer aSolverContainer
;
985 mpPptEscherEx
->PtReplaceOrInsert( EPP_Persist_MainNotes
, mpStrm
->Tell() );
986 mpPptEscherEx
->OpenContainer( EPP_Notes
);
987 mpPptEscherEx
->AddAtom( 8, EPP_NotesAtom
, 1 );
988 mpStrm
->WriteUInt32( 0x80000001 ) // Number that identifies this slide
989 .WriteUInt32( 0 ); // follow nothing
990 mpPptEscherEx
->OpenContainer( EPP_PPDrawing
);
991 mpPptEscherEx
->OpenContainer( ESCHER_DgContainer
);
992 mpPptEscherEx
->EnterGroup(nullptr,nullptr);
994 ImplWritePage( GetLayout( 20 ), aSolverContainer
, NOTICE
, true );
996 mpPptEscherEx
->LeaveGroup();
997 mpPptEscherEx
->OpenContainer( ESCHER_SpContainer
);
998 mpPptEscherEx
->AddShape( ESCHER_ShpInst_Rectangle
, ShapeFlag::Background
| ShapeFlag::HaveShapeProperty
);
999 EscherPropertyContainer aPropOpt
;
1000 aPropOpt
.AddOpt( ESCHER_Prop_fillColor
, 0xffffff ); // stock valued fill color
1001 aPropOpt
.AddOpt( ESCHER_Prop_fillBackColor
, 0 );
1002 aPropOpt
.AddOpt( ESCHER_Prop_fillRectRight
, 0x68bdde );
1003 aPropOpt
.AddOpt( ESCHER_Prop_fillRectBottom
, 0x8b9f8e );
1004 aPropOpt
.AddOpt( ESCHER_Prop_fNoFillHitTest
, 0x120012 );
1005 aPropOpt
.AddOpt( ESCHER_Prop_fNoLineDrawDash
, 0 );
1006 aPropOpt
.AddOpt( ESCHER_Prop_bWMode
, ESCHER_wDontShow
);
1007 aPropOpt
.AddOpt( ESCHER_Prop_fBackground
, 0x10001 ); // if true, this is the background shape
1008 aPropOpt
.Commit( *mpStrm
);
1009 mpPptEscherEx
->CloseContainer(); // ESCHER_SpContainer
1011 aSolverContainer
.WriteSolver( *mpStrm
);
1013 mpPptEscherEx
->CloseContainer(); // ESCHER_DgContainer
1014 mpPptEscherEx
->CloseContainer(); // EPP_Drawing
1015 mpPptEscherEx
->AddAtom( 32, EPP_ColorSchemeAtom
, 0, 1 );
1016 mpStrm
->WriteUInt32( 0xffffff ).WriteUInt32( 0x000000 ).WriteUInt32( 0x808080 ).WriteUInt32( 0x000000 ).WriteUInt32( 0x99cc00 ).WriteUInt32( 0xcc3333 ).WriteUInt32( 0xffcccc ).WriteUInt32( 0xb2b2b2 );
1017 mpPptEscherEx
->CloseContainer(); // EPP_Notes
1021 static OUString
getInitials( const OUString
& rName
)
1023 OUStringBuffer sInitials
;
1025 const sal_Unicode
* pStr
= rName
.getStr();
1026 sal_Int32 nLength
= rName
.getLength();
1031 while( nLength
&& (*pStr
<= ' ') )
1039 sInitials
.append( *pStr
);
1043 // skip letters until whitespace
1044 while( nLength
&& (*pStr
> ' ') )
1050 return sInitials
.makeStringAndClear();
1053 void ImplExportComments( const uno::Reference
< drawing::XDrawPage
>& xPage
, SvMemoryStream
& rBinaryTagData10Atom
)
1057 uno::Reference
< office::XAnnotationAccess
> xAnnotationAccess( xPage
, uno::UNO_QUERY_THROW
);
1058 uno::Reference
< office::XAnnotationEnumeration
> xAnnotationEnumeration( xAnnotationAccess
->createAnnotationEnumeration() );
1060 sal_Int32 nIndex
= 1;
1062 while( xAnnotationEnumeration
->hasMoreElements() )
1064 EscherExContainer
aComment10( rBinaryTagData10Atom
, EPP_Comment10
);
1066 uno::Reference
< office::XAnnotation
> xAnnotation( xAnnotationEnumeration
->nextElement() );
1068 geometry::RealPoint2D
aRealPoint2D( xAnnotation
->getPosition() );
1069 MapMode
aMapDest( MapUnit::MapInch
, Point(), Fraction( 1, 576 ), Fraction( 1, 576 ) );
1070 Point
aPoint( OutputDevice::LogicToLogic( Point( static_cast< sal_Int32
>( aRealPoint2D
.X
* 100.0 ),
1071 static_cast<sal_Int32
>(aRealPoint2D
.Y
* 100.0)), MapMode(MapUnit::Map100thMM
), aMapDest
));
1073 OUString
sAuthor( xAnnotation
->getAuthor() );
1074 uno::Reference
< text::XText
> xText( xAnnotation
->getTextRange() );
1075 OUString
sText( xText
->getString() );
1076 OUString
sInitials( getInitials( sAuthor
) );
1077 util::DateTime
aDateTime( xAnnotation
->getDateTime() );
1078 if ( !sAuthor
.isEmpty() )
1079 PPTWriter::WriteCString( rBinaryTagData10Atom
, sAuthor
);
1080 if ( !sText
.isEmpty() )
1081 PPTWriter::WriteCString( rBinaryTagData10Atom
, sText
, 1 );
1082 if ( !sInitials
.isEmpty() )
1083 PPTWriter::WriteCString( rBinaryTagData10Atom
, sInitials
, 2 );
1085 sal_Int16 nMilliSeconds
= static_cast<sal_Int16
>(::rtl::math::round(static_cast<double>(aDateTime
.NanoSeconds
) / 1000000000.0));
1086 EscherExAtom
aCommentAtom10( rBinaryTagData10Atom
, EPP_CommentAtom10
);
1087 rBinaryTagData10Atom
.WriteInt32( nIndex
++ )
1088 .WriteInt16( aDateTime
.Year
)
1089 .WriteUInt16( aDateTime
.Month
)
1090 .WriteUInt16( aDateTime
.Day
) // todo: day of week
1091 .WriteUInt16( aDateTime
.Day
)
1092 .WriteUInt16( aDateTime
.Hours
)
1093 .WriteUInt16( aDateTime
.Minutes
)
1094 .WriteUInt16( aDateTime
.Seconds
)
1095 .WriteInt16( nMilliSeconds
)
1096 .WriteInt32( aPoint
.X() )
1097 .WriteInt32( aPoint
.Y() );
1101 catch ( uno::Exception
& )
1106 void PPTWriter::ImplWriteNotes( sal_uInt32 nPageNum
)
1108 mpPptEscherEx
->PtReplaceOrInsert( EPP_Persist_Notes
| nPageNum
, mpStrm
->Tell() );
1109 mpPptEscherEx
->OpenContainer( EPP_Notes
);
1110 mpPptEscherEx
->AddAtom( 8, EPP_NotesAtom
, 1 );
1111 mpStrm
->WriteUInt32( nPageNum
+ 0x100 )
1112 .WriteUInt16( 3 ) // follow master ....
1115 ImplCreateHeaderFooters( mXPagePropSet
);
1117 EscherSolverContainer aSolverContainer
;
1119 mpPptEscherEx
->OpenContainer( EPP_PPDrawing
);
1120 mpPptEscherEx
->OpenContainer( ESCHER_DgContainer
);
1121 mpPptEscherEx
->EnterGroup(nullptr,nullptr);
1123 ImplWritePage( GetLayout( 20 ), aSolverContainer
, NOTICE
, false ); // the shapes of the pages are created in the PPT document
1125 mpPptEscherEx
->LeaveGroup();
1126 mpPptEscherEx
->OpenContainer( ESCHER_SpContainer
);
1127 mpPptEscherEx
->AddShape( ESCHER_ShpInst_Rectangle
, ShapeFlag::Background
| ShapeFlag::HaveShapeProperty
);
1128 EscherPropertyContainer aPropOpt
;
1129 aPropOpt
.AddOpt( ESCHER_Prop_fillColor
, 0xffffff ); // stock valued fill color
1130 aPropOpt
.AddOpt( ESCHER_Prop_fillBackColor
, 0 );
1131 aPropOpt
.AddOpt( ESCHER_Prop_fillRectRight
, 0x8b9f8e );
1132 aPropOpt
.AddOpt( ESCHER_Prop_fillRectBottom
, 0x68bdde );
1133 aPropOpt
.AddOpt( ESCHER_Prop_fNoFillHitTest
, 0x120012 );
1134 aPropOpt
.AddOpt( ESCHER_Prop_fNoLineDrawDash
, 0x80000 );
1135 aPropOpt
.AddOpt( ESCHER_Prop_bWMode
, ESCHER_wDontShow
);
1136 aPropOpt
.AddOpt( ESCHER_Prop_fBackground
, 0x10001 );
1137 aPropOpt
.Commit( *mpStrm
);
1138 mpPptEscherEx
->CloseContainer(); // ESCHER_SpContainer
1140 aSolverContainer
.WriteSolver( *mpStrm
);
1142 mpPptEscherEx
->CloseContainer(); // ESCHER_DgContainer
1143 mpPptEscherEx
->CloseContainer(); // EPP_Drawing
1144 mpPptEscherEx
->AddAtom( 32, EPP_ColorSchemeAtom
, 0, 1 );
1145 mpStrm
->WriteUInt32( 0xffffff ).WriteUInt32( 0x000000 ).WriteUInt32( 0x808080 ).WriteUInt32( 0x000000 ).WriteUInt32( 0x99cc00 ).WriteUInt32( 0xcc3333 ).WriteUInt32( 0xffcccc ).WriteUInt32( 0xb2b2b2 );
1146 mpPptEscherEx
->CloseContainer(); // EPP_Notes
1149 void PPTWriter::ImplWriteBackground( css::uno::Reference
< css::beans::XPropertySet
> const & rXPropSet
)
1151 //************************ ******
1152 //** DEFAULT BACKGROUND SHAPE **
1154 sal_uInt32 nFillColor
= 0xffffff;
1155 sal_uInt32 nFillBackColor
= 0;
1157 mpPptEscherEx
->OpenContainer( ESCHER_SpContainer
);
1158 mpPptEscherEx
->AddShape( ESCHER_ShpInst_Rectangle
, ShapeFlag::Background
| ShapeFlag::HaveShapeProperty
);
1160 // #i121183# Use real PageSize in 100th mm
1161 ::tools::Rectangle
aRect(Point(0, 0), Size(maPageSize
.Width
, maPageSize
.Height
));
1163 EscherPropertyContainer
aPropOpt( mpPptEscherEx
->GetGraphicProvider(), mpPicStrm
.get(), aRect
);
1164 aPropOpt
.AddOpt( ESCHER_Prop_fillType
, ESCHER_FillSolid
);
1165 css::drawing::FillStyle
aFS( css::drawing::FillStyle_NONE
);
1166 if ( ImplGetPropertyValue( rXPropSet
, "FillStyle" ) )
1171 case css::drawing::FillStyle_GRADIENT
:
1173 aPropOpt
.CreateGradientProperties( rXPropSet
);
1174 aPropOpt
.AddOpt( ESCHER_Prop_fNoFillHitTest
, 0x1f001e );
1175 aPropOpt
.GetOpt( ESCHER_Prop_fillColor
, nFillColor
);
1176 aPropOpt
.GetOpt( ESCHER_Prop_fillBackColor
, nFillBackColor
);
1180 case css::drawing::FillStyle_BITMAP
:
1181 aPropOpt
.CreateGraphicProperties( rXPropSet
, "FillBitmap", true );
1184 case css::drawing::FillStyle_HATCH
:
1185 aPropOpt
.CreateGraphicProperties( rXPropSet
, "FillHatch", true );
1188 case css::drawing::FillStyle_SOLID
:
1190 if ( ImplGetPropertyValue( rXPropSet
, "FillColor" ) )
1192 nFillColor
= EscherEx::GetColor( *o3tl::doAccess
<sal_uInt32
>(mAny
) );
1193 nFillBackColor
= nFillColor
^ 0xffffff;
1197 case css::drawing::FillStyle_NONE
:
1199 aPropOpt
.AddOpt( ESCHER_Prop_fNoFillHitTest
, 0x120012 );
1202 aPropOpt
.AddOpt( ESCHER_Prop_fillColor
, nFillColor
);
1203 aPropOpt
.AddOpt( ESCHER_Prop_fillBackColor
, nFillBackColor
);
1204 aPropOpt
.AddOpt( ESCHER_Prop_fillRectRight
, PPTtoEMU( maDestPageSize
.Width
) );
1205 aPropOpt
.AddOpt( ESCHER_Prop_fillRectBottom
, PPTtoEMU( maDestPageSize
.Height
) );
1206 aPropOpt
.AddOpt( ESCHER_Prop_fNoLineDrawDash
, 0x80000 );
1207 aPropOpt
.AddOpt( ESCHER_Prop_bWMode
, ESCHER_bwWhite
);
1208 aPropOpt
.AddOpt( ESCHER_Prop_fBackground
, 0x10001 );
1209 aPropOpt
.Commit( *mpStrm
);
1210 mpPptEscherEx
->CloseContainer(); // ESCHER_SpContainer
1213 void PPTWriter::ImplWriteVBA()
1217 sal_uInt32 nLen
= mpVBA
->TellEnd();
1221 mnVBAOleOfs
= mpStrm
->Tell();
1222 mpPptEscherEx
->BeginAtom();
1223 mpStrm
->WriteBytes(static_cast<sal_Int8
const *>(mpVBA
->GetData()) + 8, nLen
);
1224 mpPptEscherEx
->EndAtom( EPP_ExOleObjStg
, 0, 1 );
1229 void PPTWriter::ImplWriteOLE( )
1232 SvxMSExportOLEObjects
aOleExport( mnCnvrtFlags
);
1234 for ( auto& rxExOleObjEntry
: maExOleObj
)
1236 PPTExOleObjEntry
* pPtr
= rxExOleObjEntry
.get();
1237 std::unique_ptr
<SvMemoryStream
> pStrm
;
1238 pPtr
->nOfsB
= mpStrm
->Tell();
1239 switch ( pPtr
->eType
)
1241 case NORMAL_OLE_OBJECT
:
1243 SdrObject
* pSdrObj
= GetSdrObjectFromXShape( pPtr
->xShape
);
1244 if ( auto pSdrOle2Obj
= dynamic_cast< SdrOle2Obj
* >(pSdrObj
) )
1246 const ::uno::Reference
< embed::XEmbeddedObject
>& xObj( pSdrOle2Obj
->GetObjRef() );
1249 tools::SvRef
<SotStorage
> xTempStorage( new SotStorage( new SvMemoryStream(), true ) );
1250 aOleExport
.ExportOLEObject( xObj
, *xTempStorage
);
1253 SvMemoryStream aStream
;
1254 tools::SvRef
<SotStorage
> xCleanStorage( new SotStorage( false, aStream
) );
1255 xTempStorage
->CopyTo( xCleanStorage
.get() );
1256 // create a dummy content stream, the dummy content is necessary for ppt, but not for
1257 // doc files, so we can't share code.
1258 tools::SvRef
<SotStorageStream
> xStm
= xCleanStorage
->OpenSotStream( SVEXT_PERSIST_STREAM
);
1259 xStm
->WriteUInt32( 0 ) // no ClipboardId
1260 .WriteUInt32( 4 ) // no target device
1261 .WriteUInt32( 1 ) // aspect ratio
1262 .WriteInt32( -1 ) // L-Index
1263 .WriteUInt32( 0 ) // Advanced Flags
1264 .WriteUInt32( 0 ) // compression
1265 .WriteUInt32( 0 ) // Size
1266 .WriteUInt32( 0 ) // "
1268 pStrm
= xCleanStorage
->CreateMemoryStream();
1276 if ( pPtr
->xControlModel
.is() )
1279 //Initialize the graphic size which will be used on export
1280 css::awt::Size
aSize( pPtr
->xShape
->getSize() );
1281 tools::SvRef
<SotStorage
> xDest( new SotStorage( new SvMemoryStream(), true ) );
1282 bool bOk
= oox::ole::MSConvertOCXControls::WriteOCXStream( mXModel
, xDest
, pPtr
->xControlModel
, aSize
, aName
);
1284 pStrm
= xDest
->CreateMemoryStream();
1290 mpPptEscherEx
->BeginAtom();
1291 pStrm
->Seek( STREAM_SEEK_TO_END
);
1292 sal_uInt32 npStrmSize
= pStrm
->Tell();
1293 mpStrm
->WriteUInt32( npStrmSize
); // uncompressed size
1296 ZCodec
aZCodec( 0x8000, 0x8000 );
1297 aZCodec
.BeginCompression();
1298 aZCodec
.Compress( *pStrm
, *mpStrm
);
1299 aZCodec
.EndCompression();
1301 mpPptEscherEx
->EndAtom( EPP_ExOleObjStg
, 0, 1 );
1306 // write PersistantTable and UserEditAtom
1308 void PPTWriter::ImplWriteAtomEnding()
1311 #define EPP_LastViewTypeSlideView 1
1313 sal_uInt32 i
, nPos
, nOfs
, nPersistOfs
= mpStrm
->Tell();
1314 sal_uInt32 nPersistEntrys
= 0;
1315 mpStrm
->WriteUInt32( 0 ).WriteUInt32( 0 ).WriteUInt32( 0 ); // skip record header and first entry
1317 // write document persist
1319 mpStrm
->WriteUInt32( 0 );
1320 // write MasterPages persists
1321 for ( i
= 0; i
< mnMasterPages
; i
++ )
1323 nOfs
= mpPptEscherEx
->PtGetOffsetByID( EPP_Persist_MainMaster
| i
);
1326 mpStrm
->WriteUInt32( nOfs
);
1327 mpPptEscherEx
->InsertAtPersistOffset( EPP_MAINMASTER_PERSIST_KEY
| i
, ++nPersistEntrys
);
1330 // write MainNotesMaster persist
1331 nOfs
= mpPptEscherEx
->PtGetOffsetByID( EPP_Persist_MainNotes
);
1334 mpStrm
->WriteUInt32( nOfs
);
1335 mpPptEscherEx
->InsertAtPersistOffset( EPP_MAINNOTESMASTER_PERSIST_KEY
, ++nPersistEntrys
);
1337 // write slide persists -> we have to write a valid value into EPP_SlidePersistAtome too
1338 for ( i
= 0; i
< mnPages
; i
++ )
1340 nOfs
= mpPptEscherEx
->PtGetOffsetByID( EPP_Persist_Slide
| i
);
1343 mpStrm
->WriteUInt32( nOfs
);
1344 mpPptEscherEx
->InsertAtPersistOffset( EPP_MAINSLIDE_PERSIST_KEY
| i
, ++nPersistEntrys
);
1347 // write Notes persists
1348 for ( i
= 0; i
< mnPages
; i
++ )
1350 nOfs
= mpPptEscherEx
->PtGetOffsetByID( EPP_Persist_Notes
| i
);
1353 mpStrm
->WriteUInt32( nOfs
);
1354 mpPptEscherEx
->InsertAtPersistOffset( EPP_MAINNOTES_PERSIST_KEY
| i
, ++nPersistEntrys
);
1358 for ( auto& rxExOleObjEntry
: maExOleObj
)
1360 PPTExOleObjEntry
* pPtr
= rxExOleObjEntry
.get();
1361 nOfs
= mpPptEscherEx
->PtGetOffsetByID( EPP_Persist_ExObj
);
1365 mpStrm
->WriteUInt32( pPtr
->nOfsB
);
1366 sal_uInt32 nOldPos
, nPersOfs
= nOfs
+ pPtr
->nOfsA
+ 16 + 8; // 8 bytes atom header, +16 to the persist entry
1367 nOldPos
= mpStrm
->Tell();
1368 mpStrm
->Seek( nPersOfs
);
1369 mpStrm
->WriteUInt32( nPersistEntrys
);
1370 mpStrm
->Seek( nOldPos
);
1374 if ( mnVBAOleOfs
&& mpVBA
)
1376 nOfs
= mpPptEscherEx
->PtGetOffsetByID( EPP_Persist_VBAInfoAtom
);
1383 mpVBA
->ReadUInt32( n1
)
1386 mpStrm
->WriteUInt32( mnVBAOleOfs
);
1387 sal_uInt32 nOldPos
= mpStrm
->Tell();
1388 mpStrm
->Seek( nOfs
); // Fill the VBAInfoAtom with the correct index to the persisttable
1389 mpStrm
->WriteUInt32( nPersistEntrys
)
1392 mpStrm
->Seek( nOldPos
);
1396 nPos
= mpStrm
->Tell();
1397 mpStrm
->Seek( nPersistOfs
);
1398 mpPptEscherEx
->AddAtom( ( nPersistEntrys
+ 1 ) << 2, EPP_PersistPtrIncrementalBlock
); // insert Record Header
1399 mpStrm
->WriteUInt32( ( nPersistEntrys
<< 20 ) | 1 );
1400 mpStrm
->Seek( nPos
);
1402 mpCurUserStrm
->WriteUInt32( nPos
); // set offset to current edit
1403 mpPptEscherEx
->AddAtom( 28, EPP_UserEditAtom
);
1404 mpStrm
->WriteInt32( 0x100 ) // last slide ID
1405 .WriteUInt32( 0x03000dbc ) // minor and major app version that did the save
1406 .WriteUInt32( 0 ) // offset last save, 0 after a full save
1407 .WriteUInt32( nPersistOfs
) // File offset to persist pointers for this save operation
1408 .WriteUInt32( 1 ) // Persist reference to the document persist object
1409 .WriteUInt32( nPersistEntrys
) // max persists written, Seed value for persist object id management
1410 .WriteInt16( EPP_LastViewTypeSlideView
) // last view type
1411 .WriteInt16( 0x12 ); // padword
1414 // - exported function -
1416 extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool
ExportPPT( const std::vector
< css::beans::PropertyValue
>& rMediaData
,
1417 tools::SvRef
<SotStorage
> const & rSvStorage
,
1418 css::uno::Reference
< css::frame::XModel
> const & rXModel
,
1419 css::uno::Reference
< css::task::XStatusIndicator
> const & rXStatInd
,
1420 SvMemoryStream
* pVBA
,
1421 sal_uInt32 nCnvrtFlags
)
1423 std::unique_ptr
<PPTWriter
> pPPTWriter(new PPTWriter( rSvStorage
, rXModel
, rXStatInd
, pVBA
, nCnvrtFlags
));
1424 pPPTWriter
->exportPPT(rMediaData
);
1425 bool bStatus
= pPPTWriter
->IsValid();
1429 extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool
SaveVBA( SfxObjectShell
& rDocShell
, SvMemoryStream
*& pBas
)
1431 tools::SvRef
<SotStorage
> xDest( new SotStorage( new SvMemoryStream(), true ) );
1432 SvxImportMSVBasic
aMSVBas( rDocShell
, *xDest
);
1433 aMSVBas
.SaveOrDelMSVBAStorage( true, "_MS_VBA_Overhead" );
1435 tools::SvRef
<SotStorage
> xOverhead
= xDest
->OpenSotStorage( "_MS_VBA_Overhead" );
1436 if ( xOverhead
.is() && ( xOverhead
->GetError() == ERRCODE_NONE
) )
1438 tools::SvRef
<SotStorage
> xOverhead2
= xOverhead
->OpenSotStorage( "_MS_VBA_Overhead" );
1439 if ( xOverhead2
.is() && ( xOverhead2
->GetError() == ERRCODE_NONE
) )
1441 tools::SvRef
<SotStorageStream
> xTemp
= xOverhead2
->OpenSotStream( "_MS_VBA_Overhead2" );
1442 if ( xTemp
.is() && ( xTemp
->GetError() == ERRCODE_NONE
) )
1444 sal_uInt32 nLen
= xTemp
->GetSize();
1447 char* pTemp
= new char[ nLen
];
1448 xTemp
->Seek( STREAM_SEEK_TO_BEGIN
);
1449 xTemp
->ReadBytes(pTemp
, nLen
);
1450 pBas
= new SvMemoryStream( pTemp
, nLen
, StreamMode::READ
);
1451 pBas
->ObjectOwnsMemory( true );
1461 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */