1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include "oox/ppt/timenode.hxx" 25 #include "oox/ppt/pptshape.hxx" 26 #include "oox/ppt/slidepersist.hxx" 27 #include "oox/drawingml/fillproperties.hxx" 28 #include "oox/drawingml/shapepropertymap.hxx" 29 #include "oox/helper/propertyset.hxx" 30 #include "oox/vml/vmldrawing.hxx" 31 #include "oox/core/xmlfilterbase.hxx" 32 33 #include <com/sun/star/style/XStyle.hpp> 34 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> 35 #include <com/sun/star/container/XNamed.hpp> 36 #include <com/sun/star/beans/XMultiPropertySet.hpp> 37 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp> 38 39 using namespace ::com::sun::star; 40 using namespace ::oox::core; 41 using namespace ::com::sun::star::uno; 42 using namespace ::com::sun::star::drawing; 43 using namespace ::com::sun::star::container; 44 using namespace ::com::sun::star::animations; 45 46 namespace oox { namespace ppt { 47 48 SlidePersist::SlidePersist( XmlFilterBase& rFilter, sal_Bool bMaster, sal_Bool bNotes, 49 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& rxPage, 50 oox::drawingml::ShapePtr pShapesPtr, const drawingml::TextListStylePtr & pDefaultTextStyle ) 51 : mpDrawingPtr( new oox::vml::Drawing( rFilter, rxPage, oox::vml::VMLDRAWING_POWERPOINT ) ) 52 , mxPage( rxPage ) 53 , maShapesPtr( pShapesPtr ) 54 , mnLayoutValueToken( 0 ) 55 , mbMaster( bMaster ) 56 , mbNotes ( bNotes ) 57 , maDefaultTextStylePtr( pDefaultTextStyle ) 58 , maTitleTextStylePtr( new oox::drawingml::TextListStyle ) 59 , maBodyTextStylePtr( new oox::drawingml::TextListStyle ) 60 , maNotesTextStylePtr( new oox::drawingml::TextListStyle ) 61 , maOtherTextStylePtr( new oox::drawingml::TextListStyle ) 62 { 63 if ( pDefaultTextStyle ) 64 { 65 /* 66 maTitleTextStylePtr->apply( *pDefaultTextStyle.get() ); 67 maBodyTextStylePtr->apply( *pDefaultTextStyle.get() ); 68 maNotesTextStylePtr->apply( *pDefaultTextStyle.get() ); 69 */ 70 maOtherTextStylePtr->apply( *pDefaultTextStyle.get() ); 71 } 72 } 73 74 SlidePersist::~SlidePersist() 75 { 76 77 } 78 79 sal_Int16 SlidePersist::getLayoutFromValueToken() 80 { 81 sal_Int16 nLayout = 20; // 20 == blanc (so many magic numbers :-( the description at com.sun.star.presentation.DrawPage.Layout does not help) 82 switch( mnLayoutValueToken ) 83 { 84 case XML_blank: nLayout = 20; break; 85 case XML_chart: nLayout = 2; break; 86 case XML_chartAndTx: nLayout = 7; break; 87 case XML_clipArtAndTx: nLayout = 9; break; 88 case XML_clipArtAndVertTx: nLayout = 24; break; 89 case XML_fourObj: nLayout = 18; break; 90 case XML_obj: nLayout = 11; break; 91 case XML_objAndTx: nLayout = 13; break; 92 case XML_objOverTx: nLayout = 14; break; 93 case XML_tbl: nLayout = 8; break; 94 case XML_title: nLayout = 0; break; 95 case XML_titleOnly: nLayout = 19; break; 96 case XML_twoObj: 97 case XML_twoColTx: nLayout = 3; break; 98 case XML_twoObjAndTx: nLayout = 15; break; 99 case XML_twoObjOverTx: nLayout = 16; break; 100 case XML_tx: nLayout = 1; break; 101 case XML_txAndChart: nLayout = 4; break; 102 case XML_txAndClipArt: nLayout = 6; break; 103 case XML_txAndMedia: nLayout = 6; break; 104 case XML_txAndObj: nLayout = 10; break; 105 case XML_txAndTwoObj: nLayout = 12; break; 106 case XML_txOverObj: nLayout = 17; break; 107 case XML_vertTitleAndTx: nLayout = 22; break; 108 case XML_vertTitleAndTxOverChart: nLayout = 21; break; 109 case XML_vertTx: nLayout = 23; break; 110 111 case XML_twoTxTwoObj: 112 case XML_twoObjAndObj: 113 case XML_objTx: 114 case XML_picTx: 115 case XML_secHead: 116 case XML_objOnly: 117 case XML_objAndTwoObj: 118 case XML_mediaAndTx: 119 case XML_dgm: 120 case XML_cust: 121 default: 122 nLayout = 20; 123 } 124 return nLayout; 125 } 126 127 void SlidePersist::createXShapes( XmlFilterBase& rFilterBase ) 128 { 129 applyTextStyles( rFilterBase ); 130 131 Reference< XShapes > xShapes( getPage(), UNO_QUERY ); 132 133 std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() ); 134 std::vector< oox::drawingml::ShapePtr >::iterator aShapesIter( rShapes.begin() ); 135 while( aShapesIter != rShapes.end() ) 136 { 137 std::vector< oox::drawingml::ShapePtr >& rChildren( (*aShapesIter++)->getChildren() ); 138 std::vector< oox::drawingml::ShapePtr >::iterator aChildIter( rChildren.begin() ); 139 while( aChildIter != rChildren.end() ) 140 { 141 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( (*aChildIter).get() ); 142 if ( pPPTShape ) 143 pPPTShape->addShape( rFilterBase, *this, getTheme().get(), xShapes, 0, &getShapeMap() ); 144 else 145 (*aChildIter)->addShape( rFilterBase, getTheme().get(), xShapes, 0, &getShapeMap() ); 146 aChildIter++; 147 } 148 } 149 150 Reference< XAnimationNodeSupplier > xNodeSupplier( getPage(), UNO_QUERY); 151 if( xNodeSupplier.is() ) 152 { 153 Reference< XAnimationNode > xNode( xNodeSupplier->getAnimationNode() ); 154 if( xNode.is() && !maTimeNodeList.empty() ) 155 { 156 SlidePersistPtr pSlidePtr( shared_from_this() ); 157 TimeNodePtr pNode(maTimeNodeList.front()); 158 OSL_ENSURE( pNode, "pNode" ); 159 160 pNode->setNode( rFilterBase, xNode, pSlidePtr ); 161 } 162 } 163 } 164 165 void SlidePersist::createBackground( const XmlFilterBase& rFilterBase ) 166 { 167 if ( mpBackgroundPropertiesPtr ) 168 { 169 sal_Int32 nPhClr = maBackgroundColor.isUsed() ? 170 maBackgroundColor.getColor( rFilterBase.getGraphicHelper() ) : API_RGB_TRANSPARENT; 171 172 ::oox::drawingml::ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper() ); 173 mpBackgroundPropertiesPtr->pushToPropMap( aPropMap, rFilterBase.getGraphicHelper(), 0, nPhClr ); 174 PropertySet( mxPage ).setProperty( PROP_Background, aPropMap.makePropertySet() ); 175 } 176 } 177 178 void setTextStyle( Reference< beans::XPropertySet >& rxPropSet, const XmlFilterBase& rFilter, 179 oox::drawingml::TextListStylePtr& pTextListStylePtr, int nLevel ) 180 { 181 ::oox::drawingml::TextParagraphPropertiesPtr pTextParagraphPropertiesPtr( pTextListStylePtr->getListStyle()[ nLevel ] ); 182 if( pTextParagraphPropertiesPtr == NULL ) 183 { 184 // no properties. return 185 return; 186 } 187 188 PropertyMap& rTextParagraphPropertyMap( pTextParagraphPropertiesPtr->getTextParagraphPropertyMap() ); 189 190 PropertySet aPropSet( rxPropSet ); 191 aPropSet.setProperties( rTextParagraphPropertyMap ); 192 pTextParagraphPropertiesPtr->getTextCharacterProperties().pushToPropSet( aPropSet, rFilter ); 193 } 194 195 void SlidePersist::applyTextStyles( const XmlFilterBase& rFilterBase ) 196 { 197 if ( mbMaster ) 198 { 199 try 200 { 201 Reference< style::XStyleFamiliesSupplier > aXStyleFamiliesSupplier( rFilterBase.getModel(), UNO_QUERY_THROW ); 202 Reference< container::XNameAccess > aXNameAccess( aXStyleFamiliesSupplier->getStyleFamilies() ); 203 Reference< container::XNamed > aXNamed( mxPage, UNO_QUERY_THROW ); 204 205 if ( aXNameAccess.is() && aXNamed.is() ) 206 { 207 oox::drawingml::TextListStylePtr pTextListStylePtr; 208 rtl::OUString aStyle; 209 rtl::OUString aFamily; 210 211 const rtl::OUString sOutline( RTL_CONSTASCII_USTRINGPARAM( "outline1" ) ); 212 const rtl::OUString sTitle( RTL_CONSTASCII_USTRINGPARAM( "title" ) ); 213 const rtl::OUString sStandard( RTL_CONSTASCII_USTRINGPARAM( "standard" ) ); 214 const rtl::OUString sSubtitle( RTL_CONSTASCII_USTRINGPARAM( "subtitle" ) ); 215 216 for( int i = 0; i < 4; i++ ) // todo: aggregation of bodystyle (subtitle) 217 { 218 switch( i ) 219 { 220 case 0 : // title style 221 { 222 pTextListStylePtr = maTitleTextStylePtr; 223 aStyle = sTitle; 224 aFamily= aXNamed->getName(); 225 break; 226 } 227 case 1 : // body style 228 { 229 pTextListStylePtr = maBodyTextStylePtr; 230 aStyle = sOutline; 231 aFamily= aXNamed->getName(); 232 break; 233 } 234 case 3 : // notes style 235 { 236 pTextListStylePtr = maNotesTextStylePtr; 237 aStyle = sTitle; 238 aFamily= aXNamed->getName(); 239 break; 240 } 241 case 4 : // standard style 242 { 243 pTextListStylePtr = maOtherTextStylePtr; 244 aStyle = sStandard; 245 aFamily = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "graphics" ) ); 246 break; 247 } 248 case 5 : // subtitle 249 { 250 pTextListStylePtr = maBodyTextStylePtr; 251 aStyle = sSubtitle; 252 aFamily = aXNamed->getName(); 253 break; 254 } 255 } 256 Reference< container::XNameAccess > xFamilies; 257 if ( aXNameAccess->hasByName( aFamily ) ) 258 { 259 if( aXNameAccess->getByName( aFamily ) >>= xFamilies ) 260 { 261 if ( xFamilies->hasByName( aStyle ) ) 262 { 263 Reference< style::XStyle > aXStyle; 264 if ( xFamilies->getByName( aStyle ) >>= aXStyle ) 265 { 266 Reference< beans::XPropertySet > xPropSet( aXStyle, UNO_QUERY_THROW ); 267 setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, 0 ); 268 setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, 0 ); 269 if ( i == 1 /* BodyStyle */ ) 270 { 271 for ( int nLevel = 1; nLevel < 5; nLevel++ ) 272 { 273 { 274 sal_Char pOutline[ 9 ] = "outline1"; 275 pOutline[ 7 ] = static_cast< sal_Char >( '0' + nLevel ); 276 rtl::OUString sOutlineStyle( rtl::OUString::createFromAscii( pOutline ) ); 277 if ( xFamilies->hasByName( sOutlineStyle ) ) 278 { 279 xFamilies->getByName( sOutlineStyle ) >>= aXStyle; 280 if( aXStyle.is() ) 281 xPropSet = Reference< beans::XPropertySet >( aXStyle, UNO_QUERY_THROW ); 282 } 283 } 284 setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, nLevel ); 285 setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, nLevel ); 286 } 287 } 288 } 289 } 290 } 291 } 292 } 293 } 294 } 295 catch( Exception& ) 296 { 297 } 298 } 299 } 300 301 } } 302 303