LCOV - code coverage report
Current view: top level - sd/source/ui/presenter - SlideRenderer.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 21 68 30.9 %
Date: 2014-04-11 Functions: 9 13 69.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10