Browse Source

Fixed gradients in PostScript output

Linear gradients were not rendered properly in non-square shapes
Gradial gradients don't need to be rasterized in ellipses


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1609508 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-2_0
Vincent Hennebert 10 years ago
parent
commit
512823a2da

+ 0
- 15
src/java/org/apache/fop/render/ps/PSImageHandlerSVG.java View File

@@ -33,8 +33,6 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.imageio.ImageIO;

@@ -314,19 +312,6 @@ public class PSImageHandlerSVG implements ImageHandler {
}
}
String nodeName = curNode.getLocalName();
//Special case where rasterization needed for radial gradients
if (nodeName != null && nodeName.equals("ellipse")) {
String found = "";
String ellipseFill = curNode.getAttributes().getNamedItem("fill").getNodeValue();
Pattern pattern = Pattern.compile("#(.*?)\\)");
Matcher matcher = pattern.matcher(ellipseFill);
if (matcher.find()) {
found = matcher.group(1);
}
if (gradientsFound.get(found) != null) {
return true;
}
}
boolean inMatch = false;
if (!isMatched) {
inMatch = nodeName != null && gradMatches.contains(nodeName);

+ 11
- 2
src/java/org/apache/fop/render/ps/svg/PSPattern.java View File

@@ -48,6 +48,8 @@ public class PSPattern implements Pattern {
*/
protected StringBuffer extGState = null;

private final List<Double> matrix;

/**
* Creates a radial or axial shading pattern
* @param thePatternType The pattern type which will be 3 for radial and 2 for axial
@@ -57,12 +59,13 @@ public class PSPattern implements Pattern {
* @param theExtGState The exit state
*/
public PSPattern(int thePatternType, Shading theShading, List theXUID,
StringBuffer theExtGState) {
StringBuffer theExtGState, List<Double> matrix) {
this.patternType = 2; // thePatternType;
assert theShading instanceof PSShading;
this.shading = (PSShading)theShading;
this.xUID = theXUID;
this.extGState = theExtGState; // always null
this.matrix = matrix;
}

/**
@@ -96,7 +99,13 @@ public class PSPattern implements Pattern {
}

p.append(">> \n");
p.append("matrix makepattern setcolor\n");
p.append("[ ");
for (double m : matrix) {
p.append(Double.toString(m)); // TODO refactor so that PSGenerator.formatDouble can be used
p.append(" ");
}
p.append("] ");
p.append("makepattern setcolor\n");

return p.toString();
}

+ 26
- 27
src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java View File

@@ -23,6 +23,7 @@ import java.awt.Color;
import java.awt.Graphics;
import java.awt.Paint;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -117,20 +118,10 @@ public class PSSVGGraphics2D extends PSGraphics2D implements GradientRegistrar {


List<Double> theCoords = new java.util.ArrayList<Double>();


AffineTransform start = applyTransform(lgp.getTransform(),
lgp.getStartPoint().getX(), lgp.getStartPoint().getY());
AffineTransform end = applyTransform(lgp.getTransform(), lgp.getEndPoint().getX(), lgp.getEndPoint().getY());
double startX = start.getTranslateX();
double startY = start.getTranslateY();
double endX = end.getTranslateX();
double endY = end.getTranslateY();

theCoords.add(startX);
theCoords.add(startY);
theCoords.add(endX);
theCoords.add(endY);
theCoords.add(lgp.getStartPoint().getX());
theCoords.add(lgp.getStartPoint().getX());
theCoords.add(lgp.getEndPoint().getX());
theCoords.add(lgp.getEndPoint().getY());


List<Color> someColors = new java.util.ArrayList<Color>();
@@ -182,12 +173,6 @@ public class PSSVGGraphics2D extends PSGraphics2D implements GradientRegistrar {
rgp.getCenterPoint().getX(), rgp.getCenterPoint().getY());
AffineTransform resultFocus = applyTransform(rgp.getTransform(),
rgp.getFocusPoint().getX(), rgp.getFocusPoint().getY());
double scale = Math.sqrt(rgp.getTransform().getDeterminant());
double radius = rgp.getRadius() * scale;
double centreX = resultCentre.getTranslateX();
double centreY = resultCentre.getTranslateY();
double focusX = resultFocus.getTranslateX();
double focusY = resultFocus.getTranslateY();

List<Double> theMatrix = new java.util.ArrayList<Double>();
double [] mat = new double[6];
@@ -196,15 +181,29 @@ public class PSSVGGraphics2D extends PSGraphics2D implements GradientRegistrar {
theMatrix.add(Double.valueOf(mat[idx]));
}

List<Double> theCoords = new java.util.ArrayList<Double>();
float[] fractions = rgp.getFractions();

theCoords.add(centreX);
theCoords.add(centreY);
theCoords.add(0d);
theCoords.add(focusX);
theCoords.add(focusY);
theCoords.add(radius);
double ar = rgp.getRadius();
Point2D ac = rgp.getCenterPoint();
Point2D af = rgp.getFocusPoint();
List<Double> theCoords = new java.util.ArrayList<Double>();
double dx = af.getX() - ac.getX();
double dy = af.getY() - ac.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));

Color[] cols = rgp.getColors();
List<Color> someColors = new java.util.ArrayList<Color>();

+ 1
- 1
src/java/org/apache/fop/render/shading/PSGradientFactory.java View File

@@ -65,6 +65,6 @@ public class PSGradientFactory extends GradientFactory {
@Override
public Pattern makePattern(int thePatternType, Shading theShading, List theXUID,
StringBuffer theExtGState, List<Double> theMatrix) {
return new PSPattern(thePatternType, theShading, theXUID, theExtGState);
return new PSPattern(thePatternType, theShading, theXUID, theExtGState, theMatrix);
}
}

Loading…
Cancel
Save