Line data Source code
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 :
20 : #include "oox/drawingml/shape.hxx"
21 : #include "oox/drawingml/customshapeproperties.hxx"
22 : #include "oox/drawingml/theme.hxx"
23 : #include "oox/drawingml/fillproperties.hxx"
24 : #include "oox/drawingml/lineproperties.hxx"
25 : #include "oox/drawingml/effectproperties.hxx"
26 : #include "oox/drawingml/shapepropertymap.hxx"
27 : #include "oox/drawingml/textbody.hxx"
28 : #include "oox/drawingml/table/tableproperties.hxx"
29 : #include "oox/drawingml/chart/chartconverter.hxx"
30 : #include "oox/drawingml/chart/chartspacefragment.hxx"
31 : #include "oox/drawingml/chart/chartspacemodel.hxx"
32 : #include "oox/vml/vmldrawing.hxx"
33 : #include "oox/vml/vmlshape.hxx"
34 : #include "oox/vml/vmlshapecontainer.hxx"
35 : #include "oox/core/xmlfilterbase.hxx"
36 : #include "oox/helper/graphichelper.hxx"
37 : #include "oox/helper/propertyset.hxx"
38 :
39 : #include <tools/solar.h> // for the F_PI180 define
40 : #include <com/sun/star/graphic/XGraphic.hpp>
41 : #include <com/sun/star/container/XNamed.hpp>
42 : #include <com/sun/star/container/XNameContainer.hpp>
43 : #include <com/sun/star/beans/XMultiPropertySet.hpp>
44 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45 : #include <com/sun/star/xml/AttributeData.hpp>
46 : #include <com/sun/star/drawing/HomogenMatrix3.hpp>
47 : #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
48 : #include <com/sun/star/text/XText.hpp>
49 : #include <com/sun/star/chart2/XChartDocument.hpp>
50 : #include <com/sun/star/style/ParagraphAdjust.hpp>
51 : #include <basegfx/point/b2dpoint.hxx>
52 : #include <basegfx/polygon/b2dpolygon.hxx>
53 : #include <basegfx/matrix/b2dhommatrix.hxx>
54 : #include <com/sun/star/document/XActionLockable.hpp>
55 :
56 : using namespace ::oox::core;
57 : using namespace ::com::sun::star;
58 : using namespace ::com::sun::star::uno;
59 : using namespace ::com::sun::star::beans;
60 : using namespace ::com::sun::star::frame;
61 : using namespace ::com::sun::star::text;
62 : using namespace ::com::sun::star::drawing;
63 : using namespace ::com::sun::star::style;
64 :
65 : namespace oox { namespace drawingml {
66 :
67 : // ============================================================================
68 :
69 549 : Shape::Shape( const sal_Char* pServiceName )
70 : : mbIsChild( false )
71 549 : , mpLinePropertiesPtr( new LineProperties )
72 549 : , mpFillPropertiesPtr( new FillProperties )
73 549 : , mpGraphicPropertiesPtr( new GraphicProperties )
74 549 : , mpCustomShapePropertiesPtr( new CustomShapeProperties )
75 549 : , mpEffectPropertiesPtr( new EffectProperties )
76 549 : , mpMasterTextListStyle( new TextListStyle )
77 : , mnSubType( 0 )
78 : , meFrameType( FRAMETYPE_GENERIC )
79 : , mnRotation( 0 )
80 : , mbFlipH( false )
81 : , mbFlipV( false )
82 : , mbHidden( false )
83 : , mbHiddenMasterShape( false )
84 3843 : , mbLockedCanvas( false )
85 : {
86 549 : if ( pServiceName )
87 222 : msServiceName = OUString::createFromAscii( pServiceName );
88 549 : setDefaults();
89 549 : }
90 :
91 0 : Shape::Shape( const ShapePtr& pSourceShape )
92 : : maChildren()
93 0 : , mbIsChild( pSourceShape->mbIsChild )
94 0 : , mpTextBody(pSourceShape->mpTextBody)
95 0 : , mpLinePropertiesPtr( pSourceShape->mpLinePropertiesPtr )
96 0 : , mpFillPropertiesPtr( pSourceShape->mpFillPropertiesPtr )
97 0 : , mpGraphicPropertiesPtr( pSourceShape->mpGraphicPropertiesPtr )
98 0 : , mpCustomShapePropertiesPtr( pSourceShape->mpCustomShapePropertiesPtr )
99 0 : , mpTablePropertiesPtr( pSourceShape->mpTablePropertiesPtr )
100 0 : , mp3DPropertiesPtr( pSourceShape->mp3DPropertiesPtr )
101 0 : , mpEffectPropertiesPtr (pSourceShape->mpEffectPropertiesPtr)
102 0 : , maShapeProperties( pSourceShape->maShapeProperties )
103 0 : , mpMasterTextListStyle( pSourceShape->mpMasterTextListStyle )
104 : , mxShape()
105 0 : , msServiceName( pSourceShape->msServiceName )
106 0 : , msName( pSourceShape->msName )
107 0 : , msId( pSourceShape->msId )
108 0 : , mnSubType( pSourceShape->mnSubType )
109 0 : , moSubTypeIndex( pSourceShape->moSubTypeIndex )
110 0 : , maShapeStyleRefs( pSourceShape->maShapeStyleRefs )
111 0 : , maSize( pSourceShape->maSize )
112 0 : , maPosition( pSourceShape->maPosition )
113 0 : , meFrameType( pSourceShape->meFrameType )
114 0 : , mnRotation( pSourceShape->mnRotation )
115 0 : , mbFlipH( pSourceShape->mbFlipH )
116 0 : , mbFlipV( pSourceShape->mbFlipV )
117 0 : , mbHidden( pSourceShape->mbHidden )
118 0 : , mbHiddenMasterShape( pSourceShape->mbHiddenMasterShape )
119 0 : , mbLockedCanvas( pSourceShape->mbLockedCanvas )
120 0 : {}
121 :
122 :
123 604 : Shape::~Shape()
124 : {
125 604 : }
126 :
127 0 : table::TablePropertiesPtr Shape::getTableProperties()
128 : {
129 0 : if ( !mpTablePropertiesPtr.get() )
130 0 : mpTablePropertiesPtr.reset( new table::TableProperties() );
131 0 : return mpTablePropertiesPtr;
132 : }
133 :
134 549 : void Shape::setDefaults()
135 : {
136 549 : maDefaultShapeProperties[ PROP_TextAutoGrowHeight ] <<= false;
137 549 : maDefaultShapeProperties[ PROP_TextWordWrap ] <<= true;
138 549 : maDefaultShapeProperties[ PROP_TextLeftDistance ] <<= static_cast< sal_Int32 >( 250 );
139 549 : maDefaultShapeProperties[ PROP_TextUpperDistance ] <<= static_cast< sal_Int32 >( 125 );
140 549 : maDefaultShapeProperties[ PROP_TextRightDistance ] <<= static_cast< sal_Int32 >( 250 );
141 549 : maDefaultShapeProperties[ PROP_TextLowerDistance ] <<= static_cast< sal_Int32 >( 125 );
142 549 : maDefaultShapeProperties[ PROP_CharHeight ] <<= static_cast< float >( 18.0 );
143 549 : maDefaultShapeProperties[ PROP_TextVerticalAdjust ] <<= TextVerticalAdjust_TOP;
144 549 : maDefaultShapeProperties[ PROP_ParaAdjust ] <<= static_cast< sal_Int16 >( ParagraphAdjust_LEFT ); // check for RTL?
145 549 : }
146 :
147 0 : ::oox::vml::OleObjectInfo& Shape::setOleObjectType()
148 : {
149 : OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setOleObjectType - multiple frame types" );
150 0 : meFrameType = FRAMETYPE_OLEOBJECT;
151 0 : mxOleObjectInfo.reset( new ::oox::vml::OleObjectInfo( true ) );
152 0 : return *mxOleObjectInfo;
153 : }
154 :
155 2 : ChartShapeInfo& Shape::setChartType( bool bEmbedShapes )
156 : {
157 : OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setChartType - multiple frame types" );
158 2 : meFrameType = FRAMETYPE_CHART;
159 2 : msServiceName = "com.sun.star.drawing.OLE2Shape";
160 2 : mxChartShapeInfo.reset( new ChartShapeInfo( bEmbedShapes ) );
161 2 : return *mxChartShapeInfo;
162 : }
163 :
164 1 : void Shape::setDiagramType()
165 : {
166 : OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setDiagramType - multiple frame types" );
167 1 : meFrameType = FRAMETYPE_DIAGRAM;
168 1 : msServiceName = "com.sun.star.drawing.GroupShape";
169 1 : mnSubType = 0;
170 1 : }
171 :
172 0 : void Shape::setTableType()
173 : {
174 : OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setTableType - multiple frame types" );
175 0 : meFrameType = FRAMETYPE_TABLE;
176 0 : msServiceName = "com.sun.star.drawing.TableShape";
177 0 : mnSubType = 0;
178 0 : }
179 :
180 0 : void Shape::setServiceName( const sal_Char* pServiceName )
181 : {
182 0 : if ( pServiceName )
183 0 : msServiceName = OUString::createFromAscii( pServiceName );
184 0 : }
185 :
186 :
187 442 : const ShapeStyleRef* Shape::getShapeStyleRef( sal_Int32 nRefType ) const
188 : {
189 442 : ShapeStyleRefMap::const_iterator aIt = maShapeStyleRefs.find( nRefType );
190 442 : return (aIt == maShapeStyleRefs.end()) ? 0 : &aIt->second;
191 : }
192 :
193 26 : void Shape::addShape(
194 : ::oox::core::XmlFilterBase& rFilterBase,
195 : const Theme* pTheme,
196 : const Reference< XShapes >& rxShapes,
197 : basegfx::B2DHomMatrix& aTransformation,
198 : FillProperties& rShapeOrParentShapeFillProps,
199 : const awt::Rectangle* pShapeRect,
200 : ShapeIdMap* pShapeMap )
201 : {
202 : SAL_INFO("oox", OSL_THIS_FUNC << " id: " << msId);
203 :
204 : try
205 : {
206 26 : OUString sServiceName( msServiceName );
207 26 : if( !sServiceName.isEmpty() )
208 : {
209 26 : basegfx::B2DHomMatrix aMatrix( aTransformation );
210 52 : Reference< XShape > xShape( createAndInsert( rFilterBase, sServiceName, pTheme, rxShapes, pShapeRect, sal_False, sal_False, aMatrix, rShapeOrParentShapeFillProps ) );
211 :
212 26 : if( pShapeMap && !msId.isEmpty() )
213 : {
214 2 : (*pShapeMap)[ msId ] = shared_from_this();
215 : }
216 :
217 : // if this is a group shape, we have to add also each child shape
218 52 : Reference< XShapes > xShapes( xShape, UNO_QUERY );
219 26 : if ( xShapes.is() )
220 28 : addChildren( rFilterBase, *this, pTheme, xShapes, pShapeRect ? *pShapeRect : awt::Rectangle( maPosition.X, maPosition.Y, maSize.Width, maSize.Height ), pShapeMap, aMatrix );
221 26 : }
222 : }
223 0 : catch( const Exception& )
224 : {
225 : }
226 26 : }
227 :
228 2 : void Shape::setLockedCanvas(bool bLockedCanvas)
229 : {
230 2 : mbLockedCanvas = bLockedCanvas;
231 2 : }
232 :
233 1 : bool Shape::getLockedCanvas()
234 : {
235 1 : return mbLockedCanvas;
236 : }
237 :
238 33 : void Shape::applyShapeReference( const Shape& rReferencedShape, bool bUseText )
239 : {
240 : SAL_INFO("oox", "apply shape reference: " << rReferencedShape.msId << " to shape id: " << msId);
241 :
242 33 : if ( rReferencedShape.mpTextBody.get() && bUseText )
243 32 : mpTextBody = TextBodyPtr( new TextBody( *rReferencedShape.mpTextBody.get() ) );
244 : else
245 1 : mpTextBody.reset();
246 33 : maShapeProperties = rReferencedShape.maShapeProperties;
247 33 : mpLinePropertiesPtr = LinePropertiesPtr( new LineProperties( *rReferencedShape.mpLinePropertiesPtr.get() ) );
248 33 : mpFillPropertiesPtr = FillPropertiesPtr( new FillProperties( *rReferencedShape.mpFillPropertiesPtr.get() ) );
249 33 : mpCustomShapePropertiesPtr = CustomShapePropertiesPtr( new CustomShapeProperties( *rReferencedShape.mpCustomShapePropertiesPtr.get() ) );
250 33 : mpTablePropertiesPtr = table::TablePropertiesPtr( rReferencedShape.mpTablePropertiesPtr.get() ? new table::TableProperties( *rReferencedShape.mpTablePropertiesPtr.get() ) : NULL );
251 33 : mpEffectPropertiesPtr = EffectPropertiesPtr( new EffectProperties( *rReferencedShape.mpEffectPropertiesPtr.get() ) );
252 33 : mpMasterTextListStyle = TextListStylePtr( new TextListStyle( *rReferencedShape.mpMasterTextListStyle.get() ) );
253 33 : maShapeStyleRefs = rReferencedShape.maShapeStyleRefs;
254 33 : maSize = rReferencedShape.maSize;
255 33 : maPosition = rReferencedShape.maPosition;
256 33 : mnRotation = rReferencedShape.mnRotation;
257 33 : mbFlipH = rReferencedShape.mbFlipH;
258 33 : mbFlipV = rReferencedShape.mbFlipV;
259 33 : mbHidden = rReferencedShape.mbHidden;
260 33 : }
261 :
262 0 : void Shape::addChildren( ::oox::core::XmlFilterBase& rFilterBase,
263 : const Theme* pTheme,
264 : const Reference< XShapes >& rxShapes,
265 : basegfx::B2DHomMatrix& aTransformation,
266 : const awt::Rectangle* pShapeRect,
267 : ShapeIdMap* pShapeMap )
268 : {
269 : addChildren(rFilterBase, *this, pTheme, rxShapes,
270 : pShapeRect ?
271 : *pShapeRect :
272 : awt::Rectangle( maPosition.X, maPosition.Y, maSize.Width, maSize.Height ),
273 0 : pShapeMap, aTransformation);
274 0 : }
275 :
276 : struct ActionLockGuard
277 : {
278 124 : explicit ActionLockGuard(Reference<drawing::XShape> const& xShape)
279 124 : : m_xLockable(xShape, UNO_QUERY)
280 : {
281 124 : if (m_xLockable.is()) {
282 124 : m_xLockable->addActionLock();
283 : }
284 124 : }
285 124 : ~ActionLockGuard()
286 124 : {
287 124 : if (m_xLockable.is()) {
288 124 : m_xLockable->removeActionLock();
289 : }
290 124 : }
291 : private:
292 : Reference<document::XActionLockable> m_xLockable;
293 : };
294 :
295 : // for group shapes, the following method is also adding each child
296 3 : void Shape::addChildren(
297 : XmlFilterBase& rFilterBase,
298 : Shape& rMaster,
299 : const Theme* pTheme,
300 : const Reference< XShapes >& rxShapes,
301 : const awt::Rectangle&,
302 : ShapeIdMap* pShapeMap,
303 : basegfx::B2DHomMatrix& aTransformation )
304 : {
305 3 : basegfx::B2DHomMatrix aChildTransformation;
306 :
307 3 : aChildTransformation.translate(-maChPosition.X, -maChPosition.Y);
308 3 : aChildTransformation.scale(1/(maChSize.Width ? maChSize.Width : 1.0), 1/(maChSize.Height ? maChSize.Height : 1.0));
309 3 : aChildTransformation *= aTransformation;
310 :
311 : OSL_TRACE("parent matrix:\n%f %f %f\n%f %f %f\n%f %f %f",
312 : aChildTransformation.get(0, 0),
313 : aChildTransformation.get(0, 1),
314 : aChildTransformation.get(0, 2),
315 : aChildTransformation.get(1, 0),
316 : aChildTransformation.get(1, 1),
317 : aChildTransformation.get(1, 2),
318 : aChildTransformation.get(2, 0),
319 : aChildTransformation.get(2, 1),
320 : aChildTransformation.get(2, 2));
321 :
322 3 : std::vector< ShapePtr >::iterator aIter( rMaster.maChildren.begin() );
323 14 : while( aIter != rMaster.maChildren.end() ) {
324 8 : (*aIter)->setMasterTextListStyle( mpMasterTextListStyle );
325 8 : (*aIter++)->addShape( rFilterBase, pTheme, rxShapes, aChildTransformation, getFillProperties(), NULL, pShapeMap );
326 3 : }
327 3 : }
328 :
329 124 : Reference< XShape > Shape::createAndInsert(
330 : ::oox::core::XmlFilterBase& rFilterBase,
331 : const OUString& rServiceName,
332 : const Theme* pTheme,
333 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
334 : const awt::Rectangle* /* pShapeRect */,
335 : sal_Bool bClearText,
336 : sal_Bool bDoNotInsertEmptyTextBody,
337 : basegfx::B2DHomMatrix& aParentTransformation,
338 : FillProperties& rShapeOrParentShapeFillProps )
339 : {
340 124 : bool bIsEmbMedia = false;
341 : SAL_INFO("oox", OSL_THIS_FUNC << " id: " << msId);
342 :
343 124 : awt::Rectangle aShapeRectHmm( maPosition.X / 360, maPosition.Y / 360, maSize.Width / 360, maSize.Height / 360 );
344 :
345 124 : OUString aServiceName;
346 263 : if( rServiceName == "com.sun.star.drawing.GraphicObjectShape" &&
347 139 : mpGraphicPropertiesPtr && !mpGraphicPropertiesPtr->maAudio.msEmbed.isEmpty() )
348 : {
349 0 : aServiceName = finalizeServiceName( rFilterBase, "com.sun.star.presentation.MediaShape", aShapeRectHmm );
350 0 : bIsEmbMedia = true;
351 : }
352 : else
353 : {
354 124 : aServiceName = finalizeServiceName( rFilterBase, rServiceName, aShapeRectHmm );
355 : }
356 177 : sal_Bool bIsCustomShape = ( aServiceName == "com.sun.star.drawing.CustomShape" ||
357 177 : aServiceName == "com.sun.star.drawing.ConnectorShape" );
358 :
359 248 : basegfx::B2DHomMatrix aTransformation;
360 :
361 124 : if( maSize.Width != 1 || maSize.Height != 1)
362 : {
363 : // take care there are no zeros used by error
364 : aTransformation.scale(
365 : maSize.Width ? maSize.Width : 1.0,
366 124 : maSize.Height ? maSize.Height : 1.0 );
367 : }
368 :
369 124 : if( mbFlipH || mbFlipV || mnRotation != 0)
370 : {
371 : // calculate object's center
372 6 : basegfx::B2DPoint aCenter(0.5, 0.5);
373 6 : aCenter *= aTransformation;
374 :
375 : // center object at origin
376 6 : aTransformation.translate( -aCenter.getX(), -aCenter.getY() );
377 :
378 6 : if( !bIsCustomShape && ( mbFlipH || mbFlipV ) )
379 : {
380 : // mirror around object's center
381 0 : aTransformation.scale( mbFlipH ? -1.0 : 1.0, mbFlipV ? -1.0 : 1.0 );
382 : }
383 :
384 6 : if( mnRotation != 0 )
385 : {
386 : // rotate around object's center
387 4 : aTransformation.rotate( F_PI180 * ( (double)mnRotation / 60000.0 ) );
388 : }
389 :
390 : // move object back from center
391 6 : aTransformation.translate( aCenter.getX(), aCenter.getY() );
392 : }
393 :
394 124 : if( maPosition.X != 0 || maPosition.Y != 0)
395 : {
396 : // if global position is used, add it to transformation
397 109 : aTransformation.translate( maPosition.X, maPosition.Y );
398 : }
399 :
400 124 : aTransformation = aParentTransformation*aTransformation;
401 124 : aParentTransformation = aTransformation;
402 124 : aTransformation.scale(1/360.0, 1/360.0);
403 :
404 : // special for lineshape
405 124 : if ( aServiceName == "com.sun.star.drawing.LineShape" )
406 : {
407 1 : ::basegfx::B2DPolygon aPoly;
408 1 : aPoly.insert( 0, ::basegfx::B2DPoint( 0, 0 ) );
409 1 : aPoly.insert( 1, ::basegfx::B2DPoint( maSize.Width ? 1 : 0, maSize.Height ? 1 : 0 ) );
410 1 : aPoly.transform( aTransformation );
411 :
412 : // now creating the corresponding PolyPolygon
413 1 : sal_Int32 i, nNumPoints = aPoly.count();
414 2 : uno::Sequence< awt::Point > aPointSequence( nNumPoints );
415 1 : awt::Point* pPoints = aPointSequence.getArray();
416 3 : for( i = 0; i < nNumPoints; ++i )
417 : {
418 2 : const ::basegfx::B2DPoint aPoint( aPoly.getB2DPoint( i ) );
419 2 : pPoints[ i ] = awt::Point( static_cast< sal_Int32 >( aPoint.getX() ), static_cast< sal_Int32 >( aPoint.getY() ) );
420 2 : }
421 2 : uno::Sequence< uno::Sequence< awt::Point > > aPolyPolySequence( 1 );
422 1 : aPolyPolySequence.getArray()[ 0 ] = aPointSequence;
423 :
424 2 : maShapeProperties[ PROP_PolyPolygon ] <<= aPolyPolySequence;
425 : }
426 123 : else if ( aServiceName == "com.sun.star.drawing.ConnectorShape" )
427 : {
428 0 : ::basegfx::B2DPolygon aPoly;
429 0 : aPoly.insert( 0, ::basegfx::B2DPoint( 0, 0 ) );
430 0 : aPoly.insert( 1, ::basegfx::B2DPoint( maSize.Width ? 1 : 0, maSize.Height ? 1 : 0 ) );
431 0 : aPoly.transform( aTransformation );
432 :
433 0 : basegfx::B2DPoint aStartPosition( aPoly.getB2DPoint( 0 ) );
434 0 : basegfx::B2DPoint aEndPosition( aPoly.getB2DPoint( 1 ) );
435 0 : awt::Point aAWTStartPosition( static_cast< sal_Int32 >( aStartPosition.getX() ), static_cast< sal_Int32 >( aStartPosition.getY() ) );
436 0 : awt::Point aAWTEndPosition( static_cast< sal_Int32 >( aEndPosition.getX() ), static_cast< sal_Int32 >( aEndPosition.getY() ) );
437 :
438 0 : maShapeProperties[ PROP_StartPosition ] <<= aAWTStartPosition;
439 0 : maShapeProperties[ PROP_EndPosition ] <<= aAWTEndPosition;
440 : }
441 : else
442 : {
443 : // now set transformation for this object
444 123 : HomogenMatrix3 aMatrix;
445 :
446 :
447 123 : aMatrix.Line1.Column1 = aTransformation.get(0,0);
448 123 : aMatrix.Line1.Column2 = aTransformation.get(0,1);
449 123 : aMatrix.Line1.Column3 = aTransformation.get(0,2);
450 :
451 123 : aMatrix.Line2.Column1 = aTransformation.get(1,0);
452 123 : aMatrix.Line2.Column2 = aTransformation.get(1,1);
453 123 : aMatrix.Line2.Column3 = aTransformation.get(1,2);
454 :
455 123 : aMatrix.Line3.Column1 = aTransformation.get(2,0);
456 123 : aMatrix.Line3.Column2 = aTransformation.get(2,1);
457 123 : aMatrix.Line3.Column3 = aTransformation.get(2,2);
458 :
459 123 : maShapeProperties[ PROP_Transformation ] <<= aMatrix;
460 : }
461 :
462 248 : Reference< lang::XMultiServiceFactory > xServiceFact( rFilterBase.getModel(), UNO_QUERY_THROW );
463 124 : if ( !mxShape.is() )
464 124 : mxShape = Reference< drawing::XShape >( xServiceFact->createInstance( aServiceName ), UNO_QUERY_THROW );
465 :
466 248 : Reference< XPropertySet > xSet( mxShape, UNO_QUERY );
467 124 : if( mxShape.is() && xSet.is() )
468 : {
469 124 : if( !msName.isEmpty() )
470 : {
471 115 : Reference< container::XNamed > xNamed( mxShape, UNO_QUERY );
472 115 : if( xNamed.is() )
473 115 : xNamed->setName( msName );
474 : }
475 124 : rxShapes->add( mxShape );
476 :
477 124 : if ( mbHidden || mbHiddenMasterShape )
478 : {
479 : SAL_INFO("oox", "invisible shape with id: " << msId);
480 0 : const OUString sVisible( "Visible" );
481 0 : xSet->setPropertyValue( sVisible, Any( sal_False ) );
482 : }
483 :
484 124 : ActionLockGuard const alg(mxShape);
485 :
486 : // sj: removing default text of placeholder objects such as SlideNumberShape or HeaderShape
487 124 : if ( bClearText )
488 : {
489 17 : uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY );
490 17 : if ( xText.is() )
491 : {
492 17 : OUString aEmpty;
493 17 : xText->setString( aEmpty );
494 17 : }
495 : }
496 :
497 124 : const GraphicHelper& rGraphicHelper = rFilterBase.getGraphicHelper();
498 :
499 248 : LineProperties aLineProperties;
500 124 : aLineProperties.maLineFill.moFillType = XML_noFill;
501 124 : sal_Int32 nLinePhClr = -1;
502 248 : FillProperties aFillProperties;
503 124 : aFillProperties.moFillType = XML_noFill;
504 124 : sal_Int32 nFillPhClr = -1;
505 248 : EffectProperties aEffectProperties;
506 : // TODO: use ph color when applying effect properties
507 : //sal_Int32 nEffectPhClr = -1;
508 :
509 124 : if( pTheme )
510 : {
511 118 : if( const ShapeStyleRef* pLineRef = getShapeStyleRef( XML_lnRef ) )
512 : {
513 59 : if( const LineProperties* pLineProps = pTheme->getLineStyle( pLineRef->mnThemedIdx ) )
514 58 : aLineProperties.assignUsed( *pLineProps );
515 59 : nLinePhClr = pLineRef->maPhClr.getColor( rGraphicHelper );
516 : }
517 118 : if( const ShapeStyleRef* pFillRef = getShapeStyleRef( XML_fillRef ) )
518 : {
519 59 : if( const FillProperties* pFillProps = pTheme->getFillStyle( pFillRef->mnThemedIdx ) )
520 54 : aFillProperties.assignUsed( *pFillProps );
521 59 : nFillPhClr = pFillRef->maPhClr.getColor( rGraphicHelper );
522 : }
523 118 : if( const ShapeStyleRef* pEffectRef = getShapeStyleRef( XML_effectRef ) )
524 : {
525 59 : if( const EffectProperties* pEffectProps = pTheme->getEffectStyle( pEffectRef->mnThemedIdx ) )
526 0 : aEffectProperties.assignUsed( *pEffectProps );
527 : // TODO: use ph color when applying effect properties
528 : // nEffectPhClr = pEffectRef->maPhClr.getColor( rGraphicHelper );
529 : }
530 : }
531 :
532 124 : aLineProperties.assignUsed( getLineProperties() );
533 :
534 : // group fill inherits from parent
535 124 : if ( getFillProperties().moFillType.has() && getFillProperties().moFillType.get() == XML_grpFill )
536 0 : aFillProperties.assignUsed( rShapeOrParentShapeFillProps );
537 : else
538 124 : aFillProperties.assignUsed( getFillProperties() );
539 124 : aEffectProperties.assignUsed ( getEffectProperties() );
540 :
541 248 : ShapePropertyMap aShapeProps( rFilterBase.getModelObjectHelper() );
542 :
543 : // add properties from textbody to shape properties
544 124 : if( mpTextBody.get() )
545 : {
546 96 : mpTextBody->getTextProperties().pushRotationAdjustments( mnRotation );
547 96 : aShapeProps.assignUsed( mpTextBody->getTextProperties().maPropertyMap );
548 : }
549 :
550 : // applying properties
551 124 : aShapeProps.assignUsed( getShapeProperties() );
552 124 : aShapeProps.assignUsed( maDefaultShapeProperties );
553 124 : if ( bIsEmbMedia || aServiceName == "com.sun.star.drawing.GraphicObjectShape" || aServiceName == "com.sun.star.drawing.OLE2Shape" )
554 17 : mpGraphicPropertiesPtr->pushToPropMap( aShapeProps, rGraphicHelper );
555 124 : if ( mpTablePropertiesPtr.get() && aServiceName == "com.sun.star.drawing.TableShape" )
556 0 : mpTablePropertiesPtr->pushToPropSet( rFilterBase, xSet, mpMasterTextListStyle );
557 124 : aFillProperties.pushToPropMap( aShapeProps, rGraphicHelper, mnRotation, nFillPhClr, mbFlipH, mbFlipV );
558 124 : aLineProperties.pushToPropMap( aShapeProps, rGraphicHelper, nLinePhClr );
559 : // TODO: use ph color when applying effect properties
560 124 : aEffectProperties.pushToPropMap( aShapeProps, rGraphicHelper );
561 :
562 : // applying autogrowheight property before setting shape size, because
563 : // the shape size might be changed if currently autogrowheight is true
564 : // we must also check that the PropertySet supports the property.
565 248 : Reference< XPropertySetInfo > xSetInfo( xSet->getPropertySetInfo() );
566 124 : const OUString& rPropName = PropertyMap::getPropertyName( PROP_TextAutoGrowHeight );
567 124 : if( xSetInfo.is() && xSetInfo->hasPropertyByName( rPropName ) )
568 119 : if( aShapeProps.hasProperty( PROP_TextAutoGrowHeight ) )
569 119 : xSet->setPropertyValue( rPropName, Any( false ) );
570 :
571 : // do not set properties at a group shape (this causes assertions from svx)
572 124 : if( aServiceName != "com.sun.star.drawing.GroupShape" )
573 : {
574 121 : PropertySet( xSet ).setProperties( aShapeProps );
575 121 : if (mbLockedCanvas && aServiceName == "com.sun.star.drawing.LineShape")
576 : {
577 : // It seems the position and size for lines inside a locked canvas is absolute.
578 1 : mxShape->setPosition(awt::Point(aShapeRectHmm.X, aShapeRectHmm.Y));
579 1 : mxShape->setSize(awt::Size(aShapeRectHmm.Width, aShapeRectHmm.Height));
580 : }
581 : }
582 :
583 124 : if( bIsCustomShape )
584 : {
585 71 : if ( mbFlipH )
586 3 : mpCustomShapePropertiesPtr->setMirroredX( sal_True );
587 71 : if ( mbFlipV )
588 0 : mpCustomShapePropertiesPtr->setMirroredY( sal_True );
589 71 : if( getTextBody() )
590 : {
591 65 : sal_Int32 nTextRotateAngle = static_cast< sal_Int32 >( getTextBody()->getTextProperties().moRotation.get( 0 ) );
592 65 : mpCustomShapePropertiesPtr->setTextRotateAngle( nTextRotateAngle / 60000 );
593 : }
594 :
595 : SAL_INFO("oox", "==cscode== shape name: '" << msName << "'");
596 71 : mpCustomShapePropertiesPtr->pushToPropSet( rFilterBase, xSet, mxShape );
597 : }
598 53 : else if( getTextBody() )
599 31 : getTextBody()->getTextProperties().pushVertSimulation();
600 :
601 : // in some cases, we don't have any text body.
602 124 : if( getTextBody() && ( !bDoNotInsertEmptyTextBody || !mpTextBody->isEmpty() ) )
603 : {
604 88 : Reference < XText > xText( mxShape, UNO_QUERY );
605 88 : if ( xText.is() ) // not every shape is supporting an XText interface (e.g. GroupShape)
606 : {
607 88 : TextCharacterProperties aCharStyleProperties;
608 88 : if( const ShapeStyleRef* pFontRef = getShapeStyleRef( XML_fontRef ) )
609 : {
610 52 : if( pTheme )
611 52 : if( const TextCharacterProperties* pCharProps = pTheme->getFontStyle( pFontRef->mnThemedIdx ) )
612 52 : aCharStyleProperties.assignUsed( *pCharProps );
613 : SAL_INFO("oox", "use font color");
614 52 : aCharStyleProperties.maCharColor.assignIfUsed( pFontRef->maPhClr );
615 : }
616 :
617 176 : Reference < XTextCursor > xAt = xText->createTextCursor();
618 176 : getTextBody()->insertAt( rFilterBase, xText, xAt, aCharStyleProperties, mpMasterTextListStyle );
619 88 : }
620 124 : }
621 : }
622 :
623 124 : if( mxShape.is() )
624 124 : finalizeXShape( rFilterBase, rxShapes );
625 :
626 248 : return mxShape;
627 : }
628 :
629 149 : void Shape::setTextBody(const TextBodyPtr & pTextBody)
630 : {
631 149 : mpTextBody = pTextBody;
632 149 : }
633 :
634 :
635 911 : TextBodyPtr Shape::getTextBody()
636 : {
637 911 : return mpTextBody;
638 : }
639 :
640 0 : void Shape::moveAllToPosition( const awt::Point &rPoint )
641 : {
642 0 : setPosition( awt::Point( rPoint.X + maPosition.X, rPoint.Y + maPosition.Y ) );
643 0 : for( ::std::vector<ShapePtr>::const_iterator aIt = maChildren.begin(), aEnd = maChildren.end();aIt != aEnd; ++aIt )
644 0 : (*aIt)->moveAllToPosition( rPoint );
645 0 : }
646 :
647 106 : void Shape::setMasterTextListStyle( const TextListStylePtr& pMasterTextListStyle )
648 : {
649 : SAL_INFO("oox", "set master text list style to shape id: " << msId);
650 :
651 106 : mpMasterTextListStyle = pMasterTextListStyle;
652 106 : }
653 :
654 124 : OUString Shape::finalizeServiceName( XmlFilterBase& rFilter, const OUString& rServiceName, const awt::Rectangle& rShapeRect )
655 : {
656 124 : OUString aServiceName = rServiceName;
657 124 : switch( meFrameType )
658 : {
659 : case FRAMETYPE_OLEOBJECT:
660 : {
661 0 : awt::Size aOleSize( rShapeRect.Width, rShapeRect.Height );
662 0 : if( rFilter.getOleObjectHelper().importOleObject( maShapeProperties, *mxOleObjectInfo, aOleSize ) )
663 0 : aServiceName = "com.sun.star.drawing.OLE2Shape";
664 :
665 : // get the path to the representation graphic
666 0 : OUString aGraphicPath;
667 0 : if( !mxOleObjectInfo->maShapeId.isEmpty() )
668 0 : if( ::oox::vml::Drawing* pVmlDrawing = rFilter.getVmlDrawing() )
669 0 : if( const ::oox::vml::ShapeBase* pVmlShape = pVmlDrawing->getShapes().getShapeById( mxOleObjectInfo->maShapeId, true ) )
670 0 : aGraphicPath = pVmlShape->getGraphicPath();
671 :
672 : // import and store the graphic
673 0 : if( !aGraphicPath.isEmpty() )
674 : {
675 0 : Reference< graphic::XGraphic > xGraphic = rFilter.getGraphicHelper().importEmbeddedGraphic( aGraphicPath );
676 0 : if( xGraphic.is() )
677 0 : maShapeProperties[ PROP_Graphic ] <<= xGraphic;
678 0 : }
679 : }
680 0 : break;
681 :
682 : default:;
683 : }
684 124 : return aServiceName;
685 : }
686 :
687 124 : void Shape::finalizeXShape( XmlFilterBase& rFilter, const Reference< XShapes >& rxShapes )
688 : {
689 124 : switch( meFrameType )
690 : {
691 : case FRAMETYPE_CHART:
692 : {
693 : OSL_ENSURE( !mxChartShapeInfo->maFragmentPath.isEmpty(), "Shape::finalizeXShape - missing chart fragment" );
694 2 : if( mxShape.is() && !mxChartShapeInfo->maFragmentPath.isEmpty() ) try
695 : {
696 : // set the chart2 OLE class ID at the OLE shape
697 2 : PropertySet aShapeProp( mxShape );
698 2 : aShapeProp.setProperty( PROP_CLSID, OUString( "12dcae26-281f-416f-a234-c3086127382e" ) );
699 :
700 : // get the XModel interface of the embedded object from the OLE shape
701 4 : Reference< frame::XModel > xDocModel;
702 2 : aShapeProp.getProperty( xDocModel, PROP_Model );
703 4 : Reference< chart2::XChartDocument > xChartDoc( xDocModel, UNO_QUERY_THROW );
704 :
705 : // load the chart data from the XML fragment
706 4 : chart::ChartSpaceModel aModel;
707 2 : rFilter.importFragment( new chart::ChartSpaceFragment( rFilter, mxChartShapeInfo->maFragmentPath, aModel ) );
708 :
709 : // convert imported chart model to chart document
710 4 : Reference< drawing::XShapes > xExternalPage;
711 2 : if( !mxChartShapeInfo->mbEmbedShapes )
712 0 : xExternalPage = rxShapes;
713 2 : if( rFilter.getChartConverter() )
714 4 : rFilter.getChartConverter()->convertFromModel( rFilter, aModel, xChartDoc, xExternalPage, mxShape->getPosition(), mxShape->getSize() );
715 : }
716 0 : catch( Exception& )
717 : {
718 : }
719 : }
720 2 : break;
721 :
722 : default:;
723 : }
724 124 : }
725 :
726 : // ============================================================================
727 :
728 141 : } }
729 :
730 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|