Index: src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
===================================================================
--- src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java	(revision 326678)
+++ src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java	(working copy)
@@ -305,12 +305,19 @@
         resourceContext = page;
         pdfContext.setCurrentPage(page);
         pageRef = page.referencePDF();
-        graphicsState.setTransform(new AffineTransform(1.0, 0.0, 0.0, -1.0, 0.0, (double)height));
+
+        AffineTransform at = new AffineTransform(1.0, 0.0, 0.0, -1.0, 
+                                                 0.0, (double)height);
         currentStream.write("1 0 0 -1 0 " + height + " cm\n");
         if (svgWidth != 0) {
-            currentStream.write("" + PDFNumber.doubleOut(width / svgWidth) + " 0 0 "
-                    + PDFNumber.doubleOut(height / svgHeight) + " 0 0 cm\n");
+            double scaleX = width / svgWidth;
+            double scaleY = height / svgHeight;
+            at.scale(scaleX, scaleY);
+            currentStream.write("" + PDFNumber.doubleOut(scaleX) + " 0 0 "
+                                + PDFNumber.doubleOut(scaleY) + " 0 0 cm\n");
         }
+        // Remember the transform we installed.
+        graphicsState.setTransform(at);
 
         pdfContext.increasePageCount();
     }
Index: src/java/org/apache/fop/svg/PDFGraphics2D.java
===================================================================
--- src/java/org/apache/fop/svg/PDFGraphics2D.java	(revision 326678)
+++ src/java/org/apache/fop/svg/PDFGraphics2D.java	(working copy)
@@ -279,6 +279,15 @@
     }
 
     /**
+     * Get the string buffer from the currentStream, containing all
+     * the commands written into this Grpahics so far.
+     * @return the StringBuffer containing the PDF markup
+     */
+    public StringBuffer getBuffer() {
+        return currentStream.getBuffer();
+    }
+
+    /**
      * Set the Grpahics context.
      * @param c the graphics context to use
      */
@@ -829,17 +838,27 @@
             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();
+            // This code currently doesn't support 'repeat' as PDF has
+            // no way to support this (we need to rasterize).
+
+            // Build proper transform from gradient space to page space
+            // ('Patterns' don't get userspace transform).
+            AffineTransform transform;
+            transform = new AffineTransform(graphicsState.getTransform());
+            transform.concatenate(getTransform());
             transform.concatenate(gp.getTransform());
-            transform.concatenate(getTransform());
 
-            p1 = transform.transform(p1, null);
-            p2 = transform.transform(p2, null);
+            List theMatrix = new java.util.ArrayList();
+            double [] mat = new double[6];
+            transform.getMatrix(mat);
+            for (int idx=0; idx<mat.length; idx++) 
+                theMatrix.add(new Double(mat[idx]));
 
+            Point2D p1 = gp.getStartPoint();
+            Point2D p2 = gp.getEndPoint();
             List theCoords = new java.util.ArrayList();
             theCoords.add(new Double(p1.getX()));
             theCoords.add(new Double(p1.getY()));
@@ -874,46 +893,56 @@
                 }
             }
 
-            PDFColorSpace aColorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
+            PDFColorSpace aColorSpace;
+            aColorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
             PDFPattern myPat = pdfDoc.getFactory().makeGradient(
                     resourceContext, false, aColorSpace,
-                    someColors, theBounds, theCoords);
+                    someColors, theBounds, theCoords, theMatrix);
             currentStream.write(myPat.getColorSpaceOut(fill));
 
         } else if (paint instanceof RadialGradientPaint) {
             RadialGradientPaint rgp = (RadialGradientPaint)paint;
 
+            AffineTransform transform;
+            transform = new AffineTransform(graphicsState.getTransform());
+            transform.concatenate(getTransform());
+            transform.concatenate(rgp.getTransform());
+
+            List theMatrix = new java.util.ArrayList();
+            double [] mat = new double[6];
+            transform.getMatrix(mat);
+            for (int idx=0; idx<mat.length; idx++) 
+                theMatrix.add(new Double(mat[idx]));
+
             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();
+            List theCoords = new java.util.ArrayList();
+            double dx = af.getX()-ac.getX();
+            double dy = af.getY()-ac.getY();
+            double d = Math.sqrt(dx*dx+dy*dy);
+            if (d > ar) {
+                // the center point af must be within the circle with
+                // radius ar centered at ac so limit it to that.
+                double scale = (ar*.9999)/d;
+                dx = dx*scale;
+                dy = dy*scale;
             }
-            ar = ar * scale;
-            ac = transform.transform(ac, null);
-            af = transform.transform(af, null);
 
-            List theCoords = new java.util.ArrayList();
-            // 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(ac.getX()+dx)); // Fx
+            theCoords.add(new Double(ac.getY()+dy)); // Fy
             theCoords.add(new Double(0));
-            theCoords.add(new Double(ac.getX())); // Fx
-            theCoords.add(new Double(ac.getY())); // Fy
+            theCoords.add(new Double(ac.getX()));
+            theCoords.add(new Double(ac.getY()));
             theCoords.add(new Double(ar));
 
             Color[] cols = rgp.getColors();
             List someColors = new java.util.ArrayList();
             for (int count = 0; count < cols.length; count++) {
                 Color cc = cols[count];
-                someColors.add(new PDFColor(cc.getRed(), cc.getGreen(), cc.getBlue()));
+                someColors.add(new PDFColor(cc.getRed(), cc.getGreen(), 
+                                            cc.getBlue()));
             }
 
             float[] fractions = rgp.getFractions();
@@ -922,11 +951,13 @@
                 float offset = fractions[count];
                 theBounds.add(new Double(offset));
             }
