LCOV - code coverage report
Current view: top level - svtools/source/graphic - descriptor.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 70 195 35.9 %
Date: 2014-11-03 Functions: 12 24 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 "descriptor.hxx"
      21             : 
      22             : #include <osl/mutex.hxx>
      23             : #include <unotools/ucbstreamhelper.hxx>
      24             : #include <vcl/graphicfilter.hxx>
      25             : #include <svl/itemprop.hxx>
      26             : #include <comphelper/servicehelper.hxx>
      27             : #include <cppuhelper/supportsservice.hxx>
      28             : 
      29             : #include <com/sun/star/beans/PropertyState.hpp>
      30             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      31             : #include <com/sun/star/awt/Size.hpp>
      32             : #include <com/sun/star/graphic/GraphicType.hpp>
      33             : 
      34             : #include <vcl/graph.hxx>
      35             : #include <vcl/svapp.hxx>
      36             : #include <boost/scoped_ptr.hpp>
      37             : 
      38             : #define UNOGRAPHIC_GRAPHICTYPE  1
      39             : #define UNOGRAPHIC_MIMETYPE     2
      40             : #define UNOGRAPHIC_SIZEPIXEL    3
      41             : #define UNOGRAPHIC_SIZE100THMM  4
      42             : #define UNOGRAPHIC_BITSPERPIXEL 5
      43             : #define UNOGRAPHIC_TRANSPARENT  6
      44             : #define UNOGRAPHIC_ALPHA        7
      45             : #define UNOGRAPHIC_ANIMATED     8
      46             : 
      47             : using namespace ::com::sun::star;
      48             : 
      49             : namespace unographic {
      50             : 
      51             : 
      52             : // - GraphicDescriptor -
      53             : 
      54             : 
      55      137458 : GraphicDescriptor::GraphicDescriptor() :
      56             :     ::comphelper::PropertySetHelper( createPropertySetInfo(), SAL_NO_ACQUIRE ),
      57             :     mpGraphic( NULL ),
      58             :     meType( GRAPHIC_NONE ),
      59             :     mnBitsPerPixel ( 0 ),
      60             :     mbTransparent ( false ),
      61             :     mbAlpha( false ),
      62      137458 :     mbAnimated( false )
      63             : {
      64      137458 : }
      65             : 
      66      137456 : GraphicDescriptor::~GraphicDescriptor()
      67      137456 :     throw()
      68             : {
      69      137456 : }
      70             : 
      71      137458 : void GraphicDescriptor::init( const ::Graphic& rGraphic )
      72             : {
      73      137458 :     mpGraphic = &rGraphic;
      74      137458 : }
      75             : 
      76           0 : void GraphicDescriptor::init( const OUString& rURL )
      77             : {
      78           0 :     boost::scoped_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( rURL, STREAM_READ ));
      79             : 
      80           0 :     if( pIStm )
      81           0 :         implCreate( *pIStm, &rURL );
      82           0 : }
      83             : 
      84           0 : void GraphicDescriptor::init( const uno::Reference< io::XInputStream >& rxIStm, const OUString& rURL )
      85             : {
      86           0 :     boost::scoped_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( rxIStm ));
      87             : 
      88           0 :     if( pIStm )
      89           0 :         implCreate( *pIStm, &rURL );
      90           0 : }
      91             : 
      92           0 : void GraphicDescriptor::implCreate( SvStream& rIStm, const OUString* pURL )
      93             : {
      94           0 :     OUString aURL;
      95           0 :     if( pURL )
      96           0 :         aURL = *pURL;
      97           0 :     ::GraphicDescriptor aDescriptor( rIStm, &aURL );
      98             : 
      99           0 :     mpGraphic = NULL;
     100           0 :     maMimeType = OUString();
     101           0 :     meType = GRAPHIC_NONE;
     102           0 :     mnBitsPerPixel = 0;
     103           0 :     mbTransparent = false;
     104             : 
     105           0 :     if( aDescriptor.Detect( true ) && aDescriptor.GetFileFormat() != GFF_NOT )
     106             :     {
     107           0 :         const char*             pMimeType = NULL;
     108           0 :         sal_uInt8               cType = graphic::GraphicType::EMPTY;
     109             : 
     110           0 :         switch( aDescriptor.GetFileFormat() )
     111             :         {
     112           0 :             case( GFF_BMP ): pMimeType = MIMETYPE_BMP; cType = graphic::GraphicType::PIXEL; break;
     113           0 :             case( GFF_GIF ): pMimeType = MIMETYPE_GIF; cType = graphic::GraphicType::PIXEL; break;
     114           0 :             case( GFF_JPG ): pMimeType = MIMETYPE_JPG; cType = graphic::GraphicType::PIXEL; break;
     115           0 :             case( GFF_PCD ): pMimeType = MIMETYPE_PCD; cType = graphic::GraphicType::PIXEL; break;
     116           0 :             case( GFF_PCX ): pMimeType = MIMETYPE_PCX; cType = graphic::GraphicType::PIXEL; break;
     117           0 :             case( GFF_PNG ): pMimeType = MIMETYPE_PNG; cType = graphic::GraphicType::PIXEL; break;
     118           0 :             case( GFF_TIF ): pMimeType = MIMETYPE_TIF; cType = graphic::GraphicType::PIXEL; break;
     119           0 :             case( GFF_XBM ): pMimeType = MIMETYPE_XBM; cType = graphic::GraphicType::PIXEL; break;
     120           0 :             case( GFF_XPM ): pMimeType = MIMETYPE_XPM; cType = graphic::GraphicType::PIXEL; break;
     121           0 :             case( GFF_PBM ): pMimeType = MIMETYPE_PBM; cType = graphic::GraphicType::PIXEL; break;
     122           0 :             case( GFF_PGM ): pMimeType = MIMETYPE_PGM; cType = graphic::GraphicType::PIXEL; break;
     123           0 :             case( GFF_PPM ): pMimeType = MIMETYPE_PPM; cType = graphic::GraphicType::PIXEL; break;
     124           0 :             case( GFF_RAS ): pMimeType = MIMETYPE_RAS; cType = graphic::GraphicType::PIXEL; break;
     125           0 :             case( GFF_TGA ): pMimeType = MIMETYPE_TGA; cType = graphic::GraphicType::PIXEL; break;
     126           0 :             case( GFF_PSD ): pMimeType = MIMETYPE_PSD; cType = graphic::GraphicType::PIXEL; break;
     127             : 
     128           0 :             case( GFF_EPS ): pMimeType = MIMETYPE_EPS; cType = graphic::GraphicType::VECTOR; break;
     129           0 :             case( GFF_DXF ): pMimeType = MIMETYPE_DXF; cType = graphic::GraphicType::VECTOR; break;
     130           0 :             case( GFF_MET ): pMimeType = MIMETYPE_MET; cType = graphic::GraphicType::VECTOR; break;
     131           0 :             case( GFF_PCT ): pMimeType = MIMETYPE_PCT; cType = graphic::GraphicType::VECTOR; break;
     132           0 :             case( GFF_SGF ): pMimeType = MIMETYPE_SGF; cType = graphic::GraphicType::VECTOR; break;
     133           0 :             case( GFF_SVM ): pMimeType = MIMETYPE_SVM; cType = graphic::GraphicType::VECTOR; break;
     134           0 :             case( GFF_WMF ): pMimeType = MIMETYPE_WMF; cType = graphic::GraphicType::VECTOR; break;
     135           0 :             case( GFF_SGV ): pMimeType = MIMETYPE_SGV; cType = graphic::GraphicType::VECTOR; break;
     136           0 :             case( GFF_EMF ): pMimeType = MIMETYPE_EMF; cType = graphic::GraphicType::VECTOR; break;
     137           0 :             case( GFF_SVG ): pMimeType = MIMETYPE_SVG; cType = graphic::GraphicType::VECTOR; break;
     138             : 
     139             :             default:
     140           0 :             break;
     141             :         }
     142             : 
     143           0 :         if( graphic::GraphicType::EMPTY != cType )
     144             :         {
     145           0 :             meType = ( ( graphic::GraphicType::PIXEL == cType ) ? GRAPHIC_BITMAP : GRAPHIC_GDIMETAFILE );
     146           0 :             maMimeType = OUString( pMimeType, strlen(pMimeType), RTL_TEXTENCODING_ASCII_US );
     147           0 :             maSizePixel = aDescriptor.GetSizePixel();
     148           0 :             maSize100thMM = aDescriptor.GetSize_100TH_MM();
     149           0 :             mnBitsPerPixel = aDescriptor.GetBitsPerPixel();
     150           0 :             mbTransparent = ( graphic::GraphicType::VECTOR == cType );
     151           0 :             mbAlpha = mbAnimated = false;
     152             :         }
     153           0 :     }
     154           0 : }
     155             : 
     156             : 
     157             : 
     158           0 : OUString GraphicDescriptor::getImplementationName_Static()
     159             :     throw()
     160             : {
     161           0 :     return OUString( "com.sun.star.comp.graphic.GraphicDescriptor"  );
     162             : }
     163             : 
     164             : 
     165             : 
     166           0 : uno::Sequence< OUString > GraphicDescriptor::getSupportedServiceNames_Static()
     167             :     throw(  )
     168             : {
     169           0 :     uno::Sequence< OUString > aSeq( 1 );
     170             : 
     171           0 :     aSeq.getArray()[ 0 ] = "com.sun.star.graphic.GraphicDescriptor";
     172             : 
     173           0 :     return aSeq;
     174             : }
     175             : 
     176             : 
     177             : 
     178         692 : uno::Any SAL_CALL GraphicDescriptor::queryAggregation( const uno::Type & rType )
     179             :     throw( uno::RuntimeException, std::exception )
     180             : {
     181         692 :     uno::Any aAny;
     182             : 
     183         692 :     if( rType == cppu::UnoType<lang::XServiceInfo>::get())
     184           0 :         aAny <<= uno::Reference< lang::XServiceInfo >(this);
     185         692 :     else if( rType == cppu::UnoType<lang::XTypeProvider>::get())
     186           0 :         aAny <<= uno::Reference< lang::XTypeProvider >(this);
     187         692 :     else if( rType == cppu::UnoType<beans::XPropertySet>::get())
     188         408 :         aAny <<= uno::Reference< beans::XPropertySet >(this);
     189         284 :     else if( rType == cppu::UnoType<beans::XPropertyState>::get())
     190           0 :         aAny <<= uno::Reference< beans::XPropertyState >(this);
     191         284 :     else if( rType == cppu::UnoType<beans::XMultiPropertySet>::get())
     192         266 :         aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
     193             :     else
     194          18 :         aAny <<= OWeakAggObject::queryAggregation( rType );
     195             : 
     196         692 :     return aAny;
     197             : }
     198             : 
     199             : 
     200             : 
     201      145418 : uno::Any SAL_CALL GraphicDescriptor::queryInterface( const uno::Type & rType )
     202             :     throw( uno::RuntimeException, std::exception )
     203             : {
     204      145418 :     return OWeakAggObject::queryInterface( rType );
     205             : }
     206             : 
     207             : 
     208             : 
     209      890080 : void SAL_CALL GraphicDescriptor::acquire()
     210             :     throw()
     211             : {
     212      890080 :     OWeakAggObject::acquire();
     213      890080 : }
     214             : 
     215             : 
     216             : 
     217      890078 : void SAL_CALL GraphicDescriptor::release()
     218             :     throw()
     219             : {
     220      890078 :     OWeakAggObject::release();
     221      890078 : }
     222             : 
     223             : 
     224             : 
     225           0 : OUString SAL_CALL GraphicDescriptor::getImplementationName()
     226             :     throw( uno::RuntimeException, std::exception )
     227             : {
     228           0 :     return getImplementationName_Static();
     229             : }
     230             : 
     231           0 : sal_Bool SAL_CALL GraphicDescriptor::supportsService( const OUString& ServiceName )
     232             :     throw( uno::RuntimeException, std::exception )
     233             : {
     234           0 :     return cppu::supportsService(this, ServiceName);
     235             : }
     236             : 
     237             : 
     238             : 
     239           0 : uno::Sequence< OUString > SAL_CALL GraphicDescriptor::getSupportedServiceNames()
     240             :     throw( uno::RuntimeException, std::exception )
     241             : {
     242           0 :     return getSupportedServiceNames_Static();
     243             : }
     244             : 
     245             : 
     246             : 
     247           0 : uno::Sequence< uno::Type > SAL_CALL GraphicDescriptor::getTypes()
     248             :     throw( uno::RuntimeException, std::exception )
     249             : {
     250           0 :     uno::Sequence< uno::Type >  aTypes( 6 );
     251           0 :     uno::Type*                  pTypes = aTypes.getArray();
     252             : 
     253           0 :     *pTypes++ = cppu::UnoType<uno::XAggregation>::get();
     254           0 :     *pTypes++ = cppu::UnoType<lang::XServiceInfo>::get();
     255           0 :     *pTypes++ = cppu::UnoType<lang::XTypeProvider>::get();
     256           0 :     *pTypes++ = cppu::UnoType<beans::XPropertySet>::get();
     257           0 :     *pTypes++ = cppu::UnoType<beans::XPropertyState>::get();
     258           0 :     *pTypes++ = cppu::UnoType<beans::XMultiPropertySet>::get();
     259             : 
     260           0 :     return aTypes;
     261             : }
     262             : 
     263           0 : uno::Sequence< sal_Int8 > SAL_CALL GraphicDescriptor::getImplementationId()
     264             :     throw( uno::RuntimeException, std::exception )
     265             : {
     266           0 :     return css::uno::Sequence<sal_Int8>();
     267             : }
     268             : 
     269             : 
     270             : 
     271      137458 : ::comphelper::PropertySetInfo* GraphicDescriptor::createPropertySetInfo()
     272             : {
     273      137458 :     SolarMutexGuard aGuard;
     274      137458 :     ::comphelper::PropertySetInfo*  pRet = new ::comphelper::PropertySetInfo();
     275             : 
     276             :     static ::comphelper::PropertyMapEntry const aEntries[] =
     277             :     {
     278         118 :         { OUString("GraphicType"), UNOGRAPHIC_GRAPHICTYPE, cppu::UnoType<sal_Int8>::get(), beans::PropertyAttribute::READONLY, 0 },
     279         118 :         { OUString("MimeType"), UNOGRAPHIC_MIMETYPE, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::READONLY, 0 },
     280         118 :         { OUString("SizePixel"), UNOGRAPHIC_SIZEPIXEL, cppu::UnoType<awt::Size>::get(), beans::PropertyAttribute::READONLY, 0 },
     281         118 :         { OUString("Size100thMM"), UNOGRAPHIC_SIZE100THMM, cppu::UnoType<awt::Size>::get(), beans::PropertyAttribute::READONLY, 0 },
     282         118 :         { OUString("BitsPerPixel"), UNOGRAPHIC_BITSPERPIXEL, cppu::UnoType<sal_uInt8>::get(), beans::PropertyAttribute::READONLY, 0 },
     283         118 :         { OUString("Transparent"), UNOGRAPHIC_TRANSPARENT, cppu::UnoType<sal_Bool>::get(), beans::PropertyAttribute::READONLY, 0 },
     284         118 :         { OUString("Alpha"), UNOGRAPHIC_ALPHA, cppu::UnoType<sal_Bool>::get(), beans::PropertyAttribute::READONLY, 0 },
     285         118 :         { OUString("Animated"), UNOGRAPHIC_ANIMATED, cppu::UnoType<sal_Bool>::get(), beans::PropertyAttribute::READONLY, 0 },
     286             :         { OUString(), 0, css::uno::Type(), 0, 0 }
     287      138520 :     };
     288             : 
     289      137458 :     pRet->acquire();
     290      137458 :     pRet->add( aEntries );
     291             : 
     292      137458 :     return pRet;
     293             : }
     294             : 
     295             : 
     296             : 
     297           0 : void GraphicDescriptor::_setPropertyValues( const comphelper::PropertyMapEntry** /*ppEntries*/, const uno::Any* /*pValues*/ )
     298             :     throw( beans::UnknownPropertyException,
     299             :            beans::PropertyVetoException,
     300             :            lang::IllegalArgumentException,
     301             :               lang::WrappedTargetException )
     302             : {
     303             :     // we only have readonly attributes
     304           0 : }
     305             : 
     306             : 
     307             : 
     308         598 : void GraphicDescriptor::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValues )
     309             :     throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
     310             : {
     311         598 :     SolarMutexGuard aGuard;
     312             : 
     313        1794 :     while( *ppEntries )
     314             :     {
     315         598 :         switch( (*ppEntries)->mnHandle )
     316             :         {
     317             :             case( UNOGRAPHIC_GRAPHICTYPE ):
     318             :             {
     319           2 :                 const GraphicType eType( mpGraphic ? mpGraphic->GetType() : meType );
     320             : 
     321           2 :                 *pValues <<= ( ( eType == GRAPHIC_BITMAP ? graphic::GraphicType::PIXEL :
     322             :                                 ( eType == GRAPHIC_GDIMETAFILE ? graphic::GraphicType::VECTOR :
     323           2 :                                 graphic::GraphicType::EMPTY ) ) );
     324             :             }
     325           2 :             break;
     326             : 
     327             :             case( UNOGRAPHIC_MIMETYPE ):
     328             :             {
     329           0 :                 OUString aMimeType;
     330             : 
     331           0 :                 if( mpGraphic )
     332             :                 {
     333           0 :                     if( mpGraphic->IsLink() )
     334             :                     {
     335             :                         const char* pMimeType;
     336             : 
     337           0 :                         switch( const_cast< Graphic* >( mpGraphic )->GetLink().GetType() )
     338             :                         {
     339           0 :                             case( GFX_LINK_TYPE_NATIVE_GIF ): pMimeType = MIMETYPE_GIF; break;
     340             : 
     341             :                             // #i15508# added BMP type for better exports (checked, works)
     342           0 :                             case( GFX_LINK_TYPE_NATIVE_BMP ): pMimeType = MIMETYPE_BMP; break;
     343             : 
     344           0 :                             case( GFX_LINK_TYPE_NATIVE_JPG ): pMimeType = MIMETYPE_JPG; break;
     345           0 :                             case( GFX_LINK_TYPE_NATIVE_PNG ): pMimeType = MIMETYPE_PNG; break;
     346           0 :                             case( GFX_LINK_TYPE_NATIVE_WMF ): pMimeType = MIMETYPE_WMF; break;
     347           0 :                             case( GFX_LINK_TYPE_NATIVE_MET ): pMimeType = MIMETYPE_MET; break;
     348           0 :                             case( GFX_LINK_TYPE_NATIVE_PCT ): pMimeType = MIMETYPE_PCT; break;
     349             : 
     350             :                             // added Svg mimetype support
     351           0 :                             case( GFX_LINK_TYPE_NATIVE_SVG ): pMimeType = MIMETYPE_SVG; break;
     352             : 
     353             :                             default:
     354           0 :                                 pMimeType = NULL;
     355           0 :                             break;
     356             :                         }
     357             : 
     358           0 :                         if( pMimeType )
     359           0 :                             aMimeType = OUString::createFromAscii( pMimeType );
     360             :                     }
     361             : 
     362           0 :                     if( aMimeType.isEmpty() && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
     363           0 :                         aMimeType = MIMETYPE_VCLGRAPHIC;
     364             :                 }
     365             :                 else
     366           0 :                     aMimeType = maMimeType;
     367             : 
     368           0 :                  *pValues <<= aMimeType;
     369             :             }
     370           0 :             break;
     371             : 
     372             :             case( UNOGRAPHIC_SIZEPIXEL ):
     373             :             {
     374         194 :                 awt::Size aAWTSize( 0, 0 );
     375             : 
     376         194 :                 if( mpGraphic )
     377             :                 {
     378         194 :                     if( mpGraphic->GetType() == GRAPHIC_BITMAP )
     379             :                     {
     380         184 :                         const Size aSizePix( mpGraphic->GetBitmapEx().GetSizePixel() );
     381         184 :                         aAWTSize = awt::Size( aSizePix.Width(), aSizePix.Height() );
     382             :                     }
     383             :                 }
     384             :                 else
     385           0 :                     aAWTSize = awt::Size( maSizePixel.Width(), maSizePixel.Height() );
     386             : 
     387         194 :                 *pValues <<= aAWTSize;
     388             :             }
     389         194 :             break;
     390             : 
     391             :             case( UNOGRAPHIC_SIZE100THMM ):
     392             :             {
     393         402 :                 awt::Size aAWTSize( 0, 0 );
     394             : 
     395         402 :                 if( mpGraphic )
     396             :                 {
     397         402 :                     if( mpGraphic->GetPrefMapMode().GetMapUnit() != MAP_PIXEL )
     398             :                     {
     399         298 :                         const Size aSizeLog( OutputDevice::LogicToLogic( mpGraphic->GetPrefSize(), mpGraphic->GetPrefMapMode(), MAP_100TH_MM ) );
     400         298 :                         aAWTSize = awt::Size( aSizeLog.Width(), aSizeLog.Height() );
     401             :                     }
     402             :                 }
     403             :                 else
     404           0 :                     aAWTSize = awt::Size( maSize100thMM.Width(), maSize100thMM.Height() );
     405             : 
     406         402 :                 *pValues <<= aAWTSize;
     407             :             }
     408         402 :             break;
     409             : 
     410             :             case( UNOGRAPHIC_BITSPERPIXEL ):
     411             :             {
     412           0 :                 sal_uInt16 nBitsPerPixel = 0;
     413             : 
     414           0 :                 if( mpGraphic )
     415             :                 {
     416           0 :                     if( mpGraphic->GetType() == GRAPHIC_BITMAP )
     417           0 :                         nBitsPerPixel = mpGraphic->GetBitmapEx().GetBitmap().GetBitCount();
     418             :                 }
     419             :                 else
     420           0 :                     nBitsPerPixel = mnBitsPerPixel;
     421             : 
     422           0 :                 *pValues <<= sal::static_int_cast< sal_Int8 >(nBitsPerPixel);
     423             :             }
     424           0 :             break;
     425             : 
     426             :             case( UNOGRAPHIC_TRANSPARENT ):
     427             :             {
     428           0 :                 *pValues <<= mpGraphic ? mpGraphic->IsTransparent() : mbTransparent;
     429             :             }
     430           0 :             break;
     431             : 
     432             :             case( UNOGRAPHIC_ALPHA ):
     433             :             {
     434           0 :                 *pValues <<= mpGraphic ? mpGraphic->IsAlpha() : mbAlpha;
     435             :             }
     436           0 :             break;
     437             : 
     438             :             case( UNOGRAPHIC_ANIMATED ):
     439             :             {
     440           0 :                 *pValues <<= mpGraphic ? mpGraphic->IsAnimated() : mbAnimated;
     441             :             }
     442           0 :             break;
     443             :         }
     444             : 
     445         598 :         ++ppEntries;
     446         598 :         ++pValues;
     447         598 :     }
     448         598 : }
     449             : 
     450        1227 : }
     451             : 
     452             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10