jeremias    2003/01/08 05:57:24

  Modified:    src/org/apache/fop/pdf PDFCIDFont.java PDFDocument.java
                        PDFFont.java PDFFontDescriptor.java
                        PDFFontNonBase14.java PDFFontTrueType.java
                        PDFFontType0.java PDFFontType1.java
                        PDFFontType3.java PDFGState.java PDFICCStream.java
                        PDFStream.java PDFT1Stream.java PDFTTFStream.java
                        PDFWArray.java
  Log:
  Adjustments for the font refactoring
  Lots of Javadocs
  Fixed Checkstyle errors
  
  Revision  Changes    Path
  1.5       +96 -48    xml-fop/src/org/apache/fop/pdf/PDFCIDFont.java
  
  Index: PDFCIDFont.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFCIDFont.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PDFCIDFont.java   17 Sep 2002 09:20:57 -0000      1.4
  +++ PDFCIDFont.java   8 Jan 2003 13:57:23 -0000       1.5
  @@ -1,78 +1,98 @@
   /*
    * $Id$
  - * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 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;
   
  +import org.apache.fop.fonts.CIDFontType;
  +
   // based on work by Takayuki Takeuchi
   
   /**
  - * class representing a "character identifier" font (p 210 and onwards).
  + * Class representing a "character identifier" font (p 210 and onwards).
    */
   public class PDFCIDFont extends PDFObject {
   
  -    public static final byte CID_TYPE0 = 0;
  -    public static final byte CID_TYPE2 = 1;
  -    protected static final String[] TYPE_NAMES = {
  -        "CIDFontType0", "CIDFontType2"
  -    };
  -
  -    protected String basefont;
  -
  -    protected String cidtype;
  -    protected Integer dw;
  -    protected PDFWArray w;
  -    protected int[] dw2;
  -    protected PDFWArray w2;
  -    protected PDFCIDSystemInfo systemInfo;
  -    protected PDFCIDFontDescriptor descriptor;
  -    protected PDFCMap cmap;
  +    private String basefont;
  +    private CIDFontType cidtype;
  +    private Integer dw;
  +    private PDFWArray w;
  +    private int[] dw2;
  +    private PDFWArray w2;
  +    private PDFCIDSystemInfo systemInfo;
  +    private PDFCIDFontDescriptor descriptor;
  +    private PDFCMap cmap;
   
       /**
        * /CIDToGIDMap (only for CIDFontType2, see p 212)
        * can be either "Identity" (default) or a PDFStream
        */
  -    protected PDFStream cidMap;
  +    private PDFStream cidMap;
   
  -    // compatibility with Takayuki Takeuchi
   
       /**
  -     * create the /Font object
  +     * Create the /Font object
  +     * @param number PDF object number
  +     * @param basefont Name of the basefont
  +     * @param cidtype CID type
  +     * @param dw default width
  +     * @param w array of character widths
  +     * @param registry name of the issuer
  +     * @param ordering Unique name of the font
  +     * @param supplement Supplement number
  +     * @param descriptor CID font descriptor
        */
  -    public PDFCIDFont(int number, String basefont, byte cidtype, int dw,
  +    public PDFCIDFont(int number, String basefont, CIDFontType cidtype, int dw,
                         int[] w, String registry, String ordering,
                         int supplement, PDFCIDFontDescriptor descriptor) {
   
  -        super(number);
  +        this(number, basefont, cidtype, dw, 
  +                new PDFWArray(w), 
  +                new PDFCIDSystemInfo(registry, ordering, supplement),
  +                descriptor);
  +    }
   
  -        this.basefont = basefont;
  -        this.cidtype = TYPE_NAMES[(int)cidtype];
  -        this.dw = new Integer(dw);
  -        this.w = new PDFWArray();
  -        this.w.addEntry(0, w);
  -        this.dw2 = null;
  -        this.w2 = null;
  -        this.systemInfo = new PDFCIDSystemInfo(registry, ordering,
  -                                               supplement);
  -        this.descriptor = descriptor;
  -        this.cidMap = null;
  -        this.cmap = null;
  +    /**
  +     * Create the /Font object
  +     * @param number PDF object number
  +     * @param basefont Name of the basefont
  +     * @param cidtype CID type
  +     * @param dw default width
  +     * @param w array of character widths
  +     * @param systemInfo CID system info
  +     * @param descriptor CID font descriptor
  +     */
  +    public PDFCIDFont(int number, String basefont, CIDFontType cidtype, int dw,
  +                      int[] w, PDFCIDSystemInfo systemInfo,
  +                      PDFCIDFontDescriptor descriptor) {
  +
  +        this(number, basefont, cidtype, dw, 
  +                new PDFWArray(w), 
  +                systemInfo,
  +                descriptor);
       }
   
       /**
  -     * create the /Font object
  +     * Create the /Font object
  +     * @param number PDF object number
  +     * @param basefont Name of the basefont
  +     * @param cidtype CID type
  +     * @param dw default width
  +     * @param w array of character widths
  +     * @param systemInfo CID system info
  +     * @param descriptor CID font descriptor
        */
  -    public PDFCIDFont(int number, String basefont, byte cidtype, int dw,
  +    public PDFCIDFont(int number, String basefont, CIDFontType cidtype, int dw,
                         PDFWArray w, PDFCIDSystemInfo systemInfo,
                         PDFCIDFontDescriptor descriptor) {
   
           super(number);
   
           this.basefont = basefont;
  -        this.cidtype = TYPE_NAMES[(int)cidtype];
  +        this.cidtype = cidtype;
           this.dw = new Integer(dw);
           this.w = w;
           this.dw2 = null;
  @@ -84,28 +104,33 @@
       }
   
       /**
  -     * set the /DW attribute
  +     * Set the /DW attribute
  +     * @param dw the default width
        */
       public void setDW(int dw) {
           this.dw = new Integer(dw);
       }
   
       /**
  -     * set the /W array
  +     * Set the /W array
  +     * @param w the width array
        */
       public void setW(PDFWArray w) {
           this.w = w;
       }
   
       /**
  -     * set the (two elements) /DW2 array
  +     * Set the (two elements) /DW2 array
  +     * @param dw2 the default metrics for vertical writing
        */
       public void setDW2(int[] dw2) {
           this.dw2 = dw2;
       }
   
       /**
  -     * set the two elements of the /DW2 array
  +     * Set the two elements of the /DW2 array
  +     * @param posY position vector
  +     * @param displacementY displacement vector
        */
       public void setDW2(int posY, int displacementY) {
           this.dw2 = new int[] {
  @@ -115,34 +140,53 @@
   
       /**
        * Set the CMap used as /ToUnicode cmap
  +     * @param cmap character map
        */
       public void setCMAP(PDFCMap cmap) {
           this.cmap = cmap;
       }
   
       /**
  -     * set the /W2 array
  +     * Set the /W2 array
  +     * @param w2 array of metrics for vertical writing
        */
       public void setW2(PDFWArray w2) {
           this.w2 = w2;
       }
   
       /**
  -     * set the /CIDToGIDMap (to be used only for CIDFontType2)
  +     * Set the /CIDToGIDMap (to be used only for CIDFontType2)
  +     * @param map mapping information
        */
       public void setCIDMap(PDFStream map) {
           this.cidMap = map;
       }
   
       /**
  -     * set the /CIDToGIDMap (to be used only for CIDFontType2) to "Identity"
  +     * Set the /CIDToGIDMap (to be used only for CIDFontType2) to "Identity"
        */
       public void setCIDMapIdentity() {
           this.cidMap = null;    // not an error here, simply use the default
       }
   
       /**
  -     * produce the PDF representation for the object
  +     * Returns the PDF name for a certain CID font type.
  +     * @param cidFontType CID font type
  +     * @return corresponding PDF name
  +     */
  +    protected String getPDFNameForCIDFontType(CIDFontType cidFontType) {
  +        if (cidFontType == CIDFontType.CIDTYPE0) {
  +            return cidFontType.getName();
  +        } else if (cidFontType == CIDFontType.CIDTYPE2) {
  +            return cidFontType.getName();
  +        } else {
  +            throw new IllegalArgumentException("Unsupported CID font type: " 
  +                        + cidFontType.getName());
  +        }
  +    }
  +
  +    /**
  +     * Produce the PDF representation for the object
        *
        * @return the PDF
        */
  @@ -150,6 +194,10 @@
           return toPDFString().getBytes();
       }
   
  +    /**
  +     * Produce the PDF representation for the object
  +     * @return the generated code
  +     */
       public String toPDFString() {
           StringBuffer p = new StringBuffer();
           p.append(this.number);
  @@ -163,7 +211,7 @@
               p.append(cidMap.referencePDF());
           }
           p.append(" \n/Subtype /");
  -        p.append(this.cidtype);
  +        p.append(getPDFNameForCIDFontType(this.cidtype));
           p.append("\n");
           p.append(systemInfo.toPDFString());
           p.append("\n/FontDescriptor ");
  
  
  
  1.61      +168 -55   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.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- PDFDocument.java  29 Nov 2002 23:18:56 -0000      1.60
  +++ PDFDocument.java  8 Jan 2003 13:57:23 -0000       1.61
  @@ -1,6 +1,6 @@
   /*
    * $Id$
  - * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
    */
  @@ -10,19 +10,26 @@
   
   package org.apache.fop.pdf;
   
  -import org.apache.fop.render.pdf.CIDFont;
  -import org.apache.fop.render.pdf.fonts.LazyFont;
  +import org.apache.fop.util.StreamUtilities;
   
  -import org.apache.fop.layout.FontMetric;
  -import org.apache.fop.layout.FontDescriptor;
  +import org.apache.fop.fonts.CIDFont;
  +import org.apache.fop.fonts.CustomFont;
  +import org.apache.fop.fonts.FontDescriptor;
  +import org.apache.fop.fonts.FontMetrics;
  +import org.apache.fop.fonts.FontType;
  +import org.apache.fop.fonts.LazyFont;
  +import org.apache.fop.fonts.MultiByteFont;
  +import org.apache.fop.fonts.truetype.FontFileReader;
  +import org.apache.fop.fonts.truetype.TTFSubSetFile;
  +import org.apache.fop.fonts.type1.PFBData;
  +import org.apache.fop.fonts.type1.PFBParser;
   
   // Java
   import java.io.IOException;
  +import java.io.InputStream;
   import java.io.OutputStream;
   import java.util.List;
   import java.util.Map;
  -import java.util.ArrayList;
  -import java.util.HashMap;
   import java.util.Iterator;
   import java.awt.geom.Rectangle2D;
   
  @@ -55,6 +62,11 @@
       protected static final String PDF_VERSION = "1.4";
   
       /**
  +     * the encoding to use when converting strings to PDF commandos.
  +     */
  +    public static final String ENCODING = "ISO-8859-1";
  +
  +    /**
        * the current character position
        */
       protected int position = 0;
  @@ -62,10 +74,10 @@
       /**
        * the character position of each object
        */
  -    protected List location = new ArrayList();
  +    protected List location = new java.util.ArrayList();
   
       /** List of objects to write in the trailer */
  -    private List trailerObjects = new ArrayList();
  +    private List trailerObjects = new java.util.ArrayList();
   
       /**
        * the counter for object numbering
  @@ -75,7 +87,7 @@
       /**
        * the objects themselves
        */
  -    protected List objects = new ArrayList();
  +    protected List objects = new java.util.ArrayList();
   
       /**
        * character position of xref table
  @@ -127,57 +139,57 @@
        * the XObjects Map.
        * Should be modified (works only for image subtype)
        */
  -    protected Map xObjectsMap = new HashMap();
  +    protected Map xObjectsMap = new java.util.HashMap();
   
       /**
        * the Font Map.
        */
  -    protected Map fontMap = new HashMap();
  +    protected Map fontMap = new java.util.HashMap();
   
       /**
        * The filter map.
        */
  -    protected Map filterMap = new HashMap();
  +    protected Map filterMap = new java.util.HashMap();
   
       /**
        * List of PDFGState objects.
        */
  -    protected List gstates = new ArrayList();
  +    protected List gstates = new java.util.ArrayList();
   
       /**
        * List of functions.
        */
  -    protected List functions = new ArrayList();
  +    protected List functions = new java.util.ArrayList();
   
       /**
        * List of shadings.
        */
  -    protected List shadings = new ArrayList();
  +    protected List shadings = new java.util.ArrayList();
   
       /**
        * List of patterns.
        */
  -    protected List patterns = new ArrayList();
  +    protected List patterns = new java.util.ArrayList();
   
       /**
        * List of Links.
        */
  -    protected List links = new ArrayList();
  +    protected List links = new java.util.ArrayList();
   
       /**
        * List of FileSpecs.
        */
  -    protected List filespecs = new ArrayList();
  +    protected List filespecs = new java.util.ArrayList();
   
       /**
        * List of GoToRemotes.
        */
  -    protected List gotoremotes = new ArrayList();
  +    protected List gotoremotes = new java.util.ArrayList();
   
       /**
        * List of GoTos.
        */
  -    protected List gotos = new ArrayList();
  +    protected List gotos = new java.util.ArrayList();
   
   
       /**
  @@ -230,7 +242,7 @@
        *
        * @param map the map of filter lists for each stream type
        */
  -    public void setFilterMap(HashMap map) {
  +    public void setFilterMap(Map map) {
           filterMap = map;
       }
   
  @@ -891,9 +903,9 @@
           List theCzero;
           List theCone;
           PDFPattern myPattern;
  -        PDFColorSpace theColorSpace;
  +        //PDFColorSpace theColorSpace;
           double interpolation = (double)1.000;
  -        List theFunctions = new ArrayList();
  +        List theFunctions = new java.util.ArrayList();
   
           int currentPosition;
           int lastPosition = theColors.size() - 1;
  @@ -940,7 +952,7 @@
               } else {    // if the center x, center y, and radius specifiy
                   // the gradient, then assume the same center x, center y,
                   // and radius of zero for the other necessary component
  -                List newCoords = new ArrayList();
  +                List newCoords = new java.util.ArrayList();
                   newCoords.add(theCoords.get(0));
                   newCoords.add(theCoords.get(1));
                   newCoords.add(theCoords.get(2));
  @@ -1015,7 +1027,7 @@
        * @return the created /Font object
        */
       public PDFFont makeFont(String fontname, String basefont,
  -                            String encoding, FontMetric metrics,
  +                            String encoding, FontMetrics metrics,
                               FontDescriptor descriptor) {
           if (fontMap.containsKey(fontname)) {
               return (PDFFont)fontMap.get(fontname);
  @@ -1027,22 +1039,17 @@
            */
           if (descriptor == null) {
               PDFFont font = new PDFFont(++this.objectcount, fontname,
  -                                       PDFFont.TYPE1, basefont, encoding);
  +                                       FontType.TYPE1, basefont, encoding);
               this.objects.add(font);
               fontMap.put(fontname, font);
               return font;
           } else {
  -            byte subtype = PDFFont.TYPE1;
  -            if (metrics instanceof org.apache.fop.render.pdf.Font) {
  -                subtype =
  -                    ((org.apache.fop.render.pdf.Font)metrics).getSubType();
  -            }
  +            FontType fonttype = metrics.getFontType();
   
  -            PDFFontDescriptor pdfdesc = makeFontDescriptor(descriptor,
  -                                        subtype);
  +            PDFFontDescriptor pdfdesc = makeFontDescriptor(descriptor);
   
               PDFFontNonBase14 font = null;
  -            if (subtype == PDFFont.TYPE0) {
  +            if (fonttype == FontType.TYPE0) {
                   /*
                    * Temporary commented out - customized CMaps
                    * isn't needed until /ToUnicode support is added
  @@ -1056,24 +1063,24 @@
                    */
                   font =
                       (PDFFontNonBase14)PDFFont.createFont(++this.objectcount,
  -                                                         fontname, subtype,
  +                                                         fontname, fonttype,
                                                            basefont,
                                                            "Identity-H");
               } else {
   
                   font =
                       (PDFFontNonBase14)PDFFont.createFont(++this.objectcount,
  -                                                         fontname, subtype,
  +                                                         fontname, fonttype,
                                                            basefont, encoding);
               }
               this.objects.add(font);
   
               font.setDescriptor(pdfdesc);
   
  -            if (subtype == PDFFont.TYPE0) {
  +            if (fonttype == FontType.TYPE0) {
                   CIDFont cidMetrics;
                   if (metrics instanceof LazyFont) {
  -                    cidMetrics = (CIDFont) ((LazyFont) metrics).getRealFont();
  +                    cidMetrics = (CIDFont)((LazyFont) metrics).getRealFont();
                   } else {
                       cidMetrics = (CIDFont)metrics;
                   }
  @@ -1083,7 +1090,7 @@
                                            cidMetrics.getSupplement());
                   PDFCIDFont cidFont =
                       new PDFCIDFont(++this.objectcount, basefont,
  -                                   cidMetrics.getCidType(),
  +                                   cidMetrics.getCIDType(),
                                      cidMetrics.getDefaultWidth(),
                                      cidMetrics.getWidths(), sysInfo,
                                      (PDFCIDFontDescriptor)pdfdesc);
  @@ -1091,9 +1098,16 @@
   
                   ((PDFFontType0)font).setDescendantFonts(cidFont);
               } else {
  -                font.setWidthMetrics(metrics.getFirstChar(),
  -                                     metrics.getLastChar(),
  -                                     makeArray(metrics.getWidths(1)));
  +                int firstChar = 0;
  +                int lastChar = 255;
  +                if (metrics instanceof CustomFont) {
  +                    CustomFont cf = (CustomFont)metrics;
  +                    firstChar = cf.getFirstChar();
  +                    lastChar = cf.getLastChar();
  +                }
  +                font.setWidthMetrics(firstChar,
  +                                     lastChar,
  +                                     makeArray(metrics.getWidths()));
               }
   
               fontMap.put(fontname, font);
  @@ -1106,21 +1120,20 @@
       /**
        * make a /FontDescriptor object
        */
  -    public PDFFontDescriptor makeFontDescriptor(FontDescriptor desc,
  -            byte subtype) {
  +    public PDFFontDescriptor makeFontDescriptor(FontDescriptor desc) {
           PDFFontDescriptor font = null;
   
  -        if (subtype == PDFFont.TYPE0) {
  +        if (desc.getFontType() == FontType.TYPE0) {
               // CID Font
               font = new PDFCIDFontDescriptor(++this.objectcount,
  -                                            desc.fontName(),
  +                                            desc.getFontName(),
                                               desc.getFontBBox(),
                                               desc.getCapHeight(), desc.getFlags(),
                                               desc.getItalicAngle(),
                                               desc.getStemV(), null);
           } else {
               // Create normal FontDescriptor
  -            font = new PDFFontDescriptor(++this.objectcount, desc.fontName(),
  +            font = new PDFFontDescriptor(++this.objectcount, desc.getFontName(),
                                            desc.getAscender(),
                                            desc.getDescender(),
                                            desc.getCapHeight(),
  @@ -1133,16 +1146,116 @@
   
           // Check if the font is embeddable
           if (desc.isEmbeddable()) {
  -            PDFStream stream = desc.getFontFile(this.objectcount + 1);
  +            PDFStream stream = makeFontFile(this.objectcount + 1, desc);
               if (stream != null) {
                   this.objectcount++;
  -                font.setFontFile(desc.getSubType(), stream);
  +                font.setFontFile(desc.getFontType(), stream);
                   this.objects.add(stream);
               }
           }
           return font;
       }
   
  +    protected InputStream resolveURI(String uri) 
  +                throws java.io.FileNotFoundException {
  +        try {
  +            /**@todo Temporary hack to compile, improve later */
  +            return new java.net.URL(uri).openStream();
  +        } catch (Exception e) {
  +            throw new java.io.FileNotFoundException(
  +                "URI could not be resolved (" + e.getMessage() + "): " + uri);
  +        }
  +    }
  +
  +    /**
  +     * Embeds a font.
  +     * @param obj PDF object number to use
  +     * @param desc FontDescriptor of the font.
  +     * @return PDFStream The embedded font file
  +     */
  +    public PDFStream makeFontFile(int obj, FontDescriptor desc) {
  +        if (desc.getFontType() == FontType.OTHER) {
  +            throw new IllegalArgumentException("Trying to embed unsupported font 
type: " + desc.getFontType());
  +        } 
  +        if (!(desc instanceof CustomFont)) {
  +            throw new IllegalArgumentException("FontDescriptor must be instance of 
CustomFont, but is a " + desc.getClass().getName());
  +        }
  +        
  +        CustomFont font = (CustomFont)desc;
  +        
  +        InputStream in = null;
  +        try {
  +            // Get file first
  +            if (font.getEmbedFileName() != null) try {
  +                in = resolveURI(font.getEmbedFileName());
  +            } catch (Exception e) {
  +                System.out.println("Failed to embed fontfile: "
  +                                   + font.getEmbedFileName());
  +            }
  +    
  +            // Get resource
  +            if (in == null && font.getEmbedResourceName() != null) try {
  +                in = new java.io.BufferedInputStream(
  +                        
this.getClass().getResourceAsStream(font.getEmbedResourceName()));
  +            } catch (Exception e) {
  +                System.out.println("Failed to embed fontresource: "
  +                                   + font.getEmbedResourceName());
  +            }
  +    
  +            if (in == null) {
  +                return null;
  +            } else try {
  +                PDFStream embeddedFont;
  +                if (desc.getFontType() == FontType.TYPE0) {
  +                    MultiByteFont mbfont = (MultiByteFont)font;
  +                    FontFileReader reader = new FontFileReader(in);
  +                
  +                    TTFSubSetFile subset = new TTFSubSetFile();
  +        
  +                    byte[] subsetFont = subset.readFont(reader, 
mbfont.getTTCName(), mbfont.getUsedGlyphs());
  +                    // Only TrueType CID fonts are supported now
  +        
  +                    embeddedFont = new PDFTTFStream(obj, subsetFont.length);
  +                    ((PDFTTFStream)embeddedFont).setData(subsetFont, 
subsetFont.length);
  +                } else if (desc.getFontType() == FontType.TYPE1) {
  +                    PFBParser parser = new PFBParser();
  +                    PFBData pfb = parser.parsePFB(in);
  +                    embeddedFont = new PDFT1Stream(obj);
  +                    ((PDFT1Stream)embeddedFont).setData(pfb);
  +                } else {
  +                    byte[] file = StreamUtilities.toByteArray(in, 128000);
  +                    embeddedFont = new PDFTTFStream(obj, file.length);
  +                    ((PDFTTFStream)embeddedFont).setData(file, file.length);
  +                }
  +                embeddedFont.addFilter("flate");
  +                embeddedFont.addFilter("ascii-85");
  +                return embeddedFont;
  +            } finally {
  +                in.close();
  +            }
  +        } catch (IOException ioe) {
  +            //log.error("Failed to embed font [" + obj + "] "
  +            //                       + fontName + ": " + ioe.getMessage());
  +            return (PDFStream) null;
  +        }
  +    }
  +    
  +
  +
  +/*
  +    public PDFStream getFontFile(int i) {
  +        PDFStream embeddedFont = null;
  +
  +
  +        return (PDFStream)embeddedFont;
  +    }
  +
  +
  +    public PDFStream getFontFile(int i) {
  +    }
  +
  +*/
  +    
   
       /**
        * make an Array object (ex. Widths array for a font)
  @@ -1157,7 +1270,7 @@
       /**
        * make an ExtGState for extra graphics options
        */
  -    public PDFGState makeGState(HashMap settings, PDFGState current) {
  +    public PDFGState makeGState(Map settings, PDFGState current) {
   
           // try to locate a gstate that has all the settings
           // or will inherit from the current gstate
  @@ -1285,7 +1398,7 @@
       public PDFLink makeLink(Rectangle2D rect, String destination,
                               int linkType, float yoffset) {
   
  -        PDFLink linkObject;
  +        //PDFLink linkObject;
           int index;
   
           PDFLink link = new PDFLink(++this.objectcount, rect);
  @@ -1299,12 +1412,12 @@
                   PDFGoToRemote remote = getGoToPDFAction(destination, null, -1);
                   link.setAction(remote);
               } else if ((index = destination.indexOf(".pdf#page=")) > 0) {
  -                String file = destination.substring(0, index + 4);
  +                //String file = destination.substring(0, index + 4);
                   int page = Integer.parseInt(destination.substring(index + 10));
                   PDFGoToRemote remote = getGoToPDFAction(destination, null, page);
                   link.setAction(remote);
               } else if ((index = destination.indexOf(".pdf#dest=")) > 0) {
  -                String file = destination.substring(0, index + 4);
  +                //String file = destination.substring(0, index + 4);
                   String dest = destination.substring(index + 10);
                   PDFGoToRemote remote = getGoToPDFAction(destination, dest, -1);
                   link.setAction(remote);
  
  
  
  1.11      +67 -79    xml-fop/src/org/apache/fop/pdf/PDFFont.java
  
  Index: PDFFont.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFFont.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- PDFFont.java      30 Jul 2001 20:29:29 -0000      1.10
  +++ PDFFont.java      8 Jan 2003 13:57:23 -0000       1.11
  @@ -1,67 +1,35 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 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;
   
  +import org.apache.fop.fonts.FontType;
  +
   /**
  - * class representing a /Font object.
  - *
  + * Class representing a /Font object.
  + * <p>
    * A more complete object expressing the base font name and encoding of a
    * font along with an internal name for the font used within
    * streams of content.
  - *
  + * <p>
    * Fonts are specified on page 198 and onwards of the PDF 1.3 spec.
    */
   public class PDFFont extends PDFObject {
   
       /**
  -     * font subtype to be used as parameter to createFont()
  -     */
  -    public static final byte TYPE0 = 0;
  -
  -    /**
  -     * font subtype to be used as parameter to createFont()
  -     */
  -    public static final byte TYPE1 = 1;
  -
  -    /**
  -     * font subtype to be used as parameter to createFont()
  -     */
  -    public static final byte MMTYPE1 = 2;
  -
  -    /**
  -     * font subtype to be used as parameter to createFont()
  -     */
  -    public static final byte TYPE3 = 3;
  -
  -    /**
  -     * font subtype to be used as parameter to createFont()
  -     */
  -    public static final byte TRUETYPE = 4;
  -
  -    /**
  -     * font subtype names as output in the PDF
  -     */
  -    protected static final String[] TYPE_NAMES =
  -        new String[]    // take care of the order
  -     {
  -        "Type0", "Type1", "MMType1", "Type3", "TrueType"
  -    };
  -
  -    /**
        * the internal name for the font (eg "F1")
        */
       protected String fontname;
   
       /**
        * the font's subtype
  -     * (as defined by the constants TYPE0, TYPE1, MMTYPE1, TYPE3, TRUETYPE)
  +     * (as defined by the constants FontType: TYPE0, TYPE1, MMTYPE1, TYPE3, 
TRUETYPE)
        */
  -    protected byte subtype;
  +    protected FontType subtype;
   
       /**
        * the base font name (eg "Helvetica")
  @@ -90,9 +58,8 @@
        * @param subtype the font's subtype
        * @param basefont the base font name
        * @param encoding the character encoding schema used by the font
  -     * @param mapping the Unicode mapping mechanism
        */
  -    public PDFFont(int number, String fontname, byte subtype,
  +    public PDFFont(int number, String fontname, FontType subtype,
                      String basefont,
                      Object encoding /* , PDFToUnicode mapping */) {
   
  @@ -115,27 +82,27 @@
        * @param subtype the font's subtype
        * @param basefont the base font name
        * @param encoding the character encoding schema used by the font
  +     * @return the generated PDFFont object
        */
       public static PDFFont createFont(int number, String fontname,
  -                                     byte subtype, String basefont,
  +                                     FontType subtype, String basefont,
                                        Object encoding) {
  -        switch (subtype) {
  -        case TYPE0:
  -            return new PDFFontType0(number, fontname, subtype, basefont,
  +        if (subtype == FontType.TYPE0) {
  +            return new PDFFontType0(number, fontname, basefont,
                                       encoding);
  -        case TYPE1:
  -        case MMTYPE1:
  -            return new PDFFontType1(number, fontname, subtype, basefont,
  +        } else if ((subtype == FontType.TYPE1)
  +                || (subtype == FontType.MMTYPE1)) {
  +            return new PDFFontType1(number, fontname, basefont,
                                       encoding);
  -        /*
  -         * case TYPE3 :
  -         * return new PDFFontType3(number, fontname, subtype, basefont, encoding);
  -         */
  -        case TRUETYPE:
  -            return new PDFFontTrueType(number, fontname, subtype, basefont,
  +        } else if (subtype == FontType.TYPE3) {
  +            //return new PDFFontType3(number, fontname, basefont, encoding);
  +            return null; //NYI
  +        } else if (subtype == FontType.TRUETYPE) {
  +            return new PDFFontTrueType(number, fontname, basefont,
                                          encoding);
  +        } else {
  +            return null;    // should not happend
           }
  -        return null;    // should not happend
       }
   
       /**
  @@ -151,44 +118,42 @@
        * @param lastChar the last character code in the font
        * @param widths an array of size (lastChar - firstChar +1)
        * @param descriptor the descriptor for other font's metrics
  +     * @return the generated PDFFont object
        */
       public static PDFFont createFont(int number, String fontname,
  -                                     byte subtype, String basefont,
  +                                     FontType subtype, String basefont,
                                        Object encoding, int firstChar,
                                        int lastChar, PDFArray widths,
                                        PDFFontDescriptor descriptor) {
   
           PDFFontNonBase14 font;
  -        switch (subtype) {
  -        case TYPE0:
  -            font = new PDFFontType0(number, fontname, subtype, basefont,
  +        if (subtype == FontType.TYPE0) {
  +            font = new PDFFontType0(number, fontname, basefont,
                                       encoding);
               font.setDescriptor(descriptor);
               return font;
  -        case TYPE1:
  -        case MMTYPE1:
  -            font = new PDFFontType1(number, fontname, subtype, basefont,
  +        } else if ((subtype == FontType.TYPE1) 
  +                || (subtype == FontType.MMTYPE1)) {
  +            font = new PDFFontType1(number, fontname, basefont,
                                       encoding);
               font.setWidthMetrics(firstChar, lastChar, widths);
               font.setDescriptor(descriptor);
               return font;
  -        case TYPE3:
  -            return null;    // should not happend
  -
  -        case TRUETYPE:
  -            font = new PDFFontTrueType(number, fontname, subtype, basefont,
  +        } else if (subtype == FontType.TYPE3) {
  +            return null; //NYI, should not happend
  +        } else if (subtype == FontType.TRUETYPE) {
  +            font = new PDFFontTrueType(number, fontname, basefont,
                                          encoding);
               font.setWidthMetrics(firstChar, lastChar, widths);
               font.setDescriptor(descriptor);
               return font;
  -
  +        } else {
  +            return null;    // should not happend
           }
  -        return null;    // should not happend
       }
   
       /**
        * get the internal name used for this font
  -     *
        * @return the internal name
        */
       public String getName() {
  @@ -196,7 +161,28 @@
       }
   
       /**
  -     * produce the PDF representation for the object
  +     * Returns the PDF name for a certain font type.
  +     * @param fontType font type
  +     * @return String corresponding PDF name
  +     */
  +    protected String getPDFNameForFontType(FontType fontType) {
  +        if (fontType == FontType.TYPE0) {
  +            return fontType.getName();
  +        } else if (fontType == FontType.TYPE1) {
  +            return fontType.getName();
  +        } else if (fontType == FontType.MMTYPE1) {
  +            return fontType.getName();
  +        } else if (fontType == FontType.TYPE3) {
  +            return fontType.getName();
  +        } else if (fontType == FontType.TRUETYPE) {
  +            return fontType.getName();
  +        } else {
  +            throw new IllegalArgumentException("Unsupported font type: " + 
fontType.getName());
  +        }
  +    }
  +
  +    /**
  +     * Produce the PDF representation for the object
        *
        * @return the PDF
        */
  @@ -204,7 +190,7 @@
           StringBuffer p = new StringBuffer();
           p.append(this.number + " " + this.generation
                    + " obj\n<< /Type /Font\n/Subtype /"
  -                 + TYPE_NAMES[this.subtype] + "\n/Name /" + this.fontname
  +                 + getPDFNameForFontType(this.subtype) + "\n/Name /" + this.fontname
                    + "\n/BaseFont /" + this.basefont);
           if (encoding != null) {
               p.append("\n/Encoding ");
  @@ -222,12 +208,14 @@
       }
   
       /**
  -     * fill in the specifics for the font's subtype.
  -     *
  -     * the given buffer already contains the fields common to all font types.
  +     * This method is called to receive the specifics for the font's subtype.
  +     * <p>
  +     * The given buffer already contains the fields common to all font types.
        *
  -     * @param begin the buffer to be completed with the type specific fields
  +     * @param target the buffer to be completed with the type specific fields
        */
  -    protected void fillInPDF(StringBuffer begin) {}
  +    protected void fillInPDF(StringBuffer target) {
  +        //nop
  +    }
   
   }
  
  
  
  1.6       +47 -40    xml-fop/src/org/apache/fop/pdf/PDFFontDescriptor.java
  
  Index: PDFFontDescriptor.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFFontDescriptor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PDFFontDescriptor.java    30 Jul 2001 20:29:29 -0000      1.5
  +++ PDFFontDescriptor.java    8 Jan 2003 13:57:23 -0000       1.6
  @@ -1,42 +1,44 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 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;
   
  +import org.apache.fop.fonts.FontType;
  +
   /**
  - * class representing a font descriptor.
  - *
  + * Class representing a font descriptor (/FontDescriptor object).
  + * <p>
    * Font descriptors are specified on page 222 and onwards of the PDF 1.3 spec.
    */
   public class PDFFontDescriptor extends PDFObject {
   
       // Required fields
  -    protected int ascent;
  -    protected int capHeight;
  -    protected int descent;
  -    protected int flags;
  -    protected PDFRectangle fontBBox;
  -    protected String basefont;    // PDF-spec: FontName
  -    protected int italicAngle;
  -    protected int stemV;
  +    private int ascent;
  +    private int capHeight;
  +    private int descent;
  +    private int flags;
  +    private PDFRectangle fontBBox;
  +    private String basefont;    // PDF-spec: FontName
  +    private int italicAngle;
  +    private int stemV;
       // Optional fields
  -    protected int stemH = 0;
  -    protected int xHeight = 0;
  -    protected int leading = 0;
  -    protected int avgWidth = 0;
  -    protected int maxWidth = 0;
  -    protected int missingWidth = 0;
  -    protected PDFStream fontfile;
  -    // protected String charSet = null;
  +    private int stemH = 0;
  +    private int xHeight = 0;
  +    private int leading = 0;
  +    private int avgWidth = 0;
  +    private int maxWidth = 0;
  +    private int missingWidth = 0;
  +    private PDFStream fontfile;
  +    // private String charSet = null;
   
  -    protected byte subtype;
  +    private FontType subtype;
   
       /**
  -     * create the /FontDescriptor object
  +     * Create the /FontDescriptor object
        *
        * @param number the object's number
        * @param ascent the maximum height above the baseline
  @@ -68,7 +70,18 @@
       }
   
       /**
  -     * set the optional metrics
  +     * Set the optional metrics.
  +     * @param avgWidth The average width of characters in this font. 
  +     * The default value is 0.
  +     * @param maxWidth The maximum width of characters in this font. 
  +     * The default value is 0.
  +     * @param missingWidth missing width
  +     * @param leading the desired spacing between lines of text. 
  +     * The default value is 0.
  +     * @param stemH The vertical width of the dominant horizontal stems of 
  +     * glyphs in the font. The default value is 0.
  +     * @param xHeight The y-coordinate of the top of flat non-ascending 
  +     * lowercase letters, measured from the baseline. The default value is 0.
        */
       public void setMetrics(int avgWidth, int maxWidth, int missingWidth,
                              int leading, int stemH, int xHeight) {
  @@ -81,12 +94,12 @@
       }
   
       /**
  -     * set the optional font file stream
  +     * Set the optional font file stream
        *
        * @param subtype the font type defined in the font stream
        * @param fontfile the stream containing an embedded font
        */
  -    public void setFontFile(byte subtype, PDFStream fontfile) {
  +    public void setFontFile(FontType subtype, PDFStream fontfile) {
           this.subtype = subtype;
           this.fontfile = fontfile;
       }
  @@ -94,7 +107,7 @@
       // public void setCharSet(){}//for subset fonts
   
       /**
  -     * produce the PDF representation for the object
  +     * Produce the PDF representation for the object
        *
        * @return the PDF
        */
  @@ -143,17 +156,9 @@
               p.append(leading);
           }
           if (fontfile != null) {
  -            switch (subtype) {
  -            case PDFFont.TYPE1:
  +            if (subtype == FontType.TYPE1) {
                   p.append("\n/FontFile ");
  -                break;
  -            case PDFFont.TRUETYPE:
  -                p.append("\n/FontFile2 ");
  -                break;
  -            case PDFFont.TYPE0:
  -                p.append("\n/FontFile2 ");
  -                break;
  -            default:
  +            } else {
                   p.append("\n/FontFile2 ");
               }
               p.append(fontfile.referencePDF());
  @@ -166,12 +171,14 @@
       }
   
       /**
  -     * fill in the specifics for the font's descriptor.
  -     *
  -     * the given buffer already contains the fields common to all descriptors.
  +     * Fill in the specifics for the font's descriptor.
  +     * <p>
  +     * The given buffer already contains the fields common to all descriptors.
        *
        * @param begin the buffer to be completed with the specific fields
        */
  -    protected void fillInPDF(StringBuffer begin) {}
  +    protected void fillInPDF(StringBuffer begin) {
  +        //nop
  +    }
   
   }
  
  
  
  1.3       +18 -19    xml-fop/src/org/apache/fop/pdf/PDFFontNonBase14.java
  
  Index: PDFFontNonBase14.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFFontNonBase14.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PDFFontNonBase14.java     30 Jul 2001 20:29:29 -0000      1.2
  +++ PDFFontNonBase14.java     8 Jan 2003 13:57:23 -0000       1.3
  @@ -1,13 +1,13 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 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;
   
  -// Java
  +import org.apache.fop.fonts.FontType;
   
   /**
    * A common ancestor for Type1, TrueType, MMType1 and Type3 fonts
  @@ -36,18 +36,17 @@
       protected PDFFontDescriptor descriptor;
   
       /**
  -     * create the /Font object
  +     * Create the /Font object
        *
        * @param number the object's number
        * @param fontname the internal name for the font
        * @param subtype the font's subtype
        * @param basefont the base font name
        * @param encoding the character encoding schema used by the font
  -     * @param mapping the Unicode mapping mechanism
        */
  -    public PDFFontNonBase14(int number, String fontname, byte subtype,
  +    public PDFFontNonBase14(int number, String fontname, FontType subtype,
                               String basefont,
  -                            Object encoding /* , PDFToUnicode mapping */) {
  +                            Object encoding) {
   
           /* generic creation of PDF object */
           super(number, fontname, subtype, basefont, encoding);
  @@ -56,7 +55,7 @@
       }
   
       /**
  -     * set the width metrics for the font
  +     * Set the width metrics for the font
        *
        * @param firstChar the first character code in the font
        * @param lastChar the last character code in the font
  @@ -71,7 +70,7 @@
       }
   
       /**
  -     * set the font descriptor (unused for the Type3 fonts)
  +     * Set the font descriptor (unused for the Type3 fonts)
        *
        * @param descriptor the descriptor for other font's metrics
        */
  @@ -80,18 +79,18 @@
       }
   
       /**
  -     * fill in the specifics for the font's subtype
  +     * @see org.apache.fop.pdf.PDFFont#fillInPDF(StringBuffer)
        */
  -    protected void fillInPDF(StringBuffer p) {
  -        p.append("\n/FirstChar ");
  -        p.append(firstChar);
  -        p.append("\n/LastChar ");
  -        p.append(lastChar);
  -        p.append("\n/Widths ");
  -        p.append(this.widths.referencePDF());
  +    protected void fillInPDF(StringBuffer target) {
  +        target.append("\n/FirstChar ");
  +        target.append(firstChar);
  +        target.append("\n/LastChar ");
  +        target.append(lastChar);
  +        target.append("\n/Widths ");
  +        target.append(this.widths.referencePDF());
           if (descriptor != null) {
  -            p.append("\n/FontDescriptor ");
  -            p.append(this.descriptor.referencePDF());
  +            target.append("\n/FontDescriptor ");
  +            target.append(this.descriptor.referencePDF());
           }
       }
   
  
  
  
  1.3       +9 -9      xml-fop/src/org/apache/fop/pdf/PDFFontTrueType.java
  
  Index: PDFFontTrueType.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFFontTrueType.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PDFFontTrueType.java      30 Jul 2001 20:29:29 -0000      1.2
  +++ PDFFontTrueType.java      8 Jan 2003 13:57:23 -0000       1.3
  @@ -1,15 +1,17 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 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;
   
  +import org.apache.fop.fonts.FontType;
  +
   /**
  - * class representing a TrueType font.
  - *
  + * Class representing a TrueType font.
  + * <p>
    * In fact everything already done in the superclass.
    * Must only define the not default constructor.
    */
  @@ -20,17 +22,15 @@
        *
        * @param number the object's number
        * @param fontname the internal name for the font
  -     * @param subtype the font's subtype (PDFFont.TRUETYPE)
        * @param basefont the base font name
        * @param encoding the character encoding schema used by the font
  -     * @param mapping the Unicode mapping mechanism
        */
  -    public PDFFontTrueType(int number, String fontname, byte subtype,
  +    public PDFFontTrueType(int number, String fontname, 
                              String basefont,
  -                           Object encoding /* , PDFToUnicode mapping */) {
  +                           Object encoding) {
   
           /* generic creation of PDF object */
  -        super(number, fontname, subtype, basefont, encoding /* , mapping */);
  +        super(number, fontname, FontType.TRUETYPE, basefont, encoding /* , mapping 
*/);
       }
   
   }
  
  
  
  1.4       +27 -23    xml-fop/src/org/apache/fop/pdf/PDFFontType0.java
  
  Index: PDFFontType0.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFFontType0.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PDFFontType0.java 30 Jul 2001 20:29:29 -0000      1.3
  +++ PDFFontType0.java 8 Jan 2003 13:57:23 -0000       1.4
  @@ -1,42 +1,45 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 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;
   
  +import org.apache.fop.fonts.FontType;
  +
   /**
  - * class representing a Type0 font.
  - *
  + * Class representing a Type0 font.
  + * <p>
    * Type0 fonts are specified on page 208 and onwards of the PDF 1.3 spec.
    */
   public class PDFFontType0 extends PDFFontNonBase14 {
   
       /**
  -     * this should be an array of CIDFont but only the first one is used
  +     * This should be an array of CIDFont but only the first one is used
        */
       protected PDFCIDFont descendantFonts;
   
  +    /**
  +     * The character map
  +     */
       protected PDFCMap cmap;
   
       /**
  -     * create the /Font object
  +     * Create the /Font object
        *
        * @param number the object's number
        * @param fontname the internal name for the font
  -     * @param subtype the font's subtype (PDFFont.TYPE0)
        * @param basefont the base font name
        * @param encoding the character encoding schema used by the font
  -     * @param mapping the Unicode mapping mechanism
        */
  -    public PDFFontType0(int number, String fontname, byte subtype,
  +    public PDFFontType0(int number, String fontname, 
                           String basefont,
  -                        Object encoding /* , PDFToUnicode mapping */) {
  +                        Object encoding) {
   
           /* generic creation of PDF object */
  -        super(number, fontname, subtype, basefont, encoding /* , mapping */);
  +        super(number, fontname, FontType.TYPE0, basefont, encoding /* , mapping */);
   
           /* set fields using paramaters */
           this.descendantFonts = null;
  @@ -44,51 +47,52 @@
       }
   
       /**
  -     * create the /Font object
  +     * Create the /Font object
        *
        * @param number the object's number
        * @param fontname the internal name for the font
  -     * @param subtype the font's subtype (PDFFont.TYPE0)
        * @param basefont the base font name
        * @param encoding the character encoding schema used by the font
  -     * @param mapping the Unicode mapping mechanism
        * @param descendantFonts the CIDFont upon which this font is based
        */
  -    public PDFFontType0(int number, String fontname, byte subtype,
  +    public PDFFontType0(int number, String fontname, 
                           String basefont,
  -                        Object encoding /* , PDFToUnicode mapping */,
  +                        Object encoding, 
                           PDFCIDFont descendantFonts) {
   
           /* generic creation of PDF object */
  -        super(number, fontname, subtype, basefont, encoding /* , mapping */);
  +        super(number, fontname, FontType.TYPE0, basefont, encoding /* , mapping */);
   
           /* set fields using paramaters */
           this.descendantFonts = descendantFonts;
       }
   
       /**
  -     * set the descendant font
  -     *
  +     * Set the descendant font
        * @param descendantFonts the CIDFont upon which this font is based
        */
       public void setDescendantFonts(PDFCIDFont descendantFonts) {
           this.descendantFonts = descendantFonts;
       }
   
  +    /**
  +     * Sets the character map
  +     * @param cmap the character map
  +     */
       public void setCMAP(PDFCMap cmap) {
           this.cmap = cmap;
       }
   
       /**
  -     * fill in the specifics for the font's subtype
  +     * @see org.apache.fop.pdf.PDFFont#fillInPDF(StringBuffer)
        */
  -    protected void fillInPDF(StringBuffer p) {
  +    protected void fillInPDF(StringBuffer target) {
           if (descendantFonts != null) {
  -            p.append("\n/DescendantFonts [ "
  +            target.append("\n/DescendantFonts [ "
                        + this.descendantFonts.referencePDF() + " ] ");
           }
           if (cmap != null) {
  -            p.append("\n/ToUnicode " + cmap.referencePDF());
  +            target.append("\n/ToUnicode " + cmap.referencePDF());
           }
       }
   
  
  
  
  1.3       +12 -11    xml-fop/src/org/apache/fop/pdf/PDFFontType1.java
  
  Index: PDFFontType1.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFFontType1.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PDFFontType1.java 30 Jul 2001 20:29:29 -0000      1.2
  +++ PDFFontType1.java 8 Jan 2003 13:57:23 -0000       1.3
  @@ -1,39 +1,40 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 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;
   
  +import org.apache.fop.fonts.FontType;
  +
   /**
  - * class representing a Type1 or MMType1 font (not necessary for the base 14).
  - *
  + * Class representing a Type1 or MMType1 font (not necessary for the base 14).
  + * <p>
    * Type1 fonts are specified on page 201 and onwards of the PDF 1.3 spec.
  + * <br>
    * MMType1 fonts are specified on page 205 and onwards of the PDF 1.3 spec.
  - *
  + * <p>
    * In fact everything already done in the superclass.
    * Must only define the not default constructor.
    */
   public class PDFFontType1 extends PDFFontNonBase14 {
   
       /**
  -     * create the /Font object
  +     * Create the /Font object
        *
        * @param number the object's number
        * @param fontname the internal name for the font
  -     * @param subtype the font's subtype (PDFFont.TYPE1 or PDFFont.MMTYPE1)
        * @param basefont the base font name
        * @param encoding the character encoding schema used by the font
  -     * @param mapping the Unicode mapping mechanism
        */
  -    public PDFFontType1(int number, String fontname, byte subtype,
  +    public PDFFontType1(int number, String fontname, 
                           String basefont,
  -                        Object encoding /* , PDFToUnicode mapping */) {
  +                        Object encoding) {
   
           /* generic creation of PDF object */
  -        super(number, fontname, subtype, basefont, encoding);
  +        super(number, fontname, FontType.TYPE1, basefont, encoding);
       }
   
   }
  
  
  
  1.3       +28 -34    xml-fop/src/org/apache/fop/pdf/PDFFontType3.java
  
  Index: PDFFontType3.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFFontType3.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PDFFontType3.java 30 Jul 2001 20:29:29 -0000      1.2
  +++ PDFFontType3.java 8 Jan 2003 13:57:23 -0000       1.3
  @@ -1,19 +1,20 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 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;
   
  +import org.apache.fop.fonts.FontType;
  +
   /**
  - * class representing a Type3 font.
  - *
  - * <p><b>CAUTION: this is not yet fully implemented!!!!!!!</b>
  + * Class representing a Type3 font.
  + * <p>
  + * <b>CAUTION: this is not yet fully implemented!!!!!!!</b>
    * the /CharProcs is still missing its <code>toPDF()</code> method.
  - * </p>
  - *
  + * <p>
    * Type3 fonts are specified on page 206 and onwards of the PDF 1.3 spec.
    */
   public class PDFFontType3 extends PDFFontNonBase14 {
  @@ -39,21 +40,19 @@
       protected PDFResources resources;
   
       /**
  -     * create the /Font object
  +     * Create the /Font object
        *
        * @param number the object's number
        * @param fontname the internal name for the font
  -     * @param subtype the font's subtype (PDFFont.TYPE3)
        * @param basefont the base font name
        * @param encoding the character encoding schema used by the font
  -     * @param mapping the Unicode mapping mechanism
        */
  -    public PDFFontType3(int number, String fontname, byte subtype,
  +    public PDFFontType3(int number, String fontname, 
                           String basefont,
  -                        Object encoding /* , PDFToUnicode mapping */) {
  +                        Object encoding) {
   
           /* generic creation of PDF object */
  -        super(number, fontname, subtype, basefont, encoding /* , mapping */);
  +        super(number, fontname, FontType.TYPE3, basefont, encoding /* , mapping */);
   
           this.fontBBox = null;
           this.fontMatrix = null;
  @@ -61,26 +60,24 @@
       }
   
       /**
  -     * create the /Font object
  +     * Create the /Font object
        *
        * @param number the object's number
        * @param fontname the internal name for the font
  -     * @param subtype the font's subtype (PDFFont.TYPE3)
        * @param basefont the base font name
        * @param encoding the character encoding schema used by the font
  -     * @param mapping the Unicode mapping mechanism
        * @param fontBBox the font's bounding box
        * @param fontMatrix the font's transformation matrix
        * @param charProcs the glyphs' definitions
        */
  -    public PDFFontType3(int number, String fontname, byte subtype,
  +    public PDFFontType3(int number, String fontname, 
                           String basefont,
  -                        Object encoding /* , PDFToUnicode mapping */,
  +                        Object encoding,
                           PDFRectangle fontBBox, PDFArray fontMatrix,
                           PDFCharProcs charProcs) {
   
           /* generic creation of PDF object */
  -        super(number, fontname, subtype, basefont, encoding /* , mapping */);
  +        super(number, fontname, FontType.TYPE3, basefont, encoding /* , mapping */);
   
           this.fontBBox = fontBBox;
           this.fontMatrix = fontMatrix;
  @@ -88,7 +85,7 @@
       }
   
       /**
  -     * set the font's bounding box
  +     * Set the font's bounding box
        *
        * @param bbox bounding box for the font
        */
  @@ -97,7 +94,7 @@
       }
   
       /**
  -     * set the font's transformation matrix
  +     * Set the font's transformation matrix
        *
        * @param matrix the transformation matrix for the font
        */
  @@ -106,7 +103,8 @@
       }
   
       /**
  -     * set the glyphs' definitions.
  +     * Set the glyphs' definitions.
  +     * <p>
        * The /CharProcs object needs to be registered in the document's resources.
        *
        * @param chars the glyphs' dictionary
  @@ -116,24 +114,20 @@
       }
   
       /**
  -     * fill in the specifics for the font's subtype.
  -     *
  -     * the given buffer already contains the fields common to all font types.
  -     *
  -     * @param p the buffer to be completed with the type specific fields
  +     * @see org.apache.fop.pdf.PDFFont#fillInPDF(StringBuffer)
        */
  -    protected void fillInPDF(StringBuffer p) {
  +    protected void fillInPDF(StringBuffer target) {
           if (fontBBox != null) {
  -            p.append("\n/FontBBox ");
  -            p.append(fontBBox.toPDF());
  +            target.append("\n/FontBBox ");
  +            target.append(fontBBox.toPDF());
           }
           if (fontMatrix != null) {
  -            p.append("\n/FontMatrix ");
  -            p.append(fontMatrix.toPDF());
  +            target.append("\n/FontMatrix ");
  +            target.append(fontMatrix.toPDF());
           }
           if (charProcs != null) {
  -            p.append("\n/CharProcs ");
  -            p.append(charProcs.referencePDF());
  +            target.append("\n/CharProcs ");
  +            target.append(charProcs.referencePDF());
           }
       }
   
  
  
  
  1.5       +97 -48    xml-fop/src/org/apache/fop/pdf/PDFGState.java
  
  Index: PDFGState.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFGState.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PDFGState.java    25 Oct 2002 09:29:46 -0000      1.4
  +++ PDFGState.java    8 Jan 2003 13:57:23 -0000       1.5
  @@ -1,52 +1,82 @@
   /*
    * $Id$
  - * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 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;
   
  -import java.util.HashMap;
  +import java.util.Map;
   import java.util.Iterator;
   
   /**
  - * class representing a /ExtGState object.
  - *
  + * Class representing a /ExtGState object.
    */
   public class PDFGState extends PDFObject {
  -    public static final String LW = "lw";
  -    public static final String LC = "lc";
  -    public static final String LJ = "lj";
  -    public static final String ML = "ml";
  -    public static final String D = "d";
  -    public static final String RI = "ri";
  -    public static final String OP = "OP";
  -    public static final String op = "op";
  -    public static final String OPM = "opm";
  -    public static final String Font = "font";
  -    public static final String BG = "bg";
  -    public static final String BG2 = "bg2";
  -    public static final String UCR = "ucr";
  -    public static final String UCR2 = "ucr2";
  -    public static final String TR = "tr";
  -    public static final String TR2 = "tr2";
  -    public static final String HT = "ht";
  -    public static final String FL = "fl";
  -    public static final String SM = "sm";
  -    public static final String SA = "sa";
  -    public static final String BM = "bm";
  -    public static final String SMask = "smask";
  -    public static final String CA = "CA";
  -    public static final String ca = "ca";
  -    public static final String AIS = "ais";
  -    public static final String TK = "tk";
   
  +    /** Line width (LW) */
  +    public static final String GSTATE_LINE_WIDTH          = "LW";
  +    /** Line cap (LC) */
  +    public static final String GSTATE_LINE_CAP            = "LC";
  +    /** Line join (LJ) */
  +    public static final String GSTATE_LINE_JOIN           = "LJ";
  +    /** Miter limit (ML) */
  +    public static final String GSTATE_MITER_LIMIT         = "ML";
  +    /** Dash pattern (D) */
  +    public static final String GSTATE_DASH_PATTERN        = "D";
  +    /** Rendering intent (RI) */
  +    public static final String GSTATE_RENDERING_INTENT    = "RI";
  +    /** Overprint for stroke (OP) */
  +    public static final String GSTATE_OVERPRINT_STROKE    = "OP";
  +    /** Overprint for fill (op) */
  +    public static final String GSTATE_OVERPRINT_FILL      = "op";
  +    /** Overprint mode (OPM) */
  +    public static final String GSTATE_OVERPRINT_MODE      = "OPM";
  +    /** Font (Font) */
  +    public static final String GSTATE_FONT                = "Font";
  +    /** Black generation (BG) */
  +    public static final String GSTATE_BLACK_GENERATION    = "BG";
  +    /** Black generation with default (BG2) */
  +    public static final String GSTATE_BLACK_GENERATION2   = "BG2";
  +    /** Undercolor removal function (UCR) */
  +    public static final String GSTATE_UNDERCOLOR_REMOVAL  = "UCR";
  +    /** Undercolor removal function with default (UCR2) */
  +    public static final String GSTATE_UNDERCOLOR_REMOVAL2 = "UCR2";
  +    /** Transfer function (TR) */
  +    public static final String GSTATE_TRANSFER_FUNCTION   = "TR";
  +    /** Transfer function with default (TR2) */
  +    public static final String GSTATE_TRANSFER_FUNCTION2  = "TR2";
  +    /** Halftone dictionary or stream (HT) */
  +    public static final String GSTATE_HALFTONE_DICT       = "HT";
  +    /** Halftone phase (HTP, does not show up anymore in PDF 1.4)*/
  +    public static final String GSTATE_HALFTONE_PHASE      = "HTP";
  +    /** Flatness (FL) */
  +    public static final String GSTATE_FLATNESS            = "FL";
  +    /** Smoothness (SM) */
  +    public static final String GSTATE_SMOOTHNESS          = "SM";
  +    /** Strike adjustment (SA) */
  +    public static final String GSTATE_STRIKE_ADJ          = "SA";
  +    /** Blend mode (BM, PDF 1.4) */
  +    public static final String GSTATE_BLEND_MODE          = "BM";
  +    /** Soft mask (SMask, PDF 1.4) */
  +    public static final String GSTATE_SOFT_MASK           = "SMask";
  +    /** Stroking Alpha (CA, PDF 1.4) */
  +    public static final String GSTATE_ALPHA_STROKE        = "CA";
  +    /** Nonstroking Alpha (ca, PDF 1.4) */
  +    public static final String GSTATE_ALPHA_NONSTROKE     = "ca";
  +    /** Alpha Source Flag (AIS, PDF 1.4) */
  +    public static final String GSTATE_ALPHA_SOURCE_FLAG   = "AIS";
  +    /** Text Knockout Flag (TK, PDF 1.4) */
  +    public static final String GSTATE_TEXT_KNOCKOUT       = "TK";
  +    
  +
  +    /** Default GState object */
       public static final PDFGState DEFAULT;
   
       static {
           DEFAULT = new PDFGState(0);
  -        HashMap vals = DEFAULT.values;
  +        Map vals = DEFAULT.values;
           /*vals.put(LW, new Float(1.0));
           vals.put(LC, new Integer(0));
           vals.put(LJ, new Integer(0));
  @@ -57,55 +87,71 @@
           vals.put(op, Boolean.FALSE);
           vals.put(OPM, new Integer(1));
           vals.put(Font, "");*/
  -        vals.put(CA, new Float(1.0));
  -        vals.put(ca, new Float(1.0));
  +        
  +        vals.put(GSTATE_ALPHA_STROKE, new Float(1.0));
  +        vals.put(GSTATE_ALPHA_NONSTROKE, new Float(1.0));
       }
   
  -    HashMap values = new HashMap();
  +    private Map values = new java.util.HashMap();
   
       /**
  -     * create a /ExtGState object.
  +     * Create a /ExtGState object.
        *
        * @param number the object's number
  -     * @param pageReference the pageReference represented by this object
        */
       public PDFGState(int number) {
  -
           /* generic creation of object */
           super(number);
  -
       }
   
  +    /**
  +     * Returns the name of this object
  +     * @return the name
  +     */
       public String getName() {
           return "GS" + this.number;
       }
   
  +    /**
  +     * Sets the alpha value.
  +     * @param val alpha value (0.0 - 1.0)
  +     * @param fill True if alpha should be set for non-stroking operations, 
  +     * False if for stroking operations
  +     */
       public void setAlpha(float val, boolean fill) {
           if (fill) {
  -            values.put(ca, new Float(val));
  +            values.put(GSTATE_ALPHA_NONSTROKE, new Float(val));
           } else {
  -            values.put(CA, new Float(val));
  +            values.put(GSTATE_ALPHA_STROKE, new Float(val));
           }
       }
   
  +    /**
  +     * Adds all values from another GState object to this one.
  +     * @param state source object to copy from
  +     */
       public void addValues(PDFGState state) {
           values.putAll(state.values);
       }
   
  -    public void addValues(HashMap vals) {
  +    /**
  +     * Adds all values from a Map to this object.
  +     * @param vals source object to copy from
  +     */
  +    public void addValues(Map vals) {
           values.putAll(vals);
       }
   
       /**
  -     * represent the object in PDF
  +     * Represent the object in PDF.
        *
        * @return the PDF string
        */
       public byte[] toPDF() {
           StringBuffer sb = new StringBuffer(this.number + " " + this.generation
                                 + " obj\n<<\n/Type /ExtGState\n");
  -        appendVal(sb, ca);
  -        appendVal(sb, CA);
  +        appendVal(sb, GSTATE_ALPHA_NONSTROKE);
  +        appendVal(sb, GSTATE_ALPHA_STROKE);
   
           sb.append(">>\nendobj\n");
           return sb.toString().getBytes();
  @@ -128,6 +174,9 @@
        * endobj
        */
   
  +    /**
  +     * @see java.lang.Object#equals(Object)
  +     */
       public boolean equals(Object obj) {
           if (obj == this) {
               return true;
  @@ -135,12 +184,12 @@
           if (!(obj instanceof PDFGState)) {
               return false;
           }
  -        HashMap vals1 = values;
  -        HashMap vals2 = ((PDFGState)obj).values;
  +        Map vals1 = values;
  +        Map vals2 = ((PDFGState)obj).values;
           if (vals1.size() != vals2.size()) {
               return false;
           }
  -        for(Iterator iter = vals1.keySet().iterator(); iter.hasNext();) {
  +        for (Iterator iter = vals1.keySet().iterator(); iter.hasNext();) {
               Object str = iter.next();
               Object obj1 = vals1.get(str);
               if (!obj1.equals(vals2.get(str))) {
  
  
  
  1.6       +25 -10    xml-fop/src/org/apache/fop/pdf/PDFICCStream.java
  
  Index: PDFICCStream.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFICCStream.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PDFICCStream.java 29 Nov 2002 23:18:56 -0000      1.5
  +++ PDFICCStream.java 8 Jan 2003 13:57:23 -0000       1.6
  @@ -1,6 +1,6 @@
   /*
    * $Id$
  - * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
    */
  @@ -9,25 +9,40 @@
   
   import java.awt.color.ICC_Profile;
   
  +/**
  + * Special PDFStream for ICC profiles (color profiles).
  + */
   public class PDFICCStream extends PDFStream {
  +    
       private int origLength;
       private int len1, len3;
   
       private ICC_Profile cp;
       private PDFColorSpace pdfColorSpace;
   
  -    public void setColorSpace(ICC_Profile cp, PDFColorSpace alt) {
  -        this.cp = cp;
  -        pdfColorSpace = alt;
  -    }
  -
  +    /**
  +     * @see org.apache.fop.pdf.PDFObject#PDFObject(int)
  +     */
       public PDFICCStream(int num) {
           super(num);
           cp = null;
       }
   
  -        // overload the base object method so we don't have to copy
  -        // byte arrays around so much
  +    /**
  +     * Sets the color space to encode in PDF.
  +     * @param cp the ICC profile
  +     * @param alt the PDF color space
  +     */
  +    public void setColorSpace(ICC_Profile cp, PDFColorSpace alt) {
  +        this.cp = cp;
  +        pdfColorSpace = alt;
  +    }
  +
  +    /**
  +     * overload the base object method so we don't have to copy
  +     * byte arrays around so much
  +     * @see org.apache.fop.pdf.PDFObject#output(OutputStream)
  +     */
       protected int output(java.io.OutputStream stream)
           throws java.io.IOException {
   
  @@ -43,7 +58,7 @@
               pb.append("/Alternate 
/").append(pdfColorSpace.getColorSpacePDFString()).append(" ");
           }
   
  -        pb.append("/Length ").append((_data.getSize() + 1)).append(" 
").append(filterEntry);
  +        pb.append("/Length ").append((data.getSize() + 1)).append(" 
").append(filterEntry);
           pb.append(" >>\n");
           byte[] p = pb.toString().getBytes();
           stream.write(p);
  
  
  
  1.18      +90 -60    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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- PDFStream.java    22 Nov 2002 10:32:20 -0000      1.17
  +++ PDFStream.java    8 Jan 2003 13:57:23 -0000       1.18
  @@ -1,69 +1,74 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 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;
   
  -import java.io.ByteArrayOutputStream;
   import java.io.OutputStream;
   import java.io.IOException;
   import java.util.List;
   import java.util.Map;
  -import java.util.ArrayList;
  -import java.util.Enumeration;
   
   /**
  - * class representing a PDF stream.
  - *
  + * Class representing a PDF stream.
  + * <p>
    * A derivative of the PDF Object, a PDF Stream has not only a dictionary
    * but a stream of PDF commands. The stream of commands is where the real
    * work is done, the dictionary just provides information like the stream
    * length.
    */
   public class PDFStream extends PDFObject {
  +    
  +    /** Key for the default filter */
       public static final String DEFAULT_FILTER = "default";
  +    /** Key for the filter used for normal content*/
       public static final String CONTENT_FILTER = "content";
  +    /** Key for the filter used for images */
       public static final String IMAGE_FILTER = "image";
  +    /** Key for the filter used for JPEG images */
       public static final String JPEG_FILTER = "jpeg";
  +    /** Key for the filter used for fonts */
       public static final String FONT_FILTER = "font";
   
       /**
  -     * the stream of PDF commands
  +     * The stream of PDF commands
        */
  -    protected StreamCache _data;
  +    protected StreamCache data;
   
       /**
  -     * the filters that should be applied
  +     * The filters that should be applied
        */
  -    private List _filters;
  +    private List filters;
   
       /**
  -     * create an empty stream object
  +     * Create an empty stream object
        *
        * @param number the object's number
        */
       public PDFStream(int number) {
           super(number);
           try {
  -            _data = StreamCache.createStreamCache();
  +            data = StreamCache.createStreamCache();
           } catch (IOException ex) {
  +            /**@todo Log with Logger */
               ex.printStackTrace();
           }
  -        _filters = new ArrayList();
  +        filters = new java.util.ArrayList();
       }
   
       /**
  -     * append data to the stream
  +     * Append data to the stream
        *
        * @param s the string of PDF to add
        */
       public void add(String s) {
           try {
  -            _data.getOutputStream().write(s.getBytes());
  +            data.getOutputStream().write(s.getBytes());
           } catch (IOException ex) {
  +            /**@todo Log with Logger */
               ex.printStackTrace();
           }
   
  @@ -75,14 +80,19 @@
        * new instance of the particular filter of choice. The applied
        * flag in the filter is marked true after it has been applied to the
        * data.
  +     * @param filter filter to add
        */
       public void addFilter(PDFFilter filter) {
           if (filter != null) {
  -            _filters.add(filter);
  +            filters.add(filter);
           }
   
       }
   
  +    /**
  +     * Add a filter for compression of the stream by name.
  +     * @param filterType name of the filter to add
  +     */
       public void addFilter(String filterType) {
           if (filterType == null) {
               return;
  @@ -96,17 +106,22 @@
           } else if (filterType.equals("")) {
               return;
           } else {
  -            //log.error("Unsupported filter type in stream-filter-list: "
  -            //                       + filterType);
  +            throw new IllegalArgumentException(
  +                "Unsupported filter type in stream-filter-list: " + filterType);
           }
       }
   
  +    /**
  +     * Adds the default filters to this stream.
  +     * @param filters Map of filters
  +     * @param type which filter list to modify
  +     */
       public void addDefaultFilters(Map filters, String type) {
           List filterset = (List)filters.get(type);
  -        if(filterset == null) {
  +        if (filterset == null) {
               filterset = (List)filters.get(DEFAULT_FILTER);
           }
  -        if(filterset == null || filterset.size() == 0) {
  +        if (filterset == null || filterset.size() == 0) {
               // built-in default to flate
               addFilter(new FlateFilter());
           } else {
  @@ -118,7 +133,7 @@
       }
   
       /**
  -     * append an array of xRGB pixels, ASCII Hex Encoding it first
  +     * Append an array of xRGB pixels, ASCII Hex Encoding it first
        *
        * @param pixels the area of pixels
        * @param width the width of the image in pixels
  @@ -133,30 +148,35 @@
                       int g = (p >> 8) & 0xFF;
                       int b = (p) & 0xFF;
                       if (r < 16) {
  -                        _data.getOutputStream().write('0');
  +                        data.getOutputStream().write('0');
                       }
  -                    
_data.getOutputStream().write(Integer.toHexString(r).getBytes());
  +                    data.getOutputStream().write(Integer.toHexString(r).getBytes());
                       if (g < 16) {
  -                        _data.getOutputStream().write('0');
  +                        data.getOutputStream().write('0');
                       }
  -                    
_data.getOutputStream().write(Integer.toHexString(g).getBytes());
  +                    data.getOutputStream().write(Integer.toHexString(g).getBytes());
                       if (b < 16) {
  -                        _data.getOutputStream().write('0');
  +                        data.getOutputStream().write('0');
                       }
  -                    
_data.getOutputStream().write(Integer.toHexString(b).getBytes());
  -                    _data.getOutputStream().write(' ');
  +                    data.getOutputStream().write(Integer.toHexString(b).getBytes());
  +                    data.getOutputStream().write(' ');
                   }
               }
  -            _data.getOutputStream().write(">\n".getBytes());
  +            data.getOutputStream().write(">\n".getBytes());
           } catch (IOException ex) {
               ex.printStackTrace();
           }
   
       }
   
  +    /**
  +     * Used to set the contents of the PDF stream.
  +     * @param data the contents as a byte array
  +     * @throws IOException in case of an I/O problem
  +     */
       public void setData(byte[] data) throws IOException {
  -        _data.reset();
  -        _data.getOutputStream().write(data);
  +        this.data.reset();
  +        this.data.getOutputStream().write(data);
       }
   
       /*
  @@ -165,9 +185,13 @@
       }
       */
   
  +    /**
  +     * Returns the size of the content.
  +     * @return size of the content
  +     */
       public int getDataLength() {
           try {
  -            return _data.getSize();
  +            return data.getSize();
           } catch (Exception e) {
               e.printStackTrace();
               return 0;
  @@ -175,34 +199,35 @@
       }
   
       /**
  -     * represent as PDF.
  +     * Represent as PDF.
        *
        * @return the PDF string.
        */
  -    /*
  -     * public byte[] toPDF() {
  -     * byte[] d = _data.toByteArray();
  -     * ByteArrayOutputStream s = new ByteArrayOutputStream();
  -     * String p = this.number + " " + this.generation
  -     * + " obj\n<< /Length " + (d.length+1)
  -     * + " >>\nstream\n";
  -     * s.write(p.getBytes());
  -     * s.write(d);
  -     * s.write("\nendstream\nendobj\n".getBytes());
  -     * return s.toByteArray();
  -     * }
  -     */
       public byte[] toPDF() {
  -        throw new RuntimeException();
  +        throw new UnsupportedOperationException("Use output(OutputStream) instead");
  +        /*
  +         * byte[] d = _data.toByteArray();
  +         * ByteArrayOutputStream s = new ByteArrayOutputStream();
  +         * String p = this.number + " " + this.generation
  +         * + " obj\n<< /Length " + (d.length+1)
  +         * + " >>\nstream\n";
  +         * s.write(p.getBytes());
  +         * s.write(d);
  +         * s.write("\nendstream\nendobj\n".getBytes());
  +         * return s.toByteArray();
  +         */
       }
   
  -    // overload the base object method so we don't have to copy
  -    // byte arrays around so much
  +    /**
  +     * Overload the base object method so we don't have to copy
  +     * byte arrays around so much
  +     * @see org.apache.fop.pdf.PDFObject#output(OutputStream)
  +     */
       protected int output(OutputStream stream) throws IOException {
           int length = 0;
           String filterEntry = applyFilters();
           byte[] p = (this.number + " " + this.generation + " obj\n<< /Length "
  -                    + (_data.getSize() + 1) + " " + filterEntry
  +                    + (data.getSize() + 1) + " " + filterEntry
                       + " >>\n").getBytes();
   
           stream.write(p);
  @@ -217,15 +242,18 @@
   
       /**
        * Output just the stream data enclosed by stream/endstream markers
  +     * @param stream OutputStream to write to
  +     * @return int number of bytes written
  +     * @throws IOException in case of an I/O problem
        */
       protected int outputStreamData(OutputStream stream) throws IOException {
           int length = 0;
           byte[] p = "stream\n".getBytes();
           stream.write(p);
           length += p.length;
  -        _data.outputStreamData(stream);
  -        length += _data.getSize();
  -        _data.close();
  +        data.outputStreamData(stream);
  +        length += data.getSize();
  +        data.close();
           p = "\nendstream\n".getBytes();
           stream.write(p);
           length += p.length;
  @@ -239,18 +267,20 @@
        * entries for the stream dictionary. If the filters have already
        * been applied to the data (either externally, or internally)
        * then the dictionary entries are built and returned.
  +     * @return a String representing the filter list
  +     * @throws IOException in case of an I/O problem
        */
       protected String applyFilters() throws IOException {
  -        if (_filters.size() > 0) {
  -            List names = new ArrayList();
  -            List parms = new ArrayList();
  +        if (filters.size() > 0) {
  +            List names = new java.util.ArrayList();
  +            List parms = new java.util.ArrayList();
   
               // run the filters
  -            for (int count = 0; count < _filters.size(); count++) {
  -                PDFFilter filter = (PDFFilter)_filters.get(count);
  +            for (int count = 0; count < filters.size(); count++) {
  +                PDFFilter filter = (PDFFilter)filters.get(count);
                   // apply the filter encoding if neccessary
                   if (!filter.isApplied()) {
  -                    _data.applyFilter(filter);
  +                    data.applyFilter(filter);
                       filter.setApplied(true);
                   }
                   // place the names in our local vector in reverse order
  
  
  
  1.5       +54 -75    xml-fop/src/org/apache/fop/pdf/PDFT1Stream.java
  
  Index: PDFT1Stream.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFT1Stream.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PDFT1Stream.java  25 Oct 2002 09:29:46 -0000      1.4
  +++ PDFT1Stream.java  8 Jan 2003 13:57:23 -0000       1.5
  @@ -1,107 +1,86 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 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;
   
  +// Java
  +import java.io.IOException;
  +import java.io.UnsupportedEncodingException;
  +
  +// FOP
  +import org.apache.fop.fonts.type1.PFBData;
  +
  +/**
  + * Special PDFStream for embedding Type 1 fonts.
  + */
   public class PDFT1Stream extends PDFStream {
  -    private int origLength;
  -    private int len1, len3;
  -    private byte[] originalData = null;
  +    
  +    private PFBData pfb;
   
  -    public PDFT1Stream(int num, int len) {
  +    /**
  +     * @see org.apache.fop.pdf.PDFObject#PDFObject(int)
  +     */
  +    public PDFT1Stream(int num) {
           super(num);
  -        origLength = len;
       }
   
  -    private static final boolean byteCmp(byte[] src, int offset, byte[] cmp) {
  -        boolean ret = true;
  -        for (int i = 0; ret == true && i < cmp.length; i++) {
  -            // System.out.println("Compare: ");
  -            // System.out.println("         "+src[offset+i]+" "+cmp[i]);
  -            if (src[offset + i] != cmp[i])
  -                ret = false;
  -        }
  -        return ret;
  -    }
   
       /**
  -     * calculates the Length1 and Length3 PDFStream attributes for type1
  -     * font embedding
  +     * Overload the base object method so we don't have to copy
  +     * byte arrays around so much
  +     * @see org.apache.fop.pdf.PDFObject#output(OutputStream)
        */
  -    private void calcLengths(byte[] originalData) {
  -        // Calculate length 1 and 3
  -        // System.out.println ("Checking font, size = "+originalData.length);
  -
  -        // Length1 is the size of the initial ascii portion
  -        // search for "currentfile eexec"
  -        // Get the first binary number and search backwards for "eexec"
  -        len1 = 30;
  -
  -        byte[] eexec = (new String("currentfile eexec")).getBytes();
  -        // System.out.println("Length1="+len1);
  -        while (!byteCmp(originalData, len1 - eexec.length, eexec))
  -            len1++;
  -        // Skip newline
  -        len1++;
  -
  -        // Length3 is length of the last portion of the file
  -        len3 = 0;
  -        byte[] cltom = (new String("cleartomark")).getBytes();
  -        len3 -= cltom.length;
  -        while (!byteCmp(originalData, origLength + len3, cltom)) {
  -            len3--;
  -            // System.out.println("Len3="+len3);
  -        }
  -        len3 = -len3;
  -        len3++;
  -        // Eat 512 zeroes
  -        int numZeroes = 0;
  -        byte[] ws1 = "\n".getBytes();
  -        byte[] ws2 = "\r".getBytes();
  -        byte[] ws3 = "0".getBytes();
  -        while ((originalData[origLength - len3] == ws1[0] || 
originalData[origLength - len3] == ws2[0] || originalData[origLength - len3] == ws3[0])
  -               && numZeroes < 512) {
  -            len3++;
  -            if (originalData[origLength - len3] == ws3[0])
  -                numZeroes++;
  -        }
  -        // System.out.println("Length3="+len3);
  -    }
  -
  -    // overload the base object method so we don't have to copy
  -    // byte arrays around so much
       protected int output(java.io.OutputStream stream)
               throws java.io.IOException {
  +        if (pfb == null) {
  +            throw new IllegalStateException("pfb must not be null at this point");
  +        }
           int length = 0;
           String filterEntry = applyFilters();
  -        String preData = new String(this.number + " " + this.generation
  -                                    + " obj\n<< /Length "
  -                                    + (_data.getSize() + 1) + " " + filterEntry
  -                                    + " " + "/Length1 " + len1 + " /Length2 "
  -                                    + (origLength - len3 - len1)
  -                                    + " /Length3 " + len3 + " >>\n");
  +        String preData = this.number + " " + this.generation
  +                + " obj\n<< /Length " + pfb.getLength() + " " 
  +                + filterEntry  
  +                + " /Length1 " + pfb.getLength1()
  +                + " /Length2 " + pfb.getLength2()
  +                + " /Length3 " + pfb.getLength3() + " >>\n";
  +
  +        byte[] p;
  +        try {
  +            p = preData.getBytes(PDFDocument.ENCODING);
  +        } catch (UnsupportedEncodingException ue) {
  +            p = preData.getBytes();
  +        }       
   
  -        byte[] p = preData.getBytes();
           stream.write(p);
           length += p.length;
   
           length += outputStreamData(stream);
  -        p = "endobj\n".getBytes();
  +        try {
  +            p = "endobj\n".getBytes(PDFDocument.ENCODING);
  +        } catch (UnsupportedEncodingException ue) {
  +            p = "endobj\n".getBytes();
  +        }       
           stream.write(p);
           length += p.length;
  -        System.out.println("Embedded Type1 font");
  +        //System.out.println("Embedded Type1 font");
           return length;
       }
   
  -    public void setData(byte[] data, int size) throws java.io.IOException {
  -        calcLengths(data);
  -        _data.reset();
  +    /**
  +     * Used to set the PFBData object that represents the embeddable Type 1 
  +     * font.
  +     * @param pfb The PFB file
  +     * @throws IOException in case of an I/O problem
  +     */
  +    public void setData(PFBData pfb) throws IOException {
  +        data.reset();
           // System.out.println("Writing " + size + " bytes of font data");
  -        _data.getOutputStream().write(data, 0, size);
  +        this.pfb = pfb;
  +        pfb.outputAllParts(data.getOutputStream());
       }
   
   }
  
  
  
  1.4       +29 -8     xml-fop/src/org/apache/fop/pdf/PDFTTFStream.java
  
  Index: PDFTTFStream.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFTTFStream.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PDFTTFStream.java 27 May 2002 10:59:07 -0000      1.3
  +++ PDFTTFStream.java 8 Jan 2003 13:57:23 -0000       1.4
  @@ -1,29 +1,43 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 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;
   
  +import java.io.IOException;
  +
  +/**
  + * Special PDFStream for embeddable TrueType fonts.
  + */
   public class PDFTTFStream extends PDFStream {
  +    
       private int origLength;
   
  +    /**
  +     * Main constructor
  +     * @param num PDF object number
  +     * @param len original length
  +     */
       public PDFTTFStream(int num, int len) {
           super(num);
           origLength = len;
       }
   
  -    // overload the base object method so we don't have to copy
  -    // byte arrays around so much
  +    /**
  +     * Overload the base object method so we don't have to copy
  +     * byte arrays around so much
  +     * @see org.apache.fop.pdf.PDFObject#output(OutputStream)
  +     */
       protected int output(java.io.OutputStream stream)
               throws java.io.IOException {
           int length = 0;
           String filterEntry = applyFilters();
           String preData = new String(this.number + " " + this.generation
                                       + " obj\n<< /Length "
  -                                    + (_data.getSize() + 1) + " " + filterEntry
  +                                    + (data.getSize() + 1) + " " + filterEntry
                                       + " " + "/Length1 " + origLength
                                       + " >>\n");
   
  @@ -38,10 +52,17 @@
           return length;
       }
   
  -    public void setData(byte[] data, int size) throws java.io.IOException {
  -        _data.reset();
  +    /**
  +     * Sets the TrueType font data.
  +     * @param data the font payload
  +     * @param size size of the payload
  +     * @throws IOException in case of an I/O problem
  +     */
  +    public void setData(byte[] data, int size) throws IOException {
  +        this.data.reset();
  +        /**@todo Log using Logger */
           System.out.println("Writing " + size + " bytes of font data");
  -        _data.getOutputStream().write(data, 0, size);
  +        this.data.getOutputStream().write(data, 0, size);
       }
   
   }
  
  
  
  1.7       +29 -11    xml-fop/src/org/apache/fop/pdf/PDFWArray.java
  
  Index: PDFWArray.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFWArray.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PDFWArray.java    11 Dec 2001 12:11:00 -0000      1.6
  +++ PDFWArray.java    8 Jan 2003 13:57:23 -0000       1.7
  @@ -1,30 +1,40 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 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;
   
  -import java.util.ArrayList;
  +import java.util.List;
   
   /**
  - * class representing a <b>W</b> array for CID fonts.
  + * Class representing a <b>W</b> array for CID fonts.
    */
   public class PDFWArray {
   
       /**
  -     * the metrics
  +     * The metrics
        */
  -    private ArrayList entries;
  +    private List entries = new java.util.ArrayList();
   
  +    /** 
  +     * Default constructor 
  +     */
       public PDFWArray() {
  -        entries = new ArrayList();
  +    }
  +    
  +    /**
  +     * Convenience constructor
  +     * @param metrics the metrics array to initially add
  +     */
  +    public PDFWArray(int[] metrics) {
  +        addEntry(0, metrics);
       }
   
       /**
  -     * add an entry for single starting CID.
  +     * Add an entry for single starting CID.
        * i.e. in the form "c [w ...]"
        *
        * @param start the starting CID value.
  @@ -35,7 +45,7 @@
       }
   
       /**
  -     * add an entry for a range of CIDs (/W element on p 213)
  +     * Add an entry for a range of CIDs (/W element on p 213)
        *
        * @param first the first CID in the range
        * @param last the last CID in the range
  @@ -48,7 +58,7 @@
       }
   
       /**
  -     * add an entry for a range of CIDs (/W2 element on p 210)
  +     * Add an entry for a range of CIDs (/W2 element on p 210)
        *
        * @param first the first CID in the range
        * @param last the last CID in the range
  @@ -62,10 +72,18 @@
           });
       }
   
  +    /**
  +     * Convert this object to PDF code.
  +     * @return byte[] the PDF code
  +     */
       public byte[] toPDF() {
           return toPDFString().getBytes();
       }
   
  +    /**
  +     * Convert this object to PDF code.
  +     * @return String the PDF code
  +     */
       public String toPDFString() {
           StringBuffer p = new StringBuffer();
           p.append("[ ");
  @@ -87,7 +105,7 @@
       }
   
       /**
  -     * inner class for entries in the form "c [w ...]"
  +     * Inner class for entries in the form "c [w ...]"
        */
       private static class Entry {
           private int start;
  
  
  

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

Reply via email to