15900e8ecSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 35900e8ecSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 45900e8ecSAndrew Rist * or more contributor license agreements. See the NOTICE file 55900e8ecSAndrew Rist * distributed with this work for additional information 65900e8ecSAndrew Rist * regarding copyright ownership. The ASF licenses this file 75900e8ecSAndrew Rist * to you under the Apache License, Version 2.0 (the 85900e8ecSAndrew Rist * "License"); you may not use this file except in compliance 95900e8ecSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 115900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 135900e8ecSAndrew Rist * Unless required by applicable law or agreed to in writing, 145900e8ecSAndrew Rist * software distributed under the License is distributed on an 155900e8ecSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 165900e8ecSAndrew Rist * KIND, either express or implied. See the License for the 175900e8ecSAndrew Rist * specific language governing permissions and limitations 185900e8ecSAndrew Rist * under the License. 19cdf0e10cSrcweir * 205900e8ecSAndrew Rist *************************************************************/ 215900e8ecSAndrew Rist 22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 23cdf0e10cSrcweir #include "precompiled_svtools.hxx" 24cdf0e10cSrcweir 25cdf0e10cSrcweir #include <rtl/uuid.h> 26cdf0e10cSrcweir #include <vos/mutex.hxx> 27cdf0e10cSrcweir #include <vcl/svapp.hxx> 28cdf0e10cSrcweir #include <com/sun/star/graphic/GraphicType.hpp> 29cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicTransformer.hpp> 30cdf0e10cSrcweir #include <vcl/graph.hxx> 31cdf0e10cSrcweir #include "graphic.hxx" 32*45fd3b9aSArmin Le Grand #include <vcl/dibtools.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir using namespace com::sun::star; 35cdf0e10cSrcweir 36cdf0e10cSrcweir namespace unographic { 37cdf0e10cSrcweir 38cdf0e10cSrcweir // ------------------- 39cdf0e10cSrcweir // - GraphicProvider - 40cdf0e10cSrcweir // ------------------- 41cdf0e10cSrcweir 42cdf0e10cSrcweir Graphic::Graphic() : 43cdf0e10cSrcweir mpGraphic( NULL ) 44cdf0e10cSrcweir { 45cdf0e10cSrcweir } 46cdf0e10cSrcweir 47cdf0e10cSrcweir // ------------------------------------------------------------------------------ 48cdf0e10cSrcweir 49cdf0e10cSrcweir Graphic::~Graphic() 50cdf0e10cSrcweir throw() 51cdf0e10cSrcweir { 52cdf0e10cSrcweir delete mpGraphic; 53cdf0e10cSrcweir } 54cdf0e10cSrcweir 55cdf0e10cSrcweir // ------------------------------------------------------------------------------ 56cdf0e10cSrcweir 57cdf0e10cSrcweir void Graphic::init( const ::Graphic& rGraphic ) 58cdf0e10cSrcweir throw() 59cdf0e10cSrcweir { 60cdf0e10cSrcweir delete mpGraphic; 61cdf0e10cSrcweir mpGraphic = new ::Graphic( rGraphic ); 62cdf0e10cSrcweir ::unographic::GraphicDescriptor::init( *mpGraphic ); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir // ------------------------------------------------------------------------------ 66cdf0e10cSrcweir 67cdf0e10cSrcweir uno::Any SAL_CALL Graphic::queryAggregation( const uno::Type& rType ) 68cdf0e10cSrcweir throw( uno::RuntimeException ) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir uno::Any aAny; 71cdf0e10cSrcweir if( rType == ::getCppuType((const uno::Reference< graphic::XGraphic >*)0) ) 72cdf0e10cSrcweir aAny <<= uno::Reference< graphic::XGraphic >( this ); 73cdf0e10cSrcweir else if( rType == ::getCppuType((const uno::Reference< awt::XBitmap >*)0) ) 74cdf0e10cSrcweir aAny <<= uno::Reference< awt::XBitmap >( this ); 75cdf0e10cSrcweir else if( rType == ::getCppuType((const uno::Reference< lang::XUnoTunnel >*)0) ) 76cdf0e10cSrcweir aAny <<= uno::Reference< lang::XUnoTunnel >(this); 77cdf0e10cSrcweir else 78cdf0e10cSrcweir aAny <<= ::unographic::GraphicDescriptor::queryAggregation( rType ); 79cdf0e10cSrcweir 80cdf0e10cSrcweir return aAny ; 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir // ------------------------------------------------------------------------------ 84cdf0e10cSrcweir 85cdf0e10cSrcweir uno::Any SAL_CALL Graphic::queryInterface( const uno::Type & rType ) 86cdf0e10cSrcweir throw( uno::RuntimeException ) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir ::com::sun::star::uno::Any aReturn = ::unographic::GraphicDescriptor::queryInterface( rType ); 89cdf0e10cSrcweir if ( !aReturn.hasValue() ) 90cdf0e10cSrcweir aReturn = ::cppu::queryInterface ( rType, static_cast< graphic::XGraphicTransformer*>( this ) ); 91cdf0e10cSrcweir return aReturn; 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir // ------------------------------------------------------------------------------ 95cdf0e10cSrcweir 96cdf0e10cSrcweir void SAL_CALL Graphic::acquire() 97cdf0e10cSrcweir throw() 98cdf0e10cSrcweir { 99cdf0e10cSrcweir ::unographic::GraphicDescriptor::acquire(); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir // ------------------------------------------------------------------------------ 103cdf0e10cSrcweir 104cdf0e10cSrcweir void SAL_CALL Graphic::release() throw() 105cdf0e10cSrcweir { 106cdf0e10cSrcweir ::unographic::GraphicDescriptor::release(); 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir // ------------------------------------------------------------------------------ 110cdf0e10cSrcweir 111cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId_Static() 112cdf0e10cSrcweir throw(uno::RuntimeException) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 115cdf0e10cSrcweir static uno::Sequence< sal_Int8 > aId; 116cdf0e10cSrcweir 117cdf0e10cSrcweir if( aId.getLength() == 0 ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir aId.realloc( 16 ); 120cdf0e10cSrcweir rtl_createUuid( reinterpret_cast< sal_uInt8* >( aId.getArray() ), 0, sal_True ); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir return aId; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir // ------------------------------------------------------------------------------ 127cdf0e10cSrcweir 128cdf0e10cSrcweir ::rtl::OUString Graphic::getImplementationName_Static() 129cdf0e10cSrcweir throw() 130cdf0e10cSrcweir { 131cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.Graphic" ) ); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir // ------------------------------------------------------------------------------ 135cdf0e10cSrcweir 136cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > Graphic::getSupportedServiceNames_Static() 137cdf0e10cSrcweir throw() 138cdf0e10cSrcweir { 139cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aSeq( 1 ); 140cdf0e10cSrcweir 141cdf0e10cSrcweir aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.Graphic" ) ); 142cdf0e10cSrcweir 143cdf0e10cSrcweir return aSeq; 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir // ------------------------------------------------------------------------------ 147cdf0e10cSrcweir 148cdf0e10cSrcweir ::rtl::OUString SAL_CALL Graphic::getImplementationName() 149cdf0e10cSrcweir throw( uno::RuntimeException ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir return getImplementationName_Static(); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir // ------------------------------------------------------------------------------ 155cdf0e10cSrcweir 156cdf0e10cSrcweir sal_Bool SAL_CALL Graphic::supportsService( const ::rtl::OUString& rServiceName ) 157cdf0e10cSrcweir throw( uno::RuntimeException ) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir if( ::unographic::GraphicDescriptor::supportsService( rServiceName ) ) 160cdf0e10cSrcweir return true; 161cdf0e10cSrcweir else 162cdf0e10cSrcweir { 163cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() ); 164cdf0e10cSrcweir const ::rtl::OUString* pArray = aSNL.getConstArray(); 165cdf0e10cSrcweir 166cdf0e10cSrcweir for( int i = 0; i < aSNL.getLength(); i++ ) 167cdf0e10cSrcweir if( pArray[i] == rServiceName ) 168cdf0e10cSrcweir return true; 169cdf0e10cSrcweir 170cdf0e10cSrcweir return false; 171cdf0e10cSrcweir } 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir // ------------------------------------------------------------------------------ 175cdf0e10cSrcweir 176cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL Graphic::getSupportedServiceNames() 177cdf0e10cSrcweir throw( uno::RuntimeException ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() ); 180cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aNew( getSupportedServiceNames_Static() ); 181cdf0e10cSrcweir sal_Int32 nOldCount = aRet.getLength(); 182cdf0e10cSrcweir 183cdf0e10cSrcweir aRet.realloc( nOldCount + aNew.getLength() ); 184cdf0e10cSrcweir 185cdf0e10cSrcweir for( sal_Int32 i = 0; i < aNew.getLength(); ++i ) 186cdf0e10cSrcweir aRet[ nOldCount++ ] = aNew[ i ]; 187cdf0e10cSrcweir 188cdf0e10cSrcweir return aRet; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir // ------------------------------------------------------------------------------ 192cdf0e10cSrcweir 193cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL Graphic::getTypes() 194cdf0e10cSrcweir throw(uno::RuntimeException) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir uno::Sequence< uno::Type > aRet( ::unographic::GraphicDescriptor::getTypes() ); 197cdf0e10cSrcweir sal_Int32 nOldCount = aRet.getLength(); 198cdf0e10cSrcweir 199cdf0e10cSrcweir aRet.realloc( nOldCount + 2 ); 200cdf0e10cSrcweir aRet[ nOldCount ] = ::getCppuType((const uno::Reference< graphic::XGraphic>*)0); 201cdf0e10cSrcweir aRet[ nOldCount+1 ] = ::getCppuType((const uno::Reference< awt::XBitmap>*)0); 202cdf0e10cSrcweir 203cdf0e10cSrcweir return aRet; 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir // ------------------------------------------------------------------------------ 207cdf0e10cSrcweir 208cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId() 209cdf0e10cSrcweir throw(uno::RuntimeException) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir return getImplementationId_Static(); 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir // ------------------------------------------------------------------------------ 215cdf0e10cSrcweir 216cdf0e10cSrcweir ::sal_Int8 SAL_CALL Graphic::getType() 217cdf0e10cSrcweir throw (uno::RuntimeException) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir ::sal_Int8 cRet = graphic::GraphicType::EMPTY; 220cdf0e10cSrcweir 221cdf0e10cSrcweir if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) ) 222cdf0e10cSrcweir cRet = ( ( mpGraphic->GetType() == GRAPHIC_BITMAP ) ? graphic::GraphicType::PIXEL : graphic::GraphicType::VECTOR ); 223cdf0e10cSrcweir 224cdf0e10cSrcweir return cRet; 225cdf0e10cSrcweir } 226cdf0e10cSrcweir 227cdf0e10cSrcweir //---------------------------------------------------------------------- 228cdf0e10cSrcweir // XBitmap 229cdf0e10cSrcweir //---------------------------------------------------------------------- 230cdf0e10cSrcweir 231cdf0e10cSrcweir awt::Size SAL_CALL Graphic::getSize( ) throw (uno::RuntimeException) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 234cdf0e10cSrcweir 235cdf0e10cSrcweir ::Size aVclSize; 236cdf0e10cSrcweir if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) ) 237cdf0e10cSrcweir aVclSize = mpGraphic->GetSizePixel(); 238cdf0e10cSrcweir 239cdf0e10cSrcweir return awt::Size( aVclSize.Width(), aVclSize.Height() ); 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir //---------------------------------------------------------------------- 243cdf0e10cSrcweir 244cdf0e10cSrcweir uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getDIB( ) throw (uno::RuntimeException) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 247cdf0e10cSrcweir 248cdf0e10cSrcweir if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) ) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir SvMemoryStream aMem; 251*45fd3b9aSArmin Le Grand 252*45fd3b9aSArmin Le Grand WriteDIB(mpGraphic->GetBitmapEx().GetBitmap(), aMem, false, true); 253cdf0e10cSrcweir return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() ); 254cdf0e10cSrcweir } 255cdf0e10cSrcweir else 256cdf0e10cSrcweir { 257cdf0e10cSrcweir return uno::Sequence<sal_Int8>(); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir } 260cdf0e10cSrcweir 261cdf0e10cSrcweir //---------------------------------------------------------------------- 262cdf0e10cSrcweir 263cdf0e10cSrcweir uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getMaskDIB( ) throw (uno::RuntimeException) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 266cdf0e10cSrcweir 267cdf0e10cSrcweir if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) ) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir SvMemoryStream aMem; 270*45fd3b9aSArmin Le Grand 271*45fd3b9aSArmin Le Grand WriteDIB(mpGraphic->GetBitmapEx().GetMask(), aMem, false, true); 272cdf0e10cSrcweir return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() ); 273cdf0e10cSrcweir } 274cdf0e10cSrcweir else 275cdf0e10cSrcweir { 276cdf0e10cSrcweir return uno::Sequence<sal_Int8>(); 277cdf0e10cSrcweir } 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir //---------------------------------------------------------------------- 281cdf0e10cSrcweir const ::Graphic* Graphic::getImplementation( const uno::Reference< uno::XInterface >& rxIFace ) 282cdf0e10cSrcweir throw() 283cdf0e10cSrcweir { 284cdf0e10cSrcweir uno::Reference< lang::XUnoTunnel > xTunnel( rxIFace, uno::UNO_QUERY ); 285cdf0e10cSrcweir return( xTunnel.is() ? reinterpret_cast< ::Graphic* >( xTunnel->getSomething( getImplementationId_Static() ) ) : NULL ); 286cdf0e10cSrcweir } 287cdf0e10cSrcweir 288cdf0e10cSrcweir //---------------------------------------------------------------------- 289cdf0e10cSrcweir sal_Int64 SAL_CALL Graphic::getSomething( const uno::Sequence< sal_Int8 >& rId ) 290cdf0e10cSrcweir throw( uno::RuntimeException ) 291cdf0e10cSrcweir { 292cdf0e10cSrcweir return( ( rId.getLength() == 16 && 0 == rtl_compareMemory( getImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) ? 293cdf0e10cSrcweir reinterpret_cast< sal_Int64 >( mpGraphic ) : 294cdf0e10cSrcweir 0 ); 295cdf0e10cSrcweir } 296cdf0e10cSrcweir 297cdf0e10cSrcweir } 298