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