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

Generated by: LCOV version 1.11