Author: vhennebert
Date: Thu Jul 10 17:53:22 2014
New Revision: 1609527
URL: http://svn.apache.org/r1609527
Log:
Moved checks for repeated gradient out of gradient-creation methods
Will ease factorizing of common code between PDF and PostScript
Modified:
xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java
xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/svg/PDFGraphics2D.java
Modified:
xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java?rev=1609527&r1=1609526&r2=1609527&view=diff
==============================================================================
---
xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java
(original)
+++
xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java
Thu Jul 10 17:53:22 2014
@@ -97,11 +97,6 @@ public class PSSVGGraphics2D extends PSG
}
private void handleLinearGradient(LinearGradientPaint gp, PSGenerator gen)
throws IOException {
- MultipleGradientPaint.CycleMethodEnum cycle = gp.getCycleMethod();
- if (cycle != MultipleGradientPaint.NO_CYCLE) {
- return;
- }
-
List<Double> matrix = createGradientTransform(gp);
Point2D startPoint = gp.getStartPoint();
@@ -125,11 +120,6 @@ public class PSSVGGraphics2D extends PSG
}
private void handleRadialGradient(RadialGradientPaint gp, PSGenerator gen)
throws IOException {
- MultipleGradientPaint.CycleMethodEnum cycle = gp.getCycleMethod();
- if (cycle != MultipleGradientPaint.NO_CYCLE) {
- return;
- }
-
List<Double> matrix = createGradientTransform(gp);
double ar = gp.getRadius();
Modified:
xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/svg/PDFGraphics2D.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/svg/PDFGraphics2D.java?rev=1609527&r1=1609526&r2=1609527&view=diff
==============================================================================
---
xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/svg/PDFGraphics2D.java
(original)
+++
xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/svg/PDFGraphics2D.java
Thu Jul 10 17:53:22 2014
@@ -818,11 +818,13 @@ public class PDFGraphics2D extends Abstr
new Color[] {gpaint.getColor1(), gpaint.getColor2()},
gpaint.isCyclic() ? LinearGradientPaint.REPEAT :
LinearGradientPaint.NO_CYCLE);
}
- if (paint instanceof LinearGradientPaint &&
!gradientContainsTransparency((LinearGradientPaint) paint)) {
- return applyLinearGradient(paint, fill);
- }
- if (paint instanceof RadialGradientPaint &&
!gradientContainsTransparency((RadialGradientPaint) paint)) {
- return applyRadialGradient(paint, fill);
+ if (paint instanceof LinearGradientPaint &&
gradientSupported((LinearGradientPaint) paint)) {
+ applyLinearGradient((LinearGradientPaint) paint, fill);
+ return true;
+ }
+ if (paint instanceof RadialGradientPaint &&
gradientSupported((RadialGradientPaint) paint)) {
+ applyRadialGradient((RadialGradientPaint) paint, fill);
+ return true;
}
if (paint instanceof PatternPaint) {
PatternPaint pp = (PatternPaint)paint;
@@ -831,6 +833,10 @@ public class PDFGraphics2D extends Abstr
return false; // unknown paint
}
+ private boolean gradientSupported(MultipleGradientPaint gradient) {
+ return !(gradientContainsTransparency(gradient) ||
gradientIsRepeated(gradient));
+ }
+
private boolean gradientContainsTransparency(MultipleGradientPaint
gradient) {
for (Color color : gradient.getColors()) {
if (color.getAlpha() != 255) {
@@ -840,20 +846,20 @@ public class PDFGraphics2D extends Abstr
return false;
}
- private boolean applyLinearGradient(Paint paint, boolean fill) {
- LinearGradientPaint gp = (LinearGradientPaint)paint;
-
- // This code currently doesn't support 'repeat'.
- // For linear gradients it is possible to construct
- // a 'tile' that is repeated with a PDF pattern, but
- // it would be very tricky as you would have to rotate
- // the coordinate system so the repeat was axially
- // aligned. At this point I'm just going to rasterize it.
- MultipleGradientPaint.CycleMethodEnum cycle = gp.getCycleMethod();
- if (cycle != MultipleGradientPaint.NO_CYCLE) {
- return false;
- }
+ private boolean gradientIsRepeated(MultipleGradientPaint gradient) {
+ // For linear gradients it is possible to construct a 'tile' that is
repeated with
+ // a PDF pattern, but it would be very tricky as the coordinate
system would have
+ // to be rotated so the repeat is axially aligned.
+
+ // For radial gradients there is essentially no way to support
repeats in PDF (the
+ // one option would be to 'grow' the outer circle until it fully
covers the
+ // bounds and then grow the stops accordingly, the problem is that
this may
+ // require an extremely large number of stops for cases where the
focus is near
+ // the edge of the outer circle).
+ return (gradient.getCycleMethod() != MultipleGradientPaint.NO_CYCLE);
+ }
+ private void applyLinearGradient(LinearGradientPaint gp, boolean fill) {
List<Double> matrix = createGradientTransform(gp);
Point2D startPoint = gp.getStartPoint();
@@ -874,24 +880,9 @@ public class PDFGraphics2D extends Abstr
PDFPattern pattern = gradientFactory.createGradient(false, colSpace,
colors, bounds, coords, matrix);
currentStream.write(pattern.getColorSpaceOut(fill));
- return true;
}
- private boolean applyRadialGradient(Paint paint, boolean fill) {
- RadialGradientPaint gp = (RadialGradientPaint)paint;
-
- // There is essentially no way to support repeats
- // in PDF for radial gradients (the one option would
- // be to 'grow' the outer circle until it fully covered
- // the bounds and then grow the stops accordingly, the
- // problem is that this may require an extremely large
- // number of stops for cases where the focus is near
- // the edge of the outer circle). so we rasterize.
- MultipleGradientPaint.CycleMethodEnum cycle = gp.getCycleMethod();
- if (cycle != MultipleGradientPaint.NO_CYCLE) {
- return false;
- }
-
+ private void applyRadialGradient(RadialGradientPaint gp, boolean fill) {
List<Double> matrix = createGradientTransform(gp);
double ar = gp.getRadius();
@@ -926,7 +917,6 @@ public class PDFGraphics2D extends Abstr
PDFPattern pattern = gradientFactory.createGradient(true, colSpace,
colors, bounds, theCoords, matrix);
currentStream.write(pattern.getColorSpaceOut(fill));
- return true;
}
private List<Double> createGradientTransform(MultipleGradientPaint gp) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]