LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/drawinglayer/source/drawinglayeruno - xprimitive2drenderer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 40 53 75.5 %
Date: 2013-07-09 Functions: 9 12 75.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 <com/sun/star/graphic/XPrimitive2DRenderer.hpp>
      21             : #include <com/sun/star/lang/XServiceInfo.hpp>
      22             : #include <cppuhelper/implbase2.hxx>
      23             : #include <com/sun/star/xml/sax/XParser.hpp>
      24             : #include <com/sun/star/xml/sax/InputSource.hpp>
      25             : #include <comphelper/processfactory.hxx>
      26             : #include <drawinglayer/geometry/viewinformation2d.hxx>
      27             : #include <basegfx/numeric/ftools.hxx>
      28             : #include <vcl/bitmapex.hxx>
      29             : #include <drawinglayer/tools/converters.hxx>
      30             : #include <vcl/canvastools.hxx>
      31             : #include <com/sun/star/geometry/RealRectangle2D.hpp>
      32             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      33             : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
      34             : 
      35             : //////////////////////////////////////////////////////////////////////////////
      36             : 
      37             : using namespace ::com::sun::star;
      38             : 
      39             : //////////////////////////////////////////////////////////////////////////////
      40             : 
      41             : namespace drawinglayer
      42             : {
      43             :     namespace unorenderer
      44             :     {
      45             :         class XPrimitive2DRenderer : public ::cppu::WeakAggImplHelper2< graphic::XPrimitive2DRenderer, lang::XServiceInfo >
      46             :         {
      47             :         private:
      48             :             XPrimitive2DRenderer(const XPrimitive2DRenderer&);
      49             :             XPrimitive2DRenderer& operator=(const XPrimitive2DRenderer&);
      50             : 
      51             :         protected:
      52             :         public:
      53             :             XPrimitive2DRenderer();
      54             :             virtual ~XPrimitive2DRenderer();
      55             : 
      56             :             // XPrimitive2DRenderer
      57             :             virtual uno::Reference< rendering::XBitmap > SAL_CALL rasterize(
      58             :                 const uno::Sequence< uno::Reference< graphic::XPrimitive2D > >& Primitive2DSequence,
      59             :                 const uno::Sequence< beans::PropertyValue >& aViewInformationSequence,
      60             :                 ::sal_uInt32 DPI_X,
      61             :                 ::sal_uInt32 DPI_Y,
      62             :                 const ::com::sun::star::geometry::RealRectangle2D& Range,
      63             :                 ::sal_uInt32 MaximumQuadraticPixels) throw (uno::RuntimeException);
      64             : 
      65             :             // XServiceInfo
      66             :             virtual OUString SAL_CALL getImplementationName() throw(uno::RuntimeException);
      67             :             virtual ::sal_Bool SAL_CALL supportsService(const OUString&) throw(uno::RuntimeException);
      68             :             virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(uno::RuntimeException);
      69             :         };
      70             :     } // end of namespace unorenderer
      71             : } // end of namespace drawinglayer
      72             : 
      73             : //////////////////////////////////////////////////////////////////////////////
      74             : // uno functions
      75             : 
      76             : namespace drawinglayer
      77             : {
      78             :     namespace unorenderer
      79             :     {
      80           4 :         uno::Sequence< OUString > XPrimitive2DRenderer_getSupportedServiceNames()
      81             :         {
      82           4 :             static OUString aServiceName("com.sun.star.graphic.Primitive2DTools" );
      83           4 :             static uno::Sequence< OUString > aServiceNames( &aServiceName, 1 );
      84             : 
      85           4 :             return( aServiceNames );
      86             :         }
      87             : 
      88           8 :         OUString XPrimitive2DRenderer_getImplementationName()
      89             :         {
      90           8 :             return OUString( "drawinglayer::unorenderer::XPrimitive2DRenderer" );
      91             :         }
      92             : 
      93         292 :         uno::Reference< uno::XInterface > SAL_CALL XPrimitive2DRenderer_createInstance(const uno::Reference< lang::XMultiServiceFactory >&)
      94             :         {
      95         292 :             return static_cast< ::cppu::OWeakObject* >(new XPrimitive2DRenderer);
      96             :         }
      97             :     } // end of namespace unorenderer
      98             : } // end of namespace drawinglayer
      99             : 
     100             : //////////////////////////////////////////////////////////////////////////////
     101             : 
     102             : namespace drawinglayer
     103             : {
     104             :     namespace unorenderer
     105             :     {
     106         292 :         XPrimitive2DRenderer::XPrimitive2DRenderer()
     107             :         {
     108         292 :         }
     109             : 
     110         584 :         XPrimitive2DRenderer::~XPrimitive2DRenderer()
     111             :         {
     112         584 :         }
     113             : 
     114         292 :         uno::Reference< rendering::XBitmap > XPrimitive2DRenderer::rasterize(
     115             :             const uno::Sequence< uno::Reference< graphic::XPrimitive2D > >& Primitive2DSequence,
     116             :             const uno::Sequence< beans::PropertyValue >& aViewInformationSequence,
     117             :             ::sal_uInt32 DPI_X,
     118             :             ::sal_uInt32 DPI_Y,
     119             :             const ::com::sun::star::geometry::RealRectangle2D& Range,
     120             :             ::sal_uInt32 MaximumQuadraticPixels) throw (uno::RuntimeException)
     121             :         {
     122         292 :             uno::Reference< rendering::XBitmap > XBitmap;
     123             : 
     124         292 :             if(Primitive2DSequence.hasElements())
     125             :             {
     126         292 :                 const basegfx::B2DRange aRange(Range.X1, Range.Y1, Range.X2, Range.Y2);
     127         292 :                 const double fWidth(aRange.getWidth());
     128         292 :                 const double fHeight(aRange.getHeight());
     129             : 
     130         292 :                 if(basegfx::fTools::more(fWidth, 0.0) && basegfx::fTools::more(fHeight, 0.0))
     131             :                 {
     132         292 :                     if(0 == DPI_X)
     133             :                     {
     134           0 :                         DPI_X = 75;
     135             :                     }
     136             : 
     137         292 :                     if(0 == DPI_Y)
     138             :                     {
     139           0 :                         DPI_Y = 75;
     140             :                     }
     141             : 
     142         292 :                     if(0 == MaximumQuadraticPixels)
     143             :                     {
     144           0 :                         MaximumQuadraticPixels = 500000;
     145             :                     }
     146             : 
     147         292 :                     const geometry::ViewInformation2D aViewInformation2D(aViewInformationSequence);
     148         292 :                     const double fFactor100th_mmToInch(1.0 / (2.54 * 1000.0));
     149         292 :                     const sal_uInt32 nDiscreteWidth(basegfx::fround((fWidth * fFactor100th_mmToInch) * DPI_X));
     150         292 :                     const sal_uInt32 nDiscreteHeight(basegfx::fround((fHeight * fFactor100th_mmToInch) * DPI_Y));
     151             : 
     152             :                     basegfx::B2DHomMatrix aEmbedding(
     153             :                         basegfx::tools::createTranslateB2DHomMatrix(
     154         292 :                             -aRange.getMinX(),
     155         876 :                             -aRange.getMinY()));
     156             : 
     157             :                     aEmbedding.scale(
     158             :                         nDiscreteWidth / fWidth,
     159         292 :                         nDiscreteHeight / fHeight);
     160             : 
     161             :                     const primitive2d::Primitive2DReference xEmbedRef(
     162             :                         new primitive2d::TransformPrimitive2D(
     163             :                             aEmbedding,
     164         584 :                             Primitive2DSequence));
     165         584 :                     const primitive2d::Primitive2DSequence xEmbedSeq(&xEmbedRef, 1);
     166             : 
     167             :                     BitmapEx aBitmapEx(
     168             :                         tools::convertToBitmapEx(
     169             :                             xEmbedSeq,
     170             :                             aViewInformation2D,
     171             :                             nDiscreteWidth,
     172             :                             nDiscreteHeight,
     173         584 :                             MaximumQuadraticPixels));
     174             : 
     175         292 :                     if(!aBitmapEx.IsEmpty())
     176             :                     {
     177         292 :                         const uno::Reference< rendering::XGraphicDevice > xGraphicDevice;
     178             : 
     179         292 :                         aBitmapEx.SetPrefMapMode(MapMode(MAP_100TH_MM));
     180         292 :                         aBitmapEx.SetPrefSize(Size(basegfx::fround(fWidth), basegfx::fround(fHeight)));
     181         292 :                         XBitmap = vcl::unotools::xBitmapFromBitmapEx(xGraphicDevice, aBitmapEx);
     182         292 :                     }
     183             :                 }
     184             :             }
     185             : 
     186         292 :             return XBitmap;
     187             :         }
     188             : 
     189           0 :         OUString SAL_CALL XPrimitive2DRenderer::getImplementationName() throw(uno::RuntimeException)
     190             :         {
     191           0 :             return(XPrimitive2DRenderer_getImplementationName());
     192             :         }
     193             : 
     194           0 :         sal_Bool SAL_CALL XPrimitive2DRenderer::supportsService(const OUString& rServiceName) throw(uno::RuntimeException)
     195             :         {
     196           0 :             const uno::Sequence< OUString > aServices(XPrimitive2DRenderer_getSupportedServiceNames());
     197             : 
     198           0 :             for(sal_Int32 nService(0); nService < aServices.getLength(); nService++)
     199             :             {
     200           0 :                 if(rServiceName == aServices[nService])
     201             :                 {
     202           0 :                     return sal_True;
     203             :                 }
     204             :             }
     205             : 
     206           0 :             return sal_False;
     207             :         }
     208             : 
     209           0 :         uno::Sequence< OUString > SAL_CALL XPrimitive2DRenderer::getSupportedServiceNames() throw(uno::RuntimeException)
     210             :         {
     211           0 :             return XPrimitive2DRenderer_getSupportedServiceNames();
     212             :         }
     213             : 
     214             :     } // end of namespace unorenderer
     215         408 : } // end of namespace drawinglayer
     216             : 
     217             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10