-            PDFColorSpace colSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
-            PDFPattern myPat = pdfDoc.getFactory().makeGradient(
-                                    resourceContext, true, colSpace,
-                                    someColors, theBounds, theCoords);
+            PDFColorSpace colSpace;
+            colSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
 
+            PDFPattern myPat = pdfDoc.getFactory().makeGradient
+                (resourceContext, true, colSpace,
+                 someColors, theBounds, theCoords, theMatrix);
+
             currentStream.write(myPat.getColorSpaceOut(fill));
 
         } else if (paint instanceof PatternPaint) {
@@ -937,7 +968,6 @@
 
     private void createPattern(PatternPaint pp, boolean fill) {
         preparePainting();
-        Rectangle2D rect = pp.getPatternRect();
 
         FontInfo fontInfo = new FontInfo();
         FontSetup.setup(fontInfo, null);
@@ -947,42 +977,66 @@
         PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fontInfo,
                                         pdfDoc, context, pageRef,
                                         "", 0);
-        pattGraphic.gc = (GraphicContext)this.gc.clone();
+        pattGraphic.setGraphicContext(new GraphicContext());
         pattGraphic.gc.validateTransformStack();
+        pattGraphic.setRenderingHints(this.getRenderingHints());
         pattGraphic.setOutputStream(outputStream);
 
         GraphicsNode gn = pp.getGraphicsNode();
-        gn.paint(pattGraphic);
+        Rectangle2D gnBBox = gn.getBounds();
+        Rectangle2D rect = pp.getPatternRect();
 
-        StringWriter pattStream = new StringWriter();
-        pattStream.write("q\n");
+        if (pp.getOverflow()) {
+            // For overflow we need to paint the content from
+            // all the tiles who's overflow will intersect one
+            // tile (left->right, top->bottom).  Then we can
+            // simply replicate that tile as normal.
+            double gnMinX = gnBBox.getX();
+            double gnMaxX = gnBBox.getX() + gnBBox.getWidth();
+            double gnMinY = gnBBox.getY();
+            double gnMaxY = gnBBox.getY() + gnBBox.getHeight();
+            double patMaxX = rect.getX() + rect.getWidth();
+            double patMaxY = rect.getY() + rect.getHeight();
+            double stepX = rect.getWidth();
+            double stepY = rect.getHeight();            
 
-        // this makes the pattern the right way up, since
-        // it is outside the original transform around the
-        // whole svg document
-        pattStream.write("1 0 0 -1 0 " + (rect.getHeight() + rect.getY()) + " cm\n");
+            int startX = (int)((rect.getX() - gnMaxX)/stepX);
+            int startY = (int)((rect.getY() - gnMaxY)/stepY);
 
-        pattStream.write(pattGraphic.getString());
-        pattStream.write("Q");
+            int endX   = (int)((patMaxX - gnMinX)/stepX);
+            int endY   = (int)((patMaxY - gnMinY)/stepY);
 
+            pattGraphic.translate(startX*stepX, startY*stepY);
+            for (int yIdx=startY; yIdx<=endY; yIdx++) {
+                for (int xIdx=startX; xIdx<=endX; xIdx++) {
+                    gn.paint(pattGraphic);
+                    pattGraphic.translate(stepX,0);
+                }
+                pattGraphic.translate(-(endX-startX+1)*stepX, stepY);
+            }
+            
+        } else {
+            gn.paint(pattGraphic);
+        }
+
+
         List bbox = new java.util.ArrayList();
-        bbox.add(new Double(0));
-        bbox.add(new Double(0));
-        bbox.add(new Double(rect.getWidth() + rect.getX()));
-        bbox.add(new Double(rect.getHeight() + rect.getY()));
+        bbox.add(new Double(rect.getX()));
+        bbox.add(new Double(rect.getHeight()+rect.getY()));
+        bbox.add(new Double(rect.getWidth() +rect.getX()));
+        bbox.add(new Double(rect.getY()));
 
-        List translate = new java.util.ArrayList();
-        AffineTransform pattt = pp.getPatternTransform();
-        pattt.translate(rect.getWidth() + rect.getX(), rect.getHeight() + rect.getY());
-        double[] flatmatrix = new double[6];
-        pattt.getMatrix(flatmatrix);
-        translate.add(new Double(flatmatrix[0]));
-        translate.add(new Double(flatmatrix[1]));
-        translate.add(new Double(flatmatrix[2]));
-        translate.add(new Double(flatmatrix[3]));
-        translate.add(new Double(flatmatrix[4]));
-        translate.add(new Double(flatmatrix[5]));
+        AffineTransform transform;
+        transform = new AffineTransform(graphicsState.getTransform());
+        transform.concatenate(getTransform());
+        transform.concatenate(pp.getPatternTransform());
 
+        List theMatrix = new java.util.ArrayList();
+        double [] mat = new double[6];
+        transform.getMatrix(mat);
+        for (int idx=0; idx<mat.length; idx++) 
+            theMatrix.add(new Double(mat[idx]));
+
         /** @todo see if pdfDoc and res can be linked here,
         (currently res <> PDFDocument's resources) so addFonts() 
         can be moved to PDFDocument class */
@@ -991,7 +1045,8 @@
         PDFPattern myPat = pdfDoc.getFactory().makePattern(
                                 resourceContext, 1, res, 1, 1, bbox,
                                 rect.getWidth(), rect.getHeight(),
-                                translate, null, pattStream.getBuffer());
+                                theMatrix, null, 
+                                pattGraphic.getBuffer());
 
         currentStream.write(myPat.getColorSpaceOut(fill));
 
