LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/presenter - SlideRenderer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 70 4.3 %
Date: 2013-07-09 Functions: 3 15 20.0 %
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             : 
      31             : namespace sd { namespace presenter {
      32             : 
      33             : //===== Service ===============================================================
      34             : 
      35           0 : Reference<XInterface> SAL_CALL SlideRenderer_createInstance (
      36             :     const Reference<XComponentContext>& rxContext)
      37             : {
      38           0 :     return Reference<XInterface>(static_cast<XWeak*>(new SlideRenderer(rxContext)));
      39             : }
      40             : 
      41             : 
      42             : 
      43             : 
      44          10 : OUString SlideRenderer_getImplementationName (void) throw(RuntimeException)
      45             : {
      46          10 :     return OUString("com.sun.star.comp.Draw.SlideRenderer");
      47             : }
      48             : 
      49             : 
      50             : 
      51             : 
      52           0 : Sequence<OUString> SAL_CALL SlideRenderer_getSupportedServiceNames (void)
      53             :     throw (RuntimeException)
      54             : {
      55           0 :     static const OUString sServiceName("com.sun.star.drawing.SlideRenderer");
      56           0 :     return Sequence<OUString>(&sServiceName, 1);
      57             : }
      58             : 
      59             : 
      60             : 
      61             : 
      62             : //===== SlideRenderer ==========================================================
      63             : 
      64           0 : SlideRenderer::SlideRenderer (const Reference<XComponentContext>& rxContext)
      65             :     : SlideRendererInterfaceBase(m_aMutex),
      66           0 :       maPreviewRenderer()
      67             : {
      68             :     (void)rxContext;
      69           0 : }
      70             : 
      71             : 
      72             : 
      73             : 
      74           0 : SlideRenderer::~SlideRenderer (void)
      75             : {
      76           0 : }
      77             : 
      78             : 
      79             : 
      80             : 
      81           0 : void SAL_CALL SlideRenderer::disposing (void)
      82             : {
      83           0 : }
      84             : 
      85             : 
      86             : 
      87             : 
      88             : //----- XInitialization -------------------------------------------------------
      89             : 
      90           0 : void SAL_CALL SlideRenderer::initialize (const Sequence<Any>& rArguments)
      91             :     throw (Exception, RuntimeException)
      92             : {
      93           0 :     ThrowIfDisposed();
      94             : 
      95           0 :     if (rArguments.getLength() != 0)
      96             :     {
      97             :         throw RuntimeException("SlideRenderer: invalid number of arguments",
      98           0 :                 static_cast<XWeak*>(this));
      99             :     }
     100           0 : }
     101             : 
     102             : 
     103             : 
     104             : 
     105             : //----- XSlideRenderer --------------------------------------------------------
     106             : 
     107           0 : Reference<awt::XBitmap> SlideRenderer::createPreview (
     108             :     const Reference<drawing::XDrawPage>& rxSlide,
     109             :     const awt::Size& rMaximalSize,
     110             :     sal_Int16 nSuperSampleFactor)
     111             :     throw (css::uno::RuntimeException)
     112             : {
     113           0 :     ThrowIfDisposed();
     114           0 :     SolarMutexGuard aGuard;
     115             : 
     116             :     return VCLUnoHelper::CreateBitmap(
     117           0 :         CreatePreview(rxSlide, rMaximalSize, nSuperSampleFactor));
     118             : }
     119             : 
     120             : 
     121             : 
     122             : 
     123           0 : Reference<rendering::XBitmap> SlideRenderer::createPreviewForCanvas (
     124             :     const Reference<drawing::XDrawPage>& rxSlide,
     125             :     const awt::Size& rMaximalSize,
     126             :     sal_Int16 nSuperSampleFactor,
     127             :     const Reference<rendering::XCanvas>& rxCanvas)
     128             :     throw (css::uno::RuntimeException)
     129             : {
     130           0 :     ThrowIfDisposed();
     131           0 :     SolarMutexGuard aGuard;
     132             : 
     133           0 :     cppcanvas::BitmapCanvasSharedPtr pCanvas (cppcanvas::VCLFactory::getInstance().createCanvas(
     134           0 :         Reference<rendering::XBitmapCanvas>(rxCanvas, UNO_QUERY)));
     135           0 :     if (pCanvas.get() != NULL)
     136           0 :         return cppcanvas::VCLFactory::getInstance().createBitmap(
     137             :             pCanvas,
     138           0 :             CreatePreview(rxSlide, rMaximalSize, nSuperSampleFactor))->getUNOBitmap();
     139             :     else
     140           0 :         return NULL;
     141             : }
     142             : 
     143             : 
     144             : 
     145             : 
     146           0 : awt::Size SAL_CALL SlideRenderer::calculatePreviewSize (
     147             :     double nSlideAspectRatio,
     148             :     const awt::Size& rMaximalSize)
     149             :     throw (css::uno::RuntimeException)
     150             : {
     151           0 :     if (rMaximalSize.Width <= 0
     152           0 :         || rMaximalSize.Height <= 0
     153           0 :         || nSlideAspectRatio <= 0)
     154             :     {
     155           0 :         return awt::Size(0,0);
     156             :     }
     157             : 
     158           0 :     const double nWindowAspectRatio (double(rMaximalSize.Width) / double(rMaximalSize.Height));
     159           0 :     if (nSlideAspectRatio < nWindowAspectRatio)
     160             :         return awt::Size(
     161           0 :             sal::static_int_cast<sal_Int32>(rMaximalSize.Height * nSlideAspectRatio),
     162           0 :             rMaximalSize.Height);
     163             :     else
     164             :         return awt::Size(
     165             :             rMaximalSize.Width,
     166           0 :             sal::static_int_cast<sal_Int32>(rMaximalSize.Width / nSlideAspectRatio));
     167             : }
     168             : 
     169             : 
     170             : 
     171             : 
     172             : //-----------------------------------------------------------------------------
     173             : 
     174           0 : BitmapEx SlideRenderer::CreatePreview (
     175             :     const Reference<drawing::XDrawPage>& rxSlide,
     176             :     const awt::Size& rMaximalSize,
     177             :     sal_Int16 nSuperSampleFactor)
     178             :     throw (css::uno::RuntimeException)
     179             : {
     180           0 :     const SdPage* pPage = SdPage::getImplementation(rxSlide);
     181           0 :     if (pPage == NULL)
     182             :         throw lang::IllegalArgumentException("SlideRenderer::createPreview() called with invalid slide",
     183             :             static_cast<XWeak*>(this),
     184           0 :             0);
     185             : 
     186             :     // Determine the size of the current slide and its aspect ratio.
     187           0 :     Size aPageSize = pPage->GetSize();
     188           0 :     if (aPageSize.Height() <= 0)
     189             :         throw lang::IllegalArgumentException("SlideRenderer::createPreview() called with invalid size",
     190             :             static_cast<XWeak*>(this),
     191           0 :             1);
     192             : 
     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           0 :         double(aPageSize.Width()) / double(aPageSize.Height()),
     199           0 :         rMaximalSize));
     200           0 :     if (aPreviewSize.Width <= 0 || aPreviewSize.Height <= 0)
     201           0 :         return BitmapEx();
     202             : 
     203             :     // Make sure that the super sample factor has a sane value.
     204           0 :     sal_Int16 nFactor (nSuperSampleFactor);
     205           0 :     if (nFactor < 1)
     206           0 :         nFactor = 1;
     207           0 :     else if (nFactor > 10)
     208           0 :         nFactor = 10;
     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           0 :         OUString());
     219           0 :     if (nFactor == 1)
     220           0 :         return aPreview.GetBitmapEx();
     221             :     else
     222             :     {
     223           0 :         BitmapEx aScaledPreview = aPreview.GetBitmapEx();
     224             :         aScaledPreview.Scale(
     225             :             Size(aPreviewSize.Width,aPreviewSize.Height),
     226           0 :             BMP_SCALE_BESTQUALITY);
     227           0 :         return aScaledPreview;
     228           0 :     }
     229             : }
     230             : 
     231             : 
     232             : 
     233             : 
     234           0 : void SlideRenderer::ThrowIfDisposed (void)
     235             :     throw (::com::sun::star::lang::DisposedException)
     236             : {
     237           0 :     if (SlideRendererInterfaceBase::rBHelper.bDisposed || SlideRendererInterfaceBase::rBHelper.bInDispose)
     238             :     {
     239             :         throw lang::DisposedException ("SlideRenderer object has already been disposed",
     240           0 :             static_cast<uno::XWeak*>(this));
     241             :     }
     242           0 : }
     243             : 
     244             : 
     245          33 : } } // end of namespace ::sd::presenter
     246             : 
     247             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10