You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by sp...@apache.org on 2008/02/14 22:57:53 UTC

svn commit: r627882 [10/41] - in /xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking: ./ examples/embedding/ examples/embedding/java/embedding/ examples/embedding/java/embedding/intermediate/ examples/embedding/xml/xml/ examples/fo/ examples/...

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/BitmapImage.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/BitmapImage.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/BitmapImage.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/BitmapImage.java Thu Feb 14 13:55:44 2008
@@ -30,7 +30,7 @@
 public class BitmapImage implements PDFImage {
     private int height;
     private int width;
-    private int bitsPerPixel;
+    private int bitsPerComponent;
     private PDFDeviceColorSpace colorSpace;
     private byte[] bitmaps;
     private PDFReference maskRef;
@@ -53,10 +53,12 @@
         this.key = k;
         this.height = height;
         this.width = width;
-        this.bitsPerPixel = 8;
+        this.bitsPerComponent = 8;
         this.colorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
         this.bitmaps = data;
-        maskRef = new PDFReference(mask);
+        if (mask != null) {
+            maskRef = new PDFReference(mask);
+        }
     }
 
     /**
@@ -117,13 +119,9 @@
         return colorSpace;
     }
 
-    /**
-     * Get the number of bits per pixel.
-     *
-     * @return the number of bits per pixel
-     */
-    public int getBitsPerPixel() {
-        return bitsPerPixel;
+    /** {@inheritDoc} */
+    public int getBitsPerComponent() {
+        return bitsPerComponent;
     }
 
     /**
@@ -163,15 +161,6 @@
         return null;
     }
 
-    /**
-     * Get the soft mask reference for this image.
-     *
-     * @return the soft mask reference if any
-     */
-    public String getSoftMask() {
-        return maskRef.toInlinePDFString();
-    }
-    
     /** {@inheritDoc} */
     public PDFReference getSoftMaskReference() {
         return maskRef;
@@ -182,13 +171,16 @@
         return false;
     }
     
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public void outputContents(OutputStream out) throws IOException {
         out.write(bitmaps);
     }
     
+    /** {@inheritDoc} */
+    public void populateXObjectDictionary(PDFDictionary dict) {
+        //nop
+    }
+
     /**
      * Get the ICC stream.
      * @return always returns null since this has no icc color space

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/FlateFilter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/FlateFilter.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/FlateFilter.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/FlateFilter.java Thu Feb 14 13:55:44 2008
@@ -19,8 +19,8 @@
  
 package org.apache.fop.pdf;
 
-import java.io.OutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 
 import org.apache.xmlgraphics.util.io.FlateEncodeOutputStream;
 
@@ -98,13 +98,13 @@
         if (predictor > PREDICTION_NONE) {
             PDFDictionary dict = new PDFDictionary();
             dict.put("Predictor", predictor);
-            if (colors > 0) {
+            if (colors > 1) {
                 dict.put("Colors", colors);
             }
-            if (bitsPerComponent > 0) {
+            if (bitsPerComponent > 0 && bitsPerComponent != 8) {
                 dict.put("BitsPerComponent", bitsPerComponent);
             }
-            if (columns > 0) {
+            if (columns > 1) {
                 dict.put("Columns", columns);
             }
             return dict;

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFAMode.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFArray.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFArray.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFArray.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFArray.java Thu Feb 14 13:55:44 2008
@@ -19,9 +19,14 @@
  
 package org.apache.fop.pdf;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
 import java.util.Collection;
 import java.util.List;
 
+import org.apache.commons.io.output.CountingOutputStream;
+
 /**
  * Class representing an array object.
  */
@@ -33,20 +38,28 @@
 
     /**
      * Create a new, empty array object
+     * @param parent the array's parent if any
      */
-    public PDFArray() {
+    public PDFArray(PDFObject parent) {
         /* generic creation of PDF object */
-        super();
+        super(parent);
     }
 
     /**
-     * Create the array object
-     *
+     * Create a new, empty array object with no parent.
+     */
+    public PDFArray() {
+        this(null);
+    }
+
+    /**
+     * Create an array object.
+     * @param parent the array's parent if any
      * @param values the actual array wrapped by this object
      */
-    public PDFArray(int[] values) {
+    public PDFArray(PDFObject parent, int[] values) {
         /* generic creation of PDF object */
-        super();
+        super(parent);
 
         for (int i = 0, c = values.length; i < c; i++) {
             this.values.add(new Integer(values[i]));
@@ -54,25 +67,39 @@
     }
 
     /**
-     * Create the array object
-     *
+     * Create an array object.
+     * @param parent the array's parent if any
+     * @param values the actual array wrapped by this object
+     */
+    public PDFArray(PDFObject parent, double[] values) {
+        /* generic creation of PDF object */
+        super(parent);
+
+        for (int i = 0, c = values.length; i < c; i++) {
+            this.values.add(new Double(values[i]));
+        }
+    }
+
+    /**
+     * Create an array object.
+     * @param parent the array's parent if any
      * @param values the actual values wrapped by this object
      */
-    public PDFArray(Collection values) {
+    public PDFArray(PDFObject parent, Collection values) {
         /* generic creation of PDF object */
-        super();
+        super(parent);
         
         this.values.addAll(values);
     }
     
     /**
      * Create the array object
-     *
+     * @param parent the array's parent if any
      * @param values the actual array wrapped by this object
      */
-    public PDFArray(Object[] values) {
+    public PDFArray(PDFObject parent, Object[] values) {
         /* generic creation of PDF object */
-        super();
+        super(parent);
         
         for (int i = 0, c = values.length; i < c; i++) {
             this.values.add(values[i]);
@@ -119,6 +146,12 @@
      * @param obj the value
      */
     public void add(Object obj) {
+        if (obj instanceof PDFObject) {
+            PDFObject pdfObj = (PDFObject)obj;
+            if (!pdfObj.hasObjectNumber()) {
+                pdfObj.setParent(this);
+            }
+        }
         this.values.add(obj);
     }
     
@@ -130,27 +163,30 @@
         this.values.add(new Double(value));
     }
     
-    /**
-     * {@inheritDoc}
-     */
-    public String toPDFString() {
-        StringBuffer p = new StringBuffer(64);
+    /** {@inheritDoc} */
+    protected int output(OutputStream stream) throws IOException {
+        CountingOutputStream cout = new CountingOutputStream(stream);
+        Writer writer = PDFDocument.getWriterFor(cout);
         if (hasObjectNumber()) {
-            p.append(getObjectID());
+            writer.write(getObjectID());
         }
-        p.append("[");
+        
+        writer.write('[');
         for (int i = 0; i < values.size(); i++) {
             if (i > 0) {
-                p.append(" ");
+                writer.write(' ');
             }
             Object obj = this.values.get(i);
-            formatObject(obj, p);
+            formatObject(obj, cout, writer);
         }
-        p.append("]");
+        writer.write(']');
+        
         if (hasObjectNumber()) {
-            p.append("\nendobj\n");
+            writer.write("\nendobj\n");
         }
-        return p.toString();
+        
+        writer.flush();
+        return cout.getCount();
     }
-
+    
 }

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFCIDFontDescriptor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFCIDFontDescriptor.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFCIDFontDescriptor.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFCIDFontDescriptor.java Thu Feb 14 13:55:44 2008
@@ -22,24 +22,14 @@
 // based on work by Takayuki Takeuchi
 
 /**
- * class representing a font descriptor for CID fonts.
+ * Class representing a font descriptor for CID fonts.
  *
  * Font descriptors for CID fonts are specified on page 227 and onwards of the PDF 1.3 spec.
  */
 public class PDFCIDFontDescriptor extends PDFFontDescriptor {
 
     /**
-     * The language for the font
-     */
-    protected String lang;
-
-    /**
-     * The cid set stream
-     */
-    protected PDFStream cidSet;
-
-    /**
-     * create the /FontDescriptor object
+     * Create a /FontDescriptor object.
      *
      * @param basefont the base font name
      * @param fontBBox the bounding box for the described font
@@ -56,31 +46,19 @@
         super(basefont, fontBBox[3], fontBBox[1], capHeight, flags,
               new PDFRectangle(fontBBox), italicAngle, stemV);
 
-        this.lang = lang;
+        put("MissingWidth", new Integer(500));
+        if (lang != null) {
+            put("Lang", lang);
+        }
     }
 
     /**
      * Set the CID set stream.
-     * @param cidSet the pdf stream cotnaining the CID set
+     * @param cidSet the PDF stream containing the CID set
      */
     public void setCIDSet(PDFStream cidSet) {
-        this.cidSet = cidSet;
-    }
-
-    /**
-     * Fill in the pdf data for this font descriptor.
-     * The charset specific dictionary entries are output.
-     * @param p the string buffer to append the data
-     */
-    protected void fillInPDF(StringBuffer p) {
-        p.append("\n/MissingWidth 500\n");
-        if (lang != null) {
-            p.append("\n/Lang /");
-            p.append(lang);
-        }
         if (cidSet != null) {
-            p.append("\n/CIDSet /");
-            p.append(this.cidSet.referencePDF());
+            put("CIDSet", cidSet);
         }
     }
 

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFCMap.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFCMap.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFCMap.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFCMap.java Thu Feb 14 13:55:44 2008
@@ -21,6 +21,8 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.StringWriter;
+import java.io.Writer;
 
 /**
  * Class representing the CMap encodings.
@@ -395,15 +397,6 @@
     }
 
     /**
-     * Add the contents of this pdf object to the PDF stream.
-     */
-    public void addContents() {
-        StringBuffer p = new StringBuffer();
-        fillInPDF(p);
-        add(p.toString());
-    }
-
-    /**
      * set the base CMap
      *
      * @param base the name of the base CMap
@@ -422,107 +415,20 @@
     }
 
     /**
-     * Fill in the pdf string for this CMap.
-     *
-     * @param p the string buffer to add the pdf data to
+     * Creates the CMapBuilder that will build the CMap's content.
+     * @param writer a Writer to write the CMap's contents to
+     * @return the newly created CMapBuilder
      */
-    public void fillInPDF(StringBuffer p) {
-        writePreStream(p);
-        writeStreamComments(p);
-        writeCIDInit(p);
-        writeCIDSystemInfo(p);
-        writeVersionTypeName(p);
-        writeCodeSpaceRange(p);
-        writeCIDRange(p);
-        writeBFEntries(p);
-        writeWrapUp(p);
-        writeStreamAfterComments(p);
-        writeUseCMap(p);
-        add(p.toString());
-    }
-
-    protected void writePreStream(StringBuffer p) {
-        // p.append("/Type /CMap\n");
-        // p.append(sysInfo.toPDFString());
-        // p.append("/CMapName /" + name + EOL);
-    }
-
-    protected void writeStreamComments(StringBuffer p) {
-        p.append("%!PS-Adobe-3.0 Resource-CMap\n");
-        p.append("%%DocumentNeededResources: ProcSet (CIDInit)\n");
-        p.append("%%IncludeResource: ProcSet (CIDInit)\n");
-        p.append("%%BeginResource: CMap (" + name + ")\n");
-        p.append("%%EndComments\n");
-    }
-
-    protected void writeCIDInit(StringBuffer p) {
-        p.append("/CIDInit /ProcSet findresource begin\n");
-        p.append("12 dict begin\n");
-        p.append("begincmap\n");
-    }
-
-    protected void writeCIDSystemInfo(StringBuffer p) {
-        p.append("/CIDSystemInfo 3 dict dup begin\n");
-        p.append("  /Registry (Adobe) def\n");
-        p.append("  /Ordering (Identity) def\n");
-        p.append("  /Supplement 0 def\n");
-        p.append("end def\n");
-    }
-
-    protected void writeVersionTypeName(StringBuffer p) {
-        p.append("/CMapVersion 1 def\n");
-        p.append("/CMapType 1 def\n");
-        p.append("/CMapName /" + name + " def\n");
-    }
-
-    protected void writeCodeSpaceRange(StringBuffer p) {
-        p.append("1 begincodespacerange\n");
-        p.append("<0000> <FFFF>\n");
-        p.append("endcodespacerange\n");
-    }
-
-    protected void writeCIDRange(StringBuffer p) {
-        p.append("1 begincidrange\n");
-        p.append("<0000> <FFFF> 0\n");
-        p.append("endcidrange\n");
-    }
-
-    protected void writeBFEntries(StringBuffer p) {
-        // p.append("1 beginbfrange\n");
-        // p.append("<0020> <0100> <0000>\n");
-        // p.append("endbfrange\n");
+    protected CMapBuilder createCMapBuilder(Writer writer) {
+        return new CMapBuilder(writer, this.name);
     }
-
-    protected void writeWrapUp(StringBuffer p) {
-        p.append("endcmap\n");
-        p.append("CMapName currentdict /CMap defineresource pop\n");
-        p.append("end\n");
-        p.append("end\n");
-    }
-
-    protected void writeStreamAfterComments(StringBuffer p) {
-        p.append("%%EndResource\n");
-        p.append("%%EOF\n");
-    }
-
-    protected void writeUseCMap(StringBuffer p) {
-        /*
-         * p.append(" /Type /CMap");
-         * p.append("/CMapName /" + name + EOL);
-         * p.append("/WMode " + wMode + EOL);
-         * if (base != null) {
-         *     p.append("/UseCMap ");
-         * if (base instanceof String) {
-         * p.append("/"+base);
-         * } else {// base instanceof PDFStream
-         * p.append(((PDFStream)base).referencePDF());
-         * }
-         * }
-         */
-    }
-
+    
+    /** {@inheritDoc} */
     protected int output(OutputStream stream) throws IOException {
-        fillInPDF(new StringBuffer());
+        StringWriter writer = new StringWriter();
+        CMapBuilder builder = createCMapBuilder(writer);
+        builder.writeCMap();
+        add(writer.getBuffer().toString()); //TODO Could be optimized by not buffering
         return super.output(stream);
     }
 }

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFConformanceException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDestination.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDestination.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDestination.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDestination.java Thu Feb 14 13:55:44 2008
@@ -19,6 +19,12 @@
 
 package org.apache.fop.pdf;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+
+import org.apache.commons.io.output.CountingOutputStream;
+
 /**
  * class representing a named destination
  */
@@ -40,30 +46,24 @@
      * @param goToRef Object reference to the GoTo Action
      */
     public PDFDestination(String idRef, Object goToRef) {
+        super();
         this.goToReference = goToRef;
         this.idRef = idRef;
     }
 
-    /**
-     * Creates the key/value pair for this destination entry for the name tree.
-     * @return the formatted key/value pair
-     */
-    public String toKeyValuePair() {
-        StringBuffer sb = new StringBuffer();
-        sb.append("(").append(getIDRef()).append(") ");
-        if (goToReference instanceof PDFWritable) {
-            sb.append(((PDFWritable)goToReference).toInlinePDFString());
-        } else {
-            sb.append(goToReference);
-        }
-        return sb.toString();
-    }
-    
     /** {@inheritDoc} */
-    protected String toPDFString() {
-        return toKeyValuePair();
+    protected int output(OutputStream stream) throws IOException {
+        CountingOutputStream cout = new CountingOutputStream(stream);
+        Writer writer = PDFDocument.getWriterFor(cout);
+        
+        formatObject(getIDRef(), cout, writer);
+        writer.write(' ');
+        formatObject(goToReference, cout, writer);
+        
+        writer.flush();
+        return cout.getCount();
     }
-
+    
     /**
      * Sets the GoToReference in the associated DestinationData object.
      *
@@ -124,9 +124,7 @@
         return false;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public int hashCode() {
         return getIDRef().hashCode();
     }

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDests.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDests.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDests.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDests.java Thu Feb 14 13:55:44 2008
@@ -40,7 +40,7 @@
      */
     public PDFDests(List destinationList) {
         this();
-        setNames(new PDFArray(destinationList));
+        setNames(new PDFArray(this, destinationList));
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDictionary.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDictionary.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDictionary.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDictionary.java Thu Feb 14 13:55:44 2008
@@ -19,10 +19,15 @@
  
 package org.apache.fop.pdf;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.io.output.CountingOutputStream;
+
 /**
  * Class representing a PDF dictionary object
  */
@@ -40,19 +45,32 @@
     protected List order = new java.util.ArrayList();
     
     /**
-     * Create the dictionary object
+     * Create a new dictionary object.
      */
     public PDFDictionary() {
-        /* generic creation of PDF object */
         super();
     }
 
     /**
+     * Create a new dictionary object.
+     * @param parent the object's parent if any
+     */
+    public PDFDictionary(PDFObject parent) {
+        super(parent);
+    }
+
+    /**
      * Puts a new name/value pair.
      * @param name the name
      * @param value the value
      */
     public void put(String name, Object value) {
+        if (value instanceof PDFObject) {
+            PDFObject pdfObj = (PDFObject)value;
+            if (!pdfObj.hasObjectNumber()) {
+                pdfObj.setParent(this);
+            }
+        }
         if (!entries.containsKey(name)) {
             this.order.add(name);
         }
@@ -80,47 +98,53 @@
         return this.entries.get(name);
     }
     
-    /**
-     * {@inheritDoc}
-     */
-    public String toPDFString() {
-        StringBuffer p = new StringBuffer(64);
+    /** {@inheritDoc} */
+    protected int output(OutputStream stream) throws IOException {
+        CountingOutputStream cout = new CountingOutputStream(stream);
+        Writer writer = PDFDocument.getWriterFor(cout);
         if (hasObjectNumber()) {
-            p.append(getObjectID());
+            writer.write(getObjectID());
         }
-        writeDictionary(p);
+        
+        writeDictionary(cout, writer);
+
         if (hasObjectNumber()) {
-            p.append("endobj\n");
+            writer.write("\nendobj\n");
         }
-        return p.toString();
+        
+        writer.flush();
+        return cout.getCount();
     }
-
+    
     /**
      * Writes the contents of the dictionary to a StringBuffer.
-     * @param sb the target StringBuffer
+     * @param out the OutputStream (for binary content)
+     * @param writer the Writer (for text content, wraps the above OutputStream)
+     * @throws IOException if an I/O error occurs
      */
-    protected void writeDictionary(StringBuffer sb) {
-        sb.append("<<");
+    protected void writeDictionary(OutputStream out, Writer writer) throws IOException {
+        writer.write("<<");
         boolean compact = (this.order.size() <= 2);
         Iterator iter = this.order.iterator();
         while (iter.hasNext()) {
             String key = (String)iter.next();
             if (compact) {
-                sb.append(' ');
+                writer.write(' ');
             } else {
-                sb.append("\n  ");
+                writer.write("\n  ");
             }
-            sb.append('/').append(key);
-            sb.append(' ');
+            writer.write('/');
+            writer.write(key);
+            writer.write(' ');
             Object obj = this.entries.get(key);
-            formatObject(obj, sb);
+            formatObject(obj, out, writer);
         }
         if (compact) {
-            sb.append(' ');
+            writer.write(' ');
         } else {
-            sb.append('\n');
+            writer.write('\n');
         }
-        sb.append(">>\n");
+        writer.write(">>\n");
     }
 
 }

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDictionary.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDocument.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDocument.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDocument.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFDocument.java Thu Feb 14 13:55:44 2008
@@ -24,15 +24,16 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
+import java.io.Writer;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Collections;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Iterator;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -316,6 +317,22 @@
         }
     }
 
+    /**
+     * Creates and returns a Writer object wrapping the given OutputStream. The Writer is
+     * buffered to reduce the number of calls to the encoding converter so don't forget
+     * to <code>flush()</code> the Writer after use or before writing directly to the
+     * underlying OutputStream.
+     * @param out the OutputStream to write to
+     * @return the requested Writer
+     */
+    public static Writer getWriterFor(OutputStream out) {
+        try {
+            return new java.io.BufferedWriter(new java.io.OutputStreamWriter(out, ENCODING));
+        } catch (UnsupportedEncodingException uee) {
+            throw new Error("JVM doesn't support " + ENCODING + " encoding!");
+        }
+    }
+    
     /**
      * set the producer of the document
      *

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFEncoding.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFEncoding.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFEncoding.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFEncoding.java Thu Feb 14 13:55:44 2008
@@ -20,12 +20,11 @@
 package org.apache.fop.pdf;
 
 // Java
-import java.util.List;
-import java.util.Map;
-import java.util.Iterator;
+import java.util.Collections;
+import java.util.Set;
 
 /**
- * class representing an /Encoding object.
+ * Class representing an /Encoding object.
  *
  * A small object expressing the base encoding name and
  * the differences from the base encoding.
@@ -34,90 +33,113 @@
  *
  * Encodings are specified in section 5.5.5 of the PDF 1.4 spec.
  */
-public class PDFEncoding extends PDFObject {
+public class PDFEncoding extends PDFDictionary {
 
-    /**
-     * the name for the standard encoding scheme
-     */
+    /** the name for the standard encoding scheme */
+    public static final String STANDARD_ENCODING = "StandardEncoding";
+    /** the name for the Mac Roman encoding scheme */
     public static final String MAC_ROMAN_ENCODING = "MacRomanEncoding";
-
-    /**
-     * the name for the standard encoding scheme
-     */
+    /** the name for the Mac Export encoding scheme */
     public static final String MAC_EXPERT_ENCODING = "MacExpertEncoding";
-
-    /**
-     * the name for the standard encoding scheme
-     */
+    /** the name for the WinAnsi encoding scheme */
     public static final String WIN_ANSI_ENCODING = "WinAnsiEncoding";
+    /** the name for the PDF document encoding scheme */
+    public static final String PDF_DOC_ENCODING = "PDFDocEncoding";
 
-    /**
-     * the name for the base encoding.
-     * One of the three base encoding scheme names or
-     * the default font's base encoding if null.
-     */
-    protected String basename;
-
-    /**
-     * the differences from the base encoding
-     */
-    protected Map differences;
+    /** the set of predefined encodings that can be assumed present in a PDF viewer */
+    private static final Set PREDEFINED_ENCODINGS;
+    
+    static {
+        Set encodings = new java.util.HashSet();
+        encodings.add(STANDARD_ENCODING);
+        encodings.add(MAC_ROMAN_ENCODING);
+        encodings.add(MAC_EXPERT_ENCODING);
+        encodings.add(WIN_ANSI_ENCODING);
+        encodings.add(PDF_DOC_ENCODING);
+        PREDEFINED_ENCODINGS = Collections.unmodifiableSet(encodings);
+    }
 
     /**
-     * create the /Encoding object
+     * Create a new /Encoding object.
      *
      * @param basename the name of the character encoding schema
      */
     public PDFEncoding(String basename) {
-
-        /* generic creation of PDF object */
         super();
 
-        /* set fields using paramaters */
-        this.basename = basename;
-        this.differences = new java.util.HashMap();
+        put("Type", new PDFName("Encoding"));
+        if (basename != null) {
+            put("BaseEncoding", new PDFName(basename));
+        }
     }
 
     /**
-     * add differences to the encoding
-     *
-     * @param code the first index of the sequence to be changed
-     * @param sequence the sequence of glyph names (as String)
+     * Indicates whether a given encoding is one of the predefined encodings.
+     * @param name the encoding name (ex. "StandardEncoding")
+     * @return true if it is a predefined encoding
+     */
+    public static boolean isPredefinedEncoding(String name) {
+        return PREDEFINED_ENCODINGS.contains(name);
+    }
+    
+    /**
+     * Creates and returns a new DifferencesBuilder instance for constructing the Differences
+     * array.
+     * @return the DifferencesBuilder
      */
-    public void addDifferences(int code, List sequence) {
-        differences.put(new Integer(code), sequence);
+    public DifferencesBuilder createDifferencesBuilder() {
+        return new DifferencesBuilder();
     }
 
     /**
-     * {@inheritDoc}
+     * Sets the Differences value.
+     * @param differences the differences.
+     */
+    public void setDifferences(PDFArray differences) {
+        put("Differences", differences);
+    }
+    
+    /**
+     * Builder class for constructing the Differences array.
      */
-    public String toPDFString() {
-        StringBuffer p = new StringBuffer(128);
-        p.append(getObjectID() 
-            + "<< /Type /Encoding");
-        if ((basename != null) && (!basename.equals(""))) {
-            p.append("\n/BaseEncoding /" + this.basename);
+    public class DifferencesBuilder {
+        
+        private PDFArray differences = new PDFArray();
+        private int currentCode = -1;
+        
+        /**
+         * Start a new difference.
+         * @param code the starting code index inside the encoding
+         * @return this builder instance
+         */
+        public DifferencesBuilder addDifference(int code) {
+            this.currentCode = code;
+            this.differences.add(new Integer(code));
+            return this;
         }
-        if (!differences.isEmpty()) {
-            p.append("\n/Differences [ ");
-            Object code;
-            Iterator codes = differences.keySet().iterator();
-            while (codes.hasNext()) {
-                code = codes.next();
-                p.append(" ");
-                p.append(code);
-                List sequence = (List)differences.get(code);
-                for (int i = 0; i < sequence.size(); i++) {
-                    p.append(" /");
-                    p.append((String)sequence.get(i));
-                }
+        
+        /**
+         * Adds a character name to the current difference.
+         * @param name the character name
+         * @return this builder instance
+         */
+        public DifferencesBuilder addName(String name) {
+            if (this.currentCode < 0) {
+                throw new IllegalStateException("addDifference(int) must be called first");
             }
-            p.append(" ]");
+            this.differences.add(new PDFName(name));
+            return this;
+        }
+        
+        /**
+         * Creates and returns the PDFArray representing the Differences entry.
+         * @return the Differences entry
+         */
+        public PDFArray toPDFArray() {
+            return this.differences;
         }
-        p.append(" >>\nendobj\n");
-        return p.toString();
     }
-
+    
     /*
      * example (p. 214)
      * 25 0 obj

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFEncryptionJCE.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFEncryptionJCE.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFEncryptionJCE.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFEncryptionJCE.java Thu Feb 14 13:55:44 2008
@@ -20,20 +20,20 @@
 package org.apache.fop.pdf;
 
 // Java
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.IOException;
+import java.security.InvalidKeyException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
-import java.security.InvalidKeyException;
+import java.util.Random;
+
+import javax.crypto.BadPaddingException;
 import javax.crypto.Cipher;
-import javax.crypto.spec.SecretKeySpec;
 import javax.crypto.CipherOutputStream;
 import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.BadPaddingException;
 import javax.crypto.NoSuchPaddingException;
-
-import java.util.Random;
+import javax.crypto.spec.SecretKeySpec;
 
 /**
  * class representing a /Filter /Standard object.
@@ -358,17 +358,20 @@
         if (this.encryptionKey == null) {
             throw new IllegalStateException("PDF Encryption has not been initialized");
         }
-        log.debug("encrypting with for " + number + " " + generation);
-
         byte[] hash = calcHash(number, generation);        
         return encryptWithHash(data, hash, hash.length);
     }
 
-    /**
-     * {@inheritDoc} 
-     */
+    /** {@inheritDoc} */
     public byte[] encrypt(byte[] data, PDFObject refObj) {
-        return encryptData(data, refObj.getObjectNumber(), refObj.getGeneration());
+        PDFObject o = refObj;
+        while (o != null && !o.hasObjectNumber()) {
+            o = o.getParent();
+        }
+        if (o == null) {
+            throw new IllegalStateException("No object number could be obtained for a PDF object");
+        }
+        return encryptData(data, o.getObjectNumber(), o.getGeneration());
     }
 
     private byte[] calcHash(int number, int generation) {

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFactory.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFactory.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFactory.java Thu Feb 14 13:55:44 2008
@@ -39,19 +39,24 @@
 import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.fonts.Glyphs;
+import org.apache.xmlgraphics.xmp.Metadata;
+
 import org.apache.fop.fonts.CIDFont;
+import org.apache.fop.fonts.CodePointMapping;
 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.SingleByteFont;
 import org.apache.fop.fonts.Typeface;
 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;
-import org.apache.xmlgraphics.xmp.Metadata;
 
 /**
  * This class provides method to create and register PDF objects.
@@ -872,7 +877,7 @@
         //true for a "deep" structure (one node per entry), true for a "flat" structure
         if (deep) {
             dests = new PDFDests();
-            PDFArray kids = new PDFArray();
+            PDFArray kids = new PDFArray(dests);
             Iterator iter = destinationList.iterator();
             while (iter.hasNext()) {
                 PDFDestination dest = (PDFDestination)iter.next();
@@ -880,8 +885,9 @@
                 getDocument().registerObject(node);
                 node.setLowerLimit(dest.getIDRef());
                 node.setUpperLimit(dest.getIDRef());
-                node.setNames(new PDFArray());
-                node.getNames().add(dest);
+                node.setNames(new PDFArray(node));
+                PDFArray names = node.getNames();
+                names.add(dest);
                 kids.add(node);
             }
             dests.setLowerLimit(((PDFNameTreeNode)kids.get(0)).getLowerLimit());
@@ -1179,6 +1185,7 @@
         }
 
         if (descriptor == null) {
+            //Usually Base 14 fonts
             PDFFont font = new PDFFont(fontname, FontType.TYPE1, basefont, encoding);
             getDocument().registerObject(font);
             return font;
@@ -1187,30 +1194,11 @@
 
             PDFFontDescriptor pdfdesc = makeFontDescriptor(descriptor);
 
-            PDFFontNonBase14 font = null;
-            if (fonttype == FontType.TYPE0) {
-                /*
-                 * Temporary commented out - customized CMaps
-                 * isn't needed until /ToUnicode support is added
-                 * PDFCMap cmap = new PDFCMap(++this.objectcount,
-                 * "fop-ucs-H",
-                 * new PDFCIDSystemInfo("Adobe",
-                 * "Identity",
-                 * 0));
-                 * cmap.addContents();
-                 * this.objects.add(cmap);
-                 */
-                font = (PDFFontNonBase14)PDFFont.createFont(fontname, fonttype,
-                                                            basefont, "Identity-H");
-            } else {
-
-                font = (PDFFontNonBase14)PDFFont.createFont(fontname, fonttype,
-                                                            basefont, encoding);
-            }
+            PDFFont font = null;
+            font = (PDFFont)PDFFont.createFont(fontname, fonttype,
+                                                        basefont, encoding);
             getDocument().registerObject(font);
 
-            font.setDescriptor(pdfdesc);
-
             if (fonttype == FontType.TYPE0) {
                 CIDFont cidMetrics;
                 if (metrics instanceof LazyFont) {
@@ -1230,7 +1218,7 @@
                                    (PDFCIDFontDescriptor)pdfdesc);
                 getDocument().registerObject(cidFont);
 
-                PDFCMap cmap = new PDFToUnicodeCMap(cidMetrics, "fop-ucs-H",
+                PDFCMap cmap = new PDFToUnicodeCMap(cidMetrics.getCharsUsed(), "fop-ucs-H",
                     new PDFCIDSystemInfo("Adobe",
                         "Identity",
                         0));
@@ -1238,16 +1226,57 @@
                 ((PDFFontType0)font).setCMAP(cmap);
                 ((PDFFontType0)font).setDescendantFonts(cidFont);
             } else {
-                int firstChar = 0;
-                int lastChar = 255;
-                if (metrics instanceof CustomFont) {
-                    CustomFont cf = (CustomFont)metrics;
-                    firstChar = cf.getFirstChar();
-                    lastChar = cf.getLastChar();
+                PDFFontNonBase14 nonBase14 = (PDFFontNonBase14)font;
+                nonBase14.setDescriptor(pdfdesc);
+
+                SingleByteFont singleByteFont;
+                if (metrics instanceof LazyFont) {
+                    singleByteFont = (SingleByteFont)((LazyFont)metrics).getRealFont();
+                } else {
+                    singleByteFont = (SingleByteFont)metrics;
                 }
-                font.setWidthMetrics(firstChar,
+                int firstChar = singleByteFont.getFirstChar();
+                int lastChar = singleByteFont.getLastChar();
+                nonBase14.setWidthMetrics(firstChar,
                                      lastChar,
                                      makeArray(metrics.getWidths()));
+                
+                //Handle encoding
+                CodePointMapping mapping = singleByteFont.getCodePointMapping();
+                if (PDFEncoding.isPredefinedEncoding(mapping.getName())) {
+                    font.setEncoding(mapping.getName());
+                } else {
+                    CodePointMapping winansi = CodePointMapping.getMapping(
+                            CodePointMapping.WIN_ANSI_ENCODING);
+                    PDFEncoding pdfEncoding = new PDFEncoding(winansi.getName());
+                    PDFEncoding.DifferencesBuilder builder
+                            = pdfEncoding.createDifferencesBuilder();
+                    int start = -1;
+                    for (int i = 0; i < 256; i++) {
+                        char wac = winansi.getUnicodeForIndex(i);
+                        char c = mapping.getUnicodeForIndex(i);
+                        if (wac != c) {
+                            if (start != i) {
+                                builder.addDifference(i);
+                                start = i;
+                            }
+                            builder.addName(Glyphs.charToGlyphName(c));
+                            start++;
+                        }
+                    }
+                    pdfEncoding.setDifferences(builder.toPDFArray());
+                    font.setEncoding(pdfEncoding);
+                    
+                    /* JM: What I thought would be a necessity with custom encodings turned out to
+                     * be a bug in Adobe Acrobat 8. The following section just demonstrates how
+                     * to generate a ToUnicode CMap for a Type 1 font. 
+                    PDFCMap cmap = new PDFToUnicodeCMap(mapping.getUnicodeCharMap(),
+                            "fop-ucs-H",
+                            new PDFCIDSystemInfo("Adobe", "Identity", 0));
+                    getDocument().registerObject(cmap);
+                    nonBase14.setToUnicode(cmap);
+                    */
+                }
             }
 
             return font;
@@ -1487,9 +1516,6 @@
      */
     public PDFICCStream makePDFICCStream() {
         PDFICCStream iccStream = new PDFICCStream();
-        iccStream.getFilterList().addDefaultFilters(
-                getDocument().getFilterMap(),
-                PDFFilterList.CONTENT_FILTER);
 
         getDocument().registerObject(iccStream);
         //getDocument().applyEncryption(iccStream);
@@ -1527,7 +1553,7 @@
      * @return the PDF Array with the int values
      */
     public PDFArray makeArray(int[] values) {
-        PDFArray array = new PDFArray(values);
+        PDFArray array = new PDFArray(null, values);
 
         getDocument().registerObject(array);
         return array;

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFilterList.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFilterList.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFilterList.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFilterList.java Thu Feb 14 13:55:44 2008
@@ -34,6 +34,8 @@
     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 precompressed content */
+    public static final String PRECOMPRESSED_FILTER = "precompressed";
     /** Key for the filter used for images */
     public static final String IMAGE_FILTER = "image";
     /** Key for the filter used for JPEG images */
@@ -178,6 +180,9 @@
             } else if (TIFF_FILTER.equals(type)) {
                 //CCITT-encoded images are already well compressed
                 addFilter(new NullFilter());
+            } else if (PRECOMPRESSED_FILTER.equals(type)) {
+                //precompressed content doesn't need further compression
+                addFilter(new NullFilter());
             } else {
                 // built-in default to flate
                 addFilter(new FlateFilter());
@@ -277,7 +282,7 @@
     }
 
     private void putFilterEntries(PDFDictionary dict, List names) {
-        PDFArray array = new PDFArray();
+        PDFArray array = new PDFArray(dict);
         for (int i = 0, c = names.size(); i < c; i++) {
             final String name = (String)names.get(i);
             if (name.length() > 0) {
@@ -323,7 +328,7 @@
 
     private void putDecodeParams(PDFDictionary dict, List parms) {
         boolean needParmsEntry = false;
-        PDFArray array = new PDFArray();
+        PDFArray array = new PDFArray(dict);
         for (int i = 0, c = parms.size(); i < c; i++) {
             Object obj = parms.get(i);
             if (obj != null) {

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFont.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFont.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFont.java Thu Feb 14 13:55:44 2008
@@ -30,38 +30,11 @@
  * <p>
  * Fonts are specified on page 198 and onwards of the PDF 1.3 spec.
  */
-public class PDFFont extends PDFObject {
-
-    /**
-     * the internal name for the font (eg "F1")
-     */
-    protected String fontname;
-
-    /**
-     * the font's subtype
-     * (as defined by the constants FontType: TYPE0, TYPE1, MMTYPE1, TYPE3, TRUETYPE)
-     */
-    protected FontType subtype;
-
-    /**
-     * the base font name (eg "Helvetica")
-     */
-    protected String basefont;
-
-    /**
-     * the character encoding scheme used by the font.
-     * It can be a String for standard encodings, or
-     * a PDFEncoding for a more complex scheme, or
-     * a PDFStream containing a CMap in a Type0 font.
-     * If <code>null</code> then not written out in the PDF.
-     */
-    protected Object encoding;
-
-    /**
-     * the Unicode mapping mechanism
-     */
-    // protected PDFToUnicode mapping;
+public class PDFFont extends PDFDictionary {
 
+    /** Internal F-number for each font (it is not written to the font dict) */
+    private String fontname;
+    
     /**
      * create the /Font object
      *
@@ -72,20 +45,46 @@
      */
     public PDFFont(String fontname, FontType subtype,
                    String basefont,
-                   Object encoding /* , PDFToUnicode mapping */) {
+                   Object encoding) {
 
         /* generic creation of PDF object */
         super();
 
-        /* set fields using paramaters */
         this.fontname = fontname;
-        this.subtype = subtype;
-        this.basefont = basefont;
-        this.encoding = encoding;
-        // this.mapping = mapping;
+        put("Type", new PDFName("Font"));
+        put("Subtype", getPDFNameForFontType(subtype));
+        //put("Name", new PDFName(fontname));
+        put("BaseFont", new PDFName(basefont));
+        if (encoding instanceof PDFEncoding) {
+            setEncoding((PDFEncoding)encoding);
+        } else if (encoding instanceof String) {
+            setEncoding((String)encoding);
+        } else {
+            throw new IllegalArgumentException("Illegal value for encoding");
+        }
     }
 
     /**
+     * Sets the Encoding value of the font.
+     * @param encoding the encoding
+     */
+    public void setEncoding(String encoding) {
+        if (encoding != null) {
+            put("Encoding", new PDFName(encoding));
+        }
+    }
+    
+    /**
+     * Sets the Encoding value of the font.
+     * @param encoding the encoding
+     */
+    public void setEncoding(PDFEncoding encoding) {
+        if (encoding != null) {
+            put("Encoding", encoding);
+        }
+    }
+    
+    /**
      * factory method with the basic parameters
      *
      * @param fontname the internal name for the font
@@ -111,80 +110,42 @@
             return new PDFFontTrueType(fontname, basefont,
                                        encoding);
         } else {
-            return null;    // should not happend
-        }
-    }
-
-    /**
-     * factory method with the extended parameters
-     * for Type1, MMType1 and TrueType
-     *
-     * @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 firstChar the first character code in the font
-     * @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(String fontname,
-                                     FontType subtype, String basefont,
-                                     Object encoding, int firstChar,
-                                     int lastChar, PDFArray widths,
-                                     PDFFontDescriptor descriptor) {
-
-        PDFFontNonBase14 font;
-        if (subtype == FontType.TYPE0) {
-            font = new PDFFontType0(fontname, basefont,
-                                    encoding);
-            font.setDescriptor(descriptor);
-            return font;
-        } else if ((subtype == FontType.TYPE1) 
-                || (subtype == FontType.MMTYPE1)) {
-            font = new PDFFontType1(fontname, basefont,
-                                    encoding);
-            font.setWidthMetrics(firstChar, lastChar, widths);
-            font.setDescriptor(descriptor);
-            return font;
-        } else if (subtype == FontType.TYPE3) {
-            return null; //NYI, should not happend
-        } else if (subtype == FontType.TRUETYPE) {
-            font = new PDFFontTrueType(fontname, basefont,
-                                       encoding);
-            font.setWidthMetrics(firstChar, lastChar, widths);
-            font.setDescriptor(descriptor);
-            return font;
-        } else {
-            return null;    // should not happend
+            return null;    // should not happen
         }
     }
 
     /**
-     * get the internal name used for this font
+     * Get the internal name used for this font.
      * @return the internal name
      */
     public String getName() {
         return this.fontname;
     }
+    
+    /**
+     * Returns the name of the BaseFont.
+     * @return the BaseFont
+     */
+    public PDFName getBaseFont() {
+        return (PDFName)get("BaseFont");
+    }
 
     /**
      * Returns the PDF name for a certain font type.
      * @param fontType font type
      * @return String corresponding PDF name
      */
-    protected String getPDFNameForFontType(FontType fontType) {
+    protected PDFName getPDFNameForFontType(FontType fontType) {
         if (fontType == FontType.TYPE0) {
-            return fontType.getName();
+            return new PDFName(fontType.getName());
         } else if (fontType == FontType.TYPE1) {
-            return fontType.getName();
+            return new PDFName(fontType.getName());
         } else if (fontType == FontType.MMTYPE1) {
-            return fontType.getName();
+            return new PDFName(fontType.getName());
         } else if (fontType == FontType.TYPE3) {
-            return fontType.getName();
+            return new PDFName(fontType.getName());
         } else if (fontType == FontType.TRUETYPE) {
-            return fontType.getName();
+            return new PDFName(fontType.getName());
         } else {
             throw new IllegalArgumentException("Unsupported font type: " + fontType.getName());
         }
@@ -198,46 +159,9 @@
             if (this.getClass() == PDFFont.class) {
                 throw new PDFConformanceException("For " + getDocumentSafely().getProfile() 
                     + ", all fonts, even the base 14"
-                    + " fonts, have to be embedded! Offending font: " + this.basefont);
+                    + " fonts, have to be embedded! Offending font: " + getBaseFont());
             }
         }
     }
     
-    /**
-     * {@inheritDoc}
-     */
-    public String toPDFString() {
-        validate();
-        StringBuffer p = new StringBuffer(128);
-        p.append(getObjectID());
-        p.append("<< /Type /Font\n/Subtype /"
-                 + getPDFNameForFontType(this.subtype)
-                 + "\n/Name /" + this.fontname
-                 + "\n/BaseFont /" + this.basefont);
-        if (encoding != null) {
-            p.append("\n/Encoding ");
-            if (encoding instanceof PDFEncoding) {
-                p.append(((PDFEncoding)this.encoding).referencePDF());
-            } else if (encoding instanceof PDFStream) {
-                p.append(((PDFStream)this.encoding).referencePDF());
-            } else {
-                p.append("/").append((String)encoding);
-            }
-        }
-        fillInPDF(p);
-        p.append(" >>\nendobj\n");
-        return p.toString();
-    }
-
-    /**
-     * 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 target the buffer to be completed with the type specific fields
-     */
-    protected void fillInPDF(StringBuffer target) {
-        //nop
-    }
-
 }

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontDescriptor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontDescriptor.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontDescriptor.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontDescriptor.java Thu Feb 14 13:55:44 2008
@@ -26,29 +26,7 @@
  * <p>
  * Font descriptors are specified on page 222 and onwards of the PDF 1.3 spec.
  */
-public class PDFFontDescriptor extends PDFObject {
-
-    // Required fields
-    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
-    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 AbstractPDFStream fontfile;
-    private AbstractPDFStream cidSet;
-    // private String charSet = null;
-
-    private FontType subtype;
+public class PDFFontDescriptor extends PDFDictionary {
 
     /**
      * Create the /FontDescriptor object
@@ -66,19 +44,17 @@
                              int descent, int capHeight, int flags,
                              PDFRectangle fontBBox, int italicAngle,
                              int stemV) {
-
-        /* generic creation of PDF object */
         super();
 
-        /* set fields using paramaters */
-        this.basefont = basefont;
-        this.ascent = ascent;
-        this.descent = descent;
-        this.capHeight = capHeight;
-        this.flags = flags;
-        this.fontBBox = fontBBox;
-        this.italicAngle = italicAngle;
-        this.stemV = stemV;
+        put("Type", new PDFName("FontDescriptor"));
+        put("FontName", new PDFName(basefont));
+        put("FontBBox", fontBBox);
+        put("Flags", flags);
+        put("CapHeight", capHeight);
+        put("Ascent", ascent);
+        put("Descent", descent);
+        put("ItalicAngle", italicAngle);
+        put("StemV", stemV);
     }
 
     /**
@@ -97,12 +73,24 @@
      */
     public void setMetrics(int avgWidth, int maxWidth, int missingWidth,
                            int leading, int stemH, int xHeight) {
-        this.avgWidth = avgWidth;
-        this.maxWidth = maxWidth;
-        this.missingWidth = missingWidth;
-        this.leading = leading;
-        this.stemH = stemH;
-        this.xHeight = xHeight;
+        if (avgWidth != 0) {
+            put("AvgWidth", avgWidth);
+        }
+        if (maxWidth != 0) {
+            put("MaxWidth", maxWidth);
+        }
+        if (missingWidth != 0) {
+            put("MissingWidth", missingWidth);
+        }
+        if (leading != 0) {
+            put("Leading", leading);
+        }
+        if (stemH != 0) {
+            put("StemH", stemH);
+        }
+        if (xHeight != 0) {
+            put("XHeight", xHeight);
+        }
     }
 
     /**
@@ -112,13 +100,24 @@
      * @param fontfile the stream containing an embedded font
      */
     public void setFontFile(FontType subtype, AbstractPDFStream fontfile) {
-        this.subtype = subtype;
-        this.fontfile = fontfile;
+        if (subtype == FontType.TYPE1) {
+            put("FontFile", fontfile);
+        } else {
+            put("FontFile2", fontfile);
+        }
     }
 
     /** @return the FontFile or null if the font is not embedded */
     public AbstractPDFStream getFontFile() {
-        return this.fontfile;
+        AbstractPDFStream stream;
+        stream = (AbstractPDFStream)get("FontFile");
+        if (stream == null) {
+            stream = (AbstractPDFStream)get("FontFile2");
+        }
+        if (stream == null) {
+            stream = (AbstractPDFStream)get("FontFile3");
+        }
+        return stream;
     }
     
     /**
@@ -126,19 +125,18 @@
      * @param cidSet the CIDSet stream
      */
     public void setCIDSet(AbstractPDFStream cidSet) {
-        this.cidSet = cidSet;
+        put("CIDSet", cidSet);
     }
     
     /** @return the CIDSet stream or null if not applicable */
     public AbstractPDFStream getCIDSet() {
-        return this.cidSet;
+        return (AbstractPDFStream)get("CIDSet");
     }
     
-    // public void setCharSet(){}//for subset fonts
-
     /**
      * {@inheritDoc}
      */
+    /*
     public String toPDFString() {
         StringBuffer p = new StringBuffer(128);
         p.append(getObjectID() 
@@ -201,7 +199,7 @@
         fillInPDF(p);
         p.append(" >>\nendobj\n");
         return p.toString();
-    }
+    }*/
 
     /**
      * Fill in the specifics for the font's descriptor.
@@ -209,9 +207,9 @@
      * 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) {
         //nop
-    }
+    }*/
 
 }

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontNonBase14.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontNonBase14.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontNonBase14.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontNonBase14.java Thu Feb 14 13:55:44 2008
@@ -28,26 +28,6 @@
 public abstract class PDFFontNonBase14 extends PDFFont {
 
     /**
-     * first character code in the font
-     */
-    protected int firstChar;
-
-    /**
-     * last character code in the font
-     */
-    protected int lastChar;
-
-    /**
-     * widths of characters from firstChar to lastChar
-     */
-    protected PDFArray widths;
-
-    /**
-     * descriptor of font metrics
-     */
-    protected PDFFontDescriptor descriptor;
-
-    /**
      * Create the /Font object
      *
      * @param fontname the internal name for the font
@@ -61,8 +41,6 @@
 
         /* generic creation of PDF object */
         super(fontname, subtype, basefont, encoding);
-
-        this.descriptor = null;
     }
 
     /**
@@ -74,10 +52,9 @@
      */
     public void setWidthMetrics(int firstChar, int lastChar,
                                 PDFArray widths) {
-        /* set fields using paramaters */
-        this.firstChar = firstChar;
-        this.lastChar = lastChar;
-        this.widths = widths;
+        put("FirstChar", new Integer(firstChar));
+        put("LastChar", new Integer(lastChar));
+        put("Widths", widths);
     }
 
     /**
@@ -86,12 +63,20 @@
      * @param descriptor the descriptor for other font's metrics
      */
     public void setDescriptor(PDFFontDescriptor descriptor) {
-        this.descriptor = descriptor;
+        put("FontDescriptor", descriptor);
     }
 
     /** @return the FontDescriptor or null if there is none */
     public PDFFontDescriptor getDescriptor() {
-        return this.descriptor;
+        return (PDFFontDescriptor)get("FontDescriptor");
+    }
+    
+    /**
+     * Sets a ToUnicode CMap.
+     * @param cmap the ToUnicode character map
+     */
+    public void setToUnicode(PDFCMap cmap) {
+        put("ToUnicode", cmap);
     }
     
     /** {@inheritDoc} */
@@ -104,20 +89,4 @@
         }
     }
     
-    /**
-     * {@inheritDoc}
-     */
-    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) {
-            target.append("\n/FontDescriptor ");
-            target.append(this.descriptor.referencePDF());
-        }
-    }
-
 }

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontTrueType.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontTrueType.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontTrueType.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontTrueType.java Thu Feb 14 13:55:44 2008
@@ -39,9 +39,7 @@
     public PDFFontTrueType(String fontname, 
                            String basefont,
                            Object encoding) {
-
-        /* generic creation of PDF object */
-        super(fontname, FontType.TRUETYPE, basefont, encoding /* , mapping */);
+        super(fontname, FontType.TRUETYPE, basefont, encoding);
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontType0.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontType0.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontType0.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontType0.java Thu Feb 14 13:55:44 2008
@@ -26,17 +26,7 @@
  * <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
-     */
-    protected PDFCIDFont descendantFonts;
-
-    /**
-     * The character map
-     */
-    protected PDFCMap cmap;
+public class PDFFontType0 extends PDFFont {
 
     /**
      * Create the /Font object
@@ -48,13 +38,7 @@
     public PDFFontType0(String fontname, 
                         String basefont,
                         Object encoding) {
-
-        /* generic creation of PDF object */
-        super(fontname, FontType.TYPE0, basefont, encoding /* , mapping */);
-
-        /* set fields using paramaters */
-        this.descendantFonts = null;
-        cmap = null;
+        super(fontname, FontType.TYPE0, basefont, encoding);
     }
 
     /**
@@ -69,12 +53,9 @@
                         String basefont,
                         Object encoding, 
                         PDFCIDFont descendantFonts) {
+        super(fontname, FontType.TYPE0, basefont, encoding);
 
-        /* generic creation of PDF object */
-        super(fontname, FontType.TYPE0, basefont, encoding /* , mapping */);
-
-        /* set fields using paramaters */
-        this.descendantFonts = descendantFonts;
+        setDescendantFonts(descendantFonts);
     }
 
     /**
@@ -82,7 +63,7 @@
      * @param descendantFonts the CIDFont upon which this font is based
      */
     public void setDescendantFonts(PDFCIDFont descendantFonts) {
-        this.descendantFonts = descendantFonts;
+        put("DescendantFonts", new PDFArray(this, new PDFObject[] {descendantFonts}));
     }
 
     /**
@@ -90,20 +71,7 @@
      * @param cmap the character map
      */
     public void setCMAP(PDFCMap cmap) {
-        this.cmap = cmap;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    protected void fillInPDF(StringBuffer target) {
-        if (descendantFonts != null) {
-            target.append("\n/DescendantFonts [ "
-                     + this.descendantFonts.referencePDF() + " ] ");
-        }
-        if (cmap != null) {
-            target.append("\n/ToUnicode " + cmap.referencePDF());
-        }
+        put("ToUnicode", cmap);
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontType3.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontType3.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontType3.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFontType3.java Thu Feb 14 13:55:44 2008
@@ -32,26 +32,6 @@
 public class PDFFontType3 extends PDFFontNonBase14 {
 
     /**
-     * font's required /FontBBox bounding box
-     */
-    protected PDFRectangle fontBBox;
-
-    /**
-     * font's required /FontMatrix array
-     */
-    protected PDFArray fontMatrix;
-
-    /**
-     * font's required /CharProcs dictionary
-     */
-    protected PDFCharProcs charProcs;
-
-    /**
-     * font's optional /Resources object
-     */
-    protected PDFResources resources;
-
-    /**
      * Create the /Font object
      *
      * @param fontname the internal name for the font
@@ -61,13 +41,7 @@
     public PDFFontType3(String fontname, 
                         String basefont,
                         Object encoding) {
-
-        /* generic creation of PDF object */
-        super(fontname, FontType.TYPE3, basefont, encoding /* , mapping */);
-
-        this.fontBBox = null;
-        this.fontMatrix = null;
-        this.charProcs = null;
+        super(fontname, FontType.TYPE3, basefont, encoding);
     }
 
     /**
@@ -89,9 +63,9 @@
         /* generic creation of PDF object */
         super(fontname, FontType.TYPE3, basefont, encoding /* , mapping */);
 
-        this.fontBBox = fontBBox;
-        this.fontMatrix = fontMatrix;
-        this.charProcs = charProcs;
+        setFontBBox(fontBBox);
+        setFontMatrix(fontMatrix);
+        setCharProcs(charProcs);
     }
 
     /**
@@ -100,7 +74,7 @@
      * @param bbox bounding box for the font
      */
     public void setFontBBox(PDFRectangle bbox) {
-        this.fontBBox = bbox;
+        put("FontBBox", bbox);
     }
 
     /**
@@ -109,7 +83,7 @@
      * @param matrix the transformation matrix for the font
      */
     public void setFontMatrix(PDFArray matrix) {
-        this.fontMatrix = matrix;
+        put("FontMatrix", matrix);
     }
 
     /**
@@ -120,25 +94,7 @@
      * @param chars the glyphs' dictionary
      */
     public void setCharProcs(PDFCharProcs chars) {
-        this.charProcs = chars;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    protected void fillInPDF(StringBuffer target) {
-        if (fontBBox != null) {
-            target.append("\n/FontBBox ");
-            target.append(fontBBox.toPDF());
-        }
-        if (fontMatrix != null) {
-            target.append("\n/FontMatrix ");
-            target.append(fontMatrix.toPDF());
-        }
-        if (charProcs != null) {
-            target.append("\n/CharProcs ");
-            target.append(charProcs.referencePDF());
-        }
+        put("CharProcs", chars);
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFormXObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFormXObject.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFormXObject.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFFormXObject.java Thu Feb 14 13:55:44 2008
@@ -63,7 +63,7 @@
     public void setBBox(Rectangle2D bbox) {
         PDFArray array = (PDFArray)get("BBox");
         if (array == null) {
-            array = new PDFArray();
+            array = new PDFArray(this);
             array.add(bbox.getX());
             array.add(bbox.getY());
             array.add(bbox.getWidth());
@@ -105,7 +105,7 @@
         double[] m = new double[6];
         at.getMatrix(m);
         if (array == null) {
-            array = new PDFArray();
+            array = new PDFArray(this);
             array.add(m[0]);
             array.add(m[1]);
             array.add(m[2]);
@@ -170,7 +170,7 @@
     /** {@inheritDoc} */
     protected void populateStreamDict(Object lengthEntry) {
         if (get("Matrix") == null) {
-            put("Matrix", new PDFArray(new int[] {1, 0, 0, 1, 0, 0}));
+            put("Matrix", new PDFArray(this, new int[] {1, 0, 0, 1, 0, 0}));
         }
         put("Resources", resRef);
         super.populateStreamDict(lengthEntry);

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java Thu Feb 14 13:55:44 2008
@@ -19,6 +19,13 @@
 
 package org.apache.fop.pdf;
 
+import java.awt.color.ColorSpace;
+import java.awt.color.ICC_Profile;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.IOUtils;
+
 /**
  * Represents an ICCBased color space in PDF.
  */
@@ -93,4 +100,56 @@
         return sb.toString();
     }
 
+    /**
+     * Sets sRGB as the DefaultRGB color space in the PDF document.
+     * @param pdfDoc the PDF document
+     * @return the newly installed color space object
+     */
+    public static PDFICCBasedColorSpace setupsRGBAsDefaultRGBColorSpace(PDFDocument pdfDoc) {
+        PDFICCStream sRGBProfile = setupsRGBColorProfile(pdfDoc);
+
+        //Map sRGB as default RGB profile for DeviceRGB
+        return pdfDoc.getFactory().makeICCBasedColorSpace(null, "DefaultRGB", sRGBProfile);
+    }
+
+    /**
+     * Installs the sRGB color space in the PDF document.
+     * @param pdfDoc the PDF document
+     * @return the newly installed color space object
+     */
+    public static PDFICCBasedColorSpace setupsRGBColorSpace(PDFDocument pdfDoc) {
+        PDFICCStream sRGBProfile = setupsRGBColorProfile(pdfDoc);
+
+        //Map sRGB as default RGB profile for DeviceRGB
+        return pdfDoc.getFactory().makeICCBasedColorSpace(null, null, sRGBProfile);
+    }
+
+    /**
+     * Sets up the sRGB color profile in the PDF document. It does so by trying to
+     * install a very small ICC profile (~4KB) instead of the very big one (~140KB)
+     * the Sun JVM uses.
+     * @param pdfDoc the PDF document
+     * @return the ICC stream with the sRGB profile
+     */
+    public static PDFICCStream setupsRGBColorProfile(PDFDocument pdfDoc) {
+        ICC_Profile profile;
+        PDFICCStream sRGBProfile = pdfDoc.getFactory().makePDFICCStream();
+        InputStream in = PDFDocument.class.getResourceAsStream("sRGB Color Space Profile.icm");
+        if (in != null) {
+            try {
+                profile = ICC_Profile.getInstance(in);
+            } catch (IOException ioe) {
+                throw new RuntimeException(
+                        "Unexpected IOException loading the sRGB profile: " + ioe.getMessage());
+            } finally {
+                IOUtils.closeQuietly(in);
+            }
+        } else {
+            // Fallback: Use the sRGB profile from the JRE (about 140KB)
+            profile = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
+        }
+        sRGBProfile.setColorSpace(profile, null);
+        return sRGBProfile;
+    }
+    
 }

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFICCStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFICCStream.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFICCStream.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFICCStream.java Thu Feb 14 13:55:44 2008
@@ -66,9 +66,7 @@
         return length;
     }
     
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     protected void outputRawStreamData(OutputStream out) throws IOException {
         cp.write(out);
     }

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFImage.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFImage.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFImage.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFImage.java Thu Feb 14 13:55:44 2008
@@ -69,11 +69,11 @@
     PDFDeviceColorSpace getColorSpace();
 
     /**
-     * Get the bits per pixel for this image.
+     * Get the bits per color component for this image.
      *
-     * @return the bits per pixel
+     * @return the bits per component
      */
-    int getBitsPerPixel();
+    int getBitsPerComponent();
 
     /**
      * Check if this image is a PostScript image.
@@ -105,11 +105,8 @@
 
     /**
      * Get the PDF reference for a soft mask.
-     *
-     * @return the PDF reference for a soft mask image
+     * @return the PDF reference for a soft mask image (or null if there's no soft mask)
      */
-    String getSoftMask();
-    
     PDFReference getSoftMaskReference();
 
     /** @return true for CMYK images generated by Adobe Photoshop */
@@ -132,6 +129,14 @@
      */
     void outputContents(OutputStream out) throws IOException;
 
+    /**
+     * Populates the XObject's dictionary with additional values. The values are added to the
+     * dictionary after all the values obtained from other methods from this interface have
+     * been put into the dictionary. That allows to override certain values. 
+     * @param dict the dictionary to fill
+     */
+    void populateXObjectDictionary(PDFDictionary dict);
+    
     /**
      * Get the ICC stream for this image.
      *

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFImageXObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFImageXObject.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFImageXObject.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFImageXObject.java Thu Feb 14 13:55:44 2008
@@ -90,11 +90,12 @@
         put("Subtype", new PDFName("Image"));
         put("Width", new Integer(pdfimage.getWidth()));
         put("Height", new Integer(pdfimage.getHeight()));
-        put("BitsPerComponent", new Integer(pdfimage.getBitsPerPixel()));
+        put("BitsPerComponent", new Integer(pdfimage.getBitsPerComponent()));
 
         PDFICCStream pdfICCStream = pdfimage.getICCStream();
         if (pdfICCStream != null) {
-            put("ColorSpace", new PDFArray(new Object[] {new PDFName("ICCBased"), pdfICCStream}));
+            put("ColorSpace", new PDFArray(this,
+                    new Object[] {new PDFName("ICCBased"), pdfICCStream}));
         } else {
             PDFDeviceColorSpace cs = pdfimage.getColorSpace();
             put("ColorSpace", new PDFName(cs.getName()));
@@ -107,7 +108,7 @@
              */
             final Float zero = new Float(0.0f);
             final Float one = new Float(1.0f);
-            PDFArray decode = new PDFArray();
+            PDFArray decode = new PDFArray(this);
             for (int i = 0, c = pdfimage.getColorSpace().getNumComponents(); i < c; i++) {
                 decode.add(one);
                 decode.add(zero);
@@ -117,19 +118,26 @@
 
         if (pdfimage.isTransparent()) {
             PDFColor transp = pdfimage.getTransparentColor();
-            PDFArray mask = new PDFArray();
-            mask.add(new Integer(transp.red255()));
-            mask.add(new Integer(transp.red255()));
-            mask.add(new Integer(transp.green255()));
-            mask.add(new Integer(transp.green255()));
-            mask.add(new Integer(transp.blue255()));
-            mask.add(new Integer(transp.blue255()));
+            PDFArray mask = new PDFArray(this);
+            if (pdfimage.getColorSpace().isGrayColorSpace()) {
+                mask.add(new Integer(transp.red255()));
+                mask.add(new Integer(transp.red255()));
+            } else {
+                mask.add(new Integer(transp.red255()));
+                mask.add(new Integer(transp.red255()));
+                mask.add(new Integer(transp.green255()));
+                mask.add(new Integer(transp.green255()));
+                mask.add(new Integer(transp.blue255()));
+                mask.add(new Integer(transp.blue255()));
+            }
             put("Mask", mask);
         }
         PDFReference ref = pdfimage.getSoftMaskReference();
         if (ref != null) {
             put("SMask", ref);
         }
+        //Important: do this at the end so previous values can be overwritten.
+        pdfimage.populateXObjectDictionary(this);
     }
     
     /** {@inheritDoc} */

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFMetadata.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFMetadata.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFMetadata.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFMetadata.java Thu Feb 14 13:55:44 2008
@@ -25,6 +25,8 @@
 
 import javax.xml.transform.TransformerConfigurationException;
 
+import org.xml.sax.SAXException;
+
 import org.apache.xmlgraphics.xmp.Metadata;
 import org.apache.xmlgraphics.xmp.XMPSerializer;
 import org.apache.xmlgraphics.xmp.schemas.DublinCoreAdapter;
@@ -36,8 +38,6 @@
 import org.apache.xmlgraphics.xmp.schemas.pdf.PDFAAdapter;
 import org.apache.xmlgraphics.xmp.schemas.pdf.PDFAXMPSchema;
 
-import org.xml.sax.SAXException;
-
 /**
  * Special PDFStream for Metadata.
  * @since PDF 1.4
@@ -118,10 +118,11 @@
      * @param pdfDoc the PDF Document
      * @return the requested XMP metadata
      */
-    public static Metadata createXMPFromUserAgent(PDFDocument pdfDoc) {
+    public static Metadata createXMPFromPDFDocument(PDFDocument pdfDoc) {
         Metadata meta = new Metadata();
         
         PDFInfo info = pdfDoc.getInfo();
+        PDFRoot root = pdfDoc.getRoot();
 
         //Set creation date if not available, yet
         if (info.getCreationDate() == null) {
@@ -144,6 +145,10 @@
         if (info.getSubject() != null) {
             //Subject maps to dc:description["x-default"] as per ISO-19005-1:2005/Cor.1:2007
             dc.setDescription(null, info.getSubject());
+        }
+        if (root.getLanguage() != null) {
+            //Note: No check is performed to make sure the value is valid RFC 3066!
+            dc.addLanguage(root.getLanguage());
         }
         dc.addDate(info.getCreationDate());
 

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFMetadata.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFName.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFName.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFName.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFName.java Thu Feb 14 13:55:44 2008
@@ -19,10 +19,16 @@
  
 package org.apache.fop.pdf;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+
+import org.apache.commons.io.output.CountingOutputStream;
+
 /**
  * Class representing a PDF name object.
  */
-public class PDFName implements PDFWritable {
+public class PDFName extends PDFObject {
     
     private String name;
     
@@ -31,6 +37,7 @@
      * @param name the name value
      */
     public PDFName(String name) {
+        super();
         this.name = escapeName(name);
     }
 
@@ -65,15 +72,36 @@
         sb.append(DIGITS[ch & 0x0F]);
     }
     
-    
     /** {@inheritDoc} */
-    public String toInlinePDFString() {
+    public String toString() {
         return this.name;
     }
+
+    /** {@inheritDoc} */
+    protected int output(OutputStream stream) throws IOException {
+        CountingOutputStream cout = new CountingOutputStream(stream);
+        Writer writer = PDFDocument.getWriterFor(cout);
+        if (hasObjectNumber()) {
+            writer.write(getObjectID());
+        }
+
+        writer.write(toString());
+        
+        if (hasObjectNumber()) {
+            writer.write("\nendobj\n");
+        }
+        
+        writer.flush();
+        return cout.getCount();
+    }
     
     /** {@inheritDoc} */
-    public String toString() {
-        return toInlinePDFString();
+    public void outputInline(OutputStream out, Writer writer) throws IOException {
+        if (hasObjectNumber()) {
+            writer.write(referencePDF());
+        } else {
+            writer.write(toString());
+        }
     }
     
 }

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFName.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFNameTreeNode.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFNameTreeNode.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFNameTreeNode.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFNameTreeNode.java Thu Feb 14 13:55:44 2008
@@ -108,7 +108,7 @@
     private PDFArray prepareLimitsArray() {
         PDFArray limits = (PDFArray)get(LIMITS);
         if (limits == null) {
-            limits = new PDFArray(new Object[2]);
+            limits = new PDFArray(this, new Object[2]);
             put(LIMITS, limits);
         }
         if (limits.length() != 2) {

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFNameTreeNode.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFNull.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFNull.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFNull.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/pdf/PDFNull.java Thu Feb 14 13:55:44 2008
@@ -19,6 +19,10 @@
  
 package org.apache.fop.pdf;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+
 /**
  * Class representing a PDF name object.
  */
@@ -35,13 +39,13 @@
     }
 
     /** {@inheritDoc} */
-    public String toInlinePDFString() {
+    public String toString() {
         return "null";
     }
     
     /** {@inheritDoc} */
-    public String toString() {
-        return toInlinePDFString();
+    public void outputInline(OutputStream out, Writer writer) throws IOException {
+        writer.write(toString());
     }
     
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org