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  throw()
47 {
48  maGraphic = rGraphic;
50 }
51 
53 {
54  uno::Any aAny;
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);
61  else
63 
64  return aAny;
65 }
66 
67 uno::Any SAL_CALL Graphic::queryInterface( const uno::Type & rType )
68 {
69  css::uno::Any aReturn = ::unographic::GraphicDescriptor::queryInterface( rType );
70  if ( !aReturn.hasValue() )
71  aReturn = ::cppu::queryInterface ( rType, static_cast< graphic::XGraphicTransformer*>( this ) );
72  return aReturn;
73 }
74 
75 void SAL_CALL Graphic::acquire()
76  throw()
77 {
79 }
80 
81 void SAL_CALL Graphic::release() throw()
82 {
84 }
85 
86 OUString SAL_CALL Graphic::getImplementationName()
87 {
88  return "com.sun.star.comp.graphic.Graphic";
89 }
90 
91 sal_Bool SAL_CALL Graphic::supportsService( const OUString& rServiceName )
92 {
93  return cppu::supportsService( this, rServiceName );
94 }
95 
96 uno::Sequence< OUString > SAL_CALL Graphic::getSupportedServiceNames()
97 {
98  uno::Sequence< OUString > aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() );
99  uno::Sequence< OUString > aNew { "com.sun.star.graphic.Graphic" };
100  sal_Int32 nOldCount = aRet.getLength();
101 
102  aRet.realloc( nOldCount + aNew.getLength() );
103 
104  std::copy(aNew.begin(), aNew.end(), std::next(aRet.begin(), nOldCount));
105 
106  return aRet;
107 }
108 
109 uno::Sequence< uno::Type > SAL_CALL Graphic::getTypes()
110 {
111  return cppu::OTypeCollection(
115  ).getTypes();
116 }
117 
118 uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId()
119 {
120  return css::uno::Sequence<sal_Int8>();
121 }
122 
124 {
125  sal_Int8 cRet = graphic::GraphicType::EMPTY;
126 
127  if (!maGraphic.IsNone())
128  {
129  cRet = (maGraphic.GetType() == ::GraphicType::Bitmap) ? graphic::GraphicType::PIXEL
130  : graphic::GraphicType::VECTOR;
131  }
132 
133  return cRet;
134 }
135 
136 // XBitmap
137 
138 awt::Size SAL_CALL Graphic::getSize()
139 {
140  SolarMutexGuard aGuard;
141 
142  Size aVclSize;
143  if (!maGraphic.IsNone())
144  {
145  aVclSize = maGraphic.GetSizePixel();
146  }
147  return awt::Size(aVclSize.Width(), aVclSize.Height());
148 }
149 
150 uno::Sequence<sal_Int8> SAL_CALL Graphic::getDIB()
151 {
152  SolarMutexGuard aGuard;
153 
154  if (!maGraphic.IsNone())
155  {
156  SvMemoryStream aMemoryStream;
157 
158  WriteDIB(maGraphic.GetBitmapEx().GetBitmap(), aMemoryStream, false, true);
159  return css::uno::Sequence<sal_Int8>(static_cast<sal_Int8 const *>(aMemoryStream.GetData()), aMemoryStream.Tell());
160  }
161  else
162  {
163  return uno::Sequence<sal_Int8>();
164  }
165 }
166 
167 uno::Sequence<sal_Int8> SAL_CALL Graphic::getMaskDIB()
168 {
169  SolarMutexGuard aGuard;
170 
171  if (!maGraphic.IsNone())
172  {
173  SvMemoryStream aMemoryStream;
174 
175  WriteDIB(maGraphic.GetBitmapEx().GetMask(), aMemoryStream, false, true);
176  return css::uno::Sequence<sal_Int8>( static_cast<sal_Int8 const *>(aMemoryStream.GetData()), aMemoryStream.Tell() );
177  }
178  else
179  {
180  return uno::Sequence<sal_Int8>();
181  }
182 }
183 
184 sal_Int64 SAL_CALL Graphic::getSomething( const uno::Sequence< sal_Int8 >& rId )
185 {
186  return( ( isUnoTunnelId<::Graphic>(rId) ) ?
187  reinterpret_cast<sal_Int64>(&maGraphic) : 0 );
188 }
189 
190 }
191 
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
virtual OUString SAL_CALL getImplementationName() override
Definition: UnoGraphic.cxx:86
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: UnoGraphic.cxx:91
virtual void SAL_CALL release() override
Definition: UnoGraphic.cxx:81
virtual void SAL_CALL release() override
long Height() const
signed char sal_Int8
virtual ~Graphic() override
Definition: UnoGraphic.cxx:41
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 css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: UnoGraphic.cxx:96
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:150
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &rId) override
Definition: UnoGraphic.cxx:184
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: UnoGraphic.cxx:109
virtual void SAL_CALL acquire() override
unsigned char sal_Bool
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Definition: UnoGraphic.cxx:118
virtual css::uno::Sequence< ::sal_Int8 > SAL_CALL getMaskDIB() override
Definition: UnoGraphic.cxx:167
Graphic()
Definition: graph.cxx:181
void init(const ::Graphic &rGraphic)
virtual css::awt::Size SAL_CALL getSize() override
Definition: UnoGraphic.cxx:138
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:67
sal_uInt64 Tell() const
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
virtual void SAL_CALL acquire() override
Definition: UnoGraphic.cxx:75
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &rType) override
Definition: UnoGraphic.cxx:52
bool WriteDIB(const Bitmap &rSource, SvStream &rOStm, bool bCompressed, bool bFileHeader)
Definition: dibtools.cxx:1854
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
virtual ::sal_Int8 SAL_CALL getType() override
Definition: UnoGraphic.cxx:123
const void * GetData()
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override