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