Moved PDF/PSGradientMaker into dedicated packages Factory stands for a pattern relating to application deployment. This is just about rendering a gradient to a certain output format. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1609758 13f79535-47bb-0310-9956-ffa450edef68tags/fop-2_0
@@ -15,7 +15,7 @@ | |||
* limitations under the License. | |||
*/ | |||
package org.apache.fop.render.shading; | |||
package org.apache.fop.render.pdf.svg; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@@ -24,13 +24,16 @@ import org.apache.fop.pdf.PDFDeviceColorSpace; | |||
import org.apache.fop.pdf.PDFFunction; | |||
import org.apache.fop.pdf.PDFPattern; | |||
import org.apache.fop.pdf.PDFShading; | |||
import org.apache.fop.render.shading.Function; | |||
import org.apache.fop.render.shading.GradientMaker; | |||
import org.apache.fop.render.shading.Shading; | |||
import org.apache.fop.svg.PDFGraphics2D; | |||
public class PDFGradientFactory extends GradientFactory<PDFPattern> { | |||
public class PDFGradientMaker extends GradientMaker<PDFPattern> { | |||
private final PDFGraphics2D graphics2D; | |||
public PDFGradientFactory(PDFGraphics2D pdfGraphics2D) { | |||
public PDFGradientMaker(PDFGraphics2D pdfGraphics2D) { | |||
this.graphics2D = pdfGraphics2D; | |||
} | |||
@@ -15,15 +15,16 @@ | |||
* limitations under the License. | |||
*/ | |||
package org.apache.fop.render.shading; | |||
package org.apache.fop.render.ps.svg; | |||
import java.util.List; | |||
import org.apache.fop.pdf.PDFDeviceColorSpace; | |||
import org.apache.fop.render.ps.svg.PSPattern; | |||
import org.apache.fop.render.ps.svg.PSShading; | |||
import org.apache.fop.render.shading.Function; | |||
import org.apache.fop.render.shading.GradientMaker; | |||
import org.apache.fop.render.shading.Shading; | |||
public class PSGradientFactory extends GradientFactory<PSPattern> { | |||
public class PSGradientMaker extends GradientMaker<PSPattern> { | |||
@Override | |||
protected Shading makeShading(int shadingType, |
@@ -33,7 +33,6 @@ import org.apache.batik.ext.awt.RadialGradientPaint; | |||
import org.apache.xmlgraphics.java2d.ps.PSGraphics2D; | |||
import org.apache.xmlgraphics.ps.PSGenerator; | |||
import org.apache.fop.render.shading.PSGradientFactory; | |||
import org.apache.fop.render.shading.Pattern; | |||
@@ -71,16 +70,16 @@ public class PSSVGGraphics2D extends PSGraphics2D { | |||
protected void applyPaint(Paint paint, boolean fill) { | |||
super.applyPaint(paint, fill); | |||
if (paint instanceof LinearGradientPaint) { | |||
Pattern pattern = new PSGradientFactory() | |||
.createLinearGradient((LinearGradientPaint) paint, getBaseTransform(), getTransform()); | |||
Pattern pattern = new PSGradientMaker() | |||
.makeLinearGradient((LinearGradientPaint) paint, getBaseTransform(), getTransform()); | |||
try { | |||
gen.write(pattern.toString()); | |||
} catch (IOException ioe) { | |||
handleIOException(ioe); | |||
} | |||
} else if (paint instanceof RadialGradientPaint) { | |||
Pattern pattern = new PSGradientFactory() | |||
.createRadialGradient((RadialGradientPaint) paint, getBaseTransform(), getTransform()); | |||
Pattern pattern = new PSGradientMaker() | |||
.makeRadialGradient((RadialGradientPaint) paint, getBaseTransform(), getTransform()); | |||
try { | |||
gen.write(pattern.toString()); | |||
} catch (IOException ioe) { |
@@ -33,9 +33,9 @@ import org.apache.xmlgraphics.java2d.color.ColorUtil; | |||
import org.apache.fop.pdf.PDFDeviceColorSpace; | |||
public abstract class GradientFactory<P extends Pattern> { | |||
public abstract class GradientMaker<P extends Pattern> { | |||
public P createLinearGradient(LinearGradientPaint gp, | |||
public P makeLinearGradient(LinearGradientPaint gp, | |||
AffineTransform baseTransform, AffineTransform transform) { | |||
Point2D startPoint = gp.getStartPoint(); | |||
Point2D endPoint = gp.getEndPoint(); | |||
@@ -44,10 +44,10 @@ public abstract class GradientFactory<P extends Pattern> { | |||
coords.add(new Double(startPoint.getY())); | |||
coords.add(new Double(endPoint.getX())); | |||
coords.add(new Double(endPoint.getY())); | |||
return createGradient(gp, coords, baseTransform, transform); | |||
return makeGradient(gp, coords, baseTransform, transform); | |||
} | |||
public P createRadialGradient(RadialGradientPaint gradient, | |||
public P makeRadialGradient(RadialGradientPaint gradient, | |||
AffineTransform baseTransform, AffineTransform transform) { | |||
double radius = gradient.getRadius(); | |||
Point2D center = gradient.getCenterPoint(); | |||
@@ -69,14 +69,14 @@ public abstract class GradientFactory<P extends Pattern> { | |||
coords.add(Double.valueOf(center.getX())); | |||
coords.add(Double.valueOf(center.getY())); | |||
coords.add(Double.valueOf(radius)); | |||
return createGradient(gradient, coords, baseTransform, transform); | |||
return makeGradient(gradient, coords, baseTransform, transform); | |||
} | |||
private P createGradient(MultipleGradientPaint gradient, List<Double> coords, | |||
private P makeGradient(MultipleGradientPaint gradient, List<Double> coords, | |||
AffineTransform baseTransform, AffineTransform transform) { | |||
List<Double> matrix = createTransform(gradient, baseTransform, transform); | |||
List<Double> bounds = createBounds(gradient); | |||
List<Function> functions = createFunctions(gradient); | |||
List<Double> matrix = makeTransform(gradient, baseTransform, transform); | |||
List<Double> bounds = makeBounds(gradient); | |||
List<Function> functions = makeFunctions(gradient); | |||
// Gradients are currently restricted to sRGB | |||
PDFDeviceColorSpace colorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB); | |||
Function function = new Function(3, null, null, functions, bounds, null); | |||
@@ -85,7 +85,7 @@ public abstract class GradientFactory<P extends Pattern> { | |||
return makePattern(2, shading, matrix); | |||
} | |||
private List<Double> createTransform(MultipleGradientPaint gradient, | |||
private List<Double> makeTransform(MultipleGradientPaint gradient, | |||
AffineTransform baseTransform, AffineTransform transform) { | |||
AffineTransform gradientTransform = new AffineTransform(baseTransform); | |||
gradientTransform.concatenate(transform); | |||
@@ -105,7 +105,7 @@ public abstract class GradientFactory<P extends Pattern> { | |||
return c.getColorSpace().isCS_sRGB() ? c : ColorUtil.toSRGBColor(c); | |||
} | |||
private List<Double> createBounds(MultipleGradientPaint gradient) { | |||
private List<Double> makeBounds(MultipleGradientPaint gradient) { | |||
// TODO is the conversion to double necessary? | |||
float[] fractions = gradient.getFractions(); | |||
List<Double> bounds = new java.util.ArrayList<Double>(fractions.length); | |||
@@ -117,8 +117,8 @@ public abstract class GradientFactory<P extends Pattern> { | |||
return bounds; | |||
} | |||
private List<Function> createFunctions(MultipleGradientPaint gradient) { | |||
List<Color> colors = createColors(gradient); | |||
private List<Function> makeFunctions(MultipleGradientPaint gradient) { | |||
List<Color> colors = makeColors(gradient); | |||
List<Function> functions = new ArrayList<Function>(); | |||
for (int currentPosition = 0, lastPosition = colors.size() - 1; | |||
currentPosition < lastPosition; | |||
@@ -133,7 +133,7 @@ public abstract class GradientFactory<P extends Pattern> { | |||
return functions; | |||
} | |||
private List<Color> createColors(MultipleGradientPaint gradient) { | |||
private List<Color> makeColors(MultipleGradientPaint gradient) { | |||
Color[] svgColors = gradient.getColors(); | |||
List<Color> gradientColors = new ArrayList<Color>(svgColors.length + 2); | |||
float[] fractions = gradient.getFractions(); | |||
@@ -153,4 +153,5 @@ public abstract class GradientFactory<P extends Pattern> { | |||
List<Double> coords, Function function); | |||
protected abstract P makePattern(int patternType, Shading shading, List<Double> matrix); | |||
} |
@@ -95,7 +95,7 @@ import org.apache.fop.pdf.PDFXObject; | |||
import org.apache.fop.render.pdf.ImageRawCCITTFaxAdapter; | |||
import org.apache.fop.render.pdf.ImageRawJPEGAdapter; | |||
import org.apache.fop.render.pdf.ImageRenderedAdapter; | |||
import org.apache.fop.render.shading.PDFGradientFactory; | |||
import org.apache.fop.render.pdf.svg.PDFGradientMaker; | |||
/** | |||
* <p>PDF Graphics 2D. | |||
@@ -813,14 +813,14 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand | |||
gpaint.isCyclic() ? LinearGradientPaint.REPEAT : LinearGradientPaint.NO_CYCLE); | |||
} | |||
if (paint instanceof LinearGradientPaint && gradientSupported((LinearGradientPaint) paint)) { | |||
PDFPattern pattern = new PDFGradientFactory(this) | |||
.createLinearGradient((LinearGradientPaint) paint, getBaseTransform(), getTransform()); | |||
PDFPattern pattern = new PDFGradientMaker(this) | |||
.makeLinearGradient((LinearGradientPaint) paint, getBaseTransform(), getTransform()); | |||
currentStream.write(pattern.getColorSpaceOut(fill)); | |||
return true; | |||
} | |||
if (paint instanceof RadialGradientPaint && gradientSupported((RadialGradientPaint) paint)) { | |||
PDFPattern pattern = new PDFGradientFactory(this) | |||
.createRadialGradient((RadialGradientPaint) paint, getBaseTransform(), getTransform()); | |||
PDFPattern pattern = new PDFGradientMaker(this) | |||
.makeRadialGradient((RadialGradientPaint) paint, getBaseTransform(), getTransform()); | |||
currentStream.write(pattern.getColorSpaceOut(fill)); | |||
return true; | |||
} |