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 10cdf0e10cSrcweir * 11464702f4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 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 { GeoTexSvx()38cdf0e10cSrcweir GeoTexSvx::GeoTexSvx() 39cdf0e10cSrcweir { 40cdf0e10cSrcweir } 41cdf0e10cSrcweir ~GeoTexSvx()42cdf0e10cSrcweir GeoTexSvx::~GeoTexSvx() 43cdf0e10cSrcweir { 44cdf0e10cSrcweir } 45cdf0e10cSrcweir operator ==(const GeoTexSvx &) const46cdf0e10cSrcweir bool GeoTexSvx::operator==(const GeoTexSvx& /*rGeoTexSvx*/) const 47cdf0e10cSrcweir { 48cdf0e10cSrcweir // default implementation says yes (no data -> no difference) 49cdf0e10cSrcweir return true; 50cdf0e10cSrcweir } 51cdf0e10cSrcweir modifyBColor(const basegfx::B2DPoint &,basegfx::BColor & rBColor,double &) const52cdf0e10cSrcweir 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 modifyOpacity(const basegfx::B2DPoint & rUV,double & rfOpacity) const60cdf0e10cSrcweir 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 { 74cdf0e10cSrcweir namespace texture 75cdf0e10cSrcweir { GeoTexSvxGradient(const basegfx::B2DRange & rDefinitionRange,const basegfx::BColor & rStart,const basegfx::BColor & rEnd,sal_uInt32,double fBorder)7696fc4b33SArmin Le Grand GeoTexSvxGradient::GeoTexSvxGradient( 77*64b14621SArmin Le Grand const basegfx::B2DRange& rDefinitionRange, 7896fc4b33SArmin Le Grand const basegfx::BColor& rStart, 7996fc4b33SArmin Le Grand const basegfx::BColor& rEnd, 80d931502cSPavel Janík sal_uInt32 /* nSteps */, 8196fc4b33SArmin Le Grand double fBorder) 8296fc4b33SArmin Le Grand : GeoTexSvx(), 8396fc4b33SArmin Le Grand maGradientInfo(), 84*64b14621SArmin Le Grand maDefinitionRange(rDefinitionRange), 85cdf0e10cSrcweir maStart(rStart), 86cdf0e10cSrcweir maEnd(rEnd), 87cdf0e10cSrcweir mfBorder(fBorder) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir } 90cdf0e10cSrcweir ~GeoTexSvxGradient()91cdf0e10cSrcweir GeoTexSvxGradient::~GeoTexSvxGradient() 92cdf0e10cSrcweir { 93cdf0e10cSrcweir } 94cdf0e10cSrcweir operator ==(const GeoTexSvx & rGeoTexSvx) const95cdf0e10cSrcweir bool GeoTexSvxGradient::operator==(const GeoTexSvx& rGeoTexSvx) const 96cdf0e10cSrcweir { 97cdf0e10cSrcweir const GeoTexSvxGradient* pCompare = dynamic_cast< const GeoTexSvxGradient* >(&rGeoTexSvx); 9896fc4b33SArmin Le Grand 99cdf0e10cSrcweir return (pCompare 10096fc4b33SArmin Le Grand && maGradientInfo == pCompare->maGradientInfo 101*64b14621SArmin Le Grand && maDefinitionRange == pCompare->maDefinitionRange 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 { GeoTexSvxGradientLinear(const basegfx::B2DRange & rDefinitionRange,const basegfx::B2DRange & rOutputRange,const basegfx::BColor & rStart,const basegfx::BColor & rEnd,sal_uInt32 nSteps,double fBorder,double fAngle)11396fc4b33SArmin Le Grand GeoTexSvxGradientLinear::GeoTexSvxGradientLinear( 114*64b14621SArmin Le Grand const basegfx::B2DRange& rDefinitionRange, 115*64b14621SArmin Le Grand const basegfx::B2DRange& rOutputRange, 11696fc4b33SArmin Le Grand const basegfx::BColor& rStart, 11796fc4b33SArmin Le Grand const basegfx::BColor& rEnd, 11896fc4b33SArmin Le Grand sal_uInt32 nSteps, 11996fc4b33SArmin Le Grand double fBorder, 12096fc4b33SArmin Le Grand double fAngle) 121*64b14621SArmin Le Grand : GeoTexSvxGradient(rDefinitionRange, rStart, rEnd, nSteps, fBorder), 122*64b14621SArmin Le Grand mfUnitMinX(0.0), 123*64b14621SArmin Le Grand mfUnitWidth(1.0), 124*64b14621SArmin Le Grand mfUnitMaxY(1.0) 125cdf0e10cSrcweir { 12696fc4b33SArmin Le Grand maGradientInfo = basegfx::tools::createLinearODFGradientInfo( 127*64b14621SArmin Le Grand rDefinitionRange, 128cdf0e10cSrcweir nSteps, 129cdf0e10cSrcweir fBorder, 130cdf0e10cSrcweir fAngle); 131*64b14621SArmin Le Grand 132*64b14621SArmin Le Grand if(rDefinitionRange != rOutputRange) 133*64b14621SArmin Le Grand { 134*64b14621SArmin Le Grand basegfx::B2DRange aInvOutputRange(rOutputRange); 135*64b14621SArmin Le Grand 136*64b14621SArmin Le Grand aInvOutputRange.transform(maGradientInfo.getBackTextureTransform()); 137*64b14621SArmin Le Grand mfUnitMinX = aInvOutputRange.getMinX(); 138*64b14621SArmin Le Grand mfUnitWidth = aInvOutputRange.getWidth(); 139*64b14621SArmin Le Grand mfUnitMaxY = aInvOutputRange.getMaxY(); 140*64b14621SArmin Le Grand } 141cdf0e10cSrcweir } 142cdf0e10cSrcweir ~GeoTexSvxGradientLinear()143cdf0e10cSrcweir GeoTexSvxGradientLinear::~GeoTexSvxGradientLinear() 144cdf0e10cSrcweir { 145cdf0e10cSrcweir } 146cdf0e10cSrcweir appendTransformationsAndColors(std::vector<B2DHomMatrixAndBColor> & rEntries,basegfx::BColor & rOuterColor)14796fc4b33SArmin Le Grand void GeoTexSvxGradientLinear::appendTransformationsAndColors( 14896fc4b33SArmin Le Grand std::vector< B2DHomMatrixAndBColor >& rEntries, 149*64b14621SArmin Le Grand basegfx::BColor& rOuterColor) 150cdf0e10cSrcweir { 151*64b14621SArmin Le Grand rOuterColor = maStart; 152cdf0e10cSrcweir 15396fc4b33SArmin Le Grand if(maGradientInfo.getSteps()) 154cdf0e10cSrcweir { 15596fc4b33SArmin Le Grand const double fStripeWidth(1.0 / maGradientInfo.getSteps()); 15696fc4b33SArmin Le Grand B2DHomMatrixAndBColor aB2DHomMatrixAndBColor; 157*64b14621SArmin Le Grand basegfx::B2DHomMatrix aPattern; 158*64b14621SArmin Le Grand 159*64b14621SArmin Le Grand // bring from unit circle [-1, -1, 1, 1] to unit range [0, 0, 1, 1] 160*64b14621SArmin Le Grand aPattern.scale(0.5, 0.5); 161*64b14621SArmin Le Grand aPattern.translate(0.5, 0.5); 162*64b14621SArmin Le Grand 163*64b14621SArmin Le Grand // scale and translate in X 164*64b14621SArmin Le Grand aPattern.scale(mfUnitWidth, 1.0); 165*64b14621SArmin Le Grand aPattern.translate(mfUnitMinX, 0.0); 166cdf0e10cSrcweir 16796fc4b33SArmin Le Grand for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++) 168cdf0e10cSrcweir { 16996fc4b33SArmin Le Grand const double fPos(fStripeWidth * a); 170*64b14621SArmin Le Grand basegfx::B2DHomMatrix aNew(aPattern); 171*64b14621SArmin Le Grand 172*64b14621SArmin Le Grand // scale and translate in Y 173*64b14621SArmin Le Grand double fHeight(1.0 - fPos); 174*64b14621SArmin Le Grand 175*64b14621SArmin Le Grand if(a + 1 == maGradientInfo.getSteps() && mfUnitMaxY > 1.0) 176*64b14621SArmin Le Grand { 177*64b14621SArmin Le Grand fHeight += mfUnitMaxY - 1.0; 178*64b14621SArmin Le Grand } 179*64b14621SArmin Le Grand 180*64b14621SArmin Le Grand aNew.scale(1.0, fHeight); 181*64b14621SArmin Le Grand aNew.translate(0.0, fPos); 182*64b14621SArmin Le Grand 183*64b14621SArmin Le Grand // set at target 184*64b14621SArmin Le Grand aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * aNew; 185*64b14621SArmin Le Grand 186*64b14621SArmin Le Grand // interpolate and set color 18796fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(maGradientInfo.getSteps() - 1)); 188*64b14621SArmin Le Grand 18996fc4b33SArmin Le Grand rEntries.push_back(aB2DHomMatrixAndBColor); 190cdf0e10cSrcweir } 191cdf0e10cSrcweir } 192cdf0e10cSrcweir } 193cdf0e10cSrcweir modifyBColor(const basegfx::B2DPoint & rUV,basegfx::BColor & rBColor,double &) const194cdf0e10cSrcweir void GeoTexSvxGradientLinear::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const 195cdf0e10cSrcweir { 196cdf0e10cSrcweir const double fScaler(basegfx::tools::getLinearGradientAlpha(rUV, maGradientInfo)); 197cdf0e10cSrcweir 1987024eca9SArmin Le Grand rBColor = basegfx::interpolate(maStart, maEnd, fScaler); 199cdf0e10cSrcweir } 200cdf0e10cSrcweir } // end of namespace texture 201cdf0e10cSrcweir } // end of namespace drawinglayer 202cdf0e10cSrcweir 203cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 204cdf0e10cSrcweir 205cdf0e10cSrcweir namespace drawinglayer 206cdf0e10cSrcweir { 207cdf0e10cSrcweir namespace texture 208cdf0e10cSrcweir { GeoTexSvxGradientAxial(const basegfx::B2DRange & rDefinitionRange,const basegfx::B2DRange & rOutputRange,const basegfx::BColor & rStart,const basegfx::BColor & rEnd,sal_uInt32 nSteps,double fBorder,double fAngle)20996fc4b33SArmin Le Grand GeoTexSvxGradientAxial::GeoTexSvxGradientAxial( 210*64b14621SArmin Le Grand const basegfx::B2DRange& rDefinitionRange, 211*64b14621SArmin Le Grand const basegfx::B2DRange& rOutputRange, 21296fc4b33SArmin Le Grand const basegfx::BColor& rStart, 21396fc4b33SArmin Le Grand const basegfx::BColor& rEnd, 21496fc4b33SArmin Le Grand sal_uInt32 nSteps, 21596fc4b33SArmin Le Grand double fBorder, 21696fc4b33SArmin Le Grand double fAngle) 217*64b14621SArmin Le Grand : GeoTexSvxGradient(rDefinitionRange, rStart, rEnd, nSteps, fBorder), 218*64b14621SArmin Le Grand mfUnitMinX(0.0), 219*64b14621SArmin Le Grand mfUnitWidth(1.0) 220cdf0e10cSrcweir { 22196fc4b33SArmin Le Grand maGradientInfo = basegfx::tools::createAxialODFGradientInfo( 222*64b14621SArmin Le Grand rDefinitionRange, 223cdf0e10cSrcweir nSteps, 224cdf0e10cSrcweir fBorder, 225cdf0e10cSrcweir fAngle); 226*64b14621SArmin Le Grand 227*64b14621SArmin Le Grand if(rDefinitionRange != rOutputRange) 228*64b14621SArmin Le Grand { 229*64b14621SArmin Le Grand basegfx::B2DRange aInvOutputRange(rOutputRange); 230*64b14621SArmin Le Grand 231*64b14621SArmin Le Grand aInvOutputRange.transform(maGradientInfo.getBackTextureTransform()); 232*64b14621SArmin Le Grand mfUnitMinX = aInvOutputRange.getMinX(); 233*64b14621SArmin Le Grand mfUnitWidth = aInvOutputRange.getWidth(); 234*64b14621SArmin Le Grand } 235cdf0e10cSrcweir } 236cdf0e10cSrcweir ~GeoTexSvxGradientAxial()237cdf0e10cSrcweir GeoTexSvxGradientAxial::~GeoTexSvxGradientAxial() 238cdf0e10cSrcweir { 239cdf0e10cSrcweir } 240cdf0e10cSrcweir appendTransformationsAndColors(std::vector<B2DHomMatrixAndBColor> & rEntries,basegfx::BColor & rOuterColor)24196fc4b33SArmin Le Grand void GeoTexSvxGradientAxial::appendTransformationsAndColors( 24296fc4b33SArmin Le Grand std::vector< B2DHomMatrixAndBColor >& rEntries, 243*64b14621SArmin Le Grand basegfx::BColor& rOuterColor) 244cdf0e10cSrcweir { 245*64b14621SArmin Le Grand rOuterColor = maEnd; 246cdf0e10cSrcweir 24796fc4b33SArmin Le Grand if(maGradientInfo.getSteps()) 248cdf0e10cSrcweir { 24996fc4b33SArmin Le Grand const double fStripeWidth(1.0 / maGradientInfo.getSteps()); 25096fc4b33SArmin Le Grand B2DHomMatrixAndBColor aB2DHomMatrixAndBColor; 251cdf0e10cSrcweir 25296fc4b33SArmin Le Grand for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++) 253cdf0e10cSrcweir { 254*64b14621SArmin Le Grand const double fPos(fStripeWidth * a); 255*64b14621SArmin Le Grand basegfx::B2DHomMatrix aNew; 256*64b14621SArmin Le Grand 257*64b14621SArmin Le Grand // bring in X from unit circle [-1, -1, 1, 1] to unit range [0, 0, 1, 1] 258*64b14621SArmin Le Grand aNew.scale(0.5, 1.0); 259*64b14621SArmin Le Grand aNew.translate(0.5, 0.0); 260*64b14621SArmin Le Grand 261*64b14621SArmin Le Grand // scale/translate in X 262*64b14621SArmin Le Grand aNew.scale(mfUnitWidth, 1.0); 263*64b14621SArmin Le Grand aNew.translate(mfUnitMinX, 0.0); 264*64b14621SArmin Le Grand 265*64b14621SArmin Le Grand // already centerd in Y on X-Axis, just scale in Y 266*64b14621SArmin Le Grand aNew.scale(1.0, 1.0 - fPos); 267*64b14621SArmin Le Grand 268*64b14621SArmin Le Grand // set at target 269*64b14621SArmin Le Grand aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * aNew; 270*64b14621SArmin Le Grand 271*64b14621SArmin Le Grand // interpolate and set color 27296fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maBColor = interpolate(maEnd, maStart, double(a) / double(maGradientInfo.getSteps() - 1)); 273*64b14621SArmin Le Grand 27496fc4b33SArmin Le Grand rEntries.push_back(aB2DHomMatrixAndBColor); 275cdf0e10cSrcweir } 276cdf0e10cSrcweir } 277cdf0e10cSrcweir } 278cdf0e10cSrcweir modifyBColor(const basegfx::B2DPoint & rUV,basegfx::BColor & rBColor,double &) const279cdf0e10cSrcweir void GeoTexSvxGradientAxial::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const 280cdf0e10cSrcweir { 281cdf0e10cSrcweir const double fScaler(basegfx::tools::getAxialGradientAlpha(rUV, maGradientInfo)); 282cdf0e10cSrcweir 2837024eca9SArmin Le Grand rBColor = basegfx::interpolate(maStart, maEnd, fScaler); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir } // end of namespace texture 286cdf0e10cSrcweir } // end of namespace drawinglayer 287cdf0e10cSrcweir 288cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 289cdf0e10cSrcweir 290cdf0e10cSrcweir namespace drawinglayer 291cdf0e10cSrcweir { 292cdf0e10cSrcweir namespace texture 293cdf0e10cSrcweir { GeoTexSvxGradientRadial(const basegfx::B2DRange & rDefinitionRange,const basegfx::BColor & rStart,const basegfx::BColor & rEnd,sal_uInt32 nSteps,double fBorder,double fOffsetX,double fOffsetY)29496fc4b33SArmin Le Grand GeoTexSvxGradientRadial::GeoTexSvxGradientRadial( 295*64b14621SArmin Le Grand const basegfx::B2DRange& rDefinitionRange, 29696fc4b33SArmin Le Grand const basegfx::BColor& rStart, 29796fc4b33SArmin Le Grand const basegfx::BColor& rEnd, 29896fc4b33SArmin Le Grand sal_uInt32 nSteps, 29996fc4b33SArmin Le Grand double fBorder, 30096fc4b33SArmin Le Grand double fOffsetX, 30196fc4b33SArmin Le Grand double fOffsetY) 302*64b14621SArmin Le Grand : GeoTexSvxGradient(rDefinitionRange, rStart, rEnd, nSteps, fBorder) 303cdf0e10cSrcweir { 30496fc4b33SArmin Le Grand maGradientInfo = basegfx::tools::createRadialODFGradientInfo( 305*64b14621SArmin Le Grand rDefinitionRange, 306cdf0e10cSrcweir basegfx::B2DVector(fOffsetX,fOffsetY), 307cdf0e10cSrcweir nSteps, 308cdf0e10cSrcweir fBorder); 309cdf0e10cSrcweir } 310cdf0e10cSrcweir ~GeoTexSvxGradientRadial()311cdf0e10cSrcweir GeoTexSvxGradientRadial::~GeoTexSvxGradientRadial() 312cdf0e10cSrcweir { 313cdf0e10cSrcweir } 314cdf0e10cSrcweir appendTransformationsAndColors(std::vector<B2DHomMatrixAndBColor> & rEntries,basegfx::BColor & rOuterColor)31596fc4b33SArmin Le Grand void GeoTexSvxGradientRadial::appendTransformationsAndColors( 31696fc4b33SArmin Le Grand std::vector< B2DHomMatrixAndBColor >& rEntries, 317*64b14621SArmin Le Grand basegfx::BColor& rOuterColor) 318cdf0e10cSrcweir { 319*64b14621SArmin Le Grand rOuterColor = maStart; 320cdf0e10cSrcweir 32196fc4b33SArmin Le Grand if(maGradientInfo.getSteps()) 322cdf0e10cSrcweir { 32396fc4b33SArmin Le Grand const double fStepSize(1.0 / maGradientInfo.getSteps()); 32496fc4b33SArmin Le Grand B2DHomMatrixAndBColor aB2DHomMatrixAndBColor; 32596fc4b33SArmin Le Grand 32696fc4b33SArmin Le Grand for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++) 32796fc4b33SArmin Le Grand { 32896fc4b33SArmin Le Grand const double fSize(1.0 - (fStepSize * a)); 32996fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * basegfx::tools::createScaleB2DHomMatrix(fSize, fSize); 33096fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(maGradientInfo.getSteps() - 1)); 33196fc4b33SArmin Le Grand rEntries.push_back(aB2DHomMatrixAndBColor); 33296fc4b33SArmin Le Grand } 33396fc4b33SArmin Le Grand } 334cdf0e10cSrcweir } 335cdf0e10cSrcweir modifyBColor(const basegfx::B2DPoint & rUV,basegfx::BColor & rBColor,double &) const336cdf0e10cSrcweir void GeoTexSvxGradientRadial::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const 337cdf0e10cSrcweir { 338cdf0e10cSrcweir const double fScaler(basegfx::tools::getRadialGradientAlpha(rUV, maGradientInfo)); 339cdf0e10cSrcweir 3407024eca9SArmin Le Grand rBColor = basegfx::interpolate(maStart, maEnd, fScaler); 341cdf0e10cSrcweir } 342cdf0e10cSrcweir } // end of namespace texture 343cdf0e10cSrcweir } // end of namespace drawinglayer 344cdf0e10cSrcweir 345cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 346cdf0e10cSrcweir 347cdf0e10cSrcweir namespace drawinglayer 348cdf0e10cSrcweir { 349cdf0e10cSrcweir namespace texture 350cdf0e10cSrcweir { GeoTexSvxGradientElliptical(const basegfx::B2DRange & rDefinitionRange,const basegfx::BColor & rStart,const basegfx::BColor & rEnd,sal_uInt32 nSteps,double fBorder,double fOffsetX,double fOffsetY,double fAngle)35196fc4b33SArmin Le Grand GeoTexSvxGradientElliptical::GeoTexSvxGradientElliptical( 352*64b14621SArmin Le Grand const basegfx::B2DRange& rDefinitionRange, 35396fc4b33SArmin Le Grand const basegfx::BColor& rStart, 35496fc4b33SArmin Le Grand const basegfx::BColor& rEnd, 35596fc4b33SArmin Le Grand sal_uInt32 nSteps, 35696fc4b33SArmin Le Grand double fBorder, 35796fc4b33SArmin Le Grand double fOffsetX, 35896fc4b33SArmin Le Grand double fOffsetY, 35996fc4b33SArmin Le Grand double fAngle) 360*64b14621SArmin Le Grand : GeoTexSvxGradient(rDefinitionRange, rStart, rEnd, nSteps, fBorder) 361cdf0e10cSrcweir { 36296fc4b33SArmin Le Grand maGradientInfo = basegfx::tools::createEllipticalODFGradientInfo( 363*64b14621SArmin Le Grand rDefinitionRange, 364cdf0e10cSrcweir basegfx::B2DVector(fOffsetX,fOffsetY), 365cdf0e10cSrcweir nSteps, 366cdf0e10cSrcweir fBorder, 367cdf0e10cSrcweir fAngle); 368cdf0e10cSrcweir } 369cdf0e10cSrcweir ~GeoTexSvxGradientElliptical()370cdf0e10cSrcweir GeoTexSvxGradientElliptical::~GeoTexSvxGradientElliptical() 371cdf0e10cSrcweir { 372cdf0e10cSrcweir } 373cdf0e10cSrcweir appendTransformationsAndColors(std::vector<B2DHomMatrixAndBColor> & rEntries,basegfx::BColor & rOuterColor)37496fc4b33SArmin Le Grand void GeoTexSvxGradientElliptical::appendTransformationsAndColors( 37596fc4b33SArmin Le Grand std::vector< B2DHomMatrixAndBColor >& rEntries, 376*64b14621SArmin Le Grand basegfx::BColor& rOuterColor) 377cdf0e10cSrcweir { 378*64b14621SArmin Le Grand rOuterColor = maStart; 379cdf0e10cSrcweir 38096fc4b33SArmin Le Grand if(maGradientInfo.getSteps()) 381cdf0e10cSrcweir { 38296fc4b33SArmin Le Grand double fWidth(1.0); 38396fc4b33SArmin Le Grand double fHeight(1.0); 38496fc4b33SArmin Le Grand double fIncrementX(0.0); 38596fc4b33SArmin Le Grand double fIncrementY(0.0); 38696fc4b33SArmin Le Grand 38796fc4b33SArmin Le Grand if(maGradientInfo.getAspectRatio() > 1.0) 38896fc4b33SArmin Le Grand { 38996fc4b33SArmin Le Grand fIncrementY = fHeight / maGradientInfo.getSteps(); 39096fc4b33SArmin Le Grand fIncrementX = fIncrementY / maGradientInfo.getAspectRatio(); 391cdf0e10cSrcweir } 392cdf0e10cSrcweir else 393cdf0e10cSrcweir { 39496fc4b33SArmin Le Grand fIncrementX = fWidth / maGradientInfo.getSteps(); 39596fc4b33SArmin Le Grand fIncrementY = fIncrementX * maGradientInfo.getAspectRatio(); 396cdf0e10cSrcweir } 397cdf0e10cSrcweir 39896fc4b33SArmin Le Grand B2DHomMatrixAndBColor aB2DHomMatrixAndBColor; 39996fc4b33SArmin Le Grand 40096fc4b33SArmin Le Grand for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++) 401cdf0e10cSrcweir { 402cdf0e10cSrcweir // next step 403cdf0e10cSrcweir fWidth -= fIncrementX; 404cdf0e10cSrcweir fHeight -= fIncrementY; 405cdf0e10cSrcweir 40696fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * basegfx::tools::createScaleB2DHomMatrix(fWidth, fHeight); 40796fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(maGradientInfo.getSteps() - 1)); 40896fc4b33SArmin Le Grand rEntries.push_back(aB2DHomMatrixAndBColor); 409cdf0e10cSrcweir } 410cdf0e10cSrcweir } 411cdf0e10cSrcweir } 412cdf0e10cSrcweir modifyBColor(const basegfx::B2DPoint & rUV,basegfx::BColor & rBColor,double &) const413cdf0e10cSrcweir void GeoTexSvxGradientElliptical::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const 414cdf0e10cSrcweir { 415cdf0e10cSrcweir const double fScaler(basegfx::tools::getEllipticalGradientAlpha(rUV, maGradientInfo)); 416cdf0e10cSrcweir 4177024eca9SArmin Le Grand rBColor = basegfx::interpolate(maStart, maEnd, fScaler); 418cdf0e10cSrcweir } 419cdf0e10cSrcweir } // end of namespace texture 420cdf0e10cSrcweir } // end of namespace drawinglayer 421cdf0e10cSrcweir 422cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 423cdf0e10cSrcweir 424cdf0e10cSrcweir namespace drawinglayer 425cdf0e10cSrcweir { 426cdf0e10cSrcweir namespace texture 427cdf0e10cSrcweir { GeoTexSvxGradientSquare(const basegfx::B2DRange & rDefinitionRange,const basegfx::BColor & rStart,const basegfx::BColor & rEnd,sal_uInt32 nSteps,double fBorder,double fOffsetX,double fOffsetY,double fAngle)42896fc4b33SArmin Le Grand GeoTexSvxGradientSquare::GeoTexSvxGradientSquare( 429*64b14621SArmin Le Grand const basegfx::B2DRange& rDefinitionRange, 43096fc4b33SArmin Le Grand const basegfx::BColor& rStart, 43196fc4b33SArmin Le Grand const basegfx::BColor& rEnd, 43296fc4b33SArmin Le Grand sal_uInt32 nSteps, 43396fc4b33SArmin Le Grand double fBorder, 43496fc4b33SArmin Le Grand double fOffsetX, 43596fc4b33SArmin Le Grand double fOffsetY, 43696fc4b33SArmin Le Grand double fAngle) 437*64b14621SArmin Le Grand : GeoTexSvxGradient(rDefinitionRange, rStart, rEnd, nSteps, fBorder) 438cdf0e10cSrcweir { 43996fc4b33SArmin Le Grand maGradientInfo = basegfx::tools::createSquareODFGradientInfo( 440*64b14621SArmin Le Grand rDefinitionRange, 441cdf0e10cSrcweir basegfx::B2DVector(fOffsetX,fOffsetY), 442cdf0e10cSrcweir nSteps, 443cdf0e10cSrcweir fBorder, 444cdf0e10cSrcweir fAngle); 445cdf0e10cSrcweir } 446cdf0e10cSrcweir ~GeoTexSvxGradientSquare()447cdf0e10cSrcweir GeoTexSvxGradientSquare::~GeoTexSvxGradientSquare() 448cdf0e10cSrcweir { 449cdf0e10cSrcweir } 450cdf0e10cSrcweir appendTransformationsAndColors(std::vector<B2DHomMatrixAndBColor> & rEntries,basegfx::BColor & rOuterColor)45196fc4b33SArmin Le Grand void GeoTexSvxGradientSquare::appendTransformationsAndColors( 45296fc4b33SArmin Le Grand std::vector< B2DHomMatrixAndBColor >& rEntries, 453*64b14621SArmin Le Grand basegfx::BColor& rOuterColor) 454cdf0e10cSrcweir { 455*64b14621SArmin Le Grand rOuterColor = maStart; 456cdf0e10cSrcweir 45796fc4b33SArmin Le Grand if(maGradientInfo.getSteps()) 458cdf0e10cSrcweir { 45996fc4b33SArmin Le Grand const double fStepSize(1.0 / maGradientInfo.getSteps()); 46096fc4b33SArmin Le Grand B2DHomMatrixAndBColor aB2DHomMatrixAndBColor; 46196fc4b33SArmin Le Grand 46296fc4b33SArmin Le Grand for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++) 46396fc4b33SArmin Le Grand { 46496fc4b33SArmin Le Grand const double fSize(1.0 - (fStepSize * a)); 46596fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * basegfx::tools::createScaleB2DHomMatrix(fSize, fSize); 46696fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(maGradientInfo.getSteps() - 1)); 46796fc4b33SArmin Le Grand rEntries.push_back(aB2DHomMatrixAndBColor); 46896fc4b33SArmin Le Grand } 46996fc4b33SArmin Le Grand } 470cdf0e10cSrcweir } 471cdf0e10cSrcweir modifyBColor(const basegfx::B2DPoint & rUV,basegfx::BColor & rBColor,double &) const472cdf0e10cSrcweir void GeoTexSvxGradientSquare::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const 473cdf0e10cSrcweir { 474cdf0e10cSrcweir const double fScaler(basegfx::tools::getSquareGradientAlpha(rUV, maGradientInfo)); 475cdf0e10cSrcweir 4767024eca9SArmin Le Grand rBColor = basegfx::interpolate(maStart, maEnd, fScaler); 477cdf0e10cSrcweir } 478cdf0e10cSrcweir } // end of namespace texture 479cdf0e10cSrcweir } // end of namespace drawinglayer 480cdf0e10cSrcweir 481cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 482cdf0e10cSrcweir 483cdf0e10cSrcweir namespace drawinglayer 484cdf0e10cSrcweir { 485cdf0e10cSrcweir namespace texture 486cdf0e10cSrcweir { GeoTexSvxGradientRect(const basegfx::B2DRange & rDefinitionRange,const basegfx::BColor & rStart,const basegfx::BColor & rEnd,sal_uInt32 nSteps,double fBorder,double fOffsetX,double fOffsetY,double fAngle)48796fc4b33SArmin Le Grand GeoTexSvxGradientRect::GeoTexSvxGradientRect( 488*64b14621SArmin Le Grand const basegfx::B2DRange& rDefinitionRange, 48996fc4b33SArmin Le Grand const basegfx::BColor& rStart, 49096fc4b33SArmin Le Grand const basegfx::BColor& rEnd, 49196fc4b33SArmin Le Grand sal_uInt32 nSteps, 49296fc4b33SArmin Le Grand double fBorder, 49396fc4b33SArmin Le Grand double fOffsetX, 49496fc4b33SArmin Le Grand double fOffsetY, 49596fc4b33SArmin Le Grand double fAngle) 496*64b14621SArmin Le Grand : GeoTexSvxGradient(rDefinitionRange, rStart, rEnd, nSteps, fBorder) 497cdf0e10cSrcweir { 49896fc4b33SArmin Le Grand maGradientInfo = basegfx::tools::createRectangularODFGradientInfo( 499*64b14621SArmin Le Grand rDefinitionRange, 500cdf0e10cSrcweir basegfx::B2DVector(fOffsetX,fOffsetY), 501cdf0e10cSrcweir nSteps, 502cdf0e10cSrcweir fBorder, 503cdf0e10cSrcweir fAngle); 504cdf0e10cSrcweir } 505cdf0e10cSrcweir ~GeoTexSvxGradientRect()506cdf0e10cSrcweir GeoTexSvxGradientRect::~GeoTexSvxGradientRect() 507cdf0e10cSrcweir { 508cdf0e10cSrcweir } 509cdf0e10cSrcweir appendTransformationsAndColors(std::vector<B2DHomMatrixAndBColor> & rEntries,basegfx::BColor & rOuterColor)51096fc4b33SArmin Le Grand void GeoTexSvxGradientRect::appendTransformationsAndColors( 51196fc4b33SArmin Le Grand std::vector< B2DHomMatrixAndBColor >& rEntries, 512*64b14621SArmin Le Grand basegfx::BColor& rOuterColor) 513cdf0e10cSrcweir { 514*64b14621SArmin Le Grand rOuterColor = maStart; 515cdf0e10cSrcweir 51696fc4b33SArmin Le Grand if(maGradientInfo.getSteps()) 517cdf0e10cSrcweir { 51896fc4b33SArmin Le Grand double fWidth(1.0); 51996fc4b33SArmin Le Grand double fHeight(1.0); 52096fc4b33SArmin Le Grand double fIncrementX(0.0); 52196fc4b33SArmin Le Grand double fIncrementY(0.0); 52296fc4b33SArmin Le Grand 52396fc4b33SArmin Le Grand if(maGradientInfo.getAspectRatio() > 1.0) 52496fc4b33SArmin Le Grand { 52596fc4b33SArmin Le Grand fIncrementY = fHeight / maGradientInfo.getSteps(); 52696fc4b33SArmin Le Grand fIncrementX = fIncrementY / maGradientInfo.getAspectRatio(); 527cdf0e10cSrcweir } 528cdf0e10cSrcweir else 529cdf0e10cSrcweir { 53096fc4b33SArmin Le Grand fIncrementX = fWidth / maGradientInfo.getSteps(); 53196fc4b33SArmin Le Grand fIncrementY = fIncrementX * maGradientInfo.getAspectRatio(); 532cdf0e10cSrcweir } 533cdf0e10cSrcweir 53496fc4b33SArmin Le Grand B2DHomMatrixAndBColor aB2DHomMatrixAndBColor; 53596fc4b33SArmin Le Grand 53696fc4b33SArmin Le Grand for(sal_uInt32 a(1); a < maGradientInfo.getSteps(); a++) 537cdf0e10cSrcweir { 538cdf0e10cSrcweir // next step 539cdf0e10cSrcweir fWidth -= fIncrementX; 540cdf0e10cSrcweir fHeight -= fIncrementY; 541cdf0e10cSrcweir 54296fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maB2DHomMatrix = maGradientInfo.getTextureTransform() * basegfx::tools::createScaleB2DHomMatrix(fWidth, fHeight); 54396fc4b33SArmin Le Grand aB2DHomMatrixAndBColor.maBColor = interpolate(maStart, maEnd, double(a) / double(maGradientInfo.getSteps() - 1)); 54496fc4b33SArmin Le Grand rEntries.push_back(aB2DHomMatrixAndBColor); 545cdf0e10cSrcweir } 546cdf0e10cSrcweir } 547cdf0e10cSrcweir } 548cdf0e10cSrcweir modifyBColor(const basegfx::B2DPoint & rUV,basegfx::BColor & rBColor,double &) const549cdf0e10cSrcweir void GeoTexSvxGradientRect::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& /*rfOpacity*/) const 550cdf0e10cSrcweir { 551cdf0e10cSrcweir const double fScaler(basegfx::tools::getRectangularGradientAlpha(rUV, maGradientInfo)); 552cdf0e10cSrcweir 5537024eca9SArmin Le Grand rBColor = basegfx::interpolate(maStart, maEnd, fScaler); 554cdf0e10cSrcweir } 555cdf0e10cSrcweir } // end of namespace texture 556cdf0e10cSrcweir } // end of namespace drawinglayer 557cdf0e10cSrcweir 558cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 559cdf0e10cSrcweir 560cdf0e10cSrcweir namespace drawinglayer 561cdf0e10cSrcweir { 562cdf0e10cSrcweir namespace texture 563cdf0e10cSrcweir { GeoTexSvxHatch(const basegfx::B2DRange & rDefinitionRange,const basegfx::B2DRange & rOutputRange,double fDistance,double fAngle)56496fc4b33SArmin Le Grand GeoTexSvxHatch::GeoTexSvxHatch( 565*64b14621SArmin Le Grand const basegfx::B2DRange& rDefinitionRange, 566*64b14621SArmin Le Grand const basegfx::B2DRange& rOutputRange, 56796fc4b33SArmin Le Grand double fDistance, 56896fc4b33SArmin Le Grand double fAngle) 569*64b14621SArmin Le Grand : maOutputRange(rOutputRange), 570*64b14621SArmin Le Grand maTextureTransform(), 571*64b14621SArmin Le Grand maBackTextureTransform(), 572*64b14621SArmin Le Grand mfDistance(0.1), 573cdf0e10cSrcweir mfAngle(fAngle), 574*64b14621SArmin Le Grand mnSteps(10), 575*64b14621SArmin Le Grand mbDefinitionRangeEqualsOutputRange(rDefinitionRange == rOutputRange) 576cdf0e10cSrcweir { 577*64b14621SArmin Le Grand double fTargetSizeX(rDefinitionRange.getWidth()); 578*64b14621SArmin Le Grand double fTargetSizeY(rDefinitionRange.getHeight()); 579*64b14621SArmin Le Grand double fTargetOffsetX(rDefinitionRange.getMinX()); 580*64b14621SArmin Le Grand double fTargetOffsetY(rDefinitionRange.getMinY()); 581cdf0e10cSrcweir 582cdf0e10cSrcweir fAngle = -fAngle; 583cdf0e10cSrcweir 584cdf0e10cSrcweir // add object expansion 585cdf0e10cSrcweir if(0.0 != fAngle) 586cdf0e10cSrcweir { 587cdf0e10cSrcweir const double fAbsCos(fabs(cos(fAngle))); 588cdf0e10cSrcweir const double fAbsSin(fabs(sin(fAngle))); 589cdf0e10cSrcweir const double fNewX(fTargetSizeX * fAbsCos + fTargetSizeY * fAbsSin); 590cdf0e10cSrcweir const double fNewY(fTargetSizeY * fAbsCos + fTargetSizeX * fAbsSin); 591cdf0e10cSrcweir fTargetOffsetX -= (fNewX - fTargetSizeX) / 2.0; 592cdf0e10cSrcweir fTargetOffsetY -= (fNewY - fTargetSizeY) / 2.0; 593cdf0e10cSrcweir fTargetSizeX = fNewX; 594cdf0e10cSrcweir fTargetSizeY = fNewY; 595cdf0e10cSrcweir } 596cdf0e10cSrcweir 597cdf0e10cSrcweir // add object scale before rotate 598cdf0e10cSrcweir maTextureTransform.scale(fTargetSizeX, fTargetSizeY); 599cdf0e10cSrcweir 600cdf0e10cSrcweir // add texture rotate after scale to keep perpendicular angles 601cdf0e10cSrcweir if(0.0 != fAngle) 602cdf0e10cSrcweir { 603cdf0e10cSrcweir basegfx::B2DPoint aCenter(0.5, 0.5); 604cdf0e10cSrcweir aCenter *= maTextureTransform; 605cdf0e10cSrcweir 606cdf0e10cSrcweir maTextureTransform = basegfx::tools::createRotateAroundPoint(aCenter, fAngle) 607cdf0e10cSrcweir * maTextureTransform; 608cdf0e10cSrcweir } 609cdf0e10cSrcweir 610cdf0e10cSrcweir // add object translate 611cdf0e10cSrcweir maTextureTransform.translate(fTargetOffsetX, fTargetOffsetY); 612cdf0e10cSrcweir 613cdf0e10cSrcweir // prepare height for texture 614cdf0e10cSrcweir const double fSteps((0.0 != fDistance) ? fTargetSizeY / fDistance : 10.0); 615cdf0e10cSrcweir mnSteps = basegfx::fround(fSteps + 0.5); 616cdf0e10cSrcweir mfDistance = 1.0 / fSteps; 617cdf0e10cSrcweir } 618cdf0e10cSrcweir ~GeoTexSvxHatch()619cdf0e10cSrcweir GeoTexSvxHatch::~GeoTexSvxHatch() 620cdf0e10cSrcweir { 621cdf0e10cSrcweir } 622cdf0e10cSrcweir operator ==(const GeoTexSvx & rGeoTexSvx) const623cdf0e10cSrcweir bool GeoTexSvxHatch::operator==(const GeoTexSvx& rGeoTexSvx) const 624cdf0e10cSrcweir { 625cdf0e10cSrcweir const GeoTexSvxHatch* pCompare = dynamic_cast< const GeoTexSvxHatch* >(&rGeoTexSvx); 626cdf0e10cSrcweir return (pCompare 627*64b14621SArmin Le Grand && maOutputRange == pCompare->maOutputRange 628cdf0e10cSrcweir && maTextureTransform == pCompare->maTextureTransform 629cdf0e10cSrcweir && mfDistance == pCompare->mfDistance 630cdf0e10cSrcweir && mfAngle == pCompare->mfAngle 631cdf0e10cSrcweir && mnSteps == pCompare->mnSteps); 632cdf0e10cSrcweir } 633cdf0e10cSrcweir appendTransformations(::std::vector<basegfx::B2DHomMatrix> & rMatrices)634cdf0e10cSrcweir void GeoTexSvxHatch::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices) 635cdf0e10cSrcweir { 636*64b14621SArmin Le Grand if(mbDefinitionRangeEqualsOutputRange) 637*64b14621SArmin Le Grand { 638*64b14621SArmin Le Grand // simple hatch where the definition area equals the output area 639*64b14621SArmin Le Grand for(sal_uInt32 a(1); a < mnSteps; a++) 640cdf0e10cSrcweir { 641cdf0e10cSrcweir // create matrix 642cdf0e10cSrcweir const double fOffset(mfDistance * (double)a); 643cdf0e10cSrcweir basegfx::B2DHomMatrix aNew; 644cdf0e10cSrcweir aNew.set(1, 2, fOffset); 645cdf0e10cSrcweir rMatrices.push_back(maTextureTransform * aNew); 646cdf0e10cSrcweir } 647cdf0e10cSrcweir } 648*64b14621SArmin Le Grand else 649*64b14621SArmin Le Grand { 650*64b14621SArmin Le Grand // output area is different from definition area, back-transform to get 651*64b14621SArmin Le Grand // the output area in unit coordinates and fill this with hatch lines 652*64b14621SArmin Le Grand // using the settings derived from the definition area 653*64b14621SArmin Le Grand basegfx::B2DRange aBackUnitRange(maOutputRange); 654*64b14621SArmin Le Grand 655*64b14621SArmin Le Grand aBackUnitRange.transform(getBackTextureTransform()); 656*64b14621SArmin Le Grand 657*64b14621SArmin Le Grand // calculate vertical start value and a security maximum integer value to avoid death loops 658*64b14621SArmin Le Grand double fStart(basegfx::snapToNearestMultiple(aBackUnitRange.getMinY(), mfDistance)); 659*64b14621SArmin Le Grand const sal_uInt32 nNeededIntegerSteps(basegfx::fround((aBackUnitRange.getHeight() / mfDistance) + 0.5)); 660*64b14621SArmin Le Grand sal_uInt32 nMaxIntegerSteps(::std::min(nNeededIntegerSteps, sal_uInt32(10000))); 661*64b14621SArmin Le Grand 662*64b14621SArmin Le Grand while(fStart < aBackUnitRange.getMaxY() && nMaxIntegerSteps) 663*64b14621SArmin Le Grand { 664*64b14621SArmin Le Grand // create new transform for 665*64b14621SArmin Le Grand basegfx::B2DHomMatrix aNew; 666*64b14621SArmin Le Grand 667*64b14621SArmin Le Grand // adapt x scale and position 668*64b14621SArmin Le Grand //aNew.scale(aBackUnitRange.getWidth(), 1.0); 669*64b14621SArmin Le Grand //aNew.translate(aBackUnitRange.getMinX(), 0.0); 670*64b14621SArmin Le Grand aNew.set(0, 0, aBackUnitRange.getWidth()); 671*64b14621SArmin Le Grand aNew.set(0, 2, aBackUnitRange.getMinX()); 672*64b14621SArmin Le Grand 673*64b14621SArmin Le Grand // adapt y position to current step 674*64b14621SArmin Le Grand aNew.set(1, 2, fStart); 675*64b14621SArmin Le Grand //aNew.translate(0.0, fStart); 676*64b14621SArmin Le Grand 677*64b14621SArmin Le Grand // add new transformation 678*64b14621SArmin Le Grand rMatrices.push_back(maTextureTransform * aNew); 679*64b14621SArmin Le Grand 680*64b14621SArmin Le Grand // next step 681*64b14621SArmin Le Grand fStart += mfDistance; 682*64b14621SArmin Le Grand nMaxIntegerSteps--; 683*64b14621SArmin Le Grand } 684*64b14621SArmin Le Grand } 685*64b14621SArmin Le Grand } 686cdf0e10cSrcweir getDistanceToHatch(const basegfx::B2DPoint & rUV) const687cdf0e10cSrcweir double GeoTexSvxHatch::getDistanceToHatch(const basegfx::B2DPoint& rUV) const 688cdf0e10cSrcweir { 68996fc4b33SArmin Le Grand const basegfx::B2DPoint aCoor(getBackTextureTransform() * rUV); 690cdf0e10cSrcweir return fmod(aCoor.getY(), mfDistance); 691cdf0e10cSrcweir } 69296fc4b33SArmin Le Grand getBackTextureTransform() const69396fc4b33SArmin Le Grand const basegfx::B2DHomMatrix& GeoTexSvxHatch::getBackTextureTransform() const 69496fc4b33SArmin Le Grand { 69596fc4b33SArmin Le Grand if(maBackTextureTransform.isIdentity()) 69696fc4b33SArmin Le Grand { 69796fc4b33SArmin Le Grand const_cast< GeoTexSvxHatch* >(this)->maBackTextureTransform = maTextureTransform; 69896fc4b33SArmin Le Grand const_cast< GeoTexSvxHatch* >(this)->maBackTextureTransform.invert(); 69996fc4b33SArmin Le Grand } 70096fc4b33SArmin Le Grand 70196fc4b33SArmin Le Grand return maBackTextureTransform; 70296fc4b33SArmin Le Grand } 703cdf0e10cSrcweir } // end of namespace texture 704cdf0e10cSrcweir } // end of namespace drawinglayer 705cdf0e10cSrcweir 706cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 707cdf0e10cSrcweir 708cdf0e10cSrcweir namespace drawinglayer 709cdf0e10cSrcweir { 710cdf0e10cSrcweir namespace texture 711cdf0e10cSrcweir { GeoTexSvxTiled(const basegfx::B2DRange & rRange,double fOffsetX,double fOffsetY)71296fc4b33SArmin Le Grand GeoTexSvxTiled::GeoTexSvxTiled( 713035a2f44SArmin Le Grand const basegfx::B2DRange& rRange, 714035a2f44SArmin Le Grand double fOffsetX, 715035a2f44SArmin Le Grand double fOffsetY) 716035a2f44SArmin Le Grand : maRange(rRange), 717035a2f44SArmin Le Grand mfOffsetX(basegfx::clamp(fOffsetX, 0.0, 1.0)), 718035a2f44SArmin Le Grand mfOffsetY(basegfx::clamp(fOffsetY, 0.0, 1.0)) 719cdf0e10cSrcweir { 720035a2f44SArmin Le Grand if(!basegfx::fTools::equalZero(mfOffsetX)) 721cdf0e10cSrcweir { 722035a2f44SArmin Le Grand mfOffsetY = 0.0; 723cdf0e10cSrcweir } 724cdf0e10cSrcweir } 725cdf0e10cSrcweir ~GeoTexSvxTiled()726cdf0e10cSrcweir GeoTexSvxTiled::~GeoTexSvxTiled() 727cdf0e10cSrcweir { 728cdf0e10cSrcweir } 729cdf0e10cSrcweir operator ==(const GeoTexSvx & rGeoTexSvx) const730cdf0e10cSrcweir bool GeoTexSvxTiled::operator==(const GeoTexSvx& rGeoTexSvx) const 731cdf0e10cSrcweir { 732cdf0e10cSrcweir const GeoTexSvxTiled* pCompare = dynamic_cast< const GeoTexSvxTiled* >(&rGeoTexSvx); 733035a2f44SArmin Le Grand 734cdf0e10cSrcweir return (pCompare 735035a2f44SArmin Le Grand && maRange == pCompare->maRange 736035a2f44SArmin Le Grand && mfOffsetX == pCompare->mfOffsetX 737035a2f44SArmin Le Grand && mfOffsetY == pCompare->mfOffsetY); 738cdf0e10cSrcweir } 739cdf0e10cSrcweir appendTransformations(::std::vector<basegfx::B2DHomMatrix> & rMatrices)740cdf0e10cSrcweir void GeoTexSvxTiled::appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices) 741cdf0e10cSrcweir { 742035a2f44SArmin Le Grand const double fWidth(maRange.getWidth()); 743035a2f44SArmin Le Grand 744035a2f44SArmin Le Grand if(!basegfx::fTools::equalZero(fWidth)) 745035a2f44SArmin Le Grand { 746035a2f44SArmin Le Grand const double fHeight(maRange.getHeight()); 747035a2f44SArmin Le Grand 748035a2f44SArmin Le Grand if(!basegfx::fTools::equalZero(fHeight)) 749035a2f44SArmin Le Grand { 750035a2f44SArmin Le Grand double fStartX(maRange.getMinX()); 751035a2f44SArmin Le Grand double fStartY(maRange.getMinY()); 752035a2f44SArmin Le Grand sal_Int32 nPosX(0); 753035a2f44SArmin Le Grand sal_Int32 nPosY(0); 754cdf0e10cSrcweir 755cdf0e10cSrcweir if(basegfx::fTools::more(fStartX, 0.0)) 756cdf0e10cSrcweir { 757035a2f44SArmin Le Grand const sal_Int32 nDiff(static_cast<sal_Int32>(floor(fStartX / fWidth)) + 1); 758035a2f44SArmin Le Grand 759035a2f44SArmin Le Grand nPosX -= nDiff; 760035a2f44SArmin Le Grand fStartX -= nDiff * fWidth; 761cdf0e10cSrcweir } 762cdf0e10cSrcweir 763035a2f44SArmin Le Grand if(basegfx::fTools::less(fStartX + fWidth, 0.0)) 764cdf0e10cSrcweir { 765035a2f44SArmin Le Grand const sal_Int32 nDiff(static_cast<sal_Int32>(floor(-fStartX / fWidth))); 766035a2f44SArmin Le Grand 767035a2f44SArmin Le Grand nPosX += nDiff; 768035a2f44SArmin Le Grand fStartX += nDiff * fWidth; 769cdf0e10cSrcweir } 770cdf0e10cSrcweir 771cdf0e10cSrcweir if(basegfx::fTools::more(fStartY, 0.0)) 772cdf0e10cSrcweir { 773035a2f44SArmin Le Grand const sal_Int32 nDiff(static_cast<sal_Int32>(floor(fStartY / fHeight)) + 1); 774035a2f44SArmin Le Grand 775035a2f44SArmin Le Grand nPosY -= nDiff; 776035a2f44SArmin Le Grand fStartY -= nDiff * fHeight; 777cdf0e10cSrcweir } 778cdf0e10cSrcweir 779035a2f44SArmin Le Grand if(basegfx::fTools::less(fStartY + fHeight, 0.0)) 780cdf0e10cSrcweir { 781035a2f44SArmin Le Grand const sal_Int32 nDiff(static_cast<sal_Int32>(floor(-fStartY / fHeight))); 782035a2f44SArmin Le Grand 783035a2f44SArmin Le Grand nPosY += nDiff; 784035a2f44SArmin Le Grand fStartY += nDiff * fHeight; 785cdf0e10cSrcweir } 786cdf0e10cSrcweir 787035a2f44SArmin Le Grand if(!basegfx::fTools::equalZero(mfOffsetY)) 788cdf0e10cSrcweir { 789035a2f44SArmin Le Grand for(double fPosX(fStartX); basegfx::fTools::less(fPosX, 1.0); fPosX += fWidth, nPosX++) 790cdf0e10cSrcweir { 791035a2f44SArmin Le Grand for(double fPosY(nPosX % 2 ? fStartY - fHeight + (mfOffsetY * fHeight) : fStartY); 792035a2f44SArmin Le Grand basegfx::fTools::less(fPosY, 1.0); fPosY += fHeight) 793035a2f44SArmin Le Grand { 794035a2f44SArmin Le Grand rMatrices.push_back( 795035a2f44SArmin Le Grand basegfx::tools::createScaleTranslateB2DHomMatrix( 796035a2f44SArmin Le Grand fWidth, 797035a2f44SArmin Le Grand fHeight, 798035a2f44SArmin Le Grand fPosX, 799035a2f44SArmin Le Grand fPosY)); 800035a2f44SArmin Le Grand } 801035a2f44SArmin Le Grand } 802035a2f44SArmin Le Grand } 803035a2f44SArmin Le Grand else 804035a2f44SArmin Le Grand { 805035a2f44SArmin Le Grand for(double fPosY(fStartY); basegfx::fTools::less(fPosY, 1.0); fPosY += fHeight, nPosY++) 806035a2f44SArmin Le Grand { 807035a2f44SArmin Le Grand for(double fPosX(nPosY % 2 ? fStartX - fWidth + (mfOffsetX * fWidth) : fStartX); 808035a2f44SArmin Le Grand basegfx::fTools::less(fPosX, 1.0); fPosX += fWidth) 809035a2f44SArmin Le Grand { 810035a2f44SArmin Le Grand rMatrices.push_back( 811035a2f44SArmin Le Grand basegfx::tools::createScaleTranslateB2DHomMatrix( 812035a2f44SArmin Le Grand fWidth, 813035a2f44SArmin Le Grand fHeight, 814035a2f44SArmin Le Grand fPosX, 815035a2f44SArmin Le Grand fPosY)); 816035a2f44SArmin Le Grand } 817035a2f44SArmin Le Grand } 818035a2f44SArmin Le Grand } 819cdf0e10cSrcweir } 820cdf0e10cSrcweir } 821cdf0e10cSrcweir } 822cdf0e10cSrcweir } // end of namespace texture 823cdf0e10cSrcweir } // end of namespace drawinglayer 824cdf0e10cSrcweir 825cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 826cdf0e10cSrcweir // eof 827