keiron      2002/06/28 03:09:07

  Modified:    src/org/apache/fop/pdf BitmapImage.java PDFDocument.java
                        PDFPage.java PDFPattern.java PDFResources.java
                        PDFStream.java
               src/org/apache/fop/render/pdf FontSetup.java
                        FopPDFImage.java PDFRenderer.java
               src/org/apache/fop/svg PDFDocumentGraphics2D.java
                        PDFGraphics2D.java PDFTextElementBridge.java
  Added:       src/org/apache/fop/pdf PDFResourceContext.java
  Log:
  handles pattern resources better
  made stream filters externally configured
  
  Revision  Changes    Path
  1.2       +5 -3      xml-fop/src/org/apache/fop/pdf/BitmapImage.java
  
  Index: BitmapImage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/BitmapImage.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BitmapImage.java  27 Jun 2002 11:45:54 -0000      1.1
  +++ BitmapImage.java  28 Jun 2002 10:09:06 -0000      1.2
  @@ -8,7 +8,7 @@
   package org.apache.fop.pdf;
   
   import java.io.IOException;
  -
  +import java.util.HashMap;
   public class BitmapImage implements PDFImage {
           int m_height;
           int m_width;
  @@ -18,6 +18,7 @@
           String maskRef;
           PDFColor transparent = null;
           String key;
  +        HashMap filters;
   
           public BitmapImage(String k, int width, int height, byte[] result,
                     String mask) {
  @@ -31,6 +32,7 @@
           }
   
           public void setup(PDFDocument doc) {
  +            filters = doc.getFilterMap();
           }
   
           public String getKey() {
  @@ -87,7 +89,7 @@
   
               imgStream.setData(m_bitmaps);
   
  -            imgStream.addDefaultFilters();
  +            imgStream.addDefaultFilters(filters, PDFStream.CONTENT_FILTER);
               return imgStream;
           }
   
  
  
  
  1.42      +72 -24    xml-fop/src/org/apache/fop/pdf/PDFDocument.java
  
  Index: PDFDocument.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFDocument.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- PDFDocument.java  27 Jun 2002 11:45:54 -0000      1.41
  +++ PDFDocument.java  28 Jun 2002 10:09:06 -0000      1.42
  @@ -136,10 +136,17 @@
       protected HashMap xObjectsMap = new HashMap();
   
       /**
  +     * the Font Map.
  +     */
  +    protected HashMap fontMap = new HashMap();
  +
  +    /**
        * the objects themselves
        */
       protected ArrayList pendingLinks = null;
   
  +    protected HashMap filterMap = new HashMap();
  +
       /**
        * creates an empty PDF document <p>
        * 
  @@ -176,6 +183,14 @@
           this.info.setProducer(producer);
       }
   
  +    public void setFilterMap(HashMap map) {
  +        filterMap = map;
  +    }
  +
  +    public HashMap getFilterMap() {
  +        return filterMap;
  +    }
  +
       /**
        * Make a /Catalog (Root) object. This object is written in
        * the trailer.
  @@ -426,7 +441,7 @@
        * It's optional, the default is the identity matrix
        * @param theFunction The PDF Function that maps an (x,y) location to a color
        */
  -    public PDFShading makeShading(int theShadingType,
  +    public PDFShading makeShading(PDFResourceContext res, int theShadingType,
                                     PDFColorSpace theColorSpace,
                                     ArrayList theBackground, ArrayList theBBox,
                                     boolean theAntiAlias, ArrayList theDomain,
  @@ -442,7 +457,11 @@
           this.objects.add(shading);
   
           // add this shading to resources
  -        this.resources.addShading(shading);
  +        if(res != null) {
  +            res.getPDFResources().addShading(shading);
  +        } else {
  +            this.resources.addShading(shading);
  +        }
   
           return (shading);
       }
  @@ -466,7 +485,7 @@
        * @param theExtend ArrayList of Booleans of whether to extend teh start and 
end colors past the start and end points
        * The default is [false, false]
        */
  -    public PDFShading makeShading(int theShadingType,
  +    public PDFShading makeShading(PDFResourceContext res, int theShadingType,
                                     PDFColorSpace theColorSpace,
                                     ArrayList theBackground, ArrayList theBBox,
                                     boolean theAntiAlias, ArrayList theCoords,
  @@ -481,8 +500,11 @@
                                               theDomain, theFunction,
                                               theExtend);
   
  -        this.resources.addShading(shading);
  -
  +        if(res != null) {
  +            res.getPDFResources().addShading(shading);
  +        } else {
  +            this.resources.addShading(shading);
  +        }
           this.objects.add(shading);
           return (shading);
       }
  @@ -509,7 +531,7 @@
        * @param theDecode ArrayList of Doubles see PDF 1.3 spec pages 303 to 312.
        * @param theFunction the PDFFunction
        */
  -    public PDFShading makeShading(int theShadingType,
  +    public PDFShading makeShading(PDFResourceContext res, int theShadingType,
                                     PDFColorSpace theColorSpace,
                                     ArrayList theBackground, ArrayList theBBox,
                                     boolean theAntiAlias,
  @@ -528,7 +550,11 @@
                                               theBitsPerFlag, theDecode,
                                               theFunction);
   
  -        this.resources.addShading(shading);
  +        if(res != null) {
  +            res.getPDFResources().addShading(shading);
  +        } else {
  +            this.resources.addShading(shading);
  +        }
   
           this.objects.add(shading);
           return (shading);
  @@ -554,7 +580,7 @@
        * @param theVerticesPerRow number of vertices in each "row" of the lattice.
        * @param theFunction The PDFFunction that's mapped on to this shape
        */
  -    public PDFShading makeShading(int theShadingType,
  +    public PDFShading makeShading(PDFResourceContext res, int theShadingType,
                                     PDFColorSpace theColorSpace,
                                     ArrayList theBackground, ArrayList theBBox,
                                     boolean theAntiAlias,
  @@ -572,7 +598,11 @@
                                               theBitsPerComponent, theDecode,
                                               theVerticesPerRow, theFunction);
   
  -        this.resources.addShading(shading);
  +        if(res != null) {
  +            res.getPDFResources().addShading(shading);
  +        } else {
  +            this.resources.addShading(shading);
  +        }
   
           this.objects.add(shading);
   
  @@ -593,7 +623,7 @@
        * @param theXUID Optional vector of Integers that uniquely identify the pattern
        * @param thePatternDataStream The stream of pattern data to be tiled.
        */
  -    public PDFPattern makePattern(int thePatternType,    // 1
  +    public PDFPattern makePattern(PDFResourceContext res, int thePatternType,    // 
1
                                     PDFResources theResources, int thePaintType, int 
theTilingType,
                                     ArrayList theBBox, double theXStep, double 
theYStep, ArrayList theMatrix,
                                     ArrayList theXUID, StringBuffer 
thePatternDataStream) {
  @@ -607,7 +637,11 @@
                                               theMatrix, theXUID,
                                               thePatternDataStream);
   
  -        this.resources.addPattern(pattern);
  +        if(res != null) {
  +            res.getPDFResources().addPattern(pattern);
  +        } else {
  +            this.resources.addPattern(pattern);
  +        }
           this.objects.add(pattern);
   
           return (pattern);
  @@ -622,7 +656,7 @@
        * @param theExtGState optional: the extended graphics state, if used.
        * @param theMatrix Optional:ArrayList of Doubles that specify the matrix.
        */
  -    public PDFPattern makePattern(int thePatternType, PDFShading theShading,
  +    public PDFPattern makePattern(PDFResourceContext res, int thePatternType, 
PDFShading theShading,
                                     ArrayList theXUID, StringBuffer theExtGState,
                                     ArrayList theMatrix) {
           String thePatternName = new String("Pa" + (++this.patternCount));
  @@ -631,7 +665,11 @@
                                               thePatternName, 2, theShading,
                                               theXUID, theExtGState, theMatrix);
   
  -        this.resources.addPattern(pattern);
  +        if(res != null) {
  +            res.getPDFResources().addPattern(pattern);
  +        } else {
  +            this.resources.addPattern(pattern);
  +        }
           this.objects.add(pattern);
   
           return (pattern);
  @@ -646,7 +684,7 @@
           return;
       }
   
  -    public PDFPattern createGradient(boolean radial,
  +    public PDFPattern createGradient(PDFResourceContext res, boolean radial,
                                        PDFColorSpace theColorspace,
                                        ArrayList theColors, ArrayList theBounds,
                                        ArrayList theCoords) {
  @@ -697,7 +735,7 @@
   
           if (radial) {
               if (theCoords.size() == 6) {
  -                myShad = this.makeShading(3, this.colorspace, null, null,
  +                myShad = this.makeShading(res, 3, this.colorspace, null, null,
                                             false, theCoords, null, myfunky,
                                             null);
               } else {    // if the center x, center y, and radius specifiy
  @@ -711,18 +749,18 @@
                   newCoords.add(theCoords.get(1));
                   newCoords.add(new Double(0.0));
   
  -                myShad = this.makeShading(3, this.colorspace, null, null,
  +                myShad = this.makeShading(res, 3, this.colorspace, null, null,
                                             false, newCoords, null, myfunky,
                                             null);
   
               }
           } else {
  -            myShad = this.makeShading(2, this.colorspace, null, null, false,
  +            myShad = this.makeShading(res, 2, this.colorspace, null, null, false,
                                         theCoords, null, myfunky, null);
   
           }
   
  -        myPattern = this.makePattern(2, myShad, null, null, null);
  +        myPattern = this.makePattern(res, 2, myShad, null, null, null);
   
           return (myPattern);
       }
  @@ -757,8 +795,11 @@
           this.objects.add(iccStream);
           return iccStream;
       }
  -    
  -    
  +
  +    public HashMap getFontMap() {
  +        return fontMap;
  +    }
  +
       /**
        * make a Type1 /Font object
        *
  @@ -772,6 +813,9 @@
       public PDFFont makeFont(String fontname, String basefont,
                               String encoding, FontMetric metrics,
                               FontDescriptor descriptor) {
  +        if(fontMap.containsKey(basefont)) {
  +            return (PDFFont)fontMap.get(basefont);
  +        }
   
           /*
            * create a PDFFont with the next object number and add to the
  @@ -918,7 +962,11 @@
           return gstate;
       }
   
  -    public PDFXObject addImage(PDFImage img) {
  +    public PDFXObject addImage(PDFResourceContext res, PDFImage img) {
  +        if(res != null) {
  +            res.getPDFResources().setXObjects(xObjects);
  +        }
  +
           // check if already created
           String key = img.getKey();
           PDFXObject xObject = (PDFXObject)xObjectsMap.get(key);
  @@ -1092,7 +1140,7 @@
        *
        * @return the stream object created
        */
  -    public PDFStream makeStream() {
  +    public PDFStream makeStream(String type) {
   
           /*
            * create a PDFStream with the next object number and add it
  @@ -1100,7 +1148,7 @@
            * to the list of objects
            */
           PDFStream obj = new PDFStream(++this.objectcount);
  -        obj.addDefaultFilters();
  +        obj.addDefaultFilters(filterMap, type);
   
           this.objects.add(obj);
           return obj;
  
  
  
  1.16      +4 -43     xml-fop/src/org/apache/fop/pdf/PDFPage.java
  
  Index: PDFPage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFPage.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- PDFPage.java      20 Jun 2002 12:20:46 -0000      1.15
  +++ PDFPage.java      28 Jun 2002 10:09:06 -0000      1.16
  @@ -21,7 +21,7 @@
    * to the memory profile this was causing OOM issues. So, we store
    * only the object ID of the parent, rather than the parent itself.
    */
  -public class PDFPage extends PDFObject {
  +public class PDFPage extends PDFResourceContext {
   
       /**
        * the page's parent, a PDF reference object
  @@ -29,11 +29,6 @@
       protected String parent;
   
       /**
  -     * the page's /Resource object
  -     */
  -    protected PDFResources resources;
  -
  -    /**
        * the contents stream
        */
       protected PDFStream contents;
  @@ -49,12 +44,6 @@
       protected int pageheight;
   
       /**
  -     * the list of annotation objects for this page
  -     */
  -    protected PDFAnnotList annotList;
  -    protected PDFDocument document;
  -
  -    /**
        * create a /Page object
        *
        * @param number the object's number
  @@ -67,16 +56,12 @@
                      int pagewidth, int pageheight) {
   
           /* generic creation of object */
  -        super(number);
  +        super(number, doc, resources);
   
           /* set fields using parameters */
  -        this.document = doc;
  -        this.resources = resources;
           this.contents = contents;
           this.pagewidth = pagewidth;
           this.pageheight = pageheight;
  -
  -        this.annotList = null;
       }
   
       /**
  @@ -91,15 +76,11 @@
                      int pagewidth, int pageheight) {
   
           /* generic creation of object */
  -        super(number);
  +        super(number, doc, resources);
   
           /* set fields using parameters */
  -        this.document = doc;
  -        this.resources = resources;
           this.pagewidth = pagewidth;
           this.pageheight = pageheight;
  -
  -        this.annotList = null;
       }
   
       /**
  @@ -118,26 +99,6 @@
        */
       public void setParent(PDFPages parent) {
           this.parent = parent.referencePDF();
  -    }
  -
  -    /**
  -     * set this page's annotation list
  -     *
  -     * @param annotList a PDFAnnotList list of annotations
  -     */
  -    public void addAnnotation(PDFObject annot) {
  -        if(this.annotList == null) {
  -            this.annotList = document.makeAnnotList();
  -        }
  -        this.annotList.addAnnot(annot);
  -    }
  -
  -    public void addGState(PDFGState gstate) {
  -        this.resources.addGState(gstate);
  -    }
  -
  -    public void addShading(PDFShading shading) {
  -        this.resources.addShading(shading);
       }
   
       /**
  
  
  
  1.12      +32 -10    xml-fop/src/org/apache/fop/pdf/PDFPattern.java
  
  Index: PDFPattern.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFPattern.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- PDFPattern.java   27 Jun 2002 11:45:54 -0000      1.11
  +++ PDFPattern.java   28 Jun 2002 10:09:06 -0000      1.12
  @@ -9,6 +9,9 @@
   
   // Java...
   import java.util.ArrayList;
  +import java.util.HashMap;
  +import java.io.ByteArrayOutputStream;
  +import java.io.IOException;
   
   /**
    * class representing a PDF Function.
  @@ -32,7 +35,7 @@
       /**
        * Either one (1) for tiling, or two (2) for shading.
        */
  -    protected int patternType = 2;                                      // Default
  +    protected int patternType = 2;      // Default
   
       /**
        * The name of the pattern such as "Pa1" or "Pattern1"
  @@ -75,11 +78,11 @@
       protected ArrayList xUID = null;
   
       /**
  +     * TODO use PDFGState
        * String representing the extended Graphics state.
        * Probably will never be used like this.
        */
       protected StringBuffer extGState = null;
  -    // eventually, need a PDFExtGSState object... but not now.
   
       /**
        * ArrayList of Doubles representing the Transformation matrix.
  @@ -128,7 +131,6 @@
           this.yStep = theYStep;
           this.matrix = theMatrix;
           this.xUID = theXUID;
  -        // TODO filter this stream
           this.patternDataStream = thePatternDataStream;
       }
   
  @@ -198,12 +200,14 @@
           p.append(this.number + " " + this.generation
                    + " obj\n<< \n/Type /Pattern \n");
   
  -        if (this.resources != null) {
  +        if(this.resources != null) {
               p.append("/Resources " + this.resources.referencePDF() + " \n");
           }
   
           p.append("/PatternType " + this.patternType + " \n");
   
  +        PDFStream dataStream = null;
  +
           if (this.patternType == 1) {
               p.append("/PaintType " + this.paintType + " \n");
               p.append("/TilingType " + this.tilingType + " \n");
  @@ -240,9 +244,19 @@
                   }
                   p.append("] \n");
               }
  +
               // don't forget the length of the stream.
               if (this.patternDataStream != null) {
  -                p.append("/Length " + (this.patternDataStream.length() + 1)
  +                dataStream = new PDFStream(0);
  +                dataStream.add(this.patternDataStream.toString());
  +                // TODO get the filters from the doc
  +                dataStream.addDefaultFilters(new HashMap(), 
PDFStream.CONTENT_FILTER);
  +                try {
  +                    p.append(dataStream.applyFilters());
  +                } catch(IOException e) {
  +
  +                }
  +                p.append("/Length " + (dataStream.getDataLength() + 1)
                            + " \n");
               }
   
  @@ -261,8 +275,7 @@
                   p.append("] \n");
               }
   
  -            if (this.extGState
  -                    != null) {    // will probably have to change this if it's used.
  +            if (this.extGState != null) {
                   p.append("/ExtGState " + this.extGState + " \n");
               }
   
  @@ -280,8 +293,17 @@
           p.append(">> \n");
   
           // stream representing the function
  -        if (this.patternDataStream != null) {
  -            p.append("stream\n" + this.patternDataStream + "\nendstream\n");
  +        if (dataStream != null) {
  +            try {
  +                ByteArrayOutputStream baos = new ByteArrayOutputStream();
  +                baos.write(p.toString().getBytes());
  +                int length = dataStream.outputStreamData(baos);
  +
  +                baos.write(("endobj\n").getBytes());
  +                return baos.toByteArray();
  +            } catch(IOException e) {
  +
  +            }
           }
   
           p.append("endobj\n");
  
  
  
  1.13      +4 -6      xml-fop/src/org/apache/fop/pdf/PDFResources.java
  
  Index: PDFResources.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFResources.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PDFResources.java 20 Jun 2002 12:20:46 -0000      1.12
  +++ PDFResources.java 28 Jun 2002 10:09:06 -0000      1.13
  @@ -37,10 +37,8 @@
        * @param number the object's number
        */
       public PDFResources(int number) {
  -
           /* generic creation of object */
           super(number);
  -
       }
   
       /**
  @@ -131,7 +129,7 @@
   
           p.append("/ProcSet [ /PDF /ImageC /Text ]\n");
   
  -        if (!this.xObjects.isEmpty()) {
  +        if (this.xObjects != null && !this.xObjects.isEmpty()) {
               p = p.append("/XObject <<");
               for (int i = 1; i <= this.xObjects.size(); i++) {
                   p = p.append("/Im" + i + " "
  @@ -147,9 +145,9 @@
                   PDFGState gs = (PDFGState)this.gstates.get(i);
                   p = p.append("/" + gs.getName() + " "
                                + gs.referencePDF()
  -                             + "\n");
  +                             + " ");
               }
  -            p = p.append(" >>\n");
  +            p = p.append(">>\n");
           }
   
           p = p.append(">>\nendobj\n");
  
  
  
  1.15      +17 -22    xml-fop/src/org/apache/fop/pdf/PDFStream.java
  
  Index: PDFStream.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFStream.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- PDFStream.java    27 Jun 2002 11:45:54 -0000      1.14
  +++ PDFStream.java    28 Jun 2002 10:09:06 -0000      1.15
  @@ -11,8 +11,8 @@
   import java.io.OutputStream;
   import java.io.IOException;
   import java.util.ArrayList;
  +import java.util.HashMap;
   import java.util.Enumeration;
  -import org.apache.fop.configuration.Configuration;
   
   /**
    * class representing a PDF stream.
  @@ -23,6 +23,11 @@
    * length.
    */
   public class PDFStream extends PDFObject {
  +    public static final String DEFAULT_FILTER = "default";
  +    public static final String CONTENT_FILTER = "content";
  +    public static final String IMAGE_FILTER = "image";
  +    public static final String JPEG_FILTER = "jpeg";
  +    public static final String FONT_FILTER = "font";
   
       /**
        * the stream of PDF commands
  @@ -95,29 +100,22 @@
           }
       }
   
  -
  -    public void addDefaultFilters() {
  -        ArrayList filters = Configuration.getListValue("stream-filter-list",
  -                                                    Configuration.PDF);
  -        if (filters == null) {
  -            // try getting it as a String
  -            String filter = Configuration.getStringValue("stream-filter-list",
  -                    Configuration.PDF);
  -            if (filter == null) {
  -                // built-in default to flate
  -                addFilter(new FlateFilter());
  -            } else {
  -                addFilter(filter);
  -            }
  +    public void addDefaultFilters(HashMap filters, String type) {
  +        ArrayList filterset = (ArrayList)filters.get(type);
  +        if(filterset == null) {
  +            filterset = (ArrayList)filters.get(DEFAULT_FILTER);
  +        }
  +        if(filterset == null || filterset.size() == 0) {
  +            // built-in default to flate
  +            addFilter(new FlateFilter());
           } else {
  -            for (int i = 0; i < filters.size(); i++) {
  -                String v = (String)filters.get(i);
  +            for (int i = 0; i < filterset.size(); i++) {
  +                String v = (String)filterset.get(i);
                   addFilter(v);
               }
           }
       }
   
  -
       /**
        * append an array of xRGB pixels, ASCII Hex Encoding it first
        *
  @@ -175,8 +173,6 @@
           }
       }
   
  -
  -
       /**
        * represent as PDF.
        *
  @@ -235,7 +231,6 @@
           return length;
   
       }
  -
   
       /**
        * Apply the filters to the data
  
  
  
  1.1                  xml-fop/src/org/apache/fop/pdf/PDFResourceContext.java
  
  Index: PDFResourceContext.java
  ===================================================================
  /*
   * $Id: PDFResourceContext.java,v 1.1 2002/06/28 10:09:06 keiron Exp $
   * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
   * For details on use and redistribution please refer to the
   * LICENSE file included with these sources.
   */
  
  package org.apache.fop.pdf;
  
  /**
   * class representing a /Page object.
   *
   * There is one of these for every page in a PDF document. The object
   * specifies the dimensions of the page and references a /Resources
   * object, a contents stream and the page's parent in the page
   * hierarchy.
   * 
   * Modified by Mark Lillywhite, [EMAIL PROTECTED] The Parent
   * object was being referred to by reference, but all that we
   * ever used from the Parent was it's PDF object ID, and according
   * to the memory profile this was causing OOM issues. So, we store
   * only the object ID of the parent, rather than the parent itself.
   */
  public class PDFResourceContext extends PDFObject {
  
      /**
       * the page's /Resource object
       */
      protected PDFResources resources;
  
      /**
       * the list of annotation objects for this page
       */
      protected PDFAnnotList annotList;
      protected PDFDocument document;
  
      /**
       *
       * @param number the object's number
       * @param resources the /Resources object
       * @param contents the content stream
       * @param pagewidth the page's width in points
       * @param pageheight the page's height in points
       */
      public PDFResourceContext(int number, PDFDocument doc, PDFResources resources) {
  
          /* generic creation of object */
          super(number);
  
          /* set fields using parameters */
          this.document = doc;
          this.resources = resources;
          this.annotList = null;
      }
  
      public PDFResources getPDFResources() {
          return this.resources;
      }
  
      /**
       * set this page's annotation list
       *
       * @param annotList a PDFAnnotList list of annotations
       */
      public void addAnnotation(PDFObject annot) {
          if(this.annotList == null) {
              this.annotList = document.makeAnnotList();
          }
          this.annotList.addAnnot(annot);
      }
  
      public void addGState(PDFGState gstate) {
          this.resources.addGState(gstate);
      }
  
      public void addShading(PDFShading shading) {
          this.resources.addShading(shading);
      }
  
      public byte[] toPDF() {
          return null;
      }
  }
  
  
  
  1.17      +2 -3      xml-fop/src/org/apache/fop/render/pdf/FontSetup.java
  
  Index: FontSetup.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/FontSetup.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- FontSetup.java    22 Nov 2001 07:11:41 -0000      1.16
  +++ FontSetup.java    28 Jun 2002 10:09:06 -0000      1.17
  @@ -189,10 +189,9 @@
        * @param doc PDF document to add fonts to
        * @param fontInfo font info object to get font information from
        */
  -    public static void addToResources(PDFDocument doc, FontInfo fontInfo) {
  +    public static void addToResources(PDFDocument doc, PDFResources resources, 
FontInfo fontInfo) {
           HashMap fonts = fontInfo.getUsedFonts();
           Iterator e = fonts.keySet().iterator();
  -        PDFResources resources = doc.getResources();
           while (e.hasNext()) {
               String f = (String)e.next();
               Font font = (Font)fonts.get(f);
  
  
  
  1.2       +7 -5      xml-fop/src/org/apache/fop/render/pdf/FopPDFImage.java
  
  Index: FopPDFImage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/FopPDFImage.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FopPDFImage.java  27 Jun 2002 11:45:55 -0000      1.1
  +++ FopPDFImage.java  28 Jun 2002 10:09:06 -0000      1.2
  @@ -24,6 +24,7 @@
   import java.awt.color.ColorSpace;
   import java.awt.color.ICC_ColorSpace;
   import java.awt.color.ICC_Profile;
  +import java.util.HashMap;
   
   public class FopPDFImage implements PDFImage {
       FopImage fopImage;
  @@ -32,6 +33,7 @@
       String maskRef;
       String softMaskRef;
       boolean isPS = false;
  +    HashMap filters;
   
       public FopPDFImage(FopImage im) {
           fopImage = im;
  @@ -44,7 +46,7 @@
       }
   
       public void setup(PDFDocument doc) {
  -
  +        filters = doc.getFilterMap();
           if ("image/jpeg".equals(fopImage.getMimeType())) {
               pdfFilter = new DCTFilter();
               pdfFilter.setApplied(true);
  @@ -55,7 +57,7 @@
               if (prof != null) {
                   pdfICCStream = doc.makePDFICCStream();
                   pdfICCStream.setColorSpace(prof, pdfCS);
  -                pdfICCStream.addDefaultFilters();
  +                pdfICCStream.addDefaultFilters(filters, PDFStream.CONTENT_FILTER);
               }
           }
       }
  @@ -116,7 +118,7 @@
                   imgStream.addFilter(pdfFilter);
               }
   
  -            imgStream.addDefaultFilters();
  +            imgStream.addDefaultFilters(filters, PDFStream.IMAGE_FILTER);
               return imgStream;
           }
       }
  @@ -170,7 +172,7 @@
   
   
           imgStream.setData(imgData);
  -        imgStream.addDefaultFilters();
  +        imgStream.addDefaultFilters(filters, PDFStream.CONTENT_FILTER);
   
           return imgStream;
       }
  
  
  
  1.106     +6 -6      xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
  
  Index: PDFRenderer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java,v
  retrieving revision 1.105
  retrieving revision 1.106
  diff -u -r1.105 -r1.106
  --- PDFRenderer.java  27 Jun 2002 11:45:55 -0000      1.105
  +++ PDFRenderer.java  28 Jun 2002 10:09:06 -0000      1.106
  @@ -165,7 +165,7 @@
       }
   
       public void stopRenderer() throws IOException {
  -        FontSetup.addToResources(this.pdfDoc, fontInfo);
  +        FontSetup.addToResources(pdfDoc, pdfDoc.getResources(), fontInfo);
           pdfDoc.outputTrailer(ostream);
   
           this.pdfDoc = null;
  @@ -217,7 +217,7 @@
                                              (int) Math.round(w / 1000), (int) 
Math.round(h / 1000));
               pageReferences.put(page, currentPage.referencePDF());
           }
  -        currentStream = this.pdfDoc.makeStream();
  +        currentStream = this.pdfDoc.makeStream(PDFStream.CONTENT_FILTER);
   
           currentState = new PDFState();
           currentState.setTransform(new AffineTransform(1, 0, 0, -1, 0, (int) 
Math.round(pageHeight / 1000)));
  @@ -498,21 +498,21 @@
                   return;
               }
               FopPDFImage pdfimage = new FopPDFImage(fopimage);
  -            int xobj = pdfDoc.addImage(pdfimage).getXNumber();
  +            int xobj = pdfDoc.addImage(null, pdfimage).getXNumber();
               fact.releaseImage(url, userAgent);
           } else if("image/jpg".equals(mime)) {
               if(!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) {
                   return;
               }
               FopPDFImage pdfimage = new FopPDFImage(fopimage);
  -            int xobj = pdfDoc.addImage(pdfimage).getXNumber();
  +            int xobj = pdfDoc.addImage(null, pdfimage).getXNumber();
               fact.releaseImage(url, userAgent);
           } else {
               if(!fopimage.load(FopImage.BITMAP, userAgent)) {
                   return;
               }
               FopPDFImage pdfimage = new FopPDFImage(fopimage);
  -            int xobj = pdfDoc.addImage(pdfimage).getXNumber();
  +            int xobj = pdfDoc.addImage(null, pdfimage).getXNumber();
               fact.releaseImage(url, userAgent);
   
               closeText();
  
  
  
  1.17      +6 -4      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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- PDFDocumentGraphics2D.java        18 Jun 2002 13:42:56 -0000      1.16
  +++ PDFDocumentGraphics2D.java        28 Jun 2002 10:09:07 -0000      1.17
  @@ -37,6 +37,7 @@
   public class PDFDocumentGraphics2D extends PDFGraphics2D {
       OutputStream stream;
   
  +    PDFPage currentPage;
       PDFStream pdfStream;
       int width;
       int height;
  @@ -69,7 +70,7 @@
           standalone = true;
           this.pdfDoc = new PDFDocument();
           this.pdfDoc.setProducer("FOP SVG Renderer");
  -        pdfStream = this.pdfDoc.makeStream();
  +        pdfStream = this.pdfDoc.makeStream(PDFStream.CONTENT_FILTER);
   
           graphicsState = new PDFState();
   
  @@ -87,6 +88,7 @@
           PDFResources pdfResources = this.pdfDoc.getResources();
           currentPage = this.pdfDoc.makePage(pdfResources,
                                                      width, height);
  +        resourceContext = currentPage;
           currentStream.write("1 0 0 -1 0 " + height + " cm\n");
       }
   
  @@ -156,7 +158,7 @@
           currentPage.setContents(pdfStream);
           this.pdfDoc.addPage(currentPage);
           if (fontInfo != null) {
  -            FontSetup.addToResources(this.pdfDoc, fontInfo);
  +            FontSetup.addToResources(pdfDoc, pdfDoc.getResources(), fontInfo);
           }
           pdfDoc.outputHeader(stream);
           this.pdfDoc.output(stream);
  
  
  
  1.32      +59 -36    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.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- PDFGraphics2D.java        27 Jun 2002 11:45:55 -0000      1.31
  +++ PDFGraphics2D.java        28 Jun 2002 10:09:07 -0000      1.32
  @@ -58,7 +58,7 @@
        * the PDF Document being created
        */
       protected PDFDocument pdfDoc;
  -    protected PDFPage currentPage;
  +    protected PDFResourceContext resourceContext;
   
       /**
        * the current state of the pdf graphics
  @@ -113,10 +113,10 @@
        * existing document.
        */
       public PDFGraphics2D(boolean textAsShapes, FontState fs, PDFDocument doc,
  -                         PDFPage page, String font, float size, int xpos, int ypos) 
{
  +                         PDFResourceContext page, String font, float size, int 
xpos, int ypos) {
           super(textAsShapes);
           pdfDoc = doc;
  -        currentPage = page;
  +        resourceContext = page;
           currentFontName = font;
           currentFontSize = size;
           currentYPosition = ypos;
  @@ -175,16 +175,17 @@
   
           if(linkType != PDFLink.EXTERNAL) {
               String pdfdest = "/FitR " + dest;
  -            currentPage.addAnnotation(pdfDoc.makeLinkCurrentPage(rect, pdfdest));
  +            // TODO use page ref instead
  +            resourceContext.addAnnotation(pdfDoc.makeLinkCurrentPage(rect, 
pdfdest));
           } else {
  -            currentPage.addAnnotation(pdfDoc.makeLink(rect,
  +            resourceContext.addAnnotation(pdfDoc.makeLink(rect,
                                                    dest, linkType));
           }
       }
   
       public void addJpegImage(JpegImage jpeg, float x, float y, float width, float 
height) {
           FopPDFImage fopimage = new FopPDFImage(jpeg);
  -        int xObjectNum = this.pdfDoc.addImage(fopimage).getXNumber();
  +        int xObjectNum = this.pdfDoc.addImage(resourceContext, 
fopimage).getXNumber();
   
           AffineTransform at = getTransform();
           double[] matrix = new double[6];
  @@ -316,7 +317,7 @@
                   // if the mask is binary then we could convert it into a bitmask
                   BitmapImage fopimg = new BitmapImage("TempImageMask:" + 
img.toString(), buf.getWidth(), buf.getHeight(), mask, null);
                   fopimg.setColorSpace(new PDFColorSpace(PDFColorSpace.DEVICE_GRAY));
  -                PDFXObject xobj = pdfDoc.addImage(fopimg);
  +                PDFXObject xobj = pdfDoc.addImage(resourceContext, fopimg);
                   ref = xobj.referencePDF();
               } else {
                   mask = null;
  @@ -324,7 +325,7 @@
   
               BitmapImage fopimg = new BitmapImage("TempImage:" + img.toString(), 
buf.getWidth(), buf.getHeight(), result, ref);
               fopimg.setTransparent(new PDFColor(255, 255, 255));
  -            imageInfo.xObjectNum = pdfDoc.addImage(fopimg).getXNumber();
  +            imageInfo.xObjectNum = pdfDoc.addImage(resourceContext, 
fopimg).getXNumber();
               imageInfos.put(img, imageInfo);
           }
   
  @@ -476,7 +477,7 @@
           if(c.getAlpha() != 255) {
               PDFGState gstate = pdfDoc.makeGState();
               gstate.setAlpha(c.getAlpha() / 255f, false);
  -            currentPage.addGState(gstate);
  +            resourceContext.addGState(gstate);
               currentStream.write("/" + gstate.getName() + " gs\n");
           }
   
  @@ -655,43 +656,63 @@
                       color1.getVector(), color2.getVector(), 1.0);
   
               PDFColorSpace aColorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
  -            PDFPattern myPat = this.pdfDoc.createGradient(false, aColorSpace,
  +            PDFResources res = pdfDoc.makeResources();
  +            PDFPattern myPat = this.pdfDoc.createGradient(resourceContext, false, 
aColorSpace,
                       someColors, null, theCoords);
               currentStream.write(myPat.getColorSpaceOut(fill));
   
           } else if (paint instanceof RadialGradientPaint) {
  -            System.err.println("Radial gradient paint not supported");
  -
               RadialGradientPaint rgp = (RadialGradientPaint)paint;
  -/*
  +
  +            float ar = rgp.getRadius();
  +            Point2D ac = rgp.getCenterPoint();
  +            Point2D af = rgp.getFocusPoint();
  +
               ArrayList theCoords = new ArrayList();
  -            theCoords.add( new Double(currentXPosition / 1000f + acx));
  -            theCoords.add( new Double(currentYPosition / 1000f - acy));
  +            theCoords.add( new Double(currentXPosition + ac.getX()));
  +            theCoords.add( new Double(currentYPosition - ac.getY()));
               theCoords.add(new Double(0));
  -            theCoords.add( new Double(currentXPosition / 1000f + afx)); // Fx
  -            theCoords.add(new Double(currentYPosition / 1000f - afy)); // Fy
  +            theCoords.add( new Double(currentXPosition + af.getX())); // Fx
  +            theCoords.add(new Double(currentYPosition - af.getY())); // Fy
               theCoords.add(new Double(ar));
   
  -            float lastoffset = 0;
  -            PDFColor color = new PDFColor(0, 0, 0);
  -            color = new PDFColor(red, green, blue);
  +            Color[] cols = rgp.getColors();
  +            ArrayList someColors = new ArrayList();
  +            for(int count = 0; count < cols.length; count++) {
  +                someColors.add(new PDFColor(cols[count].getRed(), 
cols[count].getGreen(), cols[count].getBlue()));
  +            }
   
  -            float offset = stop.getOffset().getBaseVal();
  -// create bounds from last to offset
  +            float[] fractions = rgp.getFractions();
  +            ArrayList theBounds = new ArrayList();
  +            float lastoffset = 0;
  +            for(int count = 0; count < fractions.length; count++) {
  +                float offset = fractions[count];
  +                // create bounds from last to offset
                   lastoffset = offset;
  -                someColors.add(color);
               }
  -            PDFPattern myPat = pdfDoc.createGradient(true, aColorSpace,
  +            PDFColorSpace colSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
  +            PDFPattern myPat = pdfDoc.createGradient(resourceContext, true, 
colSpace,
                                       someColors, theBounds, theCoords);
   
               currentStream.write(myPat.getColorSpaceOut(fill));
  -*/
  +
           } else if (paint instanceof PatternPaint) {
               PatternPaint pp = (PatternPaint)paint;
               Rectangle2D rect = pp.getPatternRect();
   
  -            PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fontState,
  -                                            pdfDoc, currentPage,
  +            FontInfo fi = new FontInfo();
  +            FontSetup.setup(fi);
  +            FontState fs = null;
  +            try {
  +                fs = new FontState(fi, "sans-serif", "normal",
  +                                          "normal", 1, 0);
  +            } catch (org.apache.fop.apps.FOPException fope) {
  +                fope.printStackTrace();
  +            }
  +            PDFResources res = pdfDoc.makeResources();
  +            PDFResourceContext context = new PDFResourceContext(0, pdfDoc, res);
  +            PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fs,
  +                                            pdfDoc, context,
                                               currentFontName, currentFontSize,
                                               currentYPosition, currentXPosition);
               pattGraphic.gc = (GraphicContext)this.gc.clone();
  @@ -722,10 +743,12 @@
               translate.add(new Double(0));
               translate.add(new Double(0));
               translate.add(new Double(1));
  -            translate.add(new Double(rect.getX()));
  -            translate.add(new Double(rect.getY()));
  -            // TODO handle PDFResources
  -            PDFPattern myPat = pdfDoc.makePattern(1, null, 1, 1, bbox,
  +            translate.add(new Double(0/*rect.getX()*/));
  +            translate.add(new Double(0/*rect.getY()*/));
  +
  +            FontSetup.addToResources(pdfDoc, res, fi);
  +
  +            PDFPattern myPat = pdfDoc.makePattern(resourceContext, 1, res, 1, 1, 
bbox,
                                       rect.getWidth(), rect.getHeight(),
                                       translate, null, pattStream.getBuffer());
   
  @@ -916,11 +939,11 @@
   
           c = getBackground();
           applyColor(c, false);
  -        if(salpha != 255 || c.getAlpha() != 255) {
  +        if(salpha != 255/* || c.getAlpha() != 255*/) {
               PDFGState gstate = pdfDoc.makeGState();
               gstate.setAlpha(salpha / 255f, true);
               //gstate.setAlpha(c.getAlpha() / 255f, false);
  -            currentPage.addGState(gstate); 
  +            resourceContext.addGState(gstate); 
               currentStream.write("/" + gstate.getName() + " gs\n");
           }
   
  @@ -1150,7 +1173,7 @@
           if(c.getAlpha() != 255) {
               PDFGState gstate = pdfDoc.makeGState();
               gstate.setAlpha(c.getAlpha() / 255f, true);
  -            currentPage.addGState(gstate);
  +            resourceContext.addGState(gstate);
               currentStream.write("/" + gstate.getName() + " gs\n");
           }
   
  
  
  
  1.7       +2 -4      xml-fop/src/org/apache/fop/svg/PDFTextElementBridge.java
  
  Index: PDFTextElementBridge.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFTextElementBridge.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PDFTextElementBridge.java 27 Jun 2002 11:45:55 -0000      1.6
  +++ PDFTextElementBridge.java 28 Jun 2002 10:09:07 -0000      1.7
  @@ -60,9 +60,7 @@
       private boolean isSimple(BridgeContext ctx, Element element, GraphicsNode node) 
{
           // Font size, in user space units.
           float fs = TextUtilities.convertFontSize(element).floatValue();
  -        /*if(((int)fs) != fs) {
  -            return false;
  -        }*/
  +        // PDF cannot display fonts over 36pt
           if(fs > 36) {
               return false;
           }
  
  
  

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

Reply via email to