LCOV - code coverage report
Current view: top level - svtools/source/filter - DocumentToGraphicRenderer.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 65 0.0 %
Date: 2014-04-11 Functions: 0 6 0.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             : #include <svtools/DocumentToGraphicRenderer.hxx>
      21             : 
      22             : #include <vcl/graphicfilter.hxx>
      23             : #include <vcl/svapp.hxx>
      24             : #include <vcl/outdev.hxx>
      25             : 
      26             : #include <com/sun/star/awt/XDevice.hpp>
      27             : #include <com/sun/star/text/XPageCursor.hpp>
      28             : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
      29             : #include <com/sun/star/beans/PropertyValues.hpp>
      30             : 
      31             : #include <toolkit/helper/vclunohelper.hxx>
      32             : 
      33             : using namespace css;
      34             : using namespace css::uno;
      35             : using namespace css::lang;
      36             : using namespace css::beans;
      37             : 
      38           0 : DocumentToGraphicRenderer::DocumentToGraphicRenderer( const Reference<XComponent>& rxDocument ) :
      39             :     mxDocument(rxDocument),
      40             :     mxModel( mxDocument, uno::UNO_QUERY ),
      41           0 :     mxController( mxModel->getCurrentController() ),
      42             :     mxRenderable (mxDocument, uno::UNO_QUERY ),
      43           0 :     mxToolkit( VCLUnoHelper::CreateToolkit() )
      44             : {
      45           0 : }
      46             : 
      47           0 : DocumentToGraphicRenderer::~DocumentToGraphicRenderer()
      48             : {
      49           0 : }
      50             : 
      51           0 : Size DocumentToGraphicRenderer::getDocumentSizeInPixels(sal_Int32 aCurrentPage)
      52             : {
      53           0 :     Size aSize100mm = getDocumentSizeIn100mm(aCurrentPage);
      54           0 :     return Size( Application::GetDefaultDevice()->LogicToPixel( aSize100mm, MAP_100TH_MM ) );
      55             : }
      56             : 
      57           0 : Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 aCurrentPage)
      58             : {
      59           0 :     Reference< awt::XDevice > xDevice(mxToolkit->createScreenCompatibleDevice( 32, 32 ) );
      60             : 
      61           0 :     uno::Any selection;
      62           0 :     selection <<= mxDocument;
      63             : 
      64           0 :     PropertyValues renderProperties;
      65             : 
      66           0 :     renderProperties.realloc( 3 );
      67           0 :     renderProperties[0].Name = "IsPrinter";
      68           0 :     renderProperties[0].Value <<= sal_True;
      69           0 :     renderProperties[1].Name = "RenderDevice";
      70           0 :     renderProperties[1].Value <<= xDevice;
      71           0 :     renderProperties[2].Name = "View";
      72           0 :     renderProperties[2].Value <<= mxController;
      73             : 
      74           0 :     awt::Size aSize;
      75             : 
      76           0 :     sal_Int32 nPages = mxRenderable->getRendererCount( selection, renderProperties );
      77           0 :     if (nPages >= aCurrentPage)
      78             :     {
      79           0 :         Sequence< beans::PropertyValue > aResult = mxRenderable->getRenderer(aCurrentPage - 1, selection, renderProperties );
      80           0 :         for( sal_Int32 nProperty = 0, nPropertyCount = aResult.getLength(); nProperty < nPropertyCount; ++nProperty )
      81             :         {
      82           0 :             if ( aResult[ nProperty ].Name == "PageSize" )
      83             :             {
      84           0 :                 aResult[ nProperty ].Value >>= aSize;
      85             :             }
      86           0 :         }
      87             :     }
      88             : 
      89           0 :     return Size( aSize.Width, aSize.Height );
      90             : }
      91             : 
      92           0 : Graphic DocumentToGraphicRenderer::renderToGraphic(
      93             :     sal_Int32 aCurrentPage,
      94             :     Size aDocumentSizePixel,
      95             :     Size aTargetSizePixel)
      96             : 
      97             : {
      98           0 :     if (!mxModel.is() || !mxController.is() || !mxRenderable.is())
      99           0 :         return Graphic();
     100             : 
     101           0 :     Reference< awt::XDevice > xDevice(mxToolkit->createScreenCompatibleDevice( aTargetSizePixel.Width(), aTargetSizePixel.Height() ) );
     102           0 :     if (!xDevice.is())
     103           0 :         return Graphic();
     104             : 
     105           0 :     double fScaleX = aTargetSizePixel.Width()  / (double) aDocumentSizePixel.Width();
     106           0 :     double fScaleY = aTargetSizePixel.Height() / (double) aDocumentSizePixel.Height();
     107             : 
     108           0 :     PropertyValues renderProps;
     109           0 :     renderProps.realloc( 3 );
     110           0 :     renderProps[0].Name = "IsPrinter";
     111           0 :     renderProps[0].Value <<= sal_True;
     112           0 :     renderProps[1].Name = "RenderDevice";
     113           0 :     renderProps[1].Value <<= xDevice;
     114           0 :     renderProps[2].Name = "View";
     115           0 :     renderProps[2].Value <<= mxController;
     116             : 
     117           0 :     GDIMetaFile aMtf;
     118             : 
     119           0 :     OutputDevice* pOutputDev = VCLUnoHelper::GetOutputDevice( xDevice );
     120           0 :     pOutputDev->SetAntialiasing(pOutputDev->GetAntialiasing() | ANTIALIASING_ENABLE_B2DDRAW);
     121           0 :     MapMode mm = pOutputDev->GetMapMode();
     122           0 :     mm.SetScaleX( fScaleX );
     123           0 :     mm.SetScaleY( fScaleY );
     124           0 :     pOutputDev->SetMapMode( mm );
     125             : 
     126           0 :     aMtf.Record( pOutputDev );
     127             : 
     128           0 :     uno::Any aSelection;
     129           0 :     aSelection <<= mxDocument;
     130           0 :     mxRenderable->render(aCurrentPage - 1, aSelection, renderProps );
     131             : 
     132           0 :     aMtf.Stop();
     133           0 :     aMtf.WindStart();
     134           0 :     aMtf.SetPrefSize( aTargetSizePixel );
     135             : 
     136           0 :     return Graphic(aMtf);
     137             : }
     138             : 
     139           0 : sal_Int32 DocumentToGraphicRenderer::getCurrentPageWriter()
     140             : {
     141           0 :     Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(mxModel->getCurrentController(), UNO_QUERY);
     142           0 :     Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(), UNO_QUERY);
     143           0 :     return xCursor->getPage();
     144             : }
     145             : 
     146             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10