LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/drawinglayer/source/texture - texture.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 94 282 33.3 %
Date: 2013-07-09 Functions: 21 52 40.4 %
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 <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         734 :         GeoTexSvx::GeoTexSvx()
      32             :         {
      33         734 :         }
      34             : 
      35         734 :         GeoTexSvx::~GeoTexSvx()
      36             :         {
      37         734 :         }
      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::modifyBColor(const basegfx::B2DPoint& /*rUV*/, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
      46             :         {
      47             :             // base implementation creates random color (for testing only, may also be pure virtual)
      48           0 :             rBColor.setRed((rand() & 0x7fff) / 32767.0);
      49           0 :             rBColor.setGreen((rand() & 0x7fff) / 32767.0);
      50           0 :             rBColor.setBlue((rand() & 0x7fff) / 32767.0);
      51           0 :         }
      52             : 
      53      136528 :         void GeoTexSvx::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
      54             :         {
      55             :             // base implementation uses inverse of luminance of solved color (for testing only, may also be pure virtual)
      56      136528 :             basegfx::BColor aBaseColor;
      57      136528 :             modifyBColor(rUV, aBaseColor, rfOpacity);
      58      136528 :             rfOpacity = 1.0 - aBaseColor.luminance();
      59      136528 :         }
      60             :     } // end of namespace texture
      61             : } // end of namespace drawinglayer
      62             : 
      63             : //////////////////////////////////////////////////////////////////////////////
      64             : 
      65             : namespace drawinglayer
      66             : {
      67             :     namespace texture
      68             :     {
      69         702 :         GeoTexSvxGradient::GeoTexSvxGradient(
      70             :             const basegfx::B2DRange& rTargetRange,
      71             :             const basegfx::BColor& rStart,
      72             :             const basegfx::BColor& rEnd,
      73             :             sal_uInt32 /* nSteps */,
      74             :             double fBorder)
      75             :         :   GeoTexSvx(),
      76             :             maGradientInfo(),
      77             :             maTargetRange(rTargetRange),
      78             :             maStart(rStart),
      79             :             maEnd(rEnd),
      80         702 :             mfBorder(fBorder)
      81             :         {
      82         702 :         }
      83             : 
      84         702 :         GeoTexSvxGradient::~GeoTexSvxGradient()
      85             :         {
      86         702 :         }
      87             : 
      88           0 :         bool GeoTexSvxGradient::operator==(const GeoTexSvx& rGeoTexSvx) const
      89             :         {
      90           0 :             const GeoTexSvxGradient* pCompare = dynamic_cast< const GeoTexSvxGradient* >(&rGeoTexSvx);
      91             : 
      92             :             return (pCompare
      93           0 :                 && maGradientInfo == pCompare->maGradientInfo
      94           0 :                 && maTargetRange == pCompare->maTargetRange
      95           0 :                 && mfBorder == pCompare->mfBorder);
      96             :         }
      97             :     } // end of namespace texture
      98             : } // end of namespace drawinglayer
      99             : 
     100             : //////////////////////////////////////////////////////////////////////////////
     101             : 
     102             : namespace drawinglayer
     103             : {
     104             :     namespace texture
     105             :     {
     106         544 :         GeoTexSvxGradientLinear::GeoTexSvxGradientLinear(
     107             :             const basegfx::B2DRange& rTargetRange,
     108             :             const basegfx::BColor& rStart,
     109             :             const basegfx::BColor& rEnd,
     110             :             sal_uInt32 nSteps,
     111             :             double fBorder,
     112             :             double fAngle)
     113         544 :         :   GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder)
     114             :         {
     115        1088 :             maGradientInfo = basegfx::tools::createLinearODFGradientInfo(
     116             :                 rTargetRange,
     117             :                 nSteps,
     118             :                 fBorder,
     119         544 :                 fAngle);
     120         544 :         }
     121             : 
     122         552 :         GeoTexSvxGradientLinear::~GeoTexSvxGradientLinear()
     123             :         {
     124         552 :         }
     125             : 
     126         536 :         void GeoTexSvxGradientLinear::appendTransformationsAndColors(
     127             :             std::vector< B2DHomMatrixAndBColor >& rEntries,
     128             :             basegfx::BColor& rOutmostColor)
     129             :         {
     130         536 :             rOutmostColor = maStart;
     131             : 
     132         536 :             if(maGradientInfo.getSteps())
     133             :             {
     134         536 :                 const double fStripeWidth(1.0 / maGradientInfo.getSteps());
     135         536 :                 B2DHomMatrixAndBColor aB2DHomMatrixAndBColor;
     136             : 
     137       68608 :                 for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++)
     138             :                 {
     139       68072 :                     const double fPos(fStripeWidth * a);
     140             :                     // optimized below...
     141             :                     //
     142             :                     // basegfx::B2DHomMatrix aNew;
     143             :                     // aNew.scale(0.5, 0.5);
     144             :                     // aNew.translate(0.5, 0.5);
     145             :                     // aNew.scale(1.0, (1.0 - fPos));
     146             :                     // aNew.translate(0.0, fPos);
     147             :                     // aNew = maGradientInfo.getTextureTransform() * aNew;
     148      204216 :                     aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() *
     149      204216 :                         basegfx::tools::createScaleTranslateB2DHomMatrix(0.5, 0.5 * (1.0 - fPos), 0.5, 0.5 * (1.0 + fPos));
     150       68072 :                     aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(maGradientInfo.getSteps() - 1));
     151       68072 :                     rEntries.push_back(aB2DHomMatrixAndBColor);
     152         536 :                 }
     153             :             }
     154         536 :         }
     155             : 
     156       68754 :         void GeoTexSvxGradientLinear::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
     157             :         {
     158       68754 :             const double fScaler(basegfx::tools::getLinearGradientAlpha(rUV, maGradientInfo));
     159             : 
     160       68754 :             rBColor = basegfx::interpolate(maStart, maEnd, fScaler);
     161       68754 :         }
     162             :     } // end of namespace texture
     163             : } // end of namespace drawinglayer
     164             : 
     165             : //////////////////////////////////////////////////////////////////////////////
     166             : 
     167             : namespace drawinglayer
     168             : {
     169             :     namespace texture
     170             :     {
     171         158 :         GeoTexSvxGradientAxial::GeoTexSvxGradientAxial(
     172             :             const basegfx::B2DRange& rTargetRange,
     173             :             const basegfx::BColor& rStart,
     174             :             const basegfx::BColor& rEnd,
     175             :             sal_uInt32 nSteps,
     176             :             double fBorder,
     177             :             double fAngle)
     178         158 :         :   GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder)
     179             :         {
     180         316 :             maGradientInfo = basegfx::tools::createAxialODFGradientInfo(
     181             :                 rTargetRange,
     182             :                 nSteps,
     183             :                 fBorder,
     184         158 :                 fAngle);
     185         158 :         }
     186             : 
     187         166 :         GeoTexSvxGradientAxial::~GeoTexSvxGradientAxial()
     188             :         {
     189         166 :         }
     190             : 
     191         150 :         void GeoTexSvxGradientAxial::appendTransformationsAndColors(
     192             :             std::vector< B2DHomMatrixAndBColor >& rEntries,
     193             :             basegfx::BColor& rOutmostColor)
     194             :         {
     195         150 :             rOutmostColor = maEnd;
     196             : 
     197         150 :             if(maGradientInfo.getSteps())
     198             :             {
     199         150 :                 const double fStripeWidth(1.0 / maGradientInfo.getSteps());
     200         150 :                 B2DHomMatrixAndBColor aB2DHomMatrixAndBColor;
     201             : 
     202       19072 :                 for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++)
     203             :                 {
     204             :                     // const double fPos(fStripeWidth * a);
     205             :                     // optimized below...
     206             :                     //
     207             :                     // basegfx::B2DHomMatrix aNew;
     208             :                     // aNew.scale(0.50, (1.0 - fPos));
     209             :                     // aNew.translate(0.5, 0.0);
     210             :                     // aNew = maGradientInfo.getTextureTransform() * aNew;
     211       37844 :                     aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() *
     212       37844 :                         basegfx::tools::createScaleTranslateB2DHomMatrix(0.5, 1.0 - (fStripeWidth * a), 0.5, 0.0);
     213       18922 :                     aB2DHomMatrixAndBColor.maBColor = interpolate(maEnd, maStart, double(a) / double(maGradientInfo.getSteps() - 1));
     214       18922 :                     rEntries.push_back(aB2DHomMatrixAndBColor);
     215         150 :                 }
     216             :             }
     217         150 :         }
     218             : 
     219       67774 :         void GeoTexSvxGradientAxial::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
     220             :         {
     221       67774 :             const double fScaler(basegfx::tools::getAxialGradientAlpha(rUV, maGradientInfo));
     222             : 
     223       67774 :             rBColor = basegfx::interpolate(maStart, maEnd, fScaler);
     224       67774 :         }
     225             :     } // end of namespace texture
     226             : } // end of namespace drawinglayer
     227             : 
     228             : //////////////////////////////////////////////////////////////////////////////
     229             : 
     230             : namespace drawinglayer
     231             : {
     232             :     namespace texture
     233             :     {
     234           0 :         GeoTexSvxGradientRadial::GeoTexSvxGradientRadial(
     235             :             const basegfx::B2DRange& rTargetRange,
     236             :             const basegfx::BColor& rStart,
     237             :             const basegfx::BColor& rEnd,
     238             :             sal_uInt32 nSteps,
     239             :             double fBorder,
     240             :             double fOffsetX,
     241             :             double fOffsetY)
     242           0 :         :   GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder)
     243             :         {
     244           0 :             maGradientInfo = basegfx::tools::createRadialODFGradientInfo(
     245             :                 rTargetRange,
     246             :                 basegfx::B2DVector(fOffsetX,fOffsetY),
     247             :                 nSteps,
     248           0 :                 fBorder);
     249           0 :         }
     250             : 
     251           0 :         GeoTexSvxGradientRadial::~GeoTexSvxGradientRadial()
     252             :         {
     253           0 :         }
     254             : 
     255           0 :         void GeoTexSvxGradientRadial::appendTransformationsAndColors(
     256             :             std::vector< B2DHomMatrixAndBColor >& rEntries,
     257             :             basegfx::BColor& rOutmostColor)
     258             :         {
     259           0 :             rOutmostColor = maStart;
     260             : 
     261           0 :             if(maGradientInfo.getSteps())
     262             :             {
     263           0 :                 const double fStepSize(1.0 / maGradientInfo.getSteps());
     264           0 :                 B2DHomMatrixAndBColor aB2DHomMatrixAndBColor;
     265             : 
     266           0 :                 for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++)
     267             :                 {
     268           0 :                     const double fSize(1.0 - (fStepSize * a));
     269           0 :                     aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * basegfx::tools::createScaleB2DHomMatrix(fSize, fSize);
     270           0 :                     aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(maGradientInfo.getSteps() - 1));
     271           0 :                     rEntries.push_back(aB2DHomMatrixAndBColor);
     272           0 :                 }
     273             :             }
     274           0 :         }
     275             : 
     276           0 :         void GeoTexSvxGradientRadial::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
     277             :         {
     278           0 :             const double fScaler(basegfx::tools::getRadialGradientAlpha(rUV, maGradientInfo));
     279             : 
     280           0 :             rBColor = basegfx::interpolate(maStart, maEnd, fScaler);
     281           0 :         }
     282             :     } // end of namespace texture
     283             : } // end of namespace drawinglayer
     284             : 
     285             : //////////////////////////////////////////////////////////////////////////////
     286             : 
     287             : namespace drawinglayer
     288             : {
     289             :     namespace texture
     290             :     {
     291           0 :         GeoTexSvxGradientElliptical::GeoTexSvxGradientElliptical(
     292             :             const basegfx::B2DRange& rTargetRange,
     293             :             const basegfx::BColor& rStart,
     294             :             const basegfx::BColor& rEnd,
     295             :             sal_uInt32 nSteps,
     296             :             double fBorder,
     297             :             double fOffsetX,
     298             :             double fOffsetY,
     299             :             double fAngle)
     300           0 :         :   GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder)
     301             :         {
     302           0 :             maGradientInfo = basegfx::tools::createEllipticalODFGradientInfo(
     303             :                 rTargetRange,
     304             :                 basegfx::B2DVector(fOffsetX,fOffsetY),
     305             :                 nSteps,
     306             :                 fBorder,
     307           0 :                 fAngle);
     308           0 :         }
     309             : 
     310           0 :         GeoTexSvxGradientElliptical::~GeoTexSvxGradientElliptical()
     311             :         {
     312           0 :         }
     313             : 
     314           0 :         void GeoTexSvxGradientElliptical::appendTransformationsAndColors(
     315             :             std::vector< B2DHomMatrixAndBColor >& rEntries,
     316             :             basegfx::BColor& rOutmostColor)
     317             :         {
     318           0 :             rOutmostColor = maStart;
     319             : 
     320           0 :             if(maGradientInfo.getSteps())
     321             :             {
     322           0 :                 double fWidth(1.0);
     323           0 :                 double fHeight(1.0);
     324           0 :                 double fIncrementX(0.0);
     325           0 :                 double fIncrementY(0.0);
     326             : 
     327           0 :                 if(maGradientInfo.getAspectRatio() > 1.0)
     328             :                 {
     329           0 :                     fIncrementY = fHeight / maGradientInfo.getSteps();
     330           0 :                     fIncrementX = fIncrementY / maGradientInfo.getAspectRatio();
     331             :                 }
     332             :                 else
     333             :                 {
     334           0 :                     fIncrementX = fWidth / maGradientInfo.getSteps();
     335           0 :                     fIncrementY = fIncrementX * maGradientInfo.getAspectRatio();
     336             :                 }
     337             : 
     338           0 :                 B2DHomMatrixAndBColor aB2DHomMatrixAndBColor;
     339             : 
     340           0 :                 for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++)
     341             :                 {
     342             :                     // next step
     343           0 :                     fWidth -= fIncrementX;
     344           0 :                     fHeight -= fIncrementY;
     345             : 
     346           0 :                     aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * basegfx::tools::createScaleB2DHomMatrix(fWidth, fHeight);
     347           0 :                     aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(maGradientInfo.getSteps() - 1));
     348           0 :                     rEntries.push_back(aB2DHomMatrixAndBColor);
     349           0 :                 }
     350             :             }
     351           0 :         }
     352             : 
     353           0 :         void GeoTexSvxGradientElliptical::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
     354             :         {
     355           0 :             const double fScaler(basegfx::tools::getEllipticalGradientAlpha(rUV, maGradientInfo));
     356             : 
     357           0 :             rBColor = basegfx::interpolate(maStart, maEnd, fScaler);
     358           0 :         }
     359             :     } // end of namespace texture
     360             : } // end of namespace drawinglayer
     361             : 
     362             : //////////////////////////////////////////////////////////////////////////////
     363             : 
     364             : namespace drawinglayer
     365             : {
     366             :     namespace texture
     367             :     {
     368           0 :         GeoTexSvxGradientSquare::GeoTexSvxGradientSquare(
     369             :             const basegfx::B2DRange& rTargetRange,
     370             :             const basegfx::BColor& rStart,
     371             :             const basegfx::BColor& rEnd,
     372             :             sal_uInt32 nSteps,
     373             :             double fBorder,
     374             :             double fOffsetX,
     375             :             double fOffsetY,
     376             :             double fAngle)
     377           0 :         :   GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder)
     378             :         {
     379           0 :             maGradientInfo = basegfx::tools::createSquareODFGradientInfo(
     380             :                 rTargetRange,
     381             :                 basegfx::B2DVector(fOffsetX,fOffsetY),
     382             :                 nSteps,
     383             :                 fBorder,
     384           0 :                 fAngle);
     385           0 :         }
     386             : 
     387           0 :         GeoTexSvxGradientSquare::~GeoTexSvxGradientSquare()
     388             :         {
     389           0 :         }
     390             : 
     391           0 :         void GeoTexSvxGradientSquare::appendTransformationsAndColors(
     392             :             std::vector< B2DHomMatrixAndBColor >& rEntries,
     393             :             basegfx::BColor& rOutmostColor)
     394             :         {
     395           0 :             rOutmostColor = maStart;
     396             : 
     397           0 :             if(maGradientInfo.getSteps())
     398             :             {
     399           0 :                 const double fStepSize(1.0 / maGradientInfo.getSteps());
     400           0 :                 B2DHomMatrixAndBColor aB2DHomMatrixAndBColor;
     401             : 
     402           0 :                 for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++)
     403             :                 {
     404           0 :                     const double fSize(1.0 - (fStepSize * a));
     405           0 :                     aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * basegfx::tools::createScaleB2DHomMatrix(fSize, fSize);
     406           0 :                     aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(maGradientInfo.getSteps() - 1));
     407           0 :                     rEntries.push_back(aB2DHomMatrixAndBColor);
     408           0 :                 }
     409             :             }
     410           0 :         }
     411             : 
     412           0 :         void GeoTexSvxGradientSquare::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
     413             :         {
     414           0 :             const double fScaler(basegfx::tools::getSquareGradientAlpha(rUV, maGradientInfo));
     415             : 
     416           0 :             rBColor = basegfx::interpolate(maStart, maEnd, fScaler);
     417           0 :         }
     418             :     } // end of namespace texture
     419             : } // end of namespace drawinglayer
     420             : 
     421             : //////////////////////////////////////////////////////////////////////////////
     422             : 
     423             : namespace drawinglayer
     424             : {
     425             :     namespace texture
     426             :     {
     427           0 :         GeoTexSvxGradientRect::GeoTexSvxGradientRect(
     428             :             const basegfx::B2DRange& rTargetRange,
     429             :             const basegfx::BColor& rStart,
     430             :             const basegfx::BColor& rEnd,
     431             :             sal_uInt32 nSteps,
     432             :             double fBorder,
     433             :             double fOffsetX,
     434             :             double fOffsetY,
     435             :             double fAngle)
     436           0 :         :   GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder)
     437             :         {
     438           0 :             maGradientInfo = basegfx::tools::createRectangularODFGradientInfo(
     439             :                 rTargetRange,
     440             :                 basegfx::B2DVector(fOffsetX,fOffsetY),
     441             :                 nSteps,
     442             :                 fBorder,
     443           0 :                 fAngle);
     444           0 :         }
     445             : 
     446           0 :         GeoTexSvxGradientRect::~GeoTexSvxGradientRect()
     447             :         {
     448           0 :         }
     449             : 
     450           0 :         void GeoTexSvxGradientRect::appendTransformationsAndColors(
     451             :             std::vector< B2DHomMatrixAndBColor >& rEntries,
     452             :             basegfx::BColor& rOutmostColor)
     453             :         {
     454           0 :             rOutmostColor = maStart;
     455             : 
     456           0 :             if(maGradientInfo.getSteps())
     457             :             {
     458           0 :                 double fWidth(1.0);
     459           0 :                 double fHeight(1.0);
     460           0 :                 double fIncrementX(0.0);
     461           0 :                 double fIncrementY(0.0);
     462             : 
     463           0 :                 if(maGradientInfo.getAspectRatio() > 1.0)
     464             :                 {
     465           0 :                     fIncrementY = fHeight / maGradientInfo.getSteps();
     466           0 :                     fIncrementX = fIncrementY / maGradientInfo.getAspectRatio();
     467             :                 }
     468             :                 else
     469             :                 {
     470           0 :                     fIncrementX = fWidth / maGradientInfo.getSteps();
     471           0 :                     fIncrementY = fIncrementX * maGradientInfo.getAspectRatio();
     472             :                 }
     473             : 
     474           0 :                 B2DHomMatrixAndBColor aB2DHomMatrixAndBColor;
     475             : 
     476           0 :                 for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++)
     477             :                 {
     478             :                     // next step
     479           0 :                     fWidth -= fIncrementX;
     480           0 :                     fHeight -= fIncrementY;
     481             : 
     482           0 :                     aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * basegfx::tools::createScaleB2DHomMatrix(fWidth, fHeight);
     483           0 :                     aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(maGradientInfo.getSteps() - 1));
     484           0 :                     rEntries.push_back(aB2DHomMatrixAndBColor);
     485           0 :                 }
     486             :             }
     487           0 :         }
     488             : 
     489           0 :         void GeoTexSvxGradientRect::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
     490             :         {
     491           0 :             const double fScaler(basegfx::tools::getRectangularGradientAlpha(rUV, maGradientInfo));
     492             : 
     493           0 :             rBColor = basegfx::interpolate(maStart, maEnd, fScaler);
     494           0 :         }
     495             :     } // end of namespace texture
     496             : } // end of namespace drawinglayer
     497             : 
     498             : //////////////////////////////////////////////////////////////////////////////
     499             : 
     500             : namespace drawinglayer
     501             : {
     502             :     namespace texture
     503             :     {
     504          24 :         GeoTexSvxHatch::GeoTexSvxHatch(
     505             :             const basegfx::B2DRange& rTargetRange,
     506             :             double fDistance,
     507             :             double fAngle)
     508             :         :   mfDistance(0.1),
     509             :             mfAngle(fAngle),
     510          24 :             mnSteps(10L)
     511             :         {
     512          24 :             double fTargetSizeX(rTargetRange.getWidth());
     513          24 :             double fTargetSizeY(rTargetRange.getHeight());
     514          24 :             double fTargetOffsetX(rTargetRange.getMinX());
     515          24 :             double fTargetOffsetY(rTargetRange.getMinY());
     516             : 
     517          24 :             fAngle = -fAngle;
     518             : 
     519             :             // add object expansion
     520          24 :             if(0.0 != fAngle)
     521             :             {
     522           0 :                 const double fAbsCos(fabs(cos(fAngle)));
     523           0 :                 const double fAbsSin(fabs(sin(fAngle)));
     524           0 :                 const double fNewX(fTargetSizeX * fAbsCos + fTargetSizeY * fAbsSin);
     525           0 :                 const double fNewY(fTargetSizeY * fAbsCos + fTargetSizeX * fAbsSin);
     526           0 :                 fTargetOffsetX -= (fNewX - fTargetSizeX) / 2.0;
     527           0 :                 fTargetOffsetY -= (fNewY - fTargetSizeY) / 2.0;
     528           0 :                 fTargetSizeX = fNewX;
     529           0 :                 fTargetSizeY = fNewY;
     530             :             }
     531             : 
     532             :             // add object scale before rotate
     533          24 :             maTextureTransform.scale(fTargetSizeX, fTargetSizeY);
     534             : 
     535             :             // add texture rotate after scale to keep perpendicular angles
     536          24 :             if(0.0 != fAngle)
     537             :             {
     538           0 :                 basegfx::B2DPoint aCenter(0.5, 0.5);
     539           0 :                 aCenter *= maTextureTransform;
     540             : 
     541           0 :                 maTextureTransform = basegfx::tools::createRotateAroundPoint(aCenter, fAngle)
     542           0 :                     * maTextureTransform;
     543             :             }
     544             : 
     545             :             // add object translate
     546          24 :             maTextureTransform.translate(fTargetOffsetX, fTargetOffsetY);
     547             : 
     548             :             // prepare height for texture
     549          24 :             const double fSteps((0.0 != fDistance) ? fTargetSizeY / fDistance : 10.0);
     550          24 :             mnSteps = basegfx::fround(fSteps + 0.5);
     551          24 :             mfDistance = 1.0 / fSteps;
     552          24 :         }
     553             : 
     554          32 :         GeoTexSvxHatch::~GeoTexSvxHatch()
     555             :         {
     556          32 :         }
     557             : 
     558           0 :         bool GeoTexSvxHatch::operator==(const GeoTexSvx& rGeoTexSvx) const
     559             :         {
     560           0 :             const GeoTexSvxHatch* pCompare = dynamic_cast< const GeoTexSvxHatch* >(&rGeoTexSvx);
     561             :             return (pCompare
     562           0 :                 && maTextureTransform == pCompare->maTextureTransform
     563           0 :                 && mfDistance == pCompare->mfDistance
     564           0 :                 && mfAngle == pCompare->mfAngle
     565           0 :                 && mnSteps == pCompare->mnSteps);
     566             :         }
     567             : 
     568          16 :         void GeoTexSvxHatch::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices)
     569             :         {
     570         752 :             for(sal_uInt32 a(1L); a < mnSteps; a++)
     571             :             {
     572             :                 // create matrix
     573         736 :                 const double fOffset(mfDistance * (double)a);
     574         736 :                 basegfx::B2DHomMatrix aNew;
     575         736 :                 aNew.set(1, 2, fOffset);
     576         736 :                 rMatrices.push_back(maTextureTransform * aNew);
     577         736 :             }
     578          16 :         }
     579             : 
     580       47800 :         double GeoTexSvxHatch::getDistanceToHatch(const basegfx::B2DPoint& rUV) const
     581             :         {
     582       47800 :             const basegfx::B2DPoint aCoor(getBackTextureTransform() * rUV);
     583       47800 :             return fmod(aCoor.getY(), mfDistance);
     584             :         }
     585             : 
     586       47800 :         const basegfx::B2DHomMatrix& GeoTexSvxHatch::getBackTextureTransform() const
     587             :         {
     588       47800 :             if(maBackTextureTransform.isIdentity())
     589             :             {
     590           8 :                 const_cast< GeoTexSvxHatch* >(this)->maBackTextureTransform = maTextureTransform;
     591           8 :                 const_cast< GeoTexSvxHatch* >(this)->maBackTextureTransform.invert();
     592             :             }
     593             : 
     594       47800 :             return maBackTextureTransform;
     595             :         }
     596             :     } // end of namespace texture
     597             : } // end of namespace drawinglayer
     598             : 
     599             : //////////////////////////////////////////////////////////////////////////////
     600             : 
     601             : namespace drawinglayer
     602             : {
     603             :     namespace texture
     604             :     {
     605           0 :         GeoTexSvxTiled::GeoTexSvxTiled(
     606             :             const basegfx::B2DRange& rRange,
     607             :             double fOffsetX,
     608             :             double fOffsetY)
     609             :         :   maRange(rRange),
     610           0 :             mfOffsetX(basegfx::clamp(fOffsetX, 0.0, 1.0)),
     611           0 :             mfOffsetY(basegfx::clamp(fOffsetY, 0.0, 1.0))
     612             :         {
     613           0 :             if(!basegfx::fTools::equalZero(mfOffsetX))
     614             :             {
     615           0 :                 mfOffsetY = 0.0;
     616             :             }
     617           0 :         }
     618             : 
     619           0 :         GeoTexSvxTiled::~GeoTexSvxTiled()
     620             :         {
     621           0 :         }
     622             : 
     623           0 :         bool GeoTexSvxTiled::operator==(const GeoTexSvx& rGeoTexSvx) const
     624             :         {
     625           0 :             const GeoTexSvxTiled* pCompare = dynamic_cast< const GeoTexSvxTiled* >(&rGeoTexSvx);
     626             : 
     627             :             return (pCompare
     628           0 :                 && maRange == pCompare->maRange
     629           0 :                 && mfOffsetX == pCompare->mfOffsetX
     630           0 :                 && mfOffsetY == pCompare->mfOffsetY);
     631             :         }
     632             : 
     633           0 :         void GeoTexSvxTiled::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices)
     634             :         {
     635           0 :             const double fWidth(maRange.getWidth());
     636             : 
     637           0 :             if(!basegfx::fTools::equalZero(fWidth))
     638             :             {
     639           0 :                 const double fHeight(maRange.getHeight());
     640             : 
     641           0 :                 if(!basegfx::fTools::equalZero(fHeight))
     642             :                 {
     643           0 :                     double fStartX(maRange.getMinX());
     644           0 :                     double fStartY(maRange.getMinY());
     645           0 :                     sal_Int32 nPosX(0);
     646           0 :                     sal_Int32 nPosY(0);
     647             : 
     648           0 :                     if(basegfx::fTools::more(fStartX, 0.0))
     649             :                     {
     650           0 :                         const sal_Int32 nDiff(static_cast<sal_Int32>(floor(fStartX / fWidth)) + 1);
     651             : 
     652           0 :                         nPosX -= nDiff;
     653           0 :                         fStartX -= nDiff * fWidth;
     654             :                     }
     655             : 
     656           0 :                     if(basegfx::fTools::less(fStartX + fWidth, 0.0))
     657             :                     {
     658           0 :                         const sal_Int32 nDiff(static_cast<sal_Int32>(floor(-fStartX / fWidth)));
     659             : 
     660           0 :                         nPosX += nDiff;
     661           0 :                         fStartX += nDiff * fWidth;
     662             :                     }
     663             : 
     664           0 :                     if(basegfx::fTools::more(fStartY, 0.0))
     665             :                     {
     666           0 :                         const sal_Int32 nDiff(static_cast<sal_Int32>(floor(fStartY / fHeight)) + 1);
     667             : 
     668           0 :                         nPosY -= nDiff;
     669           0 :                         fStartY -= nDiff * fHeight;
     670             :                     }
     671             : 
     672           0 :                     if(basegfx::fTools::less(fStartY + fHeight, 0.0))
     673             :                     {
     674           0 :                         const sal_Int32 nDiff(static_cast<sal_Int32>(floor(-fStartY / fHeight)));
     675             : 
     676           0 :                         nPosY += nDiff;
     677           0 :                         fStartY += nDiff * fHeight;
     678             :                     }
     679             : 
     680           0 :                     if(!basegfx::fTools::equalZero(mfOffsetY))
     681             :                     {
     682           0 :                         for(double fPosX(fStartX); basegfx::fTools::less(fPosX, 1.0); fPosX += fWidth, nPosX++)
     683             :                         {
     684           0 :                             for(double fPosY(nPosX % 2 ? fStartY - fHeight + (mfOffsetY * fHeight) : fStartY);
     685           0 :                                 basegfx::fTools::less(fPosY, 1.0); fPosY += fHeight)
     686             :                             {
     687             :                                 rMatrices.push_back(
     688             :                                     basegfx::tools::createScaleTranslateB2DHomMatrix(
     689             :                                         fWidth,
     690             :                                         fHeight,
     691             :                                         fPosX,
     692           0 :                                         fPosY));
     693             :                             }
     694             :                         }
     695             :                     }
     696             :                     else
     697             :                     {
     698           0 :                         for(double fPosY(fStartY); basegfx::fTools::less(fPosY, 1.0); fPosY += fHeight, nPosY++)
     699             :                         {
     700           0 :                             for(double fPosX(nPosY % 2 ? fStartX - fWidth + (mfOffsetX * fWidth) : fStartX);
     701           0 :                                 basegfx::fTools::less(fPosX, 1.0); fPosX += fWidth)
     702             :                             {
     703             :                                 rMatrices.push_back(
     704             :                                     basegfx::tools::createScaleTranslateB2DHomMatrix(
     705             :                                         fWidth,
     706             :                                         fHeight,
     707             :                                         fPosX,
     708           0 :                                         fPosY));
     709             :                             }
     710             :                         }
     711             :                     }
     712             :                 }
     713             :             }
     714           0 :         }
     715             :     } // end of namespace texture
     716             : } // end of namespace drawinglayer
     717             : 
     718             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10