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