1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <config_options.h>
23 #include <basegfx/point/b2dpoint.hxx>
24 #include <basegfx/vector/b2dvector.hxx>
25 #include <basegfx/matrix/b2dhommatrix.hxx>
26 #include <basegfx/basegfxdllapi.h>
28 namespace basegfx
{ class B2DRange
; }
32 /** Gradient definition as used in ODF 1.2
34 This struct collects all data necessary for rendering ODF
35 1.2-compatible gradients. Use the createXXXODFGradientInfo()
36 methods below for initializing from ODF attributes.
38 class UNLESS_MERGELIBS(BASEGFX_DLLPUBLIC
) ODFGradientInfo
41 /** transformation mapping from [0,1]^2 texture coordinate
42 space to [0,1]^2 shape coordinate space
44 B2DHomMatrix maTextureTransform
;
46 /** transformation mapping from [0,1]^2 shape coordinate space
47 to [0,1]^2 texture coordinate space. This is the
48 transformation commonly used to create gradients from a
49 scanline rasterizer (put shape u/v coordinates into it, get
50 texture s/t coordinates out of it)
52 B2DHomMatrix maBackTextureTransform
;
54 /** Aspect ratio of the gradient. Only used in drawinglayer
55 for generating nested gradient polygons currently. Already
56 catered for in the transformations above.
60 /** Requested gradient steps to render. See the
61 implementations of the getXXXGradientAlpha() methods below,
62 the semantic differs slightly for the different gradient
69 : maTextureTransform(),
70 maBackTextureTransform(),
77 const B2DHomMatrix
& rTextureTransform
,
80 : maTextureTransform(rTextureTransform
),
81 maBackTextureTransform(),
82 mfAspectRatio(fAspectRatio
),
87 ODFGradientInfo(const ODFGradientInfo
& rODFGradientInfo
)
88 : maTextureTransform(rODFGradientInfo
.getTextureTransform()),
89 maBackTextureTransform(rODFGradientInfo
.maBackTextureTransform
),
90 mfAspectRatio(rODFGradientInfo
.getAspectRatio()),
91 mnSteps(rODFGradientInfo
.getSteps())
95 ODFGradientInfo
& operator=(const ODFGradientInfo
& rODFGradientInfo
)
97 maTextureTransform
= rODFGradientInfo
.getTextureTransform();
98 maBackTextureTransform
= rODFGradientInfo
.maBackTextureTransform
;
99 mfAspectRatio
= rODFGradientInfo
.getAspectRatio();
100 mnSteps
= rODFGradientInfo
.getSteps();
106 bool operator==(const ODFGradientInfo
& rGeoTexSvx
) const;
108 const B2DHomMatrix
& getTextureTransform() const { return maTextureTransform
; }
109 const B2DHomMatrix
& getBackTextureTransform() const;
110 double getAspectRatio() const { return mfAspectRatio
; }
111 sal_uInt32
getSteps() const { return mnSteps
; }
113 void setTextureTransform(const B2DHomMatrix
& rNew
)
115 maTextureTransform
= rNew
;
116 maBackTextureTransform
.identity();
122 /** Create matrix for ODF's linear gradient definition
124 Note that odf linear gradients are varying in y direction.
126 @param o_rGradientInfo
127 Receives the calculated texture transformation matrix (for
128 use with standard [0,1]x[0,1] texture coordinates)
131 Output area, needed for aspect ratio calculations and
132 texture transformation
135 Number of gradient steps (from ODF)
138 Width of gradient border (from ODF)
141 Gradient angle (from ODF)
143 BASEGFX_DLLPUBLIC ODFGradientInfo
createLinearODFGradientInfo(
144 const B2DRange
& rTargetArea
,
150 /** Calculate linear gradient blend value
152 This method generates you the lerp alpha value for
153 blending linearly between gradient start and end color,
154 according to the formula (startCol*(1.0-alpha) + endCol*alpha)
157 Current uv coordinate. Values outside [0,1] will be
158 clamped. Assumes gradient color varies along the y axis.
161 Gradient info, for transformation and number of steps
163 BASEGFX_DLLPUBLIC
double getLinearGradientAlpha(const B2DPoint
& rUV
,
164 const ODFGradientInfo
& rGradInfo
);
166 /** Create matrix for ODF's axial gradient definition
168 Note that odf axial gradients are varying in y
169 direction. Note further that you can map the axial
170 gradient to a linear gradient (in case you want or need to
171 avoid an extra gradient renderer), by using
172 createLinearODFGradientInfo() instead, shifting the
173 resulting texture transformation by 0.5 to the top and
174 appending the same stop colors again, but mirrored.
176 @param o_rGradientInfo
177 Receives the calculated texture transformation matrix (for
178 use with standard [0,1]x[0,1] texture coordinates)
181 Output area, needed for aspect ratio calculations and
182 texture transformation
185 Number of gradient steps (from ODF)
188 Width of gradient border (from ODF)
191 Gradient angle (from ODF)
193 BASEGFX_DLLPUBLIC ODFGradientInfo
createAxialODFGradientInfo(
194 const B2DRange
& rTargetArea
,
200 /** Calculate axial gradient blend value
202 This method generates you the lerp alpha value for
203 blending linearly between gradient start and end color,
204 according to the formula (startCol*(1.0-alpha) + endCol*alpha)
207 Current uv coordinate. Values outside [0,1] will be
208 clamped. Assumes gradient color varies along the y axis.
211 Gradient info, for transformation and number of steps
213 BASEGFX_DLLPUBLIC
double getAxialGradientAlpha(const B2DPoint
& rUV
,
214 const ODFGradientInfo
& rGradInfo
);
216 /** Create matrix for ODF's radial gradient definition
218 @param o_rGradientInfo
219 Receives the calculated texture transformation matrix (for
220 use with standard [0,1]x[0,1] texture coordinates)
223 Output area, needed for aspect ratio calculations and
224 texture transformation
227 Gradient offset value (from ODF)
230 Number of gradient steps (from ODF)
233 Width of gradient border (from ODF)
236 Gradient angle (from ODF)
238 BASEGFX_DLLPUBLIC ODFGradientInfo
createRadialODFGradientInfo(
239 const B2DRange
& rTargetArea
,
240 const B2DVector
& rOffset
,
245 /** Calculate radial gradient blend value
247 This method generates you the lerp alpha value for
248 blending linearly between gradient start and end color,
249 according to the formula (startCol*(1.0-alpha) + endCol*alpha)
252 Current uv coordinate. Values outside [0,1] will be
256 Gradient info, for transformation and number of steps
258 BASEGFX_DLLPUBLIC
double getRadialGradientAlpha(const B2DPoint
& rUV
,
259 const ODFGradientInfo
& rGradInfo
);
261 /** Create matrix for ODF's elliptical gradient definition
263 @param o_rGradientInfo
264 Receives the calculated texture transformation matrix (for
265 use with standard [0,1]x[0,1] texture coordinates)
268 Output area, needed for aspect ratio calculations and
269 texture transformation
272 Gradient offset value (from ODF)
275 Number of gradient steps (from ODF)
278 Width of gradient border (from ODF)
281 Gradient angle (from ODF)
283 BASEGFX_DLLPUBLIC ODFGradientInfo
createEllipticalODFGradientInfo(
284 const B2DRange
& rTargetArea
,
285 const B2DVector
& rOffset
,
291 /** Calculate elliptical gradient blend value
293 This method generates you the lerp alpha value for
294 blending linearly between gradient start and end color,
295 according to the formula (startCol*(1.0-alpha) + endCol*alpha)
298 Current uv coordinate. Values outside [0,1] will be
302 Gradient info, for transformation and number of steps
304 BASEGFX_DLLPUBLIC
double getEllipticalGradientAlpha(const B2DPoint
& rUV
,
305 const ODFGradientInfo
& rGradInfo
);
307 /** Create matrix for ODF's square gradient definition
309 @param o_rGradientInfo
310 Receives the calculated texture transformation matrix (for
311 use with standard [0,1]x[0,1] texture coordinates)
314 Output area, needed for aspect ratio calculations and
315 texture transformation
318 Gradient offset value (from ODF)
321 Number of gradient steps (from ODF)
324 Width of gradient border (from ODF)
327 Gradient angle (from ODF)
329 BASEGFX_DLLPUBLIC ODFGradientInfo
createSquareODFGradientInfo(
330 const B2DRange
& rTargetArea
,
331 const B2DVector
& rOffset
,
337 /** Calculate square gradient blend value
339 This method generates you the lerp alpha value for
340 blending linearly between gradient start and end color,
341 according to the formula (startCol*(1.0-alpha) + endCol*alpha)
344 Current uv coordinate. Values outside [0,1] will be
348 Gradient info, for transformation and number of steps
350 BASEGFX_DLLPUBLIC
double getSquareGradientAlpha(const B2DPoint
& rUV
,
351 const ODFGradientInfo
& rGradInfo
);
353 /** Create matrix for ODF's rectangular gradient definition
355 @param o_rGradientInfo
356 Receives the calculated texture transformation matrix (for
357 use with standard [0,1]x[0,1] texture coordinates)
360 Output area, needed for aspect ratio calculations and
361 texture transformation
364 Gradient offset value (from ODF)
367 Number of gradient steps (from ODF)
370 Width of gradient border (from ODF)
373 Gradient angle (from ODF)
375 BASEGFX_DLLPUBLIC ODFGradientInfo
createRectangularODFGradientInfo(
376 const B2DRange
& rTargetArea
,
377 const B2DVector
& rOffset
,
383 /** Calculate rectangular gradient blend value
385 This method generates you the lerp alpha value for
386 blending linearly between gradient start and end color,
387 according to the formula (startCol*(1.0-alpha) + endCol*alpha)
390 Current uv coordinate. Values outside [0,1] will be
394 Gradient info, for transformation and number of steps
396 BASEGFX_DLLPUBLIC
double getRectangularGradientAlpha(const B2DPoint
& rUV
,
397 const ODFGradientInfo
& rGradInfo
);
401 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */