LCOV - code coverage report
Current view: top level - oox/source/drawingml - graphicshapecontext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 97 115 84.3 %
Date: 2014-11-03 Functions: 19 19 100.0 %
Legend: Lines: hit not hit

          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           4 : lcl_GetMediaStream(const OUString& rStream, const oox::core::XmlFilterBase& rFilter)
      54             : {
      55           4 :     if (rStream.isEmpty())
      56           0 :         return nullptr;
      57             : 
      58           4 :     Reference< XInputStream > xInStrm( rFilter.openInputStream(rStream), UNO_SET_THROW );
      59           4 :     return xInStrm;
      60             : }
      61             : 
      62           4 : static OUString lcl_GetMediaReference(const OUString& rStream)
      63             : {
      64           4 :     return rStream.isEmpty() ? OUString() : "vnd.sun.star.Package:" + rStream;
      65             : }
      66             : 
      67             : namespace oox {
      68             : namespace drawingml {
      69             : 
      70             : // CT_Picture
      71             : 
      72         550 : GraphicShapeContext::GraphicShapeContext( ContextHandler2Helper& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr )
      73         550 : : ShapeContext( rParent, pMasterShapePtr, pShapePtr )
      74             : {
      75         550 : }
      76             : 
      77        3396 : ContextHandlerRef GraphicShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
      78             : {
      79        3396 :     switch( getBaseToken( aElementToken ) )
      80             :     {
      81             :     // CT_ShapeProperties
      82             :     case XML_xfrm:
      83           0 :         return new Transform2DContext( *this, rAttribs, *mpShapePtr );
      84             :     case XML_blipFill:
      85         516 :         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           4 :             OUString rPath = getRelations().getFragmentPathFromRelId(
      99           8 :                     rAttribs.getString(R_TOKEN(link)).get() );
     100           8 :             mpShapePtr->getGraphicProperties().m_xMediaStream =
     101           8 :                 lcl_GetMediaStream(rPath, getFilter());
     102           8 :             mpShapePtr->getGraphicProperties().m_sMediaPackageURL =
     103           8 :                 lcl_GetMediaReference(rPath);
     104             :         }
     105           4 :         break;
     106             :     }
     107             : 
     108        2880 :     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        2880 :     return ShapeContext::onCreateContext( aElementToken, rAttribs );
     118             : }
     119             : 
     120             : // CT_GraphicalObjectFrameContext
     121             : 
     122          78 : GraphicalObjectFrameContext::GraphicalObjectFrameContext( ContextHandler2Helper& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr, bool bEmbedShapesInChart ) :
     123             :     ShapeContext( rParent, pMasterShapePtr, pShapePtr ),
     124             :     mbEmbedShapesInChart( bEmbedShapesInChart ),
     125          78 :     mpParent(&rParent)
     126             : {
     127          78 : }
     128             : 
     129         604 : ContextHandlerRef GraphicalObjectFrameContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     130             : {
     131         604 :     switch( getBaseToken( aElementToken ) )
     132             :     {
     133             :     // CT_ShapeProperties
     134             :     case XML_nvGraphicFramePr:      // CT_GraphicalObjectFrameNonVisual
     135          78 :         break;
     136             :     case XML_xfrm:                  // CT_Transform2D
     137          78 :         return new Transform2DContext( *this, rAttribs, *mpShapePtr );
     138             :     case XML_graphic:               // CT_GraphicalObject
     139          78 :         return this;
     140             : 
     141             :         case XML_graphicData :          // CT_GraphicalObjectData
     142             :         {
     143          78 :             OUString sUri( rAttribs.getString( XML_uri ).get() );
     144         152 :             if ( sUri == "http://schemas.openxmlformats.org/presentationml/2006/ole" ||
     145          74 :                     sUri == "http://purl.oclc.org/ooxml/presentationml/ole" )
     146           4 :                 return new OleObjectGraphicDataContext( *this, mpShapePtr );
     147         132 :             else if ( sUri == "http://schemas.openxmlformats.org/drawingml/2006/diagram" ||
     148          58 :                     sUri == "http://purl.oclc.org/ooxml/drawingml/diagram" )
     149          16 :                 return new DiagramGraphicDataContext( *this, mpShapePtr );
     150          64 :             else if ( sUri == "http://schemas.openxmlformats.org/drawingml/2006/chart" ||
     151           6 :                     sUri == "http://purl.oclc.org/ooxml/drawingml/chart" )
     152          52 :                 return new ChartGraphicDataContext( *this, mpShapePtr, mbEmbedShapesInChart );
     153           6 :             else if ( sUri == "http://schemas.openxmlformats.org/drawingml/2006/table" ||
     154           0 :                     sUri == "http://purl.oclc.org/ooxml/drawingml/table" )
     155           6 :                 return new table::TableContext( *this, mpShapePtr );
     156             :             else
     157             :             {
     158             :                 SAL_WARN("oox", "OOX: Ignore graphicsData of :" << sUri );
     159           0 :                 return 0;
     160          78 :             }
     161             :         }
     162             :         break;
     163             :     }
     164             : 
     165         370 :     return ShapeContext::onCreateContext( aElementToken, rAttribs );
     166             : }
     167             : 
     168         526 : void GraphicalObjectFrameContext::onEndElement()
     169             : {
     170         526 :     if( getCurrentElement() == PPT_TOKEN( graphicFrame ) && mpParent )
     171             :     {
     172          44 :         oox::ppt::PPTShapeGroupContext* pParent = dynamic_cast<oox::ppt::PPTShapeGroupContext*>(mpParent);
     173          44 :         if( pParent )
     174          44 :             pParent->importExtDrawings();
     175             :     }
     176         526 : }
     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           4 :         if( ::oox::vml::Drawing* pVmlDrawing = getFilter().getVmlDrawing() )
     190           4 :             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          88 : DiagramGraphicDataContext::DiagramGraphicDataContext( ContextHandler2Helper& rParent, ShapePtr pShapePtr )
     239          88 : : ShapeContext( rParent, ShapePtr(), pShapePtr )
     240             : {
     241          88 :     pShapePtr->setDiagramType();
     242          88 : }
     243             : 
     244         176 : DiagramGraphicDataContext::~DiagramGraphicDataContext()
     245             : {
     246         176 : }
     247             : 
     248          88 : ContextHandlerRef DiagramGraphicDataContext::onCreateContext( ::sal_Int32 aElementToken, const AttributeList& rAttribs )
     249             : {
     250          88 :     switch( aElementToken )
     251             :     {
     252             :     case DGM_TOKEN( relIds ):
     253             :     {
     254          88 :         msDm = rAttribs.getString( R_TOKEN( dm ) ).get();
     255          88 :         msLo = rAttribs.getString( R_TOKEN( lo ) ).get();
     256          88 :         msQs = rAttribs.getString( R_TOKEN( qs ) ).get();
     257          88 :         msCs = rAttribs.getString( R_TOKEN( cs ) ).get();
     258             :         loadDiagram(mpShapePtr,
     259          88 :                     getFilter(),
     260             :                     getFragmentPathFromRelId( msDm ),
     261             :                     getFragmentPathFromRelId( msLo ),
     262             :                     getFragmentPathFromRelId( msQs ),
     263         176 :                     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          88 :         break;
     273             :     }
     274             :     default:
     275           0 :         break;
     276             :     }
     277             : 
     278          88 :     return ShapeContext::onCreateContext( aElementToken, rAttribs );
     279             : }
     280             : 
     281         232 : ChartGraphicDataContext::ChartGraphicDataContext( ContextHandler2Helper& rParent, const ShapePtr& rxShape, bool bEmbedShapes ) :
     282             :     ShapeContext( rParent, ShapePtr(), rxShape ),
     283         232 :     mrChartShapeInfo( rxShape->setChartType( bEmbedShapes ) )
     284             : {
     285         232 : }
     286             : 
     287         232 : ContextHandlerRef ChartGraphicDataContext::onCreateContext( ::sal_Int32 nElement, const AttributeList& rAttribs )
     288             : {
     289         232 :     if( nElement == C_TOKEN( chart ) )
     290             :     {
     291         224 :         mrChartShapeInfo.maFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
     292             :     }
     293         232 :     return 0;
     294             : }
     295             : 
     296             : } // namespace drawingml
     297         408 : } // namespace oox
     298             : 
     299             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10