LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/presenter - SlideRenderer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 67 3.0 %
Date: 2012-12-27 Functions: 1 13 7.7 %
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 <osl/mutex.hxx>
      25             : #include <vcl/svapp.hxx>
      26             : #include <cppcanvas/vclfactory.hxx>
      27             : 
      28             : using namespace ::com::sun::star;
      29             : using namespace ::com::sun::star::uno;
      30             : using ::rtl::OUString;
      31             : 
      32             : namespace sd { namespace presenter {
      33             : 
      34             : //===== Service ===============================================================
      35             : 
      36           0 : Reference<XInterface> SAL_CALL SlideRenderer_createInstance (
      37             :     const Reference<XComponentContext>& rxContext)
      38             : {
      39           0 :     return Reference<XInterface>(static_cast<XWeak*>(new SlideRenderer(rxContext)));
      40             : }
      41             : 
      42             : 
      43             : 
      44             : 
      45           2 : ::rtl::OUString SlideRenderer_getImplementationName (void) throw(RuntimeException)
      46             : {
      47           2 :     return OUString("com.sun.star.comp.Draw.SlideRenderer");
      48             : }
      49             : 
      50             : 
      51             : 
      52             : 
      53           0 : Sequence<rtl::OUString> SAL_CALL SlideRenderer_getSupportedServiceNames (void)
      54             :     throw (RuntimeException)
      55             : {
      56           0 :     static const ::rtl::OUString sServiceName("com.sun.star.drawing.SlideRenderer");
      57           0 :     return Sequence<rtl::OUString>(&sServiceName, 1);
      58             : }
      59             : 
      60             : 
      61             : 
      62             : 
      63             : //===== SlideRenderer ==========================================================
      64             : 
      65           0 : SlideRenderer::SlideRenderer (const Reference<XComponentContext>& rxContext)
      66             :     : SlideRendererInterfaceBase(m_aMutex),
      67           0 :       maPreviewRenderer()
      68             : {
      69             :     (void)rxContext;
      70           0 : }
      71             : 
      72             : 
      73             : 
      74             : 
      75           0 : SlideRenderer::~SlideRenderer (void)
      76             : {
      77           0 : }
      78             : 
      79             : 
      80             : 
      81             : 
      82           0 : void SAL_CALL SlideRenderer::disposing (void)
      83             : {
      84           0 : }
      85             : 
      86             : 
      87             : 
      88             : 
      89             : //----- XInitialization -------------------------------------------------------
      90             : 
      91           0 : void SAL_CALL SlideRenderer::initialize (const Sequence<Any>& rArguments)
      92             :     throw (Exception, RuntimeException)
      93             : {
      94           0 :     ThrowIfDisposed();
      95             : 
      96           0 :     if (rArguments.getLength() != 0)
      97             :     {
      98             :         throw RuntimeException("SlideRenderer: invalid number of arguments",
      99           0 :                 static_cast<XWeak*>(this));
     100             :     }
     101           0 : }
     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)
     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)
     130             : {
     131           0 :     ThrowIfDisposed();
     132           0 :     SolarMutexGuard aGuard;
     133             : 
     134           0 :     cppcanvas::BitmapCanvasSharedPtr pCanvas (cppcanvas::VCLFactory::getInstance().createCanvas(
     135           0 :         Reference<rendering::XBitmapCanvas>(rxCanvas, UNO_QUERY)));
     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)
     151             : {
     152           0 :     if (rMaximalSize.Width <= 0
     153             :         || rMaximalSize.Height <= 0
     154             :         || 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 :         ::rtl::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_BEST);
     228           0 :         return aScaledPreview;
     229           0 :     }
     230             : }
     231             : 
     232             : 
     233             : 
     234             : 
     235           0 : void SlideRenderer::ThrowIfDisposed (void)
     236             :     throw (::com::sun::star::lang::DisposedException)
     237             : {
     238           0 :     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           0 : }
     244             : 
     245             : 
     246             : } } // end of namespace ::sd::presenter
     247             : 
     248             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10