LCOV - code coverage report
Current view: top level - canvas/source/tools - parametricpolypolygon.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 79 0.0 %
Date: 2014-04-14 Functions: 0 18 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 <canvas/debug.hxx>
      21             : #include <canvas/canvastools.hxx>
      22             : 
      23             : #include <rtl/math.hxx>
      24             : 
      25             : #include <basegfx/matrix/b2dhommatrix.hxx>
      26             : #include <basegfx/polygon/b2dpolygontools.hxx>
      27             : #include <basegfx/point/b2dpoint.hxx>
      28             : #include <basegfx/range/b2drectangle.hxx>
      29             : #include <basegfx/tools/canvastools.hxx>
      30             : #include <basegfx/numeric/ftools.hxx>
      31             : #include <basegfx/tools/tools.hxx>
      32             : #include <cppuhelper/supportsservice.hxx>
      33             : 
      34             : #include <limits>
      35             : 
      36             : #include <canvas/parametricpolypolygon.hxx>
      37             : 
      38             : using namespace ::com::sun::star;
      39             : 
      40             : namespace canvas
      41             : {
      42           0 :     uno::Sequence<OUString> ParametricPolyPolygon::getAvailableServiceNames()
      43             :     {
      44           0 :         uno::Sequence<OUString> aRet(3);
      45           0 :         aRet[0] = "LinearGradient";
      46           0 :         aRet[1] = "EllipticalGradient";
      47           0 :         aRet[2] = "RectangularGradient";
      48             : 
      49           0 :         return aRet;
      50             :     }
      51             : 
      52           0 :     ParametricPolyPolygon* ParametricPolyPolygon::create(
      53             :         const uno::Reference< rendering::XGraphicDevice >& rDevice,
      54             :         const OUString& rServiceName,
      55             :         const uno::Sequence< uno::Any >& rArgs )
      56             :     {
      57           0 :         uno::Sequence< uno::Sequence< double > > colorSequence(2);
      58           0 :         uno::Sequence< double > colorStops(2);
      59           0 :         double fAspectRatio=1.0;
      60             : 
      61             :         // defaults
      62           0 :         uno::Sequence< rendering::RGBColor > rgbColors(1);
      63           0 :         rgbColors[0] = rendering::RGBColor(0,0,0);
      64           0 :         colorSequence[0] = rDevice->getDeviceColorSpace()->convertFromRGB(rgbColors);
      65           0 :         rgbColors[0] = rendering::RGBColor(1,1,1);
      66           0 :         colorSequence[1] = rDevice->getDeviceColorSpace()->convertFromRGB(rgbColors);
      67           0 :         colorStops[0] = 0;
      68           0 :         colorStops[1] = 1;
      69             : 
      70             :         // extract args
      71           0 :         for( sal_Int32 i=0; i<rArgs.getLength(); ++i )
      72             :         {
      73           0 :             beans::PropertyValue aProp;
      74           0 :             if( (rArgs[i] >>= aProp) )
      75             :             {
      76           0 :                 if ( aProp.Name == "Colors" )
      77             :                 {
      78           0 :                     aProp.Value >>= colorSequence;
      79             :                 }
      80           0 :                 else if ( aProp.Name == "Stops" )
      81             :                 {
      82           0 :                     aProp.Value >>= colorStops;
      83             :                 }
      84           0 :                 else if ( aProp.Name == "AspectRatio" )
      85             :                 {
      86           0 :                     aProp.Value >>= fAspectRatio;
      87             :                 }
      88             :             }
      89           0 :         }
      90             : 
      91           0 :         if ( rServiceName == "LinearGradient" )
      92             :         {
      93           0 :             return createLinearHorizontalGradient(rDevice, colorSequence, colorStops);
      94             :         }
      95           0 :         else if ( rServiceName == "EllipticalGradient" )
      96             :         {
      97           0 :             return createEllipticalGradient(rDevice, colorSequence, colorStops, fAspectRatio);
      98             :         }
      99           0 :         else if ( rServiceName == "RectangularGradient" )
     100             :         {
     101           0 :             return createRectangularGradient(rDevice, colorSequence, colorStops, fAspectRatio);
     102             :         }
     103           0 :         else if ( rServiceName == "VerticalLineHatch" )
     104             :         {
     105             :             // TODO: NYI
     106             :         }
     107           0 :         else if ( rServiceName == "OrthogonalLinesHatch" )
     108             :         {
     109             :             // TODO: NYI
     110             :         }
     111           0 :         else if ( rServiceName == "ThreeCrossingLinesHatch" )
     112             :         {
     113             :             // TODO: NYI
     114             :         }
     115           0 :         else if ( rServiceName == "FourCrossingLinesHatch" )
     116             :         {
     117             :             // TODO: NYI
     118             :         }
     119             : 
     120           0 :         return NULL;
     121             :     }
     122             : 
     123           0 :     ParametricPolyPolygon* ParametricPolyPolygon::createLinearHorizontalGradient(
     124             :         const uno::Reference< rendering::XGraphicDevice >&  rDevice,
     125             :         const uno::Sequence< uno::Sequence< double > >&     colors,
     126             :         const uno::Sequence< double >&                      stops )
     127             :     {
     128             :         // TODO(P2): hold gradient brush statically, and only setup
     129             :         // the colors
     130           0 :         return new ParametricPolyPolygon( rDevice, GRADIENT_LINEAR, colors, stops );
     131             :     }
     132             : 
     133           0 :     ParametricPolyPolygon* ParametricPolyPolygon::createEllipticalGradient(
     134             :         const uno::Reference< rendering::XGraphicDevice >&  rDevice,
     135             :         const uno::Sequence< uno::Sequence< double > >&     colors,
     136             :         const uno::Sequence< double >&                      stops,
     137             :         double                                              fAspectRatio )
     138             :     {
     139             :         // TODO(P2): hold gradient polygon statically, and only setup
     140             :         // the colors
     141             :         return new ParametricPolyPolygon(
     142             :             rDevice,
     143             :             ::basegfx::tools::createPolygonFromCircle(
     144             :                 ::basegfx::B2DPoint(0,0), 1 ),
     145             :             GRADIENT_ELLIPTICAL,
     146           0 :             colors, stops, fAspectRatio );
     147             :     }
     148             : 
     149           0 :     ParametricPolyPolygon* ParametricPolyPolygon::createRectangularGradient( const uno::Reference< rendering::XGraphicDevice >& rDevice,
     150             :                                                                              const uno::Sequence< uno::Sequence< double > >&    colors,
     151             :                                                                              const uno::Sequence< double >&                     stops,
     152             :                                                                              double                                             fAspectRatio )
     153             :     {
     154             :         // TODO(P2): hold gradient polygon statically, and only setup
     155             :         // the colors
     156             :         return new ParametricPolyPolygon(
     157             :             rDevice,
     158             :             ::basegfx::tools::createPolygonFromRect(
     159             :                 ::basegfx::B2DRectangle( -1, -1, 1, 1 ) ),
     160             :             GRADIENT_RECTANGULAR,
     161           0 :             colors, stops, fAspectRatio );
     162             :     }
     163             : 
     164           0 :     void SAL_CALL ParametricPolyPolygon::disposing()
     165             :     {
     166           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     167             : 
     168           0 :         mxDevice.clear();
     169           0 :     }
     170             : 
     171           0 :     uno::Reference< rendering::XPolyPolygon2D > SAL_CALL ParametricPolyPolygon::getOutline( double /*t*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     172             :     {
     173           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     174             : 
     175             :         // TODO(F1): outline NYI
     176           0 :         return uno::Reference< rendering::XPolyPolygon2D >();
     177             :     }
     178             : 
     179           0 :     uno::Sequence< double > SAL_CALL ParametricPolyPolygon::getColor( double /*t*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     180             :     {
     181           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     182             : 
     183             :         // TODO(F1): color NYI
     184           0 :         return uno::Sequence< double >();
     185             :     }
     186             : 
     187           0 :     uno::Sequence< double > SAL_CALL ParametricPolyPolygon::getPointColor( const geometry::RealPoint2D& /*point*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     188             :     {
     189           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     190             : 
     191             :         // TODO(F1): point color NYI
     192           0 :         return uno::Sequence< double >();
     193             :     }
     194             : 
     195           0 :     uno::Reference< rendering::XColorSpace > SAL_CALL ParametricPolyPolygon::getColorSpace() throw (uno::RuntimeException, std::exception)
     196             :     {
     197           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     198             : 
     199           0 :         return mxDevice.is() ? mxDevice->getDeviceColorSpace() : uno::Reference< rendering::XColorSpace >();
     200             :     }
     201             : 
     202             : 
     203           0 :     OUString SAL_CALL ParametricPolyPolygon::getImplementationName(  ) throw (uno::RuntimeException, std::exception)
     204             :     {
     205           0 :         return OUString( "Canvas::ParametricPolyPolygon" );
     206             :     }
     207             : 
     208           0 :     sal_Bool SAL_CALL ParametricPolyPolygon::supportsService( const OUString& ServiceName ) throw (uno::RuntimeException, std::exception)
     209             :     {
     210           0 :         return cppu::supportsService(this, ServiceName);
     211             :     }
     212             : 
     213           0 :     uno::Sequence< OUString > SAL_CALL ParametricPolyPolygon::getSupportedServiceNames(  ) throw (uno::RuntimeException, std::exception)
     214             :     {
     215           0 :         uno::Sequence< OUString > aRet(1);
     216           0 :         aRet[0] = "com.sun.star.rendering.ParametricPolyPolygon";
     217             : 
     218           0 :         return aRet;
     219             :     }
     220             : 
     221           0 :     ParametricPolyPolygon::~ParametricPolyPolygon()
     222             :     {
     223           0 :     }
     224             : 
     225           0 :     ParametricPolyPolygon::ParametricPolyPolygon( const uno::Reference< rendering::XGraphicDevice >&    rDevice,
     226             :                                                   const ::basegfx::B2DPolygon&                          rGradientPoly,
     227             :                                                   GradientType                                          eType,
     228             :                                                   const uno::Sequence< uno::Sequence< double > >&       rColors,
     229             :                                                   const uno::Sequence< double >&                        rStops,
     230             :                                                   double                                                nAspectRatio ) :
     231             :         ParametricPolyPolygon_Base( m_aMutex ),
     232             :         mxDevice( rDevice ),
     233             :         maValues( rGradientPoly,
     234             :                   rColors,
     235             :                   rStops,
     236             :                   nAspectRatio,
     237           0 :                   eType )
     238             :     {
     239           0 :     }
     240             : 
     241           0 :     ParametricPolyPolygon::ParametricPolyPolygon( const uno::Reference< rendering::XGraphicDevice >&    rDevice,
     242             :                                                   GradientType                                          eType,
     243             :                                                   const uno::Sequence< uno::Sequence< double > >&       rColors,
     244             :                                                   const uno::Sequence< double >&                        rStops ) :
     245             :         ParametricPolyPolygon_Base( m_aMutex ),
     246             :         mxDevice( rDevice ),
     247             :         maValues( ::basegfx::B2DPolygon(),
     248             :                   rColors,
     249             :                   rStops,
     250             :                   1.0,
     251           0 :                   eType )
     252             :     {
     253           0 :     }
     254             : 
     255           0 :     ParametricPolyPolygon::Values ParametricPolyPolygon::getValues() const
     256             :     {
     257           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     258             : 
     259           0 :         return maValues;
     260             :     }
     261             : 
     262             : }
     263             : 
     264             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10