You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by vh...@apache.org on 2014/07/10 19:59:15 UTC
svn commit: r1609530 -
/xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/GradientFactory.java
Author: vhennebert
Date: Thu Jul 10 17:59:14 2014
New Revision: 1609530
URL: http://svn.apache.org/r1609530
Log:
Factorized code that is common to linear and radial gradient creation
Modified:
xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/GradientFactory.java
Modified: xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/GradientFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/GradientFactory.java?rev=1609530&r1=1609529&r2=1609530&view=diff
==============================================================================
--- xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/GradientFactory.java (original)
+++ xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/shading/GradientFactory.java Thu Jul 10 17:59:14 2014
@@ -37,8 +37,6 @@ public abstract class GradientFactory<P
public P createLinearGradient(LinearGradientPaint gp,
AffineTransform baseTransform, AffineTransform transform) {
- List<Double> matrix = createGradientTransform(gp, baseTransform, transform);
-
Point2D startPoint = gp.getStartPoint();
Point2D endPoint = gp.getEndPoint();
List<Double> coords = new java.util.ArrayList<Double>(4);
@@ -46,52 +44,45 @@ public abstract class GradientFactory<P
coords.add(new Double(startPoint.getY()));
coords.add(new Double(endPoint.getX()));
coords.add(new Double(endPoint.getY()));
-
- List<Color> colors = createGradientColors(gp);
-
- List<Double> bounds = createGradientBounds(gp);
-
- //Gradients are currently restricted to sRGB
- PDFDeviceColorSpace colSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
- return createGradient(false, colSpace, colors, bounds, coords, matrix);
+ return createGradient(gp, coords, baseTransform, transform);
}
- public P createRadialGradient(RadialGradientPaint gp,
+ public P createRadialGradient(RadialGradientPaint gradient,
AffineTransform baseTransform, AffineTransform transform) {
- List<Double> matrix = createGradientTransform(gp, baseTransform, transform);
-
- double ar = gp.getRadius();
- Point2D ac = gp.getCenterPoint();
- Point2D af = gp.getFocusPoint();
- List<Double> theCoords = new java.util.ArrayList<Double>();
- double dx = af.getX() - ac.getX();
- double dy = af.getY() - ac.getY();
+ double radius = gradient.getRadius();
+ Point2D center = gradient.getCenterPoint();
+ Point2D focus = gradient.getFocusPoint();
+ double dx = focus.getX() - center.getX();
+ double dy = focus.getY() - center.getY();
double d = Math.sqrt(dx * dx + dy * dy);
- if (d > ar) {
- // the center point af must be within the circle with
- // radius ar centered at ac so limit it to that.
- double scale = (ar * .9999) / d;
- dx = dx * scale;
- dy = dy * scale;
- }
-
- theCoords.add(new Double(ac.getX() + dx)); // Fx
- theCoords.add(new Double(ac.getY() + dy)); // Fy
- theCoords.add(new Double(0));
- theCoords.add(new Double(ac.getX()));
- theCoords.add(new Double(ac.getY()));
- theCoords.add(new Double(ar));
-
- List<Color> colors = createGradientColors(gp);
-
- List<Double> bounds = createGradientBounds(gp);
+ if (d > radius) {
+ // The center point must be within the circle with
+ // radius radius centered at center so limit it to that.
+ double scale = (radius * .9999) / d;
+ dx *= scale;
+ dy *= scale;
+ }
+ List<Double> coords = new java.util.ArrayList<Double>();
+ coords.add(Double.valueOf(center.getX() + dx));
+ coords.add(Double.valueOf(center.getY() + dy));
+ coords.add(Double.valueOf(0));
+ coords.add(Double.valueOf(center.getX()));
+ coords.add(Double.valueOf(center.getY()));
+ coords.add(Double.valueOf(radius));
+ return createGradient(gradient, coords, baseTransform, transform);
+ }
+ private P createGradient(MultipleGradientPaint gradient, List<Double> coords,
+ AffineTransform baseTransform, AffineTransform transform) {
+ List<Double> matrix = createTransform(gradient, baseTransform, transform);
+ List<Color> colors = createColors(gradient);
+ List<Double> bounds = createBounds(gradient);
//Gradients are currently restricted to sRGB
PDFDeviceColorSpace colSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
- return createGradient(true, colSpace, colors, bounds, theCoords, matrix);
+ return createGradient(gradient instanceof RadialGradientPaint, colSpace, colors, bounds, coords, matrix);
}
- private List<Double> createGradientTransform(MultipleGradientPaint gradient,
+ private List<Double> createTransform(MultipleGradientPaint gradient,
AffineTransform baseTransform, AffineTransform transform) {
AffineTransform gradientTransform = new AffineTransform(baseTransform);
gradientTransform.concatenate(transform);
@@ -105,7 +96,7 @@ public abstract class GradientFactory<P
return matrix;
}
- private List<Color> createGradientColors(MultipleGradientPaint gradient) {
+ private List<Color> createColors(MultipleGradientPaint gradient) {
Color[] svgColors = gradient.getColors();
List<Color> gradientColors = new ArrayList<Color>(svgColors.length + 2);
float[] fractions = gradient.getFractions();
@@ -121,7 +112,7 @@ public abstract class GradientFactory<P
return gradientColors;
}
- private List<Double> createGradientBounds(MultipleGradientPaint gradient) {
+ private List<Double> createBounds(MultipleGradientPaint gradient) {
// TODO is the conversion to double necessary?
float[] fractions = gradient.getFractions();
List<Double> bounds = new java.util.ArrayList<Double>(fractions.length);
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org