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

Generated by: LCOV version 1.11