fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / oox / source / drawingml / graphicshapecontext.cxx
blob7c82395f822dd556b971026bc7751987f4f3f1dd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/io/TempFile.hpp>
21 #include "oox/drawingml/graphicshapecontext.hxx"
23 #include <osl/diagnose.h>
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"
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;
52 static uno::Reference<io::XInputStream>
53 lcl_GetMediaStream(const OUString& rStream, const oox::core::XmlFilterBase& rFilter)
55 if (rStream.isEmpty())
56 return nullptr;
58 Reference< XInputStream > xInStrm( rFilter.openInputStream(rStream), UNO_SET_THROW );
59 return xInStrm;
62 static OUString lcl_GetMediaReference(const OUString& rStream)
64 return rStream.isEmpty() ? OUString() : "vnd.sun.star.Package:" + rStream;
67 namespace oox {
68 namespace drawingml {
70 // CT_Picture
72 GraphicShapeContext::GraphicShapeContext( ContextHandler2Helper& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr )
73 : ShapeContext( rParent, pMasterShapePtr, pShapePtr )
77 ContextHandlerRef GraphicShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
79 switch( getBaseToken( aElementToken ) )
81 // CT_ShapeProperties
82 case XML_xfrm:
83 return new Transform2DContext( *this, rAttribs, *mpShapePtr );
84 case XML_blipFill:
85 return new BlipFillContext( *this, rAttribs, mpShapePtr->getGraphicProperties().maBlipProps );
86 case XML_wavAudioFile:
88 OUString const path(getEmbeddedWAVAudioFile(getRelations(), rAttribs));
89 mpShapePtr->getGraphicProperties().m_xMediaStream =
90 lcl_GetMediaStream(path, getFilter());
91 mpShapePtr->getGraphicProperties().m_sMediaPackageURL =
92 lcl_GetMediaReference(path);
94 break;
95 case XML_audioFile:
96 case XML_videoFile:
98 OUString rPath = getRelations().getFragmentPathFromRelId(
99 rAttribs.getString(R_TOKEN(link)).get() );
100 mpShapePtr->getGraphicProperties().m_xMediaStream =
101 lcl_GetMediaStream(rPath, getFilter());
102 mpShapePtr->getGraphicProperties().m_sMediaPackageURL =
103 lcl_GetMediaReference(rPath);
105 break;
108 if ((getNamespace( aElementToken ) == NMSP_vml) && mpShapePtr)
110 mpShapePtr->setServiceName("com.sun.star.drawing.CustomShape");
111 CustomShapePropertiesPtr pCstmShpProps
112 (mpShapePtr->getCustomShapeProperties());
114 pCstmShpProps->setShapePresetType( getBaseToken( aElementToken ) );
117 return ShapeContext::onCreateContext( aElementToken, rAttribs );
120 // CT_GraphicalObjectFrameContext
122 GraphicalObjectFrameContext::GraphicalObjectFrameContext( ContextHandler2Helper& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr, bool bEmbedShapesInChart ) :
123 ShapeContext( rParent, pMasterShapePtr, pShapePtr ),
124 mbEmbedShapesInChart( bEmbedShapesInChart ),
125 mpParent(&rParent)
129 ContextHandlerRef GraphicalObjectFrameContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
131 switch( getBaseToken( aElementToken ) )
133 // CT_ShapeProperties
134 case XML_nvGraphicFramePr: // CT_GraphicalObjectFrameNonVisual
135 break;
136 case XML_xfrm: // CT_Transform2D
137 return new Transform2DContext( *this, rAttribs, *mpShapePtr );
138 case XML_graphic: // CT_GraphicalObject
139 return this;
141 case XML_graphicData : // CT_GraphicalObjectData
143 OUString sUri( rAttribs.getString( XML_uri ).get() );
144 if ( sUri == "http://schemas.openxmlformats.org/presentationml/2006/ole" ||
145 sUri == "http://purl.oclc.org/ooxml/presentationml/ole" )
146 return new OleObjectGraphicDataContext( *this, mpShapePtr );
147 else if ( sUri == "http://schemas.openxmlformats.org/drawingml/2006/diagram" ||
148 sUri == "http://purl.oclc.org/ooxml/drawingml/diagram" )
149 return new DiagramGraphicDataContext( *this, mpShapePtr );
150 else if ( sUri == "http://schemas.openxmlformats.org/drawingml/2006/chart" ||
151 sUri == "http://purl.oclc.org/ooxml/drawingml/chart" )
152 return new ChartGraphicDataContext( *this, mpShapePtr, mbEmbedShapesInChart );
153 else if ( sUri == "http://schemas.openxmlformats.org/drawingml/2006/table" ||
154 sUri == "http://purl.oclc.org/ooxml/drawingml/table" )
155 return new table::TableContext( *this, mpShapePtr );
156 else
158 SAL_WARN("oox", "OOX: Ignore graphicsData of :" << sUri );
159 return 0;
162 break;
165 return ShapeContext::onCreateContext( aElementToken, rAttribs );
168 void GraphicalObjectFrameContext::onEndElement()
170 if( getCurrentElement() == PPT_TOKEN( graphicFrame ) && mpParent )
172 oox::ppt::PPTShapeGroupContext* pParent = dynamic_cast<oox::ppt::PPTShapeGroupContext*>(mpParent);
173 if( pParent )
174 pParent->importExtDrawings();
178 OleObjectGraphicDataContext::OleObjectGraphicDataContext( ContextHandler2Helper& rParent, ShapePtr xShape ) :
179 ShapeContext( rParent, ShapePtr(), xShape ),
180 mrOleObjectInfo( xShape->setOleObjectType() )
184 OleObjectGraphicDataContext::~OleObjectGraphicDataContext()
186 /* Register the OLE shape at the VML drawing, this prevents that the
187 related VML shape converts the OLE object by itself. */
188 if( !mrOleObjectInfo.maShapeId.isEmpty() )
189 if( ::oox::vml::Drawing* pVmlDrawing = getFilter().getVmlDrawing() )
190 pVmlDrawing->registerOleObject( mrOleObjectInfo );
193 ContextHandlerRef OleObjectGraphicDataContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
195 switch( nElement )
197 case PPT_TOKEN( oleObj ):
199 mrOleObjectInfo.maShapeId = rAttribs.getXString( XML_spid, OUString() );
200 const Relation* pRelation = getRelations().getRelationFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
201 OSL_ENSURE( pRelation, "OleObjectGraphicDataContext::createFastChildContext - missing relation for OLE object" );
202 if( pRelation )
204 mrOleObjectInfo.mbLinked = pRelation->mbExternal;
205 if( pRelation->mbExternal )
207 mrOleObjectInfo.maTargetLink = getFilter().getAbsoluteUrl( pRelation->maTarget );
209 else
211 OUString aFragmentPath = getFragmentPathFromRelation( *pRelation );
212 if( !aFragmentPath.isEmpty() )
213 getFilter().importBinaryData( mrOleObjectInfo.maEmbeddedData, aFragmentPath );
216 mrOleObjectInfo.maName = rAttribs.getXString( XML_name, OUString() );
217 mrOleObjectInfo.maProgId = rAttribs.getXString( XML_progId, OUString() );
218 mrOleObjectInfo.mbShowAsIcon = rAttribs.getBool( XML_showAsIcon, false );
219 return this;
221 break;
223 case PPT_TOKEN( embed ):
224 OSL_ENSURE( !mrOleObjectInfo.mbLinked, "OleObjectGraphicDataContext::createFastChildContext - unexpected child element" );
225 break;
227 case PPT_TOKEN( link ):
228 OSL_ENSURE( mrOleObjectInfo.mbLinked, "OleObjectGraphicDataContext::createFastChildContext - unexpected child element" );
229 mrOleObjectInfo.mbAutoUpdate = rAttribs.getBool( XML_updateAutomatic, false );
230 break;
231 case PPT_TOKEN( pic ):
232 return new GraphicShapeContext( *this, mpMasterShapePtr, mpShapePtr );
233 break;
235 return 0;
238 DiagramGraphicDataContext::DiagramGraphicDataContext( ContextHandler2Helper& rParent, ShapePtr pShapePtr )
239 : ShapeContext( rParent, ShapePtr(), pShapePtr )
241 pShapePtr->setDiagramType();
244 DiagramGraphicDataContext::~DiagramGraphicDataContext()
248 ContextHandlerRef DiagramGraphicDataContext::onCreateContext( ::sal_Int32 aElementToken, const AttributeList& rAttribs )
250 switch( aElementToken )
252 case DGM_TOKEN( relIds ):
254 msDm = rAttribs.getString( R_TOKEN( dm ) ).get();
255 msLo = rAttribs.getString( R_TOKEN( lo ) ).get();
256 msQs = rAttribs.getString( R_TOKEN( qs ) ).get();
257 msCs = rAttribs.getString( R_TOKEN( cs ) ).get();
258 loadDiagram(mpShapePtr,
259 getFilter(),
260 getFragmentPathFromRelId( msDm ),
261 getFragmentPathFromRelId( msLo ),
262 getFragmentPathFromRelId( msQs ),
263 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 break;
274 default:
275 break;
278 return ShapeContext::onCreateContext( aElementToken, rAttribs );
281 ChartGraphicDataContext::ChartGraphicDataContext( ContextHandler2Helper& rParent, const ShapePtr& rxShape, bool bEmbedShapes ) :
282 ShapeContext( rParent, ShapePtr(), rxShape ),
283 mrChartShapeInfo( rxShape->setChartType( bEmbedShapes ) )
287 ContextHandlerRef ChartGraphicDataContext::onCreateContext( ::sal_Int32 nElement, const AttributeList& rAttribs )
289 if( nElement == C_TOKEN( chart ) )
291 mrChartShapeInfo.maFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
293 return 0;
296 } // namespace drawingml
297 } // namespace oox
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */