keiron      2002/07/09 07:59:03

  Modified:    src/org/apache/fop/svg PDFDocumentGraphics2D.java
                        PDFGraphics2D.java
  Log:
  improved linear and radial gradients
  
  Revision  Changes    Path
  1.19      +4 -3      xml-fop/src/org/apache/fop/svg/PDFDocumentGraphics2D.java
  
  Index: PDFDocumentGraphics2D.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFDocumentGraphics2D.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- PDFDocumentGraphics2D.java        1 Jul 2002 14:42:43 -0000       1.18
  +++ PDFDocumentGraphics2D.java        9 Jul 2002 14:59:03 -0000       1.19
  @@ -20,6 +20,7 @@
   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 @@
           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);
  
  
  
  1.36      +38 -28    xml-fop/src/org/apache/fop/svg/PDFGraphics2D.java
  
  Index: PDFGraphics2D.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFGraphics2D.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- PDFGraphics2D.java        4 Jul 2002 14:08:20 -0000       1.35
  +++ PDFGraphics2D.java        9 Jul 2002 14:59:03 -0000       1.36
  @@ -639,10 +639,16 @@
           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 @@
               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 @@
   
               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);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to