1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <graphic/UnoGraphic.hxx>
22 #include <tools/stream.hxx>
23 #include <vcl/svapp.hxx>
24 #include <com/sun/star/graphic/GraphicType.hpp>
25 #include <com/sun/star/graphic/XGraphicTransformer.hpp>
26 #include <vcl/dibtools.hxx>
27 #include <comphelper/servicehelper.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <cppuhelper/queryinterface.hxx>
30 #include <cppuhelper/typeprovider.hxx>
32 using namespace com::sun::star
;
34 namespace unographic
{
41 Graphic::~Graphic() throw()
45 void Graphic::init( const ::Graphic
& rGraphic
)
49 unographic::GraphicDescriptor::init(maGraphic
);
52 uno::Any SAL_CALL
Graphic::queryAggregation( const uno::Type
& rType
)
55 if( rType
== cppu::UnoType
<graphic::XGraphic
>::get())
56 aAny
<<= uno::Reference
< graphic::XGraphic
>( this );
57 else if( rType
== cppu::UnoType
<awt::XBitmap
>::get())
58 aAny
<<= uno::Reference
< awt::XBitmap
>( this );
59 else if( rType
== cppu::UnoType
<lang::XUnoTunnel
>::get())
60 aAny
<<= uno::Reference
< lang::XUnoTunnel
>(this);
62 aAny
= ::unographic::GraphicDescriptor::queryAggregation( rType
);
67 uno::Any SAL_CALL
Graphic::queryInterface( const uno::Type
& rType
)
69 css::uno::Any aReturn
= ::unographic::GraphicDescriptor::queryInterface( rType
);
70 if ( !aReturn
.hasValue() )
71 aReturn
= ::cppu::queryInterface ( rType
, static_cast< graphic::XGraphicTransformer
*>( this ) );
75 void SAL_CALL
Graphic::acquire()
78 unographic::GraphicDescriptor::acquire();
81 void SAL_CALL
Graphic::release() throw()
83 unographic::GraphicDescriptor::release();
86 OUString SAL_CALL
Graphic::getImplementationName()
88 return "com.sun.star.comp.graphic.Graphic";
91 sal_Bool SAL_CALL
Graphic::supportsService( const OUString
& rServiceName
)
93 return cppu::supportsService( this, rServiceName
);
96 uno::Sequence
< OUString
> SAL_CALL
Graphic::getSupportedServiceNames()
98 uno::Sequence
< OUString
> aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() );
99 uno::Sequence
< OUString
> aNew
{ "com.sun.star.graphic.Graphic" };
100 sal_Int32 nOldCount
= aRet
.getLength();
102 aRet
.realloc( nOldCount
+ aNew
.getLength() );
104 std::copy(aNew
.begin(), aNew
.end(), std::next(aRet
.begin(), nOldCount
));
109 uno::Sequence
< uno::Type
> SAL_CALL
Graphic::getTypes()
111 return cppu::OTypeCollection(
112 cppu::UnoType
<graphic::XGraphic
>::get(),
113 cppu::UnoType
<awt::XBitmap
>::get(),
114 ::unographic::GraphicDescriptor::getTypes()
118 uno::Sequence
< sal_Int8
> SAL_CALL
Graphic::getImplementationId()
120 return css::uno::Sequence
<sal_Int8
>();
123 sal_Int8 SAL_CALL
Graphic::getType()
125 sal_Int8 cRet
= graphic::GraphicType::EMPTY
;
127 if (!maGraphic
.IsNone())
129 cRet
= (maGraphic
.GetType() == ::GraphicType::Bitmap
) ? graphic::GraphicType::PIXEL
130 : graphic::GraphicType::VECTOR
;
138 awt::Size SAL_CALL
Graphic::getSize()
140 SolarMutexGuard aGuard
;
143 if (!maGraphic
.IsNone())
145 aVclSize
= maGraphic
.GetSizePixel();
147 return awt::Size(aVclSize
.Width(), aVclSize
.Height());
150 uno::Sequence
<sal_Int8
> SAL_CALL
Graphic::getDIB()
152 SolarMutexGuard aGuard
;
154 if (!maGraphic
.IsNone())
156 SvMemoryStream aMemoryStream
;
158 WriteDIB(maGraphic
.GetBitmapEx().GetBitmap(), aMemoryStream
, false, true);
159 return css::uno::Sequence
<sal_Int8
>(static_cast<sal_Int8
const *>(aMemoryStream
.GetData()), aMemoryStream
.Tell());
163 return uno::Sequence
<sal_Int8
>();
167 uno::Sequence
<sal_Int8
> SAL_CALL
Graphic::getMaskDIB()
169 SolarMutexGuard aGuard
;
171 if (!maGraphic
.IsNone())
173 SvMemoryStream aMemoryStream
;
175 WriteDIB(maGraphic
.GetBitmapEx().GetMask(), aMemoryStream
, false, true);
176 return css::uno::Sequence
<sal_Int8
>( static_cast<sal_Int8
const *>(aMemoryStream
.GetData()), aMemoryStream
.Tell() );
180 return uno::Sequence
<sal_Int8
>();
184 sal_Int64 SAL_CALL
Graphic::getSomething( const uno::Sequence
< sal_Int8
>& rId
)
186 return( ( isUnoTunnelId
<::Graphic
>(rId
) ) ?
187 reinterpret_cast<sal_Int64
>(&maGraphic
) : 0 );
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */