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

Generated by: LCOV version 1.10