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 <osl/mutex.hxx>
21 : #include <vcl/svapp.hxx>
22 : #include <com/sun/star/graphic/GraphicType.hpp>
23 : #include <com/sun/star/graphic/XGraphicTransformer.hpp>
24 : #include <vcl/dibtools.hxx>
25 : #include <vcl/graph.hxx>
26 : #include "graphic.hxx"
27 : #include <comphelper/servicehelper.hxx>
28 : #include <string.h>
29 :
30 : using namespace com::sun::star;
31 :
32 : namespace unographic {
33 :
34 : // -------------------
35 : // - GraphicProvider -
36 : // -------------------
37 :
38 43324 : Graphic::Graphic() :
39 43324 : mpGraphic( NULL )
40 : {
41 43324 : }
42 :
43 : // ------------------------------------------------------------------------------
44 :
45 86648 : Graphic::~Graphic()
46 86648 : throw()
47 : {
48 43324 : delete mpGraphic;
49 86648 : }
50 :
51 : // ------------------------------------------------------------------------------
52 :
53 43324 : void Graphic::init( const ::Graphic& rGraphic )
54 : throw()
55 : {
56 43324 : delete mpGraphic;
57 43324 : mpGraphic = new ::Graphic( rGraphic );
58 43324 : ::unographic::GraphicDescriptor::init( *mpGraphic );
59 43324 : }
60 :
61 : // ------------------------------------------------------------------------------
62 :
63 86549 : uno::Any SAL_CALL Graphic::queryAggregation( const uno::Type& rType )
64 : throw( uno::RuntimeException )
65 : {
66 86549 : uno::Any aAny;
67 86549 : if( rType == ::getCppuType((const uno::Reference< graphic::XGraphic >*)0) )
68 58 : aAny <<= uno::Reference< graphic::XGraphic >( this );
69 86491 : else if( rType == ::getCppuType((const uno::Reference< awt::XBitmap >*)0) )
70 253 : aAny <<= uno::Reference< awt::XBitmap >( this );
71 86238 : else if( rType == ::getCppuType((const uno::Reference< lang::XUnoTunnel >*)0) )
72 43107 : aAny <<= uno::Reference< lang::XUnoTunnel >(this);
73 : else
74 43131 : aAny <<= ::unographic::GraphicDescriptor::queryAggregation( rType );
75 :
76 86549 : return aAny ;
77 : }
78 :
79 : // ------------------------------------------------------------------------------
80 :
81 86549 : uno::Any SAL_CALL Graphic::queryInterface( const uno::Type & rType )
82 : throw( uno::RuntimeException )
83 : {
84 86549 : ::com::sun::star::uno::Any aReturn = ::unographic::GraphicDescriptor::queryInterface( rType );
85 86549 : if ( !aReturn.hasValue() )
86 0 : aReturn = ::cppu::queryInterface ( rType, static_cast< graphic::XGraphicTransformer*>( this ) );
87 86549 : return aReturn;
88 : }
89 :
90 : // ------------------------------------------------------------------------------
91 :
92 392714 : void SAL_CALL Graphic::acquire()
93 : throw()
94 : {
95 392714 : ::unographic::GraphicDescriptor::acquire();
96 392714 : }
97 :
98 : // ------------------------------------------------------------------------------
99 :
100 392714 : void SAL_CALL Graphic::release() throw()
101 : {
102 392714 : ::unographic::GraphicDescriptor::release();
103 392714 : }
104 :
105 : // ------------------------------------------------------------------------------
106 :
107 : namespace
108 : {
109 : class theGraphicUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theGraphicUnoTunnelId > {};
110 : }
111 :
112 86214 : uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId_Static()
113 : throw(uno::RuntimeException)
114 : {
115 86214 : return theGraphicUnoTunnelId::get().getSeq();
116 : }
117 :
118 : // ------------------------------------------------------------------------------
119 :
120 0 : OUString Graphic::getImplementationName_Static()
121 : throw()
122 : {
123 0 : return OUString( "com.sun.star.comp.graphic.Graphic" );
124 : }
125 :
126 : // ------------------------------------------------------------------------------
127 :
128 0 : uno::Sequence< OUString > Graphic::getSupportedServiceNames_Static()
129 : throw()
130 : {
131 0 : uno::Sequence< OUString > aSeq( 1 );
132 :
133 0 : aSeq.getArray()[ 0 ] = OUString( "com.sun.star.graphic.Graphic" );
134 :
135 0 : return aSeq;
136 : }
137 :
138 : // ------------------------------------------------------------------------------
139 :
140 0 : OUString SAL_CALL Graphic::getImplementationName()
141 : throw( uno::RuntimeException )
142 : {
143 0 : return getImplementationName_Static();
144 : }
145 :
146 : // ------------------------------------------------------------------------------
147 :
148 0 : sal_Bool SAL_CALL Graphic::supportsService( const OUString& rServiceName )
149 : throw( uno::RuntimeException )
150 : {
151 0 : if( ::unographic::GraphicDescriptor::supportsService( rServiceName ) )
152 0 : return true;
153 : else
154 : {
155 0 : uno::Sequence< OUString > aSNL( getSupportedServiceNames() );
156 0 : const OUString* pArray = aSNL.getConstArray();
157 :
158 0 : for( int i = 0; i < aSNL.getLength(); i++ )
159 0 : if( pArray[i] == rServiceName )
160 0 : return true;
161 :
162 0 : return false;
163 : }
164 : }
165 :
166 : // ------------------------------------------------------------------------------
167 :
168 0 : uno::Sequence< OUString > SAL_CALL Graphic::getSupportedServiceNames()
169 : throw( uno::RuntimeException )
170 : {
171 0 : uno::Sequence< OUString > aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() );
172 0 : uno::Sequence< OUString > aNew( getSupportedServiceNames_Static() );
173 0 : sal_Int32 nOldCount = aRet.getLength();
174 :
175 0 : aRet.realloc( nOldCount + aNew.getLength() );
176 :
177 0 : for( sal_Int32 i = 0; i < aNew.getLength(); ++i )
178 0 : aRet[ nOldCount++ ] = aNew[ i ];
179 :
180 0 : return aRet;
181 : }
182 :
183 : // ------------------------------------------------------------------------------
184 :
185 0 : uno::Sequence< uno::Type > SAL_CALL Graphic::getTypes()
186 : throw(uno::RuntimeException)
187 : {
188 0 : uno::Sequence< uno::Type > aRet( ::unographic::GraphicDescriptor::getTypes() );
189 0 : sal_Int32 nOldCount = aRet.getLength();
190 :
191 0 : aRet.realloc( nOldCount + 2 );
192 0 : aRet[ nOldCount ] = ::getCppuType((const uno::Reference< graphic::XGraphic>*)0);
193 0 : aRet[ nOldCount+1 ] = ::getCppuType((const uno::Reference< awt::XBitmap>*)0);
194 :
195 0 : return aRet;
196 : }
197 :
198 : // ------------------------------------------------------------------------------
199 :
200 86214 : uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId()
201 : throw(uno::RuntimeException)
202 : {
203 86214 : return getImplementationId_Static();
204 : }
205 :
206 : // ------------------------------------------------------------------------------
207 :
208 0 : ::sal_Int8 SAL_CALL Graphic::getType()
209 : throw (uno::RuntimeException)
210 : {
211 0 : ::sal_Int8 cRet = graphic::GraphicType::EMPTY;
212 :
213 0 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
214 0 : cRet = ( ( mpGraphic->GetType() == GRAPHIC_BITMAP ) ? graphic::GraphicType::PIXEL : graphic::GraphicType::VECTOR );
215 :
216 0 : return cRet;
217 : }
218 :
219 : //----------------------------------------------------------------------
220 : // XBitmap
221 : //----------------------------------------------------------------------
222 :
223 134 : awt::Size SAL_CALL Graphic::getSize( ) throw (uno::RuntimeException)
224 : {
225 134 : SolarMutexGuard aGuard;
226 :
227 134 : ::Size aVclSize;
228 134 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
229 134 : aVclSize = mpGraphic->GetSizePixel();
230 :
231 134 : return awt::Size( aVclSize.Width(), aVclSize.Height() );
232 : }
233 :
234 : //----------------------------------------------------------------------
235 :
236 0 : uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getDIB( ) throw (uno::RuntimeException)
237 : {
238 0 : SolarMutexGuard aGuard;
239 :
240 0 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
241 : {
242 0 : SvMemoryStream aMem;
243 :
244 0 : WriteDIB(mpGraphic->GetBitmapEx().GetBitmap(), aMem, false, true);
245 0 : return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() );
246 : }
247 : else
248 : {
249 0 : return uno::Sequence<sal_Int8>();
250 0 : }
251 : }
252 :
253 : //----------------------------------------------------------------------
254 :
255 0 : uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getMaskDIB( ) throw (uno::RuntimeException)
256 : {
257 0 : SolarMutexGuard aGuard;
258 :
259 0 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
260 : {
261 0 : SvMemoryStream aMem;
262 :
263 0 : WriteDIB(mpGraphic->GetBitmapEx().GetMask(), aMem, false, true);
264 0 : return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() );
265 : }
266 : else
267 : {
268 0 : return uno::Sequence<sal_Int8>();
269 0 : }
270 : }
271 :
272 : //----------------------------------------------------------------------
273 0 : const ::Graphic* Graphic::getImplementation( const uno::Reference< uno::XInterface >& rxIFace )
274 : throw()
275 : {
276 0 : uno::Reference< lang::XUnoTunnel > xTunnel( rxIFace, uno::UNO_QUERY );
277 0 : return( xTunnel.is() ? reinterpret_cast< ::Graphic* >( xTunnel->getSomething( getImplementationId_Static() ) ) : NULL );
278 : }
279 :
280 : //----------------------------------------------------------------------
281 43107 : sal_Int64 SAL_CALL Graphic::getSomething( const uno::Sequence< sal_Int8 >& rId )
282 : throw( uno::RuntimeException )
283 : {
284 172428 : return( ( rId.getLength() == 16 && 0 == memcmp( getImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) ?
285 : reinterpret_cast< sal_Int64 >( mpGraphic ) :
286 172428 : 0 );
287 : }
288 :
289 465 : }
290 :
291 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|