1ca5ec200SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ca5ec200SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ca5ec200SAndrew Rist * or more contributor license agreements. See the NOTICE file 5ca5ec200SAndrew Rist * distributed with this work for additional information 6ca5ec200SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ca5ec200SAndrew Rist * to you under the Apache License, Version 2.0 (the 8ca5ec200SAndrew Rist * "License"); you may not use this file except in compliance 9ca5ec200SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11ca5ec200SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13ca5ec200SAndrew Rist * Unless required by applicable law or agreed to in writing, 14ca5ec200SAndrew Rist * software distributed under the License is distributed on an 15ca5ec200SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ca5ec200SAndrew Rist * KIND, either express or implied. See the License for the 17ca5ec200SAndrew Rist * specific language governing permissions and limitations 18ca5ec200SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20ca5ec200SAndrew Rist *************************************************************/ 21ca5ec200SAndrew Rist 22ca5ec200SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "oox/drawingml/shape.hxx" 25cdf0e10cSrcweir #include "oox/drawingml/customshapeproperties.hxx" 26cdf0e10cSrcweir #include "oox/drawingml/theme.hxx" 27cdf0e10cSrcweir #include "oox/drawingml/fillproperties.hxx" 28cdf0e10cSrcweir #include "oox/drawingml/lineproperties.hxx" 29cdf0e10cSrcweir #include "oox/drawingml/shapepropertymap.hxx" 30cdf0e10cSrcweir #include "oox/drawingml/textbody.hxx" 31cdf0e10cSrcweir #include "oox/drawingml/table/tableproperties.hxx" 32cdf0e10cSrcweir #include "oox/drawingml/chart/chartconverter.hxx" 33cdf0e10cSrcweir #include "oox/drawingml/chart/chartspacefragment.hxx" 34cdf0e10cSrcweir #include "oox/drawingml/chart/chartspacemodel.hxx" 35cdf0e10cSrcweir #include "oox/vml/vmldrawing.hxx" 36cdf0e10cSrcweir #include "oox/vml/vmlshape.hxx" 37cdf0e10cSrcweir #include "oox/vml/vmlshapecontainer.hxx" 38cdf0e10cSrcweir #include "oox/core/xmlfilterbase.hxx" 39cdf0e10cSrcweir #include "oox/helper/graphichelper.hxx" 40cdf0e10cSrcweir #include "oox/helper/propertyset.hxx" 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include <tools/solar.h> // for the F_PI180 define 43cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphic.hpp> 44cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp> 45cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertySet.hpp> 46cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 47cdf0e10cSrcweir #include <com/sun/star/drawing/HomogenMatrix3.hpp> 48cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp> 49cdf0e10cSrcweir #include <com/sun/star/chart2/XChartDocument.hpp> 50cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx> 51cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 52cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 53cdf0e10cSrcweir #include <com/sun/star/document/XActionLockable.hpp> 54cdf0e10cSrcweir 55cdf0e10cSrcweir using rtl::OUString; 56cdf0e10cSrcweir using namespace ::oox::core; 57cdf0e10cSrcweir using namespace ::com::sun::star; 58cdf0e10cSrcweir using namespace ::com::sun::star::awt; 59cdf0e10cSrcweir using namespace ::com::sun::star::uno; 60cdf0e10cSrcweir using namespace ::com::sun::star::beans; 61cdf0e10cSrcweir using namespace ::com::sun::star::frame; 62cdf0e10cSrcweir using namespace ::com::sun::star::text; 63cdf0e10cSrcweir using namespace ::com::sun::star::drawing; 64cdf0e10cSrcweir 65cdf0e10cSrcweir namespace oox { namespace drawingml { 66cdf0e10cSrcweir 67cdf0e10cSrcweir // ============================================================================ 68cdf0e10cSrcweir 69cdf0e10cSrcweir Shape::Shape( const sal_Char* pServiceName ) 70cdf0e10cSrcweir : mpLinePropertiesPtr( new LineProperties ) 71cdf0e10cSrcweir , mpFillPropertiesPtr( new FillProperties ) 72cdf0e10cSrcweir , mpGraphicPropertiesPtr( new GraphicProperties ) 73cdf0e10cSrcweir , mpCustomShapePropertiesPtr( new CustomShapeProperties ) 74cdf0e10cSrcweir , mpMasterTextListStyle( new TextListStyle ) 75cdf0e10cSrcweir , mnSubType( 0 ) 76cdf0e10cSrcweir , mnSubTypeIndex( -1 ) 77cdf0e10cSrcweir , meFrameType( FRAMETYPE_GENERIC ) 78cdf0e10cSrcweir , mnRotation( 0 ) 79cdf0e10cSrcweir , mbFlipH( false ) 80cdf0e10cSrcweir , mbFlipV( false ) 81cdf0e10cSrcweir , mbHidden( false ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir if ( pServiceName ) 84cdf0e10cSrcweir msServiceName = OUString::createFromAscii( pServiceName ); 85cdf0e10cSrcweir setDefaults(); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir Shape::~Shape() 89cdf0e10cSrcweir { 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir table::TablePropertiesPtr Shape::getTableProperties() 93cdf0e10cSrcweir { 94cdf0e10cSrcweir if ( !mpTablePropertiesPtr.get() ) 95cdf0e10cSrcweir mpTablePropertiesPtr.reset( new table::TableProperties() ); 96cdf0e10cSrcweir return mpTablePropertiesPtr; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir void Shape::setDefaults() 100cdf0e10cSrcweir { 101cdf0e10cSrcweir maShapeProperties[ PROP_TextAutoGrowHeight ] <<= false; 102cdf0e10cSrcweir maShapeProperties[ PROP_TextWordWrap ] <<= true; 103cdf0e10cSrcweir maShapeProperties[ PROP_TextLeftDistance ] <<= static_cast< sal_Int32 >( 250 ); 104cdf0e10cSrcweir maShapeProperties[ PROP_TextUpperDistance ] <<= static_cast< sal_Int32 >( 125 ); 105cdf0e10cSrcweir maShapeProperties[ PROP_TextRightDistance ] <<= static_cast< sal_Int32 >( 250 ); 106cdf0e10cSrcweir maShapeProperties[ PROP_TextLowerDistance ] <<= static_cast< sal_Int32 >( 125 ); 107cdf0e10cSrcweir maShapeProperties[ PROP_CharHeight ] <<= static_cast< float >( 18.0 ); 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir ::oox::vml::OleObjectInfo& Shape::setOleObjectType() 111cdf0e10cSrcweir { 112cdf0e10cSrcweir OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setOleObjectType - multiple frame types" ); 113cdf0e10cSrcweir meFrameType = FRAMETYPE_OLEOBJECT; 114cdf0e10cSrcweir mxOleObjectInfo.reset( new ::oox::vml::OleObjectInfo( true ) ); 115cdf0e10cSrcweir return *mxOleObjectInfo; 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir ChartShapeInfo& Shape::setChartType( bool bEmbedShapes ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setChartType - multiple frame types" ); 121cdf0e10cSrcweir meFrameType = FRAMETYPE_CHART; 122cdf0e10cSrcweir msServiceName = CREATE_OUSTRING( "com.sun.star.drawing.OLE2Shape" ); 123cdf0e10cSrcweir mxChartShapeInfo.reset( new ChartShapeInfo( bEmbedShapes ) ); 124cdf0e10cSrcweir return *mxChartShapeInfo; 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir void Shape::setDiagramType() 128cdf0e10cSrcweir { 129cdf0e10cSrcweir OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setDiagramType - multiple frame types" ); 130cdf0e10cSrcweir meFrameType = FRAMETYPE_DIAGRAM; 131cdf0e10cSrcweir msServiceName = CREATE_OUSTRING( "com.sun.star.drawing.GroupShape" ); 132cdf0e10cSrcweir mnSubType = 0; 133cdf0e10cSrcweir } 134cdf0e10cSrcweir 135cdf0e10cSrcweir void Shape::setTableType() 136cdf0e10cSrcweir { 137cdf0e10cSrcweir OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setTableType - multiple frame types" ); 138cdf0e10cSrcweir meFrameType = FRAMETYPE_TABLE; 139cdf0e10cSrcweir msServiceName = CREATE_OUSTRING( "com.sun.star.drawing.TableShape" ); 140cdf0e10cSrcweir mnSubType = 0; 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir void Shape::setServiceName( const sal_Char* pServiceName ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir if ( pServiceName ) 146cdf0e10cSrcweir msServiceName = OUString::createFromAscii( pServiceName ); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir 150cdf0e10cSrcweir const ShapeStyleRef* Shape::getShapeStyleRef( sal_Int32 nRefType ) const 151cdf0e10cSrcweir { 152cdf0e10cSrcweir ShapeStyleRefMap::const_iterator aIt = maShapeStyleRefs.find( nRefType ); 153cdf0e10cSrcweir return (aIt == maShapeStyleRefs.end()) ? 0 : &aIt->second; 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir void Shape::addShape( 157cdf0e10cSrcweir ::oox::core::XmlFilterBase& rFilterBase, 158cdf0e10cSrcweir const Theme* pTheme, 159cdf0e10cSrcweir const Reference< XShapes >& rxShapes, 160cdf0e10cSrcweir const awt::Rectangle* pShapeRect, 161cdf0e10cSrcweir ShapeIdMap* pShapeMap ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir try 164cdf0e10cSrcweir { 165cdf0e10cSrcweir rtl::OUString sServiceName( msServiceName ); 166cdf0e10cSrcweir if( sServiceName.getLength() ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir Reference< XShape > xShape( createAndInsert( rFilterBase, sServiceName, pTheme, rxShapes, pShapeRect, sal_False ) ); 169cdf0e10cSrcweir 170cdf0e10cSrcweir if( pShapeMap && msId.getLength() ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir (*pShapeMap)[ msId ] = shared_from_this(); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir // if this is a group shape, we have to add also each child shape 176cdf0e10cSrcweir Reference< XShapes > xShapes( xShape, UNO_QUERY ); 177cdf0e10cSrcweir if ( xShapes.is() ) 178cdf0e10cSrcweir addChildren( rFilterBase, *this, pTheme, xShapes, pShapeRect ? *pShapeRect : awt::Rectangle( maPosition.X, maPosition.Y, maSize.Width, maSize.Height ), pShapeMap ); 179cdf0e10cSrcweir } 180cdf0e10cSrcweir } 181cdf0e10cSrcweir catch( const Exception& ) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir } 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir void Shape::applyShapeReference( const Shape& rReferencedShape ) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir mpTextBody = TextBodyPtr( new TextBody( *rReferencedShape.mpTextBody.get() ) ); 189cdf0e10cSrcweir maShapeProperties = rReferencedShape.maShapeProperties; 190cdf0e10cSrcweir mpLinePropertiesPtr = LinePropertiesPtr( new LineProperties( *rReferencedShape.mpLinePropertiesPtr.get() ) ); 191cdf0e10cSrcweir mpFillPropertiesPtr = FillPropertiesPtr( new FillProperties( *rReferencedShape.mpFillPropertiesPtr.get() ) ); 192cdf0e10cSrcweir mpCustomShapePropertiesPtr = CustomShapePropertiesPtr( new CustomShapeProperties( *rReferencedShape.mpCustomShapePropertiesPtr.get() ) ); 193cdf0e10cSrcweir mpTablePropertiesPtr = table::TablePropertiesPtr( rReferencedShape.mpTablePropertiesPtr.get() ? new table::TableProperties( *rReferencedShape.mpTablePropertiesPtr.get() ) : NULL ); 194cdf0e10cSrcweir mpMasterTextListStyle = TextListStylePtr( new TextListStyle( *rReferencedShape.mpMasterTextListStyle.get() ) ); 195cdf0e10cSrcweir maShapeStyleRefs = rReferencedShape.maShapeStyleRefs; 196cdf0e10cSrcweir maSize = rReferencedShape.maSize; 197cdf0e10cSrcweir maPosition = rReferencedShape.maPosition; 198cdf0e10cSrcweir mnRotation = rReferencedShape.mnRotation; 199cdf0e10cSrcweir mbFlipH = rReferencedShape.mbFlipH; 200cdf0e10cSrcweir mbFlipV = rReferencedShape.mbFlipV; 201cdf0e10cSrcweir mbHidden = rReferencedShape.mbHidden; 202cdf0e10cSrcweir } 203cdf0e10cSrcweir 204cdf0e10cSrcweir // for group shapes, the following method is also adding each child 205cdf0e10cSrcweir void Shape::addChildren( 206cdf0e10cSrcweir XmlFilterBase& rFilterBase, 207cdf0e10cSrcweir Shape& rMaster, 208cdf0e10cSrcweir const Theme* pTheme, 209cdf0e10cSrcweir const Reference< XShapes >& rxShapes, 210cdf0e10cSrcweir const awt::Rectangle& rClientRect, 211cdf0e10cSrcweir ShapeIdMap* pShapeMap ) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir // first the global child union needs to be calculated 214cdf0e10cSrcweir sal_Int32 nGlobalLeft = SAL_MAX_INT32; 215cdf0e10cSrcweir sal_Int32 nGlobalRight = SAL_MIN_INT32; 216cdf0e10cSrcweir sal_Int32 nGlobalTop = SAL_MAX_INT32; 217cdf0e10cSrcweir sal_Int32 nGlobalBottom= SAL_MIN_INT32; 218cdf0e10cSrcweir std::vector< ShapePtr >::iterator aIter( rMaster.maChildren.begin() ); 219cdf0e10cSrcweir while( aIter != rMaster.maChildren.end() ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir sal_Int32 l = (*aIter)->maPosition.X; 222cdf0e10cSrcweir sal_Int32 t = (*aIter)->maPosition.Y; 223cdf0e10cSrcweir sal_Int32 r = l + (*aIter)->maSize.Width; 224cdf0e10cSrcweir sal_Int32 b = t + (*aIter)->maSize.Height; 225cdf0e10cSrcweir if ( nGlobalLeft > l ) 226cdf0e10cSrcweir nGlobalLeft = l; 227cdf0e10cSrcweir if ( nGlobalRight < r ) 228cdf0e10cSrcweir nGlobalRight = r; 229cdf0e10cSrcweir if ( nGlobalTop > t ) 230cdf0e10cSrcweir nGlobalTop = t; 231cdf0e10cSrcweir if ( nGlobalBottom < b ) 232cdf0e10cSrcweir nGlobalBottom = b; 233cdf0e10cSrcweir aIter++; 234cdf0e10cSrcweir } 235cdf0e10cSrcweir aIter = rMaster.maChildren.begin(); 236cdf0e10cSrcweir while( aIter != rMaster.maChildren.end() ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir awt::Rectangle aShapeRect; 239cdf0e10cSrcweir awt::Rectangle* pShapeRect = 0; 240cdf0e10cSrcweir if ( ( nGlobalLeft != SAL_MAX_INT32 ) && ( nGlobalRight != SAL_MIN_INT32 ) && ( nGlobalTop != SAL_MAX_INT32 ) && ( nGlobalBottom != SAL_MIN_INT32 ) ) 241cdf0e10cSrcweir { 242cdf0e10cSrcweir sal_Int32 nGlobalWidth = nGlobalRight - nGlobalLeft; 243cdf0e10cSrcweir sal_Int32 nGlobalHeight = nGlobalBottom - nGlobalTop; 244cdf0e10cSrcweir if ( nGlobalWidth && nGlobalHeight ) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir double fWidth = (*aIter)->maSize.Width; 247cdf0e10cSrcweir double fHeight= (*aIter)->maSize.Height; 248cdf0e10cSrcweir double fXScale = (double)rClientRect.Width / (double)nGlobalWidth; 249cdf0e10cSrcweir double fYScale = (double)rClientRect.Height / (double)nGlobalHeight; 250cdf0e10cSrcweir aShapeRect.X = static_cast< sal_Int32 >( ( ( (*aIter)->maPosition.X - nGlobalLeft ) * fXScale ) + rClientRect.X ); 251cdf0e10cSrcweir aShapeRect.Y = static_cast< sal_Int32 >( ( ( (*aIter)->maPosition.Y - nGlobalTop ) * fYScale ) + rClientRect.Y ); 252cdf0e10cSrcweir fWidth *= fXScale; 253cdf0e10cSrcweir fHeight *= fYScale; 254cdf0e10cSrcweir aShapeRect.Width = static_cast< sal_Int32 >( fWidth ); 255cdf0e10cSrcweir aShapeRect.Height = static_cast< sal_Int32 >( fHeight ); 256cdf0e10cSrcweir pShapeRect = &aShapeRect; 257cdf0e10cSrcweir } 258cdf0e10cSrcweir } 259cdf0e10cSrcweir (*aIter++)->addShape( rFilterBase, pTheme, rxShapes, pShapeRect, pShapeMap ); 260cdf0e10cSrcweir } 261cdf0e10cSrcweir } 262cdf0e10cSrcweir 263cdf0e10cSrcweir Reference< XShape > Shape::createAndInsert( 264cdf0e10cSrcweir ::oox::core::XmlFilterBase& rFilterBase, 265cdf0e10cSrcweir const rtl::OUString& rServiceName, 266cdf0e10cSrcweir const Theme* pTheme, 267cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, 268cdf0e10cSrcweir const awt::Rectangle* pShapeRect, 269cdf0e10cSrcweir sal_Bool bClearText ) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir awt::Size aSize( pShapeRect ? awt::Size( pShapeRect->Width, pShapeRect->Height ) : maSize ); 272cdf0e10cSrcweir awt::Point aPosition( pShapeRect ? awt::Point( pShapeRect->X, pShapeRect->Y ) : maPosition ); 273cdf0e10cSrcweir awt::Rectangle aShapeRectHmm( aPosition.X / 360, aPosition.Y / 360, aSize.Width / 360, aSize.Height / 360 ); 274cdf0e10cSrcweir 275cdf0e10cSrcweir OUString aServiceName = finalizeServiceName( rFilterBase, rServiceName, aShapeRectHmm ); 276cdf0e10cSrcweir sal_Bool bIsCustomShape = aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.drawing.CustomShape" ) ); 277cdf0e10cSrcweir 278cdf0e10cSrcweir basegfx::B2DHomMatrix aTransformation; 279cdf0e10cSrcweir if( aSize.Width != 1 || aSize.Height != 1) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir // take care there are no zeros used by error 282cdf0e10cSrcweir aTransformation.scale( 283cdf0e10cSrcweir aSize.Width ? aSize.Width / 360.0 : 1.0, 284cdf0e10cSrcweir aSize.Height ? aSize.Height / 360.0 : 1.0 ); 285cdf0e10cSrcweir } 286cdf0e10cSrcweir 287cdf0e10cSrcweir if( mbFlipH || mbFlipV || mnRotation != 0) 288cdf0e10cSrcweir { 289cdf0e10cSrcweir // calculate object's center 290cdf0e10cSrcweir basegfx::B2DPoint aCenter(0.5, 0.5); 291cdf0e10cSrcweir aCenter *= aTransformation; 292cdf0e10cSrcweir 293cdf0e10cSrcweir // center object at origin 294cdf0e10cSrcweir aTransformation.translate( -aCenter.getX(), -aCenter.getY() ); 295cdf0e10cSrcweir 296cdf0e10cSrcweir if( !bIsCustomShape && ( mbFlipH || mbFlipV ) ) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir // mirror around object's center 299cdf0e10cSrcweir aTransformation.scale( mbFlipH ? -1.0 : 1.0, mbFlipV ? -1.0 : 1.0 ); 300cdf0e10cSrcweir } 301cdf0e10cSrcweir 302cdf0e10cSrcweir if( mnRotation != 0 ) 303cdf0e10cSrcweir { 304cdf0e10cSrcweir // rotate around object's center 305cdf0e10cSrcweir aTransformation.rotate( F_PI180 * ( (double)mnRotation / 60000.0 ) ); 306cdf0e10cSrcweir } 307cdf0e10cSrcweir 308cdf0e10cSrcweir // move object back from center 309cdf0e10cSrcweir aTransformation.translate( aCenter.getX(), aCenter.getY() ); 310cdf0e10cSrcweir } 311cdf0e10cSrcweir 312cdf0e10cSrcweir if( aPosition.X != 0 || aPosition.Y != 0) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir // if global position is used, add it to transformation 315cdf0e10cSrcweir aTransformation.translate( aPosition.X / 360.0, aPosition.Y / 360.0 ); 316cdf0e10cSrcweir } 317cdf0e10cSrcweir 318cdf0e10cSrcweir // special for lineshape 319cdf0e10cSrcweir if ( aServiceName == OUString::createFromAscii( "com.sun.star.drawing.LineShape" ) ) 320cdf0e10cSrcweir { 321cdf0e10cSrcweir ::basegfx::B2DPolygon aPoly; 322cdf0e10cSrcweir aPoly.insert( 0, ::basegfx::B2DPoint( 0, 0 ) ); 323cdf0e10cSrcweir aPoly.insert( 1, ::basegfx::B2DPoint( maSize.Width ? 1 : 0, maSize.Height ? 1 : 0 ) ); 324cdf0e10cSrcweir aPoly.transform( aTransformation ); 325cdf0e10cSrcweir 326cdf0e10cSrcweir // now creating the corresponding PolyPolygon 327cdf0e10cSrcweir sal_Int32 i, nNumPoints = aPoly.count(); 328cdf0e10cSrcweir uno::Sequence< awt::Point > aPointSequence( nNumPoints ); 329cdf0e10cSrcweir awt::Point* pPoints = aPointSequence.getArray(); 330cdf0e10cSrcweir for( i = 0; i < nNumPoints; ++i ) 331cdf0e10cSrcweir { 332cdf0e10cSrcweir const ::basegfx::B2DPoint aPoint( aPoly.getB2DPoint( i ) ); 333cdf0e10cSrcweir pPoints[ i ] = awt::Point( static_cast< sal_Int32 >( aPoint.getX() ), static_cast< sal_Int32 >( aPoint.getY() ) ); 334cdf0e10cSrcweir } 335cdf0e10cSrcweir uno::Sequence< uno::Sequence< awt::Point > > aPolyPolySequence( 1 ); 336cdf0e10cSrcweir aPolyPolySequence.getArray()[ 0 ] = aPointSequence; 337cdf0e10cSrcweir 338cdf0e10cSrcweir maShapeProperties[ PROP_PolyPolygon ] <<= aPolyPolySequence; 339cdf0e10cSrcweir } 340cdf0e10cSrcweir else if ( aServiceName == OUString::createFromAscii( "com.sun.star.drawing.ConnectorShape" ) ) 341cdf0e10cSrcweir { 342cdf0e10cSrcweir ::basegfx::B2DPolygon aPoly; 343cdf0e10cSrcweir aPoly.insert( 0, ::basegfx::B2DPoint( 0, 0 ) ); 344cdf0e10cSrcweir aPoly.insert( 1, ::basegfx::B2DPoint( maSize.Width ? 1 : 0, maSize.Height ? 1 : 0 ) ); 345cdf0e10cSrcweir aPoly.transform( aTransformation ); 346cdf0e10cSrcweir 347cdf0e10cSrcweir basegfx::B2DPoint aStartPosition( aPoly.getB2DPoint( 0 ) ); 348cdf0e10cSrcweir basegfx::B2DPoint aEndPosition( aPoly.getB2DPoint( 1 ) ); 349cdf0e10cSrcweir awt::Point aAWTStartPosition( static_cast< sal_Int32 >( aStartPosition.getX() ), static_cast< sal_Int32 >( aStartPosition.getY() ) ); 350cdf0e10cSrcweir awt::Point aAWTEndPosition( static_cast< sal_Int32 >( aEndPosition.getX() ), static_cast< sal_Int32 >( aEndPosition.getY() ) ); 351cdf0e10cSrcweir 352cdf0e10cSrcweir maShapeProperties[ PROP_StartPosition ] <<= aAWTStartPosition; 353cdf0e10cSrcweir maShapeProperties[ PROP_EndPosition ] <<= aAWTEndPosition; 354cdf0e10cSrcweir } 355cdf0e10cSrcweir else 356cdf0e10cSrcweir { 357cdf0e10cSrcweir // now set transformation for this object 358cdf0e10cSrcweir HomogenMatrix3 aMatrix; 359cdf0e10cSrcweir 360cdf0e10cSrcweir aMatrix.Line1.Column1 = aTransformation.get(0,0); 361cdf0e10cSrcweir aMatrix.Line1.Column2 = aTransformation.get(0,1); 362cdf0e10cSrcweir aMatrix.Line1.Column3 = aTransformation.get(0,2); 363cdf0e10cSrcweir 364cdf0e10cSrcweir aMatrix.Line2.Column1 = aTransformation.get(1,0); 365cdf0e10cSrcweir aMatrix.Line2.Column2 = aTransformation.get(1,1); 366cdf0e10cSrcweir aMatrix.Line2.Column3 = aTransformation.get(1,2); 367cdf0e10cSrcweir 368cdf0e10cSrcweir aMatrix.Line3.Column1 = aTransformation.get(2,0); 369cdf0e10cSrcweir aMatrix.Line3.Column2 = aTransformation.get(2,1); 370cdf0e10cSrcweir aMatrix.Line3.Column3 = aTransformation.get(2,2); 371cdf0e10cSrcweir 372cdf0e10cSrcweir maShapeProperties[ PROP_Transformation ] <<= aMatrix; 373cdf0e10cSrcweir } 374cdf0e10cSrcweir Reference< lang::XMultiServiceFactory > xServiceFact( rFilterBase.getModel(), UNO_QUERY_THROW ); 375cdf0e10cSrcweir if ( !mxShape.is() ) 376cdf0e10cSrcweir mxShape = Reference< drawing::XShape >( xServiceFact->createInstance( aServiceName ), UNO_QUERY_THROW ); 377cdf0e10cSrcweir 378cdf0e10cSrcweir Reference< XPropertySet > xSet( mxShape, UNO_QUERY ); 379cdf0e10cSrcweir if( mxShape.is() && xSet.is() ) 380cdf0e10cSrcweir { 381cdf0e10cSrcweir if( msName.getLength() ) 382cdf0e10cSrcweir { 383cdf0e10cSrcweir Reference< container::XNamed > xNamed( mxShape, UNO_QUERY ); 384cdf0e10cSrcweir if( xNamed.is() ) 385cdf0e10cSrcweir xNamed->setName( msName ); 386cdf0e10cSrcweir } 387cdf0e10cSrcweir rxShapes->add( mxShape ); 388cdf0e10cSrcweir 389cdf0e10cSrcweir if ( mbHidden ) 390cdf0e10cSrcweir { 391cdf0e10cSrcweir const OUString sHidden( CREATE_OUSTRING( "Visible" ) ); 392cdf0e10cSrcweir xSet->setPropertyValue( sHidden, Any( !mbHidden ) ); 393cdf0e10cSrcweir } 394cdf0e10cSrcweir 395cdf0e10cSrcweir Reference< document::XActionLockable > xLockable( mxShape, UNO_QUERY ); 396cdf0e10cSrcweir if( xLockable.is() ) 397cdf0e10cSrcweir xLockable->addActionLock(); 398cdf0e10cSrcweir 399cdf0e10cSrcweir // sj: removing default text of placeholder objects such as SlideNumberShape or HeaderShape 400cdf0e10cSrcweir if ( bClearText ) 401cdf0e10cSrcweir { 402cdf0e10cSrcweir uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY ); 403cdf0e10cSrcweir if ( xText.is() ) 404cdf0e10cSrcweir { 405cdf0e10cSrcweir OUString aEmpty; 406cdf0e10cSrcweir xText->setString( aEmpty ); 407cdf0e10cSrcweir } 408cdf0e10cSrcweir } 409cdf0e10cSrcweir 410cdf0e10cSrcweir const GraphicHelper& rGraphicHelper = rFilterBase.getGraphicHelper(); 411cdf0e10cSrcweir 412cdf0e10cSrcweir LineProperties aLineProperties; 413cdf0e10cSrcweir aLineProperties.maLineFill.moFillType = XML_noFill; 414cdf0e10cSrcweir sal_Int32 nLinePhClr = -1; 415cdf0e10cSrcweir FillProperties aFillProperties; 416cdf0e10cSrcweir aFillProperties.moFillType = XML_noFill; 417cdf0e10cSrcweir sal_Int32 nFillPhClr = -1; 418cdf0e10cSrcweir 419cdf0e10cSrcweir if( pTheme ) 420cdf0e10cSrcweir { 421cdf0e10cSrcweir if( const ShapeStyleRef* pLineRef = getShapeStyleRef( XML_lnRef ) ) 422cdf0e10cSrcweir { 423cdf0e10cSrcweir if( const LineProperties* pLineProps = pTheme->getLineStyle( pLineRef->mnThemedIdx ) ) 424cdf0e10cSrcweir aLineProperties.assignUsed( *pLineProps ); 425cdf0e10cSrcweir nLinePhClr = pLineRef->maPhClr.getColor( rGraphicHelper ); 426cdf0e10cSrcweir } 427cdf0e10cSrcweir if( const ShapeStyleRef* pFillRef = getShapeStyleRef( XML_fillRef ) ) 428cdf0e10cSrcweir { 429cdf0e10cSrcweir if( const FillProperties* pFillProps = pTheme->getFillStyle( pFillRef->mnThemedIdx ) ) 430cdf0e10cSrcweir aFillProperties.assignUsed( *pFillProps ); 431cdf0e10cSrcweir nFillPhClr = pFillRef->maPhClr.getColor( rGraphicHelper ); 432cdf0e10cSrcweir } 433cdf0e10cSrcweir // if( const ShapeStyleRef* pEffectRef = getShapeStyleRef( XML_fillRef ) ) 434cdf0e10cSrcweir // { 435cdf0e10cSrcweir // if( const EffectProperties* pEffectProps = pTheme->getEffectStyle( pEffectRef->mnThemedIdx ) ) 436cdf0e10cSrcweir // aEffectProperties.assignUsed( *pEffectProps ); 437cdf0e10cSrcweir // nEffectPhClr = pEffectRef->maPhClr.getColor( rGraphicHelper ); 438cdf0e10cSrcweir // } 439cdf0e10cSrcweir } 440cdf0e10cSrcweir 441cdf0e10cSrcweir aLineProperties.assignUsed( getLineProperties() ); 442cdf0e10cSrcweir aFillProperties.assignUsed( getFillProperties() ); 443cdf0e10cSrcweir 444cdf0e10cSrcweir ShapePropertyMap aShapeProps( rFilterBase.getModelObjectHelper() ); 445cdf0e10cSrcweir 446cdf0e10cSrcweir // add properties from textbody to shape properties 447cdf0e10cSrcweir if( mpTextBody.get() ) 448cdf0e10cSrcweir aShapeProps.assignUsed( mpTextBody->getTextProperties().maPropertyMap ); 449cdf0e10cSrcweir 450cdf0e10cSrcweir // applying properties 451cdf0e10cSrcweir aShapeProps.assignUsed( getShapeProperties() ); 452cdf0e10cSrcweir if ( aServiceName == OUString::createFromAscii( "com.sun.star.drawing.GraphicObjectShape" ) ) 453cdf0e10cSrcweir mpGraphicPropertiesPtr->pushToPropMap( aShapeProps, rGraphicHelper ); 454cdf0e10cSrcweir if ( mpTablePropertiesPtr.get() && ( aServiceName == OUString::createFromAscii( "com.sun.star.drawing.TableShape" ) ) ) 455cdf0e10cSrcweir mpTablePropertiesPtr->pushToPropSet( rFilterBase, xSet, mpMasterTextListStyle ); 456cdf0e10cSrcweir aFillProperties.pushToPropMap( aShapeProps, rGraphicHelper, mnRotation, nFillPhClr ); 457cdf0e10cSrcweir aLineProperties.pushToPropMap( aShapeProps, rGraphicHelper, nLinePhClr ); 458cdf0e10cSrcweir 459cdf0e10cSrcweir // applying autogrowheight property before setting shape size, because 460cdf0e10cSrcweir // the shape size might be changed if currently autogrowheight is true 461cdf0e10cSrcweir // we must also check that the PropertySet supports the property. 462cdf0e10cSrcweir Reference< XPropertySetInfo > xSetInfo( xSet->getPropertySetInfo() ); 463cdf0e10cSrcweir const OUString& rPropName = PropertyMap::getPropertyName( PROP_TextAutoGrowHeight ); 464cdf0e10cSrcweir if( xSetInfo.is() && xSetInfo->hasPropertyByName( rPropName ) ) 465cdf0e10cSrcweir if( aShapeProps.hasProperty( PROP_TextAutoGrowHeight ) ) 466cdf0e10cSrcweir xSet->setPropertyValue( rPropName, Any( false ) ); 467cdf0e10cSrcweir 468cdf0e10cSrcweir // do not set properties at a group shape (this causes assertions from svx) 469cdf0e10cSrcweir if( aServiceName != OUString::createFromAscii( "com.sun.star.drawing.GroupShape" ) ) 470cdf0e10cSrcweir PropertySet( xSet ).setProperties( aShapeProps ); 471cdf0e10cSrcweir 472cdf0e10cSrcweir if( bIsCustomShape ) 473cdf0e10cSrcweir { 474cdf0e10cSrcweir if ( mbFlipH ) 475cdf0e10cSrcweir mpCustomShapePropertiesPtr->setMirroredX( sal_True ); 476cdf0e10cSrcweir if ( mbFlipV ) 477cdf0e10cSrcweir mpCustomShapePropertiesPtr->setMirroredY( sal_True ); 478*d742e3ecSArmin Le Grand 479*d742e3ecSArmin Le Grand // #119920 Handle missing text rotation 480*d742e3ecSArmin Le Grand if(getTextBody()) 481*d742e3ecSArmin Le Grand { 482*d742e3ecSArmin Le Grand const sal_Int32 nTextRotation(getTextBody()->getTextProperties().moRotation.get(0)); 483*d742e3ecSArmin Le Grand 484*d742e3ecSArmin Le Grand if(nTextRotation) 485*d742e3ecSArmin Le Grand { 486*d742e3ecSArmin Le Grand mpCustomShapePropertiesPtr->setTextRotation((nTextRotation * -1) / 60000); 487*d742e3ecSArmin Le Grand } 488*d742e3ecSArmin Le Grand } 489*d742e3ecSArmin Le Grand 490cdf0e10cSrcweir mpCustomShapePropertiesPtr->pushToPropSet( rFilterBase, xSet, mxShape ); 491cdf0e10cSrcweir } 492cdf0e10cSrcweir 493cdf0e10cSrcweir // in some cases, we don't have any text body. 494cdf0e10cSrcweir if( getTextBody() ) 495cdf0e10cSrcweir { 496cdf0e10cSrcweir Reference < XText > xText( mxShape, UNO_QUERY ); 497cdf0e10cSrcweir if ( xText.is() ) // not every shape is supporting an XText interface (e.g. GroupShape) 498cdf0e10cSrcweir { 499cdf0e10cSrcweir TextCharacterProperties aCharStyleProperties; 500cdf0e10cSrcweir if( const ShapeStyleRef* pFontRef = getShapeStyleRef( XML_fontRef ) ) 501cdf0e10cSrcweir { 502cdf0e10cSrcweir if( pTheme ) 503cdf0e10cSrcweir if( const TextCharacterProperties* pCharProps = pTheme->getFontStyle( pFontRef->mnThemedIdx ) ) 504cdf0e10cSrcweir aCharStyleProperties.assignUsed( *pCharProps ); 505cdf0e10cSrcweir aCharStyleProperties.maCharColor.assignIfUsed( pFontRef->maPhClr ); 506cdf0e10cSrcweir } 507cdf0e10cSrcweir 508cdf0e10cSrcweir Reference < XTextCursor > xAt = xText->createTextCursor(); 509cdf0e10cSrcweir getTextBody()->insertAt( rFilterBase, xText, xAt, aCharStyleProperties, mpMasterTextListStyle ); 510cdf0e10cSrcweir } 511cdf0e10cSrcweir } 512cdf0e10cSrcweir if( xLockable.is() ) 513cdf0e10cSrcweir xLockable->removeActionLock(); 514cdf0e10cSrcweir } 515cdf0e10cSrcweir 516cdf0e10cSrcweir if( mxShape.is() ) 517cdf0e10cSrcweir finalizeXShape( rFilterBase, rxShapes ); 518cdf0e10cSrcweir 519cdf0e10cSrcweir return mxShape; 520cdf0e10cSrcweir } 521cdf0e10cSrcweir 522cdf0e10cSrcweir // the properties of rSource which are not part of rDest are being put into rDest 523cdf0e10cSrcweir void addMissingProperties( const PropertyMap& rSource, PropertyMap& rDest ) 524cdf0e10cSrcweir { 525cdf0e10cSrcweir PropertyMap::const_iterator aSourceIter( rSource.begin() ); 526cdf0e10cSrcweir while( aSourceIter != rSource.end() ) 527cdf0e10cSrcweir { 528cdf0e10cSrcweir if ( rDest.find( (*aSourceIter ).first ) == rDest.end() ) 529cdf0e10cSrcweir rDest[ (*aSourceIter).first ] <<= (*aSourceIter).second; 530cdf0e10cSrcweir aSourceIter++; 531cdf0e10cSrcweir } 532cdf0e10cSrcweir } 533cdf0e10cSrcweir 534cdf0e10cSrcweir void Shape::setTextBody(const TextBodyPtr & pTextBody) 535cdf0e10cSrcweir { 536cdf0e10cSrcweir mpTextBody = pTextBody; 537cdf0e10cSrcweir } 538cdf0e10cSrcweir 539cdf0e10cSrcweir 540cdf0e10cSrcweir TextBodyPtr Shape::getTextBody() 541cdf0e10cSrcweir { 542cdf0e10cSrcweir return mpTextBody; 543cdf0e10cSrcweir } 544cdf0e10cSrcweir 545cdf0e10cSrcweir void Shape::setMasterTextListStyle( const TextListStylePtr& pMasterTextListStyle ) 546cdf0e10cSrcweir { 547cdf0e10cSrcweir mpMasterTextListStyle = pMasterTextListStyle; 548cdf0e10cSrcweir } 549cdf0e10cSrcweir 550cdf0e10cSrcweir OUString Shape::finalizeServiceName( XmlFilterBase& rFilter, const OUString& rServiceName, const Rectangle& rShapeRect ) 551cdf0e10cSrcweir { 552cdf0e10cSrcweir OUString aServiceName = rServiceName; 553cdf0e10cSrcweir switch( meFrameType ) 554cdf0e10cSrcweir { 555cdf0e10cSrcweir case FRAMETYPE_OLEOBJECT: 556cdf0e10cSrcweir { 557cdf0e10cSrcweir Size aOleSize( rShapeRect.Width, rShapeRect.Height ); 558cdf0e10cSrcweir if( rFilter.getOleObjectHelper().importOleObject( maShapeProperties, *mxOleObjectInfo, aOleSize ) ) 559cdf0e10cSrcweir aServiceName = CREATE_OUSTRING( "com.sun.star.drawing.OLE2Shape" ); 560cdf0e10cSrcweir 561cdf0e10cSrcweir // get the path to the representation graphic 562cdf0e10cSrcweir OUString aGraphicPath; 563cdf0e10cSrcweir if( mxOleObjectInfo->maShapeId.getLength() > 0 ) 564cdf0e10cSrcweir if( ::oox::vml::Drawing* pVmlDrawing = rFilter.getVmlDrawing() ) 565cdf0e10cSrcweir if( const ::oox::vml::ShapeBase* pVmlShape = pVmlDrawing->getShapes().getShapeById( mxOleObjectInfo->maShapeId, true ) ) 566cdf0e10cSrcweir aGraphicPath = pVmlShape->getGraphicPath(); 567cdf0e10cSrcweir 568cdf0e10cSrcweir // import and store the graphic 569cdf0e10cSrcweir if( aGraphicPath.getLength() > 0 ) 570cdf0e10cSrcweir { 571cdf0e10cSrcweir Reference< graphic::XGraphic > xGraphic = rFilter.getGraphicHelper().importEmbeddedGraphic( aGraphicPath ); 572cdf0e10cSrcweir if( xGraphic.is() ) 573cdf0e10cSrcweir maShapeProperties[ PROP_Graphic ] <<= xGraphic; 574cdf0e10cSrcweir } 575cdf0e10cSrcweir } 576cdf0e10cSrcweir break; 577cdf0e10cSrcweir 578cdf0e10cSrcweir default:; 579cdf0e10cSrcweir } 580cdf0e10cSrcweir return aServiceName; 581cdf0e10cSrcweir } 582cdf0e10cSrcweir 583cdf0e10cSrcweir void Shape::finalizeXShape( XmlFilterBase& rFilter, const Reference< XShapes >& rxShapes ) 584cdf0e10cSrcweir { 585cdf0e10cSrcweir switch( meFrameType ) 586cdf0e10cSrcweir { 587cdf0e10cSrcweir case FRAMETYPE_CHART: 588cdf0e10cSrcweir { 589cdf0e10cSrcweir OSL_ENSURE( mxChartShapeInfo->maFragmentPath.getLength() > 0, "Shape::finalizeXShape - missing chart fragment" ); 590cdf0e10cSrcweir if( mxShape.is() && (mxChartShapeInfo->maFragmentPath.getLength() > 0) ) try 591cdf0e10cSrcweir { 592cdf0e10cSrcweir // set the chart2 OLE class ID at the OLE shape 593cdf0e10cSrcweir PropertySet aShapeProp( mxShape ); 594cdf0e10cSrcweir aShapeProp.setProperty( PROP_CLSID, CREATE_OUSTRING( "12dcae26-281f-416f-a234-c3086127382e" ) ); 595cdf0e10cSrcweir 596cdf0e10cSrcweir // get the XModel interface of the embedded object from the OLE shape 597cdf0e10cSrcweir Reference< frame::XModel > xDocModel; 598cdf0e10cSrcweir aShapeProp.getProperty( xDocModel, PROP_Model ); 599cdf0e10cSrcweir Reference< chart2::XChartDocument > xChartDoc( xDocModel, UNO_QUERY_THROW ); 600cdf0e10cSrcweir 601cdf0e10cSrcweir // load the chart data from the XML fragment 602cdf0e10cSrcweir chart::ChartSpaceModel aModel; 603cdf0e10cSrcweir rFilter.importFragment( new chart::ChartSpaceFragment( rFilter, mxChartShapeInfo->maFragmentPath, aModel ) ); 604cdf0e10cSrcweir 605cdf0e10cSrcweir // convert imported chart model to chart document 606cdf0e10cSrcweir Reference< drawing::XShapes > xExternalPage; 607cdf0e10cSrcweir if( !mxChartShapeInfo->mbEmbedShapes ) 608cdf0e10cSrcweir xExternalPage = rxShapes; 609cdf0e10cSrcweir rFilter.getChartConverter().convertFromModel( rFilter, aModel, xChartDoc, xExternalPage, mxShape->getPosition(), mxShape->getSize() ); 610cdf0e10cSrcweir } 611cdf0e10cSrcweir catch( Exception& ) 612cdf0e10cSrcweir { 613cdf0e10cSrcweir } 614cdf0e10cSrcweir } 615cdf0e10cSrcweir break; 616cdf0e10cSrcweir 617cdf0e10cSrcweir default:; 618cdf0e10cSrcweir } 619cdf0e10cSrcweir } 620cdf0e10cSrcweir 621cdf0e10cSrcweir // ============================================================================ 622cdf0e10cSrcweir 623cdf0e10cSrcweir } } 624