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