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
Shape(const sal_Char * pServiceName)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
~Shape()88cdf0e10cSrcweir Shape::~Shape()
89cdf0e10cSrcweir {
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
getTableProperties()92cdf0e10cSrcweir table::TablePropertiesPtr Shape::getTableProperties()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir if ( !mpTablePropertiesPtr.get() )
95cdf0e10cSrcweir mpTablePropertiesPtr.reset( new table::TableProperties() );
96cdf0e10cSrcweir return mpTablePropertiesPtr;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir
setDefaults()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
setOleObjectType()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
setChartType(bool bEmbedShapes)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
setDiagramType()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
setTableType()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
setServiceName(const sal_Char * pServiceName)143cdf0e10cSrcweir void Shape::setServiceName( const sal_Char* pServiceName )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir if ( pServiceName )
146cdf0e10cSrcweir msServiceName = OUString::createFromAscii( pServiceName );
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
149cdf0e10cSrcweir
getShapeStyleRef(sal_Int32 nRefType) const150cdf0e10cSrcweir 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
addShape(::oox::core::XmlFilterBase & rFilterBase,const Theme * pTheme,const Reference<XShapes> & rxShapes,const awt::Rectangle * pShapeRect,ShapeIdMap * pShapeMap)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
applyShapeReference(const Shape & rReferencedShape)186cdf0e10cSrcweir void Shape::applyShapeReference( const Shape& rReferencedShape )
187cdf0e10cSrcweir {
188*4b2c1a94SSteve Yin if ( rReferencedShape.mpTextBody.get() )
189cdf0e10cSrcweir mpTextBody = TextBodyPtr( new TextBody( *rReferencedShape.mpTextBody.get() ) );
190cdf0e10cSrcweir maShapeProperties = rReferencedShape.maShapeProperties;
191cdf0e10cSrcweir mpLinePropertiesPtr = LinePropertiesPtr( new LineProperties( *rReferencedShape.mpLinePropertiesPtr.get() ) );
192cdf0e10cSrcweir mpFillPropertiesPtr = FillPropertiesPtr( new FillProperties( *rReferencedShape.mpFillPropertiesPtr.get() ) );
193cdf0e10cSrcweir mpCustomShapePropertiesPtr = CustomShapePropertiesPtr( new CustomShapeProperties( *rReferencedShape.mpCustomShapePropertiesPtr.get() ) );
194cdf0e10cSrcweir mpTablePropertiesPtr = table::TablePropertiesPtr( rReferencedShape.mpTablePropertiesPtr.get() ? new table::TableProperties( *rReferencedShape.mpTablePropertiesPtr.get() ) : NULL );
195cdf0e10cSrcweir mpMasterTextListStyle = TextListStylePtr( new TextListStyle( *rReferencedShape.mpMasterTextListStyle.get() ) );
196cdf0e10cSrcweir maShapeStyleRefs = rReferencedShape.maShapeStyleRefs;
197cdf0e10cSrcweir maSize = rReferencedShape.maSize;
198cdf0e10cSrcweir maPosition = rReferencedShape.maPosition;
199cdf0e10cSrcweir mnRotation = rReferencedShape.mnRotation;
200cdf0e10cSrcweir mbFlipH = rReferencedShape.mbFlipH;
201cdf0e10cSrcweir mbFlipV = rReferencedShape.mbFlipV;
202cdf0e10cSrcweir mbHidden = rReferencedShape.mbHidden;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir
205cdf0e10cSrcweir // for group shapes, the following method is also adding each child
addChildren(XmlFilterBase & rFilterBase,Shape & rMaster,const Theme * pTheme,const Reference<XShapes> & rxShapes,const awt::Rectangle & rClientRect,ShapeIdMap * pShapeMap)206cdf0e10cSrcweir void Shape::addChildren(
207cdf0e10cSrcweir XmlFilterBase& rFilterBase,
208cdf0e10cSrcweir Shape& rMaster,
209cdf0e10cSrcweir const Theme* pTheme,
210cdf0e10cSrcweir const Reference< XShapes >& rxShapes,
211cdf0e10cSrcweir const awt::Rectangle& rClientRect,
212cdf0e10cSrcweir ShapeIdMap* pShapeMap )
213cdf0e10cSrcweir {
214cdf0e10cSrcweir // first the global child union needs to be calculated
215cdf0e10cSrcweir sal_Int32 nGlobalLeft = SAL_MAX_INT32;
216cdf0e10cSrcweir sal_Int32 nGlobalRight = SAL_MIN_INT32;
217cdf0e10cSrcweir sal_Int32 nGlobalTop = SAL_MAX_INT32;
218cdf0e10cSrcweir sal_Int32 nGlobalBottom= SAL_MIN_INT32;
219cdf0e10cSrcweir std::vector< ShapePtr >::iterator aIter( rMaster.maChildren.begin() );
220cdf0e10cSrcweir while( aIter != rMaster.maChildren.end() )
221cdf0e10cSrcweir {
222cdf0e10cSrcweir sal_Int32 l = (*aIter)->maPosition.X;
223cdf0e10cSrcweir sal_Int32 t = (*aIter)->maPosition.Y;
224cdf0e10cSrcweir sal_Int32 r = l + (*aIter)->maSize.Width;
225cdf0e10cSrcweir sal_Int32 b = t + (*aIter)->maSize.Height;
226cdf0e10cSrcweir if ( nGlobalLeft > l )
227cdf0e10cSrcweir nGlobalLeft = l;
228cdf0e10cSrcweir if ( nGlobalRight < r )
229cdf0e10cSrcweir nGlobalRight = r;
230cdf0e10cSrcweir if ( nGlobalTop > t )
231cdf0e10cSrcweir nGlobalTop = t;
232cdf0e10cSrcweir if ( nGlobalBottom < b )
233cdf0e10cSrcweir nGlobalBottom = b;
234cdf0e10cSrcweir aIter++;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir aIter = rMaster.maChildren.begin();
237cdf0e10cSrcweir while( aIter != rMaster.maChildren.end() )
238cdf0e10cSrcweir {
239cdf0e10cSrcweir awt::Rectangle aShapeRect;
240cdf0e10cSrcweir awt::Rectangle* pShapeRect = 0;
241cdf0e10cSrcweir if ( ( nGlobalLeft != SAL_MAX_INT32 ) && ( nGlobalRight != SAL_MIN_INT32 ) && ( nGlobalTop != SAL_MAX_INT32 ) && ( nGlobalBottom != SAL_MIN_INT32 ) )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir sal_Int32 nGlobalWidth = nGlobalRight - nGlobalLeft;
244cdf0e10cSrcweir sal_Int32 nGlobalHeight = nGlobalBottom - nGlobalTop;
245cdf0e10cSrcweir if ( nGlobalWidth && nGlobalHeight )
246cdf0e10cSrcweir {
247cdf0e10cSrcweir double fWidth = (*aIter)->maSize.Width;
248cdf0e10cSrcweir double fHeight= (*aIter)->maSize.Height;
249cdf0e10cSrcweir double fXScale = (double)rClientRect.Width / (double)nGlobalWidth;
250cdf0e10cSrcweir double fYScale = (double)rClientRect.Height / (double)nGlobalHeight;
251cdf0e10cSrcweir aShapeRect.X = static_cast< sal_Int32 >( ( ( (*aIter)->maPosition.X - nGlobalLeft ) * fXScale ) + rClientRect.X );
252cdf0e10cSrcweir aShapeRect.Y = static_cast< sal_Int32 >( ( ( (*aIter)->maPosition.Y - nGlobalTop ) * fYScale ) + rClientRect.Y );
253cdf0e10cSrcweir fWidth *= fXScale;
254cdf0e10cSrcweir fHeight *= fYScale;
255cdf0e10cSrcweir aShapeRect.Width = static_cast< sal_Int32 >( fWidth );
256cdf0e10cSrcweir aShapeRect.Height = static_cast< sal_Int32 >( fHeight );
257cdf0e10cSrcweir pShapeRect = &aShapeRect;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir }
260cdf0e10cSrcweir (*aIter++)->addShape( rFilterBase, pTheme, rxShapes, pShapeRect, pShapeMap );
261cdf0e10cSrcweir }
262cdf0e10cSrcweir }
263cdf0e10cSrcweir
createAndInsert(::oox::core::XmlFilterBase & rFilterBase,const rtl::OUString & rServiceName,const Theme * pTheme,const::com::sun::star::uno::Reference<::com::sun::star::drawing::XShapes> & rxShapes,const awt::Rectangle * pShapeRect,sal_Bool bClearText)264cdf0e10cSrcweir Reference< XShape > Shape::createAndInsert(
265cdf0e10cSrcweir ::oox::core::XmlFilterBase& rFilterBase,
266cdf0e10cSrcweir const rtl::OUString& rServiceName,
267cdf0e10cSrcweir const Theme* pTheme,
268cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
269cdf0e10cSrcweir const awt::Rectangle* pShapeRect,
270cdf0e10cSrcweir sal_Bool bClearText )
271cdf0e10cSrcweir {
272cdf0e10cSrcweir awt::Size aSize( pShapeRect ? awt::Size( pShapeRect->Width, pShapeRect->Height ) : maSize );
273cdf0e10cSrcweir awt::Point aPosition( pShapeRect ? awt::Point( pShapeRect->X, pShapeRect->Y ) : maPosition );
274cdf0e10cSrcweir awt::Rectangle aShapeRectHmm( aPosition.X / 360, aPosition.Y / 360, aSize.Width / 360, aSize.Height / 360 );
275cdf0e10cSrcweir
276cdf0e10cSrcweir OUString aServiceName = finalizeServiceName( rFilterBase, rServiceName, aShapeRectHmm );
277cdf0e10cSrcweir sal_Bool bIsCustomShape = aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.drawing.CustomShape" ) );
278cdf0e10cSrcweir
279cdf0e10cSrcweir basegfx::B2DHomMatrix aTransformation;
280cdf0e10cSrcweir if( aSize.Width != 1 || aSize.Height != 1)
281cdf0e10cSrcweir {
282cdf0e10cSrcweir // take care there are no zeros used by error
283cdf0e10cSrcweir aTransformation.scale(
284cdf0e10cSrcweir aSize.Width ? aSize.Width / 360.0 : 1.0,
285cdf0e10cSrcweir aSize.Height ? aSize.Height / 360.0 : 1.0 );
286cdf0e10cSrcweir }
287cdf0e10cSrcweir
288cdf0e10cSrcweir if( mbFlipH || mbFlipV || mnRotation != 0)
289cdf0e10cSrcweir {
290cdf0e10cSrcweir // calculate object's center
291cdf0e10cSrcweir basegfx::B2DPoint aCenter(0.5, 0.5);
292cdf0e10cSrcweir aCenter *= aTransformation;
293cdf0e10cSrcweir
294cdf0e10cSrcweir // center object at origin
295cdf0e10cSrcweir aTransformation.translate( -aCenter.getX(), -aCenter.getY() );
296cdf0e10cSrcweir
297cdf0e10cSrcweir if( !bIsCustomShape && ( mbFlipH || mbFlipV ) )
298cdf0e10cSrcweir {
299cdf0e10cSrcweir // mirror around object's center
300cdf0e10cSrcweir aTransformation.scale( mbFlipH ? -1.0 : 1.0, mbFlipV ? -1.0 : 1.0 );
301cdf0e10cSrcweir }
302cdf0e10cSrcweir
303cdf0e10cSrcweir if( mnRotation != 0 )
304cdf0e10cSrcweir {
305cdf0e10cSrcweir // rotate around object's center
306cdf0e10cSrcweir aTransformation.rotate( F_PI180 * ( (double)mnRotation / 60000.0 ) );
307cdf0e10cSrcweir }
308cdf0e10cSrcweir
309cdf0e10cSrcweir // move object back from center
310cdf0e10cSrcweir aTransformation.translate( aCenter.getX(), aCenter.getY() );
311cdf0e10cSrcweir }
312cdf0e10cSrcweir
313cdf0e10cSrcweir if( aPosition.X != 0 || aPosition.Y != 0)
314cdf0e10cSrcweir {
315cdf0e10cSrcweir // if global position is used, add it to transformation
316cdf0e10cSrcweir aTransformation.translate( aPosition.X / 360.0, aPosition.Y / 360.0 );
317cdf0e10cSrcweir }
318cdf0e10cSrcweir
319cdf0e10cSrcweir // special for lineshape
320cdf0e10cSrcweir if ( aServiceName == OUString::createFromAscii( "com.sun.star.drawing.LineShape" ) )
321cdf0e10cSrcweir {
322cdf0e10cSrcweir ::basegfx::B2DPolygon aPoly;
323cdf0e10cSrcweir aPoly.insert( 0, ::basegfx::B2DPoint( 0, 0 ) );
324cdf0e10cSrcweir aPoly.insert( 1, ::basegfx::B2DPoint( maSize.Width ? 1 : 0, maSize.Height ? 1 : 0 ) );
325cdf0e10cSrcweir aPoly.transform( aTransformation );
326cdf0e10cSrcweir
327cdf0e10cSrcweir // now creating the corresponding PolyPolygon
328cdf0e10cSrcweir sal_Int32 i, nNumPoints = aPoly.count();
329cdf0e10cSrcweir uno::Sequence< awt::Point > aPointSequence( nNumPoints );
330cdf0e10cSrcweir awt::Point* pPoints = aPointSequence.getArray();
331cdf0e10cSrcweir for( i = 0; i < nNumPoints; ++i )
332cdf0e10cSrcweir {
333cdf0e10cSrcweir const ::basegfx::B2DPoint aPoint( aPoly.getB2DPoint( i ) );
334cdf0e10cSrcweir pPoints[ i ] = awt::Point( static_cast< sal_Int32 >( aPoint.getX() ), static_cast< sal_Int32 >( aPoint.getY() ) );
335cdf0e10cSrcweir }
336cdf0e10cSrcweir uno::Sequence< uno::Sequence< awt::Point > > aPolyPolySequence( 1 );
337cdf0e10cSrcweir aPolyPolySequence.getArray()[ 0 ] = aPointSequence;
338cdf0e10cSrcweir
339cdf0e10cSrcweir maShapeProperties[ PROP_PolyPolygon ] <<= aPolyPolySequence;
340cdf0e10cSrcweir }
341cdf0e10cSrcweir else if ( aServiceName == OUString::createFromAscii( "com.sun.star.drawing.ConnectorShape" ) )
342cdf0e10cSrcweir {
343cdf0e10cSrcweir ::basegfx::B2DPolygon aPoly;
344cdf0e10cSrcweir aPoly.insert( 0, ::basegfx::B2DPoint( 0, 0 ) );
345cdf0e10cSrcweir aPoly.insert( 1, ::basegfx::B2DPoint( maSize.Width ? 1 : 0, maSize.Height ? 1 : 0 ) );
346cdf0e10cSrcweir aPoly.transform( aTransformation );
347cdf0e10cSrcweir
348cdf0e10cSrcweir basegfx::B2DPoint aStartPosition( aPoly.getB2DPoint( 0 ) );
349cdf0e10cSrcweir basegfx::B2DPoint aEndPosition( aPoly.getB2DPoint( 1 ) );
350cdf0e10cSrcweir awt::Point aAWTStartPosition( static_cast< sal_Int32 >( aStartPosition.getX() ), static_cast< sal_Int32 >( aStartPosition.getY() ) );
351cdf0e10cSrcweir awt::Point aAWTEndPosition( static_cast< sal_Int32 >( aEndPosition.getX() ), static_cast< sal_Int32 >( aEndPosition.getY() ) );
352cdf0e10cSrcweir
353cdf0e10cSrcweir maShapeProperties[ PROP_StartPosition ] <<= aAWTStartPosition;
354cdf0e10cSrcweir maShapeProperties[ PROP_EndPosition ] <<= aAWTEndPosition;
355cdf0e10cSrcweir }
356cdf0e10cSrcweir else
357cdf0e10cSrcweir {
358cdf0e10cSrcweir // now set transformation for this object
359cdf0e10cSrcweir HomogenMatrix3 aMatrix;
360cdf0e10cSrcweir
361cdf0e10cSrcweir aMatrix.Line1.Column1 = aTransformation.get(0,0);
362cdf0e10cSrcweir aMatrix.Line1.Column2 = aTransformation.get(0,1);
363cdf0e10cSrcweir aMatrix.Line1.Column3 = aTransformation.get(0,2);
364cdf0e10cSrcweir
365cdf0e10cSrcweir aMatrix.Line2.Column1 = aTransformation.get(1,0);
366cdf0e10cSrcweir aMatrix.Line2.Column2 = aTransformation.get(1,1);
367cdf0e10cSrcweir aMatrix.Line2.Column3 = aTransformation.get(1,2);
368cdf0e10cSrcweir
369cdf0e10cSrcweir aMatrix.Line3.Column1 = aTransformation.get(2,0);
370cdf0e10cSrcweir aMatrix.Line3.Column2 = aTransformation.get(2,1);
371cdf0e10cSrcweir aMatrix.Line3.Column3 = aTransformation.get(2,2);
372cdf0e10cSrcweir
373cdf0e10cSrcweir maShapeProperties[ PROP_Transformation ] <<= aMatrix;
374cdf0e10cSrcweir }
375cdf0e10cSrcweir Reference< lang::XMultiServiceFactory > xServiceFact( rFilterBase.getModel(), UNO_QUERY_THROW );
376cdf0e10cSrcweir if ( !mxShape.is() )
377cdf0e10cSrcweir mxShape = Reference< drawing::XShape >( xServiceFact->createInstance( aServiceName ), UNO_QUERY_THROW );
378cdf0e10cSrcweir
379cdf0e10cSrcweir Reference< XPropertySet > xSet( mxShape, UNO_QUERY );
380cdf0e10cSrcweir if( mxShape.is() && xSet.is() )
381cdf0e10cSrcweir {
382cdf0e10cSrcweir if( msName.getLength() )
383cdf0e10cSrcweir {
384cdf0e10cSrcweir Reference< container::XNamed > xNamed( mxShape, UNO_QUERY );
385cdf0e10cSrcweir if( xNamed.is() )
386cdf0e10cSrcweir xNamed->setName( msName );
387cdf0e10cSrcweir }
388cdf0e10cSrcweir rxShapes->add( mxShape );
389cdf0e10cSrcweir
390cdf0e10cSrcweir if ( mbHidden )
391cdf0e10cSrcweir {
392cdf0e10cSrcweir const OUString sHidden( CREATE_OUSTRING( "Visible" ) );
393cdf0e10cSrcweir xSet->setPropertyValue( sHidden, Any( !mbHidden ) );
394cdf0e10cSrcweir }
395cdf0e10cSrcweir
396cdf0e10cSrcweir Reference< document::XActionLockable > xLockable( mxShape, UNO_QUERY );
397cdf0e10cSrcweir if( xLockable.is() )
398cdf0e10cSrcweir xLockable->addActionLock();
399cdf0e10cSrcweir
400cdf0e10cSrcweir // sj: removing default text of placeholder objects such as SlideNumberShape or HeaderShape
401cdf0e10cSrcweir if ( bClearText )
402cdf0e10cSrcweir {
403cdf0e10cSrcweir uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY );
404cdf0e10cSrcweir if ( xText.is() )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir OUString aEmpty;
407cdf0e10cSrcweir xText->setString( aEmpty );
408cdf0e10cSrcweir }
409cdf0e10cSrcweir }
410cdf0e10cSrcweir
411cdf0e10cSrcweir const GraphicHelper& rGraphicHelper = rFilterBase.getGraphicHelper();
412cdf0e10cSrcweir
413cdf0e10cSrcweir LineProperties aLineProperties;
414cdf0e10cSrcweir aLineProperties.maLineFill.moFillType = XML_noFill;
415cdf0e10cSrcweir sal_Int32 nLinePhClr = -1;
416cdf0e10cSrcweir FillProperties aFillProperties;
417cdf0e10cSrcweir aFillProperties.moFillType = XML_noFill;
418cdf0e10cSrcweir sal_Int32 nFillPhClr = -1;
419cdf0e10cSrcweir
420cdf0e10cSrcweir if( pTheme )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir if( const ShapeStyleRef* pLineRef = getShapeStyleRef( XML_lnRef ) )
423cdf0e10cSrcweir {
424cdf0e10cSrcweir if( const LineProperties* pLineProps = pTheme->getLineStyle( pLineRef->mnThemedIdx ) )
425cdf0e10cSrcweir aLineProperties.assignUsed( *pLineProps );
426cdf0e10cSrcweir nLinePhClr = pLineRef->maPhClr.getColor( rGraphicHelper );
427cdf0e10cSrcweir }
428cdf0e10cSrcweir if( const ShapeStyleRef* pFillRef = getShapeStyleRef( XML_fillRef ) )
429cdf0e10cSrcweir {
430cdf0e10cSrcweir if( const FillProperties* pFillProps = pTheme->getFillStyle( pFillRef->mnThemedIdx ) )
431cdf0e10cSrcweir aFillProperties.assignUsed( *pFillProps );
432cdf0e10cSrcweir nFillPhClr = pFillRef->maPhClr.getColor( rGraphicHelper );
433cdf0e10cSrcweir }
434cdf0e10cSrcweir // if( const ShapeStyleRef* pEffectRef = getShapeStyleRef( XML_fillRef ) )
435cdf0e10cSrcweir // {
436cdf0e10cSrcweir // if( const EffectProperties* pEffectProps = pTheme->getEffectStyle( pEffectRef->mnThemedIdx ) )
437cdf0e10cSrcweir // aEffectProperties.assignUsed( *pEffectProps );
438cdf0e10cSrcweir // nEffectPhClr = pEffectRef->maPhClr.getColor( rGraphicHelper );
439cdf0e10cSrcweir // }
440cdf0e10cSrcweir }
441cdf0e10cSrcweir
442cdf0e10cSrcweir aLineProperties.assignUsed( getLineProperties() );
443cdf0e10cSrcweir aFillProperties.assignUsed( getFillProperties() );
444cdf0e10cSrcweir
445cdf0e10cSrcweir ShapePropertyMap aShapeProps( rFilterBase.getModelObjectHelper() );
446cdf0e10cSrcweir
447cdf0e10cSrcweir // add properties from textbody to shape properties
448cdf0e10cSrcweir if( mpTextBody.get() )
449cdf0e10cSrcweir aShapeProps.assignUsed( mpTextBody->getTextProperties().maPropertyMap );
450cdf0e10cSrcweir
451cdf0e10cSrcweir // applying properties
452cdf0e10cSrcweir aShapeProps.assignUsed( getShapeProperties() );
453cdf0e10cSrcweir if ( aServiceName == OUString::createFromAscii( "com.sun.star.drawing.GraphicObjectShape" ) )
454cdf0e10cSrcweir mpGraphicPropertiesPtr->pushToPropMap( aShapeProps, rGraphicHelper );
455cdf0e10cSrcweir if ( mpTablePropertiesPtr.get() && ( aServiceName == OUString::createFromAscii( "com.sun.star.drawing.TableShape" ) ) )
456cdf0e10cSrcweir mpTablePropertiesPtr->pushToPropSet( rFilterBase, xSet, mpMasterTextListStyle );
457cdf0e10cSrcweir aFillProperties.pushToPropMap( aShapeProps, rGraphicHelper, mnRotation, nFillPhClr );
458cdf0e10cSrcweir aLineProperties.pushToPropMap( aShapeProps, rGraphicHelper, nLinePhClr );
459cdf0e10cSrcweir
460cdf0e10cSrcweir // applying autogrowheight property before setting shape size, because
461cdf0e10cSrcweir // the shape size might be changed if currently autogrowheight is true
462cdf0e10cSrcweir // we must also check that the PropertySet supports the property.
463cdf0e10cSrcweir Reference< XPropertySetInfo > xSetInfo( xSet->getPropertySetInfo() );
464cdf0e10cSrcweir const OUString& rPropName = PropertyMap::getPropertyName( PROP_TextAutoGrowHeight );
465cdf0e10cSrcweir if( xSetInfo.is() && xSetInfo->hasPropertyByName( rPropName ) )
466cdf0e10cSrcweir if( aShapeProps.hasProperty( PROP_TextAutoGrowHeight ) )
467cdf0e10cSrcweir xSet->setPropertyValue( rPropName, Any( false ) );
468cdf0e10cSrcweir
469cdf0e10cSrcweir // do not set properties at a group shape (this causes assertions from svx)
470cdf0e10cSrcweir if( aServiceName != OUString::createFromAscii( "com.sun.star.drawing.GroupShape" ) )
471cdf0e10cSrcweir PropertySet( xSet ).setProperties( aShapeProps );
472cdf0e10cSrcweir
473cdf0e10cSrcweir if( bIsCustomShape )
474cdf0e10cSrcweir {
475cdf0e10cSrcweir if ( mbFlipH )
476cdf0e10cSrcweir mpCustomShapePropertiesPtr->setMirroredX( sal_True );
477cdf0e10cSrcweir if ( mbFlipV )
478cdf0e10cSrcweir mpCustomShapePropertiesPtr->setMirroredY( sal_True );
479d742e3ecSArmin Le Grand
480a44335ceSArmin Le Grand // #119920# Handle missing text rotation
481d742e3ecSArmin Le Grand if(getTextBody())
482d742e3ecSArmin Le Grand {
483d742e3ecSArmin Le Grand const sal_Int32 nTextRotation(getTextBody()->getTextProperties().moRotation.get(0));
484d742e3ecSArmin Le Grand
485d742e3ecSArmin Le Grand if(nTextRotation)
486d742e3ecSArmin Le Grand {
487d742e3ecSArmin Le Grand mpCustomShapePropertiesPtr->setTextRotation((nTextRotation * -1) / 60000);
488d742e3ecSArmin Le Grand }
489d742e3ecSArmin Le Grand }
490d742e3ecSArmin Le Grand
491cdf0e10cSrcweir mpCustomShapePropertiesPtr->pushToPropSet( rFilterBase, xSet, mxShape );
492cdf0e10cSrcweir }
493cdf0e10cSrcweir
494cdf0e10cSrcweir // in some cases, we don't have any text body.
495cdf0e10cSrcweir if( getTextBody() )
496cdf0e10cSrcweir {
497cdf0e10cSrcweir Reference < XText > xText( mxShape, UNO_QUERY );
498cdf0e10cSrcweir if ( xText.is() ) // not every shape is supporting an XText interface (e.g. GroupShape)
499cdf0e10cSrcweir {
500cdf0e10cSrcweir TextCharacterProperties aCharStyleProperties;
501cdf0e10cSrcweir if( const ShapeStyleRef* pFontRef = getShapeStyleRef( XML_fontRef ) )
502cdf0e10cSrcweir {
503cdf0e10cSrcweir if( pTheme )
504cdf0e10cSrcweir if( const TextCharacterProperties* pCharProps = pTheme->getFontStyle( pFontRef->mnThemedIdx ) )
505cdf0e10cSrcweir aCharStyleProperties.assignUsed( *pCharProps );
506cdf0e10cSrcweir aCharStyleProperties.maCharColor.assignIfUsed( pFontRef->maPhClr );
507cdf0e10cSrcweir }
508cdf0e10cSrcweir
509cdf0e10cSrcweir Reference < XTextCursor > xAt = xText->createTextCursor();
510cdf0e10cSrcweir getTextBody()->insertAt( rFilterBase, xText, xAt, aCharStyleProperties, mpMasterTextListStyle );
511cdf0e10cSrcweir }
512cdf0e10cSrcweir }
513cdf0e10cSrcweir if( xLockable.is() )
514cdf0e10cSrcweir xLockable->removeActionLock();
515cdf0e10cSrcweir }
516cdf0e10cSrcweir
517cdf0e10cSrcweir if( mxShape.is() )
518cdf0e10cSrcweir finalizeXShape( rFilterBase, rxShapes );
519cdf0e10cSrcweir
520cdf0e10cSrcweir return mxShape;
521cdf0e10cSrcweir }
522cdf0e10cSrcweir
523cdf0e10cSrcweir // the properties of rSource which are not part of rDest are being put into rDest
addMissingProperties(const PropertyMap & rSource,PropertyMap & rDest)524cdf0e10cSrcweir void addMissingProperties( const PropertyMap& rSource, PropertyMap& rDest )
525cdf0e10cSrcweir {
526cdf0e10cSrcweir PropertyMap::const_iterator aSourceIter( rSource.begin() );
527cdf0e10cSrcweir while( aSourceIter != rSource.end() )
528cdf0e10cSrcweir {
529cdf0e10cSrcweir if ( rDest.find( (*aSourceIter ).first ) == rDest.end() )
530cdf0e10cSrcweir rDest[ (*aSourceIter).first ] <<= (*aSourceIter).second;
531cdf0e10cSrcweir aSourceIter++;
532cdf0e10cSrcweir }
533cdf0e10cSrcweir }
534cdf0e10cSrcweir
setTextBody(const TextBodyPtr & pTextBody)535cdf0e10cSrcweir void Shape::setTextBody(const TextBodyPtr & pTextBody)
536cdf0e10cSrcweir {
537cdf0e10cSrcweir mpTextBody = pTextBody;
538cdf0e10cSrcweir }
539cdf0e10cSrcweir
540cdf0e10cSrcweir
getTextBody()541cdf0e10cSrcweir TextBodyPtr Shape::getTextBody()
542cdf0e10cSrcweir {
543cdf0e10cSrcweir return mpTextBody;
544cdf0e10cSrcweir }
545cdf0e10cSrcweir
setMasterTextListStyle(const TextListStylePtr & pMasterTextListStyle)546cdf0e10cSrcweir void Shape::setMasterTextListStyle( const TextListStylePtr& pMasterTextListStyle )
547cdf0e10cSrcweir {
548cdf0e10cSrcweir mpMasterTextListStyle = pMasterTextListStyle;
549cdf0e10cSrcweir }
550cdf0e10cSrcweir
finalizeServiceName(XmlFilterBase & rFilter,const OUString & rServiceName,const Rectangle & rShapeRect)551cdf0e10cSrcweir OUString Shape::finalizeServiceName( XmlFilterBase& rFilter, const OUString& rServiceName, const Rectangle& rShapeRect )
552cdf0e10cSrcweir {
553cdf0e10cSrcweir OUString aServiceName = rServiceName;
554cdf0e10cSrcweir switch( meFrameType )
555cdf0e10cSrcweir {
556cdf0e10cSrcweir case FRAMETYPE_OLEOBJECT:
557cdf0e10cSrcweir {
558cdf0e10cSrcweir Size aOleSize( rShapeRect.Width, rShapeRect.Height );
559cdf0e10cSrcweir if( rFilter.getOleObjectHelper().importOleObject( maShapeProperties, *mxOleObjectInfo, aOleSize ) )
560cdf0e10cSrcweir aServiceName = CREATE_OUSTRING( "com.sun.star.drawing.OLE2Shape" );
561cdf0e10cSrcweir
562cdf0e10cSrcweir // get the path to the representation graphic
563cdf0e10cSrcweir OUString aGraphicPath;
564cdf0e10cSrcweir if( mxOleObjectInfo->maShapeId.getLength() > 0 )
565cdf0e10cSrcweir if( ::oox::vml::Drawing* pVmlDrawing = rFilter.getVmlDrawing() )
566cdf0e10cSrcweir if( const ::oox::vml::ShapeBase* pVmlShape = pVmlDrawing->getShapes().getShapeById( mxOleObjectInfo->maShapeId, true ) )
567cdf0e10cSrcweir aGraphicPath = pVmlShape->getGraphicPath();
568cdf0e10cSrcweir
569cdf0e10cSrcweir // import and store the graphic
570cdf0e10cSrcweir if( aGraphicPath.getLength() > 0 )
571cdf0e10cSrcweir {
572cdf0e10cSrcweir Reference< graphic::XGraphic > xGraphic = rFilter.getGraphicHelper().importEmbeddedGraphic( aGraphicPath );
573cdf0e10cSrcweir if( xGraphic.is() )
574cdf0e10cSrcweir maShapeProperties[ PROP_Graphic ] <<= xGraphic;
575cdf0e10cSrcweir }
576cdf0e10cSrcweir }
577cdf0e10cSrcweir break;
578cdf0e10cSrcweir
579cdf0e10cSrcweir default:;
580cdf0e10cSrcweir }
581cdf0e10cSrcweir return aServiceName;
582cdf0e10cSrcweir }
583cdf0e10cSrcweir
finalizeXShape(XmlFilterBase & rFilter,const Reference<XShapes> & rxShapes)584cdf0e10cSrcweir void Shape::finalizeXShape( XmlFilterBase& rFilter, const Reference< XShapes >& rxShapes )
585cdf0e10cSrcweir {
586cdf0e10cSrcweir switch( meFrameType )
587cdf0e10cSrcweir {
588cdf0e10cSrcweir case FRAMETYPE_CHART:
589cdf0e10cSrcweir {
590cdf0e10cSrcweir OSL_ENSURE( mxChartShapeInfo->maFragmentPath.getLength() > 0, "Shape::finalizeXShape - missing chart fragment" );
591cdf0e10cSrcweir if( mxShape.is() && (mxChartShapeInfo->maFragmentPath.getLength() > 0) ) try
592cdf0e10cSrcweir {
593cdf0e10cSrcweir // set the chart2 OLE class ID at the OLE shape
594cdf0e10cSrcweir PropertySet aShapeProp( mxShape );
595cdf0e10cSrcweir aShapeProp.setProperty( PROP_CLSID, CREATE_OUSTRING( "12dcae26-281f-416f-a234-c3086127382e" ) );
596cdf0e10cSrcweir
597cdf0e10cSrcweir // get the XModel interface of the embedded object from the OLE shape
598cdf0e10cSrcweir Reference< frame::XModel > xDocModel;
599cdf0e10cSrcweir aShapeProp.getProperty( xDocModel, PROP_Model );
600cdf0e10cSrcweir Reference< chart2::XChartDocument > xChartDoc( xDocModel, UNO_QUERY_THROW );
601cdf0e10cSrcweir
602cdf0e10cSrcweir // load the chart data from the XML fragment
603cdf0e10cSrcweir chart::ChartSpaceModel aModel;
604cdf0e10cSrcweir rFilter.importFragment( new chart::ChartSpaceFragment( rFilter, mxChartShapeInfo->maFragmentPath, aModel ) );
605cdf0e10cSrcweir
606cdf0e10cSrcweir // convert imported chart model to chart document
607cdf0e10cSrcweir Reference< drawing::XShapes > xExternalPage;
608cdf0e10cSrcweir if( !mxChartShapeInfo->mbEmbedShapes )
609cdf0e10cSrcweir xExternalPage = rxShapes;
610cdf0e10cSrcweir rFilter.getChartConverter().convertFromModel( rFilter, aModel, xChartDoc, xExternalPage, mxShape->getPosition(), mxShape->getSize() );
611cdf0e10cSrcweir }
612cdf0e10cSrcweir catch( Exception& )
613cdf0e10cSrcweir {
614cdf0e10cSrcweir }
615cdf0e10cSrcweir }
616cdf0e10cSrcweir break;
617cdf0e10cSrcweir
618cdf0e10cSrcweir default:;
619cdf0e10cSrcweir }
620cdf0e10cSrcweir }
621cdf0e10cSrcweir
622cdf0e10cSrcweir // ============================================================================
623cdf0e10cSrcweir
624cdf0e10cSrcweir } }
625