1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <com/sun/star/drawing/XDrawPage.hpp>
#include <com/sun/star/drawing/XShapes.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <oox/ppt/timenode.hxx>
#include <oox/ppt/pptshape.hxx>
#include <oox/ppt/pptimport.hxx>
#include <oox/ppt/slidepersist.hxx>
#include <drawingml/fillproperties.hxx>
#include <oox/drawingml/shapepropertymap.hxx>
#include <oox/helper/propertymap.hxx>
#include <oox/helper/propertyset.hxx>
#include <oox/vml/vmldrawing.hxx>
#include <oox/token/properties.hxx>
#include <oox/token/tokens.hxx>
#include <oox/core/xmlfilterbase.hxx>
#include <drawingml/textliststyle.hxx>
#include <drawingml/textparagraphproperties.hxx>
#include <drawingml/textbody.hxx>
#include <osl/diagnose.h>
#include <com/sun/star/style/XStyle.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/container/XNamed.hpp>
#include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
using namespace ::com::sun::star;
using namespace ::oox::core;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::drawing;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::animations;
namespace oox::ppt {
std::vector< PPTShape* > PowerPointImport::maPPTShapes;
SlidePersist::SlidePersist( XmlFilterBase& rFilter, bool bMaster, bool bNotes,
const css::uno::Reference< css::drawing::XDrawPage >& rxPage,
oox::drawingml::ShapePtr const & pShapesPtr, const drawingml::TextListStylePtr & pDefaultTextStyle )
: mpDrawingPtr( std::make_shared<oox::vml::Drawing>( rFilter, rxPage, oox::vml::VMLDRAWING_POWERPOINT ) )
, mxPage( rxPage )
, maShapesPtr( pShapesPtr )
, mnLayoutValueToken( 0 )
, mbMaster( bMaster )
, mbNotes ( bNotes )
, maDefaultTextStylePtr( pDefaultTextStyle )
, maTitleTextStylePtr( std::make_shared<oox::drawingml::TextListStyle>() )
, maBodyTextStylePtr( std::make_shared<oox::drawingml::TextListStyle>() )
, maNotesTextStylePtr( std::make_shared<oox::drawingml::TextListStyle>() )
, maOtherTextStylePtr( std::make_shared<oox::drawingml::TextListStyle>() )
{
#if OSL_DEBUG_LEVEL > 0
mxDebugPage = mxPage;
#endif
}
#if OSL_DEBUG_LEVEL > 0
css::uno::WeakReference< css::drawing::XDrawPage > SlidePersist::mxDebugPage;
#endif
SlidePersist::~SlidePersist()
{
}
sal_Int16 SlidePersist::getLayoutFromValueToken() const
{
sal_Int16 nLayout = 20; // 20 == blanc (so many magic numbers :-( the description at com.sun.star.presentation.DrawPage.Layout does not help)
switch( mnLayoutValueToken )
{
case XML_blank: nLayout = 20; break;
case XML_chart: nLayout = 2; break;
case XML_chartAndTx: nLayout = 7; break;
case XML_clipArtAndTx: nLayout = 9; break;
case XML_clipArtAndVertTx: nLayout = 24; break;
case XML_fourObj: nLayout = 18; break;
case XML_obj: nLayout = 11; break;
case XML_objAndTx: nLayout = 13; break;
case XML_objOverTx: nLayout = 14; break;
case XML_tbl: nLayout = 8; break;
case XML_title: nLayout = 0; break;
case XML_titleOnly: nLayout = 19; break;
case XML_twoObj:
case XML_twoColTx: nLayout = 3; break;
case XML_twoObjAndTx: nLayout = 15; break;
case XML_twoObjOverTx: nLayout = 16; break;
case XML_tx: nLayout = 1; break;
case XML_txAndChart: nLayout = 4; break;
case XML_txAndClipArt: nLayout = 6; break;
case XML_txAndMedia: nLayout = 6; break;
case XML_txAndObj: nLayout = 10; break;
case XML_txAndTwoObj: nLayout = 12; break;
case XML_txOverObj: nLayout = 17; break;
case XML_vertTitleAndTx: nLayout = 22; break;
case XML_vertTitleAndTxOverChart: nLayout = 21; break;
case XML_vertTx: nLayout = 23; break;
case XML_twoTxTwoObj:
case XML_twoObjAndObj:
case XML_objTx:
case XML_picTx:
case XML_secHead:
case XML_objOnly:
case XML_objAndTwoObj:
case XML_mediaAndTx:
case XML_dgm:
case XML_cust:
default:
nLayout = 20;
}
return nLayout;
}
static bool hasSameSubTypeIndex(sal_Int32 checkSubTypeIndex)
{
sal_Int32 nSubTypeIndex = -1;
for(PPTShape* pPPTShape : PowerPointImport::maPPTShapes)
{
if(!pPPTShape->getSubTypeIndex().has())
continue;
nSubTypeIndex = pPPTShape->getSubTypeIndex().get();
if( nSubTypeIndex == checkSubTypeIndex )
return true;
}
return false;
}
void SlidePersist::createXShapes( XmlFilterBase& rFilterBase )
{
applyTextStyles( rFilterBase );
Reference< XShapes > xShapes( getPage() );
std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
bool bhasSameSubTypeIndex = false;
sal_Int32 nNumCol = 1;
for (auto const& shape : rShapes)
{
std::vector< oox::drawingml::ShapePtr >& rChildren( shape->getChildren() );
for (auto const& child : rChildren)
{
PPTShape* pPPTShape = dynamic_cast< PPTShape* >( child.get() );
basegfx::B2DHomMatrix aTransformation;
if ( pPPTShape )
{
bhasSameSubTypeIndex = hasSameSubTypeIndex( pPPTShape->getSubTypeIndex().get());
if(pPPTShape->getTextBody())
nNumCol = pPPTShape->getTextBody()->getTextProperties().mnNumCol;
if(pPPTShape->getSubTypeIndex().has() && nNumCol > 1 )
PowerPointImport::maPPTShapes.push_back(pPPTShape);
pPPTShape->addShape( rFilterBase, *this, getTheme().get(), xShapes, aTransformation, &getShapeMap(), bhasSameSubTypeIndex );
}
else
child->addShape( rFilterBase, getTheme().get(), xShapes, aTransformation, maShapesPtr->getFillProperties(), &getShapeMap() );
}
}
Reference< XAnimationNodeSupplier > xNodeSupplier( getPage(), UNO_QUERY);
if( !xNodeSupplier.is() )
return;
Reference< XAnimationNode > xNode( xNodeSupplier->getAnimationNode() );
if( xNode.is() && !maTimeNodeList.empty() )
{
SlidePersistPtr pSlidePtr( shared_from_this() );
TimeNodePtr pNode(maTimeNodeList.front());
OSL_ENSURE( pNode, "pNode" );
Reference<XAnimationNode> xDummy;
pNode->setNode(rFilterBase, xNode, pSlidePtr, xDummy);
}
}
void SlidePersist::createBackground( const XmlFilterBase& rFilterBase )
{
if ( mpBackgroundPropertiesPtr )
{
::Color nPhClr = maBackgroundColor.isUsed() ?
maBackgroundColor.getColor( rFilterBase.getGraphicHelper() ) : API_RGB_TRANSPARENT;
oox::drawingml::ShapePropertyIds aPropertyIds = oox::drawingml::ShapePropertyInfo::DEFAULT.mrPropertyIds;
aPropertyIds[oox::drawingml::ShapeProperty::FillGradient] = PROP_FillGradientName;
oox::drawingml::ShapePropertyInfo aPropInfo( aPropertyIds, true, false, true, false, false );
oox::drawingml::ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper(), aPropInfo );
mpBackgroundPropertiesPtr->pushToPropMap( aPropMap, rFilterBase.getGraphicHelper(), 0, nPhClr );
PropertySet( mxPage ).setProperty( PROP_Background, aPropMap.makePropertySet() );
}
}
static void setTextStyle( Reference< beans::XPropertySet > const & rxPropSet, const XmlFilterBase& rFilter,
oox::drawingml::TextListStylePtr const & pTextListStylePtr, int nLevel )
{
::oox::drawingml::TextParagraphPropertiesPtr pTextParagraphPropertiesPtr( pTextListStylePtr->getListStyle()[ nLevel ] );
if( pTextParagraphPropertiesPtr == nullptr )
{
// no properties. return
return;
}
PropertyMap& rTextParagraphPropertyMap( pTextParagraphPropertiesPtr->getTextParagraphPropertyMap() );
PropertySet aPropSet( rxPropSet );
aPropSet.setProperties( rTextParagraphPropertyMap );
pTextParagraphPropertiesPtr->getTextCharacterProperties().pushToPropSet( aPropSet, rFilter );
}
void SlidePersist::applyTextStyles( const XmlFilterBase& rFilterBase )
{
if ( !mbMaster )
return;
try
{
Reference< style::XStyleFamiliesSupplier > aXStyleFamiliesSupplier( rFilterBase.getModel(), UNO_QUERY_THROW );
Reference< container::XNameAccess > aXNameAccess( aXStyleFamiliesSupplier->getStyleFamilies() );
Reference< container::XNamed > aXNamed( mxPage, UNO_QUERY_THROW );
if ( aXNameAccess.is() )
{
oox::drawingml::TextListStylePtr pTextListStylePtr;
OUString aStyle;
OUString aFamily;
const OUString sOutline( "outline1" );
const OUString sTitle( "title" );
const OUString sStandard( "standard" );
const OUString sSubtitle( "subtitle" );
for( int i = 0; i < 4; i++ ) // todo: aggregation of bodystyle (subtitle)
{
switch( i )
{
case 0 : // title style
{
pTextListStylePtr = maTitleTextStylePtr;
aStyle = sTitle;
aFamily= aXNamed->getName();
break;
}
case 1 : // body style
{
pTextListStylePtr = maBodyTextStylePtr;
aStyle = sOutline;
aFamily= aXNamed->getName();
break;
}
case 3 : // notes style
{
pTextListStylePtr = maNotesTextStylePtr;
aStyle = sTitle;
aFamily= aXNamed->getName();
break;
}
case 4 : // standard style
{
pTextListStylePtr = maOtherTextStylePtr;
aStyle = sStandard;
aFamily = "graphics";
break;
}
case 5 : // subtitle
{
pTextListStylePtr = maBodyTextStylePtr;
aStyle = sSubtitle;
aFamily = aXNamed->getName();
break;
}
}
Reference< container::XNameAccess > xFamilies;
if ( aXNameAccess->hasByName( aFamily ) )
{
if( aXNameAccess->getByName( aFamily ) >>= xFamilies )
{
if ( xFamilies->hasByName( aStyle ) )
{
Reference< style::XStyle > aXStyle;
if ( xFamilies->getByName( aStyle ) >>= aXStyle )
{
Reference< beans::XPropertySet > xPropSet( aXStyle, UNO_QUERY_THROW );
setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, 0 );
setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, 0 );
if ( i == 1 /* BodyStyle */ )
{
for ( int nLevel = 1; nLevel < 5; nLevel++ )
{
{
char pOutline[ 9 ] = "outline1";
pOutline[ 7 ] = static_cast< char >( '0' + nLevel );
OUString sOutlineStyle( OUString::createFromAscii( pOutline ) );
if ( xFamilies->hasByName( sOutlineStyle ) )
{
xFamilies->getByName( sOutlineStyle ) >>= aXStyle;
if( aXStyle.is() )
xPropSet.set( aXStyle, UNO_QUERY_THROW );
}
}
setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, nLevel );
setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, nLevel );
}
}
}
}
}
}
}
}
}
catch( const Exception& )
{
}
}
void SlidePersist::hideShapesAsMasterShapes()
{
std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
for (auto const& shape : rShapes)
{
std::vector< oox::drawingml::ShapePtr >& rChildren( shape->getChildren() );
for (auto const& child : rChildren)
{
PPTShape* pPPTShape = dynamic_cast< PPTShape* >( child.get() );
if (!pPPTShape)
continue;
pPPTShape->setHiddenMasterShape( true );
}
}
}
Reference<XAnimationNode> SlidePersist::getAnimationNode(const OUString& sId) const
{
const auto& pIter = maAnimNodesMap.find(sId);
if (pIter != maAnimNodesMap.end())
return pIter->second;
Reference<XAnimationNode> aResult;
return aResult;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|