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 <cppuhelper/supportsservice.hxx>
29 : #include <cppuhelper/queryinterface.hxx>
30 : #include <string.h>
31 :
32 : using namespace com::sun::star;
33 :
34 : namespace unographic {
35 :
36 80753 : Graphic::Graphic() :
37 80753 : mpGraphic( NULL )
38 : {
39 80753 : }
40 :
41 :
42 :
43 161504 : Graphic::~Graphic()
44 161504 : throw()
45 : {
46 80752 : delete mpGraphic;
47 161504 : }
48 :
49 :
50 :
51 80753 : void Graphic::init( const ::Graphic& rGraphic )
52 : throw()
53 : {
54 80753 : delete mpGraphic;
55 80753 : mpGraphic = new ::Graphic( rGraphic );
56 80753 : ::unographic::GraphicDescriptor::init( *mpGraphic );
57 80753 : }
58 :
59 :
60 :
61 86224 : uno::Any SAL_CALL Graphic::queryAggregation( const uno::Type& rType )
62 : throw( uno::RuntimeException, std::exception )
63 : {
64 86224 : uno::Any aAny;
65 86224 : if( rType == cppu::UnoType<graphic::XGraphic>::get())
66 4435 : aAny <<= uno::Reference< graphic::XGraphic >( this );
67 81789 : else if( rType == cppu::UnoType<awt::XBitmap>::get())
68 728 : aAny <<= uno::Reference< awt::XBitmap >( this );
69 81061 : else if( rType == cppu::UnoType<lang::XUnoTunnel>::get())
70 80495 : aAny <<= uno::Reference< lang::XUnoTunnel >(this);
71 : else
72 566 : aAny <<= ::unographic::GraphicDescriptor::queryAggregation( rType );
73 :
74 86224 : return aAny ;
75 : }
76 :
77 :
78 :
79 86224 : uno::Any SAL_CALL Graphic::queryInterface( const uno::Type & rType )
80 : throw( uno::RuntimeException, std::exception )
81 : {
82 86224 : ::com::sun::star::uno::Any aReturn = ::unographic::GraphicDescriptor::queryInterface( rType );
83 86224 : if ( !aReturn.hasValue() )
84 4 : aReturn = ::cppu::queryInterface ( rType, static_cast< graphic::XGraphicTransformer*>( this ) );
85 86224 : return aReturn;
86 : }
87 :
88 :
89 :
90 527580 : void SAL_CALL Graphic::acquire()
91 : throw()
92 : {
93 527580 : ::unographic::GraphicDescriptor::acquire();
94 527580 : }
95 :
96 :
97 :
98 527579 : void SAL_CALL Graphic::release() throw()
99 : {
100 527579 : ::unographic::GraphicDescriptor::release();
101 527579 : }
102 :
103 0 : OUString Graphic::getImplementationName_Static()
104 : throw()
105 : {
106 0 : return OUString( "com.sun.star.comp.graphic.Graphic" );
107 : }
108 :
109 :
110 :
111 0 : uno::Sequence< OUString > Graphic::getSupportedServiceNames_Static()
112 : throw()
113 : {
114 0 : uno::Sequence< OUString > aSeq( 1 );
115 :
116 0 : aSeq.getArray()[ 0 ] = "com.sun.star.graphic.Graphic";
117 :
118 0 : return aSeq;
119 : }
120 :
121 0 : OUString SAL_CALL Graphic::getImplementationName()
122 : throw( uno::RuntimeException, std::exception )
123 : {
124 0 : return getImplementationName_Static();
125 : }
126 :
127 0 : sal_Bool SAL_CALL Graphic::supportsService( const OUString& rServiceName )
128 : throw( uno::RuntimeException, std::exception )
129 : {
130 0 : return cppu::supportsService( this, rServiceName );
131 : }
132 :
133 0 : uno::Sequence< OUString > SAL_CALL Graphic::getSupportedServiceNames()
134 : throw( uno::RuntimeException, std::exception )
135 : {
136 0 : uno::Sequence< OUString > aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() );
137 0 : uno::Sequence< OUString > aNew( getSupportedServiceNames_Static() );
138 0 : sal_Int32 nOldCount = aRet.getLength();
139 :
140 0 : aRet.realloc( nOldCount + aNew.getLength() );
141 :
142 0 : for( sal_Int32 i = 0; i < aNew.getLength(); ++i )
143 0 : aRet[ nOldCount++ ] = aNew[ i ];
144 :
145 0 : return aRet;
146 : }
147 :
148 0 : uno::Sequence< uno::Type > SAL_CALL Graphic::getTypes()
149 : throw(uno::RuntimeException, std::exception)
150 : {
151 0 : uno::Sequence< uno::Type > aRet( ::unographic::GraphicDescriptor::getTypes() );
152 0 : sal_Int32 nOldCount = aRet.getLength();
153 :
154 0 : aRet.realloc( nOldCount + 2 );
155 0 : aRet[ nOldCount ] = cppu::UnoType<graphic::XGraphic>::get();
156 0 : aRet[ nOldCount+1 ] = cppu::UnoType<awt::XBitmap>::get();
157 :
158 0 : return aRet;
159 : }
160 :
161 :
162 :
163 0 : uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId()
164 : throw(uno::RuntimeException, std::exception)
165 : {
166 0 : return css::uno::Sequence<sal_Int8>();
167 : }
168 :
169 :
170 :
171 1 : ::sal_Int8 SAL_CALL Graphic::getType()
172 : throw (uno::RuntimeException, std::exception)
173 : {
174 1 : ::sal_Int8 cRet = graphic::GraphicType::EMPTY;
175 :
176 1 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
177 1 : cRet = ( ( mpGraphic->GetType() == GRAPHIC_BITMAP ) ? graphic::GraphicType::PIXEL : graphic::GraphicType::VECTOR );
178 :
179 1 : return cRet;
180 : }
181 :
182 :
183 : // XBitmap
184 :
185 :
186 349 : awt::Size SAL_CALL Graphic::getSize( ) throw (uno::RuntimeException, std::exception)
187 : {
188 349 : SolarMutexGuard aGuard;
189 :
190 349 : ::Size aVclSize;
191 349 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
192 349 : aVclSize = mpGraphic->GetSizePixel();
193 :
194 349 : return awt::Size( aVclSize.Width(), aVclSize.Height() );
195 : }
196 :
197 :
198 :
199 1 : uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getDIB( ) throw (uno::RuntimeException, std::exception)
200 : {
201 1 : SolarMutexGuard aGuard;
202 :
203 1 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
204 : {
205 1 : SvMemoryStream aMem;
206 :
207 1 : WriteDIB(mpGraphic->GetBitmapEx().GetBitmap(), aMem, false, true);
208 1 : return ::com::sun::star::uno::Sequence<sal_Int8>( static_cast<sal_Int8 const *>(aMem.GetData()), aMem.Tell() );
209 : }
210 : else
211 : {
212 0 : return uno::Sequence<sal_Int8>();
213 1 : }
214 : }
215 :
216 :
217 :
218 0 : uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getMaskDIB( ) throw (uno::RuntimeException, std::exception)
219 : {
220 0 : SolarMutexGuard aGuard;
221 :
222 0 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
223 : {
224 0 : SvMemoryStream aMem;
225 :
226 0 : WriteDIB(mpGraphic->GetBitmapEx().GetMask(), aMem, false, true);
227 0 : return ::com::sun::star::uno::Sequence<sal_Int8>( static_cast<sal_Int8 const *>(aMem.GetData()), aMem.Tell() );
228 : }
229 : else
230 : {
231 0 : return uno::Sequence<sal_Int8>();
232 0 : }
233 : }
234 :
235 :
236 5 : const ::Graphic* Graphic::getImplementation( const uno::Reference< uno::XInterface >& rxIFace )
237 : throw()
238 : {
239 5 : uno::Reference< lang::XUnoTunnel > xTunnel( rxIFace, uno::UNO_QUERY );
240 5 : return( xTunnel.is() ? reinterpret_cast< ::Graphic* >( xTunnel->getSomething( ::Graphic::getUnoTunnelId() ) ) : NULL );
241 : }
242 :
243 :
244 80495 : sal_Int64 SAL_CALL Graphic::getSomething( const uno::Sequence< sal_Int8 >& rId )
245 : throw( uno::RuntimeException, std::exception )
246 : {
247 321980 : return( ( rId.getLength() == 16 && 0 == memcmp( ::Graphic::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) ?
248 : reinterpret_cast< sal_Int64 >( mpGraphic ) :
249 321980 : 0 );
250 : }
251 :
252 : }
253 :
254 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|