LibreOffice Module vcl (master)  1
UnoGraphic.cxx
Go to the documentation of this file.
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 <graphic/UnoGraphic.hxx>
21 
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>
31 
32 using namespace com::sun::star;
33 
34 namespace unographic {
35 
37  maGraphic()
38 {
39 }
40 
42 {
43 }
44 
45 void Graphic::init(const ::Graphic& rGraphic)
46 {
47  maGraphic = rGraphic;
49 }
50 
52 {
53  uno::Any aAny;
55  aAny <<= uno::Reference< graphic::XGraphic >( this );
56  else if( rType == cppu::UnoType<awt::XBitmap>::get())
57  aAny <<= uno::Reference< awt::XBitmap >( this );
58  else if( rType == cppu::UnoType<lang::XUnoTunnel>::get())
59  aAny <<= uno::Reference< lang::XUnoTunnel >(this);
60  else
62 
63  return aAny;
64 }
65 
66 uno::Any SAL_CALL Graphic::queryInterface( const uno::Type & rType )
67 {
68  css::uno::Any aReturn = ::unographic::GraphicDescriptor::queryInterface( rType );
69  if ( !aReturn.hasValue() )
70  aReturn = ::cppu::queryInterface ( rType, static_cast< graphic::XGraphicTransformer*>( this ) );
71  return aReturn;
72 }
73 
74 void SAL_CALL Graphic::acquire()
75  noexcept
76 {
78 }
79 
80 void SAL_CALL Graphic::release() noexcept
81 {
83 }
84 
85 OUString SAL_CALL Graphic::getImplementationName()
86 {
87  return "com.sun.star.comp.graphic.Graphic";
88 }
89 
90 sal_Bool SAL_CALL Graphic::supportsService( const OUString& rServiceName )
91 {
92  return cppu::supportsService( this, rServiceName );
93 }
94 
95 uno::Sequence< OUString > SAL_CALL Graphic::getSupportedServiceNames()
96 {
97  uno::Sequence< OUString > aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() );
98  uno::Sequence< OUString > aNew { "com.sun.star.graphic.Graphic" };
99  sal_Int32 nOldCount = aRet.getLength();
100 
101  aRet.realloc( nOldCount + aNew.getLength() );
102 
103  std::copy(aNew.begin(), aNew.end(), std::next(aRet.begin(), nOldCount));
104 
105  return aRet;
106 }
107 
108 uno::Sequence< uno::Type > SAL_CALL Graphic::getTypes()
109 {
110  return cppu::OTypeCollection(
114  ).getTypes();
115 }
116 
117 uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId()
118 {
119  return css::uno::Sequence<sal_Int8>();
120 }
121 
123 {
124  sal_Int8 cRet = graphic::GraphicType::EMPTY;
125 
126  if (!maGraphic.IsNone())
127  {
128  cRet = (maGraphic.GetType() == ::GraphicType::Bitmap) ? graphic::GraphicType::PIXEL
129  : graphic::GraphicType::VECTOR;
130  }
131 
132  return cRet;
133 }
134 
135 // XBitmap
136 
137 awt::Size SAL_CALL Graphic::getSize()
138 {
139  SolarMutexGuard aGuard;
140 
141  Size aVclSize;
142  if (!maGraphic.IsNone())
143  {
144  aVclSize = maGraphic.GetSizePixel();
145  }
146  return awt::Size(aVclSize.Width(), aVclSize.Height());
147 }
148 
149 uno::Sequence<sal_Int8> SAL_CALL Graphic::getDIB()
150 {
151  SolarMutexGuard aGuard;
152 
153  if (!maGraphic.IsNone())
154  {
155  SvMemoryStream aMemoryStream;
156 
157  WriteDIB(maGraphic.GetBitmapEx().GetBitmap(), aMemoryStream, false, true);
158  return css::uno::Sequence<sal_Int8>(static_cast<sal_Int8 const *>(aMemoryStream.GetData()), aMemoryStream.Tell());
159  }
160  else
161  {
162  return uno::Sequence<sal_Int8>();
163  }
164 }
165 
166 uno::Sequence<sal_Int8> SAL_CALL Graphic::getMaskDIB()
167 {
168  SolarMutexGuard aGuard;
169 
170  if (!maGraphic.IsNone())
171  {
172  SvMemoryStream aMemoryStream;
173 
174  WriteDIB(maGraphic.GetBitmapEx().GetAlpha(), aMemoryStream, false, true);
175  return css::uno::Sequence<sal_Int8>( static_cast<sal_Int8 const *>(aMemoryStream.GetData()), aMemoryStream.Tell() );
176  }
177  else
178  {
179  return uno::Sequence<sal_Int8>();
180  }
181 }
182 
183 sal_Int64 SAL_CALL Graphic::getSomething( const uno::Sequence< sal_Int8 >& rId )
184 {
185  return( ( isUnoTunnelId<::Graphic>(rId) ) ?
186  reinterpret_cast<sal_Int64>(&maGraphic) : 0 );
187 }
188 
189 }
190 
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual OUString SAL_CALL getImplementationName() override
Definition: UnoGraphic.cxx:85
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: UnoGraphic.cxx:90
virtual void SAL_CALL acquire() noexcept override
Definition: UnoGraphic.cxx:74
signed char sal_Int8
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &rType) override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual void SAL_CALL release() noexcept override
constexpr tools::Long Width() const
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: UnoGraphic.cxx:95
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual css::uno::Sequence< ::sal_Int8 > SAL_CALL getDIB() override
Definition: UnoGraphic.cxx:149
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &rId) override
Definition: UnoGraphic.cxx:183
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: UnoGraphic.cxx:108
unsigned char sal_Bool
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Definition: UnoGraphic.cxx:117
virtual css::uno::Sequence< ::sal_Int8 > SAL_CALL getMaskDIB() override
Definition: UnoGraphic.cxx:166
virtual void SAL_CALL acquire() noexcept override
Graphic()
Definition: graph.cxx:162
virtual void SAL_CALL release() noexcept override
Definition: UnoGraphic.cxx:80
virtual ~Graphic() noexcept override
Definition: UnoGraphic.cxx:41
constexpr tools::Long Height() const
void init(const ::Graphic &rGraphic)
virtual css::awt::Size SAL_CALL getSize() override
Definition: UnoGraphic.cxx:137
void init(const ::Graphic &rGraphic)
Definition: UnoGraphic.cxx:45
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Definition: UnoGraphic.cxx:66
sal_uInt64 Tell() const
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &rType) override
Definition: UnoGraphic.cxx:51
bool WriteDIB(const Bitmap &rSource, SvStream &rOStm, bool bCompressed, bool bFileHeader)
Definition: dibtools.cxx:1823
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
const Graphic maGraphic
virtual ::sal_Int8 SAL_CALL getType() override
Definition: UnoGraphic.cxx:122
const void * GetData()
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override