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