LibreOffice Module sd (master) 1
SlideRenderer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "SlideRenderer.hxx"
21#include <sdpage.hxx>
23#include <vcl/svapp.hxx>
26
27using namespace ::com::sun::star;
28using namespace ::com::sun::star::uno;
29
30namespace sd::presenter {
31
32//===== SlideRenderer ==========================================================
33
35{
36}
37
39{
40}
41
42//----- XInitialization -------------------------------------------------------
43
44void SAL_CALL SlideRenderer::initialize (const Sequence<Any>& rArguments)
45{
47
48 if (rArguments.hasElements())
49 {
50 throw RuntimeException("SlideRenderer: invalid number of arguments",
51 static_cast<XWeak*>(this));
52 }
53}
54
56{
57 return "com.sun.star.comp.Draw.SlideRenderer";
58}
59
60sal_Bool SlideRenderer::supportsService(OUString const & ServiceName)
61{
63}
64
65css::uno::Sequence<OUString> SlideRenderer::getSupportedServiceNames()
66{
67 return {"com.sun.star.drawing.SlideRenderer"};
68}
69
70//----- XSlideRenderer --------------------------------------------------------
71
72Reference<awt::XBitmap> SlideRenderer::createPreview (
73 const Reference<drawing::XDrawPage>& rxSlide,
74 const awt::Size& rMaximalSize,
75 sal_Int16 nSuperSampleFactor)
76{
78 SolarMutexGuard aGuard;
79
81 CreatePreview(rxSlide, rMaximalSize, nSuperSampleFactor));
82}
83
84Reference<rendering::XBitmap> SlideRenderer::createPreviewForCanvas (
85 const Reference<drawing::XDrawPage>& rxSlide,
86 const awt::Size& rMaximalSize,
87 sal_Int16 nSuperSampleFactor,
88 const Reference<rendering::XCanvas>& rxCanvas)
89{
91 SolarMutexGuard aGuard;
92
95 if (pCanvas)
97 pCanvas,
98 CreatePreview(rxSlide, rMaximalSize, nSuperSampleFactor))->getUNOBitmap();
99 else
100 return nullptr;
101}
102
104 double nSlideAspectRatio,
105 const awt::Size& rMaximalSize)
106{
107 if (rMaximalSize.Width <= 0
108 || rMaximalSize.Height <= 0
109 || nSlideAspectRatio <= 0)
110 {
111 return awt::Size(0,0);
112 }
113
114 const double nWindowAspectRatio (double(rMaximalSize.Width) / double(rMaximalSize.Height));
115 if (nSlideAspectRatio < nWindowAspectRatio)
116 return awt::Size(
117 sal::static_int_cast<sal_Int32>(rMaximalSize.Height * nSlideAspectRatio),
118 rMaximalSize.Height);
119 else
120 return awt::Size(
121 rMaximalSize.Width,
122 sal::static_int_cast<sal_Int32>(rMaximalSize.Width / nSlideAspectRatio));
123}
124
126 const Reference<drawing::XDrawPage>& rxSlide,
127 const awt::Size& rMaximalSize,
128 sal_Int16 nSuperSampleFactor)
129{
130 const SdPage* pPage = SdPage::getImplementation(rxSlide);
131 if (pPage == nullptr)
132 throw lang::IllegalArgumentException("SlideRenderer::createPreview() called with invalid slide",
133 static_cast<XWeak*>(this),
134 0);
135
136 // Determine the size of the current slide and its aspect ratio.
137 Size aPageSize = pPage->GetSize();
138 if (aPageSize.Height() <= 0)
139 throw lang::IllegalArgumentException("SlideRenderer::createPreview() called with invalid size",
140 static_cast<XWeak*>(this),
141 1);
142
143 // Compare with the aspect ratio of the window (which rMaximalSize
144 // assumed to be) and calculate the size of the preview so that it
145 // a) will have the aspect ratio of the page and
146 // b) will be as large as possible.
147 awt::Size aPreviewSize (calculatePreviewSize(
148 double(aPageSize.Width()) / double(aPageSize.Height()),
149 rMaximalSize));
150 if (aPreviewSize.Width <= 0 || aPreviewSize.Height <= 0)
151 return BitmapEx();
152
153 // Make sure that the super sample factor has a sane value.
154 sal_Int16 nFactor (nSuperSampleFactor);
155 if (nFactor < 1)
156 nFactor = 1;
157 else if (nFactor > 10)
158 nFactor = 10;
159
160 // Create the preview. When the super sample factor n is greater than 1
161 // then a preview is created in size (n*width, n*height) and then scaled
162 // down to (width, height). This is a poor mans antialiasing for the
163 // time being. When we have true antialiasing support this workaround
164 // can be removed.
165 const Image aPreview = maPreviewRenderer.RenderPage (
166 pPage,
167 Size(aPreviewSize.Width*nFactor, aPreviewSize.Height*nFactor),
168 true);
169 if (nFactor == 1)
170 return aPreview.GetBitmapEx();
171 else
172 {
173 BitmapEx aScaledPreview = aPreview.GetBitmapEx();
174 aScaledPreview.Scale(
175 Size(aPreviewSize.Width,aPreviewSize.Height),
176 BmpScaleFlag::BestQuality);
177 return aScaledPreview;
178 }
179}
180
182{
183 if (m_bDisposed)
184 {
185 throw lang::DisposedException ("SlideRenderer object has already been disposed",
186 static_cast<uno::XWeak*>(this));
187 }
188}
189
190} // end of namespace ::sd::presenter
191
192
193extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
195 css::uno::Sequence<css::uno::Any> const &)
196{
197 return cppu::acquire(new sd::presenter::SlideRenderer);
198}
199
200
201/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_Draw_SlideRenderer_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
BitmapEx GetBitmapEx() const
static SdPage * getImplementation(const css::uno::Reference< css::drawing::XDrawPage > &xPage)
returns the SdPage implementation for the given XDrawPage or 0 if not available
Definition: sdpage.cxx:2682
Size GetSize() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
static css::uno::Reference< css::awt::XBitmap > CreateBitmap(const BitmapEx &rBitmap)
static BitmapSharedPtr createBitmap(const CanvasSharedPtr &, const ::BitmapEx &rBmpEx)
static CanvasSharedPtr createCanvas(const css::uno::Reference< css::rendering::XCanvas > &xCanvas)
Image RenderPage(const SdPage *pPage, const sal_Int32 nWidth)
Render a page with the given pixel size.
Render single slides into bitmaps.
virtual css::uno::Reference< css::rendering::XBitmap > SAL_CALL createPreviewForCanvas(const css::uno::Reference< css::drawing::XDrawPage > &rxSlide, const css::awt::Size &rMaximumPreviewPixelSize, sal_Int16 nSuperSampleFactor, const css::uno::Reference< css::rendering::XCanvas > &rxCanvas) override
BitmapEx CreatePreview(const css::uno::Reference< css::drawing::XDrawPage > &rxSlide, const css::awt::Size &rMaximumPreviewPixelSize, sal_Int16 nSuperSampleFactor)
sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
OUString SAL_CALL getImplementationName() override
PreviewRenderer maPreviewRenderer
virtual css::awt::Size SAL_CALL calculatePreviewSize(double nSlideAspectRatio, const css::awt::Size &rMaximumPreviewPixelSize) override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &rArguments) override
virtual ~SlideRenderer() override
virtual css::uno::Reference< css::awt::XBitmap > SAL_CALL createPreview(const css::uno::Reference< css::drawing::XDrawPage > &rxSlide, const css::awt::Size &rMaximumPreviewPixelSize, sal_Int16 nSuperSampleFactor) override
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
std::shared_ptr< Canvas > CanvasSharedPtr
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool