xref: /aoo42x/main/svtools/source/graphic/graphic.cxx (revision 45fd3b9a)
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 
Graphic()42 Graphic::Graphic() :
43 	mpGraphic( NULL )
44 {
45 }
46 
47 // ------------------------------------------------------------------------------
48 
~Graphic()49 Graphic::~Graphic()
50 	throw()
51 {
52 	delete mpGraphic;
53 }
54 
55 // ------------------------------------------------------------------------------
56 
init(const::Graphic & rGraphic)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 
queryAggregation(const uno::Type & rType)67 uno::Any SAL_CALL Graphic::queryAggregation( const uno::Type& rType )
68 	throw( uno::RuntimeException )
69 {
70 	uno::Any aAny;
71 	if( rType == ::getCppuType((const uno::Reference< graphic::XGraphic >*)0) )
72 		aAny <<= uno::Reference< graphic::XGraphic >( this );
73 	else if( rType == ::getCppuType((const uno::Reference< awt::XBitmap >*)0) )
74 		aAny <<= uno::Reference< awt::XBitmap >( this );
75 	else if( rType == ::getCppuType((const uno::Reference< lang::XUnoTunnel >*)0) )
76 		aAny <<= uno::Reference< lang::XUnoTunnel >(this);
77 	else
78 		aAny <<= ::unographic::GraphicDescriptor::queryAggregation( rType );
79 
80 	return aAny ;
81 }
82 
83 // ------------------------------------------------------------------------------
84 
queryInterface(const uno::Type & rType)85 uno::Any SAL_CALL Graphic::queryInterface( const uno::Type & rType )
86 	throw( uno::RuntimeException )
87 {
88     ::com::sun::star::uno::Any aReturn = ::unographic::GraphicDescriptor::queryInterface( rType );
89     if ( !aReturn.hasValue() )
90 		aReturn = ::cppu::queryInterface ( rType, static_cast< graphic::XGraphicTransformer*>( this ) );
91 	return aReturn;
92 }
93 
94 // ------------------------------------------------------------------------------
95 
acquire()96 void SAL_CALL Graphic::acquire()
97 	throw()
98 {
99 	::unographic::GraphicDescriptor::acquire();
100 }
101 
102 // ------------------------------------------------------------------------------
103 
release()104 void SAL_CALL Graphic::release() throw()
105 {
106 	::unographic::GraphicDescriptor::release();
107 }
108 
109 // ------------------------------------------------------------------------------
110 
getImplementationId_Static()111 uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId_Static()
112 	throw(uno::RuntimeException)
113 {
114 	vos::OGuard 						aGuard( Application::GetSolarMutex() );
115 	static uno::Sequence< sal_Int8 >	aId;
116 
117 	if( aId.getLength() == 0 )
118 	{
119 		aId.realloc( 16 );
120 		rtl_createUuid( reinterpret_cast< sal_uInt8* >( aId.getArray() ), 0, sal_True );
121 	}
122 
123 	return aId;
124 }
125 
126 // ------------------------------------------------------------------------------
127 
getImplementationName_Static()128 ::rtl::OUString Graphic::getImplementationName_Static()
129 	throw()
130 {
131 	return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.Graphic" ) );
132 }
133 
134 // ------------------------------------------------------------------------------
135 
getSupportedServiceNames_Static()136 uno::Sequence< ::rtl::OUString > Graphic::getSupportedServiceNames_Static()
137 	throw()
138 {
139 	uno::Sequence< ::rtl::OUString > aSeq( 1 );
140 
141 	aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.Graphic" ) );
142 
143 	return aSeq;
144 }
145 
146 // ------------------------------------------------------------------------------
147 
getImplementationName()148 ::rtl::OUString SAL_CALL Graphic::getImplementationName()
149 	throw( uno::RuntimeException )
150 {
151 	return getImplementationName_Static();
152 }
153 
154 // ------------------------------------------------------------------------------
155 
supportsService(const::rtl::OUString & rServiceName)156 sal_Bool SAL_CALL Graphic::supportsService( const ::rtl::OUString& rServiceName )
157 	throw( uno::RuntimeException )
158 {
159 	if( ::unographic::GraphicDescriptor::supportsService( rServiceName ) )
160 		return true;
161 	else
162 	{
163 		uno::Sequence< ::rtl::OUString >	aSNL( getSupportedServiceNames() );
164 		const ::rtl::OUString*				pArray = aSNL.getConstArray();
165 
166 		for( int i = 0; i < aSNL.getLength(); i++ )
167 			if( pArray[i] == rServiceName )
168 				return true;
169 
170 		return false;
171 	}
172 }
173 
174 // ------------------------------------------------------------------------------
175 
getSupportedServiceNames()176 uno::Sequence< ::rtl::OUString > SAL_CALL Graphic::getSupportedServiceNames()
177 	throw( uno::RuntimeException )
178 {
179 	uno::Sequence< ::rtl::OUString > 	aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() );
180 	uno::Sequence< ::rtl::OUString > 	aNew( getSupportedServiceNames_Static() );
181 	sal_Int32							nOldCount = aRet.getLength();
182 
183 	aRet.realloc( nOldCount + aNew.getLength() );
184 
185 	for( sal_Int32 i = 0; i < aNew.getLength(); ++i )
186 		aRet[ nOldCount++ ] = aNew[ i ];
187 
188 	return aRet;
189 }
190 
191 // ------------------------------------------------------------------------------
192 
getTypes()193 uno::Sequence< uno::Type > SAL_CALL Graphic::getTypes()
194 	throw(uno::RuntimeException)
195 {
196 	uno::Sequence< uno::Type >	aRet( ::unographic::GraphicDescriptor::getTypes() );
197 	sal_Int32 					nOldCount = aRet.getLength();
198 
199 	aRet.realloc( nOldCount + 2 );
200 	aRet[ nOldCount ] = ::getCppuType((const uno::Reference< graphic::XGraphic>*)0);
201 	aRet[ nOldCount+1 ] = ::getCppuType((const uno::Reference< awt::XBitmap>*)0);
202 
203 	return aRet;
204 }
205 
206 // ------------------------------------------------------------------------------
207 
getImplementationId()208 uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId()
209 	throw(uno::RuntimeException)
210 {
211 	return getImplementationId_Static();
212 }
213 
214 // ------------------------------------------------------------------------------
215 
getType()216 ::sal_Int8 SAL_CALL Graphic::getType()
217  	throw (uno::RuntimeException)
218 {
219 	::sal_Int8 cRet = graphic::GraphicType::EMPTY;
220 
221 	if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
222 		cRet = ( ( mpGraphic->GetType() == GRAPHIC_BITMAP ) ? graphic::GraphicType::PIXEL : graphic::GraphicType::VECTOR );
223 
224 	return cRet;
225 }
226 
227 //----------------------------------------------------------------------
228 // XBitmap
229 //----------------------------------------------------------------------
230 
getSize()231 awt::Size SAL_CALL Graphic::getSize(  ) throw (uno::RuntimeException)
232 {
233 	::vos::OGuard aGuard( Application::GetSolarMutex() );
234 
235 	::Size aVclSize;
236 	if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
237 		aVclSize = mpGraphic->GetSizePixel();
238 
239 	return awt::Size( aVclSize.Width(), aVclSize.Height() );
240 }
241 
242 //----------------------------------------------------------------------
243 
getDIB()244 uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getDIB(  ) throw (uno::RuntimeException)
245 {
246 	::vos::OGuard aGuard( Application::GetSolarMutex() );
247 
248 	if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
249 	{
250 		SvMemoryStream aMem;
251 
252         WriteDIB(mpGraphic->GetBitmapEx().GetBitmap(), aMem, false, true);
253 		return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() );
254 	}
255 	else
256 	{
257 		return uno::Sequence<sal_Int8>();
258 	}
259 }
260 
261 //----------------------------------------------------------------------
262 
getMaskDIB()263 uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getMaskDIB(  ) throw (uno::RuntimeException)
264 {
265 	::vos::OGuard aGuard( Application::GetSolarMutex() );
266 
267 	if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
268 	{
269 		SvMemoryStream aMem;
270 
271         WriteDIB(mpGraphic->GetBitmapEx().GetMask(), aMem, false, true);
272 		return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() );
273 	}
274 	else
275 	{
276 		return uno::Sequence<sal_Int8>();
277 	}
278 }
279 
280 //----------------------------------------------------------------------
getImplementation(const uno::Reference<uno::XInterface> & rxIFace)281 const ::Graphic* Graphic::getImplementation( const uno::Reference< uno::XInterface >& rxIFace )
282 	throw()
283 {
284 	uno::Reference< lang::XUnoTunnel > xTunnel( rxIFace, uno::UNO_QUERY );
285 	return( xTunnel.is() ? reinterpret_cast< ::Graphic* >( xTunnel->getSomething( getImplementationId_Static() ) ) : NULL );
286 }
287 
288 //----------------------------------------------------------------------
getSomething(const uno::Sequence<sal_Int8> & rId)289 sal_Int64 SAL_CALL Graphic::getSomething( const uno::Sequence< sal_Int8 >& rId )
290 	throw( uno::RuntimeException )
291 {
292 	return( ( rId.getLength() == 16 && 0 == rtl_compareMemory( getImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) ?
293 			reinterpret_cast< sal_Int64 >( mpGraphic ) :
294 			0 );
295 }
296 
297 }
298