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 <com/sun/star/io/XTempFile.hpp>
21 : : #include "oox/drawingml/graphicshapecontext.hxx"
22 : : #include <osl/diagnose.h>
23 : :
24 : : #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
25 : : #include "oox/drawingml/customshapeproperties.hxx"
26 : : #include "oox/drawingml/diagram/diagram.hxx"
27 : : #include "oox/drawingml/table/tablecontext.hxx"
28 : : #include "oox/core/xmlfilterbase.hxx"
29 : : #include "oox/helper/attributelist.hxx"
30 : : #include "oox/helper/graphichelper.hxx"
31 : : #include "oox/helper/propertyset.hxx"
32 : : #include "oox/vml/vmldrawing.hxx"
33 : : #include "oox/vml/vmlshape.hxx"
34 : : #include "oox/vml/vmlshapecontainer.hxx"
35 : : #include "oox/drawingml/fillproperties.hxx"
36 : : #include "oox/drawingml/transform2dcontext.hxx"
37 : : #include "oox/helper/binaryinputstream.hxx"
38 : : #include "oox/helper/binaryoutputstream.hxx"
39 : : #include <comphelper/processfactory.hxx>
40 : :
41 : : using ::rtl::OUString;
42 : : using namespace ::com::sun::star;
43 : : using namespace ::com::sun::star::io;
44 : : using namespace ::com::sun::star::uno;
45 : : using namespace ::com::sun::star::lang;
46 : : using namespace ::com::sun::star::beans;
47 : : using namespace ::com::sun::star::xml::sax;
48 : : using namespace ::oox::core;
49 : :
50 : : namespace oox {
51 : : namespace drawingml {
52 : :
53 : : // ============================================================================
54 : : // CT_Picture
55 : :
56 : 15 : GraphicShapeContext::GraphicShapeContext( ContextHandler& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr )
57 [ + - ][ + - ]: 15 : : ShapeContext( rParent, pMasterShapePtr, pShapePtr )
[ + - ]
58 : : {
59 : 15 : }
60 : :
61 : 87 : Reference< XFastContextHandler > GraphicShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
62 : : {
63 : 87 : Reference< XFastContextHandler > xRet;
64 : :
65 [ - + - + ]: 87 : switch( getBaseToken( aElementToken ) )
66 : : {
67 : : // CT_ShapeProperties
68 : : case XML_xfrm:
69 [ # # ][ # # ]: 0 : xRet.set( new Transform2DContext( *this, xAttribs, *mpShapePtr ) );
70 : 0 : break;
71 : : case XML_blipFill:
72 [ + - ][ + - ]: 15 : xRet.set( new BlipFillContext( *this, xAttribs, mpShapePtr->getGraphicProperties().maBlipProps ) );
[ + - ][ + - ]
73 : 15 : break;
74 : : case XML_wavAudioFile:
75 : : {
76 [ # # ][ # # ]: 0 : getEmbeddedWAVAudioFile( getRelations(), xAttribs, mpShapePtr->getGraphicProperties().maAudio );
[ # # ]
77 [ # # ][ # # ]: 0 : if( !mpShapePtr->getGraphicProperties().maAudio.msEmbed.isEmpty() )
78 : : {
79 [ # # ]: 0 : Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
80 [ # # ][ # # ]: 0 : Reference< XInputStream > xInStrm( getFilter().openInputStream( mpShapePtr->getGraphicProperties().maAudio.msEmbed ), UNO_SET_THROW );
[ # # ][ # # ]
81 [ # # ][ # # ]: 0 : Reference< XTempFile > xTempFile( xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.io.TempFile" ) ), UNO_QUERY_THROW );
[ # # ][ # # ]
82 [ # # ][ # # ]: 0 : Reference< XOutputStream > xOutStrm( xTempFile->getOutputStream(), UNO_SET_THROW );
[ # # ]
83 [ # # ]: 0 : BinaryXOutputStream aOutStrm( xOutStrm, false );
84 [ # # ]: 0 : BinaryXInputStream aInStrm( xInStrm, false );
85 [ # # ]: 0 : aInStrm.copyToStream( aOutStrm );
86 : :
87 [ # # ][ # # ]: 0 : xTempFile->setRemoveFile( false );
88 [ # # ][ # # ]: 0 : mpShapePtr->getGraphicProperties().maAudio.msEmbed = xTempFile->getUri();
[ # # ][ # # ]
[ # # ]
89 : : }
90 : : }
91 : 0 : break;
92 : : }
93 : :
94 [ - + ][ # # ]: 87 : if ((getNamespace( aElementToken ) == NMSP_vml) && mpShapePtr)
[ - + ]
95 : : {
96 [ # # ]: 0 : mpShapePtr->setServiceName("com.sun.star.drawing.CustomShape");
97 : : CustomShapePropertiesPtr pCstmShpProps
98 [ # # ]: 0 : (mpShapePtr->getCustomShapeProperties());
99 : :
100 [ # # ]: 0 : pCstmShpProps->setShapePresetType( getBaseToken( aElementToken ) );
101 : : }
102 : :
103 [ + + ]: 87 : if( !xRet.is() )
104 [ + - ][ + - ]: 72 : xRet.set( ShapeContext::createFastChildContext( aElementToken, xAttribs ) );
105 : :
106 : 87 : return xRet;
107 : : }
108 : :
109 : : // ============================================================================
110 : : // CT_GraphicalObjectFrameContext
111 : :
112 : 0 : GraphicalObjectFrameContext::GraphicalObjectFrameContext( ContextHandler& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr, bool bEmbedShapesInChart ) :
113 : : ShapeContext( rParent, pMasterShapePtr, pShapePtr ),
114 [ # # ][ # # ]: 0 : mbEmbedShapesInChart( bEmbedShapesInChart )
[ # # ]
115 : : {
116 : 0 : }
117 : :
118 : 0 : Reference< XFastContextHandler > GraphicalObjectFrameContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
119 : : {
120 : 0 : Reference< XFastContextHandler > xRet;
121 : :
122 [ # # # # : 0 : switch( getBaseToken( aElementToken ) )
# ]
123 : : {
124 : : // CT_ShapeProperties
125 : : case XML_nvGraphicFramePr: // CT_GraphicalObjectFrameNonVisual
126 : 0 : break;
127 : : case XML_xfrm: // CT_Transform2D
128 [ # # ][ # # ]: 0 : xRet.set( new Transform2DContext( *this, xAttribs, *mpShapePtr ) );
129 : 0 : break;
130 : : case XML_graphic: // CT_GraphicalObject
131 [ # # ]: 0 : xRet.set( this );
132 : 0 : break;
133 : :
134 : : case XML_graphicData : // CT_GraphicalObjectData
135 : : {
136 [ # # ][ # # ]: 0 : OUString sUri( xAttribs->getOptionalValue( XML_uri ) );
137 [ # # ]: 0 : if ( sUri == "http://schemas.openxmlformats.org/presentationml/2006/ole" )
138 [ # # ][ # # ]: 0 : xRet.set( new OleObjectGraphicDataContext( *this, mpShapePtr ) );
[ # # ][ # # ]
[ # # ]
139 [ # # ]: 0 : else if ( sUri == "http://schemas.openxmlformats.org/drawingml/2006/diagram" )
140 [ # # ][ # # ]: 0 : xRet.set( new DiagramGraphicDataContext( *this, mpShapePtr ) );
[ # # ][ # # ]
[ # # ]
141 [ # # ]: 0 : else if ( sUri == "http://schemas.openxmlformats.org/drawingml/2006/chart" )
142 [ # # ][ # # ]: 0 : xRet.set( new ChartGraphicDataContext( *this, mpShapePtr, mbEmbedShapesInChart ) );
[ # # ]
143 [ # # ]: 0 : else if ( sUri.compareToAscii( "http://schemas.openxmlformats.org/drawingml/2006/table" ) == 0 )
144 [ # # ][ # # ]: 0 : xRet.set( new table::TableContext( *this, mpShapePtr ) );
[ # # ][ # # ]
[ # # ]
145 : : else
146 : : {
147 : : OSL_TRACE( "OOX: Ignore graphicsData of %s", OUSTRING_TO_CSTR( sUri ) );
148 : : return xRet;
149 [ # # ]: 0 : }
150 : : }
151 : 0 : break;
152 : : }
153 [ # # ]: 0 : if( !xRet.is() )
154 [ # # ][ # # ]: 0 : xRet.set( ShapeContext::createFastChildContext( aElementToken, xAttribs ) );
155 : :
156 : 0 : return xRet;
157 : : }
158 : :
159 : : // ============================================================================
160 : :
161 : 0 : OleObjectGraphicDataContext::OleObjectGraphicDataContext( ContextHandler& rParent, ShapePtr xShape ) :
162 : : ShapeContext( rParent, ShapePtr(), xShape ),
163 [ # # ][ # # ]: 0 : mrOleObjectInfo( xShape->setOleObjectType() )
[ # # ][ # # ]
164 : : {
165 : 0 : }
166 : :
167 : 0 : OleObjectGraphicDataContext::~OleObjectGraphicDataContext()
168 : : {
169 : : /* Register the OLE shape at the VML drawing, this prevents that the
170 : : related VML shape converts the OLE object by itself. */
171 [ # # ]: 0 : if( !mrOleObjectInfo.maShapeId.isEmpty() )
172 [ # # ][ # # ]: 0 : if( ::oox::vml::Drawing* pVmlDrawing = getFilter().getVmlDrawing() )
[ # # ]
173 [ # # ]: 0 : pVmlDrawing->registerOleObject( mrOleObjectInfo );
174 [ # # ]: 0 : }
175 : :
176 : 0 : Reference< XFastContextHandler > OleObjectGraphicDataContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
177 : : {
178 : 0 : Reference< XFastContextHandler > xRet;
179 [ # # ]: 0 : AttributeList aAttribs( xAttribs );
180 : :
181 [ # # # # ]: 0 : switch( nElement )
182 : : {
183 : : case PPT_TOKEN( oleObj ):
184 : : {
185 [ # # ]: 0 : mrOleObjectInfo.maShapeId = aAttribs.getXString( XML_spid, OUString() );
186 [ # # ][ # # ]: 0 : const Relation* pRelation = getRelations().getRelationFromRelId( aAttribs.getString( R_TOKEN( id ), OUString() ) );
[ # # ]
187 : : OSL_ENSURE( pRelation, "OleObjectGraphicDataContext::createFastChildContext - missing relation for OLE object" );
188 [ # # ]: 0 : if( pRelation )
189 : : {
190 : 0 : mrOleObjectInfo.mbLinked = pRelation->mbExternal;
191 [ # # ]: 0 : if( pRelation->mbExternal )
192 : : {
193 [ # # ][ # # ]: 0 : mrOleObjectInfo.maTargetLink = getFilter().getAbsoluteUrl( pRelation->maTarget );
194 : : }
195 : : else
196 : : {
197 [ # # ]: 0 : OUString aFragmentPath = getFragmentPathFromRelation( *pRelation );
198 [ # # ]: 0 : if( !aFragmentPath.isEmpty() )
199 [ # # ][ # # ]: 0 : getFilter().importBinaryData( mrOleObjectInfo.maEmbeddedData, aFragmentPath );
200 : : }
201 : : }
202 [ # # ]: 0 : mrOleObjectInfo.maName = aAttribs.getXString( XML_name, OUString() );
203 [ # # ]: 0 : mrOleObjectInfo.maProgId = aAttribs.getXString( XML_progId, OUString() );
204 [ # # ]: 0 : mrOleObjectInfo.mbShowAsIcon = aAttribs.getBool( XML_showAsIcon, false );
205 [ # # ]: 0 : xRet.set( this );
206 : : }
207 : 0 : break;
208 : :
209 : : case PPT_TOKEN( embed ):
210 : : OSL_ENSURE( !mrOleObjectInfo.mbLinked, "OleObjectGraphicDataContext::createFastChildContext - unexpected child element" );
211 : 0 : break;
212 : :
213 : : case PPT_TOKEN( link ):
214 : : OSL_ENSURE( mrOleObjectInfo.mbLinked, "OleObjectGraphicDataContext::createFastChildContext - unexpected child element" );
215 [ # # ]: 0 : mrOleObjectInfo.mbAutoUpdate = aAttribs.getBool( XML_updateAutomatic, false );
216 : 0 : break;
217 : : }
218 [ # # ]: 0 : return xRet;
219 : : }
220 : :
221 : : // ============================================================================
222 : :
223 : 3 : DiagramGraphicDataContext::DiagramGraphicDataContext( ContextHandler& rParent, ShapePtr pShapePtr )
224 [ + - ][ + - ]: 3 : : ShapeContext( rParent, ShapePtr(), pShapePtr )
[ + - ]
225 : : {
226 [ + - ]: 3 : pShapePtr->setDiagramType();
227 : 3 : }
228 : :
229 : 3 : DiagramGraphicDataContext::~DiagramGraphicDataContext()
230 : : {
231 [ - + ]: 6 : }
232 : :
233 : 3 : Reference< XFastContextHandler > DiagramGraphicDataContext::createFastChildContext( ::sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs )
234 : : throw (SAXException, RuntimeException)
235 : : {
236 : 3 : Reference< XFastContextHandler > xRet;
237 : :
238 [ + - ]: 3 : switch( aElementToken )
239 : : {
240 : : case DGM_TOKEN( relIds ):
241 : : {
242 [ + - ][ + - ]: 3 : msDm = xAttribs->getOptionalValue( R_TOKEN( dm ) );
243 [ + - ][ + - ]: 3 : msLo = xAttribs->getOptionalValue( R_TOKEN( lo ) );
244 [ + - ][ + - ]: 3 : msQs = xAttribs->getOptionalValue( R_TOKEN( qs ) );
245 [ + - ][ + - ]: 3 : msCs = xAttribs->getOptionalValue( R_TOKEN( cs ) );
246 : : loadDiagram(mpShapePtr,
247 [ + - ]: 3 : getFilter(),
248 : : getFragmentPathFromRelId( msDm ),
249 : : getFragmentPathFromRelId( msLo ),
250 : : getFragmentPathFromRelId( msQs ),
251 [ + - ][ + - ]: 6 : getFragmentPathFromRelId( msCs ));
[ + - ][ + - ]
[ + - ]
252 : : OSL_TRACE("diagram added shape %s of type %s, size (%d,%d,%d,%d)",
253 : : OUSTRING_TO_CSTR( mpShapePtr->getName() ),
254 : : OUSTRING_TO_CSTR( mpShapePtr->getServiceName() ),
255 : : mpShapePtr->getPosition().X,
256 : : mpShapePtr->getPosition().Y,
257 : : mpShapePtr->getSize().Width,
258 : : mpShapePtr->getSize().Height);
259 : 3 : break;
260 : : }
261 : : default:
262 : 0 : break;
263 : : }
264 : :
265 [ + - ]: 3 : if( !xRet.is() )
266 [ + - ][ + - ]: 3 : xRet.set( ShapeContext::createFastChildContext( aElementToken, xAttribs ) );
267 : :
268 : 3 : return xRet;
269 : : }
270 : :
271 : : // ============================================================================
272 : :
273 : 0 : ChartGraphicDataContext::ChartGraphicDataContext( ContextHandler& rParent, const ShapePtr& rxShape, bool bEmbedShapes ) :
274 : : ShapeContext( rParent, ShapePtr(), rxShape ),
275 [ # # ][ # # ]: 0 : mrChartShapeInfo( rxShape->setChartType( bEmbedShapes ) )
[ # # ][ # # ]
276 : : {
277 : 0 : }
278 : :
279 : 0 : Reference< XFastContextHandler > ChartGraphicDataContext::createFastChildContext( ::sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
280 : : throw (SAXException, RuntimeException)
281 : : {
282 [ # # ]: 0 : if( nElement == C_TOKEN( chart ) )
283 : : {
284 [ # # ]: 0 : AttributeList aAttribs( rxAttribs );
285 [ # # ][ # # ]: 0 : mrChartShapeInfo.maFragmentPath = getFragmentPathFromRelId( aAttribs.getString( R_TOKEN( id ), OUString() ) );
[ # # ]
286 : : }
287 : 0 : return 0;
288 : : }
289 : :
290 : : // ============================================================================
291 : :
292 : : } // namespace drawingml
293 [ + - ][ + - ]: 285 : } // namespace oox
294 : :
295 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|