15b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
35b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
45b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file
55b190011SAndrew Rist * distributed with this work for additional information
65b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file
75b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the
85b190011SAndrew Rist * "License"); you may not use this file except in compliance
95b190011SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
115b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
135b190011SAndrew Rist * Unless required by applicable law or agreed to in writing,
145b190011SAndrew Rist * software distributed under the License is distributed on an
155b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165b190011SAndrew Rist * KIND, either express or implied. See the License for the
175b190011SAndrew Rist * specific language governing permissions and limitations
185b190011SAndrew Rist * under the License.
19cdf0e10cSrcweir *
205b190011SAndrew Rist *************************************************************/
215b190011SAndrew Rist
225b190011SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "precompiled_sd.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include "SlideRenderer.hxx"
27cdf0e10cSrcweir #include "sdpage.hxx"
28cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
29cdf0e10cSrcweir #include <vos/mutex.hxx>
30cdf0e10cSrcweir #include <vcl/svapp.hxx>
31cdf0e10cSrcweir #include <cppcanvas/vclfactory.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir using namespace ::com::sun::star;
34cdf0e10cSrcweir using namespace ::com::sun::star::uno;
35cdf0e10cSrcweir using ::rtl::OUString;
36cdf0e10cSrcweir
37cdf0e10cSrcweir namespace sd { namespace presenter {
38cdf0e10cSrcweir
39cdf0e10cSrcweir //===== Service ===============================================================
40cdf0e10cSrcweir
SlideRenderer_createInstance(const Reference<XComponentContext> & rxContext)41cdf0e10cSrcweir Reference<XInterface> SAL_CALL SlideRenderer_createInstance (
42cdf0e10cSrcweir const Reference<XComponentContext>& rxContext)
43cdf0e10cSrcweir {
44cdf0e10cSrcweir return Reference<XInterface>(static_cast<XWeak*>(new SlideRenderer(rxContext)));
45cdf0e10cSrcweir }
46cdf0e10cSrcweir
47cdf0e10cSrcweir
SlideRenderer_getImplementationName(void)48cdf0e10cSrcweir ::rtl::OUString SlideRenderer_getImplementationName (void) throw(RuntimeException)
49cdf0e10cSrcweir {
50cdf0e10cSrcweir return OUString::createFromAscii("com.sun.star.comp.Draw.SlideRenderer");
51cdf0e10cSrcweir }
52cdf0e10cSrcweir
53cdf0e10cSrcweir
SlideRenderer_getSupportedServiceNames(void)54cdf0e10cSrcweir Sequence<rtl::OUString> SAL_CALL SlideRenderer_getSupportedServiceNames (void)
55cdf0e10cSrcweir throw (RuntimeException)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir static const ::rtl::OUString sServiceName(
58cdf0e10cSrcweir ::rtl::OUString::createFromAscii("com.sun.star.drawing.SlideRenderer"));
59cdf0e10cSrcweir return Sequence<rtl::OUString>(&sServiceName, 1);
60cdf0e10cSrcweir }
61cdf0e10cSrcweir
62cdf0e10cSrcweir
63cdf0e10cSrcweir //===== SlideRenderer ==========================================================
64cdf0e10cSrcweir
SlideRenderer(const Reference<XComponentContext> & rxContext)65cdf0e10cSrcweir SlideRenderer::SlideRenderer (const Reference<XComponentContext>& rxContext)
66cdf0e10cSrcweir : SlideRendererInterfaceBase(m_aMutex),
67cdf0e10cSrcweir maPreviewRenderer()
68cdf0e10cSrcweir {
69cdf0e10cSrcweir (void)rxContext;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir
72cdf0e10cSrcweir
~SlideRenderer(void)73cdf0e10cSrcweir SlideRenderer::~SlideRenderer (void)
74cdf0e10cSrcweir {
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
77cdf0e10cSrcweir
disposing(void)78cdf0e10cSrcweir void SAL_CALL SlideRenderer::disposing (void)
79cdf0e10cSrcweir {
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
82cdf0e10cSrcweir
83cdf0e10cSrcweir //----- XInitialization -------------------------------------------------------
84cdf0e10cSrcweir
initialize(const Sequence<Any> & rArguments)85cdf0e10cSrcweir void SAL_CALL SlideRenderer::initialize (const Sequence<Any>& rArguments)
86cdf0e10cSrcweir throw (Exception, RuntimeException)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir ThrowIfDisposed();
89cdf0e10cSrcweir
90cdf0e10cSrcweir if (rArguments.getLength() == 0)
91cdf0e10cSrcweir {
92cdf0e10cSrcweir try
93cdf0e10cSrcweir {
94cdf0e10cSrcweir }
95cdf0e10cSrcweir catch (RuntimeException&)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir throw;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir }
100cdf0e10cSrcweir else
101cdf0e10cSrcweir {
102cdf0e10cSrcweir throw RuntimeException(
103cdf0e10cSrcweir OUString::createFromAscii("SlideRenderer: invalid number of arguments"),
104cdf0e10cSrcweir static_cast<XWeak*>(this));
105cdf0e10cSrcweir }
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
108cdf0e10cSrcweir
109cdf0e10cSrcweir //----- XSlideRenderer --------------------------------------------------------
110cdf0e10cSrcweir
createPreview(const Reference<drawing::XDrawPage> & rxSlide,const awt::Size & rMaximalSize,sal_Int16 nSuperSampleFactor)111cdf0e10cSrcweir Reference<awt::XBitmap> SlideRenderer::createPreview (
112cdf0e10cSrcweir const Reference<drawing::XDrawPage>& rxSlide,
113cdf0e10cSrcweir const awt::Size& rMaximalSize,
114cdf0e10cSrcweir sal_Int16 nSuperSampleFactor)
115cdf0e10cSrcweir throw (css::uno::RuntimeException)
116cdf0e10cSrcweir {
117cdf0e10cSrcweir ThrowIfDisposed();
118cdf0e10cSrcweir ::vos::OGuard aGuard (Application::GetSolarMutex());
119cdf0e10cSrcweir
120cdf0e10cSrcweir return VCLUnoHelper::CreateBitmap(
121cdf0e10cSrcweir CreatePreview(rxSlide, rMaximalSize, nSuperSampleFactor));
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir
createPreviewForCanvas(const Reference<drawing::XDrawPage> & rxSlide,const awt::Size & rMaximalSize,sal_Int16 nSuperSampleFactor,const Reference<rendering::XCanvas> & rxCanvas)125cdf0e10cSrcweir Reference<rendering::XBitmap> SlideRenderer::createPreviewForCanvas (
126cdf0e10cSrcweir const Reference<drawing::XDrawPage>& rxSlide,
127cdf0e10cSrcweir const awt::Size& rMaximalSize,
128cdf0e10cSrcweir sal_Int16 nSuperSampleFactor,
129cdf0e10cSrcweir const Reference<rendering::XCanvas>& rxCanvas)
130cdf0e10cSrcweir throw (css::uno::RuntimeException)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir ThrowIfDisposed();
133cdf0e10cSrcweir ::vos::OGuard aGuard (Application::GetSolarMutex());
134cdf0e10cSrcweir
135cdf0e10cSrcweir cppcanvas::BitmapCanvasSharedPtr pCanvas (cppcanvas::VCLFactory::getInstance().createCanvas(
136cdf0e10cSrcweir Reference<rendering::XBitmapCanvas>(rxCanvas, UNO_QUERY)));
137cdf0e10cSrcweir if (pCanvas.get() != NULL)
138cdf0e10cSrcweir return cppcanvas::VCLFactory::getInstance().createBitmap(
139cdf0e10cSrcweir pCanvas,
140cdf0e10cSrcweir CreatePreview(rxSlide, rMaximalSize, nSuperSampleFactor))->getUNOBitmap();
141cdf0e10cSrcweir else
142cdf0e10cSrcweir return NULL;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
145cdf0e10cSrcweir
calculatePreviewSize(double nSlideAspectRatio,const awt::Size & rMaximalSize)146cdf0e10cSrcweir awt::Size SAL_CALL SlideRenderer::calculatePreviewSize (
147cdf0e10cSrcweir double nSlideAspectRatio,
148cdf0e10cSrcweir const awt::Size& rMaximalSize)
149cdf0e10cSrcweir throw (css::uno::RuntimeException)
150cdf0e10cSrcweir {
151cdf0e10cSrcweir if (rMaximalSize.Width <= 0
152cdf0e10cSrcweir || rMaximalSize.Height <= 0
153cdf0e10cSrcweir || nSlideAspectRatio <= 0)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir return awt::Size(0,0);
156cdf0e10cSrcweir }
157cdf0e10cSrcweir
158cdf0e10cSrcweir const double nWindowAspectRatio (double(rMaximalSize.Width) / double(rMaximalSize.Height));
159cdf0e10cSrcweir if (nSlideAspectRatio < nWindowAspectRatio)
160cdf0e10cSrcweir return awt::Size(
161cdf0e10cSrcweir sal::static_int_cast<sal_Int32>(rMaximalSize.Height * nSlideAspectRatio),
162cdf0e10cSrcweir rMaximalSize.Height);
163cdf0e10cSrcweir else
164cdf0e10cSrcweir return awt::Size(
165cdf0e10cSrcweir rMaximalSize.Width,
166cdf0e10cSrcweir sal::static_int_cast<sal_Int32>(rMaximalSize.Width / nSlideAspectRatio));
167cdf0e10cSrcweir }
168cdf0e10cSrcweir
169cdf0e10cSrcweir
170cdf0e10cSrcweir //-----------------------------------------------------------------------------
171cdf0e10cSrcweir
CreatePreview(const Reference<drawing::XDrawPage> & rxSlide,const awt::Size & rMaximalSize,sal_Int16 nSuperSampleFactor)172cdf0e10cSrcweir BitmapEx SlideRenderer::CreatePreview (
173cdf0e10cSrcweir const Reference<drawing::XDrawPage>& rxSlide,
174cdf0e10cSrcweir const awt::Size& rMaximalSize,
175cdf0e10cSrcweir sal_Int16 nSuperSampleFactor)
176cdf0e10cSrcweir throw (css::uno::RuntimeException)
177cdf0e10cSrcweir {
178cdf0e10cSrcweir const SdPage* pPage = SdPage::getImplementation(rxSlide);
179cdf0e10cSrcweir if (pPage == NULL)
180cdf0e10cSrcweir throw lang::IllegalArgumentException(
181cdf0e10cSrcweir OUString::createFromAscii("SlideRenderer::createPreview() called with invalid slide"),
182cdf0e10cSrcweir static_cast<XWeak*>(this),
183cdf0e10cSrcweir 0);
184cdf0e10cSrcweir
185cdf0e10cSrcweir // Determine the size of the current slide and its aspect ratio.
186cdf0e10cSrcweir Size aPageSize = pPage->GetSize();
187cdf0e10cSrcweir if (aPageSize.Height() <= 0)
188cdf0e10cSrcweir throw lang::IllegalArgumentException(
189cdf0e10cSrcweir OUString::createFromAscii("SlideRenderer::createPreview() called with invalid size"),
190cdf0e10cSrcweir static_cast<XWeak*>(this),
191cdf0e10cSrcweir 1);
192cdf0e10cSrcweir
193cdf0e10cSrcweir // Compare with the aspect ratio of the window (which rMaximalSize
194cdf0e10cSrcweir // assumed to be) and calculate the size of the preview so that it
195cdf0e10cSrcweir // a) will have the aspect ratio of the page and
196cdf0e10cSrcweir // b) will be as large as possible.
197cdf0e10cSrcweir awt::Size aPreviewSize (calculatePreviewSize(
198cdf0e10cSrcweir double(aPageSize.Width()) / double(aPageSize.Height()),
199cdf0e10cSrcweir rMaximalSize));
200cdf0e10cSrcweir if (aPreviewSize.Width <= 0 || aPreviewSize.Height <= 0)
201cdf0e10cSrcweir return BitmapEx();
202cdf0e10cSrcweir
203cdf0e10cSrcweir // Make sure that the super sample factor has a sane value.
204cdf0e10cSrcweir sal_Int16 nFactor (nSuperSampleFactor);
205cdf0e10cSrcweir if (nFactor < 1)
206cdf0e10cSrcweir nFactor = 1;
207cdf0e10cSrcweir else if (nFactor > 10)
208cdf0e10cSrcweir nFactor = 10;
209cdf0e10cSrcweir
210cdf0e10cSrcweir // Create the preview. When the super sample factor n is greater than 1
211cdf0e10cSrcweir // then a preview is created in size (n*width, n*height) and then scaled
212cdf0e10cSrcweir // down to (width, height). This is a poor mans antialiasing for the
213cdf0e10cSrcweir // time being. When we have true antialiasing support this workaround
214cdf0e10cSrcweir // can be removed.
215cdf0e10cSrcweir const Image aPreview = maPreviewRenderer.RenderPage (
216cdf0e10cSrcweir pPage,
217cdf0e10cSrcweir Size(aPreviewSize.Width*nFactor, aPreviewSize.Height*nFactor),
218cdf0e10cSrcweir ::rtl::OUString());
219cdf0e10cSrcweir if (nFactor == 1)
220cdf0e10cSrcweir return aPreview.GetBitmapEx();
221cdf0e10cSrcweir else
222cdf0e10cSrcweir {
223cdf0e10cSrcweir BitmapEx aScaledPreview = aPreview.GetBitmapEx();
224cdf0e10cSrcweir aScaledPreview.Scale(
225cdf0e10cSrcweir Size(aPreviewSize.Width,aPreviewSize.Height),
226*26490e24Smseidel BMP_SCALE_FASTESTINTERPOLATE);
227cdf0e10cSrcweir return aScaledPreview;
228cdf0e10cSrcweir }
229cdf0e10cSrcweir }
230cdf0e10cSrcweir
231cdf0e10cSrcweir
ThrowIfDisposed(void)232cdf0e10cSrcweir void SlideRenderer::ThrowIfDisposed (void)
233cdf0e10cSrcweir throw (::com::sun::star::lang::DisposedException)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir if (SlideRendererInterfaceBase::rBHelper.bDisposed || SlideRendererInterfaceBase::rBHelper.bInDispose)
236cdf0e10cSrcweir {
237cdf0e10cSrcweir throw lang::DisposedException (
238cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
239cdf0e10cSrcweir "SlideRenderer object has already been disposed")),
240cdf0e10cSrcweir static_cast<uno::XWeak*>(this));
241cdf0e10cSrcweir }
242cdf0e10cSrcweir }
243cdf0e10cSrcweir
244cdf0e10cSrcweir
245cdf0e10cSrcweir } } // end of namespace ::sd::presenter
246cdf0e10cSrcweir
247*26490e24Smseidel /* vim: set noet sw=4 ts=4: */
248