Index: src/java/org/apache/fop/pdf/PDFState.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFState.java	(revision 326678)
+++ src/java/org/apache/fop/pdf/PDFState.java	(working copy)
@@ -72,7 +72,6 @@
             throw new RuntimeException(e.getMessage());
         }
         stateStack.add(copy);
-        data.resetConcatenations();
     }
 
     /**
@@ -280,16 +279,7 @@
      * @return the calculate combined transform for the current state
      */
     public AffineTransform getTransform() {
-        AffineTransform tf;
-        AffineTransform at = new AffineTransform();
-        for (Iterator iter = stateStack.iterator(); iter.hasNext();) {
-            Data d = (Data)iter.next();
-            tf = d.transform;
-            at.concatenate(tf);
-        }
-        at.concatenate(getData().transform);
-
-        return at;
+        return new AffineTransform(getData().transform);
     }
 
     /**
@@ -339,8 +329,6 @@
         public String fontName = "";
         public Shape clip = null;
         public PDFGState gstate = null;
-        /** Log of all concatenation operations */
-        public List concatenations = null;
 
         
         /** @see java.lang.Object#clone() */
@@ -362,20 +350,10 @@
             obj.fontName = this.fontName;
             obj.clip = this.clip;
             obj.gstate = this.gstate;
-            if (this.concatenations != null) {
-                obj.concatenations = new java.util.ArrayList(this.concatenations);
-            }
             return obj;
         }
         
         /**
-         * Forgets the previously made AffineTransform concatenations.
-         */
-        public void resetConcatenations() {
-            this.concatenations = null;
-        }
-        
-        /**
          * Concatenate the given AffineTransform with the current thus creating
          * a new viewport. Note that all concatenation operations are logged
          * so they can be replayed if necessary (ex. for block-containers with
@@ -383,16 +361,12 @@
          * @param at Transformation to perform
          */
         public void concatenate(AffineTransform at) {
-            if (this.concatenations == null) {
-                this.concatenations = new java.util.ArrayList();
-            }
-            concatenations.add(at);
             transform.concatenate(at);
         }
         
         /** @see java.lang.Object#toString() */
         public String toString() {
-            return super.toString() + ", " + this.transform + " | " + this.concatenations;
+            return super.toString() + ", " + this.transform;
         }
     }
 }
Index: src/java/org/apache/fop/pdf/PDFFactory.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFFactory.java	(revision 326678)
+++ src/java/org/apache/fop/pdf/PDFFactory.java	(working copy)
@@ -688,7 +688,7 @@
     public PDFPattern makeGradient(PDFResourceContext res, boolean radial,
                                    PDFColorSpace theColorspace,
                                    List theColors, List theBounds,
-                                   List theCoords) {
+                                   List theCoords, List theMatrix) {
         PDFShading myShad;
         PDFFunction myfunky;
         PDFFunction myfunc;
@@ -770,7 +770,7 @@
 
         }
 
-        myPattern = makePattern(res, 2, myShad, null, null, null);
+        myPattern = makePattern(res, 2, myShad, null, null, theMatrix);
 
         return (myPattern);
     }
Index: lib/batik-all-1.6.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
