LCOV - code coverage report
Current view: top level - drawinglayer/source/texture - texture.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 100 266 37.6 %
Date: 2012-08-25 Functions: 23 60 38.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 65 256 25.4 %

           Branch data     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 <drawinglayer/texture/texture.hxx>
      21                 :            : #include <basegfx/numeric/ftools.hxx>
      22                 :            : #include <basegfx/tools/gradienttools.hxx>
      23                 :            : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      24                 :            : 
      25                 :            : //////////////////////////////////////////////////////////////////////////////
      26                 :            : 
      27                 :            : namespace drawinglayer
      28                 :            : {
      29                 :            :     namespace texture
      30                 :            :     {
      31                 :       1617 :         GeoTexSvx::GeoTexSvx()
      32                 :            :         {
      33                 :       1617 :         }
      34                 :            : 
      35                 :       1617 :         GeoTexSvx::~GeoTexSvx()
      36                 :            :         {
      37         [ -  + ]:       1617 :         }
      38                 :            : 
      39                 :          0 :         bool GeoTexSvx::operator==(const GeoTexSvx& /*rGeoTexSvx*/) const
      40                 :            :         {
      41                 :            :             // default implementation says yes (no data -> no difference)
      42                 :          0 :             return true;
      43                 :            :         }
      44                 :            : 
      45                 :          0 :         void GeoTexSvx::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& /*rMatrices*/)
      46                 :            :         {
      47                 :            :             // default implementation does nothing
      48                 :          0 :         }
      49                 :            : 
      50                 :          0 :         void GeoTexSvx::modifyBColor(const basegfx::B2DPoint& /*rUV*/, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
      51                 :            :         {
      52                 :            :             // base implementation creates random color (for testing only, may also be pure virtual)
      53                 :          0 :             rBColor.setRed((rand() & 0x7fff) / 32767.0);
      54                 :          0 :             rBColor.setGreen((rand() & 0x7fff) / 32767.0);
      55                 :          0 :             rBColor.setBlue((rand() & 0x7fff) / 32767.0);
      56                 :          0 :         }
      57                 :            : 
      58                 :     136536 :         void GeoTexSvx::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
      59                 :            :         {
      60                 :            :             // base implementation uses inverse of luminance of solved color (for testing only, may also be pure virtual)
      61                 :     136536 :             basegfx::BColor aBaseColor;
      62         [ +  - ]:     136536 :             modifyBColor(rUV, aBaseColor, rfOpacity);
      63                 :     136536 :             rfOpacity = 1.0 - aBaseColor.luminance();
      64                 :     136536 :         }
      65                 :            :     } // end of namespace texture
      66                 :            : } // end of namespace drawinglayer
      67                 :            : 
      68                 :            : //////////////////////////////////////////////////////////////////////////////
      69                 :            : 
      70                 :            : namespace drawinglayer
      71                 :            : {
      72                 :            :     namespace texture
      73                 :            :     {
      74                 :     181020 :         void GeoTexSvxGradient::impAppendMatrix(::std::vector< basegfx::B2DHomMatrix >& rMatrices, const basegfx::B2DRange& rRange)
      75                 :            :         {
      76         [ +  - ]:     181020 :             basegfx::B2DHomMatrix aNew;
      77 [ +  - ][ +  - ]:     181020 :             aNew.set(0, 0, rRange.getWidth());
      78 [ +  - ][ +  - ]:     181020 :             aNew.set(1, 1, rRange.getHeight());
      79 [ +  - ][ +  - ]:     181020 :             aNew.set(0, 2, rRange.getMinX());
      80 [ +  - ][ +  - ]:     181020 :             aNew.set(1, 2, rRange.getMinY());
      81 [ +  - ][ +  - ]:     181020 :             rMatrices.push_back(maGradientInfo.maTextureTransform * aNew);
         [ +  - ][ +  - ]
      82                 :     181020 :         }
      83                 :            : 
      84                 :          0 :         void GeoTexSvxGradient::impAppendColorsRadial(::std::vector< basegfx::BColor >& rColors)
      85                 :            :         {
      86         [ #  # ]:          0 :             if(maGradientInfo.mnSteps)
      87                 :            :             {
      88                 :          0 :                 rColors.push_back(maStart);
      89                 :            : 
      90         [ #  # ]:          0 :                 for(sal_uInt32 a(1L); a < maGradientInfo.mnSteps - 1L; a++)
      91                 :            :                 {
      92         [ #  # ]:          0 :                     rColors.push_back(interpolate(maStart, maEnd, (double)a / (double)maGradientInfo.mnSteps));
      93                 :            :                 }
      94                 :            : 
      95                 :          0 :                 rColors.push_back(maEnd);
      96                 :            :             }
      97                 :          0 :         }
      98                 :            : 
      99                 :       1585 :         GeoTexSvxGradient::GeoTexSvxGradient(const basegfx::B2DRange& rTargetRange, const basegfx::BColor& rStart, const basegfx::BColor& rEnd, sal_uInt32 nSteps, double fBorder)
     100                 :            :         :   maTargetRange(rTargetRange),
     101                 :            :             maStart(rStart),
     102                 :            :             maEnd(rEnd),
     103         [ +  - ]:       1585 :             mfBorder(fBorder)
     104                 :            :         {
     105                 :       1585 :             maGradientInfo.mnSteps = nSteps;
     106                 :       1585 :             maGradientInfo.mfAspectRatio = 1.0;
     107                 :       1585 :         }
     108                 :            : 
     109         [ +  - ]:       1585 :         GeoTexSvxGradient::~GeoTexSvxGradient()
     110                 :            :         {
     111         [ -  + ]:       1585 :         }
     112                 :            : 
     113                 :          0 :         bool GeoTexSvxGradient::operator==(const GeoTexSvx& rGeoTexSvx) const
     114                 :            :         {
     115         [ #  # ]:          0 :             const GeoTexSvxGradient* pCompare = dynamic_cast< const GeoTexSvxGradient* >(&rGeoTexSvx);
     116                 :            :             return (pCompare
     117                 :          0 :                 && maGradientInfo.maTextureTransform == pCompare->maGradientInfo.maTextureTransform
     118                 :          0 :                 && maTargetRange == pCompare->maTargetRange
     119                 :            :                 && maGradientInfo.mnSteps == pCompare->maGradientInfo.mnSteps
     120                 :            :                 && maGradientInfo.mfAspectRatio == pCompare->maGradientInfo.mfAspectRatio
     121   [ #  #  #  #  :          0 :                 && mfBorder == pCompare->mfBorder);
           #  # ][ #  # ]
         [ #  # ][ #  # ]
     122                 :            :         }
     123                 :            :     } // end of namespace texture
     124                 :            : } // end of namespace drawinglayer
     125                 :            : 
     126                 :            : //////////////////////////////////////////////////////////////////////////////
     127                 :            : 
     128                 :            : namespace drawinglayer
     129                 :            : {
     130                 :            :     namespace texture
     131                 :            :     {
     132                 :       1248 :         GeoTexSvxGradientLinear::GeoTexSvxGradientLinear(const basegfx::B2DRange& rTargetRange, const basegfx::BColor& rStart, const basegfx::BColor& rEnd, sal_uInt32 nSteps, double fBorder, double fAngle)
     133                 :       1248 :         :   GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder)
     134                 :            :         {
     135                 :            :             basegfx::tools::createLinearODFGradientInfo(maGradientInfo,
     136                 :            :                                                         rTargetRange,
     137                 :            :                                                         nSteps,
     138                 :            :                                                         fBorder,
     139         [ +  - ]:       1248 :                                                         fAngle);
     140                 :       1248 :         }
     141                 :            : 
     142                 :       1248 :         GeoTexSvxGradientLinear::~GeoTexSvxGradientLinear()
     143                 :            :         {
     144         [ -  + ]:       1256 :         }
     145                 :            : 
     146                 :       1240 :         void GeoTexSvxGradientLinear::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices)
     147                 :            :         {
     148         [ +  - ]:       1240 :             if(maGradientInfo.mnSteps)
     149                 :            :             {
     150                 :       1240 :                 const double fStripeWidth(1.0 / maGradientInfo.mnSteps);
     151         [ +  + ]:     140810 :                 for(sal_uInt32 a(1L); a < maGradientInfo.mnSteps; a++)
     152                 :            :                 {
     153         [ +  - ]:     139570 :                     const basegfx::B2DRange aRect(0.0, fStripeWidth * a, 1.0, 1.0);
     154         [ +  - ]:     139570 :                     impAppendMatrix(rMatrices, aRect);
     155                 :            :                 }
     156                 :            :             }
     157                 :       1240 :         }
     158                 :            : 
     159                 :       1240 :         void GeoTexSvxGradientLinear::appendColors(::std::vector< basegfx::BColor >& rColors)
     160                 :            :         {
     161         [ +  - ]:       1240 :             if(maGradientInfo.mnSteps)
     162                 :            :             {
     163                 :       1240 :                 rColors.push_back(maStart);
     164                 :            : 
     165         [ +  + ]:     140810 :                 for(sal_uInt32 a(1L); a < maGradientInfo.mnSteps; a++)
     166                 :            :                 {
     167         [ +  - ]:     139570 :                     rColors.push_back(interpolate(maStart, maEnd, (double)a / (double)(maGradientInfo.mnSteps + 1L)));
     168                 :            :                 }
     169                 :            :             }
     170                 :       1240 :         }
     171                 :            : 
     172                 :      68762 :         void GeoTexSvxGradientLinear::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
     173                 :            :         {
     174                 :      68762 :             const double fScaler(basegfx::tools::getLinearGradientAlpha(rUV, maGradientInfo));
     175                 :            : 
     176                 :      68762 :             rBColor = (maStart * (1.0 - fScaler)) + (maEnd * fScaler);
     177                 :      68762 :         }
     178                 :            :     } // end of namespace texture
     179                 :            : } // end of namespace drawinglayer
     180                 :            : 
     181                 :            : //////////////////////////////////////////////////////////////////////////////
     182                 :            : 
     183                 :            : namespace drawinglayer
     184                 :            : {
     185                 :            :     namespace texture
     186                 :            :     {
     187                 :        337 :         GeoTexSvxGradientAxial::GeoTexSvxGradientAxial(const basegfx::B2DRange& rTargetRange, const basegfx::BColor& rStart, const basegfx::BColor& rEnd, sal_uInt32 nSteps, double fBorder, double fAngle)
     188                 :        337 :         :   GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder)
     189                 :            :         {
     190                 :            :             basegfx::tools::createAxialODFGradientInfo(maGradientInfo,
     191                 :            :                                                        rTargetRange,
     192                 :            :                                                        nSteps,
     193                 :            :                                                        fBorder,
     194         [ +  - ]:        337 :                                                        fAngle);
     195                 :        337 :         }
     196                 :            : 
     197                 :        337 :         GeoTexSvxGradientAxial::~GeoTexSvxGradientAxial()
     198                 :            :         {
     199         [ -  + ]:        345 :         }
     200                 :            : 
     201                 :        329 :         void GeoTexSvxGradientAxial::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices)
     202                 :            :         {
     203         [ +  - ]:        329 :             if(maGradientInfo.mnSteps)
     204                 :            :             {
     205                 :        329 :                 const double fStripeWidth=1.0 / (maGradientInfo.mnSteps - 1L);
     206         [ +  + ]:      41779 :                 for(sal_uInt32 a(maGradientInfo.mnSteps-1L); a != 0; a--)
     207                 :            :                 {
     208         [ +  - ]:      41450 :                     const basegfx::B2DRange aRect(0, 0, 1.0, fStripeWidth * a);
     209         [ +  - ]:      41450 :                     impAppendMatrix(rMatrices, aRect);
     210                 :            :                 }
     211                 :            :             }
     212                 :        329 :         }
     213                 :            : 
     214                 :        329 :         void GeoTexSvxGradientAxial::appendColors(::std::vector< basegfx::BColor >& rColors)
     215                 :            :         {
     216         [ +  - ]:        329 :             if(maGradientInfo.mnSteps)
     217                 :            :             {
     218                 :        329 :                 rColors.push_back(maEnd);
     219                 :            : 
     220         [ +  + ]:      41779 :                 for(sal_uInt32 a(1L); a < maGradientInfo.mnSteps; a++)
     221                 :            :                 {
     222         [ +  - ]:      41450 :                     rColors.push_back(interpolate(maEnd, maStart, (double)a / (double)maGradientInfo.mnSteps));
     223                 :            :                 }
     224                 :            :             }
     225                 :        329 :         }
     226                 :            : 
     227                 :      67774 :         void GeoTexSvxGradientAxial::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
     228                 :            :         {
     229                 :      67774 :             const double fScaler(basegfx::tools::getAxialGradientAlpha(rUV, maGradientInfo));
     230                 :            : 
     231                 :      67774 :             rBColor = (maStart * (1.0 - fScaler)) + (maEnd * fScaler);
     232                 :      67774 :         }
     233                 :            :     } // end of namespace texture
     234                 :            : } // end of namespace drawinglayer
     235                 :            : 
     236                 :            : //////////////////////////////////////////////////////////////////////////////
     237                 :            : 
     238                 :            : namespace drawinglayer
     239                 :            : {
     240                 :            :     namespace texture
     241                 :            :     {
     242                 :          0 :         GeoTexSvxGradientRadial::GeoTexSvxGradientRadial(const basegfx::B2DRange& rTargetRange, const basegfx::BColor& rStart, const basegfx::BColor& rEnd, sal_uInt32 nSteps, double fBorder, double fOffsetX, double fOffsetY)
     243                 :          0 :         :   GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder)
     244                 :            :         {
     245                 :            :             basegfx::tools::createRadialODFGradientInfo(maGradientInfo,
     246                 :            :                                                         rTargetRange,
     247                 :            :                                                         basegfx::B2DVector(fOffsetX,fOffsetY),
     248                 :            :                                                         nSteps,
     249         [ #  # ]:          0 :                                                         fBorder);
     250                 :          0 :         }
     251                 :            : 
     252                 :          0 :         GeoTexSvxGradientRadial::~GeoTexSvxGradientRadial()
     253                 :            :         {
     254         [ #  # ]:          0 :         }
     255                 :            : 
     256                 :          0 :         void GeoTexSvxGradientRadial::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices)
     257                 :            :         {
     258         [ #  # ]:          0 :             if(maGradientInfo.mnSteps)
     259                 :            :             {
     260                 :          0 :                 const double fStepSize=1.0 / maGradientInfo.mnSteps;
     261         [ #  # ]:          0 :                 for(sal_uInt32 a(maGradientInfo.mnSteps-1L); a > 0; a--)
     262                 :            :                 {
     263         [ #  # ]:          0 :                     const basegfx::B2DRange aRect(0, 0, fStepSize*a, fStepSize*a);
     264         [ #  # ]:          0 :                     impAppendMatrix(rMatrices, aRect);
     265                 :            :                 }
     266                 :            :             }
     267                 :          0 :         }
     268                 :            : 
     269                 :          0 :         void GeoTexSvxGradientRadial::appendColors(::std::vector< basegfx::BColor >& rColors)
     270                 :            :         {
     271                 :          0 :             impAppendColorsRadial(rColors);
     272                 :          0 :         }
     273                 :            : 
     274                 :          0 :         void GeoTexSvxGradientRadial::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
     275                 :            :         {
     276                 :          0 :             const double fScaler(basegfx::tools::getRadialGradientAlpha(rUV, maGradientInfo));
     277                 :            : 
     278                 :          0 :             rBColor = (maStart * (1.0 - fScaler)) + (maEnd * fScaler);
     279                 :          0 :         }
     280                 :            :     } // end of namespace texture
     281                 :            : } // end of namespace drawinglayer
     282                 :            : 
     283                 :            : //////////////////////////////////////////////////////////////////////////////
     284                 :            : 
     285                 :            : namespace drawinglayer
     286                 :            : {
     287                 :            :     namespace texture
     288                 :            :     {
     289                 :          0 :         GeoTexSvxGradientElliptical::GeoTexSvxGradientElliptical(const basegfx::B2DRange& rTargetRange, const basegfx::BColor& rStart, const basegfx::BColor& rEnd, sal_uInt32 nSteps, double fBorder, double fOffsetX, double fOffsetY, double fAngle)
     290                 :          0 :         :   GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder)
     291                 :            :         {
     292                 :            :             basegfx::tools::createEllipticalODFGradientInfo(maGradientInfo,
     293                 :            :                                                             rTargetRange,
     294                 :            :                                                             basegfx::B2DVector(fOffsetX,fOffsetY),
     295                 :            :                                                             nSteps,
     296                 :            :                                                             fBorder,
     297         [ #  # ]:          0 :                                                             fAngle);
     298                 :          0 :         }
     299                 :            : 
     300                 :          0 :         GeoTexSvxGradientElliptical::~GeoTexSvxGradientElliptical()
     301                 :            :         {
     302         [ #  # ]:          0 :         }
     303                 :            : 
     304                 :          0 :         void GeoTexSvxGradientElliptical::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices)
     305                 :            :         {
     306         [ #  # ]:          0 :             if(maGradientInfo.mnSteps)
     307                 :            :             {
     308                 :          0 :                 double fWidth(1);
     309                 :          0 :                 double fHeight(1);
     310                 :            :                 double fIncrementX, fIncrementY;
     311                 :            : 
     312         [ #  # ]:          0 :                 if(maGradientInfo.mfAspectRatio > 1.0)
     313                 :            :                 {
     314                 :          0 :                     fIncrementY = fHeight / maGradientInfo.mnSteps;
     315                 :          0 :                     fIncrementX = fIncrementY / maGradientInfo.mfAspectRatio;
     316                 :            :                 }
     317                 :            :                 else
     318                 :            :                 {
     319                 :          0 :                     fIncrementX = fWidth / maGradientInfo.mnSteps;
     320                 :          0 :                     fIncrementY = fIncrementX * maGradientInfo.mfAspectRatio;
     321                 :            :                 }
     322                 :            : 
     323         [ #  # ]:          0 :                 for(sal_uInt32 a(1L); a < maGradientInfo.mnSteps; a++)
     324                 :            :                 {
     325                 :            :                     // next step
     326                 :          0 :                     fWidth  -= fIncrementX;
     327                 :          0 :                     fHeight -= fIncrementY;
     328                 :            : 
     329                 :            :                     // create matrix
     330         [ #  # ]:          0 :                     const basegfx::B2DRange aRect(0, 0, fWidth, fHeight);
     331         [ #  # ]:          0 :                     impAppendMatrix(rMatrices, aRect);
     332                 :            :                 }
     333                 :            :             }
     334                 :          0 :         }
     335                 :            : 
     336                 :          0 :         void GeoTexSvxGradientElliptical::appendColors(::std::vector< basegfx::BColor >& rColors)
     337                 :            :         {
     338                 :          0 :             impAppendColorsRadial(rColors);
     339                 :          0 :         }
     340                 :            : 
     341                 :          0 :         void GeoTexSvxGradientElliptical::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
     342                 :            :         {
     343                 :          0 :             const double fScaler(basegfx::tools::getEllipticalGradientAlpha(rUV, maGradientInfo));
     344                 :            : 
     345                 :          0 :             rBColor = (maStart * (1.0 - fScaler)) + (maEnd * fScaler);
     346                 :          0 :         }
     347                 :            :     } // end of namespace texture
     348                 :            : } // end of namespace drawinglayer
     349                 :            : 
     350                 :            : //////////////////////////////////////////////////////////////////////////////
     351                 :            : 
     352                 :            : namespace drawinglayer
     353                 :            : {
     354                 :            :     namespace texture
     355                 :            :     {
     356                 :          0 :         GeoTexSvxGradientSquare::GeoTexSvxGradientSquare(const basegfx::B2DRange& rTargetRange, const basegfx::BColor& rStart, const basegfx::BColor& rEnd, sal_uInt32 nSteps, double fBorder, double fOffsetX, double fOffsetY, double fAngle)
     357                 :          0 :         :   GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder)
     358                 :            :         {
     359                 :            :             basegfx::tools::createSquareODFGradientInfo(maGradientInfo,
     360                 :            :                                                         rTargetRange,
     361                 :            :                                                         basegfx::B2DVector(fOffsetX,fOffsetY),
     362                 :            :                                                         nSteps,
     363                 :            :                                                         fBorder,
     364         [ #  # ]:          0 :                                                         fAngle);
     365                 :          0 :         }
     366                 :            : 
     367                 :          0 :         GeoTexSvxGradientSquare::~GeoTexSvxGradientSquare()
     368                 :            :         {
     369         [ #  # ]:          0 :         }
     370                 :            : 
     371                 :          0 :         void GeoTexSvxGradientSquare::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices)
     372                 :            :         {
     373         [ #  # ]:          0 :             if(maGradientInfo.mnSteps)
     374                 :            :             {
     375                 :          0 :                 const double fStepSize=1.0 / maGradientInfo.mnSteps;
     376         [ #  # ]:          0 :                 for(sal_uInt32 a(maGradientInfo.mnSteps-1L); a > 0; a--)
     377                 :            :                 {
     378         [ #  # ]:          0 :                     const basegfx::B2DRange aRect(0, 0, fStepSize*a, fStepSize*a);
     379         [ #  # ]:          0 :                     impAppendMatrix(rMatrices, aRect);
     380                 :            :                 }
     381                 :            :             }
     382                 :          0 :         }
     383                 :            : 
     384                 :          0 :         void GeoTexSvxGradientSquare::appendColors(::std::vector< basegfx::BColor >& rColors)
     385                 :            :         {
     386                 :          0 :             impAppendColorsRadial(rColors);
     387                 :          0 :         }
     388                 :            : 
     389                 :          0 :         void GeoTexSvxGradientSquare::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
     390                 :            :         {
     391                 :          0 :             const double fScaler(basegfx::tools::getSquareGradientAlpha(rUV, maGradientInfo));
     392                 :            : 
     393                 :          0 :             rBColor = (maStart * (1.0 - fScaler)) + (maEnd * fScaler);
     394                 :          0 :         }
     395                 :            :     } // end of namespace texture
     396                 :            : } // end of namespace drawinglayer
     397                 :            : 
     398                 :            : //////////////////////////////////////////////////////////////////////////////
     399                 :            : 
     400                 :            : namespace drawinglayer
     401                 :            : {
     402                 :            :     namespace texture
     403                 :            :     {
     404                 :          0 :         GeoTexSvxGradientRect::GeoTexSvxGradientRect(const basegfx::B2DRange& rTargetRange, const basegfx::BColor& rStart, const basegfx::BColor& rEnd, sal_uInt32 nSteps, double fBorder, double fOffsetX, double fOffsetY, double fAngle)
     405                 :          0 :         :   GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder)
     406                 :            :         {
     407                 :            :             basegfx::tools::createRectangularODFGradientInfo(maGradientInfo,
     408                 :            :                                                              rTargetRange,
     409                 :            :                                                              basegfx::B2DVector(fOffsetX,fOffsetY),
     410                 :            :                                                              nSteps,
     411                 :            :                                                              fBorder,
     412         [ #  # ]:          0 :                                                              fAngle);
     413                 :          0 :         }
     414                 :            : 
     415                 :          0 :         GeoTexSvxGradientRect::~GeoTexSvxGradientRect()
     416                 :            :         {
     417         [ #  # ]:          0 :         }
     418                 :            : 
     419                 :          0 :         void GeoTexSvxGradientRect::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices)
     420                 :            :         {
     421         [ #  # ]:          0 :             if(maGradientInfo.mnSteps)
     422                 :            :             {
     423                 :          0 :                 double fWidth(1);
     424                 :          0 :                 double fHeight(1);
     425                 :            :                 double fIncrementX, fIncrementY;
     426                 :            : 
     427         [ #  # ]:          0 :                 if(maGradientInfo.mfAspectRatio > 1.0)
     428                 :            :                 {
     429                 :          0 :                     fIncrementY = fHeight / maGradientInfo.mnSteps;
     430                 :          0 :                     fIncrementX = fIncrementY / maGradientInfo.mfAspectRatio;
     431                 :            :                 }
     432                 :            :                 else
     433                 :            :                 {
     434                 :          0 :                     fIncrementX = fWidth / maGradientInfo.mnSteps;
     435                 :          0 :                     fIncrementY = fIncrementX * maGradientInfo.mfAspectRatio;
     436                 :            :                 }
     437                 :            : 
     438         [ #  # ]:          0 :                 for(sal_uInt32 a(1L); a < maGradientInfo.mnSteps; a++)
     439                 :            :                 {
     440                 :            :                     // next step
     441                 :          0 :                     fWidth  -= fIncrementX;
     442                 :          0 :                     fHeight -= fIncrementY;
     443                 :            : 
     444                 :            :                     // create matrix
     445         [ #  # ]:          0 :                     const basegfx::B2DRange aRect(0, 0, fWidth, fHeight);
     446         [ #  # ]:          0 :                     impAppendMatrix(rMatrices, aRect);
     447                 :            :                 }
     448                 :            :             }
     449                 :          0 :         }
     450                 :            : 
     451                 :          0 :         void GeoTexSvxGradientRect::appendColors(::std::vector< basegfx::BColor >& rColors)
     452                 :            :         {
     453                 :          0 :             impAppendColorsRadial(rColors);
     454                 :          0 :         }
     455                 :            : 
     456                 :          0 :         void GeoTexSvxGradientRect::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
     457                 :            :         {
     458                 :          0 :             const double fScaler(basegfx::tools::getRectangularGradientAlpha(rUV, maGradientInfo));
     459                 :            : 
     460                 :          0 :             rBColor = (maStart * (1.0 - fScaler)) + (maEnd * fScaler);
     461                 :          0 :         }
     462                 :            :     } // end of namespace texture
     463                 :            : } // end of namespace drawinglayer
     464                 :            : 
     465                 :            : //////////////////////////////////////////////////////////////////////////////
     466                 :            : 
     467                 :            : namespace drawinglayer
     468                 :            : {
     469                 :            :     namespace texture
     470                 :            :     {
     471                 :         24 :         GeoTexSvxHatch::GeoTexSvxHatch(const basegfx::B2DRange& rTargetRange, double fDistance, double fAngle)
     472                 :            :         :   mfDistance(0.1),
     473                 :            :             mfAngle(fAngle),
     474 [ +  - ][ +  - ]:         24 :             mnSteps(10L)
     475                 :            :         {
     476         [ +  - ]:         24 :             double fTargetSizeX(rTargetRange.getWidth());
     477         [ +  - ]:         24 :             double fTargetSizeY(rTargetRange.getHeight());
     478         [ +  - ]:         24 :             double fTargetOffsetX(rTargetRange.getMinX());
     479         [ +  - ]:         24 :             double fTargetOffsetY(rTargetRange.getMinY());
     480                 :            : 
     481                 :         24 :             fAngle = -fAngle;
     482                 :            : 
     483                 :            :             // add object expansion
     484         [ -  + ]:         24 :             if(0.0 != fAngle)
     485                 :            :             {
     486                 :          0 :                 const double fAbsCos(fabs(cos(fAngle)));
     487                 :          0 :                 const double fAbsSin(fabs(sin(fAngle)));
     488                 :          0 :                 const double fNewX(fTargetSizeX * fAbsCos + fTargetSizeY * fAbsSin);
     489                 :          0 :                 const double fNewY(fTargetSizeY * fAbsCos + fTargetSizeX * fAbsSin);
     490                 :          0 :                 fTargetOffsetX -= (fNewX - fTargetSizeX) / 2.0;
     491                 :          0 :                 fTargetOffsetY -= (fNewY - fTargetSizeY) / 2.0;
     492                 :          0 :                 fTargetSizeX = fNewX;
     493                 :          0 :                 fTargetSizeY = fNewY;
     494                 :            :             }
     495                 :            : 
     496                 :            :             // add object scale before rotate
     497         [ +  - ]:         24 :             maTextureTransform.scale(fTargetSizeX, fTargetSizeY);
     498                 :            : 
     499                 :            :             // add texture rotate after scale to keep perpendicular angles
     500         [ -  + ]:         24 :             if(0.0 != fAngle)
     501                 :            :             {
     502                 :          0 :                 basegfx::B2DPoint aCenter(0.5, 0.5);
     503         [ #  # ]:          0 :                 aCenter *= maTextureTransform;
     504                 :            : 
     505                 :            :                 maTextureTransform = basegfx::tools::createRotateAroundPoint(aCenter, fAngle)
     506 [ #  # ][ #  # ]:          0 :                     * maTextureTransform;
         [ #  # ][ #  # ]
                 [ #  # ]
     507                 :            :             }
     508                 :            : 
     509                 :            :             // add object translate
     510         [ +  - ]:         24 :             maTextureTransform.translate(fTargetOffsetX, fTargetOffsetY);
     511                 :            : 
     512                 :            :             // prepare height for texture
     513         [ +  - ]:         24 :             const double fSteps((0.0 != fDistance) ? fTargetSizeY / fDistance : 10.0);
     514                 :         24 :             mnSteps = basegfx::fround(fSteps + 0.5);
     515                 :         24 :             mfDistance = 1.0 / fSteps;
     516                 :            : 
     517                 :            :             // build transform from u,v to [0.0 .. 1.0]. As base, use inverse texture transform
     518         [ +  - ]:         24 :             maBackTextureTransform = maTextureTransform;
     519         [ +  - ]:         24 :             maBackTextureTransform.invert();
     520                 :         24 :         }
     521                 :            : 
     522 [ +  - ][ +  - ]:         24 :         GeoTexSvxHatch::~GeoTexSvxHatch()
     523                 :            :         {
     524         [ -  + ]:         32 :         }
     525                 :            : 
     526                 :          0 :         bool GeoTexSvxHatch::operator==(const GeoTexSvx& rGeoTexSvx) const
     527                 :            :         {
     528         [ #  # ]:          0 :             const GeoTexSvxHatch* pCompare = dynamic_cast< const GeoTexSvxHatch* >(&rGeoTexSvx);
     529                 :            :             return (pCompare
     530                 :          0 :                 && maTextureTransform == pCompare->maTextureTransform
     531                 :            :                 && mfDistance == pCompare->mfDistance
     532                 :            :                 && mfAngle == pCompare->mfAngle
     533   [ #  #  #  # ]:          0 :                 && mnSteps == pCompare->mnSteps);
         [ #  # ][ #  # ]
                 [ #  # ]
     534                 :            :         }
     535                 :            : 
     536                 :         16 :         void GeoTexSvxHatch::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices)
     537                 :            :         {
     538         [ +  + ]:        752 :             for(sal_uInt32 a(1L); a < mnSteps; a++)
     539                 :            :             {
     540                 :            :                 // create matrix
     541                 :        736 :                 const double fOffset(mfDistance * (double)a);
     542         [ +  - ]:        736 :                 basegfx::B2DHomMatrix aNew;
     543         [ +  - ]:        736 :                 aNew.set(1, 2, fOffset);
     544 [ +  - ][ +  - ]:        736 :                 rMatrices.push_back(maTextureTransform * aNew);
                 [ +  - ]
     545         [ +  - ]:        736 :             }
     546                 :         16 :         }
     547                 :            : 
     548                 :      47800 :         double GeoTexSvxHatch::getDistanceToHatch(const basegfx::B2DPoint& rUV) const
     549                 :            :         {
     550         [ +  - ]:      47800 :             const basegfx::B2DPoint aCoor(maBackTextureTransform * rUV);
     551                 :      47800 :             return fmod(aCoor.getY(), mfDistance);
     552                 :            :         }
     553                 :            :     } // end of namespace texture
     554                 :            : } // end of namespace drawinglayer
     555                 :            : 
     556                 :            : //////////////////////////////////////////////////////////////////////////////
     557                 :            : 
     558                 :            : namespace drawinglayer
     559                 :            : {
     560                 :            :     namespace texture
     561                 :            :     {
     562                 :          0 :         GeoTexSvxTiled::GeoTexSvxTiled(const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize)
     563                 :            :         :   maTopLeft(rTopLeft),
     564                 :          0 :             maSize(rSize)
     565                 :            :         {
     566         [ #  # ]:          0 :             if(basegfx::fTools::lessOrEqual(maSize.getX(), 0.0))
     567                 :            :             {
     568                 :          0 :                 maSize.setX(1.0);
     569                 :            :             }
     570                 :            : 
     571         [ #  # ]:          0 :             if(basegfx::fTools::lessOrEqual(maSize.getY(), 0.0))
     572                 :            :             {
     573                 :          0 :                 maSize.setY(1.0);
     574                 :            :             }
     575                 :          0 :         }
     576                 :            : 
     577                 :          0 :         GeoTexSvxTiled::~GeoTexSvxTiled()
     578                 :            :         {
     579         [ #  # ]:          0 :         }
     580                 :            : 
     581                 :          0 :         bool GeoTexSvxTiled::operator==(const GeoTexSvx& rGeoTexSvx) const
     582                 :            :         {
     583         [ #  # ]:          0 :             const GeoTexSvxTiled* pCompare = dynamic_cast< const GeoTexSvxTiled* >(&rGeoTexSvx);
     584                 :            :             return (pCompare
     585                 :          0 :                 && maTopLeft == pCompare->maTopLeft
     586   [ #  #  #  # ]:          0 :                 && maSize == pCompare->maSize);
                 [ #  # ]
     587                 :            :         }
     588                 :            : 
     589                 :          0 :         void GeoTexSvxTiled::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices)
     590                 :            :         {
     591                 :          0 :             double fStartX(maTopLeft.getX());
     592                 :          0 :             double fStartY(maTopLeft.getY());
     593                 :            : 
     594         [ #  # ]:          0 :             if(basegfx::fTools::more(fStartX, 0.0))
     595                 :            :             {
     596                 :          0 :                 fStartX -= (floor(fStartX / maSize.getX()) + 1.0) * maSize.getX();
     597                 :            :             }
     598                 :            : 
     599         [ #  # ]:          0 :             if(basegfx::fTools::less(fStartX + maSize.getX(), 0.0))
     600                 :            :             {
     601                 :          0 :                 fStartX += floor(-fStartX / maSize.getX()) * maSize.getX();
     602                 :            :             }
     603                 :            : 
     604         [ #  # ]:          0 :             if(basegfx::fTools::more(fStartY, 0.0))
     605                 :            :             {
     606                 :          0 :                 fStartY -= (floor(fStartY / maSize.getY()) + 1.0) * maSize.getY();
     607                 :            :             }
     608                 :            : 
     609         [ #  # ]:          0 :             if(basegfx::fTools::less(fStartY + maSize.getY(), 0.0))
     610                 :            :             {
     611                 :          0 :                 fStartY += floor(-fStartY / maSize.getY()) * maSize.getY();
     612                 :            :             }
     613                 :            : 
     614         [ #  # ]:          0 :             for(double fPosY(fStartY); basegfx::fTools::less(fPosY, 1.0); fPosY += maSize.getY())
     615                 :            :             {
     616         [ #  # ]:          0 :                 for(double fPosX(fStartX); basegfx::fTools::less(fPosX, 1.0); fPosX += maSize.getX())
     617                 :            :                 {
     618         [ #  # ]:          0 :                     basegfx::B2DHomMatrix aNew;
     619                 :            : 
     620         [ #  # ]:          0 :                     aNew.set(0, 0, maSize.getX());
     621         [ #  # ]:          0 :                     aNew.set(1, 1, maSize.getY());
     622         [ #  # ]:          0 :                     aNew.set(0, 2, fPosX);
     623         [ #  # ]:          0 :                     aNew.set(1, 2, fPosY);
     624                 :            : 
     625         [ #  # ]:          0 :                     rMatrices.push_back(aNew);
     626         [ #  # ]:          0 :                 }
     627                 :            :             }
     628                 :          0 :         }
     629                 :            :     } // end of namespace texture
     630                 :            : } // end of namespace drawinglayer
     631                 :            : 
     632                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10