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 vh...@apache.org on 2012/04/05 18:20:17 UTC

svn commit: r1309921 [28/42] - in /xmlgraphics/fop/branches/Temp_TrueTypeInPostScript: ./ examples/embedding/ examples/embedding/java/embedding/ examples/embedding/java/embedding/atxml/ examples/embedding/java/embedding/tools/ examples/plan/src/org/apa...

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFFormXObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFFormXObject.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFFormXObject.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFFormXObject.java Thu Apr  5 16:19:19 2012
@@ -44,7 +44,7 @@ public class PDFFormXObject extends PDFX
      * @param resources the resource PDF reference
      */
     public PDFFormXObject(int xnumber, PDFStream contents, PDFReference resources) {
-        super();
+        super(contents.getDictionary());
         put("Name", new PDFName("Form" + xnumber));
         this.contents = contents;
 
@@ -160,7 +160,7 @@ public class PDFFormXObject extends PDFX
     }
 
     /** {@inheritDoc} */
-    protected int output(OutputStream stream) throws IOException {
+    public int output(OutputStream stream) throws IOException {
         final int len = super.output(stream);
 
         //Now that the data has been written, it can be discarded.

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFFunction.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFFunction.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFFunction.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFFunction.java Thu Apr  5 16:19:19 2012
@@ -380,8 +380,7 @@ public class PDFFunction extends PDFObje
         int numberOfFunctions = 0;
         int tempInt = 0;
         StringBuffer p = new StringBuffer(256);
-        p.append(getObjectID()
-                + "<< \n/FunctionType " + this.functionType + " \n");
+        p.append("<< \n/FunctionType " + this.functionType + " \n");
 
         // FunctionType 0
         if (this.functionType == 0) {
@@ -482,15 +481,14 @@ public class PDFFunction extends PDFObje
                     p.append("] \n");
                 }
             }
-            p.append(">> \n");
+            p.append(">>");
 
             // stream representing the function
             if (this.functionDataStream != null) {
-                p.append("stream\n" + this.functionDataStream
-                         + "\nendstream\n");
+                p.append("\nstream\n" + this.functionDataStream
+                         + "\nendstream");
             }
 
-            p.append("endobj\n");
             // end of if FunctionType 0
 
         } else if (this.functionType == 2) {
@@ -550,7 +548,7 @@ public class PDFFunction extends PDFObje
                      + PDFNumber.doubleOut(new Double(this.interpolationExponentN))
                      + " \n");
 
-            p.append(">> \nendobj\n");
+            p.append(">>");
 
         } else if (this.functionType
                    == 3) {                       // fix this up when my eyes uncross
@@ -643,10 +641,7 @@ public class PDFFunction extends PDFObje
                 }
 
             }
-            p.append("] \n");
-
-
-            p.append(">> \nendobj\n");
+            p.append("]\n>>");
         } else if (this.functionType
                    == 4) {                       // fix this up when my eyes uncross
             // DOMAIN
@@ -681,15 +676,14 @@ public class PDFFunction extends PDFObje
                          + " \n");
             }
 
-            p.append(">> \n");
+            p.append(">>");
 
             // stream representing the function
             if (this.functionDataStream != null) {
-                p.append("stream\n{ " + this.functionDataStream
-                         + " } \nendstream\n");
+                p.append("\nstream\n{ " + this.functionDataStream
+                         + " }\nendstream");
             }
 
-            p.append("endobj\n");
 
         }
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFGState.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFGState.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFGState.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFGState.java Thu Apr  5 16:19:19 2012
@@ -19,8 +19,8 @@
 
 package org.apache.fop.pdf;
 
-import java.util.Map;
 import java.util.Iterator;
+import java.util.Map;
 
 /**
  * Class representing a /ExtGState object.
@@ -149,12 +149,10 @@ public class PDFGState extends PDFObject
      */
     public String toPDFString() {
         StringBuffer sb = new StringBuffer(64);
-        sb.append(getObjectID());
         sb.append("<<\n/Type /ExtGState\n");
         appendVal(sb, GSTATE_ALPHA_NONSTROKE);
         appendVal(sb, GSTATE_ALPHA_STROKE);
-
-        sb.append(">>\nendobj\n");
+        sb.append(">>");
         return sb.toString();
     }
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFGoTo.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFGoTo.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFGoTo.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFGoTo.java Thu Apr  5 16:19:19 2012
@@ -124,9 +124,7 @@ public class PDFGoTo extends PDFAction {
         } else {
             dest = "/D [" + this.pageReference + " " + destination + "]\n";
         }
-        return getObjectID()
-                    + "<< /Type /Action\n/S /GoTo\n" + dest
-                    + ">>\nendobj\n";
+        return "<< /Type /Action\n/S /GoTo\n" + dest + ">>";
     }
 
     /*

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFGoToRemote.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFGoToRemote.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFGoToRemote.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFGoToRemote.java Thu Apr  5 16:19:19 2012
@@ -106,7 +106,6 @@ public class PDFGoToRemote extends PDFAc
      */
     public String toPDFString() {
         StringBuffer sb = new StringBuffer(64);
-        sb.append(getObjectID());
         sb.append("<<\n/S /GoToR\n/F ");
         sb.append(pdfFileSpec.toString());
         sb.append("\n");
@@ -121,7 +120,7 @@ public class PDFGoToRemote extends PDFAc
             sb.append("/NewWindow true");
         }
 
-        sb.append(" \n>>\nendobj\n");
+        sb.append("\n>>");
 
         return sb.toString();
     }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java Thu Apr  5 16:19:19 2012
@@ -26,6 +26,8 @@ import java.io.InputStream;
 
 import org.apache.commons.io.IOUtils;
 
+import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
+
 /**
  * Represents an ICCBased color space in PDF.
  */
@@ -33,6 +35,7 @@ public class PDFICCBasedColorSpace exten
 
     private PDFICCStream iccStream;
     private String explicitName;
+    private int numComponents;
 
     /**
      * Constructs a the ICCBased color space with an explicit name (ex. "DefaultRGB").
@@ -42,6 +45,7 @@ public class PDFICCBasedColorSpace exten
     public PDFICCBasedColorSpace(String explicitName, PDFICCStream iccStream) {
         this.explicitName = explicitName;
         this.iccStream = iccStream;
+        this.numComponents = iccStream.getICCProfile().getNumComponents();
     }
 
     /**
@@ -59,7 +63,7 @@ public class PDFICCBasedColorSpace exten
 
     /** {@inheritDoc} */
     public int getNumComponents() {
-        return iccStream.getICCProfile().getNumComponents();
+        return this.numComponents;
     }
 
     /** {@inheritDoc} */
@@ -92,11 +96,10 @@ public class PDFICCBasedColorSpace exten
     }
 
     /** {@inheritDoc} */
+    @Override
     protected String toPDFString() {
         StringBuffer sb = new StringBuffer(64);
-        sb.append(getObjectID());
         sb.append("[/ICCBased ").append(getICCStream().referencePDF()).append("]");
-        sb.append("\nendobj\n");
         return sb.toString();
     }
 
