1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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
),
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
)
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
)
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
)
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(
138 CreatePreview(rxSlide
, rMaximalSize
, nSuperSampleFactor
))->getUNOBitmap();
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
)
161 sal::static_int_cast
<sal_Int32
>(rMaximalSize
.Height
* nSlideAspectRatio
),
162 rMaximalSize
.Height
);
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
);
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()),
200 if (aPreviewSize
.Width
<= 0 || aPreviewSize
.Height
<= 0)
203 // Make sure that the super sample factor has a sane value.
204 sal_Int16
nFactor (nSuperSampleFactor
);
207 else if (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
215 const Image aPreview
= maPreviewRenderer
.RenderPage (
217 Size(aPreviewSize
.Width
*nFactor
, aPreviewSize
.Height
*nFactor
),
220 return aPreview
.GetBitmapEx();
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: */