1464702f4SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3464702f4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4464702f4SAndrew Rist * or more contributor license agreements. See the NOTICE file 5464702f4SAndrew Rist * distributed with this work for additional information 6464702f4SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7464702f4SAndrew Rist * to you under the Apache License, Version 2.0 (the 8464702f4SAndrew Rist * "License"); you may not use this file except in compliance 9464702f4SAndrew Rist * with the License. You may obtain a copy of the License at 10464702f4SAndrew Rist * 11464702f4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12464702f4SAndrew Rist * 13464702f4SAndrew Rist * Unless required by applicable law or agreed to in writing, 14464702f4SAndrew Rist * software distributed under the License is distributed on an 15464702f4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16464702f4SAndrew Rist * KIND, either express or implied. See the License for the 17464702f4SAndrew Rist * specific language governing permissions and limitations 18464702f4SAndrew Rist * under the License. 19464702f4SAndrew Rist * 20464702f4SAndrew Rist *************************************************************/ 21464702f4SAndrew Rist 22464702f4SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <drawinglayer/texture/texture.hxx> 28cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 29cdf0e10cSrcweir #include <basegfx/tools/gradienttools.hxx> 30cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 33cdf0e10cSrcweir 34cdf0e10cSrcweir namespace drawinglayer 35cdf0e10cSrcweir { 36cdf0e10cSrcweir namespace texture 37cdf0e10cSrcweir { 38cdf0e10cSrcweir GeoTexSvx::GeoTexSvx() 39cdf0e10cSrcweir { 40cdf0e10cSrcweir } 41cdf0e10cSrcweir 42cdf0e10cSrcweir GeoTexSvx::~GeoTexSvx() 43cdf0e10cSrcweir { 44cdf0e10cSrcweir } 45cdf0e10cSrcweir 46cdf0e10cSrcweir bool GeoTexSvx::operator==(const GeoTexSvx& /*rGeoTexSvx*/) const 47cdf0e10cSrcweir { 48cdf0e10cSrcweir // default implementation says yes (no data -> no difference) 49cdf0e10cSrcweir return true; 50cdf0e10cSrcweir } 51cdf0e10cSrcweir 52cdf0e10cSrcweir void GeoTexSvx::modifyBColor(const basegfx::B2DPoint& /*rUV*/, basegfx::BColor& rBColor, double& /*rfOpacity*/) const 53cdf0e10cSrcweir { 54cdf0e10cSrcweir // base implementation creates random color (for testing only, may also be pure virtual) 55cdf0e10cSrcweir rBColor.setRed((rand() & 0x7fff) / 32767.0); 56cdf0e10cSrcweir rBColor.setGreen((rand() & 0x7fff) / 32767.0); 57cdf0e10cSrcweir rBColor.setBlue((rand() & 0x7fff) / 32767.0); 58cdf0e10cSrcweir } 59cdf0e10cSrcweir 60cdf0e10cSrcweir void GeoTexSvx::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const 61cdf0e10cSrcweir { 62cdf0e10cSrcweir // base implementation uses inverse of luminance of solved color (for testing only, may also be pure virtual) 63cdf0e10cSrcweir basegfx::BColor aBaseColor; 64cdf0e10cSrcweir modifyBColor(rUV, aBaseColor, rfOpacity); 65cdf0e10cSrcweir rfOpacity = 1.0 - aBaseColor.luminance(); 66cdf0e10cSrcweir } 67cdf0e10cSrcweir } // end of namespace texture 68cdf0e10cSrcweir } // end of namespace drawinglayer 69cdf0e10cSrcweir 70cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 71cdf0e10cSrcweir 72cdf0e10cSrcweir namespace drawinglayer 73cdf0e10cSrcweir { 7496fc4b33SArmin Le Grand namespace texture 7596fc4b33SArmin Le Grand { 7696fc4b33SArmin Le Grand GeoTexSvxGradient::GeoTexSvxGradient( 7796fc4b33SArmin Le Grand const basegfx::B2DRange& rTargetRange, 7896fc4b33SArmin Le Grand const basegfx::BColor& rStart, 7996fc4b33SArmin Le Grand const basegfx::BColor& rEnd, 80*d931502cSPavel Janík sal_uInt32 /* nSteps */, 8196fc4b33SArmin Le Grand double fBorder) 8296fc4b33SArmin Le Grand : GeoTexSvx(), 8396fc4b33SArmin Le Grand maGradientInfo(), 8496fc4b33SArmin Le Grand maTargetRange(rTargetRange), 85cdf0e10cSrcweir maStart(rStart), 86cdf0e10cSrcweir maEnd(rEnd), 87cdf0e10cSrcweir mfBorder(fBorder) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir GeoTexSvxGradient::~GeoTexSvxGradient() 92cdf0e10cSrcweir { 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir bool GeoTexSvxGradient::operator==(const GeoTexSvx& rGeoTexSvx) const 96cdf0e10cSrcweir { 97cdf0e10cSrcweir const GeoTexSvxGradient* pCompare = dynamic_cast< const GeoTexSvxGradient* >(&rGeoTexSvx); 9896fc4b33SArmin Le Grand 9996fc4b33SArmin Le Grand return (pCompare 10096fc4b33SArmin Le Grand && maGradientInfo == pCompare->maGradientInfo 101cdf0e10cSrcweir && maTargetRange == pCompare->maTargetRange 102cdf0e10cSrcweir && mfBorder == pCompare->mfBorder); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir } // end of namespace texture 105cdf0e10cSrcweir } // end of namespace drawinglayer 106cdf0e10cSrcweir 107cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 108cdf0e10cSrcweir 109cdf0e10cSrcweir namespace drawinglayer 110cdf0e10cSrcweir { 111cdf0e10cSrcweir namespace texture 112cdf0e10cSrcweir { 11396fc4b33SArmin Le Grand GeoTexSvxGradientLinear::GeoTexSvxGradientLinear( 11496fc4b33SArmin Le Grand const basegfx::B2DRange& rTargetRange, 11596fc4b33SArmin Le Grand const basegfx::BColor& rStart, 11696fc4b33SArmin Le Grand const basegfx::BColor& rEnd, 11796fc4b33SArmin Le Grand sal_uInt32 nSteps, 11896fc4b33SArmin Le Grand double fBorder, 11996fc4b33SArmin Le Grand double fAngle) 120cdf0e10cSrcweir : GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder) 121cdf0e10cSrcweir { 12296fc4b33SArmin Le Grand maGradientInfo = basegfx::tools::createLinearODFGradientInfo( 12396fc4b33SArmin Le Grand rTargetRange, 12496fc4b33SArmin Le Grand nSteps, 12596fc4b33SArmin Le Grand fBorder, 12696fc4b33SArmin Le Grand fAngle); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir GeoTexSvxGradientLinear::~GeoTexSvxGradientLinear() 130cdf0e10cSrcweir { 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 13396fc4b33SArmin Le Grand void GeoTexSvxGradientLinear::appendTransformationsAndColors( 13496fc4b33SArmin Le Grand std::vector< B2DHomMatrixAndBColor >& rEntries, 13596fc4b33SArmin Le Grand basegfx::BColor& rOutmostColor) 13696fc4b33SArmin Le Grand { 13796fc4b33SArmin Le Grand rOutmostColor = maStart; 13896fc4b33SArmin Le Grand 13996fc4b33SArmin Le Grand if(maGradientInfo.getSteps()) 14096fc4b33SArmin Le Grand { 14196fc4b33SArmin Le Grand const double fStripeWidth(1.0 / maGradientInfo.getSteps()); 14296fc4b33SArmin Le Grand B2DHomMatrixAndBColor aB2DHomMatrixAndBColor; 14396fc4b33SArmin Le Grand 14496fc4b33SArmin Le Grand for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++) 14596fc4b33SArmin Le Grand { 14696fc4b33SArmin Le Grand const double fPos(fStripeWidth * a); 14796fc4b33SArmin Le Grand // optimized below... 14896fc4b33SArmin Le Grand // 14996fc4b33SArmin Le Grand // basegfx::B2DHomMatrix aNew; 15096fc4b33SArmin Le Grand // aNew.scale(0.5, 0.5); 15196fc4b33SArmin Le Grand // aNew.translate(0.5, 0.5); 15296fc4b33SArmin Le Grand // aNew.scale(1.0, (1.0 - fPos)); 15396fc4b33SArmin Le Grand // aNew.translate(0.0, fPos); 15496fc4b33SArmin Le Grand // aNew = maGradientInfo.getTextureTransform() * aNew; 15596fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * 15696fc4b33SArmin Le Grand basegfx::tools::createScaleTranslateB2DHomMatrix(0.5, 0.5 * (1.0 - fPos), 0.5, 0.5 * (1.0 + fPos)); 15796fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(maGradientInfo.getSteps() - 1)); 15896fc4b33SArmin Le Grand rEntries.push_back(aB2DHomMatrixAndBColor); 15996fc4b33SArmin Le Grand } 16096fc4b33SArmin Le Grand } 16196fc4b33SArmin Le Grand } 162cdf0e10cSrcweir 163cdf0e10cSrcweir void GeoTexSvxGradientLinear::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const 164cdf0e10cSrcweir { 165cdf0e10cSrcweir const double fScaler(basegfx::tools::getLinearGradientAlpha(rUV, maGradientInfo)); 166cdf0e10cSrcweir 167cdf0e10cSrcweir rBColor = (maStart * (1.0 - fScaler)) + (maEnd * fScaler); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir } // end of namespace texture 170cdf0e10cSrcweir } // end of namespace drawinglayer 171cdf0e10cSrcweir 172cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 173cdf0e10cSrcweir 174cdf0e10cSrcweir namespace drawinglayer 175cdf0e10cSrcweir { 176cdf0e10cSrcweir namespace texture 177cdf0e10cSrcweir { 17896fc4b33SArmin Le Grand GeoTexSvxGradientAxial::GeoTexSvxGradientAxial( 17996fc4b33SArmin Le Grand const basegfx::B2DRange& rTargetRange, 18096fc4b33SArmin Le Grand const basegfx::BColor& rStart, 18196fc4b33SArmin Le Grand const basegfx::BColor& rEnd, 18296fc4b33SArmin Le Grand sal_uInt32 nSteps, 18396fc4b33SArmin Le Grand double fBorder, 18496fc4b33SArmin Le Grand double fAngle) 185cdf0e10cSrcweir : GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder) 186cdf0e10cSrcweir { 18796fc4b33SArmin Le Grand maGradientInfo = basegfx::tools::createAxialODFGradientInfo( 18896fc4b33SArmin Le Grand rTargetRange, 18996fc4b33SArmin Le Grand nSteps, 19096fc4b33SArmin Le Grand fBorder, 19196fc4b33SArmin Le Grand fAngle); 192cdf0e10cSrcweir } 193cdf0e10cSrcweir 194cdf0e10cSrcweir GeoTexSvxGradientAxial::~GeoTexSvxGradientAxial() 195cdf0e10cSrcweir { 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 19896fc4b33SArmin Le Grand void GeoTexSvxGradientAxial::appendTransformationsAndColors( 19996fc4b33SArmin Le Grand std::vector< B2DHomMatrixAndBColor >& rEntries, 20096fc4b33SArmin Le Grand basegfx::BColor& rOutmostColor) 20196fc4b33SArmin Le Grand { 20296fc4b33SArmin Le Grand rOutmostColor = maEnd; 203cdf0e10cSrcweir 20496fc4b33SArmin Le Grand if(maGradientInfo.getSteps()) 20596fc4b33SArmin Le Grand { 20696fc4b33SArmin Le Grand const double fStripeWidth(1.0 / maGradientInfo.getSteps()); 20796fc4b33SArmin Le Grand B2DHomMatrixAndBColor aB2DHomMatrixAndBColor; 208cdf0e10cSrcweir 20996fc4b33SArmin Le Grand for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++) 21096fc4b33SArmin Le Grand { 21196fc4b33SArmin Le Grand // const double fPos(fStripeWidth * a); 21296fc4b33SArmin Le Grand // optimized below... 21396fc4b33SArmin Le Grand // 21496fc4b33SArmin Le Grand // basegfx::B2DHomMatrix aNew; 21596fc4b33SArmin Le Grand // aNew.scale(0.50, (1.0 - fPos)); 21696fc4b33SArmin Le Grand // aNew.translate(0.5, 0.0); 21796fc4b33SArmin Le Grand // aNew = maGradientInfo.getTextureTransform() * aNew; 21896fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * 21996fc4b33SArmin Le Grand basegfx::tools::createScaleTranslateB2DHomMatrix(0.5, 1.0 - (fStripeWidth * a), 0.5, 0.0); 22096fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maBColor = interpolate(maEnd, maStart, double(a) / double(maGradientInfo.getSteps() - 1)); 22196fc4b33SArmin Le Grand rEntries.push_back(aB2DHomMatrixAndBColor); 22296fc4b33SArmin Le Grand } 22396fc4b33SArmin Le Grand } 224cdf0e10cSrcweir } 225cdf0e10cSrcweir 226cdf0e10cSrcweir void GeoTexSvxGradientAxial::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const 227cdf0e10cSrcweir { 228cdf0e10cSrcweir const double fScaler(basegfx::tools::getAxialGradientAlpha(rUV, maGradientInfo)); 229cdf0e10cSrcweir 230cdf0e10cSrcweir rBColor = (maStart * (1.0 - fScaler)) + (maEnd * fScaler); 231cdf0e10cSrcweir } 232cdf0e10cSrcweir } // end of namespace texture 233cdf0e10cSrcweir } // end of namespace drawinglayer 234cdf0e10cSrcweir 235cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 236cdf0e10cSrcweir 237cdf0e10cSrcweir namespace drawinglayer 238cdf0e10cSrcweir { 239cdf0e10cSrcweir namespace texture 240cdf0e10cSrcweir { 24196fc4b33SArmin Le Grand GeoTexSvxGradientRadial::GeoTexSvxGradientRadial( 24296fc4b33SArmin Le Grand const basegfx::B2DRange& rTargetRange, 24396fc4b33SArmin Le Grand const basegfx::BColor& rStart, 24496fc4b33SArmin Le Grand const basegfx::BColor& rEnd, 24596fc4b33SArmin Le Grand sal_uInt32 nSteps, 24696fc4b33SArmin Le Grand double fBorder, 24796fc4b33SArmin Le Grand double fOffsetX, 24896fc4b33SArmin Le Grand double fOffsetY) 249cdf0e10cSrcweir : GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder) 250cdf0e10cSrcweir { 25196fc4b33SArmin Le Grand maGradientInfo = basegfx::tools::createRadialODFGradientInfo( 25296fc4b33SArmin Le Grand rTargetRange, 25396fc4b33SArmin Le Grand basegfx::B2DVector(fOffsetX,fOffsetY), 25496fc4b33SArmin Le Grand nSteps, 25596fc4b33SArmin Le Grand fBorder); 256cdf0e10cSrcweir } 257cdf0e10cSrcweir 258cdf0e10cSrcweir GeoTexSvxGradientRadial::~GeoTexSvxGradientRadial() 259cdf0e10cSrcweir { 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 26296fc4b33SArmin Le Grand void GeoTexSvxGradientRadial::appendTransformationsAndColors( 26396fc4b33SArmin Le Grand std::vector< B2DHomMatrixAndBColor >& rEntries, 26496fc4b33SArmin Le Grand basegfx::BColor& rOutmostColor) 265cdf0e10cSrcweir { 26696fc4b33SArmin Le Grand rOutmostColor = maStart; 267cdf0e10cSrcweir 26896fc4b33SArmin Le Grand if(maGradientInfo.getSteps()) 26996fc4b33SArmin Le Grand { 27096fc4b33SArmin Le Grand const double fStepSize(1.0 / maGradientInfo.getSteps()); 27196fc4b33SArmin Le Grand B2DHomMatrixAndBColor aB2DHomMatrixAndBColor; 27296fc4b33SArmin Le Grand 27396fc4b33SArmin Le Grand for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++) 27496fc4b33SArmin Le Grand { 27596fc4b33SArmin Le Grand const double fSize(1.0 - (fStepSize * a)); 27696fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * basegfx::tools::createScaleB2DHomMatrix(fSize, fSize); 27796fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(maGradientInfo.getSteps() - 1)); 27896fc4b33SArmin Le Grand rEntries.push_back(aB2DHomMatrixAndBColor); 27996fc4b33SArmin Le Grand } 28096fc4b33SArmin Le Grand } 28196fc4b33SArmin Le Grand } 282cdf0e10cSrcweir 283cdf0e10cSrcweir void GeoTexSvxGradientRadial::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const 284cdf0e10cSrcweir { 285cdf0e10cSrcweir const double fScaler(basegfx::tools::getRadialGradientAlpha(rUV, maGradientInfo)); 286cdf0e10cSrcweir 287cdf0e10cSrcweir rBColor = (maStart * (1.0 - fScaler)) + (maEnd * fScaler); 288cdf0e10cSrcweir } 289cdf0e10cSrcweir } // end of namespace texture 290cdf0e10cSrcweir } // end of namespace drawinglayer 291cdf0e10cSrcweir 292cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 293cdf0e10cSrcweir 294cdf0e10cSrcweir namespace drawinglayer 295cdf0e10cSrcweir { 296cdf0e10cSrcweir namespace texture 297cdf0e10cSrcweir { 29896fc4b33SArmin Le Grand GeoTexSvxGradientElliptical::GeoTexSvxGradientElliptical( 29996fc4b33SArmin Le Grand const basegfx::B2DRange& rTargetRange, 30096fc4b33SArmin Le Grand const basegfx::BColor& rStart, 30196fc4b33SArmin Le Grand const basegfx::BColor& rEnd, 30296fc4b33SArmin Le Grand sal_uInt32 nSteps, 30396fc4b33SArmin Le Grand double fBorder, 30496fc4b33SArmin Le Grand double fOffsetX, 30596fc4b33SArmin Le Grand double fOffsetY, 30696fc4b33SArmin Le Grand double fAngle) 307cdf0e10cSrcweir : GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder) 308cdf0e10cSrcweir { 30996fc4b33SArmin Le Grand maGradientInfo = basegfx::tools::createEllipticalODFGradientInfo( 31096fc4b33SArmin Le Grand rTargetRange, 31196fc4b33SArmin Le Grand basegfx::B2DVector(fOffsetX,fOffsetY), 31296fc4b33SArmin Le Grand nSteps, 31396fc4b33SArmin Le Grand fBorder, 31496fc4b33SArmin Le Grand fAngle); 315cdf0e10cSrcweir } 316cdf0e10cSrcweir 317cdf0e10cSrcweir GeoTexSvxGradientElliptical::~GeoTexSvxGradientElliptical() 318cdf0e10cSrcweir { 319cdf0e10cSrcweir } 320cdf0e10cSrcweir 32196fc4b33SArmin Le Grand void GeoTexSvxGradientElliptical::appendTransformationsAndColors( 32296fc4b33SArmin Le Grand std::vector< B2DHomMatrixAndBColor >& rEntries, 32396fc4b33SArmin Le Grand basegfx::BColor& rOutmostColor) 324cdf0e10cSrcweir { 32596fc4b33SArmin Le Grand rOutmostColor = maStart; 326cdf0e10cSrcweir 32796fc4b33SArmin Le Grand if(maGradientInfo.getSteps()) 32896fc4b33SArmin Le Grand { 32996fc4b33SArmin Le Grand double fWidth(1.0); 33096fc4b33SArmin Le Grand double fHeight(1.0); 33196fc4b33SArmin Le Grand double fIncrementX(0.0); 33296fc4b33SArmin Le Grand double fIncrementY(0.0); 33396fc4b33SArmin Le Grand 33496fc4b33SArmin Le Grand if(maGradientInfo.getAspectRatio() > 1.0) 33596fc4b33SArmin Le Grand { 33696fc4b33SArmin Le Grand fIncrementY = fHeight / maGradientInfo.getSteps(); 33796fc4b33SArmin Le Grand fIncrementX = fIncrementY / maGradientInfo.getAspectRatio(); 33896fc4b33SArmin Le Grand } 33996fc4b33SArmin Le Grand else 34096fc4b33SArmin Le Grand { 34196fc4b33SArmin Le Grand fIncrementX = fWidth / maGradientInfo.getSteps(); 34296fc4b33SArmin Le Grand fIncrementY = fIncrementX * maGradientInfo.getAspectRatio(); 34396fc4b33SArmin Le Grand } 34496fc4b33SArmin Le Grand 34596fc4b33SArmin Le Grand B2DHomMatrixAndBColor aB2DHomMatrixAndBColor; 34696fc4b33SArmin Le Grand 34796fc4b33SArmin Le Grand for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++) 34896fc4b33SArmin Le Grand { 34996fc4b33SArmin Le Grand // next step 35096fc4b33SArmin Le Grand fWidth -= fIncrementX; 35196fc4b33SArmin Le Grand fHeight -= fIncrementY; 35296fc4b33SArmin Le Grand 35396fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * basegfx::tools::createScaleB2DHomMatrix(fWidth, fHeight); 35496fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(maGradientInfo.getSteps() - 1)); 35596fc4b33SArmin Le Grand rEntries.push_back(aB2DHomMatrixAndBColor); 35696fc4b33SArmin Le Grand } 35796fc4b33SArmin Le Grand } 358cdf0e10cSrcweir } 359cdf0e10cSrcweir 360cdf0e10cSrcweir void GeoTexSvxGradientElliptical::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const 361cdf0e10cSrcweir { 362cdf0e10cSrcweir const double fScaler(basegfx::tools::getEllipticalGradientAlpha(rUV, maGradientInfo)); 363cdf0e10cSrcweir 364cdf0e10cSrcweir rBColor = (maStart * (1.0 - fScaler)) + (maEnd * fScaler); 365cdf0e10cSrcweir } 366cdf0e10cSrcweir } // end of namespace texture 367cdf0e10cSrcweir } // end of namespace drawinglayer 368cdf0e10cSrcweir 369cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 370cdf0e10cSrcweir 371cdf0e10cSrcweir namespace drawinglayer 372cdf0e10cSrcweir { 373cdf0e10cSrcweir namespace texture 374cdf0e10cSrcweir { 37596fc4b33SArmin Le Grand GeoTexSvxGradientSquare::GeoTexSvxGradientSquare( 37696fc4b33SArmin Le Grand const basegfx::B2DRange& rTargetRange, 37796fc4b33SArmin Le Grand const basegfx::BColor& rStart, 37896fc4b33SArmin Le Grand const basegfx::BColor& rEnd, 37996fc4b33SArmin Le Grand sal_uInt32 nSteps, 38096fc4b33SArmin Le Grand double fBorder, 38196fc4b33SArmin Le Grand double fOffsetX, 38296fc4b33SArmin Le Grand double fOffsetY, 38396fc4b33SArmin Le Grand double fAngle) 384cdf0e10cSrcweir : GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder) 385cdf0e10cSrcweir { 38696fc4b33SArmin Le Grand maGradientInfo = basegfx::tools::createSquareODFGradientInfo( 38796fc4b33SArmin Le Grand rTargetRange, 38896fc4b33SArmin Le Grand basegfx::B2DVector(fOffsetX,fOffsetY), 38996fc4b33SArmin Le Grand nSteps, 39096fc4b33SArmin Le Grand fBorder, 39196fc4b33SArmin Le Grand fAngle); 392cdf0e10cSrcweir } 393cdf0e10cSrcweir 394cdf0e10cSrcweir GeoTexSvxGradientSquare::~GeoTexSvxGradientSquare() 395cdf0e10cSrcweir { 396cdf0e10cSrcweir } 397cdf0e10cSrcweir 39896fc4b33SArmin Le Grand void GeoTexSvxGradientSquare::appendTransformationsAndColors( 39996fc4b33SArmin Le Grand std::vector< B2DHomMatrixAndBColor >& rEntries, 40096fc4b33SArmin Le Grand basegfx::BColor& rOutmostColor) 401cdf0e10cSrcweir { 40296fc4b33SArmin Le Grand rOutmostColor = maStart; 403cdf0e10cSrcweir 40496fc4b33SArmin Le Grand if(maGradientInfo.getSteps()) 40596fc4b33SArmin Le Grand { 40696fc4b33SArmin Le Grand const double fStepSize(1.0 / maGradientInfo.getSteps()); 40796fc4b33SArmin Le Grand B2DHomMatrixAndBColor aB2DHomMatrixAndBColor; 40896fc4b33SArmin Le Grand 40996fc4b33SArmin Le Grand for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++) 41096fc4b33SArmin Le Grand { 41196fc4b33SArmin Le Grand const double fSize(1.0 - (fStepSize * a)); 41296fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * basegfx::tools::createScaleB2DHomMatrix(fSize, fSize); 41396fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(maGradientInfo.getSteps() - 1)); 41496fc4b33SArmin Le Grand rEntries.push_back(aB2DHomMatrixAndBColor); 41596fc4b33SArmin Le Grand } 41696fc4b33SArmin Le Grand } 417cdf0e10cSrcweir } 418cdf0e10cSrcweir 419cdf0e10cSrcweir void GeoTexSvxGradientSquare::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const 420cdf0e10cSrcweir { 421cdf0e10cSrcweir const double fScaler(basegfx::tools::getSquareGradientAlpha(rUV, maGradientInfo)); 422cdf0e10cSrcweir 423cdf0e10cSrcweir rBColor = (maStart * (1.0 - fScaler)) + (maEnd * fScaler); 424cdf0e10cSrcweir } 425cdf0e10cSrcweir } // end of namespace texture 426cdf0e10cSrcweir } // end of namespace drawinglayer 427cdf0e10cSrcweir 428cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 429cdf0e10cSrcweir 430cdf0e10cSrcweir namespace drawinglayer 431cdf0e10cSrcweir { 432cdf0e10cSrcweir namespace texture 433cdf0e10cSrcweir { 43496fc4b33SArmin Le Grand GeoTexSvxGradientRect::GeoTexSvxGradientRect( 43596fc4b33SArmin Le Grand const basegfx::B2DRange& rTargetRange, 43696fc4b33SArmin Le Grand const basegfx::BColor& rStart, 43796fc4b33SArmin Le Grand const basegfx::BColor& rEnd, 43896fc4b33SArmin Le Grand sal_uInt32 nSteps, 43996fc4b33SArmin Le Grand double fBorder, 44096fc4b33SArmin Le Grand double fOffsetX, 44196fc4b33SArmin Le Grand double fOffsetY, 44296fc4b33SArmin Le Grand double fAngle) 443cdf0e10cSrcweir : GeoTexSvxGradient(rTargetRange, rStart, rEnd, nSteps, fBorder) 444cdf0e10cSrcweir { 44596fc4b33SArmin Le Grand maGradientInfo = basegfx::tools::createRectangularODFGradientInfo( 44696fc4b33SArmin Le Grand rTargetRange, 44796fc4b33SArmin Le Grand basegfx::B2DVector(fOffsetX,fOffsetY), 44896fc4b33SArmin Le Grand nSteps, 44996fc4b33SArmin Le Grand fBorder, 45096fc4b33SArmin Le Grand fAngle); 451cdf0e10cSrcweir } 452cdf0e10cSrcweir 453cdf0e10cSrcweir GeoTexSvxGradientRect::~GeoTexSvxGradientRect() 454cdf0e10cSrcweir { 455cdf0e10cSrcweir } 456cdf0e10cSrcweir 45796fc4b33SArmin Le Grand void GeoTexSvxGradientRect::appendTransformationsAndColors( 45896fc4b33SArmin Le Grand std::vector< B2DHomMatrixAndBColor >& rEntries, 45996fc4b33SArmin Le Grand basegfx::BColor& rOutmostColor) 460cdf0e10cSrcweir { 46196fc4b33SArmin Le Grand rOutmostColor = maStart; 462cdf0e10cSrcweir 46396fc4b33SArmin Le Grand if(maGradientInfo.getSteps()) 46496fc4b33SArmin Le Grand { 46596fc4b33SArmin Le Grand double fWidth(1.0); 46696fc4b33SArmin Le Grand double fHeight(1.0); 46796fc4b33SArmin Le Grand double fIncrementX(0.0); 46896fc4b33SArmin Le Grand double fIncrementY(0.0); 46996fc4b33SArmin Le Grand 47096fc4b33SArmin Le Grand if(maGradientInfo.getAspectRatio() > 1.0) 47196fc4b33SArmin Le Grand { 47296fc4b33SArmin Le Grand fIncrementY = fHeight / maGradientInfo.getSteps(); 47396fc4b33SArmin Le Grand fIncrementX = fIncrementY / maGradientInfo.getAspectRatio(); 47496fc4b33SArmin Le Grand } 47596fc4b33SArmin Le Grand else 47696fc4b33SArmin Le Grand { 47796fc4b33SArmin Le Grand fIncrementX = fWidth / maGradientInfo.getSteps(); 47896fc4b33SArmin Le Grand fIncrementY = fIncrementX * maGradientInfo.getAspectRatio(); 47996fc4b33SArmin Le Grand } 48096fc4b33SArmin Le Grand 48196fc4b33SArmin Le Grand B2DHomMatrixAndBColor aB2DHomMatrixAndBColor; 48296fc4b33SArmin Le Grand 48396fc4b33SArmin Le Grand for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++) 48496fc4b33SArmin Le Grand { 48596fc4b33SArmin Le Grand // next step 48696fc4b33SArmin Le Grand fWidth -= fIncrementX; 48796fc4b33SArmin Le Grand fHeight -= fIncrementY; 48896fc4b33SArmin Le Grand 48996fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * basegfx::tools::createScaleB2DHomMatrix(fWidth, fHeight); 49096fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(maGradientInfo.getSteps() - 1)); 49196fc4b33SArmin Le Grand rEntries.push_back(aB2DHomMatrixAndBColor); 49296fc4b33SArmin Le Grand } 49396fc4b33SArmin Le Grand } 494cdf0e10cSrcweir } 495cdf0e10cSrcweir 496cdf0e10cSrcweir void GeoTexSvxGradientRect::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const 497cdf0e10cSrcweir { 498cdf0e10cSrcweir const double fScaler(basegfx::tools::getRectangularGradientAlpha(rUV, maGradientInfo)); 499cdf0e10cSrcweir 500cdf0e10cSrcweir rBColor = (maStart * (1.0 - fScaler)) + (maEnd * fScaler); 501cdf0e10cSrcweir } 502cdf0e10cSrcweir } // end of namespace texture 503cdf0e10cSrcweir } // end of namespace drawinglayer 504cdf0e10cSrcweir 505cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 506cdf0e10cSrcweir 507cdf0e10cSrcweir namespace drawinglayer 508cdf0e10cSrcweir { 509cdf0e10cSrcweir namespace texture 510cdf0e10cSrcweir { 51196fc4b33SArmin Le Grand GeoTexSvxHatch::GeoTexSvxHatch( 51296fc4b33SArmin Le Grand const basegfx::B2DRange& rTargetRange, 51396fc4b33SArmin Le Grand double fDistance, 51496fc4b33SArmin Le Grand double fAngle) 515cdf0e10cSrcweir : mfDistance(0.1), 516cdf0e10cSrcweir mfAngle(fAngle), 517cdf0e10cSrcweir mnSteps(10L) 518cdf0e10cSrcweir { 519cdf0e10cSrcweir double fTargetSizeX(rTargetRange.getWidth()); 520cdf0e10cSrcweir double fTargetSizeY(rTargetRange.getHeight()); 521cdf0e10cSrcweir double fTargetOffsetX(rTargetRange.getMinX()); 522cdf0e10cSrcweir double fTargetOffsetY(rTargetRange.getMinY()); 523cdf0e10cSrcweir 524cdf0e10cSrcweir fAngle = -fAngle; 525cdf0e10cSrcweir 526cdf0e10cSrcweir // add object expansion 527cdf0e10cSrcweir if(0.0 != fAngle) 528cdf0e10cSrcweir { 529cdf0e10cSrcweir const double fAbsCos(fabs(cos(fAngle))); 530cdf0e10cSrcweir const double fAbsSin(fabs(sin(fAngle))); 531cdf0e10cSrcweir const double fNewX(fTargetSizeX * fAbsCos + fTargetSizeY * fAbsSin); 532cdf0e10cSrcweir const double fNewY(fTargetSizeY * fAbsCos + fTargetSizeX * fAbsSin); 533cdf0e10cSrcweir fTargetOffsetX -= (fNewX - fTargetSizeX) / 2.0; 534cdf0e10cSrcweir fTargetOffsetY -= (fNewY - fTargetSizeY) / 2.0; 535cdf0e10cSrcweir fTargetSizeX = fNewX; 536cdf0e10cSrcweir fTargetSizeY = fNewY; 537cdf0e10cSrcweir } 538cdf0e10cSrcweir 539cdf0e10cSrcweir // add object scale before rotate 540cdf0e10cSrcweir maTextureTransform.scale(fTargetSizeX, fTargetSizeY); 541cdf0e10cSrcweir 542cdf0e10cSrcweir // add texture rotate after scale to keep perpendicular angles 543cdf0e10cSrcweir if(0.0 != fAngle) 544cdf0e10cSrcweir { 545cdf0e10cSrcweir basegfx::B2DPoint aCenter(0.5, 0.5); 546cdf0e10cSrcweir aCenter *= maTextureTransform; 547cdf0e10cSrcweir 548cdf0e10cSrcweir maTextureTransform = basegfx::tools::createRotateAroundPoint(aCenter, fAngle) 549cdf0e10cSrcweir * maTextureTransform; 550cdf0e10cSrcweir } 551cdf0e10cSrcweir 552cdf0e10cSrcweir // add object translate 553cdf0e10cSrcweir maTextureTransform.translate(fTargetOffsetX, fTargetOffsetY); 554cdf0e10cSrcweir 555cdf0e10cSrcweir // prepare height for texture 556cdf0e10cSrcweir const double fSteps((0.0 != fDistance) ? fTargetSizeY / fDistance : 10.0); 557cdf0e10cSrcweir mnSteps = basegfx::fround(fSteps + 0.5); 558cdf0e10cSrcweir mfDistance = 1.0 / fSteps; 559cdf0e10cSrcweir } 560cdf0e10cSrcweir 561cdf0e10cSrcweir GeoTexSvxHatch::~GeoTexSvxHatch() 562cdf0e10cSrcweir { 563cdf0e10cSrcweir } 564cdf0e10cSrcweir 565cdf0e10cSrcweir bool GeoTexSvxHatch::operator==(const GeoTexSvx& rGeoTexSvx) const 566cdf0e10cSrcweir { 567cdf0e10cSrcweir const GeoTexSvxHatch* pCompare = dynamic_cast< const GeoTexSvxHatch* >(&rGeoTexSvx); 568cdf0e10cSrcweir return (pCompare 569cdf0e10cSrcweir && maTextureTransform == pCompare->maTextureTransform 570cdf0e10cSrcweir && mfDistance == pCompare->mfDistance 571cdf0e10cSrcweir && mfAngle == pCompare->mfAngle 572cdf0e10cSrcweir && mnSteps == pCompare->mnSteps); 573cdf0e10cSrcweir } 574cdf0e10cSrcweir 575cdf0e10cSrcweir void GeoTexSvxHatch::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices) 576cdf0e10cSrcweir { 577cdf0e10cSrcweir for(sal_uInt32 a(1L); a < mnSteps; a++) 578cdf0e10cSrcweir { 579cdf0e10cSrcweir // create matrix 580cdf0e10cSrcweir const double fOffset(mfDistance * (double)a); 581cdf0e10cSrcweir basegfx::B2DHomMatrix aNew; 582cdf0e10cSrcweir aNew.set(1, 2, fOffset); 583cdf0e10cSrcweir rMatrices.push_back(maTextureTransform * aNew); 584cdf0e10cSrcweir } 585cdf0e10cSrcweir } 586cdf0e10cSrcweir 587cdf0e10cSrcweir double GeoTexSvxHatch::getDistanceToHatch(const basegfx::B2DPoint& rUV) const 588cdf0e10cSrcweir { 58996fc4b33SArmin Le Grand const basegfx::B2DPoint aCoor(getBackTextureTransform() * rUV); 590cdf0e10cSrcweir return fmod(aCoor.getY(), mfDistance); 591cdf0e10cSrcweir } 59296fc4b33SArmin Le Grand 59396fc4b33SArmin Le Grand const basegfx::B2DHomMatrix& GeoTexSvxHatch::getBackTextureTransform() const 59496fc4b33SArmin Le Grand { 59596fc4b33SArmin Le Grand if(maBackTextureTransform.isIdentity()) 59696fc4b33SArmin Le Grand { 59796fc4b33SArmin Le Grand const_cast< GeoTexSvxHatch* >(this)->maBackTextureTransform = maTextureTransform; 59896fc4b33SArmin Le Grand const_cast< GeoTexSvxHatch* >(this)->maBackTextureTransform.invert(); 59996fc4b33SArmin Le Grand } 60096fc4b33SArmin Le Grand 60196fc4b33SArmin Le Grand return maBackTextureTransform; 60296fc4b33SArmin Le Grand } 603cdf0e10cSrcweir } // end of namespace texture 604cdf0e10cSrcweir } // end of namespace drawinglayer 605cdf0e10cSrcweir 606cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 607cdf0e10cSrcweir 608cdf0e10cSrcweir namespace drawinglayer 609cdf0e10cSrcweir { 610cdf0e10cSrcweir namespace texture 611cdf0e10cSrcweir { 61296fc4b33SArmin Le Grand GeoTexSvxTiled::GeoTexSvxTiled( 61396fc4b33SArmin Le Grand const basegfx::B2DPoint& rTopLeft, 61496fc4b33SArmin Le Grand const basegfx::B2DVector& rSize) 615cdf0e10cSrcweir : maTopLeft(rTopLeft), 616cdf0e10cSrcweir maSize(rSize) 617cdf0e10cSrcweir { 618cdf0e10cSrcweir if(basegfx::fTools::lessOrEqual(maSize.getX(), 0.0)) 619cdf0e10cSrcweir { 620cdf0e10cSrcweir maSize.setX(1.0); 621cdf0e10cSrcweir } 622cdf0e10cSrcweir 623cdf0e10cSrcweir if(basegfx::fTools::lessOrEqual(maSize.getY(), 0.0)) 624cdf0e10cSrcweir { 625cdf0e10cSrcweir maSize.setY(1.0); 626cdf0e10cSrcweir } 627cdf0e10cSrcweir } 628cdf0e10cSrcweir 629cdf0e10cSrcweir GeoTexSvxTiled::~GeoTexSvxTiled() 630cdf0e10cSrcweir { 631cdf0e10cSrcweir } 632cdf0e10cSrcweir 633cdf0e10cSrcweir bool GeoTexSvxTiled::operator==(const GeoTexSvx& rGeoTexSvx) const 634cdf0e10cSrcweir { 635cdf0e10cSrcweir const GeoTexSvxTiled* pCompare = dynamic_cast< const GeoTexSvxTiled* >(&rGeoTexSvx); 636cdf0e10cSrcweir return (pCompare 637cdf0e10cSrcweir && maTopLeft == pCompare->maTopLeft 638cdf0e10cSrcweir && maSize == pCompare->maSize); 639cdf0e10cSrcweir } 640cdf0e10cSrcweir 641cdf0e10cSrcweir void GeoTexSvxTiled::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices) 642cdf0e10cSrcweir { 643cdf0e10cSrcweir double fStartX(maTopLeft.getX()); 644cdf0e10cSrcweir double fStartY(maTopLeft.getY()); 645cdf0e10cSrcweir 646cdf0e10cSrcweir if(basegfx::fTools::more(fStartX, 0.0)) 647cdf0e10cSrcweir { 648cdf0e10cSrcweir fStartX -= (floor(fStartX / maSize.getX()) + 1.0) * maSize.getX(); 649cdf0e10cSrcweir } 650cdf0e10cSrcweir 651cdf0e10cSrcweir if(basegfx::fTools::less(fStartX + maSize.getX(), 0.0)) 652cdf0e10cSrcweir { 653cdf0e10cSrcweir fStartX += floor(-fStartX / maSize.getX()) * maSize.getX(); 654cdf0e10cSrcweir } 655cdf0e10cSrcweir 656cdf0e10cSrcweir if(basegfx::fTools::more(fStartY, 0.0)) 657cdf0e10cSrcweir { 658cdf0e10cSrcweir fStartY -= (floor(fStartY / maSize.getY()) + 1.0) * maSize.getY(); 659cdf0e10cSrcweir } 660cdf0e10cSrcweir 661cdf0e10cSrcweir if(basegfx::fTools::less(fStartY + maSize.getY(), 0.0)) 662cdf0e10cSrcweir { 663cdf0e10cSrcweir fStartY += floor(-fStartY / maSize.getY()) * maSize.getY(); 664cdf0e10cSrcweir } 665cdf0e10cSrcweir 666cdf0e10cSrcweir for(double fPosY(fStartY); basegfx::fTools::less(fPosY, 1.0); fPosY += maSize.getY()) 667cdf0e10cSrcweir { 668cdf0e10cSrcweir for(double fPosX(fStartX); basegfx::fTools::less(fPosX, 1.0); fPosX += maSize.getX()) 669cdf0e10cSrcweir { 670cdf0e10cSrcweir basegfx::B2DHomMatrix aNew; 671cdf0e10cSrcweir 672cdf0e10cSrcweir aNew.set(0, 0, maSize.getX()); 673cdf0e10cSrcweir aNew.set(1, 1, maSize.getY()); 674cdf0e10cSrcweir aNew.set(0, 2, fPosX); 675cdf0e10cSrcweir aNew.set(1, 2, fPosY); 676cdf0e10cSrcweir 677cdf0e10cSrcweir rMatrices.push_back(aNew); 678cdf0e10cSrcweir } 679cdf0e10cSrcweir } 680cdf0e10cSrcweir } 681cdf0e10cSrcweir } // end of namespace texture 682cdf0e10cSrcweir } // end of namespace drawinglayer 683cdf0e10cSrcweir 684cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 685cdf0e10cSrcweir // eof 686