LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/oox/source/drawingml - graphicshapecontext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 47 97 48.5 %
Date: 2013-07-09 Functions: 12 16 75.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          15 : GraphicShapeContext::GraphicShapeContext( ContextHandler2Helper& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr )
      56          15 : : ShapeContext( rParent, pMasterShapePtr, pShapePtr )
      57             : {
      58          15 : }
      59             : 
      60          82 : ContextHandlerRef GraphicShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
      61             : {
      62          82 :     switch( getBaseToken( aElementToken ) )
      63             :     {
      64             :     // CT_ShapeProperties
      65             :     case XML_xfrm:
      66           0 :         return new Transform2DContext( *this, rAttribs, *mpShapePtr );
      67             :     case XML_blipFill:
      68          15 :         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          67 :     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          67 :     return ShapeContext::onCreateContext( aElementToken, rAttribs );
      99             : }
     100             : 
     101             : // ============================================================================
     102             : // CT_GraphicalObjectFrameContext
     103             : 
     104           2 : GraphicalObjectFrameContext::GraphicalObjectFrameContext( ContextHandler2Helper& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr, bool bEmbedShapesInChart ) :
     105             :     ShapeContext( rParent, pMasterShapePtr, pShapePtr ),
     106           2 :     mbEmbedShapesInChart( bEmbedShapesInChart )
     107             : {
     108           2 : }
     109             : 
     110          12 : ContextHandlerRef GraphicalObjectFrameContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
     111             : {
     112          12 :     switch( getBaseToken( aElementToken ) )
     113             :     {
     114             :     // CT_ShapeProperties
     115             :     case XML_nvGraphicFramePr:      // CT_GraphicalObjectFrameNonVisual
     116           2 :         break;
     117             :     case XML_xfrm:                  // CT_Transform2D
     118           2 :         return new Transform2DContext( *this, rAttribs, *mpShapePtr );
     119             :     case XML_graphic:               // CT_GraphicalObject
     120           2 :         return this;
     121             : 
     122             :         case XML_graphicData :          // CT_GraphicalObjectData
     123             :         {
     124           2 :             OUString sUri( rAttribs.getString( XML_uri ).get() );
     125           2 :             if ( sUri == "http://schemas.openxmlformats.org/presentationml/2006/ole" )
     126           0 :                 return new OleObjectGraphicDataContext( *this, mpShapePtr );
     127           2 :             else if ( sUri == "http://schemas.openxmlformats.org/drawingml/2006/diagram" )
     128           0 :                 return new DiagramGraphicDataContext( *this, mpShapePtr );
     129           2 :             else if ( sUri == "http://schemas.openxmlformats.org/drawingml/2006/chart" )
     130           2 :                 return new ChartGraphicDataContext( *this, mpShapePtr, mbEmbedShapesInChart );
     131           0 :             else if ( sUri.compareToAscii( "http://schemas.openxmlformats.org/drawingml/2006/table" ) == 0 )
     132           0 :                 return new table::TableContext( *this, mpShapePtr );
     133             :             else
     134             :             {
     135             :                 OSL_TRACE( "OOX: Ignore graphicsData of %s", OUSTRING_TO_CSTR( sUri ) );
     136           0 :                 return 0;
     137           2 :             }
     138             :         }
     139             :         break;
     140             :     }
     141             : 
     142           6 :     return ShapeContext::onCreateContext( aElementToken, rAttribs );
     143             : }
     144             : 
     145             : // ============================================================================
     146             : 
     147           0 : OleObjectGraphicDataContext::OleObjectGraphicDataContext( ContextHandler2Helper& rParent, ShapePtr xShape ) :
     148             :     ShapeContext( rParent, ShapePtr(), xShape ),
     149           0 :     mrOleObjectInfo( xShape->setOleObjectType() )
     150             : {
     151           0 : }
     152             : 
     153           0 : OleObjectGraphicDataContext::~OleObjectGraphicDataContext()
     154             : {
     155             :     /*  Register the OLE shape at the VML drawing, this prevents that the
     156             :         related VML shape converts the OLE object by itself. */
     157           0 :     if( !mrOleObjectInfo.maShapeId.isEmpty() )
     158           0 :         if( ::oox::vml::Drawing* pVmlDrawing = getFilter().getVmlDrawing() )
     159           0 :             pVmlDrawing->registerOleObject( mrOleObjectInfo );
     160           0 : }
     161             : 
     162           0 : ContextHandlerRef OleObjectGraphicDataContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     163             : {
     164           0 :     switch( nElement )
     165             :     {
     166             :         case PPT_TOKEN( oleObj ):
     167             :         {
     168           0 :             mrOleObjectInfo.maShapeId = rAttribs.getXString( XML_spid, OUString() );
     169           0 :             const Relation* pRelation = getRelations().getRelationFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
     170             :             OSL_ENSURE( pRelation, "OleObjectGraphicDataContext::createFastChildContext - missing relation for OLE object" );
     171           0 :             if( pRelation )
     172             :             {
     173           0 :                 mrOleObjectInfo.mbLinked = pRelation->mbExternal;
     174           0 :                 if( pRelation->mbExternal )
     175             :                 {
     176           0 :                     mrOleObjectInfo.maTargetLink = getFilter().getAbsoluteUrl( pRelation->maTarget );
     177             :                 }
     178             :                 else
     179             :                 {
     180           0 :                     OUString aFragmentPath = getFragmentPathFromRelation( *pRelation );
     181           0 :                     if( !aFragmentPath.isEmpty() )
     182           0 :                         getFilter().importBinaryData( mrOleObjectInfo.maEmbeddedData, aFragmentPath );
     183             :                 }
     184             :             }
     185           0 :             mrOleObjectInfo.maName = rAttribs.getXString( XML_name, OUString() );
     186           0 :             mrOleObjectInfo.maProgId = rAttribs.getXString( XML_progId, OUString() );
     187           0 :             mrOleObjectInfo.mbShowAsIcon = rAttribs.getBool( XML_showAsIcon, false );
     188           0 :             return this;
     189             :         }
     190             :         break;
     191             : 
     192             :         case PPT_TOKEN( embed ):
     193             :             OSL_ENSURE( !mrOleObjectInfo.mbLinked, "OleObjectGraphicDataContext::createFastChildContext - unexpected child element" );
     194           0 :         break;
     195             : 
     196             :         case PPT_TOKEN( link ):
     197             :             OSL_ENSURE( mrOleObjectInfo.mbLinked, "OleObjectGraphicDataContext::createFastChildContext - unexpected child element" );
     198           0 :             mrOleObjectInfo.mbAutoUpdate = rAttribs.getBool( XML_updateAutomatic, false );
     199           0 :         break;
     200             :         case PPT_TOKEN( pic ):
     201           0 :             return new GraphicShapeContext( *this, mpMasterShapePtr, mpShapePtr );
     202             :         break;
     203             :     }
     204           0 :     return 0;
     205             : }
     206             : 
     207             : // ============================================================================
     208             : 
     209           1 : DiagramGraphicDataContext::DiagramGraphicDataContext( ContextHandler2Helper& rParent, ShapePtr pShapePtr )
     210           1 : : ShapeContext( rParent, ShapePtr(), pShapePtr )
     211             : {
     212           1 :     pShapePtr->setDiagramType();
     213           1 : }
     214             : 
     215           2 : DiagramGraphicDataContext::~DiagramGraphicDataContext()
     216             : {
     217           2 : }
     218             : 
     219           1 : ContextHandlerRef DiagramGraphicDataContext::onCreateContext( ::sal_Int32 aElementToken, const AttributeList& rAttribs )
     220             : {
     221           1 :     switch( aElementToken )
     222             :     {
     223             :     case DGM_TOKEN( relIds ):
     224             :     {
     225           1 :         msDm = rAttribs.getString( R_TOKEN( dm ) ).get();
     226           1 :         msLo = rAttribs.getString( R_TOKEN( lo ) ).get();
     227           1 :         msQs = rAttribs.getString( R_TOKEN( qs ) ).get();
     228           1 :         msCs = rAttribs.getString( R_TOKEN( cs ) ).get();
     229             :         loadDiagram(mpShapePtr,
     230           1 :                     getFilter(),
     231             :                     getFragmentPathFromRelId( msDm ),
     232             :                     getFragmentPathFromRelId( msLo ),
     233             :                     getFragmentPathFromRelId( msQs ),
     234           2 :                     getFragmentPathFromRelId( msCs ));
     235             :         OSL_TRACE("diagram added shape %s of type %s, size (%d,%d,%d,%d)",
     236             :                   OUSTRING_TO_CSTR( mpShapePtr->getName() ),
     237             :                   OUSTRING_TO_CSTR( mpShapePtr->getServiceName() ),
     238             :                   mpShapePtr->getPosition().X,
     239             :                   mpShapePtr->getPosition().Y,
     240             :                   mpShapePtr->getSize().Width,
     241             :                   mpShapePtr->getSize().Height);
     242           1 :         break;
     243             :     }
     244             :     default:
     245           0 :         break;
     246             :     }
     247             : 
     248           1 :     return ShapeContext::onCreateContext( aElementToken, rAttribs );
     249             : }
     250             : 
     251             : // ============================================================================
     252             : 
     253           2 : ChartGraphicDataContext::ChartGraphicDataContext( ContextHandler2Helper& rParent, const ShapePtr& rxShape, bool bEmbedShapes ) :
     254             :     ShapeContext( rParent, ShapePtr(), rxShape ),
     255           2 :     mrChartShapeInfo( rxShape->setChartType( bEmbedShapes ) )
     256             : {
     257           2 : }
     258             : 
     259           2 : ContextHandlerRef ChartGraphicDataContext::onCreateContext( ::sal_Int32 nElement, const AttributeList& rAttribs )
     260             : {
     261           2 :     if( nElement == C_TOKEN( chart ) )
     262             :     {
     263           2 :         mrChartShapeInfo.maFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
     264             :     }
     265           2 :     return 0;
     266             : }
     267             : 
     268             : // ============================================================================
     269             : 
     270             : } // namespace drawingml
     271         141 : } // namespace oox
     272             : 
     273             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10