]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
improved linear and radial gradients
authorKeiron Liddle <keiron@apache.org>
Tue, 9 Jul 2002 14:59:03 +0000 (14:59 +0000)
committerKeiron Liddle <keiron@apache.org>
Tue, 9 Jul 2002 14:59:03 +0000 (14:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194990 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/svg/PDFDocumentGraphics2D.java
src/org/apache/fop/svg/PDFGraphics2D.java

index 03cd602ea9e0d7db0438a05bc9ee11e99213e39b..3894d1140f2580aa8a2d95999a6643a7d5b38fee 100644 (file)
@@ -20,6 +20,7 @@ import java.awt.Color;
 import java.awt.Shape;
 import java.awt.font.FontRenderContext;
 import java.awt.font.GlyphVector;
+import java.awt.geom.AffineTransform;
 import java.io.OutputStream;
 import java.io.IOException;
 
@@ -92,7 +93,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D {
         resourceContext = currentPage;
         pageRef = currentPage.referencePDF();
         currentStream.write("1 0 0 -1 0 " + height + " cm\n");
-
+        graphicsState.setTransform(new AffineTransform(1.0, 0.0, 0.0, -1.0, 0.0, (double)height));
         pdfDoc.outputHeader(stream);
 
         setOutputStream(stream);
index 72686fb68545709302397d2e79c6764ae2cffee0..98736e5abae38d9624076875a041bd924537a18c 100644 (file)
@@ -639,10 +639,16 @@ public class PDFGraphics2D extends AbstractGraphics2D {
         if (paint instanceof LinearGradientPaint) {
             LinearGradientPaint gp = (LinearGradientPaint)paint;
             Color[] cols = gp.getColors();
+            float[] fractions = gp.getFractions();
             Point2D p1 = gp.getStartPoint();
             Point2D p2 = gp.getEndPoint();
             MultipleGradientPaint.CycleMethodEnum cycenum = gp.getCycleMethod();
             boolean cyclic = cycenum == MultipleGradientPaint.REPEAT;
+            AffineTransform transform = graphicsState.getTransform();
+            transform.concatenate(gp.getTransform());
+
+            p1 = transform.transform(p1, null);
+            p2 = transform.transform(p2, null);
 
             ArrayList theCoords = new ArrayList();
             theCoords.add(new Double(p1.getX()));
@@ -665,44 +671,51 @@ public class PDFGraphics2D extends AbstractGraphics2D {
             theEncode.add(new Double(1));
 
             ArrayList theBounds = new ArrayList();
-            theBounds.add(new Double(0));
-            theBounds.add(new Double(1));
-
-            ArrayList theFunctions = new ArrayList();
 
             ArrayList someColors = new ArrayList();
 
-            Color c1 = cols[0];
-            Color c2 = cols[1];
-
-            PDFColor color1 = new PDFColor(c1.getRed(), c1.getGreen(),
-                                           c1.getBlue());
-            someColors.add(color1);
-            PDFColor color2 = new PDFColor(c2.getRed(), c2.getGreen(),
-                                           c2.getBlue());
-            someColors.add(color2);
-
-            PDFFunction myfunc = this.pdfDoc.makeFunction(2, theDomain, null,
-                    color1.getVector(), color2.getVector(), 1.0);
+            for(int count = 0; count < cols.length; count++) {
+                Color c1 = cols[count];
+                PDFColor color1 = new PDFColor(c1.getRed(), c1.getGreen(),
+                                               c1.getBlue());
+                someColors.add(color1);
+                if(count > 0 && count < cols.length - 1) {
+                    theBounds.add(new Double(fractions[count]));
+                }
+            }
 
             PDFColorSpace aColorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
-            PDFPattern myPat = this.pdfDoc.createGradient(resourceContext, false, aColorSpace,
-                    someColors, null, theCoords);
+            PDFPattern myPat = pdfDoc.createGradient(resourceContext, false, aColorSpace,
+                    someColors, theBounds, theCoords);
             currentStream.write(myPat.getColorSpaceOut(fill));
 
         } else if (paint instanceof RadialGradientPaint) {
             RadialGradientPaint rgp = (RadialGradientPaint)paint;
 
-            float ar = rgp.getRadius();
+            double ar = rgp.getRadius();
             Point2D ac = rgp.getCenterPoint();
             Point2D af = rgp.getFocusPoint();
+            AffineTransform transform = graphicsState.getTransform();
+            AffineTransform gradt = rgp.getTransform();
+            transform.concatenate(gradt);
+
+            // find largest scaling for the radius
+            double scale = gradt.getScaleX();
+            if(gradt.getScaleY() > scale) {
+                scale = gradt.getScaleY();
+            }
+            ar = ar * scale;
+            ac = transform.transform(ac, null);
+            af = transform.transform(af, null);
 
             ArrayList theCoords = new ArrayList();
-            theCoords.add( new Double(currentXPosition + ac.getX()));
-            theCoords.add( new Double(currentYPosition - ac.getY()));
+            // the center point af must be within the circle with
+            // radius ar centered at ac
+            theCoords.add(new Double(af.getX()));
+            theCoords.add(new Double(af.getY()));
             theCoords.add(new Double(0));
-            theCoords.add( new Double(currentXPosition + af.getX())); // Fx
-            theCoords.add(new Double(currentYPosition - af.getY())); // Fy
+            theCoords.add(new Double(ac.getX())); // Fx
+            theCoords.add(new Double(ac.getY())); // Fy
             theCoords.add(new Double(ar));
 
             Color[] cols = rgp.getColors();
@@ -713,11 +726,8 @@ public class PDFGraphics2D extends AbstractGraphics2D {
 
             float[] fractions = rgp.getFractions();
             ArrayList theBounds = new ArrayList();
-            float lastoffset = 0;
             for(int count = 1; count < fractions.length - 1; count++) {
                 float offset = fractions[count];
-                // create bounds from last to offset
-                lastoffset = offset;
                 theBounds.add(new Double(offset));
             }
             PDFColorSpace colSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);