Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "SlideRenderer.hxx"
31 : : #include "sdpage.hxx"
32 : : #include <toolkit/helper/vclunohelper.hxx>
33 : : #include <osl/mutex.hxx>
34 : : #include <vcl/svapp.hxx>
35 : : #include <cppcanvas/vclfactory.hxx>
36 : :
37 : : using namespace ::com::sun::star;
38 : : using namespace ::com::sun::star::uno;
39 : : using ::rtl::OUString;
40 : :
41 : : namespace sd { namespace presenter {
42 : :
43 : : //===== Service ===============================================================
44 : :
45 : 0 : Reference<XInterface> SAL_CALL SlideRenderer_createInstance (
46 : : const Reference<XComponentContext>& rxContext)
47 : : {
48 [ # # ]: 0 : return Reference<XInterface>(static_cast<XWeak*>(new SlideRenderer(rxContext)));
49 : : }
50 : :
51 : :
52 : :
53 : :
54 : 22 : ::rtl::OUString SlideRenderer_getImplementationName (void) throw(RuntimeException)
55 : : {
56 : 22 : return OUString("com.sun.star.comp.Draw.SlideRenderer");
57 : : }
58 : :
59 : :
60 : :
61 : :
62 : 0 : Sequence<rtl::OUString> SAL_CALL SlideRenderer_getSupportedServiceNames (void)
63 : : throw (RuntimeException)
64 : : {
65 [ # # ][ # # ]: 0 : static const ::rtl::OUString sServiceName("com.sun.star.drawing.SlideRenderer");
66 : 0 : return Sequence<rtl::OUString>(&sServiceName, 1);
67 : : }
68 : :
69 : :
70 : :
71 : :
72 : : //===== SlideRenderer ==========================================================
73 : :
74 : 0 : SlideRenderer::SlideRenderer (const Reference<XComponentContext>& rxContext)
75 : : : SlideRendererInterfaceBase(m_aMutex),
76 [ # # ][ # # ]: 0 : maPreviewRenderer()
77 : : {
78 : : (void)rxContext;
79 : 0 : }
80 : :
81 : :
82 : :
83 : :
84 [ # # ][ # # ]: 0 : SlideRenderer::~SlideRenderer (void)
[ # # ]
85 : : {
86 [ # # ]: 0 : }
87 : :
88 : :
89 : :
90 : :
91 : 0 : void SAL_CALL SlideRenderer::disposing (void)
92 : : {
93 : 0 : }
94 : :
95 : :
96 : :
97 : :
98 : : //----- XInitialization -------------------------------------------------------
99 : :
100 : 0 : void SAL_CALL SlideRenderer::initialize (const Sequence<Any>& rArguments)
101 : : throw (Exception, RuntimeException)
102 : : {
103 : 0 : ThrowIfDisposed();
104 : :
105 [ # # ]: 0 : if (rArguments.getLength() != 0)
106 : : {
107 : : throw RuntimeException("SlideRenderer: invalid number of arguments",
108 [ # # ][ # # ]: 0 : static_cast<XWeak*>(this));
109 : : }
110 : 0 : }
111 : :
112 : :
113 : :
114 : :
115 : : //----- XSlideRenderer --------------------------------------------------------
116 : :
117 : 0 : Reference<awt::XBitmap> SlideRenderer::createPreview (
118 : : const Reference<drawing::XDrawPage>& rxSlide,
119 : : const awt::Size& rMaximalSize,
120 : : sal_Int16 nSuperSampleFactor)
121 : : throw (css::uno::RuntimeException)
122 : : {
123 [ # # ]: 0 : ThrowIfDisposed();
124 [ # # ]: 0 : SolarMutexGuard aGuard;
125 : :
126 : : return VCLUnoHelper::CreateBitmap(
127 [ # # ][ # # ]: 0 : CreatePreview(rxSlide, rMaximalSize, nSuperSampleFactor));
[ # # ][ # # ]
128 : : }
129 : :
130 : :
131 : :
132 : :
133 : 0 : Reference<rendering::XBitmap> SlideRenderer::createPreviewForCanvas (
134 : : const Reference<drawing::XDrawPage>& rxSlide,
135 : : const awt::Size& rMaximalSize,
136 : : sal_Int16 nSuperSampleFactor,
137 : : const Reference<rendering::XCanvas>& rxCanvas)
138 : : throw (css::uno::RuntimeException)
139 : : {
140 [ # # ]: 0 : ThrowIfDisposed();
141 [ # # ]: 0 : SolarMutexGuard aGuard;
142 : :
143 [ # # ]: 0 : cppcanvas::BitmapCanvasSharedPtr pCanvas (cppcanvas::VCLFactory::getInstance().createCanvas(
144 [ # # ][ # # ]: 0 : Reference<rendering::XBitmapCanvas>(rxCanvas, UNO_QUERY)));
145 [ # # ]: 0 : if (pCanvas.get() != NULL)
146 [ # # ]: 0 : return cppcanvas::VCLFactory::getInstance().createBitmap(
147 : : pCanvas,
148 [ # # ][ # # ]: 0 : CreatePreview(rxSlide, rMaximalSize, nSuperSampleFactor))->getUNOBitmap();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
149 : : else
150 [ # # ][ # # ]: 0 : return NULL;
[ # # ]
151 : : }
152 : :
153 : :
154 : :
155 : :
156 : 0 : awt::Size SAL_CALL SlideRenderer::calculatePreviewSize (
157 : : double nSlideAspectRatio,
158 : : const awt::Size& rMaximalSize)
159 : : throw (css::uno::RuntimeException)
160 : : {
161 [ # # ][ # # ]: 0 : if (rMaximalSize.Width <= 0
[ # # ]
162 : : || rMaximalSize.Height <= 0
163 : : || nSlideAspectRatio <= 0)
164 : : {
165 : 0 : return awt::Size(0,0);
166 : : }
167 : :
168 : 0 : const double nWindowAspectRatio (double(rMaximalSize.Width) / double(rMaximalSize.Height));
169 [ # # ]: 0 : if (nSlideAspectRatio < nWindowAspectRatio)
170 : : return awt::Size(
171 : 0 : sal::static_int_cast<sal_Int32>(rMaximalSize.Height * nSlideAspectRatio),
172 : 0 : rMaximalSize.Height);
173 : : else
174 : : return awt::Size(
175 : : rMaximalSize.Width,
176 : 0 : sal::static_int_cast<sal_Int32>(rMaximalSize.Width / nSlideAspectRatio));
177 : : }
178 : :
179 : :
180 : :
181 : :
182 : : //-----------------------------------------------------------------------------
183 : :
184 : 0 : BitmapEx SlideRenderer::CreatePreview (
185 : : const Reference<drawing::XDrawPage>& rxSlide,
186 : : const awt::Size& rMaximalSize,
187 : : sal_Int16 nSuperSampleFactor)
188 : : throw (css::uno::RuntimeException)
189 : : {
190 [ # # ]: 0 : const SdPage* pPage = SdPage::getImplementation(rxSlide);
191 [ # # ]: 0 : if (pPage == NULL)
192 : : throw lang::IllegalArgumentException("SlideRenderer::createPreview() called with invalid slide",
193 : : static_cast<XWeak*>(this),
194 [ # # ][ # # ]: 0 : 0);
195 : :
196 : : // Determine the size of the current slide and its aspect ratio.
197 [ # # ]: 0 : Size aPageSize = pPage->GetSize();
198 [ # # ]: 0 : if (aPageSize.Height() <= 0)
199 : : throw lang::IllegalArgumentException("SlideRenderer::createPreview() called with invalid size",
200 : : static_cast<XWeak*>(this),
201 [ # # ][ # # ]: 0 : 1);
202 : :
203 : : // Compare with the aspect ratio of the window (which rMaximalSize
204 : : // assumed to be) and calculate the size of the preview so that it
205 : : // a) will have the aspect ratio of the page and
206 : : // b) will be as large as possible.
207 : : awt::Size aPreviewSize (calculatePreviewSize(
208 : 0 : double(aPageSize.Width()) / double(aPageSize.Height()),
209 [ # # ]: 0 : rMaximalSize));
210 [ # # ][ # # ]: 0 : if (aPreviewSize.Width <= 0 || aPreviewSize.Height <= 0)
211 [ # # ]: 0 : return BitmapEx();
212 : :
213 : : // Make sure that the super sample factor has a sane value.
214 : 0 : sal_Int16 nFactor (nSuperSampleFactor);
215 [ # # ]: 0 : if (nFactor < 1)
216 : 0 : nFactor = 1;
217 [ # # ]: 0 : else if (nFactor > 10)
218 : 0 : nFactor = 10;
219 : :
220 : : // Create the preview. When the super sample factor n is greater than 1
221 : : // then a preview is created in size (n*width, n*height) and then scaled
222 : : // down to (width, height). This is a poor mans antialiasing for the
223 : : // time being. When we have true antialiasing support this workaround
224 : : // can be removed.
225 : : const Image aPreview = maPreviewRenderer.RenderPage (
226 : : pPage,
227 : : Size(aPreviewSize.Width*nFactor, aPreviewSize.Height*nFactor),
228 [ # # ][ # # ]: 0 : ::rtl::OUString());
[ # # ]
229 [ # # ]: 0 : if (nFactor == 1)
230 [ # # ]: 0 : return aPreview.GetBitmapEx();
231 : : else
232 : : {
233 [ # # ]: 0 : BitmapEx aScaledPreview = aPreview.GetBitmapEx();
234 : : aScaledPreview.Scale(
235 : : Size(aPreviewSize.Width,aPreviewSize.Height),
236 [ # # ]: 0 : BMP_SCALE_BEST);
237 [ # # ][ # # ]: 0 : return aScaledPreview;
238 [ # # ]: 0 : }
239 : : }
240 : :
241 : :
242 : :
243 : :
244 : 0 : void SlideRenderer::ThrowIfDisposed (void)
245 : : throw (::com::sun::star::lang::DisposedException)
246 : : {
247 [ # # ][ # # ]: 0 : if (SlideRendererInterfaceBase::rBHelper.bDisposed || SlideRendererInterfaceBase::rBHelper.bInDispose)
248 : : {
249 : : throw lang::DisposedException ("SlideRenderer object has already been disposed",
250 [ # # ][ # # ]: 0 : static_cast<uno::XWeak*>(this));
251 : : }
252 : 0 : }
253 : :
254 : :
255 : : } } // end of namespace ::sd::presenter
256 : :
257 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|