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

Generated by: LCOV version 1.10