Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <osl/mutex.hxx>
31 : : #include <vcl/svapp.hxx>
32 : : #include <com/sun/star/graphic/GraphicType.hpp>
33 : : #include <com/sun/star/graphic/XGraphicTransformer.hpp>
34 : : #include <vcl/graph.hxx>
35 : : #include "graphic.hxx"
36 : : #include <comphelper/servicehelper.hxx>
37 : :
38 : : using namespace com::sun::star;
39 : :
40 : : namespace unographic {
41 : :
42 : : // -------------------
43 : : // - GraphicProvider -
44 : : // -------------------
45 : :
46 : 74707 : Graphic::Graphic() :
47 [ + - ][ + - ]: 74707 : mpGraphic( NULL )
48 : : {
49 : 74707 : }
50 : :
51 : : // ------------------------------------------------------------------------------
52 : :
53 : 149414 : Graphic::~Graphic()
54 [ + - ]: 74707 : throw()
55 : : {
56 [ + - ][ + - ]: 74707 : delete mpGraphic;
57 [ - + ]: 149414 : }
58 : :
59 : : // ------------------------------------------------------------------------------
60 : :
61 : 74707 : void Graphic::init( const ::Graphic& rGraphic )
62 : : throw()
63 : : {
64 [ - + ]: 74707 : delete mpGraphic;
65 [ + - ]: 74707 : mpGraphic = new ::Graphic( rGraphic );
66 : 74707 : ::unographic::GraphicDescriptor::init( *mpGraphic );
67 : 74707 : }
68 : :
69 : : // ------------------------------------------------------------------------------
70 : :
71 : 75073 : uno::Any SAL_CALL Graphic::queryAggregation( const uno::Type& rType )
72 : : throw( uno::RuntimeException )
73 : : {
74 : 75073 : uno::Any aAny;
75 [ + + ][ + - ]: 75073 : if( rType == ::getCppuType((const uno::Reference< graphic::XGraphic >*)0) )
76 [ + - ][ + - ]: 171 : aAny <<= uno::Reference< graphic::XGraphic >( this );
77 [ + - ][ + + ]: 74902 : else if( rType == ::getCppuType((const uno::Reference< awt::XBitmap >*)0) )
78 [ + - ][ + - ]: 390 : aAny <<= uno::Reference< awt::XBitmap >( this );
79 [ + - ][ + + ]: 74512 : else if( rType == ::getCppuType((const uno::Reference< lang::XUnoTunnel >*)0) )
80 [ + - ][ + - ]: 74466 : aAny <<= uno::Reference< lang::XUnoTunnel >(this);
81 : : else
82 [ + - ][ + - ]: 46 : aAny <<= ::unographic::GraphicDescriptor::queryAggregation( rType );
83 : :
84 : 75073 : return aAny ;
85 : : }
86 : :
87 : : // ------------------------------------------------------------------------------
88 : :
89 : 75073 : uno::Any SAL_CALL Graphic::queryInterface( const uno::Type & rType )
90 : : throw( uno::RuntimeException )
91 : : {
92 : 75073 : ::com::sun::star::uno::Any aReturn = ::unographic::GraphicDescriptor::queryInterface( rType );
93 [ - + ]: 75073 : if ( !aReturn.hasValue() )
94 [ # # ]: 0 : aReturn = ::cppu::queryInterface ( rType, static_cast< graphic::XGraphicTransformer*>( this ) );
95 : 75073 : return aReturn;
96 : : }
97 : :
98 : : // ------------------------------------------------------------------------------
99 : :
100 : 453133 : void SAL_CALL Graphic::acquire()
101 : : throw()
102 : : {
103 : 453133 : ::unographic::GraphicDescriptor::acquire();
104 : 453133 : }
105 : :
106 : : // ------------------------------------------------------------------------------
107 : :
108 : 453133 : void SAL_CALL Graphic::release() throw()
109 : : {
110 : 453133 : ::unographic::GraphicDescriptor::release();
111 : 453133 : }
112 : :
113 : : // ------------------------------------------------------------------------------
114 : :
115 : 0 : ::rtl::OUString Graphic::getImplementationName_Static()
116 : : throw()
117 : : {
118 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.Graphic" ) );
119 : : }
120 : :
121 : : // ------------------------------------------------------------------------------
122 : :
123 : 0 : uno::Sequence< ::rtl::OUString > Graphic::getSupportedServiceNames_Static()
124 : : throw()
125 : : {
126 : 0 : uno::Sequence< ::rtl::OUString > aSeq( 1 );
127 : :
128 [ # # ][ # # ]: 0 : aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.Graphic" ) );
129 : :
130 : 0 : return aSeq;
131 : : }
132 : :
133 : : // ------------------------------------------------------------------------------
134 : :
135 : 0 : ::rtl::OUString SAL_CALL Graphic::getImplementationName()
136 : : throw( uno::RuntimeException )
137 : : {
138 : 0 : return getImplementationName_Static();
139 : : }
140 : :
141 : : // ------------------------------------------------------------------------------
142 : :
143 : 0 : sal_Bool SAL_CALL Graphic::supportsService( const ::rtl::OUString& rServiceName )
144 : : throw( uno::RuntimeException )
145 : : {
146 [ # # ]: 0 : if( ::unographic::GraphicDescriptor::supportsService( rServiceName ) )
147 : 0 : return true;
148 : : else
149 : : {
150 [ # # ]: 0 : uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() );
151 : 0 : const ::rtl::OUString* pArray = aSNL.getConstArray();
152 : :
153 [ # # ]: 0 : for( int i = 0; i < aSNL.getLength(); i++ )
154 [ # # ]: 0 : if( pArray[i] == rServiceName )
155 : 0 : return true;
156 : :
157 [ # # ]: 0 : return false;
158 : : }
159 : : }
160 : :
161 : : // ------------------------------------------------------------------------------
162 : :
163 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL Graphic::getSupportedServiceNames()
164 : : throw( uno::RuntimeException )
165 : : {
166 [ # # ]: 0 : uno::Sequence< ::rtl::OUString > aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() );
167 : 0 : uno::Sequence< ::rtl::OUString > aNew( getSupportedServiceNames_Static() );
168 : 0 : sal_Int32 nOldCount = aRet.getLength();
169 : :
170 [ # # ]: 0 : aRet.realloc( nOldCount + aNew.getLength() );
171 : :
172 [ # # ]: 0 : for( sal_Int32 i = 0; i < aNew.getLength(); ++i )
173 [ # # ][ # # ]: 0 : aRet[ nOldCount++ ] = aNew[ i ];
174 : :
175 [ # # ]: 0 : return aRet;
176 : : }
177 : :
178 : : // ------------------------------------------------------------------------------
179 : :
180 : 0 : uno::Sequence< uno::Type > SAL_CALL Graphic::getTypes()
181 : : throw(uno::RuntimeException)
182 : : {
183 : 0 : uno::Sequence< uno::Type > aRet( ::unographic::GraphicDescriptor::getTypes() );
184 : 0 : sal_Int32 nOldCount = aRet.getLength();
185 : :
186 [ # # ]: 0 : aRet.realloc( nOldCount + 2 );
187 [ # # ][ # # ]: 0 : aRet[ nOldCount ] = ::getCppuType((const uno::Reference< graphic::XGraphic>*)0);
188 [ # # ][ # # ]: 0 : aRet[ nOldCount+1 ] = ::getCppuType((const uno::Reference< awt::XBitmap>*)0);
189 : :
190 : 0 : return aRet;
191 : : }
192 : :
193 : : // ------------------------------------------------------------------------------
194 : :
195 : 0 : uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId()
196 : : throw(uno::RuntimeException)
197 : : {
198 : 0 : return uno::Sequence< sal_Int8 >();
199 : : }
200 : :
201 : : // ------------------------------------------------------------------------------
202 : :
203 : 0 : ::sal_Int8 SAL_CALL Graphic::getType()
204 : : throw (uno::RuntimeException)
205 : : {
206 : 0 : ::sal_Int8 cRet = graphic::GraphicType::EMPTY;
207 : :
208 [ # # ][ # # ]: 0 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
[ # # ]
209 [ # # ]: 0 : cRet = ( ( mpGraphic->GetType() == GRAPHIC_BITMAP ) ? graphic::GraphicType::PIXEL : graphic::GraphicType::VECTOR );
210 : :
211 : 0 : return cRet;
212 : : }
213 : :
214 : : //----------------------------------------------------------------------
215 : : // XBitmap
216 : : //----------------------------------------------------------------------
217 : :
218 : 222 : awt::Size SAL_CALL Graphic::getSize( ) throw (uno::RuntimeException)
219 : : {
220 [ + - ]: 222 : SolarMutexGuard aGuard;
221 : :
222 : 222 : ::Size aVclSize;
223 [ + - ][ + - ]: 222 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
[ + - ][ + - ]
224 [ + - ]: 222 : aVclSize = mpGraphic->GetSizePixel();
225 : :
226 [ + - ]: 222 : return awt::Size( aVclSize.Width(), aVclSize.Height() );
227 : : }
228 : :
229 : : //----------------------------------------------------------------------
230 : :
231 : 0 : uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getDIB( ) throw (uno::RuntimeException)
232 : : {
233 [ # # ]: 0 : SolarMutexGuard aGuard;
234 : :
235 [ # # ][ # # ]: 0 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
[ # # ][ # # ]
236 : : {
237 [ # # ]: 0 : SvMemoryStream aMem;
238 [ # # ][ # # ]: 0 : aMem << mpGraphic->GetBitmapEx().GetBitmap();
[ # # ][ # # ]
[ # # ]
239 [ # # ][ # # ]: 0 : return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() );
[ # # ]
240 : : }
241 : : else
242 : : {
243 [ # # ]: 0 : return uno::Sequence<sal_Int8>();
244 [ # # ]: 0 : }
245 : : }
246 : :
247 : : //----------------------------------------------------------------------
248 : :
249 : 0 : uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getMaskDIB( ) throw (uno::RuntimeException)
250 : : {
251 [ # # ]: 0 : SolarMutexGuard aGuard;
252 : :
253 [ # # ][ # # ]: 0 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
[ # # ][ # # ]
254 : : {
255 [ # # ]: 0 : SvMemoryStream aMem;
256 [ # # ][ # # ]: 0 : aMem << mpGraphic->GetBitmapEx().GetMask();
[ # # ][ # # ]
[ # # ]
257 [ # # ][ # # ]: 0 : return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() );
[ # # ]
258 : : }
259 : : else
260 : : {
261 [ # # ]: 0 : return uno::Sequence<sal_Int8>();
262 [ # # ]: 0 : }
263 : : }
264 : :
265 : : //----------------------------------------------------------------------
266 : 0 : const ::Graphic* Graphic::getImplementation( const uno::Reference< uno::XInterface >& rxIFace )
267 : : throw()
268 : : {
269 [ # # ]: 0 : uno::Reference< lang::XUnoTunnel > xTunnel( rxIFace, uno::UNO_QUERY );
270 [ # # ][ # # ]: 0 : return( xTunnel.is() ? reinterpret_cast< ::Graphic* >( xTunnel->getSomething( ::Graphic::getUnoTunnelId() ) ) : NULL );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
271 : : }
272 : :
273 : : //----------------------------------------------------------------------
274 : 74466 : sal_Int64 SAL_CALL Graphic::getSomething( const uno::Sequence< sal_Int8 >& rId )
275 : : throw( uno::RuntimeException )
276 : : {
277 [ + - ][ + - ]: 223398 : return( ( rId.getLength() == 16 && 0 == rtl_compareMemory( ::Graphic::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) ?
[ + - ][ # # ]
278 : : reinterpret_cast< sal_Int64 >( mpGraphic ) :
279 [ + - ][ + - ]: 223398 : 0 );
280 : : }
281 : :
282 : : }
283 : :
284 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|