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

Generated by: LCOV version 1.10