]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Bugzilla #39033:
authorJeremias Maerki <jeremias@apache.org>
Mon, 10 Apr 2006 10:42:58 +0000 (10:42 +0000)
committerJeremias Maerki <jeremias@apache.org>
Mon, 10 Apr 2006 10:42:58 +0000 (10:42 +0000)
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 <sevcenko.at.vc.cvut.cz>

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

index 16c3573cb9088ca0495d9c10396eec4ec24c830a..1709caba79cf778cea8e711ced644f3a9eeed4eb 100644 (file)
@@ -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;