LibreOffice Module oox (master)  1
slidepersist.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
21 #include <com/sun/star/drawing/XDrawPage.hpp>
22 #include <com/sun/star/drawing/XShapes.hpp>
23 #include <com/sun/star/frame/XModel.hpp>
24 #include <oox/ppt/timenode.hxx>
25 #include <oox/ppt/pptshape.hxx>
26 #include <oox/ppt/slidepersist.hxx>
31 #include <oox/vml/vmldrawing.hxx>
32 #include <oox/token/properties.hxx>
33 #include <oox/token/tokens.hxx>
37 
38 #include <osl/diagnose.h>
39 
40 #include <com/sun/star/style/XStyle.hpp>
41 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
42 #include <com/sun/star/container/XNamed.hpp>
43 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
44 
45 using namespace ::com::sun::star;
46 using namespace ::oox::core;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::drawing;
49 using namespace ::com::sun::star::container;
50 using namespace ::com::sun::star::animations;
51 
52 
53 namespace oox::ppt {
54 
55 SlidePersist::SlidePersist( XmlFilterBase& rFilter, bool bMaster, bool bNotes,
56  const css::uno::Reference< css::drawing::XDrawPage >& rxPage,
57  oox::drawingml::ShapePtr const & pShapesPtr, const drawingml::TextListStylePtr & pDefaultTextStyle )
58 : mpDrawingPtr( std::make_shared<oox::vml::Drawing>( rFilter, rxPage, oox::vml::VMLDRAWING_POWERPOINT ) )
59 , mxPage( rxPage )
60 , maShapesPtr( pShapesPtr )
61 , mnLayoutValueToken( 0 )
62 , mbMaster( bMaster )
63 , mbNotes ( bNotes )
64 , maDefaultTextStylePtr( pDefaultTextStyle )
65 , maTitleTextStylePtr( std::make_shared<oox::drawingml::TextListStyle>() )
66 , maBodyTextStylePtr( std::make_shared<oox::drawingml::TextListStyle>() )
67 , maNotesTextStylePtr( std::make_shared<oox::drawingml::TextListStyle>() )
68 , maOtherTextStylePtr( std::make_shared<oox::drawingml::TextListStyle>() )
69 {
70 #if OSL_DEBUG_LEVEL > 0
72 #endif
73 }
74 
75 #if OSL_DEBUG_LEVEL > 0
76 css::uno::WeakReference< css::drawing::XDrawPage > SlidePersist::mxDebugPage;
77 #endif
78 
80 {
81 }
82 
84 {
85  sal_Int16 nLayout = 20; // 20 == blank (so many magic numbers :-( the description at com.sun.star.presentation.DrawPage.Layout does not help)
86  switch( mnLayoutValueToken )
87  {
88  case XML_blank: nLayout = 20; break;
89  case XML_chart: nLayout = 2; break;
90  case XML_chartAndTx: nLayout = 7; break;
91  case XML_clipArtAndTx: nLayout = 9; break;
92  case XML_clipArtAndVertTx: nLayout = 24; break;
93  case XML_fourObj: nLayout = 18; break;
94  case XML_obj: nLayout = 11; break;
95  case XML_objAndTx: nLayout = 13; break;
96  case XML_objOverTx: nLayout = 14; break;
97  case XML_tbl: nLayout = 8; break;
98  case XML_title: nLayout = 0; break;
99  case XML_titleOnly: nLayout = 19; break;
100  case XML_twoObj:
101  case XML_twoColTx: nLayout = 3; break;
102  case XML_twoObjAndTx: nLayout = 15; break;
103  case XML_twoObjOverTx: nLayout = 16; break;
104  case XML_tx: nLayout = 1; break;
105  case XML_txAndChart: nLayout = 4; break;
106  case XML_txAndClipArt: nLayout = 6; break;
107  case XML_txAndMedia: nLayout = 6; break;
108  case XML_txAndObj: nLayout = 10; break;
109  case XML_txAndTwoObj: nLayout = 12; break;
110  case XML_txOverObj: nLayout = 17; break;
111  case XML_vertTitleAndTx: nLayout = 22; break;
112  case XML_vertTitleAndTxOverChart: nLayout = 21; break;
113  case XML_vertTx: nLayout = 23; break;
114 
115  case XML_twoTxTwoObj:
116  case XML_twoObjAndObj:
117  case XML_objTx:
118  case XML_picTx:
119  case XML_secHead:
120  case XML_objOnly:
121  case XML_objAndTwoObj:
122  case XML_mediaAndTx:
123  case XML_dgm:
124  case XML_cust:
125  default:
126  nLayout = 20;
127  }
128  return nLayout;
129 }
130 
131 void SlidePersist::createXShapes( XmlFilterBase& rFilterBase )
132 {
133  applyTextStyles( rFilterBase );
134 
135  Reference< XShapes > xShapes( getPage() );
136  std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
137 
138  for (auto const& shape : rShapes)
139  {
140  std::vector< oox::drawingml::ShapePtr >& rChildren( shape->getChildren() );
141  for (auto const& child : rChildren)
142  {
143  PPTShape* pPPTShape = dynamic_cast< PPTShape* >( child.get() );
144  basegfx::B2DHomMatrix aTransformation;
145  if ( pPPTShape )
146  pPPTShape->addShape( rFilterBase, *this, getTheme().get(), xShapes, aTransformation, &getShapeMap() );
147  else
148  child->addShape( rFilterBase, getTheme().get(), xShapes, aTransformation, maShapesPtr->getFillProperties(), &getShapeMap() );
149  }
150  }
151 
152  Reference< XAnimationNodeSupplier > xNodeSupplier( getPage(), UNO_QUERY);
153  if( !xNodeSupplier.is() )
154  return;
155 
156  Reference< XAnimationNode > xNode( xNodeSupplier->getAnimationNode() );
157  if( xNode.is() && !maTimeNodeList.empty() )
158  {
159  SlidePersistPtr pSlidePtr( shared_from_this() );
160  TimeNodePtr pNode(maTimeNodeList.front());
161  OSL_ENSURE( pNode, "pNode" );
162 
163  Reference<XAnimationNode> xDummy;
164  pNode->setNode(rFilterBase, xNode, pSlidePtr, xDummy);
165  }
166 }
167 
168 void SlidePersist::createBackground( const XmlFilterBase& rFilterBase )
169 {
171  {
172  ::Color nPhClr = maBackgroundColor.isUsed() ?
173  maBackgroundColor.getColor( rFilterBase.getGraphicHelper() ) : API_RGB_TRANSPARENT;
174 
176  aPropertyIds[oox::drawingml::ShapeProperty::FillGradient] = PROP_FillGradientName;
177  oox::drawingml::ShapePropertyInfo aPropInfo( aPropertyIds, true, false, true, false, false );
178  oox::drawingml::ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper(), aPropInfo );
179  mpBackgroundPropertiesPtr->pushToPropMap( aPropMap, rFilterBase.getGraphicHelper(), 0, nPhClr );
180  PropertySet( mxPage ).setProperty( PROP_Background, aPropMap.makePropertySet() );
181  }
182 }
183 
184 static void setTextStyle( Reference< beans::XPropertySet > const & rxPropSet, const XmlFilterBase& rFilter,
185  oox::drawingml::TextListStylePtr const & pTextListStylePtr, int nLevel )
186 {
187  ::oox::drawingml::TextParagraphProperties* pTextParagraphPropertiesPtr( &pTextListStylePtr->getListStyle()[ nLevel ] );
188  if( pTextParagraphPropertiesPtr == nullptr )
189  {
190  // no properties. return
191  return;
192  }
193 
194  PropertyMap& rTextParagraphPropertyMap( pTextParagraphPropertiesPtr->getTextParagraphPropertyMap() );
195 
196  PropertySet aPropSet( rxPropSet );
197  aPropSet.setProperties( rTextParagraphPropertyMap );
198  pTextParagraphPropertiesPtr->getTextCharacterProperties().pushToPropSet( aPropSet, rFilter );
199 }
200 
201 void SlidePersist::applyTextStyles( const XmlFilterBase& rFilterBase )
202 {
203  if ( !mbMaster )
204  return;
205 
206  try
207  {
208  Reference< style::XStyleFamiliesSupplier > aXStyleFamiliesSupplier( rFilterBase.getModel(), UNO_QUERY_THROW );
209  Reference< container::XNameAccess > aXNameAccess( aXStyleFamiliesSupplier->getStyleFamilies() );
210  Reference< container::XNamed > aXNamed( mxPage, UNO_QUERY_THROW );
211 
212  if ( aXNameAccess.is() )
213  {
214  oox::drawingml::TextListStylePtr pTextListStylePtr;
215  OUString aStyle;
216  OUString aFamily;
217 
218  static const OUStringLiteral sOutline( u"outline1" );
219  static const OUStringLiteral sTitle( u"title" );
220  static const OUStringLiteral sStandard( u"standard" );
221  static const OUStringLiteral sSubtitle( u"subtitle" );
222 
223  for( int i = 0; i < 4; i++ ) // todo: aggregation of bodystyle (subtitle)
224  {
225  switch( i )
226  {
227  case 0 : // title style
228  {
229  pTextListStylePtr = maTitleTextStylePtr;
230  aStyle = sTitle;
231  aFamily= aXNamed->getName();
232  break;
233  }
234  case 1 : // body style
235  {
236  pTextListStylePtr = maBodyTextStylePtr;
237  aStyle = sOutline;
238  aFamily= aXNamed->getName();
239  break;
240  }
241  case 3 : // notes style
242  {
243  pTextListStylePtr = maNotesTextStylePtr;
244  aStyle = sTitle;
245  aFamily= aXNamed->getName();
246  break;
247  }
248  case 4 : // standard style
249  {
250  pTextListStylePtr = maOtherTextStylePtr;
251  aStyle = sStandard;
252  aFamily = "graphics";
253  break;
254  }
255  case 5 : // subtitle
256  {
257  pTextListStylePtr = maBodyTextStylePtr;
258  aStyle = sSubtitle;
259  aFamily = aXNamed->getName();
260  break;
261  }
262  }
264  if ( aXNameAccess->hasByName( aFamily ) )
265  {
266  if( aXNameAccess->getByName( aFamily ) >>= xFamilies )
267  {
268  if ( xFamilies->hasByName( aStyle ) )
269  {
270  Reference< style::XStyle > aXStyle;
271  if ( xFamilies->getByName( aStyle ) >>= aXStyle )
272  {
273  Reference< beans::XPropertySet > xPropSet( aXStyle, UNO_QUERY_THROW );
274  setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, 0 );
275  setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, 0 );
276  if ( i == 1 /* BodyStyle */ )
277  {
278  for ( int nLevel = 1; nLevel < 5; nLevel++ )
279  {
280  {
281  char pOutline[ 9 ] = "outline1";
282  pOutline[ 7 ] = static_cast< char >( '0' + nLevel );
283  OUString sOutlineStyle( OUString::createFromAscii( pOutline ) );
284  if ( xFamilies->hasByName( sOutlineStyle ) )
285  {
286  xFamilies->getByName( sOutlineStyle ) >>= aXStyle;
287  if( aXStyle.is() )
288  xPropSet.set( aXStyle, UNO_QUERY_THROW );
289  }
290  }
291  setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, nLevel );
292  setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, nLevel );
293  }
294  }
295  }
296  }
297  }
298  }
299  }
300  }
301  }
302  catch( const Exception& )
303  {
304  }
305 }
306 
308 {
309  std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
310  for (auto const& shape : rShapes)
311  {
312  std::vector< oox::drawingml::ShapePtr >& rChildren( shape->getChildren() );
313  for (auto const& child : rChildren)
314  {
315  PPTShape* pPPTShape = dynamic_cast< PPTShape* >( child.get() );
316  if (!pPPTShape)
317  continue;
318  pPPTShape->setHiddenMasterShape( true );
319  }
320  }
321 }
322 
323 Reference<XAnimationNode> SlidePersist::getAnimationNode(const OUString& sId) const
324 {
325  const auto& pIter = maAnimNodesMap.find(sId);
326  if (pIter != maAnimNodesMap.end())
327  return pIter->second;
328 
329  Reference<XAnimationNode> aResult;
330  return aResult;
331 }
332 
333 }
334 
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::vector< std::shared_ptr< TimeNode > > maTimeNodeList
oox::drawingml::ShapePtr maShapesPtr
sal_Int16 getLayoutFromValueToken() const
const ::Color API_RGB_TRANSPARENT(ColorTransparency, 0xffffffff)
Transparent color for API calls.
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
const oox::drawingml::ThemePtr & getTheme() const
SlidePersist(oox::core::XmlFilterBase &rFilter, bool bMaster, bool bNotes, const css::uno::Reference< css::drawing::XDrawPage > &, oox::drawingml::ShapePtr const &pShapesPtr, const ::oox::drawingml::TextListStylePtr &)
std::shared_ptr< T > make_shared(Args &&...args)
oox::drawingml::TextListStylePtr maNotesTextStylePtr
oox::drawingml::TextListStylePtr maTitleTextStylePtr
std::map< OUString, css::uno::Reference< css::animations::XAnimationNode > > maAnimNodesMap
void createBackground(const oox::core::XmlFilterBase &rFilterBase)
oox::drawingml::FillPropertiesPtr mpBackgroundPropertiesPtr
static ShapePropertyInfo DEFAULT
True = use named fill hatch instead of explicit fill hatch.
const css::uno::Reference< css::drawing::XDrawPage > & getPage() const
::Color getColor(const GraphicHelper &rGraphicHelper,::Color nPhClr=API_RGB_TRANSPARENT) const
Returns the final RGB color value.
Definition: color.cxx:481
oox::drawingml::TextListStylePtr maOtherTextStylePtr
bool isUsed() const
Returns true, if the color is initialized.
Definition: color.hxx:87
PowerPoint: OLE objects are part of DrawingML.
Definition: vmldrawing.hxx:57
oox::drawingml::TextListStylePtr maBodyTextStylePtr
css::uno::Reference< css::animations::XAnimationNode > getAnimationNode(const OUString &sId) const
void applyTextStyles(const oox::core::XmlFilterBase &rFilterBase)
const ShapePropertyIds & mrPropertyIds
float u
css::uno::Reference< css::drawing::XDrawPage > mxPage
A wrapper for a UNO property set.
Definition: propertyset.hxx:57
::oox::drawingml::ShapeIdMap & getShapeMap()
void setHiddenMasterShape(bool bHiddenMasterShape)
Definition: shape.hxx:159
Explicit fill gradient or name of a fill gradient stored in a global container.
std::shared_ptr< TextListStyle > TextListStylePtr
oox::drawingml::Color maBackgroundColor
std::shared_ptr< SlidePersist > SlidePersistPtr
std::shared_ptr< TimeNode > TimeNodePtr
Definition: timenode.hxx:44
oox::drawingml::TextListStylePtr maDefaultTextStylePtr
static void setTextStyle(Reference< beans::XPropertySet > const &rxPropSet, const XmlFilterBase &rFilter, oox::drawingml::TextListStylePtr const &pTextListStylePtr, int nLevel)
static css::uno::WeakReference< css::drawing::XDrawPage > mxDebugPage
std::shared_ptr< Shape > ShapePtr
void createXShapes(oox::core::XmlFilterBase &rFilterBase)
void addShape(oox::core::XmlFilterBase &rFilterBase, const SlidePersist &rPersist, const oox::drawingml::Theme *pTheme, const css::uno::Reference< css::drawing::XShapes > &rxShapes, basegfx::B2DHomMatrix &aTransformation,::oox::drawingml::ShapeIdMap *pShapeMap)
Definition: pptshape.cxx:155
bool setProperty(sal_Int32 nPropId, const Type &rValue)
Puts the passed value into the property set.