fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / presenter / SlideRenderer.cxx
blob6bf192a70baa5cfed0be420583aa13e3ff2bfa92
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include "SlideRenderer.hxx"
22 #include "sdpage.hxx"
23 #include <toolkit/helper/vclunohelper.hxx>
24 #include <osl/mutex.hxx>
25 #include <vcl/svapp.hxx>
26 #include <cppcanvas/vclfactory.hxx>
28 using namespace ::com::sun::star;
29 using namespace ::com::sun::star::uno;
31 namespace sd { namespace presenter {
33 //===== Service ===============================================================
35 Reference<XInterface> SAL_CALL SlideRenderer_createInstance (
36 const Reference<XComponentContext>& rxContext)
38 return Reference<XInterface>(static_cast<XWeak*>(new SlideRenderer(rxContext)));
44 OUString SlideRenderer_getImplementationName (void) throw(RuntimeException)
46 return OUString("com.sun.star.comp.Draw.SlideRenderer");
52 Sequence<OUString> SAL_CALL SlideRenderer_getSupportedServiceNames (void)
53 throw (RuntimeException)
55 static const OUString sServiceName("com.sun.star.drawing.SlideRenderer");
56 return Sequence<OUString>(&sServiceName, 1);
62 //===== SlideRenderer ==========================================================
64 SlideRenderer::SlideRenderer (const Reference<XComponentContext>& rxContext)
65 : SlideRendererInterfaceBase(m_aMutex),
66 maPreviewRenderer()
68 (void)rxContext;
74 SlideRenderer::~SlideRenderer (void)
81 void SAL_CALL SlideRenderer::disposing (void)
88 //----- XInitialization -------------------------------------------------------
90 void SAL_CALL SlideRenderer::initialize (const Sequence<Any>& rArguments)
91 throw (Exception, RuntimeException)
93 ThrowIfDisposed();
95 if (rArguments.getLength() != 0)
97 throw RuntimeException("SlideRenderer: invalid number of arguments",
98 static_cast<XWeak*>(this));
105 //----- XSlideRenderer --------------------------------------------------------
107 Reference<awt::XBitmap> SlideRenderer::createPreview (
108 const Reference<drawing::XDrawPage>& rxSlide,
109 const awt::Size& rMaximalSize,
110 sal_Int16 nSuperSampleFactor)
111 throw (css::uno::RuntimeException)
113 ThrowIfDisposed();
114 SolarMutexGuard aGuard;
116 return VCLUnoHelper::CreateBitmap(
117 CreatePreview(rxSlide, rMaximalSize, nSuperSampleFactor));
123 Reference<rendering::XBitmap> SlideRenderer::createPreviewForCanvas (
124 const Reference<drawing::XDrawPage>& rxSlide,
125 const awt::Size& rMaximalSize,
126 sal_Int16 nSuperSampleFactor,
127 const Reference<rendering::XCanvas>& rxCanvas)
128 throw (css::uno::RuntimeException)
130 ThrowIfDisposed();
131 SolarMutexGuard aGuard;
133 cppcanvas::BitmapCanvasSharedPtr pCanvas (cppcanvas::VCLFactory::getInstance().createCanvas(
134 Reference<rendering::XBitmapCanvas>(rxCanvas, UNO_QUERY)));
135 if (pCanvas.get() != NULL)
136 return cppcanvas::VCLFactory::getInstance().createBitmap(
137 pCanvas,
138 CreatePreview(rxSlide, rMaximalSize, nSuperSampleFactor))->getUNOBitmap();
139 else
140 return NULL;
146 awt::Size SAL_CALL SlideRenderer::calculatePreviewSize (
147 double nSlideAspectRatio,
148 const awt::Size& rMaximalSize)
149 throw (css::uno::RuntimeException)
151 if (rMaximalSize.Width <= 0
152 || rMaximalSize.Height <= 0
153 || nSlideAspectRatio <= 0)
155 return awt::Size(0,0);
158 const double nWindowAspectRatio (double(rMaximalSize.Width) / double(rMaximalSize.Height));
159 if (nSlideAspectRatio < nWindowAspectRatio)
160 return awt::Size(
161 sal::static_int_cast<sal_Int32>(rMaximalSize.Height * nSlideAspectRatio),
162 rMaximalSize.Height);
163 else
164 return awt::Size(
165 rMaximalSize.Width,
166 sal::static_int_cast<sal_Int32>(rMaximalSize.Width / nSlideAspectRatio));
172 //-----------------------------------------------------------------------------
174 BitmapEx SlideRenderer::CreatePreview (
175 const Reference<drawing::XDrawPage>& rxSlide,
176 const awt::Size& rMaximalSize,
177 sal_Int16 nSuperSampleFactor)
178 throw (css::uno::RuntimeException)
180 const SdPage* pPage = SdPage::getImplementation(rxSlide);
181 if (pPage == NULL)
182 throw lang::IllegalArgumentException("SlideRenderer::createPreview() called with invalid slide",
183 static_cast<XWeak*>(this),
186 // Determine the size of the current slide and its aspect ratio.
187 Size aPageSize = pPage->GetSize();
188 if (aPageSize.Height() <= 0)
189 throw lang::IllegalArgumentException("SlideRenderer::createPreview() called with invalid size",
190 static_cast<XWeak*>(this),
193 // Compare with the aspect ratio of the window (which rMaximalSize
194 // assumed to be) and calculate the size of the preview so that it
195 // a) will have the aspect ratio of the page and
196 // b) will be as large as possible.
197 awt::Size aPreviewSize (calculatePreviewSize(
198 double(aPageSize.Width()) / double(aPageSize.Height()),
199 rMaximalSize));
200 if (aPreviewSize.Width <= 0 || aPreviewSize.Height <= 0)
201 return BitmapEx();
203 // Make sure that the super sample factor has a sane value.
204 sal_Int16 nFactor (nSuperSampleFactor);
205 if (nFactor < 1)
206 nFactor = 1;
207 else if (nFactor > 10)
208 nFactor = 10;
210 // Create the preview. When the super sample factor n is greater than 1
211 // then a preview is created in size (n*width, n*height) and then scaled
212 // down to (width, height). This is a poor mans antialiasing for the
213 // time being. When we have true antialiasing support this workaround
214 // can be removed.
215 const Image aPreview = maPreviewRenderer.RenderPage (
216 pPage,
217 Size(aPreviewSize.Width*nFactor, aPreviewSize.Height*nFactor),
218 OUString());
219 if (nFactor == 1)
220 return aPreview.GetBitmapEx();
221 else
223 BitmapEx aScaledPreview = aPreview.GetBitmapEx();
224 aScaledPreview.Scale(
225 Size(aPreviewSize.Width,aPreviewSize.Height),
226 BMP_SCALE_BESTQUALITY);
227 return aScaledPreview;
234 void SlideRenderer::ThrowIfDisposed (void)
235 throw (::com::sun::star::lang::DisposedException)
237 if (SlideRendererInterfaceBase::rBHelper.bDisposed || SlideRendererInterfaceBase::rBHelper.bInDispose)
239 throw lang::DisposedException ("SlideRenderer object has already been disposed",
240 static_cast<uno::XWeak*>(this));
245 } } // end of namespace ::sd::presenter
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */