LibreOffice Module toolkit (master) 1
vclxdevice.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 <sal/config.h>
21
22#include <com/sun/star/util/MeasureUnit.hpp>
23#include <com/sun/star/lang/IllegalArgumentException.hpp>
24
27#include <awt/vclxbitmap.hxx>
29
30#include <vcl/svapp.hxx>
31#include <vcl/outdev.hxx>
32#include <vcl/virdev.hxx>
33#include <vcl/bitmapex.hxx>
34#include <vcl/metric.hxx>
35
36
38{
39}
40
42{
43 //TODO: why was this empty, and everything done in ~VCLXVirtualDevice?
46}
47
48// css::awt::XDevice,
49css::uno::Reference< css::awt::XGraphics > VCLXDevice::createGraphics( )
50{
51 SolarMutexGuard aGuard;
52
53 css::uno::Reference< css::awt::XGraphics > xRef;
54
55 if ( mpOutputDevice )
56 xRef = mpOutputDevice->CreateUnoGraphics();
57
58 return xRef;
59}
60
61css::uno::Reference< css::awt::XDevice > VCLXDevice::createDevice( sal_Int32 nWidth, sal_Int32 nHeight )
62{
63 SolarMutexGuard aGuard;
64
65 css::uno::Reference< css::awt::XDevice > xRef;
66 if ( GetOutputDevice() )
67 {
70 pVclVDev->SetOutputSizePixel( Size( nWidth, nHeight ) );
71 pVDev->SetVirtualDevice( pVclVDev );
72 xRef = pVDev;
73 }
74 return xRef;
75}
76
77css::awt::DeviceInfo VCLXDevice::getInfo()
78{
79 SolarMutexGuard aGuard;
80
81 css::awt::DeviceInfo aInfo;
82
84 aInfo = mpOutputDevice->GetDeviceInfo();
85
86 return aInfo;
87}
88
89css::uno::Sequence< css::awt::FontDescriptor > VCLXDevice::getFontDescriptors( )
90{
91 SolarMutexGuard aGuard;
92
93 css::uno::Sequence< css::awt::FontDescriptor> aFonts;
94 if( mpOutputDevice )
95 {
96 int nFonts = mpOutputDevice->GetFontFaceCollectionCount();
97 if ( nFonts )
98 {
99 aFonts = css::uno::Sequence< css::awt::FontDescriptor>( nFonts );
100 css::awt::FontDescriptor* pFonts = aFonts.getArray();
101 for ( int n = 0; n < nFonts; n++ )
102 pFonts[n] = VCLUnoHelper::CreateFontDescriptor( mpOutputDevice->GetFontMetricFromCollection( n ) );
103 }
104 }
105 return aFonts;
106}
107
108css::uno::Reference< css::awt::XFont > VCLXDevice::getFont( const css::awt::FontDescriptor& rDescriptor )
109{
110 SolarMutexGuard aGuard;
111
112 css::uno::Reference< css::awt::XFont > xRef;
113 if( mpOutputDevice )
114 {
116 pMetric->Init( *this, VCLUnoHelper::CreateFont( rDescriptor, mpOutputDevice->GetFont() ) );
117 xRef = pMetric;
118 }
119 return xRef;
120}
121
122css::uno::Reference< css::awt::XBitmap > VCLXDevice::createBitmap( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight )
123{
124 SolarMutexGuard aGuard;
125
126 css::uno::Reference< css::awt::XBitmap > xBmp;
127 if( mpOutputDevice )
128 {
129 BitmapEx aBmp = mpOutputDevice->GetBitmapEx( Point( nX, nY ), Size( nWidth, nHeight ) );
130
132 pBmp->SetBitmap( aBmp );
133 xBmp = pBmp;
134 }
135 return xBmp;
136}
137
138css::uno::Reference< css::awt::XDisplayBitmap > VCLXDevice::createDisplayBitmap( const css::uno::Reference< css::awt::XBitmap >& rxBitmap )
139{
140 SolarMutexGuard aGuard;
141
142 BitmapEx aBmp = VCLUnoHelper::GetBitmap( rxBitmap );
144 pBmp->SetBitmap( aBmp );
145 return pBmp;
146}
147
149{
150 SolarMutexGuard aGuard;
151
153}
154
155// Interface implementation of css::awt::XUnitConversion
156
157css::awt::Point SAL_CALL VCLXDevice::convertPointToLogic( const css::awt::Point& aPoint, ::sal_Int16 TargetUnit )
158{
159 SolarMutexGuard aGuard;
160 if (TargetUnit == css::util::MeasureUnit::PERCENT )
161 {
162 // percentage not allowed here
163 throw css::lang::IllegalArgumentException();
164 }
165
166 css::awt::Point aAWTPoint(0,0);
167 // X,Y
168
169 if( mpOutputDevice )
170 {
172 ::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint);
173 ::Point aDevPoint = mpOutputDevice->PixelToLogic(aVCLPoint, aMode );
174 aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint);
175 }
176
177 return aAWTPoint;
178}
179
180
181css::awt::Point SAL_CALL VCLXDevice::convertPointToPixel( const css::awt::Point& aPoint, ::sal_Int16 SourceUnit )
182{
183 SolarMutexGuard aGuard;
184 if (SourceUnit == css::util::MeasureUnit::PERCENT ||
185 SourceUnit == css::util::MeasureUnit::PIXEL )
186 {
187 // pixel or percentage not allowed here
188 throw css::lang::IllegalArgumentException();
189 }
190
191 css::awt::Point aAWTPoint(0,0);
192
193 if( mpOutputDevice )
194 {
196 ::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint);
197 ::Point aDevPoint = mpOutputDevice->LogicToPixel(aVCLPoint, aMode );
198 aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint);
199 }
200
201 return aAWTPoint;
202}
203
204css::awt::Size SAL_CALL VCLXDevice::convertSizeToLogic( const css::awt::Size& aSize, ::sal_Int16 TargetUnit )
205{
206 SolarMutexGuard aGuard;
207 if (TargetUnit == css::util::MeasureUnit::PERCENT)
208 {
209 // percentage not allowed here
210 throw css::lang::IllegalArgumentException();
211 }
212
213 css::awt::Size aAWTSize(0,0);
214 // Width, Height
215
216
217 if( mpOutputDevice )
218 {
220 ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize);
221 ::Size aDevSz = mpOutputDevice->PixelToLogic(aVCLSize, aMode );
222 aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz);
223 }
224
225 return aAWTSize;
226}
227
228css::awt::Size SAL_CALL VCLXDevice::convertSizeToPixel( const css::awt::Size& aSize, ::sal_Int16 SourceUnit )
229{
230 SolarMutexGuard aGuard;
231 if (SourceUnit == css::util::MeasureUnit::PERCENT ||
232 SourceUnit == css::util::MeasureUnit::PIXEL)
233 {
234 // pixel or percentage not allowed here
235 throw css::lang::IllegalArgumentException();
236 }
237
238 css::awt::Size aAWTSize(0,0);
239 // Width, Height
240 if( mpOutputDevice )
241 {
243 ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize);
244 ::Size aDevSz = mpOutputDevice->LogicToPixel(aVCLSize, aMode );
245 aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz);
246 }
247
248 return aAWTSize;
249}
250
251/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static css::awt::FontDescriptor CreateFontDescriptor(const vcl::Font &rFont)
convert Font to css::awt::FontDescriptor
static BitmapEx GetBitmap(const css::uno::Reference< css::awt::XBitmap > &rxBitmap)
static css::awt::Size ConvertToAWTSize(::Size const &_aSize)
static css::awt::Point ConvertToAWTPoint(::Point const &_aPoint)
static MapUnit ConvertToMapModeUnit(sal_Int16 _nMeasureUnit)
::Size ConvertToVCLSize(css::awt::Size const &_aSize)
::Point ConvertToVCLPoint(css::awt::Point const &_aPoint)
static vcl::Font CreateFont(const css::awt::FontDescriptor &rDescr, const vcl::Font &rInitFont)
css::uno::Reference< css::awt::XGraphics > SAL_CALL createGraphics() override
Definition: vclxdevice.cxx:49
css::uno::Reference< css::awt::XFont > SAL_CALL getFont(const css::awt::FontDescriptor &aDescriptor) override
Definition: vclxdevice.cxx:108
css::awt::Point SAL_CALL convertPointToLogic(const css::awt::Point &aPoint, ::sal_Int16 TargetUnit) override
Definition: vclxdevice.cxx:157
VclPtr< OutputDevice > mpOutputDevice
Definition: vclxdevice.hxx:42
css::awt::Size SAL_CALL convertSizeToLogic(const css::awt::Size &aSize, ::sal_Int16 TargetUnit) override
Definition: vclxdevice.cxx:204
virtual ~VCLXDevice() override
Definition: vclxdevice.cxx:41
css::uno::Reference< css::awt::XDevice > SAL_CALL createDevice(sal_Int32 nWidth, sal_Int32 nHeight) override
Definition: vclxdevice.cxx:61
friend class VCLXVirtualDevice
Definition: vclxdevice.hxx:39
css::awt::Point SAL_CALL convertPointToPixel(const css::awt::Point &aPoint, ::sal_Int16 SourceUnit) override
Definition: vclxdevice.cxx:181
css::uno::Reference< css::awt::XDisplayBitmap > SAL_CALL createDisplayBitmap(const css::uno::Reference< css::awt::XBitmap > &Bitmap) override
Definition: vclxdevice.cxx:138
css::awt::DeviceInfo SAL_CALL getInfo() override
Definition: vclxdevice.cxx:77
css::awt::Size SAL_CALL convertSizeToPixel(const css::awt::Size &aSize, ::sal_Int16 SourceUnit) override
Definition: vclxdevice.cxx:228
css::uno::Reference< css::awt::XBitmap > SAL_CALL createBitmap(sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight) override
Definition: vclxdevice.cxx:122
const VclPtr< OutputDevice > & GetOutputDevice() const
Definition: vclxdevice.hxx:49
css::uno::Sequence< css::awt::FontDescriptor > SAL_CALL getFontDescriptors() override
Definition: vclxdevice.cxx:89
virtual ~VCLXVirtualDevice() override
Definition: vclxdevice.cxx:148
void disposeAndClear()
void reset(reference_type *pBody)
sal_Int64 n