SlideRenderer.cxx (79aad27f) SlideRenderer.cxx (61060e70)
1/**************************************************************
1/**************************************************************
2 *
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
19 *
20 *************************************************************/
21
22
23
24#include "precompiled_sd.hxx"
25
26#include "SlideRenderer.hxx"
27#include "sdpage.hxx"

--- 6 unchanged lines hidden (view full) ---

34using namespace ::com::sun::star::uno;
35using ::rtl::OUString;
36
37namespace sd { namespace presenter {
38
39//===== Service ===============================================================
40
41Reference<XInterface> SAL_CALL SlideRenderer_createInstance (
20 *************************************************************/
21
22
23
24#include "precompiled_sd.hxx"
25
26#include "SlideRenderer.hxx"
27#include "sdpage.hxx"

--- 6 unchanged lines hidden (view full) ---

34using namespace ::com::sun::star::uno;
35using ::rtl::OUString;
36
37namespace sd { namespace presenter {
38
39//===== Service ===============================================================
40
41Reference<XInterface> SAL_CALL SlideRenderer_createInstance (
42 const Reference<XComponentContext>& rxContext)
42 const Reference<XComponentContext>& rxContext)
43{
43{
44 return Reference<XInterface>(static_cast<XWeak*>(new SlideRenderer(rxContext)));
44 return Reference<XInterface>(static_cast<XWeak*>(new SlideRenderer(rxContext)));
45}
46
47
45}
46
47
48
49
50::rtl::OUString SlideRenderer_getImplementationName (void) throw(RuntimeException)
51{
48::rtl::OUString SlideRenderer_getImplementationName (void) throw(RuntimeException)
49{
52 return OUString::createFromAscii("com.sun.star.comp.Draw.SlideRenderer");
50 return OUString::createFromAscii("com.sun.star.comp.Draw.SlideRenderer");
53}
54
55
51}
52
53
56
57
58Sequence<rtl::OUString> SAL_CALL SlideRenderer_getSupportedServiceNames (void)
54Sequence<rtl::OUString> SAL_CALL SlideRenderer_getSupportedServiceNames (void)
59 throw (RuntimeException)
55 throw (RuntimeException)
60{
61 static const ::rtl::OUString sServiceName(
56{
57 static const ::rtl::OUString sServiceName(
62 ::rtl::OUString::createFromAscii("com.sun.star.drawing.SlideRenderer"));
58 ::rtl::OUString::createFromAscii("com.sun.star.drawing.SlideRenderer"));
63 return Sequence<rtl::OUString>(&sServiceName, 1);
64}
65
66
59 return Sequence<rtl::OUString>(&sServiceName, 1);
60}
61
62
67
68
69//===== SlideRenderer ==========================================================
70
71SlideRenderer::SlideRenderer (const Reference<XComponentContext>& rxContext)
63//===== SlideRenderer ==========================================================
64
65SlideRenderer::SlideRenderer (const Reference<XComponentContext>& rxContext)
72 : SlideRendererInterfaceBase(m_aMutex),
73 maPreviewRenderer()
66 : SlideRendererInterfaceBase(m_aMutex),
67 maPreviewRenderer()
74{
68{
75 (void)rxContext;
69 (void)rxContext;
76}
77
78
70}
71
72
79
80
81SlideRenderer::~SlideRenderer (void)
82{
83}
84
85
73SlideRenderer::~SlideRenderer (void)
74{
75}
76
77
86
87
88void SAL_CALL SlideRenderer::disposing (void)
89{
90}
91
92
78void SAL_CALL SlideRenderer::disposing (void)
79{
80}
81
82
93
94
95//----- XInitialization -------------------------------------------------------
96
97void SAL_CALL SlideRenderer::initialize (const Sequence<Any>& rArguments)
83//----- XInitialization -------------------------------------------------------
84
85void SAL_CALL SlideRenderer::initialize (const Sequence<Any>& rArguments)
98 throw (Exception, RuntimeException)
86 throw (Exception, RuntimeException)
99{
87{
100 ThrowIfDisposed();
88 ThrowIfDisposed();
101
89
102 if (rArguments.getLength() == 0)
103 {
104 try
105 {
106 }
107 catch (RuntimeException&)
108 {
109 throw;
110 }
111 }
112 else
113 {
114 throw RuntimeException(
115 OUString::createFromAscii("SlideRenderer: invalid number of arguments"),
116 static_cast<XWeak*>(this));
117 }
90 if (rArguments.getLength() == 0)
91 {
92 try
93 {
94 }
95 catch (RuntimeException&)
96 {
97 throw;
98 }
99 }
100 else
101 {
102 throw RuntimeException(
103 OUString::createFromAscii("SlideRenderer: invalid number of arguments"),
104 static_cast<XWeak*>(this));
105 }
118}
119
120
106}
107
108
121
122
123//----- XSlideRenderer --------------------------------------------------------
124
125Reference<awt::XBitmap> SlideRenderer::createPreview (
109//----- XSlideRenderer --------------------------------------------------------
110
111Reference<awt::XBitmap> SlideRenderer::createPreview (
126 const Reference<drawing::XDrawPage>& rxSlide,
127 const awt::Size& rMaximalSize,
128 sal_Int16 nSuperSampleFactor)
129 throw (css::uno::RuntimeException)
112 const Reference<drawing::XDrawPage>& rxSlide,
113 const awt::Size& rMaximalSize,
114 sal_Int16 nSuperSampleFactor)
115 throw (css::uno::RuntimeException)
130{
116{
131 ThrowIfDisposed();
117 ThrowIfDisposed();
132 ::vos::OGuard aGuard (Application::GetSolarMutex());
133
118 ::vos::OGuard aGuard (Application::GetSolarMutex());
119
134 return VCLUnoHelper::CreateBitmap(
135 CreatePreview(rxSlide, rMaximalSize, nSuperSampleFactor));
120 return VCLUnoHelper::CreateBitmap(
121 CreatePreview(rxSlide, rMaximalSize, nSuperSampleFactor));
136}
137
138
122}
123
124
139
140
141Reference<rendering::XBitmap> SlideRenderer::createPreviewForCanvas (
125Reference<rendering::XBitmap> SlideRenderer::createPreviewForCanvas (
142 const Reference<drawing::XDrawPage>& rxSlide,
143 const awt::Size& rMaximalSize,
144 sal_Int16 nSuperSampleFactor,
145 const Reference<rendering::XCanvas>& rxCanvas)
146 throw (css::uno::RuntimeException)
126 const Reference<drawing::XDrawPage>& rxSlide,
127 const awt::Size& rMaximalSize,
128 sal_Int16 nSuperSampleFactor,
129 const Reference<rendering::XCanvas>& rxCanvas)
130 throw (css::uno::RuntimeException)
147{
131{
148 ThrowIfDisposed();
132 ThrowIfDisposed();
149 ::vos::OGuard aGuard (Application::GetSolarMutex());
150
133 ::vos::OGuard aGuard (Application::GetSolarMutex());
134
151 cppcanvas::BitmapCanvasSharedPtr pCanvas (cppcanvas::VCLFactory::getInstance().createCanvas(
152 Reference<rendering::XBitmapCanvas>(rxCanvas, UNO_QUERY)));
153 if (pCanvas.get() != NULL)
154 return cppcanvas::VCLFactory::getInstance().createBitmap(
155 pCanvas,
156 CreatePreview(rxSlide, rMaximalSize, nSuperSampleFactor))->getUNOBitmap();
157 else
158 return NULL;
135 cppcanvas::BitmapCanvasSharedPtr pCanvas (cppcanvas::VCLFactory::getInstance().createCanvas(
136 Reference<rendering::XBitmapCanvas>(rxCanvas, UNO_QUERY)));
137 if (pCanvas.get() != NULL)
138 return cppcanvas::VCLFactory::getInstance().createBitmap(
139 pCanvas,
140 CreatePreview(rxSlide, rMaximalSize, nSuperSampleFactor))->getUNOBitmap();
141 else
142 return NULL;
159}
160
161
143}
144
145
162
163
164awt::Size SAL_CALL SlideRenderer::calculatePreviewSize (
146awt::Size SAL_CALL SlideRenderer::calculatePreviewSize (
165 double nSlideAspectRatio,
166 const awt::Size& rMaximalSize)
167 throw (css::uno::RuntimeException)
147 double nSlideAspectRatio,
148 const awt::Size& rMaximalSize)
149 throw (css::uno::RuntimeException)
168{
150{
169 if (rMaximalSize.Width <= 0
170 || rMaximalSize.Height <= 0
171 || nSlideAspectRatio <= 0)
172 {
173 return awt::Size(0,0);
174 }
151 if (rMaximalSize.Width <= 0
152 || rMaximalSize.Height <= 0
153 || nSlideAspectRatio <= 0)
154 {
155 return awt::Size(0,0);
156 }
175
157
176 const double nWindowAspectRatio (double(rMaximalSize.Width) / double(rMaximalSize.Height));
177 if (nSlideAspectRatio < nWindowAspectRatio)
178 return awt::Size(
179 sal::static_int_cast<sal_Int32>(rMaximalSize.Height * nSlideAspectRatio),
180 rMaximalSize.Height);
181 else
182 return awt::Size(
183 rMaximalSize.Width,
184 sal::static_int_cast<sal_Int32>(rMaximalSize.Width / nSlideAspectRatio));
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));
185}
186
187
167}
168
169
188
189
190//-----------------------------------------------------------------------------
191
192BitmapEx SlideRenderer::CreatePreview (
170//-----------------------------------------------------------------------------
171
172BitmapEx SlideRenderer::CreatePreview (
193 const Reference<drawing::XDrawPage>& rxSlide,
194 const awt::Size& rMaximalSize,
195 sal_Int16 nSuperSampleFactor)
196 throw (css::uno::RuntimeException)
173 const Reference<drawing::XDrawPage>& rxSlide,
174 const awt::Size& rMaximalSize,
175 sal_Int16 nSuperSampleFactor)
176 throw (css::uno::RuntimeException)
197{
177{
198 const SdPage* pPage = SdPage::getImplementation(rxSlide);
199 if (pPage == NULL)
200 throw lang::IllegalArgumentException(
201 OUString::createFromAscii("SlideRenderer::createPreview() called with invalid slide"),
202 static_cast<XWeak*>(this),
203 0);
204
205 // Determine the size of the current slide and its aspect ratio.
206 Size aPageSize = pPage->GetSize();
207 if (aPageSize.Height() <= 0)
208 throw lang::IllegalArgumentException(
209 OUString::createFromAscii("SlideRenderer::createPreview() called with invalid size"),
210 static_cast<XWeak*>(this),
211 1);
178 const SdPage* pPage = SdPage::getImplementation(rxSlide);
179 if (pPage == NULL)
180 throw lang::IllegalArgumentException(
181 OUString::createFromAscii("SlideRenderer::createPreview() called with invalid slide"),
182 static_cast<XWeak*>(this),
183 0);
212
184
213 // Compare with the aspect ratio of the window (which rMaximalSize
214 // assumed to be) and calculate the size of the preview so that it
215 // a) will have the aspect ratio of the page and
216 // b) will be as large as possible.
217 awt::Size aPreviewSize (calculatePreviewSize(
218 double(aPageSize.Width()) / double(aPageSize.Height()),
219 rMaximalSize));
220 if (aPreviewSize.Width <= 0 || aPreviewSize.Height <= 0)
221 return BitmapEx();
185 // Determine the size of the current slide and its aspect ratio.
186 Size aPageSize = pPage->GetSize();
187 if (aPageSize.Height() <= 0)
188 throw lang::IllegalArgumentException(
189 OUString::createFromAscii("SlideRenderer::createPreview() called with invalid size"),
190 static_cast<XWeak*>(this),
191 1);
222
192
223 // Make sure that the super sample factor has a sane value.
224 sal_Int16 nFactor (nSuperSampleFactor);
225 if (nFactor < 1)
226 nFactor = 1;
227 else if (nFactor > 10)
228 nFactor = 10;
229
230 // Create the preview. When the super sample factor n is greater than 1
231 // then a preview is created in size (n*width, n*height) and then scaled
232 // down to (width, height). This is a poor mans antialiasing for the
233 // time being. When we have true antialiasing support this workaround
234 // can be removed.
235 const Image aPreview = maPreviewRenderer.RenderPage (
236 pPage,
237 Size(aPreviewSize.Width*nFactor, aPreviewSize.Height*nFactor),
238 ::rtl::OUString());
239 if (nFactor == 1)
240 return aPreview.GetBitmapEx();
241 else
242 {
243 BitmapEx aScaledPreview = aPreview.GetBitmapEx();
244 aScaledPreview.Scale(
245 Size(aPreviewSize.Width,aPreviewSize.Height),
246 BMP_SCALE_INTERPOLATE);
247 return aScaledPreview;
248 }
249}
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();
250
202
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;
251
209
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 ::rtl::OUString());
219 if (nFactor == 1)
220 return aPreview.GetBitmapEx();
221 else
222 {
223 BitmapEx aScaledPreview = aPreview.GetBitmapEx();
224 aScaledPreview.Scale(
225 Size(aPreviewSize.Width,aPreviewSize.Height),
226 BMP_SCALE_FASTESTINTERPOLATE);
227 return aScaledPreview;
228 }
229}
252
253
254void SlideRenderer::ThrowIfDisposed (void)
230
231
232void SlideRenderer::ThrowIfDisposed (void)
255 throw (::com::sun::star::lang::DisposedException)
233 throw (::com::sun::star::lang::DisposedException)
256{
257 if (SlideRendererInterfaceBase::rBHelper.bDisposed || SlideRendererInterfaceBase::rBHelper.bInDispose)
258 {
234{
235 if (SlideRendererInterfaceBase::rBHelper.bDisposed || SlideRendererInterfaceBase::rBHelper.bInDispose)
236 {
259 throw lang::DisposedException (
260 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
261 "SlideRenderer object has already been disposed")),
262 static_cast<uno::XWeak*>(this));
263 }
237 throw lang::DisposedException (
238 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
239 "SlideRenderer object has already been disposed")),
240 static_cast<uno::XWeak*>(this));
241 }
264}
265
266
267} } // end of namespace ::sd::presenter
268
242}
243
244
245} } // end of namespace ::sd::presenter
246
247/* vim: set noet sw=4 ts=4: */