LCOV - code coverage report
Current view: top level - svtools/source/graphic - graphic.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 52 93 55.9 %
Date: 2014-04-11 Functions: 12 21 57.1 %
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 <osl/mutex.hxx>
      21             : #include <vcl/svapp.hxx>
      22             : #include <com/sun/star/graphic/GraphicType.hpp>
      23             : #include <com/sun/star/graphic/XGraphicTransformer.hpp>
      24             : #include <vcl/dibtools.hxx>
      25             : #include <vcl/graph.hxx>
      26             : #include "graphic.hxx"
      27             : #include <comphelper/servicehelper.hxx>
      28             : #include <cppuhelper/supportsservice.hxx>
      29             : #include <string.h>
      30             : 
      31             : using namespace com::sun::star;
      32             : 
      33             : namespace unographic {
      34             : 
      35       46568 : Graphic::Graphic() :
      36       46568 :     mpGraphic( NULL )
      37             : {
      38       46568 : }
      39             : 
      40             : 
      41             : 
      42       93126 : Graphic::~Graphic()
      43       93126 :     throw()
      44             : {
      45       46563 :     delete mpGraphic;
      46       93126 : }
      47             : 
      48             : 
      49             : 
      50       46568 : void Graphic::init( const ::Graphic& rGraphic )
      51             :     throw()
      52             : {
      53       46568 :     delete mpGraphic;
      54       46568 :     mpGraphic = new ::Graphic( rGraphic );
      55       46568 :     ::unographic::GraphicDescriptor::init( *mpGraphic );
      56       46568 : }
      57             : 
      58             : 
      59             : 
      60       47472 : uno::Any SAL_CALL Graphic::queryAggregation( const uno::Type& rType )
      61             :     throw( uno::RuntimeException, std::exception )
      62             : {
      63       47472 :     uno::Any aAny;
      64       47472 :     if( rType == ::getCppuType((const uno::Reference< graphic::XGraphic >*)0) )
      65         476 :         aAny <<= uno::Reference< graphic::XGraphic >( this );
      66       46996 :     else if( rType == ::getCppuType((const uno::Reference< awt::XBitmap >*)0) )
      67         483 :         aAny <<= uno::Reference< awt::XBitmap >( this );
      68       46513 :     else if( rType == ::getCppuType((const uno::Reference< lang::XUnoTunnel >*)0) )
      69       46306 :         aAny <<= uno::Reference< lang::XUnoTunnel >(this);
      70             :     else
      71         207 :         aAny <<= ::unographic::GraphicDescriptor::queryAggregation( rType );
      72             : 
      73       47472 :     return aAny ;
      74             : }
      75             : 
      76             : 
      77             : 
      78       47472 : uno::Any SAL_CALL Graphic::queryInterface( const uno::Type & rType )
      79             :     throw( uno::RuntimeException, std::exception )
      80             : {
      81       47472 :     ::com::sun::star::uno::Any aReturn = ::unographic::GraphicDescriptor::queryInterface( rType );
      82       47472 :     if ( !aReturn.hasValue() )
      83           1 :         aReturn = ::cppu::queryInterface ( rType, static_cast< graphic::XGraphicTransformer*>( this ) );
      84       47472 :     return aReturn;
      85             : }
      86             : 
      87             : 
      88             : 
      89      288019 : void SAL_CALL Graphic::acquire()
      90             :     throw()
      91             : {
      92      288019 :     ::unographic::GraphicDescriptor::acquire();
      93      288019 : }
      94             : 
      95             : 
      96             : 
      97      288014 : void SAL_CALL Graphic::release() throw()
      98             : {
      99      288014 :     ::unographic::GraphicDescriptor::release();
     100      288014 : }
     101             : 
     102           0 : OUString Graphic::getImplementationName_Static()
     103             :     throw()
     104             : {
     105           0 :     return OUString( "com.sun.star.comp.graphic.Graphic" );
     106             : }
     107             : 
     108             : 
     109             : 
     110           0 : uno::Sequence< OUString > Graphic::getSupportedServiceNames_Static()
     111             :     throw()
     112             : {
     113           0 :     uno::Sequence< OUString > aSeq( 1 );
     114             : 
     115           0 :     aSeq.getArray()[ 0 ] = "com.sun.star.graphic.Graphic";
     116             : 
     117           0 :     return aSeq;
     118             : }
     119             : 
     120           0 : OUString SAL_CALL Graphic::getImplementationName()
     121             :     throw( uno::RuntimeException, std::exception )
     122             : {
     123           0 :     return getImplementationName_Static();
     124             : }
     125             : 
     126           0 : sal_Bool SAL_CALL Graphic::supportsService( const OUString& rServiceName )
     127             :     throw( uno::RuntimeException, std::exception )
     128             : {
     129           0 :     return cppu::supportsService( this, rServiceName );
     130             : }
     131             : 
     132           0 : uno::Sequence< OUString > SAL_CALL Graphic::getSupportedServiceNames()
     133             :     throw( uno::RuntimeException, std::exception )
     134             : {
     135           0 :     uno::Sequence< OUString >    aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() );
     136           0 :     uno::Sequence< OUString >    aNew( getSupportedServiceNames_Static() );
     137           0 :     sal_Int32                           nOldCount = aRet.getLength();
     138             : 
     139           0 :     aRet.realloc( nOldCount + aNew.getLength() );
     140             : 
     141           0 :     for( sal_Int32 i = 0; i < aNew.getLength(); ++i )
     142           0 :         aRet[ nOldCount++ ] = aNew[ i ];
     143             : 
     144           0 :     return aRet;
     145             : }
     146             : 
     147           0 : uno::Sequence< uno::Type > SAL_CALL Graphic::getTypes()
     148             :     throw(uno::RuntimeException, std::exception)
     149             : {
     150           0 :     uno::Sequence< uno::Type >  aRet( ::unographic::GraphicDescriptor::getTypes() );
     151           0 :     sal_Int32                   nOldCount = aRet.getLength();
     152             : 
     153           0 :     aRet.realloc( nOldCount + 2 );
     154           0 :     aRet[ nOldCount ] = ::getCppuType((const uno::Reference< graphic::XGraphic>*)0);
     155           0 :     aRet[ nOldCount+1 ] = ::getCppuType((const uno::Reference< awt::XBitmap>*)0);
     156             : 
     157           0 :     return aRet;
     158             : }
     159             : 
     160             : 
     161             : 
     162           0 : uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId()
     163             :     throw(uno::RuntimeException, std::exception)
     164             : {
     165           0 :     return css::uno::Sequence<sal_Int8>();
     166             : }
     167             : 
     168             : 
     169             : 
     170           0 : ::sal_Int8 SAL_CALL Graphic::getType()
     171             :      throw (uno::RuntimeException, std::exception)
     172             : {
     173           0 :     ::sal_Int8 cRet = graphic::GraphicType::EMPTY;
     174             : 
     175           0 :     if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
     176           0 :         cRet = ( ( mpGraphic->GetType() == GRAPHIC_BITMAP ) ? graphic::GraphicType::PIXEL : graphic::GraphicType::VECTOR );
     177             : 
     178           0 :     return cRet;
     179             : }
     180             : 
     181             : 
     182             : // XBitmap
     183             : 
     184             : 
     185         247 : awt::Size SAL_CALL Graphic::getSize(  ) throw (uno::RuntimeException, std::exception)
     186             : {
     187         247 :     SolarMutexGuard aGuard;
     188             : 
     189         247 :     ::Size aVclSize;
     190         247 :     if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
     191         247 :         aVclSize = mpGraphic->GetSizePixel();
     192             : 
     193         247 :     return awt::Size( aVclSize.Width(), aVclSize.Height() );
     194             : }
     195             : 
     196             : 
     197             : 
     198           1 : uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getDIB(  ) throw (uno::RuntimeException, std::exception)
     199             : {
     200           1 :     SolarMutexGuard aGuard;
     201             : 
     202           1 :     if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
     203             :     {
     204           1 :         SvMemoryStream aMem;
     205             : 
     206           1 :         WriteDIB(mpGraphic->GetBitmapEx().GetBitmap(), aMem, false, true);
     207           1 :         return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() );
     208             :     }
     209             :     else
     210             :     {
     211           0 :         return uno::Sequence<sal_Int8>();
     212           1 :     }
     213             : }
     214             : 
     215             : 
     216             : 
     217           0 : uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getMaskDIB(  ) throw (uno::RuntimeException, std::exception)
     218             : {
     219           0 :     SolarMutexGuard aGuard;
     220             : 
     221           0 :     if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
     222             :     {
     223           0 :         SvMemoryStream aMem;
     224             : 
     225           0 :         WriteDIB(mpGraphic->GetBitmapEx().GetMask(), aMem, false, true);
     226           0 :         return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() );
     227             :     }
     228             :     else
     229             :     {
     230           0 :         return uno::Sequence<sal_Int8>();
     231           0 :     }
     232             : }
     233             : 
     234             : 
     235           1 : const ::Graphic* Graphic::getImplementation( const uno::Reference< uno::XInterface >& rxIFace )
     236             :     throw()
     237             : {
     238           1 :     uno::Reference< lang::XUnoTunnel > xTunnel( rxIFace, uno::UNO_QUERY );
     239           1 :     return( xTunnel.is() ? reinterpret_cast< ::Graphic* >( xTunnel->getSomething( ::Graphic::getUnoTunnelId() ) ) : NULL );
     240             : }
     241             : 
     242             : 
     243       46306 : sal_Int64 SAL_CALL Graphic::getSomething( const uno::Sequence< sal_Int8 >& rId )
     244             :     throw( uno::RuntimeException, std::exception )
     245             : {
     246      185224 :     return( ( rId.getLength() == 16 && 0 == memcmp( ::Graphic::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) ?
     247             :             reinterpret_cast< sal_Int64 >( mpGraphic ) :
     248      185224 :             0 );
     249             : }
     250             : 
     251             : }
     252             : 
     253             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10