@@ -134,21 +137,19 @@ public class PDFICCBasedColorSpace exten
     public static PDFICCStream setupsRGBColorProfile(PDFDocument pdfDoc) {
         ICC_Profile profile;
         PDFICCStream sRGBProfile = pdfDoc.getFactory().makePDFICCStream();
-        synchronized (PDFICCBasedColorSpace.class) {
-            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);
+        InputStream in = PDFDocument.class.getResourceAsStream("sRGB Color Space Profile.icm");
+        if (in != null) {
+            try {
+                profile = ColorProfileUtil.getICC_Profile(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 = ColorProfileUtil.getICC_Profile(ColorSpace.CS_sRGB);
         }
         sRGBProfile.setColorSpace(profile, null);
         return sRGBProfile;

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFICCStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFICCStream.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFICCStream.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFICCStream.java Thu Apr  5 16:19:19 2012
@@ -49,7 +49,11 @@ public class PDFICCStream extends PDFStr
         pdfColorSpace = alt;
     }
 
-    /** @return the ICC profile */
+    /**
+     * Returns the associated ICC profile. Note that this will return null once the
+     * ICC stream has been written to the PDF file.
+     * @return the ICC profile (or null if the stream has already been written)
+     */
     public ICC_Profile getICCProfile() {
         return this.cp;
     }
@@ -59,7 +63,8 @@ public class PDFICCStream extends PDFStr
      * byte arrays around so much
      * {@inheritDoc}
      */
-    protected int output(java.io.OutputStream stream)
+    @Override
+    public int output(java.io.OutputStream stream)
                 throws java.io.IOException {
         int length = super.output(stream);
         this.cp = null; //Free ICC stream when it's not used anymore
@@ -67,11 +72,13 @@ public class PDFICCStream extends PDFStr
     }
 
     /** {@inheritDoc} */
+    @Override
     protected void outputRawStreamData(OutputStream out) throws IOException {
         cp.write(out);
     }
 
     /** {@inheritDoc} */
+    @Override
     protected void populateStreamDict(Object lengthEntry) {
         put("N", cp.getNumComponents());
         if (pdfColorSpace != null) {

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFImageXObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFImageXObject.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFImageXObject.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFImageXObject.java Thu Apr  5 16:19:19 2012
@@ -61,7 +61,7 @@ public class PDFImageXObject extends PDF
      * @throws IOException if there is an error writing the data
      * @return the length of the data written
      */
-    protected int output(OutputStream stream) throws IOException {
+    public int output(OutputStream stream) throws IOException {
         int length = super.output(stream);
 
         // let it gc
@@ -137,7 +137,7 @@ public class PDFImageXObject extends PDF
             put("SMask", ref);
         }
         //Important: do this at the end so previous values can be overwritten.
-        pdfimage.populateXObjectDictionary(this);
+        pdfimage.populateXObjectDictionary(getDictionary());
     }
 
     /** {@inheritDoc} */

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFInfo.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFInfo.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFInfo.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFInfo.java Thu Apr  5 16:19:19 2012
@@ -19,9 +19,13 @@
 
 package org.apache.fop.pdf;
 
-import java.util.Date;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
 
 /**
  * class representing an /Info object
@@ -165,7 +169,6 @@ public class PDFInfo extends PDFObject {
         PDFProfile profile = getDocumentSafely().getProfile();
         ByteArrayOutputStream bout = new ByteArrayOutputStream(128);
         try {
-            bout.write(encode(getObjectID()));
             bout.write(encode("<<\n"));
             if (title != null && title.length() > 0) {
                 bout.write(encode("/Title "));
@@ -225,12 +228,74 @@ public class PDFInfo extends PDFObject {
                 bout.write(encode("/Trapped /False\n"));
             }
 
-            bout.write(encode(">>\nendobj\n"));
+            bout.write(encode(">>"));
         } catch (IOException ioe) {
             log.error("Ignored I/O exception", ioe);
         }
         return bout.toByteArray();
     }
 
+    /**
+     * Returns a SimpleDateFormat instance for formatting PDF date-times.
+     * @return a new SimpleDateFormat instance
+     */
+    protected static SimpleDateFormat getPDFDateFormat() {
+        SimpleDateFormat df = new SimpleDateFormat("'D:'yyyyMMddHHmmss", Locale.ENGLISH);
+        df.setTimeZone(TimeZone.getTimeZone("GMT"));
+        return df;
+    }
+
+    /**
+     * Formats a date/time according to the PDF specification (D:YYYYMMDDHHmmSSOHH'mm').
+     * @param time date/time value to format
+     * @param tz the time zone
+     * @return the requested String representation
+     */
+    protected static String formatDateTime(Date time, TimeZone tz) {
+        Calendar cal = Calendar.getInstance(tz, Locale.ENGLISH);
+        cal.setTime(time);
+
+        int offset = cal.get(Calendar.ZONE_OFFSET);
+        offset += cal.get(Calendar.DST_OFFSET);
+
+        // DateFormat is operating on GMT so adjust for time zone offset
+        Date dt1 = new Date(time.getTime() + offset);
+        StringBuffer sb = new StringBuffer();
+        sb.append(getPDFDateFormat().format(dt1));
+
+        offset /= (1000 * 60); // Convert to minutes
+
+        if (offset == 0) {
+            sb.append('Z');
+        } else {
+            if (offset > 0) {
+                sb.append('+');
+            } else {
+                sb.append('-');
+            }
+            int offsetHour = Math.abs(offset / 60);
+            int offsetMinutes = Math.abs(offset % 60);
+            if (offsetHour < 10) {
+                sb.append('0');
+            }
+            sb.append(Integer.toString(offsetHour));
+            sb.append('\'');
+            if (offsetMinutes < 10) {
+                sb.append('0');
+            }
+            sb.append(Integer.toString(offsetMinutes));
+            sb.append('\'');
+        }
+        return sb.toString();
+    }
+
+    /**
+     * Formats a date/time according to the PDF specification. (D:YYYYMMDDHHmmSSOHH'mm').
+     * @param time date/time value to format
+     * @return the requested String representation
+     */
+    protected static String formatDateTime(Date time) {
+        return formatDateTime(time, TimeZone.getDefault());
+    }
 }
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFLaunch.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFLaunch.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFLaunch.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFLaunch.java Thu Apr  5 16:19:19 2012
@@ -54,10 +54,9 @@ public class PDFLaunch extends PDFAction
     /** {@inheritDoc} */
     public String toPDFString() {
         StringBuffer sb = new StringBuffer(64);
-        sb.append(getObjectID());
         sb.append("<<\n/S /Launch\n/F ");
         sb.append(externalFileSpec.toString());
-        sb.append(" \n>>\nendobj\n");
+        sb.append("\n>>");
 
         return sb.toString();
     }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFLink.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFLink.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFLink.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFLink.java Thu Apr  5 16:19:19 2012
@@ -92,15 +92,14 @@ public class PDFLink extends PDFObject {
             f |= 1 << (5 - 1); //NoRotate, bit 5
             fFlag = "/F " + f;
         }
-        String s = getObjectID()
-                   + "<< /Type /Annot\n" + "/Subtype /Link\n" + "/Rect [ "
+        String s = "<< /Type /Annot\n" + "/Subtype /Link\n" + "/Rect [ "
                    + (ulx) + " " + (uly) + " "
                    + (brx) + " " + (bry) + " ]\n" + "/C [ "
                    + this.color + " ]\n" + "/Border [ 0 0 0 ]\n" + "/A "
                    + this.action.getAction() + "\n" + "/H /I\n"
                    + (this.structParent != null
                            ? "/StructParent " + this.structParent.toString() + "\n" : "")
-                   + fFlag + "\n>>\nendobj\n";
+                   + fFlag + "\n>>";
         return s;
     }
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFMetadata.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFMetadata.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFMetadata.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFMetadata.java Thu Apr  5 16:19:19 2012
@@ -79,7 +79,7 @@ public class PDFMetadata extends PDFStre
      * byte arrays around so much
      * {@inheritDoc}
      */
-    protected int output(java.io.OutputStream stream)
+    public int output(java.io.OutputStream stream)
                 throws java.io.IOException {
         int length = super.output(stream);
         this.xmpMetadata = null; //Release DOM when it's not used anymore

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFName.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFName.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFName.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFName.java Thu Apr  5 16:19:19 2012
@@ -21,7 +21,6 @@ package org.apache.fop.pdf;
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.Writer;
 
 import org.apache.commons.io.output.CountingOutputStream;
 
@@ -49,7 +48,7 @@ public class PDFName extends PDFObject {
      * @return the escaped name
      */
     static String escapeName(String name) {
-        StringBuffer sb = new StringBuffer(Math.min(16, name.length() + 4));
+        StringBuilder sb = new StringBuilder(Math.min(16, name.length() + 4));
         boolean skipFirst = false;
         sb.append('/');
         if (name.startsWith("/")) {
@@ -72,7 +71,7 @@ public class PDFName extends PDFObject {
         = {'0', '1', '2', '3', '4', '5', '6', '7',
            '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
 
-    private static void toHex(char ch, StringBuffer sb) {
+    private static void toHex(char ch, StringBuilder sb) {
         if (ch >= 256) {
             throw new IllegalArgumentException(
                     "Only 8-bit characters allowed by this implementation");
@@ -82,34 +81,48 @@ public class PDFName extends PDFObject {
     }
 
     /** {@inheritDoc} */
+    @Override
     public String toString() {
         return this.name;
     }
 
+    /**
+     * Returns the name without the leading slash.
+     * @return the name without the leading slash
+     */
+    public String getName() {
+        return this.name.substring(1);
+    }
+
     /** {@inheritDoc} */
-    protected int output(OutputStream stream) throws IOException {
-        CountingOutputStream cout = new CountingOutputStream(stream);
-        Writer writer = PDFDocument.getWriterFor(cout);
-        if (hasObjectNumber()) {
-            writer.write(getObjectID());
+    public boolean equals(Object obj) {
+        if (!(obj instanceof PDFName)) {
+            return false;
         }
+        PDFName other = (PDFName)obj;
+        return this.name.equals(other.name);
+    }
 
-        writer.write(toString());
-
-        if (hasObjectNumber()) {
-            writer.write("\nendobj\n");
-        }
+    /** {@inheritDoc} */
+    public int hashCode() {
+        return name.hashCode();
+    }
 
-        writer.flush();
+    @Override
+    public int output(OutputStream stream) throws IOException {
+        CountingOutputStream cout = new CountingOutputStream(stream);
+        StringBuilder textBuffer = new StringBuilder(64);
+        textBuffer.append(toString());
+        PDFDocument.flushTextBuffer(textBuffer, cout);
         return cout.getCount();
     }
 
-    /** {@inheritDoc} */
-    public void outputInline(OutputStream out, Writer writer) throws IOException {
+    @Override
+    public void outputInline(OutputStream out, StringBuilder textBuffer) throws IOException {
         if (hasObjectNumber()) {
-            writer.write(referencePDF());
+            textBuffer.append(referencePDF());
         } else {
-            writer.write(toString());
+            textBuffer.append(toString());
         }
     }
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFNull.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFNull.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFNull.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFNull.java Thu Apr  5 16:19:19 2012
@@ -21,7 +21,6 @@ package org.apache.fop.pdf;
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.Writer;
 
 /**
  * Class representing a PDF name object.
@@ -38,13 +37,14 @@ public final class PDFNull implements PD
     }
 
     /** {@inheritDoc} */
+    @Override
     public String toString() {
         return "null";
     }
 
     /** {@inheritDoc} */
-    public void outputInline(OutputStream out, Writer writer) throws IOException {
-        writer.write(toString());
+    public void outputInline(OutputStream out, StringBuilder textBuffer) throws IOException {
+        textBuffer.append(toString());
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFNumber.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFNumber.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFNumber.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFNumber.java Thu Apr  5 16:19:19 2012
@@ -85,13 +85,7 @@ public class PDFNumber extends PDFObject
                 "The number of this PDFNumber must not be empty");
         }
         StringBuffer sb = new StringBuffer(64);
-        if (hasObjectNumber()) {
-            sb.append(getObjectID());
-        }
         sb.append(doubleOut(getNumber().doubleValue(), 10));
-        if (hasObjectNumber()) {
-            sb.append("\nendobj\n");
-        }
         return sb.toString();
     }
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFNumsArray.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFNumsArray.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFNumsArray.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFNumsArray.java Thu Apr  5 16:19:19 2012
@@ -21,8 +21,6 @@ package org.apache.fop.pdf;
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.Writer;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.SortedMap;
 
@@ -34,7 +32,7 @@ import org.apache.commons.io.output.Coun
 public class PDFNumsArray extends PDFObject {
 
     /** Sorted Map holding the values of this array. */
-    protected SortedMap map = new java.util.TreeMap();
+    protected SortedMap<Integer, Object> map = new java.util.TreeMap<Integer, Object>();
 
     /**
      * Create a new, empty array object.
@@ -67,7 +65,7 @@ public class PDFNumsArray extends PDFObj
      * @param obj the new value
      */
     public void put(int key, Object obj) {
-        put(new Integer(key), obj);
+        put(Integer.valueOf(key), obj);
     }
 
     /**
@@ -85,37 +83,27 @@ public class PDFNumsArray extends PDFObj
      * @return the requested value
      */
     public Object get(int key) {
-        return get(new Integer(key));
+        return get(Integer.valueOf(key));
     }
 
     /** {@inheritDoc} */
-    protected int output(OutputStream stream) throws IOException {
+    @Override
+    public int output(OutputStream stream) throws IOException {
         CountingOutputStream cout = new CountingOutputStream(stream);
-        Writer writer = PDFDocument.getWriterFor(cout);
-        if (hasObjectNumber()) {
-            writer.write(getObjectID());
-        }
-
-        writer.write('[');
+        StringBuilder textBuffer = new StringBuilder(64);
+        textBuffer.append('[');
         boolean first = true;
-        Iterator iter = this.map.entrySet().iterator();
-        while (iter.hasNext()) {
-            Map.Entry entry = (Map.Entry)iter.next();
+        for (Map.Entry<Integer, Object> entry : this.map.entrySet()) {
             if (!first) {
-                writer.write(" ");
+                textBuffer.append(" ");
             }
             first = false;
-            formatObject(entry.getKey(), cout, writer);
-            writer.write(" ");
-            formatObject(entry.getValue(), cout, writer);
+            formatObject(entry.getKey(), cout, textBuffer);
+            textBuffer.append(" ");
+            formatObject(entry.getValue(), cout, textBuffer);
         }
-        writer.write(']');
-
-        if (hasObjectNumber()) {
-            writer.write("\nendobj\n");
-        }
-
-        writer.flush();
+        textBuffer.append(']');
+        PDFDocument.flushTextBuffer(textBuffer, cout);
         return cout.getCount();
     }
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFObject.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFObject.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFObject.java Thu Apr  5 16:19:19 2012
@@ -23,11 +23,6 @@ package org.apache.fop.pdf;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.Writer;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -112,7 +107,7 @@ public abstract class PDFObject implemen
     }
 
     /**
-     * Returns the object's generation.
+     * Returns this object's generation.
      * @return the PDF Object generation
      */
     public int getGeneration() {
@@ -209,7 +204,7 @@ public abstract class PDFObject implemen
      * @throws IOException if there is an error writing to the stream
      * @return the number of bytes written
      */
-    protected int output(OutputStream stream) throws IOException {
+    public int output(OutputStream stream) throws IOException {
         byte[] pdf = this.toPDF();
         stream.write(pdf);
         return pdf.length;
@@ -217,10 +212,15 @@ public abstract class PDFObject implemen
 
     /** {@inheritDoc} */
     public void outputInline(OutputStream out, Writer writer) throws IOException {
+        throw new UnsupportedOperationException("Don't use anymore: " + getClass().getName());
+    }
+
+    /** {@inheritDoc} */
+    public void outputInline(OutputStream out, StringBuilder textBuffer) throws IOException {
         if (hasObjectNumber()) {
-            writer.write(referencePDF());
+            textBuffer.append(referencePDF());
         } else {
-            writer.flush();
+            PDFDocument.flushTextBuffer(textBuffer, out);
             output(out);
         }
     }
@@ -302,97 +302,38 @@ public abstract class PDFObject implemen
 
     /**
      * Formats an object for serialization to PDF.
+     * <p>
+     * IMPORTANT: If you need to write out binary output, call
+     * {@link PDFDocument#flushTextBuffer(StringBuilder, OutputStream)} before writing any content
+     * to the {@link OutputStream}!
      * @param obj the object
      * @param out the OutputStream to write to
-     * @param writer a Writer for text content (will always be a wrapper around the above
-     *                  OutputStream. Make sure <code>flush</code> is called when mixing calls)
+     * @param textBuffer a text buffer for text output
      * @throws IOException If an I/O error occurs
      */
-    protected void formatObject(Object obj, OutputStream out, Writer writer) throws IOException {
+    protected void formatObject(Object obj, OutputStream out, StringBuilder textBuffer)
+                throws IOException {
         if (obj == null) {
-            writer.write("null");
+            textBuffer.append("null");
         } else if (obj instanceof PDFWritable) {
-            ((PDFWritable)obj).outputInline(out, writer);
+            ((PDFWritable)obj).outputInline(out, textBuffer);
         } else if (obj instanceof Number) {
             if (obj instanceof Double || obj instanceof Float) {
-                writer.write(PDFNumber.doubleOut(((Number)obj).doubleValue()));
+                textBuffer.append(PDFNumber.doubleOut(((Number)obj).doubleValue()));
             } else {
-                writer.write(obj.toString());
+                textBuffer.append(obj.toString());
             }
         } else if (obj instanceof Boolean) {
-            writer.write(obj.toString());
+            textBuffer.append(obj.toString());
         } else if (obj instanceof byte[]) {
-            writer.flush();
+            PDFDocument.flushTextBuffer(textBuffer, out);
             encodeBinaryToHexString((byte[])obj, out);
         } else {
-            writer.flush();
+            PDFDocument.flushTextBuffer(textBuffer, out);
             out.write(encodeText(obj.toString()));
         }
     }
 
-    /** Formatting pattern for PDF date */
-    protected static final SimpleDateFormat DATE_FORMAT;
-
-    static {
-        DATE_FORMAT = new SimpleDateFormat("'D:'yyyyMMddHHmmss", Locale.ENGLISH);
-        DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
-    }
-
-    /**
-     * Formats a date/time according to the PDF specification
-     * (D:YYYYMMDDHHmmSSOHH'mm').
-     * @param time date/time value to format
-     * @param tz the time zone
-     * @return the requested String representation
-     */
-    protected String formatDateTime(Date time, TimeZone tz) {
-        Calendar cal = Calendar.getInstance(tz, Locale.ENGLISH);
-        cal.setTime(time);
-
-        int offset = cal.get(Calendar.ZONE_OFFSET);
-        offset += cal.get(Calendar.DST_OFFSET);
-
-        //DateFormat is operating on GMT so adjust for time zone offset
-        Date dt1 = new Date(time.getTime() + offset);
-        StringBuffer sb = new StringBuffer();
-        sb.append(DATE_FORMAT.format(dt1));
-
-        offset /= (1000 * 60); //Convert to minutes
-
-        if (offset == 0) {
-            sb.append('Z');
-        } else {
-            if (offset > 0) {
-                sb.append('+');
-            } else {
-                sb.append('-');
-            }
-            int offsetHour = Math.abs(offset / 60);
-            int offsetMinutes = Math.abs(offset % 60);
-            if (offsetHour < 10) {
-                sb.append('0');
-            }
-            sb.append(Integer.toString(offsetHour));
-            sb.append('\'');
-            if (offsetMinutes < 10) {
-                sb.append('0');
-            }
-            sb.append(Integer.toString(offsetMinutes));
-            sb.append('\'');
-        }
-        return sb.toString();
-    }
-
-    /**
-     * Formats a date/time according to the PDF specification.
-     * (D:YYYYMMDDHHmmSSOHH'mm').
-     * @param time date/time value to format
-     * @return the requested String representation
-     */
-    protected String formatDateTime(Date time) {
-        return formatDateTime(time, TimeZone.getDefault());
-    }
-
     /**
      * Check if the other PDFObject has the same content as the current object.
      * <p>

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFOutline.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFOutline.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFOutline.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFOutline.java Thu Apr  5 16:19:19 2012
@@ -24,12 +24,11 @@ import java.io.IOException;
 import java.util.List;
 
 /**
- * This represents a single Outline object in a PDF, including the root Outlines
+ * <p>This represents a single Outline object in a PDF, including the root Outlines
  * object. Outlines provide the bookmark bar, usually rendered to the right of
- * a PDF document in user agents such as Acrobat Reader
- *
- * @author Kelly A. Campbell
+ * a PDF document in user agents such as Acrobat Reader.</p>
  *
+ * <p>This work was authored by Kelly A. Campbell.</p>
  */
 public class PDFOutline extends PDFObject {
 
@@ -132,7 +131,6 @@ public class PDFOutline extends PDFObjec
     protected byte[] toPDF() {
         ByteArrayOutputStream bout = new ByteArrayOutputStream(128);
         try {
-            bout.write(encode(getObjectID()));
             bout.write(encode("<<"));
             if (parent == null) {
                 // root Outlines object
@@ -165,7 +163,7 @@ public class PDFOutline extends PDFObjec
                     bout.write(encode(" /A " + actionRef + "\n"));
                 }
             }
-            bout.write(encode(">> endobj\n"));
+            bout.write(encode(">>"));
         } catch (IOException ioe) {
             log.error("Ignored I/O exception", ioe);
         }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFOutputIntent.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFOutputIntent.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFOutputIntent.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFOutputIntent.java Thu Apr  5 16:19:19 2012
@@ -130,7 +130,6 @@ public class PDFOutputIntent extends PDF
     public byte[] toPDF() {
         ByteArrayOutputStream bout = new ByteArrayOutputStream(128);
         try {
-            bout.write(encode(getObjectID()));
             bout.write(encode("<<\n"));
             bout.write(encode("/Type /OutputIntent\n"));
 
@@ -164,7 +163,7 @@ public class PDFOutputIntent extends PDF
                 bout.write(encode("/DestOutputProfile " + destOutputProfile.referencePDF() + "\n"));
             }
 
-            bout.write(encode(">>\nendobj\n"));
+            bout.write(encode(">>"));
         } catch (IOException ioe) {
             log.error("Ignored I/O exception", ioe);
         }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFPages.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFPages.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFPages.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFPages.java Thu Apr  5 16:19:19 2012
@@ -19,9 +19,8 @@
 
 package org.apache.fop.pdf;
 
-// Java
-import java.util.List;
 import java.util.ArrayList;
+import java.util.List;
 
 /**
  * class representing a /Pages object.
@@ -110,10 +109,9 @@ public class PDFPages extends PDFObject 
      */
     public String toPDFString() {
         StringBuffer sb = new StringBuffer(64);
-        sb.append(getObjectID()).
-            append("<< /Type /Pages\n/Count ").
-            append(this.getCount()).
-            append("\n/Kids [");
+        sb.append("<< /Type /Pages\n/Count ")
+                .append(this.getCount())
+                .append("\n/Kids [");
         for (int i = 0; i < kids.size(); i++) {
             Object kid = kids.get(i);
             if (kid == null) {
@@ -121,7 +119,7 @@ public class PDFPages extends PDFObject 
             }
             sb.append(kid).append(" ");
         }
-        sb.append("] >>\nendobj\n");
+        sb.append("] >>");
         return sb.toString();
     }
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFPaintingState.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFPaintingState.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFPaintingState.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFPaintingState.java Thu Apr  5 16:19:19 2012
@@ -19,12 +19,15 @@
 
 package org.apache.fop.pdf;
 
+import java.awt.Color;
 import java.awt.Paint;
 import java.awt.Shape;
 import java.awt.geom.Area;
 import java.awt.geom.GeneralPath;
 import java.util.Iterator;
 
+import org.apache.xmlgraphics.java2d.color.ColorUtil;
+
 import org.apache.fop.util.AbstractPaintingState;
 
 /**
@@ -63,13 +66,18 @@ public class PDFPaintingState extends or
      */
     public boolean setPaint(Paint p) {
         PDFData data = getPDFData();
-        Paint paint = data.paint;
-        if (paint == null) {
+        Paint currentPaint = data.paint;
+        if (currentPaint == null) {
             if (p != null) {
                 data.paint = p;
                 return true;
             }
-        } else if (!paint.equals(p)) {
+        } else if (p instanceof Color && currentPaint instanceof Color) {
+            if (!ColorUtil.isSameColor((Color)p, (Color)currentPaint)) {
+                data.paint = p;
+                return true;
+            }
+        } else if (!currentPaint.equals(p)) {
             data.paint = p;
             return true;
         }
@@ -180,11 +188,13 @@ public class PDFPaintingState extends or
     }
 
     /** {@inheritDoc} */
+    @Override
     protected AbstractData instantiateData() {
         return new PDFData();
     }
 
     /** {@inheritDoc} */
+    @Override
     protected AbstractPaintingState instantiate() {
         return new PDFPaintingState();
     }
@@ -194,6 +204,7 @@ public class PDFPaintingState extends or
      * This call should be used when the q operator is used
      * so that the state is known when popped.
      */
+    @Override
     public void save() {
         AbstractData data = getData();
         AbstractData copy = (AbstractData)data.clone();
@@ -222,6 +233,7 @@ public class PDFPaintingState extends or
         private float characterSpacing = 0f;
 
         /** {@inheritDoc} */
+        @Override
         public Object clone() {
             PDFData obj = (PDFData)super.clone();
             obj.paint = this.paint;
@@ -237,6 +249,7 @@ public class PDFPaintingState extends or
         }
 
         /** {@inheritDoc} */
+        @Override
         public String toString() {
             return super.toString()
                 + ", paint=" + paint
@@ -249,6 +262,7 @@ public class PDFPaintingState extends or
         }
 
         /** {@inheritDoc} */
+        @Override
         protected AbstractData instantiate() {
             return new PDFData();
         }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFPattern.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFPattern.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFPattern.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFPattern.java Thu Apr  5 16:19:19 2012
@@ -19,10 +19,9 @@
 
 package org.apache.fop.pdf;
 
-// Java
-import java.util.List;
-import java.io.OutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
+import java.util.List;
 
 /**
  * class representing a PDF Function.
@@ -211,13 +210,12 @@ public class PDFPattern extends PDFPathP
      * @throws IOException if there is an error writing to the stream
      * @return the PDF string.
      */
-    protected int output(OutputStream stream) throws IOException {
+    public int output(OutputStream stream) throws IOException {
 
         int vectorSize = 0;
         int tempInt = 0;
         byte[] buffer;
         StringBuffer p = new StringBuffer(64);
-        p.append(getObjectID());
         p.append("<< \n/Type /Pattern \n");
 
         if (this.resources != null) {
@@ -324,10 +322,6 @@ public class PDFPattern extends PDFPathP
             length += pdfStream.outputStreamData(encodedStream, stream);
         }
 
-        buffer = encode("\nendobj\n");
-        stream.write(buffer);
-        length += buffer.length;
-
         return length;
     }
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFProfile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFProfile.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFProfile.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFProfile.java Thu Apr  5 16:19:19 2012
@@ -133,8 +133,12 @@ public class PDFProfile {
 
     //---------=== Info and validation methods ===---------
 
+    private String format(String pattern, Object[] args) {
+        return MessageFormat.format(pattern, args);
+    }
+
     private String format(String pattern, Object arg) {
-        return MessageFormat.format(pattern, new Object[] {arg});
+        return format(pattern, new Object[] {arg});
     }
 
     /** Checks if encryption is allowed. */
@@ -180,11 +184,11 @@ public class PDFProfile {
     public void verifyPDFVersion() {
         final String err = "PDF version must be 1.4 for {0}";
         if (getPDFAMode().isPDFA1LevelB()
-                && getDocument().getPDFVersion() != PDFDocument.PDF_VERSION_1_4) {
+                && !Version.V1_4.equals(getDocument().getPDFVersion())) {
             throw new PDFConformanceException(format(err, getPDFAMode()));
         }
         if (getPDFXMode() == PDFXMode.PDFX_3_2003
-                && getDocument().getPDFVersion() != PDFDocument.PDF_VERSION_1_4) {
+                && !Version.V1_4.equals(getDocument().getPDFVersion())) {
             throw new PDFConformanceException(format(err, getPDFXMode()));
         }
     }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFRectangle.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFRectangle.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFRectangle.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFRectangle.java Thu Apr  5 16:19:19 2012
@@ -21,7 +21,6 @@ package org.apache.fop.pdf;
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.Writer;
 
 /**
  * class representing a rectangle
@@ -78,16 +77,26 @@ public class PDFRectangle implements PDF
     }
 
     private String format() {
-        return "[" + llx + " " + lly + " " + urx + " " + ury + "]";
+        StringBuilder textBuffer = new StringBuilder(32);
+        format(textBuffer);
+        return textBuffer.toString();
+    }
+
+    private void format(StringBuilder textBuffer) {
+        textBuffer.append('[').append(llx)
+                  .append(' ').append(lly)
+                  .append(' ').append(urx)
+                  .append(' ').append(ury).append(']');
     }
 
     /** {@inheritDoc} */
+    @Override
     public String toString() {
         return "PDFRectangle" + format();
     }
 
     /** {@inheritDoc} */
-    public void outputInline(OutputStream out, Writer writer) throws IOException {
-        writer.write(format());
+    public void outputInline(OutputStream out, StringBuilder textBuffer) throws IOException {
+        format(textBuffer);
     }
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFReference.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFReference.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFReference.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFReference.java Thu Apr  5 16:19:19 2012
@@ -19,9 +19,7 @@
 
 package org.apache.fop.pdf;
 
-import java.io.IOException;
 import java.io.OutputStream;
-import java.io.Writer;
 import java.lang.ref.Reference;
 import java.lang.ref.SoftReference;
 
@@ -36,7 +34,7 @@ public class PDFReference implements PDF
     private int objectNumber;
     private int generation;
 
-    private Reference objReference;
+    private Reference<PDFObject> objReference;
 
     /**
      * Creates a new PDF reference.
@@ -45,7 +43,7 @@ public class PDFReference implements PDF
     public PDFReference(PDFObject obj) {
         this.objectNumber = obj.getObjectNumber();
         this.generation = obj.getGeneration();
-        this.objReference = new SoftReference(obj);
+        this.objReference = new SoftReference<PDFObject>(obj);
     }
 
     /**
@@ -69,7 +67,7 @@ public class PDFReference implements PDF
      */
     public PDFObject getObject() {
         if (this.objReference != null) {
-            PDFObject obj = (PDFObject)this.objReference.get();
+            PDFObject obj = this.objReference.get();
             if (obj == null) {
                 this.objReference = null;
             }
@@ -96,13 +94,16 @@ public class PDFReference implements PDF
     }
 
     /** {@inheritDoc} */
+    @Override
     public String toString() {
-        return getObjectNumber() + " " + getGeneration() + " R";
+        StringBuilder textBuffer = new StringBuilder();
+        outputInline(null, textBuffer);
+        return textBuffer.toString();
     }
 
     /** {@inheritDoc} */
-    public void outputInline(OutputStream out, Writer writer) throws IOException {
-        writer.write(toString());
+    public void outputInline(OutputStream out, StringBuilder textBuffer) {
+        textBuffer.append(getObjectNumber()).append(' ').append(getGeneration()).append(" R");
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFResources.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFResources.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFResources.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFResources.java Thu Apr  5 16:19:19 2012
@@ -19,26 +19,29 @@
 
 package org.apache.fop.pdf;
 
+import java.io.IOException;
+import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
+
 import org.apache.fop.fonts.FontDescriptor;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.Typeface;
 import org.apache.fop.fonts.base14.Symbol;
 import org.apache.fop.fonts.base14.ZapfDingbats;
-import org.apache.fop.util.ColorProfileUtil;
 
 /**
- * class representing a /Resources object.
+ * Class representing a /Resources object.
  *
  * /Resources object contain a list of references to the fonts for the
  * document
  */
-public class PDFResources extends PDFObject {
+public class PDFResources extends PDFDictionary {
 
     /**
      * /Font objects keyed by their internal name
@@ -159,11 +162,14 @@ public class PDFResources extends PDFObj
      * Add a ColorSpace dictionary to the resources.
      * @param colorSpace the color space
      */
-    public void addColorSpace(PDFICCBasedColorSpace colorSpace) {
-        this.colorSpaces.put(colorSpace.getName(), colorSpace);
-        String desc = ColorProfileUtil.getICCProfileDescription(
-                colorSpace.getICCStream().getICCProfile());
-        this.iccColorSpaces.put(desc, colorSpace);
+    public void addColorSpace(PDFColorSpace colorSpace) {
+        this.colorSpaces.put(new PDFName(colorSpace.getName()), colorSpace);
+        if (colorSpace instanceof PDFICCBasedColorSpace) {
+            PDFICCBasedColorSpace icc = (PDFICCBasedColorSpace)colorSpace;
+            String desc = ColorProfileUtil.getICCProfileDescription(
+                    icc.getICCStream().getICCProfile());
+            this.iccColorSpaces.put(desc, colorSpace);
+        }
     }
 
     /**
@@ -181,106 +187,80 @@ public class PDFResources extends PDFObj
      * @param name the name of the color space
      * @return the requested color space or null if it wasn't found
      */
-    public PDFICCBasedColorSpace getColorSpace(String name) {
-        PDFICCBasedColorSpace cs = (PDFICCBasedColorSpace)this.colorSpaces.get(name);
+    public PDFColorSpace getColorSpace(PDFName name) {
+        PDFColorSpace cs = (PDFColorSpace)this.colorSpaces.get(name);
         return cs;
     }
 
-    /**
-     * represent the object in PDF
-     * This adds the references to all the objects in the current
-     * resource context.
-     *
-     * @return the PDF
-     * {@inheritDoc}
-     */
     @Override
-    public String toPDFString() {
-        StringBuffer p = new StringBuffer(128);
-        p.append(getObjectID() + "<<\n");
-        if (!this.fonts.isEmpty()) {
-            p.append("/Font <<\n");
+    public int output(OutputStream stream) throws IOException {
+        populateDictionary();
+        return super.output(stream);
+    }
 
+    private void populateDictionary() {
+        if (!this.fonts.isEmpty()) {
+            PDFDictionary dict = new PDFDictionary(this);
             /* construct PDF dictionary of font object references */
             Iterator fontIterator = this.fonts.keySet().iterator();
             while (fontIterator.hasNext()) {
                 String fontName = (String)fontIterator.next();
-                p.append("  /" + fontName + " "
-                         + ((PDFFont)this.fonts.get(fontName)).referencePDF()
-                         + "\n");
+                dict.put(fontName, (PDFFont)this.fonts.get(fontName));
             }
-
-            p.append(">>\n");
+            put("Font", dict);
         }
 
-        PDFShading currentShading = null;
         if (!this.shadings.isEmpty()) {
-            p.append("/Shading <<\n");
-
+            PDFDictionary dict = new PDFDictionary(this);
             for (Iterator iter = shadings.iterator(); iter.hasNext();) {
-                currentShading = (PDFShading)iter.next();
-                p.append("  /" + currentShading.getName() + " "
-                         + currentShading.referencePDF() + " ");    // \n ??????
+                PDFShading currentShading = (PDFShading)iter.next();
+                dict.put(currentShading.getName(), currentShading);
             }
-
-            p.append(">>\n");
+            put("Shading", dict);
         }
-        // "free" the memory. Sorta.
-        currentShading = null;
 
-        PDFPattern currentPattern = null;
         if (!this.patterns.isEmpty()) {
-            p.append("/Pattern <<\n");
-
+            PDFDictionary dict = new PDFDictionary(this);
             for (Iterator iter = patterns.iterator(); iter.hasNext();) {
-                currentPattern = (PDFPattern)iter.next();
-                p.append("  /" + currentPattern.getName() + " "
-                         + currentPattern.referencePDF() + " ");
+                PDFPattern currentPattern = (PDFPattern)iter.next();
+                dict.put(currentPattern.getName(), currentPattern);
             }
-
-            p.append(">>\n");
+            put("Pattern", dict);
         }
-        // "free" the memory. Sorta.
-        currentPattern = null;
 
-        p.append("/ProcSet [ /PDF /ImageB /ImageC /Text ]\n");
+        PDFArray procset = new PDFArray(this);
+        procset.add(new PDFName("PDF"));
+        procset.add(new PDFName("ImageB"));
+        procset.add(new PDFName("ImageC"));
+        procset.add(new PDFName("Text"));
+        put("ProcSet", procset);
 
         if (this.xObjects != null && !this.xObjects.isEmpty()) {
-            p = p.append("/XObject <<\n");
+            PDFDictionary dict = new PDFDictionary(this);
             for (Iterator iter = xObjects.iterator(); iter.hasNext();) {
                 PDFXObject xobj = (PDFXObject)iter.next();
-                p = p.append("  " + xobj.getName() + " "
-                             + xobj.referencePDF()
-                             + "\n");
+                dict.put(xobj.getName().toString(), xobj);
             }
-            p = p.append(">>\n");
+            put("XObject", dict);
         }
 
         if (!this.gstates.isEmpty()) {
-            p = p.append("/ExtGState <<\n");
+            PDFDictionary dict = new PDFDictionary(this);
             for (Iterator iter = gstates.iterator(); iter.hasNext();) {
                 PDFGState gs = (PDFGState)iter.next();
-                p = p.append("  /" + gs.getName() + " "
-                             + gs.referencePDF()
-                             + "\n");
+                dict.put(gs.getName(), gs);
             }
-            p = p.append(">>\n");
+            put("ExtGState", dict);
         }
 
         if (!this.colorSpaces.isEmpty()) {
-            p = p.append("/ColorSpace <<\n");
+            PDFDictionary dict = new PDFDictionary(this);
             for (Iterator iter = colorSpaces.values().iterator(); iter.hasNext();) {
-                PDFICCBasedColorSpace colorSpace = (PDFICCBasedColorSpace)iter.next();
-                p = p.append("  /" + colorSpace.getName() + " "
-                             + colorSpace.referencePDF()
-                             + "\n");
+                PDFColorSpace colorSpace = (PDFColorSpace)iter.next();
+                dict.put(colorSpace.getName(), colorSpace);
             }
-            p = p.append(">>\n");
+            put("ColorSpace", dict);
         }
-
-        p = p.append(">>\nendobj\n");
-
-        return p.toString();
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFRoot.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFRoot.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFRoot.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFRoot.java Thu Apr  5 16:19:19 2012
@@ -21,6 +21,9 @@ package org.apache.fop.pdf;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Locale;
+
+import org.apache.fop.util.LanguageTags;
 
 /**
  * Class representing a Root (/Catalog) object.
@@ -69,10 +72,11 @@ public class PDFRoot extends PDFDictiona
         setObjectNumber(objnum);
         put("Type", new PDFName("Catalog"));
         setRootPages(pages);
+        setLanguage("x-unknown");
     }
 
     /** {@inheritDoc} */
-    protected int output(OutputStream stream) throws IOException {
+    public int output(OutputStream stream) throws IOException {
         getDocument().getProfile().verifyTaggedPDF();
         return super.output(stream);
     }
@@ -201,7 +205,7 @@ public class PDFRoot extends PDFDictiona
      * @since PDF 1.4
      */
     public void setMetadata(PDFMetadata meta) {
-        if (getDocumentSafely().getPDFVersion() >= PDFDocument.PDF_VERSION_1_4) {
+        if (getDocumentSafely().getPDFVersion().compareTo(Version.V1_4) >= 0) {
             put("Metadata", meta.makeReference());
         }
     }
@@ -231,7 +235,7 @@ public class PDFRoot extends PDFDictiona
      * @since PDF 1.4
      */
     public void addOutputIntent(PDFOutputIntent outputIntent) {
-        if (getDocumentSafely().getPDFVersion() >= PDFDocument.PDF_VERSION_1_4) {
+        if (getDocumentSafely().getPDFVersion().compareTo(Version.V1_4) >= 0) {
             PDFArray outputIntents = getOutputIntents();
             if (outputIntents == null) {
                 outputIntents = new PDFArray(this);
@@ -242,6 +246,17 @@ public class PDFRoot extends PDFDictiona
     }
 
     /**
+     * Sets the "Version" entry. If this version is greater than that specified in the header, this
+     * version takes precedence.
+     *
+     * @param version the PDF document version
+     * @since PDF 1.4
+     */
+    void setVersion(Version version) {
+        put("Version", new PDFName(version.toString()));
+    }
+
+    /**
      * Returns the language identifier of the document.
      * @return the language identifier of the document (or null if not set or undefined)
      * @since PDF 1.4
@@ -251,13 +266,17 @@ public class PDFRoot extends PDFDictiona
     }
 
     /**
-     * Sets the language identifier of the document.
-     * @param lang the language identifier of the document.
+     * Sets the locale of the document.
+     * @param locale the locale of the document.
      */
-    public void setLanguage(String lang) {
-        if (lang == null) {
-            throw new NullPointerException("lang must not be null");
+    public void setLanguage(Locale locale) {
+        if (locale == null) {
+            throw new NullPointerException("locale must not be null");
         }
+        setLanguage(LanguageTags.toLanguageTag(locale));
+    }
+
+    private void setLanguage(String lang) {
         put("Lang", lang);
     }
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFShading.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFShading.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFShading.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFShading.java Thu Apr  5 16:19:19 2012
@@ -342,8 +342,7 @@ public class PDFShading extends PDFObjec
         int vectorSize;
         int tempInt;
         StringBuffer p = new StringBuffer(128);
-        p.append(getObjectID()
-            + "<< \n/ShadingType " + this.shadingType + " \n");
+        p.append("<<\n/ShadingType " + this.shadingType + " \n");
         if (this.colorSpace != null) {
             p.append("/ColorSpace /"
                      + this.colorSpace.getName() + " \n");
@@ -528,7 +527,7 @@ public class PDFShading extends PDFObjec
 
         }
 
-        p.append(">> \nendobj\n");
+        p.append(">>");
 
         return (p.toString());
     }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFStream.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFStream.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFStream.java Thu Apr  5 16:19:19 2012
@@ -21,6 +21,7 @@ package org.apache.fop.pdf;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.io.Writer;
 
 /**
@@ -44,16 +45,33 @@ public class PDFStream extends AbstractP
      * Create an empty stream object
      */
     public PDFStream() {
-        super();
+        setUp();
+    }
+
+    public PDFStream(PDFDictionary dictionary) {
+        super(dictionary);
+        setUp();
+    }
+
+    public PDFStream(PDFDictionary dictionary, boolean encodeOnTheFly) {
+        super(dictionary, encodeOnTheFly);
+        setUp();
+    }
+
+    public PDFStream(boolean encodeOnTheFly) {
+        super(encodeOnTheFly);
+        setUp();
+    }
+
+    private void setUp() {
         try {
             data = StreamCacheFactory.getInstance().createStreamCache();
-            this.streamWriter = new java.io.OutputStreamWriter(
+            this.streamWriter = new OutputStreamWriter(
                     getBufferOutputStream(), PDFDocument.ENCODING);
             //Buffer to minimize calls to the converter
             this.streamWriter = new java.io.BufferedWriter(this.streamWriter);
-        } catch (IOException ex) {
-            //TODO throw the exception and catch it elsewhere
-            ex.printStackTrace();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
         }
     }
 
@@ -136,7 +154,7 @@ public class PDFStream extends AbstractP
     /**
      * {@inheritDoc}
      */
-    protected int output(OutputStream stream) throws IOException {
+    public int output(OutputStream stream) throws IOException {
         final int len = super.output(stream);
 
         //Now that the data has been written, it can be discarded.

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFStructElem.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFStructElem.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFStructElem.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFStructElem.java Thu Apr  5 16:19:19 2012
@@ -19,18 +19,28 @@
 
 package org.apache.fop.pdf;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Locale;
 
-import org.apache.fop.util.XMLUtil;
+import org.apache.fop.accessibility.StructureTreeElement;
+import org.apache.fop.util.LanguageTags;
 
 /**
  * Class representing a PDF Structure Element.
  */
-public class PDFStructElem extends PDFDictionary {
+public class PDFStructElem extends PDFDictionary implements StructureTreeElement, CompressedObject {
 
     private PDFStructElem parentElement;
 
     /**
+     * Elements to be added to the kids array.
+     */
+    protected List<PDFObject> kids;
+
+    /**
      * Creates a new structure element.
      *
      * @param parent parent of this element
@@ -57,21 +67,12 @@ public class PDFStructElem extends PDFDi
 
     /** {@inheritDoc} */
     public void setParent(PDFObject parent) {
-        if (parent != null) {
+        if (parent != null && parent.hasObjectNumber()) {
            put("P", new PDFReference(parent));
         }
     }
 
     /**
-     * Returns the kids of this structure element.
-     *
-     * @return the value of the K entry
-     */
-    private PDFArray getKids() {
-        return (PDFArray) get("K");
-    }
-
-    /**
      * Add a kid to this structure element. This element will then add itself to
      * its parent structure element if it has not already, and so will the
      * parent, and so on.
@@ -79,24 +80,10 @@ public class PDFStructElem extends PDFDi
      * @param kid element to be added
      */
     public void addKid(PDFObject kid) {
-        PDFArray kids = getKids();
         if (kids == null) {
-            kids = new PDFArray();
-            put("K", kids);
+            kids = new ArrayList<PDFObject>();
         }
         kids.add(kid);
-        joinHierarchy();
-    }
-
-    private boolean containsKid(PDFObject kid) {
-        PDFArray kids = getKids();
-        return kids != null && kids.contains(kid);
-    }
-
-    private void joinHierarchy() {
-        if (parentElement != null && !parentElement.containsKid(this)) {
-            parentElement.addKid(this);
-        }
     }
 
     /**
@@ -109,7 +96,6 @@ public class PDFStructElem extends PDFDi
      */
     public void setMCIDKid(int mcid) {
         put("K", mcid);
-        joinHierarchy();
     }
 
     /**
@@ -127,7 +113,7 @@ public class PDFStructElem extends PDFDi
      * @return the value of the S entry
      */
     public PDFName getStructureType() {
-        return (PDFName)get("S");
+        return (PDFName) get("S");
     }
 
     /**
@@ -145,7 +131,7 @@ public class PDFStructElem extends PDFDi
      * @param language a value for the Lang entry
      */
     public void setLanguage(Locale language) {
-        setLanguage(XMLUtil.toRFC3066(language));
+        setLanguage(LanguageTags.toLanguageTag(language));
     }
 
     /**
@@ -154,6 +140,71 @@ public class PDFStructElem extends PDFDi
      * @return the value of the Lang entry (<code>null</code> if no language was specified)
      */
     public String getLanguage() {
-        return (String)get("Lang");
+        return (String) get("Lang");
+    }
+
+    @Override
+    protected void writeDictionary(OutputStream out, StringBuilder textBuffer) throws IOException {
+        attachKids();
+        super.writeDictionary(out, textBuffer);
     }
+
+    /**
+     * Attaches all valid kids to the kids array.
+     *
+     * @return true iff 1+ kids were added to the kids array
+     */
+    protected boolean attachKids() {
+        List<PDFObject> validKids = new ArrayList<PDFObject>();
+        if (kids != null) {
+            for (PDFObject kid : kids) {
+                if (kid instanceof Placeholder)  {
+                    if (((Placeholder) kid).attachKids()) {
+                        validKids.add(kid);
+                    }
+                } else {
+                    validKids.add(kid);
+                }
+            }
+        }
+        boolean kidsAttached = !validKids.isEmpty();
+        if (kidsAttached) {
+            PDFArray array = new PDFArray();
+            for (PDFObject ob : validKids) {
+                array.add(ob);
+            }
+            put("K", array);
+        }
+        return kidsAttached;
+    }
+
+    /**
+     * Class representing a placeholder for a PDF Structure Element.
+     */
+    public static class Placeholder extends PDFStructElem {
+
+        @Override
+        public void outputInline(OutputStream out, StringBuilder textBuffer) throws IOException {
+            if (kids != null) {
+                assert kids.size() > 0;
+                for (int i = 0; i < kids.size(); i++) {
+                    if (i > 0) {
+                        textBuffer.append(' ');
+                    }
+                    Object obj = kids.get(i);
+                    formatObject(obj, out, textBuffer);
+                }
+            }
+        }
+
+        /**
+         * Constructor
+         * @param parent -
+         * @param name -
+         */
+        public Placeholder(PDFObject parent, String name) {
+            super(parent, new PDFName(name));
+        }
+    }
+
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFStructTreeRoot.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFStructTreeRoot.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFStructTreeRoot.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFStructTreeRoot.java Thu Apr  5 16:19:19 2012
@@ -52,4 +52,4 @@ public class PDFStructTreeRoot extends P
     public void addKid(PDFObject kid) {
         getKids().add(kid);
     }
-}
\ No newline at end of file
+}

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFT1Stream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFT1Stream.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFT1Stream.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFT1Stream.java Thu Apr  5 16:19:19 2012
@@ -46,7 +46,7 @@ public class PDFT1Stream extends Abstrac
      * byte arrays around so much
      * {@inheritDoc}
      */
-    protected int output(java.io.OutputStream stream)
+    public int output(java.io.OutputStream stream)
             throws java.io.IOException {
         if (pfb == null) {
             throw new IllegalStateException("pfb must not be null at this point");

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFTTFStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFTTFStream.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFTTFStream.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFTTFStream.java Thu Apr  5 16:19:19 2012
@@ -53,7 +53,7 @@ public class PDFTTFStream extends Abstra
      * byte arrays around so much
      * {@inheritDoc}
      */
-    protected int output(java.io.OutputStream stream)
+    public int output(java.io.OutputStream stream)
             throws java.io.IOException {
         if (log.isDebugEnabled()) {
             log.debug("Writing " + origLength + " bytes of TTF font data");

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFText.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFText.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFText.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFText.java Thu Apr  5 16:19:19 2012
@@ -60,11 +60,9 @@ public class PDFText extends PDFObject {
                 "The text of this PDFText must not be empty");
         }
         StringBuffer sb = new StringBuffer(64);
-        sb.append(getObjectID());
         sb.append("(");
         sb.append(escapeText(getText()));
         sb.append(")");
-        sb.append("\nendobj\n");
         return sb.toString();
     }
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFTextUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFTextUtil.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFTextUtil.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFTextUtil.java Thu Apr  5 16:19:19 2012
@@ -81,10 +81,10 @@ public abstract class PDFTextUtil {
         sb.append(PDFNumber.doubleOut(lt[5], DEC));
     }
 
-    private void writeChar(char ch, StringBuffer sb) {
-        if (!useMultiByte) {
+    private static void writeChar(char ch, StringBuffer sb, boolean multibyte) {
+        if (!multibyte) {
             if (ch < 32 || ch > 127) {
-                sb.append("\\").append(Integer.toOctalString((int)ch));
+                sb.append("\\").append(Integer.toOctalString(ch));
             } else {
                 switch (ch) {
                 case '(':
@@ -101,6 +101,10 @@ public abstract class PDFTextUtil {
         }
     }
 
+    private void writeChar(char ch, StringBuffer sb) {
+        writeChar ( ch, sb, useMultiByte );
+    }
+
     private void checkInTextObject() {
         if (!inTextObject) {
             throw new IllegalStateException("Not in text object");
@@ -147,21 +151,6 @@ public abstract class PDFTextUtil {
     }
 
     /**
-     * Creates a "q" command, pushing a copy of the entire graphics state onto the stack.
-     */
-    public void saveGraphicsState() {
-        write("q\n");
-    }
-
-    /**
-     * Creates a "Q" command, restoring the entire graphics state to its former value by popping
-     * it from the stack.
-     */
-    public void restoreGraphicsState() {
-        write("Q\n");
-    }
-
-    /**
      * Creates a "cm" command.
      * @param at the transformation matrix
      */
@@ -260,24 +249,38 @@ public abstract class PDFTextUtil {
             bufTJ = new StringBuffer();
         }
         if (bufTJ.length() == 0) {
-            bufTJ.append("[").append(startText);
+            bufTJ.append("[");
+            bufTJ.append(startText);
         }
         writeChar(codepoint, bufTJ);
     }
 
     /**
      * Writes a glyph adjust value to the "TJ-Buffer".
+
+     * <p>Assumes the following:</p>
+     * <ol>
+     * <li>if buffer is currently empty, then this is the start of the array object
+     * that encodes the adjustment and character values, and, therfore, a LEFT
+     * SQUARE BRACKET '[' must be prepended; and
+     * </li>
+     * <li>otherwise (the buffer is
+     * not empty), then the last element written to the buffer was a mapped
+     * character, and, therefore, a terminating '&gt;' or ')' followed by a space
+     * must be appended to the buffer prior to appending the adjustment value.
+     * </li>
+     * </ol>
      * @param adjust the glyph adjust value in thousands of text unit space.
      */
     public void adjustGlyphTJ(double adjust) {
         if (bufTJ == null) {
             bufTJ = new StringBuffer();
         }
-        if (bufTJ.length() > 0) {
-            bufTJ.append(endText).append(" ");
-        }
         if (bufTJ.length() == 0) {
             bufTJ.append("[");
+        } else {
+            bufTJ.append(endText);
+            bufTJ.append(" ");
         }
         bufTJ.append(PDFNumber.doubleOut(adjust, DEC - 4));
         bufTJ.append(" ");
@@ -300,4 +303,31 @@ public abstract class PDFTextUtil {
         return bufTJ != null && bufTJ.length() > 0;
     }
 
+    /**
+     * Writes a "Td" command with specified x and y coordinates.
+     * @param x coordinate
+     * @param y coordinate
+     */
+    public void writeTd ( double x, double y ) {
+        StringBuffer sb = new StringBuffer();
+        sb.append(PDFNumber.doubleOut(x, DEC));
+        sb.append(' ');
+        sb.append(PDFNumber.doubleOut(y, DEC));
+        sb.append ( " Td\n" );
+        write ( sb.toString() );
+    }
+
+    /**
+     * Writes a "Tj" command with specified character code.
+     * @param ch character code to write
+     */
+    public void writeTj ( char ch ) {
+        StringBuffer sb = new StringBuffer();
+        sb.append ( '<' );
+        writeChar ( ch, sb, true );
+        sb.append ( '>' );
+        sb.append ( " Tj\n" );
+        write ( sb.toString() );
+    }
+
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFUri.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFUri.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFUri.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFUri.java Thu Apr  5 16:19:19 2012
@@ -55,8 +55,7 @@ public class PDFUri extends PDFAction {
     /** {@inheritDoc} */
     public String toPDFString() {
         //TODO Convert this class into a dictionary
-        return getObjectID() + getDictString() + "\nendobj\n";
-        //throw new UnsupportedOperationException("This method should not be called");
+        return getDictString();
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFWritable.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFWritable.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFWritable.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFWritable.java Thu Apr  5 16:19:19 2012
@@ -21,7 +21,6 @@ package org.apache.fop.pdf;
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.Writer;
 
 /**
  * This interface is implemented by classes that can be serialized to a PDF file either by
@@ -30,13 +29,16 @@ import java.io.Writer;
 public interface PDFWritable {
 
     /**
-     * Writes a "direct object" (inline object) representation to the stream. A Writer is given
-     * for optimized encoding of text content. Since the Writer is buffered, make sure
-     * <code>flush()</code> is called before any direct calls to <code>out</code> are made.
+     * Writes a "direct object" (inline object) representation to the stream. A text buffer is given
+     * for optimized encoding of text content.
+     * <p>
+     * IMPORTANT: If you need to write out binary output, call
+     * {@link PDFDocument#flushTextBuffer(StringBuilder, OutputStream)} before writing any content
+     * to the {@link OutputStream}!
      * @param out the OutputStream (for binary content)
-     * @param writer the Writer (for text content, wraps the above OutputStream)
+     * @param textBuffer the text buffer for text content
      * @throws IOException if an I/O error occurs
      */
-    void outputInline(OutputStream out, Writer writer) throws IOException;
+    void outputInline(OutputStream out, StringBuilder textBuffer) throws IOException;
 
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFXObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFXObject.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFXObject.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFXObject.java Thu Apr  5 16:19:19 2012
@@ -41,6 +41,10 @@ public abstract class PDFXObject extends
         super();
     }
 
+    protected PDFXObject(PDFDictionary dictionary) {
+        super(dictionary);
+    }
+
     /**
      * Returns the XObject's name.
      * @return the name of the XObject

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/StreamCache.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/StreamCache.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/StreamCache.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/StreamCache.java Thu Apr  5 16:19:19 2012
@@ -19,8 +19,8 @@
 
 package org.apache.fop.pdf;
 
-import java.io.OutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 
 /**
  * Interface used to store the bytes for a PDFStream. It's actually a generic

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/TempFileStreamCache.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/TempFileStreamCache.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/TempFileStreamCache.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/TempFileStreamCache.java Thu Apr  5 16:19:19 2012
@@ -19,13 +19,11 @@
 
 package org.apache.fop.pdf;
 
-// Java
+import java.io.File;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.IOException;
-import java.io.File;
 
-//Commons
 import org.apache.commons.io.IOUtils;
 
 /**

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/AbstractConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/AbstractConfigurator.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/AbstractConfigurator.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/AbstractConfigurator.java Thu Apr  5 16:19:19 2012
@@ -21,8 +21,10 @@ package org.apache.fop.render;
 
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.apache.fop.apps.FOUserAgent;
 
 /**

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java Thu Apr  5 16:19:19 2012
@@ -148,7 +148,10 @@ public abstract class AbstractGraphics2D
             RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
     }
 
-    /** {@inheritDoc} */
+    /**
+     * {@inheritDoc}
+     * @deprecated
+     */
     public void paintImage(Graphics2DImagePainter painter,
             RendererContext context,
             int x, int y, int width, int height) throws IOException {



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