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

Generated by: LCOV version 1.10