From 58c137a7e685be701c9df214309aa81be9e9128a Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Mon, 10 Apr 2006 10:42:58 +0000 Subject: [PATCH] Bugzilla #39033: Enancement: convert java.awt.GradientPaint to Batik's LinearGradientPaint to avoid rasterization when painting. This is useful when someone uses PDFGraphics2D outside FOP. Submitted by: Michal Sevcenko git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@392917 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/svg/PDFGraphics2D.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/java/org/apache/fop/svg/PDFGraphics2D.java b/src/java/org/apache/fop/svg/PDFGraphics2D.java index 16c3573cb..1709caba7 100644 --- a/src/java/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/java/org/apache/fop/svg/PDFGraphics2D.java @@ -60,6 +60,7 @@ import java.awt.Color; import java.awt.GraphicsConfiguration; /* java.awt.Font is not imported to avoid confusion with org.apache.fop.fonts.Font */ +import java.awt.GradientPaint; import java.awt.Image; import java.awt.Shape; import java.awt.Stroke; @@ -852,6 +853,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { * * @param paint the paint to convert to PDF * @param fill true if the paint should be set for filling + * @return true if the paint is handled natively, false if the paint should be rasterized */ protected boolean applyPaint(Paint paint, boolean fill) { preparePainting(); @@ -859,6 +861,18 @@ public class PDFGraphics2D extends AbstractGraphics2D { if (paint instanceof Color) { return true; } + // convert java.awt.GradientPaint to LinearGradientPaint to avoid rasterization + if (paint instanceof GradientPaint) { + GradientPaint gpaint = (GradientPaint) paint; + paint = new LinearGradientPaint( + (float) gpaint.getPoint1().getX(), + (float) gpaint.getPoint1().getY(), + (float) gpaint.getPoint2().getX(), + (float) gpaint.getPoint2().getY(), + new float[] {0, 1}, + new Color[] {gpaint.getColor1(), gpaint.getColor2()}, + gpaint.isCyclic() ? LinearGradientPaint.REPEAT : LinearGradientPaint.NO_CYCLE); + } if (paint instanceof LinearGradientPaint) { LinearGradientPaint gp = (LinearGradientPaint)paint; -- 2.39.5