LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svtools/source/graphic - renderer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 121 2.5 %
Date: 2013-07-09 Functions: 3 21 14.3 %
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             : 
      21             : #include <com/sun/star/beans/PropertyState.hpp>
      22             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      23             : #include <com/sun/star/awt/Rectangle.hpp>
      24             : #include <osl/mutex.hxx>
      25             : #include <vcl/svapp.hxx>
      26             : #include <toolkit/helper/vclunohelper.hxx>
      27             : #include <comphelper/propertysetinfo.hxx>
      28             : #include <svl/itemprop.hxx>
      29             : #include <svtools/grfmgr.hxx>
      30             : #include <comphelper/servicehelper.hxx>
      31             : #include "graphic.hxx"
      32             : #include "renderer.hxx"
      33             : 
      34             : #define UNOGRAPHIC_DEVICE           1
      35             : #define UNOGRAPHIC_DESTINATIONRECT  2
      36             : #define UNOGRAPHIC_RENDERDATA       3
      37             : 
      38             : using namespace ::com::sun::star;
      39             : 
      40             : namespace unographic {
      41             : 
      42             : // ---------------------
      43             : // - GraphicRendererVCL -
      44             : // ---------------------
      45             : 
      46           0 : uno::Reference< uno::XInterface > SAL_CALL GraphicRendererVCL_CreateInstance( const uno::Reference< lang::XMultiServiceFactory >& )
      47             : {
      48           0 :     return (static_cast< ::cppu::OWeakObject* >(new GraphicRendererVCL ));
      49             : }
      50             : 
      51             : 
      52           0 : GraphicRendererVCL::GraphicRendererVCL() :
      53             :     ::comphelper::PropertySetHelper( createPropertySetInfo() ),
      54           0 :     mpOutDev( NULL )
      55             : {
      56           0 : }
      57             : 
      58             : // ------------------------------------------------------------------------------
      59             : 
      60           0 : GraphicRendererVCL::~GraphicRendererVCL()
      61           0 :     throw()
      62             : {
      63           0 : }
      64             : 
      65             : // ------------------------------------------------------------------------------
      66             : 
      67           8 : OUString GraphicRendererVCL::getImplementationName_Static()
      68             :     throw()
      69             : {
      70           8 :     return OUString( "com.sun.star.comp.graphic.GraphicRendererVCL" );
      71             : }
      72             : 
      73             : // ------------------------------------------------------------------------------
      74             : 
      75           0 : uno::Sequence< OUString > GraphicRendererVCL::getSupportedServiceNames_Static()
      76             :     throw(  )
      77             : {
      78           0 :     uno::Sequence< OUString > aSeq( 1 );
      79             : 
      80           0 :     aSeq.getArray()[ 0 ] = OUString( "com.sun.star.graphic.GraphicRendererVCL" );
      81             : 
      82           0 :     return aSeq;
      83             : }
      84             : 
      85             : // ------------------------------------------------------------------------------
      86             : 
      87           0 : uno::Any SAL_CALL GraphicRendererVCL::queryAggregation( const uno::Type & rType )
      88             :     throw( uno::RuntimeException )
      89             : {
      90           0 :     uno::Any aAny;
      91             : 
      92           0 :     if( rType == ::getCppuType((const uno::Reference< lang::XServiceInfo >*)0) )
      93           0 :         aAny <<= uno::Reference< lang::XServiceInfo >(this);
      94           0 :     else if( rType == ::getCppuType((const uno::Reference< lang::XTypeProvider >*)0) )
      95           0 :         aAny <<= uno::Reference< lang::XTypeProvider >(this);
      96           0 :     else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) )
      97           0 :         aAny <<= uno::Reference< beans::XPropertySet >(this);
      98           0 :     else if( rType == ::getCppuType((const uno::Reference< beans::XPropertyState >*)0) )
      99           0 :         aAny <<= uno::Reference< beans::XPropertyState >(this);
     100           0 :     else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) )
     101           0 :         aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
     102           0 :     else if( rType == ::getCppuType((const uno::Reference< graphic::XGraphicRenderer >*)0) )
     103           0 :         aAny <<= uno::Reference< graphic::XGraphicRenderer >(this);
     104             :     else
     105           0 :         aAny <<= OWeakAggObject::queryAggregation( rType );
     106             : 
     107           0 :     return aAny;
     108             : }
     109             : 
     110             : // ------------------------------------------------------------------------------
     111             : 
     112           0 : uno::Any SAL_CALL GraphicRendererVCL::queryInterface( const uno::Type & rType )
     113             :     throw( uno::RuntimeException )
     114             : {
     115           0 :     return OWeakAggObject::queryInterface( rType );
     116             : }
     117             : 
     118             : // ------------------------------------------------------------------------------
     119             : 
     120           0 : void SAL_CALL GraphicRendererVCL::acquire()
     121             :     throw()
     122             : {
     123           0 :     OWeakAggObject::acquire();
     124           0 : }
     125             : 
     126             : // ------------------------------------------------------------------------------
     127             : 
     128           0 : void SAL_CALL GraphicRendererVCL::release()
     129             :     throw()
     130             : {
     131           0 :     OWeakAggObject::release();
     132           0 : }
     133             : 
     134             : // ------------------------------------------------------------------------------
     135             : 
     136           0 : OUString SAL_CALL GraphicRendererVCL::getImplementationName()
     137             :     throw( uno::RuntimeException )
     138             : {
     139           0 :     return getImplementationName_Static();
     140             : }
     141             : 
     142             : // ------------------------------------------------------------------------------
     143             : 
     144           0 : sal_Bool SAL_CALL GraphicRendererVCL::supportsService( const OUString& ServiceName )
     145             :     throw( uno::RuntimeException )
     146             : {
     147           0 :     uno::Sequence< OUString >    aSNL( getSupportedServiceNames() );
     148           0 :     const OUString*              pArray = aSNL.getConstArray();
     149             : 
     150           0 :     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
     151           0 :         if( pArray[i] == ServiceName )
     152           0 :             return true;
     153             : 
     154           0 :     return false;
     155             : }
     156             : 
     157             : // ------------------------------------------------------------------------------
     158             : 
     159           0 : uno::Sequence< OUString > SAL_CALL GraphicRendererVCL::getSupportedServiceNames()
     160             :     throw( uno::RuntimeException )
     161             : {
     162           0 :     return getSupportedServiceNames_Static();
     163             : }
     164             : 
     165             : // ------------------------------------------------------------------------------
     166             : 
     167           0 : uno::Sequence< uno::Type > SAL_CALL GraphicRendererVCL::getTypes()
     168             :     throw( uno::RuntimeException )
     169             : {
     170           0 :     uno::Sequence< uno::Type >  aTypes( 7 );
     171           0 :     uno::Type*                  pTypes = aTypes.getArray();
     172             : 
     173           0 :     *pTypes++ = ::getCppuType((const uno::Reference< uno::XAggregation>*)0);
     174           0 :     *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
     175           0 :     *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
     176           0 :     *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertySet>*)0);
     177           0 :     *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertyState>*)0);
     178           0 :     *pTypes++ = ::getCppuType((const uno::Reference< beans::XMultiPropertySet>*)0);
     179           0 :     *pTypes++ = ::getCppuType((const uno::Reference< graphic::XGraphicRenderer>*)0);
     180             : 
     181           0 :     return aTypes;
     182             : }
     183             : 
     184             : namespace
     185             : {
     186             :     class theGraphicRendererVCLUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theGraphicRendererVCLUnoTunnelId > {};
     187             : }
     188             : 
     189           0 : uno::Sequence< sal_Int8 > SAL_CALL GraphicRendererVCL::getImplementationId()
     190             :     throw( uno::RuntimeException )
     191             : {
     192           0 :     return theGraphicRendererVCLUnoTunnelId::get().getSeq();
     193             : }
     194             : 
     195             : // ------------------------------------------------------------------------------
     196             : 
     197           0 : ::comphelper::PropertySetInfo* GraphicRendererVCL::createPropertySetInfo()
     198             : {
     199           0 :     SolarMutexGuard aGuard;
     200           0 :     ::comphelper::PropertySetInfo*  pRet = new ::comphelper::PropertySetInfo();
     201             : 
     202             :     static ::comphelper::PropertyMapEntry aEntries[] =
     203             :     {
     204           0 :         { MAP_CHAR_LEN( "Device" ), UNOGRAPHIC_DEVICE, &::getCppuType( (const uno::Any*)(0)), 0, 0 },
     205           0 :         { MAP_CHAR_LEN( "DestinationRect" ), UNOGRAPHIC_DESTINATIONRECT, &::getCppuType( (const awt::Rectangle*)(0)), 0, 0 },
     206           0 :         { MAP_CHAR_LEN( "RenderData" ), UNOGRAPHIC_RENDERDATA,  &::getCppuType( (const uno::Any*)(0)), 0, 0 },
     207             : 
     208             :         { 0,0,0,0,0,0 }
     209           0 :     };
     210             : 
     211           0 :     pRet->acquire();
     212           0 :     pRet->add( aEntries );
     213             : 
     214           0 :     return pRet;
     215             : }
     216             : 
     217             : // ------------------------------------------------------------------------------
     218             : 
     219           0 : void GraphicRendererVCL::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
     220             :     throw( beans::UnknownPropertyException,
     221             :            beans::PropertyVetoException,
     222             :            lang::IllegalArgumentException,
     223             :               lang::WrappedTargetException )
     224             : {
     225           0 :     SolarMutexGuard aGuard;
     226             : 
     227           0 :     while( *ppEntries )
     228             :     {
     229           0 :         switch( (*ppEntries)->mnHandle )
     230             :         {
     231             :             case( UNOGRAPHIC_DEVICE ):
     232             :             {
     233           0 :                 uno::Reference< awt::XDevice > xDevice;
     234             : 
     235           0 :                 if( ( *pValues >>= xDevice ) && xDevice.is() )
     236             :                 {
     237           0 :                     mxDevice = xDevice;
     238           0 :                     mpOutDev = VCLUnoHelper::GetOutputDevice( xDevice );
     239             :                 }
     240             :                 else
     241             :                 {
     242           0 :                     mxDevice.clear();
     243           0 :                     mpOutDev = NULL;
     244           0 :                 }
     245             :             }
     246           0 :             break;
     247             : 
     248             :             case( UNOGRAPHIC_DESTINATIONRECT ):
     249             :             {
     250           0 :                 awt::Rectangle aAWTRect;
     251             : 
     252           0 :                 if( *pValues >>= aAWTRect )
     253             :                 {
     254             :                     maDestRect = Rectangle( Point( aAWTRect.X, aAWTRect.Y ),
     255           0 :                                             Size( aAWTRect.Width, aAWTRect.Height ) );
     256             :                 }
     257             :             }
     258           0 :             break;
     259             : 
     260             :             case( UNOGRAPHIC_RENDERDATA ):
     261             :             {
     262           0 :                 *pValues >>= maRenderData;
     263             :             }
     264           0 :             break;
     265             :         }
     266             : 
     267           0 :         ++ppEntries;
     268           0 :         ++pValues;
     269           0 :     }
     270           0 : }
     271             : 
     272             : // ------------------------------------------------------------------------------
     273             : 
     274           0 : void GraphicRendererVCL::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValues )
     275             :     throw( beans::UnknownPropertyException, lang::WrappedTargetException )
     276             : {
     277           0 :     SolarMutexGuard aGuard;
     278             : 
     279           0 :     while( *ppEntries )
     280             :     {
     281           0 :         switch( (*ppEntries)->mnHandle )
     282             :         {
     283             :             case( UNOGRAPHIC_DEVICE ):
     284             :             {
     285           0 :                 if( mxDevice.is() )
     286           0 :                     *pValues <<= mxDevice;
     287             :             }
     288           0 :             break;
     289             : 
     290             :             case( UNOGRAPHIC_DESTINATIONRECT ):
     291             :             {
     292           0 :                 const awt::Rectangle aAWTRect( maDestRect.Left(), maDestRect.Top(),
     293           0 :                                                maDestRect.GetWidth(), maDestRect.GetHeight() );
     294             : 
     295           0 :                 *pValues <<= aAWTRect;
     296             :             }
     297           0 :             break;
     298             : 
     299             :             case( UNOGRAPHIC_RENDERDATA ):
     300             :             {
     301           0 :                 *pValues <<= maRenderData;
     302             :             }
     303           0 :             break;
     304             :         }
     305             : 
     306           0 :         ++ppEntries;
     307           0 :         ++pValues;
     308           0 :     }
     309           0 : }
     310             : 
     311             : // ------------------------------------------------------------------------------
     312             : 
     313           0 : void SAL_CALL GraphicRendererVCL::render( const uno::Reference< graphic::XGraphic >& rxGraphic )
     314             :     throw (uno::RuntimeException)
     315             : {
     316           0 :     if( mpOutDev && mxDevice.is() && rxGraphic.is() )
     317             :     {
     318           0 :         const uno::Reference< XInterface >  xIFace( rxGraphic, uno::UNO_QUERY );
     319           0 :         const ::Graphic*                    pGraphic = ::unographic::Graphic::getImplementation( xIFace );
     320             : 
     321           0 :         if( pGraphic )
     322             :         {
     323           0 :             GraphicObject aGraphicObject( *pGraphic );
     324           0 :             aGraphicObject.Draw( mpOutDev, maDestRect.TopLeft(), maDestRect.GetSize() );
     325           0 :         }
     326             :     }
     327           0 : }
     328             : 
     329         465 : }
     330             : 
     331             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10