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 .
20 #include <basegfx/matrix/b2dhommatrix.hxx>
21 #include <com/sun/star/drawing/XShapes.hpp>
22 #include <oox/ppt/timenode.hxx>
23 #include <oox/ppt/pptshape.hxx>
24 #include <oox/ppt/slidepersist.hxx>
25 #include <drawingml/fillproperties.hxx>
26 #include <oox/drawingml/shapepropertymap.hxx>
27 #include <oox/helper/propertymap.hxx>
28 #include <oox/helper/propertyset.hxx>
29 #include <oox/vml/vmldrawing.hxx>
30 #include <oox/token/properties.hxx>
31 #include <oox/token/tokens.hxx>
32 #include <oox/core/xmlfilterbase.hxx>
33 #include <drawingml/textliststyle.hxx>
34 #include <drawingml/textparagraphproperties.hxx>
36 #include <osl/diagnose.h>
38 #include <com/sun/star/style/XStyle.hpp>
39 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
40 #include <com/sun/star/container/XNamed.hpp>
41 #include <com/sun/star/beans/XMultiPropertySet.hpp>
42 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
44 using namespace ::com::sun::star
;
45 using namespace ::oox::core
;
46 using namespace ::com::sun::star::uno
;
47 using namespace ::com::sun::star::drawing
;
48 using namespace ::com::sun::star::container
;
49 using namespace ::com::sun::star::animations
;
51 namespace oox
{ namespace ppt
{
53 SlidePersist::SlidePersist( XmlFilterBase
& rFilter
, bool bMaster
, bool bNotes
,
54 const css::uno::Reference
< css::drawing::XDrawPage
>& rxPage
,
55 oox::drawingml::ShapePtr
const & pShapesPtr
, const drawingml::TextListStylePtr
& pDefaultTextStyle
)
56 : mpDrawingPtr( new oox::vml::Drawing( rFilter
, rxPage
, oox::vml::VMLDRAWING_POWERPOINT
) )
58 , maShapesPtr( pShapesPtr
)
59 , mnLayoutValueToken( 0 )
62 , maDefaultTextStylePtr( pDefaultTextStyle
)
63 , maTitleTextStylePtr( new oox::drawingml::TextListStyle
)
64 , maBodyTextStylePtr( new oox::drawingml::TextListStyle
)
65 , maNotesTextStylePtr( new oox::drawingml::TextListStyle
)
66 , maOtherTextStylePtr( new oox::drawingml::TextListStyle
)
68 #if OSL_DEBUG_LEVEL > 0
73 #if OSL_DEBUG_LEVEL > 0
74 css::uno::WeakReference
< css::drawing::XDrawPage
> SlidePersist::mxDebugPage
;
77 SlidePersist::~SlidePersist()
81 sal_Int16
SlidePersist::getLayoutFromValueToken()
83 sal_Int16 nLayout
= 20; // 20 == blanc (so many magic numbers :-( the description at com.sun.star.presentation.DrawPage.Layout does not help)
84 switch( mnLayoutValueToken
)
86 case XML_blank
: nLayout
= 20; break;
87 case XML_chart
: nLayout
= 2; break;
88 case XML_chartAndTx
: nLayout
= 7; break;
89 case XML_clipArtAndTx
: nLayout
= 9; break;
90 case XML_clipArtAndVertTx
: nLayout
= 24; break;
91 case XML_fourObj
: nLayout
= 18; break;
92 case XML_obj
: nLayout
= 11; break;
93 case XML_objAndTx
: nLayout
= 13; break;
94 case XML_objOverTx
: nLayout
= 14; break;
95 case XML_tbl
: nLayout
= 8; break;
96 case XML_title
: nLayout
= 0; break;
97 case XML_titleOnly
: nLayout
= 19; break;
99 case XML_twoColTx
: nLayout
= 3; break;
100 case XML_twoObjAndTx
: nLayout
= 15; break;
101 case XML_twoObjOverTx
: nLayout
= 16; break;
102 case XML_tx
: nLayout
= 1; break;
103 case XML_txAndChart
: nLayout
= 4; break;
104 case XML_txAndClipArt
: nLayout
= 6; break;
105 case XML_txAndMedia
: nLayout
= 6; break;
106 case XML_txAndObj
: nLayout
= 10; break;
107 case XML_txAndTwoObj
: nLayout
= 12; break;
108 case XML_txOverObj
: nLayout
= 17; break;
109 case XML_vertTitleAndTx
: nLayout
= 22; break;
110 case XML_vertTitleAndTxOverChart
: nLayout
= 21; break;
111 case XML_vertTx
: nLayout
= 23; break;
113 case XML_twoTxTwoObj
:
114 case XML_twoObjAndObj
:
119 case XML_objAndTwoObj
:
129 void SlidePersist::createXShapes( XmlFilterBase
& rFilterBase
)
131 applyTextStyles( rFilterBase
);
133 Reference
< XShapes
> xShapes( getPage(), UNO_QUERY
);
135 std::vector
< oox::drawingml::ShapePtr
>& rShapes( maShapesPtr
->getChildren() );
136 for (auto const& shape
: rShapes
)
138 std::vector
< oox::drawingml::ShapePtr
>& rChildren( shape
->getChildren() );
139 for (auto const& child
: rChildren
)
141 PPTShape
* pPPTShape
= dynamic_cast< PPTShape
* >( child
.get() );
142 basegfx::B2DHomMatrix aTransformation
;
144 pPPTShape
->addShape( rFilterBase
, *this, getTheme().get(), xShapes
, aTransformation
, &getShapeMap() );
146 child
->addShape( rFilterBase
, getTheme().get(), xShapes
, aTransformation
, maShapesPtr
->getFillProperties(), &getShapeMap() );
150 Reference
< XAnimationNodeSupplier
> xNodeSupplier( getPage(), UNO_QUERY
);
151 if( xNodeSupplier
.is() )
153 Reference
< XAnimationNode
> xNode( xNodeSupplier
->getAnimationNode() );
154 if( xNode
.is() && !maTimeNodeList
.empty() )
156 SlidePersistPtr
pSlidePtr( shared_from_this() );
157 TimeNodePtr
pNode(maTimeNodeList
.front());
158 OSL_ENSURE( pNode
, "pNode" );
160 pNode
->setNode( rFilterBase
, xNode
, pSlidePtr
);
165 void SlidePersist::createBackground( const XmlFilterBase
& rFilterBase
)
167 if ( mpBackgroundPropertiesPtr
)
169 ::Color nPhClr
= maBackgroundColor
.isUsed() ?
170 maBackgroundColor
.getColor( rFilterBase
.getGraphicHelper() ) : API_RGB_TRANSPARENT
;
172 oox::drawingml::ShapePropertyIds aPropertyIds
= oox::drawingml::ShapePropertyInfo::DEFAULT
.mrPropertyIds
;
173 aPropertyIds
[oox::drawingml::ShapeProperty::FillGradient
] = PROP_FillGradientName
;
174 oox::drawingml::ShapePropertyInfo
aPropInfo( aPropertyIds
, true, false, true, false, false );
175 oox::drawingml::ShapePropertyMap
aPropMap( rFilterBase
.getModelObjectHelper(), aPropInfo
);
176 mpBackgroundPropertiesPtr
->pushToPropMap( aPropMap
, rFilterBase
.getGraphicHelper(), 0, nPhClr
);
177 PropertySet( mxPage
).setProperty( PROP_Background
, aPropMap
.makePropertySet() );
181 void setTextStyle( Reference
< beans::XPropertySet
> const & rxPropSet
, const XmlFilterBase
& rFilter
,
182 oox::drawingml::TextListStylePtr
const & pTextListStylePtr
, int nLevel
)
184 ::oox::drawingml::TextParagraphPropertiesPtr
pTextParagraphPropertiesPtr( pTextListStylePtr
->getListStyle()[ nLevel
] );
185 if( pTextParagraphPropertiesPtr
== nullptr )
187 // no properties. return
191 PropertyMap
& rTextParagraphPropertyMap( pTextParagraphPropertiesPtr
->getTextParagraphPropertyMap() );
193 PropertySet
aPropSet( rxPropSet
);
194 aPropSet
.setProperties( rTextParagraphPropertyMap
);
195 pTextParagraphPropertiesPtr
->getTextCharacterProperties().pushToPropSet( aPropSet
, rFilter
);
198 void SlidePersist::applyTextStyles( const XmlFilterBase
& rFilterBase
)
204 Reference
< style::XStyleFamiliesSupplier
> aXStyleFamiliesSupplier( rFilterBase
.getModel(), UNO_QUERY_THROW
);
205 Reference
< container::XNameAccess
> aXNameAccess( aXStyleFamiliesSupplier
->getStyleFamilies() );
206 Reference
< container::XNamed
> aXNamed( mxPage
, UNO_QUERY_THROW
);
208 if ( aXNameAccess
.is() && aXNamed
.is() )
210 oox::drawingml::TextListStylePtr pTextListStylePtr
;
214 const OUString
sOutline( "outline1" );
215 const OUString
sTitle( "title" );
216 const OUString
sStandard( "standard" );
217 const OUString
sSubtitle( "subtitle" );
219 for( int i
= 0; i
< 4; i
++ ) // todo: aggregation of bodystyle (subtitle)
223 case 0 : // title style
225 pTextListStylePtr
= maTitleTextStylePtr
;
227 aFamily
= aXNamed
->getName();
230 case 1 : // body style
232 pTextListStylePtr
= maBodyTextStylePtr
;
234 aFamily
= aXNamed
->getName();
237 case 3 : // notes style
239 pTextListStylePtr
= maNotesTextStylePtr
;
241 aFamily
= aXNamed
->getName();
244 case 4 : // standard style
246 pTextListStylePtr
= maOtherTextStylePtr
;
248 aFamily
= "graphics";
253 pTextListStylePtr
= maBodyTextStylePtr
;
255 aFamily
= aXNamed
->getName();
259 Reference
< container::XNameAccess
> xFamilies
;
260 if ( aXNameAccess
->hasByName( aFamily
) )
262 if( aXNameAccess
->getByName( aFamily
) >>= xFamilies
)
264 if ( xFamilies
->hasByName( aStyle
) )
266 Reference
< style::XStyle
> aXStyle
;
267 if ( xFamilies
->getByName( aStyle
) >>= aXStyle
)
269 Reference
< beans::XPropertySet
> xPropSet( aXStyle
, UNO_QUERY_THROW
);
270 setTextStyle( xPropSet
, rFilterBase
, maDefaultTextStylePtr
, 0 );
271 setTextStyle( xPropSet
, rFilterBase
, pTextListStylePtr
, 0 );
272 if ( i
== 1 /* BodyStyle */ )
274 for ( int nLevel
= 1; nLevel
< 5; nLevel
++ )
277 sal_Char pOutline
[ 9 ] = "outline1";
278 pOutline
[ 7 ] = static_cast< sal_Char
>( '0' + nLevel
);
279 OUString
sOutlineStyle( OUString::createFromAscii( pOutline
) );
280 if ( xFamilies
->hasByName( sOutlineStyle
) )
282 xFamilies
->getByName( sOutlineStyle
) >>= aXStyle
;
284 xPropSet
.set( aXStyle
, UNO_QUERY_THROW
);
287 setTextStyle( xPropSet
, rFilterBase
, maDefaultTextStylePtr
, nLevel
);
288 setTextStyle( xPropSet
, rFilterBase
, pTextListStylePtr
, nLevel
);
298 catch( const Exception
& )
304 void SlidePersist::hideShapesAsMasterShapes()
306 std::vector
< oox::drawingml::ShapePtr
>& rShapes( maShapesPtr
->getChildren() );
307 for (auto const& shape
: rShapes
)
309 std::vector
< oox::drawingml::ShapePtr
>& rChildren( shape
->getChildren() );
310 for (auto const& child
: rChildren
)
312 PPTShape
* pPPTShape
= dynamic_cast< PPTShape
* >( child
.get() );
315 pPPTShape
->setHiddenMasterShape( true );
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */