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 [9/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/apac...

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/parser/UnparsedStructuredField.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/parser/UnparsedStructuredField.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/parser/UnparsedStructuredField.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/parser/UnparsedStructuredField.java Thu Apr  5 16:19:19 2012
@@ -19,337 +19,331 @@
 
 package org.apache.fop.afp.parser;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.DataInputStream;
-import java.io.EOFException;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.PrintStream;
 import java.text.DecimalFormat;
 
-import org.apache.commons.io.HexDump;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 /**
- * Represents an unparsed (generic) AFP structured field.
- */
-public class UnparsedStructuredField {
-
-    private static final Log LOG = LogFactory.getLog(UnparsedStructuredField.class);
-
-    private static final int INTRODUCER_LENGTH = 8;
-
-    private short sfLength;
-    private byte sfClassCode;
-    private byte sfTypeCode;
-    private byte sfCategoryCode;
-    private boolean sfiExtensionPresent;
-    private boolean sfiSegmentedData;
-    private boolean sfiPaddingPresent;
-    private short extLength;
-    private byte[] introducerData;
-    private byte[] extData;
-    private byte[] data;
-
-    /**
-     * Default constructor.
-     */
-    public UnparsedStructuredField() {
-        //nop
-    }
-
-    /**
-     * Reads a structured field from a {@link DataInputStream}. The resulting object can be
-     * further interpreted be follow-up code.
-     * @param din the stream to read from
-     * @return the generic structured field
-     * @throws IOException if an I/O error occurs
-     */
-    public static UnparsedStructuredField readStructuredField(DataInputStream din)
-            throws IOException {
-        UnparsedStructuredField sf = new UnparsedStructuredField();
-
-        //Read introducer as byte array to preserve any data not parsed below
-        din.mark(INTRODUCER_LENGTH);
-        sf.introducerData = new byte[INTRODUCER_LENGTH]; //Length of introducer
-        din.readFully(sf.introducerData);
-        din.reset();
-
-        //Parse the introducer
-        short len;
-        try {
-            len = din.readShort();
-        } catch (EOFException eof) {
-            return null;
-        }
-        sf.sfLength = len;
-        sf.sfClassCode = din.readByte();
-        sf.sfTypeCode = din.readByte();
-        sf.sfCategoryCode = din.readByte();
-
-        //Flags
-        byte f = din.readByte();
-        sf.sfiExtensionPresent = (f & 0x01) != 0;
-        sf.sfiSegmentedData = (f & 0x04) != 0;
-        sf.sfiPaddingPresent = (f & 0x10) != 0;
-        din.skip(2); //Reserved
-
-        int dataLength = sf.sfLength - INTRODUCER_LENGTH;
-
-        //Handle optional extension
-        if (sf.sfiExtensionPresent) {
-            sf.extLength = (short)(((short)din.readByte()) & 0xFF);
-            if (sf.extLength > 0) {
-                sf.extData = new byte[sf.extLength - 1];
-                din.readFully(sf.extData);
-                dataLength -= sf.extLength;
-            }
-        }
-
-        //Read payload
-        sf.data = new byte[dataLength];
-        din.readFully(sf.data);
-
-        if (LOG.isTraceEnabled()) {
-            LOG.trace(sf);
-        }
-
-        return sf;
-    }
-
-    /** {@inheritDoc} */
-    public String toString() {
-        StringBuffer sb = new StringBuffer("Structured Field: ");
-        sb.append(Integer.toHexString(getSfTypeID()).toUpperCase());
-        sb.append(", len=");
-        sb.append(new DecimalFormat("00000").format(getSfLength()));
-        sb.append(" ").append(getTypeCodeAsString());
-        sb.append(" ").append(getCategoryCodeAsString());
-        if (isSfiExtensionPresent()) {
-            sb.append(", SFI extension present");
-        }
-        if (isSfiSegmentedData()) {
-            sb.append(", segmented data");
-        }
-        if (isSfiPaddingPresent()) {
-            sb.append(", with padding");
-        }
-        return sb.toString();
-    }
-
-    /**
-     * Dump the structured field as hex data to the given {@link PrintStream}.
-     * @param out the {@link PrintStream} to dump to
-     * @throws IOException if an I/O error occurs
-     */
-    public void dump(PrintStream out) throws IOException {
-        out.println(toString());
-        HexDump.dump(getData(), 0, out, 0);
-    }
-
-    /**
-     * Dump the structured field as hex data to <code>System.out</code>.
-     * @throws IOException if an I/O error occurs
-     */
-    public void dump() throws IOException {
-        dump(System.out);
-    }
-
-    /**
-     * Returns type code function name for this field.
-     * @return the type code function name
-     */
-    public String getTypeCodeAsString() {
-        switch ((int)getSfTypeCode() & 0xFF) {
-        case 0xA0: return "Attribute";
-        case 0xA2: return "CopyCount";
-        case 0xA6: return "Descriptor";
-        case 0xA7: return "Control";
-        case 0xA8: return "Begin";
-        case 0xA9: return "End";
-        case 0xAB: return "Map";
-        case 0xAC: return "Position";
-        case 0xAD: return "Process";
-        case 0xAF: return "Include";
-        case 0xB0: return "Table";
-        case 0xB1: return "Migration";
-        case 0xB2: return "Variable";
-        case 0xB4: return "Link";
-        case 0xEE: return "Data";
-        default: return "Unknown:" + Integer.toHexString((int)getSfTypeCode()).toUpperCase();
-        }
-    }
-
-    /**
-     * Returns category code function name for this field.
-     * @return the category code function name
-     */
-    public String getCategoryCodeAsString() {
-        switch ((int)getSfCategoryCode() & 0xFF) {
-        case 0x5F: return "Page Segment";
-        case 0x6B: return "Object Area";
-        case 0x77: return "Color Attribute Table";
-        case 0x7B: return "IM Image";
-        case 0x88: return "Medium";
-        case 0x89: return "Font";
-        case 0x8A: return "Coded Font";
-        case 0x90: return "Process Element";
-        case 0x92: return "Object Container";
-        case 0x9B: return "Presentation Text";
-        case 0xA7: return "Index";
-        case 0xA8: return "Document";
-        case 0xAD: return "Page Group";
-        case 0xAF: return "Page";
-        case 0xBB: return "Graphics";
-        case 0xC3: return "Data Resource";
-        case 0xC4: return "Document Environment Group (DEG)";
-        case 0xC6: return "Resource Group";
-        case 0xC7: return "Object Environment Group (OEG)";
-        case 0xC9: return "Active Environment Group (AEG)";
-        case 0xCC: return "Medium Map";
-        case 0xCD: return "Form Map";
-        case 0xCE: return "Name Resource";
-        case 0xD8: return "Page Overlay";
-        case 0xD9: return "Resource Environment Group (REG)";
-        case 0xDF: return "Overlay";
-        case 0xEA: return "Data Supression";
-        case 0xEB: return "Bar Code";
-        case 0xEE: return "No Operation";
-        case 0xFB: return "Image";
-        default: return "Unknown:" + Integer.toHexString((int)getSfTypeCode()).toUpperCase();
-        }
-    }
-
-    /**
-     * Returns the structured field's length.
-     * @return the field length
-     */
-    public short getSfLength() {
-        return this.sfLength;
-    }
-
-    /**
-     * Returns the structured field's identifier.
-     * @return the field identifier
-     */
-    public int getSfTypeID() {
-        return ((getSfClassCode() & 0xFF) << 16)
-                | ((getSfTypeCode() & 0xFF) << 8)
-                | (getSfCategoryCode() & 0xFF);
-    }
-
-    /**
-     * Returns the structured field's class code.
-     * @return the field class code
-     */
-    public byte getSfClassCode() {
-        return this.sfClassCode;
-    }
-
-    /**
-     * Returns the structured field's type code.
-     * @return the type code
-     */
-    public byte getSfTypeCode() {
-        return this.sfTypeCode;
-    }
-
-    /**
-     * Returns the structured field's category code.
-     * @return the sfCategoryCode
-     */
-    public byte getSfCategoryCode() {
-        return this.sfCategoryCode;
-    }
-
-    /**
-     * Indicates whether an field introducer extension is present.
-     * @return true if an field introducer extension is present
-     */
-    public boolean isSfiExtensionPresent() {
-        return this.sfiExtensionPresent && (this.extData != null);
-    }
-
-    /**
-     * Indicates whether segmented data is present.
-     * @return true if the data is segmented
-     */
-    public boolean isSfiSegmentedData() {
-        return this.sfiSegmentedData;
-    }
-
-    /**
-     * Indicates whether the data is padded.
-     * @return true if the data is padded
-     */
-    public boolean isSfiPaddingPresent() {
-        return this.sfiPaddingPresent;
-    }
-
-    /**
-     * Returns the length of the extension if present.
-     * @return the length of the extension (or 0 if no extension is present)
-     */
-    public short getExtLength() {
-        return this.extLength;
-    }
-
-    /**
-     * Returns the extension data if present.
-     * @return the extension data (or null if no extension is present)
-     */
-    public byte[] getExtData() {
-        return this.extData;
-    }
-
-    /**
-     * Returns the structured field's payload.
-     * @return the field's data
-     */
-    public byte[] getData() {
-        return this.data;
-    }
-
-    /**
-     * Returns the structured field's introducer data.
-     * @return the introducer data
-     */
-    public byte[] getIntroducerData() {
-        return this.introducerData;
-    }
-
-    /**
-     * Returns the complete structured field as a byte array.
-     * @return the complete field data
-     */
-    public byte[] getCompleteFieldAsBytes() {
-        int len = INTRODUCER_LENGTH;
-        if (isSfiExtensionPresent()) {
-            len += getExtLength();
-        }
-        len += getData().length;
-        byte[] bytes = new byte[len];
-        int pos = 0;
-        System.arraycopy(getIntroducerData(), 0, bytes, pos, INTRODUCER_LENGTH);
-        pos += INTRODUCER_LENGTH;
-        if (isSfiExtensionPresent()) {
-            System.arraycopy(getExtData(), 0, bytes, pos, getExtLength());
-            pos += getExtLength();
-        }
-        System.arraycopy(getData(), 0, bytes, pos, getData().length);
-        return bytes;
-    }
-
-    /**
-     * Writes this structured field to the given {@link OutputStream}.
-     * @param out the output stream
-     * @throws IOException if an I/O error occurs
-     */
-    public void writeTo(OutputStream out) throws IOException {
-        out.write(this.introducerData);
-        if (isSfiExtensionPresent()) {
-            out.write(this.extData);
-        }
-        out.write(this.data);
-    }
+* Represents an unparsed (generic) AFP structured field.
+*/
+public final class UnparsedStructuredField {
+
+   private final Introducer introducer;
+   private final byte[] extData;
+   private final byte[] data;
+
+   /**
+    *
+    * @param Structured field introducer
+    * @param data Structured field data
+    * @param extData Structured field extension data
+    */
+   UnparsedStructuredField(Introducer introducer,
+           byte[] data, byte[] extData) {
+       this.introducer = introducer;
+       this.data = data;
+       if (extData != null) {
+           this.extData = extData;
+       } else {
+           this.extData = null;
+       }
+   }
+
+   @Override
+   public String toString() {
+       StringBuffer sb = new StringBuffer("Structured Field: ");
+       sb.append(Integer.toHexString(getSfTypeID()).toUpperCase());
+       sb.append(", len=");
+       sb.append(new DecimalFormat("00000").format(getSfLength()));
+       sb.append(" ").append(getTypeCodeAsString());
+       sb.append(" ").append(getCategoryCodeAsString());
+       if (isSfiExtensionPresent()) {
+           sb.append(", SFI extension present");
+       }
+       if (isSfiSegmentedData()) {
+           sb.append(", segmented data");
+       }
+       if (isSfiPaddingPresent()) {
+           sb.append(", with padding");
+       }
+       return sb.toString();
+   }
+
+
+   /**
+    * Returns type code function name for this field.
+    * @return the type code function name
+    */
+   private String getTypeCodeAsString() {
+       switch (getSfTypeCode() & 0xFF) {
+       case 0xA0: return "Attribute";
+       case 0xA2: return "CopyCount";
+       case 0xA6: return "Descriptor";
+       case 0xA7: return "Control";
+       case 0xA8: return "Begin";
+       case 0xA9: return "End";
+       case 0xAB: return "Map";
+       case 0xAC: return "Position";
+       case 0xAD: return "Process";
+       case 0xAF: return "Include";
+       case 0xB0: return "Table";
+       case 0xB1: return "Migration";
+       case 0xB2: return "Variable";
+       case 0xB4: return "Link";
+       case 0xEE: return "Data";
+       default: return "Unknown:" + Integer.toHexString(getSfTypeCode()).toUpperCase();
+       }
+   }
+
+   /**
+    * Returns category code function name for this field.
+    * @return the category code function name
+    */
+   private String getCategoryCodeAsString() {
+       switch (getSfCategoryCode() & 0xFF) {
+       case 0x5F: return "Page Segment";
+       case 0x6B: return "Object Area";
+       case 0x77: return "Color Attribute Table";
+       case 0x7B: return "IM Image";
+       case 0x88: return "Medium";
+       case 0x89: return "Font";
+       case 0x8A: return "Coded Font";
+       case 0x90: return "Process Element";
+       case 0x92: return "Object Container";
+       case 0x9B: return "Presentation Text";
+       case 0xA7: return "Index";
+       case 0xA8: return "Document";
+       case 0xAD: return "Page Group";
+       case 0xAF: return "Page";
+       case 0xBB: return "Graphics";
+       case 0xC3: return "Data Resource";
+       case 0xC4: return "Document Environment Group (DEG)";
+       case 0xC6: return "Resource Group";
+       case 0xC7: return "Object Environment Group (OEG)";
+       case 0xC9: return "Active Environment Group (AEG)";
+       case 0xCC: return "Medium Map";
+       case 0xCD: return "Form Map";
+       case 0xCE: return "Name Resource";
+       case 0xD8: return "Page Overlay";
+       case 0xD9: return "Resource Environment Group (REG)";
+       case 0xDF: return "Overlay";
+       case 0xEA: return "Data Supression";
+       case 0xEB: return "Bar Code";
+       case 0xEE: return "No Operation";
+       case 0xFB: return "Image";
+       default: return "Unknown:" + Integer.toHexString(getSfTypeCode()).toUpperCase();
+       }
+   }
+
+   /**
+    * Returns the structured field's length.
+    * @return the field length
+    */
+   public short getSfLength() {
+       return introducer.length;
+   }
+
+   /**
+    * Returns the structured field's identifier.
+    * @return the field identifier
+    */
+   public int getSfTypeID() {
+       return ((getSfClassCode() & 0xFF) << 16)
+       | ((getSfTypeCode() & 0xFF) << 8)
+       | (getSfCategoryCode() & 0xFF);
+   }
+
+   /**
+    * Returns the structured field's class code.
+    * @return the field class code
+    */
+   public byte getSfClassCode() {
+       return introducer.classCode;
+   }
+
+   /**
+    * Returns the structured field's type code.
+    * @return the type code
+    */
+   public byte getSfTypeCode() {
+       return introducer.typeCode;
+   }
+
+   /**
+    * Returns the structured field's category code.
+    * @return the sfCategoryCode
+    */
+   public byte getSfCategoryCode() {
+       return introducer.categoryCode;
+   }
+
+   /**
+    * Indicates whether an field introducer extension is present.
+    * @return true if an field introducer extension is present
+    */
+   public boolean isSfiExtensionPresent() {
+       return introducer.extensionPresent && (this.extData != null);
+   }
+
+   /**
+    * Indicates whether segmented data is present.
+    * @return true if the data is segmented
+    */
+   public boolean isSfiSegmentedData() {
+       return introducer.segmentedData;
+   }
+
+   /**
+    * Indicates whether the data is padded.
+    * @return true if the data is padded
+    */
+   public boolean isSfiPaddingPresent() {
+       return introducer.paddingPresent;
+   }
+
+   /**
+    * Returns the length of the extension if present.
+    * @return the length of the extension (or 0 if no extension is present)
+    */
+   public short getExtLength() {
+       return (extData != null) ? (short)(extData.length + 1) : 0;
+
+   }
+
+   /**
+    * Returns the extension data if present.
+    * @return the extension data (or null if no extension is present)
+    */
+   byte[] getExtData() {
+       if (this.extData == null) {
+           return new byte[0];
+       }
+       byte[] rtn = new byte[this.extData.length];
+       System.arraycopy(this.extData, 0, rtn, 0, rtn.length);
+       return rtn;
+   }
+
+   /**
+    * Returns the structured field's payload.
+    * @return the field's data
+    */
+   public byte[] getData() {
+       if (this.data == null) {
+           return new byte[0];
+       }
+       byte[] rtn = new byte[this.data.length];
+       System.arraycopy(this.data, 0, rtn, 0, rtn.length);
+       return rtn;
+   }
+
+   //For unit testing
+   byte[] getIntroducerData() {
+       return introducer.getIntroducerData();
+   }
+
+   /**
+    * Returns the complete structured field as a byte array.
+    * @return the complete field data
+    */
+   public byte[] getCompleteFieldAsBytes() {
+
+       ByteArrayOutputStream baos = new ByteArrayOutputStream(getSfLength());
+       try {
+           writeTo(baos);
+       } catch (IOException ioe) {
+           //nop
+       }
+       return baos.toByteArray();
+
+   }
+
+   /**
+    * Writes this structured field to the given {@link OutputStream}.
+    * @param out the output stream
+    * @throws IOException if an I/O error occurs
+    */
+   public void writeTo(OutputStream out) throws IOException {
+       out.write(introducer.introducerData);
+       if (isSfiExtensionPresent()) {
+           out.write(this.extData.length + 1);
+           out.write(this.extData);
+       }
+       out.write(this.data);
+   }
+
+   static final class Introducer {
+
+       private final short length;
+       private final byte classCode;
+       private final byte typeCode;
+       private final byte categoryCode;
+       private final boolean extensionPresent;
+       private final boolean segmentedData;
+       private final boolean paddingPresent;
+       private final byte[] introducerData;
+
+       Introducer(byte[] introducerData) throws IOException {
+
+           this.introducerData = introducerData;
+
+           // Parse the introducer; the 8 bytes have already been read from the stream just
+           // before, so we parse the introducer from the byte array
+           DataInputStream iis = new DataInputStream(
+                   new ByteArrayInputStream(introducerData));
+
+           length = iis.readShort();
+
+           classCode = iis.readByte();
+           typeCode = iis.readByte();
+           categoryCode = iis.readByte();
+
+           //Flags
+           byte f = iis.readByte();
+
+           extensionPresent = (f & 0x01) != 0;
+           segmentedData = (f & 0x04) != 0;
+           paddingPresent = (f & 0x10) != 0;
+
+       }
+
+
+       public short getLength() {
+           return length;
+       }
+
+       public byte getClassCode() {
+           return classCode;
+       }
+
+       public byte getTypeCode() {
+           return typeCode;
+       }
+
+       public byte getCategoryCode() {
+           return categoryCode;
+       }
+
+       public boolean isExtensionPresent() {
+           return extensionPresent;
+       }
+
+
+       public boolean isSegmentedData() {
+           return segmentedData;
+       }
+
+       public boolean isPaddingPresent() {
+           return paddingPresent;
+       }
+
+       public byte[] getIntroducerData() {
+           byte[] rtn = new byte[introducerData.length];
+           System.arraycopy(introducerData, 0, rtn, 0, rtn.length);
+           return rtn;
+       }
+   }
+
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/ptoca/PtocaBuilder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/ptoca/PtocaBuilder.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/ptoca/PtocaBuilder.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/ptoca/PtocaBuilder.java Thu Apr  5 16:19:19 2012
@@ -26,6 +26,12 @@ import java.io.OutputStream;
 
 import org.apache.commons.io.output.ByteArrayOutputStream;
 
+import org.apache.xmlgraphics.java2d.color.CIELabColorSpace;
+import org.apache.xmlgraphics.java2d.color.ColorUtil;
+import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives;
+
+import org.apache.fop.afp.fonts.CharactersetEncoder.EncodedChars;
+
 /**
  * Generator class for PTOCA data structures.
  */
@@ -81,10 +87,6 @@ public abstract class PtocaBuilder imple
         baout.writeTo(out);
     }
 
-    private void write(byte[] data, int offset, int length) {
-        baout.write(data, offset, length);
-    }
-
     private void writeByte(int data) {
         baout.write(data);
     }
@@ -176,44 +178,34 @@ public abstract class PtocaBuilder imple
         currentX = -1;
     }
 
-    private static final int TRANSPARENT_MAX_SIZE = 253;
-
     /**
      * The Transparent Data control sequence contains a sequence of code points
      * that are presented without a scan for embedded control sequences. If the data is larger
      * than fits in one chunk, additional chunks are automatically generated.
      *
-     * @param data The text data to add.
+     * @param encodedChars The encoded text data to add.
      * @throws IOException if an I/O error occurs
      */
-    public void addTransparentData(byte[] data) throws IOException {
-        if (data.length <= TRANSPARENT_DATA_MAX_SIZE) {
-            addTransparentDataChunk(data);
-        } else {
-            // data size greater than TRANSPARENT_MAX_SIZE, so slice
-            int numTransData = data.length / TRANSPARENT_DATA_MAX_SIZE;
-            int currIndex = 0;
-            for (int transDataCnt = 0; transDataCnt < numTransData; transDataCnt++) {
-                addTransparentDataChunk(data, currIndex, TRANSPARENT_DATA_MAX_SIZE);
-                currIndex += TRANSPARENT_DATA_MAX_SIZE;
-            }
-            int left = data.length - currIndex;
-            addTransparentDataChunk(data, currIndex, left);
+    public void addTransparentData(EncodedChars encodedChars) throws IOException {
+
+        // data size greater than TRANSPARENT_MAX_SIZE, so slice
+        int numTransData = encodedChars.getLength() / TRANSPARENT_DATA_MAX_SIZE;
+        int currIndex = 0;
+        for (int transDataCnt = 0; transDataCnt < numTransData; transDataCnt++) {
+            addTransparentDataChunk(encodedChars, currIndex, TRANSPARENT_DATA_MAX_SIZE);
+            currIndex += TRANSPARENT_DATA_MAX_SIZE;
         }
-    }
+        int left = encodedChars.getLength() - currIndex;
+        addTransparentDataChunk(encodedChars, currIndex, left);
 
-    private void addTransparentDataChunk(byte[] data) throws IOException {
-        addTransparentDataChunk(data, 0, data.length);
     }
 
-    private void addTransparentDataChunk(byte[] data, int offset, int length) throws IOException {
-        if (length > TRANSPARENT_MAX_SIZE) {
-            // Check that we are not exceeding the maximum length
-            throw new IllegalArgumentException(
-                    "Transparent data is longer than " + TRANSPARENT_MAX_SIZE + " bytes");
-        }
+
+
+    private void addTransparentDataChunk(EncodedChars encodedChars, int offset, int length)
+            throws IOException {
         newControlSequence();
-        write(data, offset, length);
+        encodedChars.writeTo(baout, offset, length);
         commit(chained(TRN));
     }
 
@@ -311,9 +303,18 @@ public abstract class PtocaBuilder imple
      * @throws IOException if an I/O error occurs
      */
     public void setExtendedTextColor(Color col) throws IOException {
-        if (col.equals(currentColor)) {
+        if (ColorUtil.isSameColor(col, currentColor)) {
             return;
         }
+        if (col instanceof ColorWithAlternatives) {
+            ColorWithAlternatives cwa = (ColorWithAlternatives)col;
+            Color alt = cwa.getFirstAlternativeOfType(ColorSpace.TYPE_CMYK);
+            if (alt != null) {
+                col = alt;
+            }
+        }
+        ColorSpace cs = col.getColorSpace();
+
         newControlSequence();
         if (col.getColorSpace().getType() == ColorSpace.TYPE_CMYK) {
             writeByte(0x00); // Reserved; must be zero
@@ -332,6 +333,25 @@ public abstract class PtocaBuilder imple
                 int component = Math.round(comps[i] * 255);
                 writeByte(component);
             }
+        } else if (cs instanceof CIELabColorSpace) {
+            writeByte(0x00); // Reserved; must be zero
+            writeByte(0x08); // Color space - 0x08 = CIELAB
+            writeByte(0x00); // Reserved; must be zero
+            writeByte(0x00); // Reserved; must be zero
+            writeByte(0x00); // Reserved; must be zero
+            writeByte(0x00); // Reserved; must be zero
+            writeByte(8); // Number of bits in component 1
+            writeByte(8); // Number of bits in component 2
+            writeByte(8); // Number of bits in component 3
+            writeByte(0); // Number of bits in component 4
+            //Sadly, 16 bit components don't seem to work
+            float[] colorComponents = col.getColorComponents(null);
+            int l = Math.round(colorComponents[0] * 255f);
+            int a = Math.round(colorComponents[1] * 255f) - 128;
+            int b = Math.round(colorComponents[2] * 255f) - 128;
+            writeByte(l); // L*
+            writeByte(a); // a*
+            writeByte(b); // b*
         } else {
             writeByte(0x00); // Reserved; must be zero
             writeByte(0x01); // Color space - 0x01 = RGB

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/ptoca/PtocaProducer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/ptoca/PtocaProducer.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/ptoca/PtocaProducer.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/ptoca/PtocaProducer.java Thu Apr  5 16:19:19 2012
@@ -21,8 +21,6 @@ package org.apache.fop.afp.ptoca;
 
 import java.io.IOException;
 
-import org.apache.fop.afp.modca.PresentationTextObject;
-
 /**
  * Producer interface that is passed to a {@link PresentationTextObject} to produce PTOCA control
  * sequences using a {@link PtocaBuilder}.

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/ptoca/TextDataInfoProducer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/ptoca/TextDataInfoProducer.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/ptoca/TextDataInfoProducer.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/ptoca/TextDataInfoProducer.java Thu Apr  5 16:19:19 2012
@@ -22,6 +22,7 @@ package org.apache.fop.afp.ptoca;
 import java.io.IOException;
 
 import org.apache.fop.afp.AFPTextDataInfo;
+import org.apache.fop.afp.fonts.CharactersetEncoder;
 
 /**
  * {@link PtocaProducer} implementation that interprets {@link AFPTextDataInfo} objects.
@@ -55,8 +56,7 @@ public class TextDataInfoProducer implem
         // Add transparent data
         String textString = textDataInfo.getString();
         String encoding = textDataInfo.getEncoding();
-        byte[] data = textString.getBytes(encoding);
-        builder.addTransparentData(data);
+        builder.addTransparentData(CharactersetEncoder.encodeSBCS(textString, encoding, false));
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/svg/AFPBridgeContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/svg/AFPBridgeContext.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/svg/AFPBridgeContext.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/svg/AFPBridgeContext.java Thu Apr  5 16:19:19 2012
@@ -25,11 +25,13 @@ import org.apache.batik.bridge.BridgeCon
 import org.apache.batik.bridge.DocumentLoader;
 import org.apache.batik.bridge.UserAgent;
 import org.apache.batik.gvt.TextPainter;
+
+import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+
 import org.apache.fop.afp.AFPGraphics2D;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.svg.AbstractFOPBridgeContext;
-import org.apache.xmlgraphics.image.loader.ImageManager;
-import org.apache.xmlgraphics.image.loader.ImageSessionContext;
 
 /**
  * An AFP specific implementation of a Batik BridgeContext
@@ -79,11 +81,12 @@ public class AFPBridgeContext extends Ab
     }
 
     /** {@inheritDoc} */
+    @Override
     public void registerSVGBridges() {
         super.registerSVGBridges();
 
         if (fontInfo != null) {
-            AFPTextHandler textHandler = new AFPTextHandler(fontInfo);
+            AFPTextHandler textHandler = new AFPTextHandler(fontInfo, g2d.getResourceManager());
             g2d.setCustomTextHandler(textHandler);
 
             TextPainter textPainter = new AFPTextPainter(textHandler);
@@ -96,6 +99,7 @@ public class AFPBridgeContext extends Ab
     }
 
     /** {@inheritDoc} */
+    @Override
     public BridgeContext createBridgeContext() {
         return new AFPBridgeContext(getUserAgent(), getDocumentLoader(),
                 fontInfo,

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/svg/AFPTextElementBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/svg/AFPTextElementBridge.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/svg/AFPTextElementBridge.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/svg/AFPTextElementBridge.java Thu Apr  5 16:19:19 2012
@@ -20,6 +20,7 @@
 package org.apache.fop.afp.svg;
 
 import org.apache.batik.gvt.TextPainter;
+
 import org.apache.fop.svg.AbstractFOPTextElementBridge;
 
 /**

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/svg/AFPTextHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/svg/AFPTextHandler.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/svg/AFPTextHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/svg/AFPTextHandler.java Thu Apr  5 16:19:19 2012
@@ -21,15 +21,18 @@ package org.apache.fop.afp.svg;
 
 import java.awt.Color;
 import java.awt.Graphics2D;
+import java.io.IOException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.fop.afp.AFPGraphics2D;
 import org.apache.fop.afp.AFPPaintingState;
+import org.apache.fop.afp.AFPResourceManager;
 import org.apache.fop.afp.fonts.AFPFont;
 import org.apache.fop.afp.fonts.AFPFontAttributes;
 import org.apache.fop.afp.fonts.AFPPageFonts;
+import org.apache.fop.afp.fonts.CharacterSet;
 import org.apache.fop.afp.modca.GraphicsObject;
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontInfo;
@@ -50,13 +53,18 @@ public class AFPTextHandler extends FOPT
     /** Font information */
     private final FontInfo fontInfo;
 
+    /** the resource manager */
+    private AFPResourceManager resourceManager;
+
     /**
      * Main constructor.
      *
      * @param fontInfo the AFPGraphics2D instance
+     * @param resourceManager the AFPResourceManager instance
      */
-    public AFPTextHandler(FontInfo fontInfo) {
+    public AFPTextHandler(FontInfo fontInfo, AFPResourceManager resourceManager) {
         this.fontInfo = fontInfo;
+        this.resourceManager = resourceManager;
     }
 
     /**
@@ -83,6 +91,14 @@ public class AFPTextHandler extends FOPT
                 afpFont,
                 fontSize
         );
+        if (afpFont.isEmbeddable()) {
+            try {
+                final CharacterSet charSet = afpFont.getCharacterSet(fontSize);
+                this.resourceManager.embedFont(afpFont, charSet);
+            } catch (IOException ioe) {
+                throw new RuntimeException("Error while embedding font resources", ioe);
+            }
+        }
         return afpFontAttributes.getFontReference();
     }
 
@@ -92,6 +108,7 @@ public class AFPTextHandler extends FOPT
      *
      * {@inheritDoc}
      */
+    @Override
     public void drawString(Graphics2D g, String str, float x, float y) {
         if (log.isDebugEnabled()) {
             log.debug("drawString() str=" + str + ", x=" + x + ", y=" + y);
@@ -115,19 +132,30 @@ public class AFPTextHandler extends FOPT
             if (overrideFont != null) {
                 internalFontName = overrideFont.getFontName();
                 fontSize = overrideFont.getFontSize();
+                if (log.isDebugEnabled()) {
+                    log.debug("  with overriding font: " + internalFontName + ", " + fontSize);
+                }
             } else {
                 java.awt.Font awtFont = g2d.getFont();
                 Font fopFont = fontInfo.getFontInstanceForAWTFont(awtFont);
+                if (log.isDebugEnabled()) {
+                    log.debug("  with font: " + fopFont);
+                }
                 internalFontName = fopFont.getFontName();
                 fontSize = fopFont.getFontSize();
             }
             fontSize = (int)Math.round(
                     g2d.convertToAbsoluteLength(fontSize));
             fontReference = registerPageFont(pageFonts, internalFontName, fontSize);
+            // TODO: re-think above registerPageFont code...
+            AFPFont afpFont = (AFPFont) fontInfo.getFonts().get(internalFontName);
+            final CharacterSet charSet = afpFont.getCharacterSet(fontSize);
+            // Work-around for InfoPrint's AFP which loses character set state
+            // over Graphics Data
+            // boundaries.
             graphicsObj.setCharacterSet(fontReference);
-
             // add the character string
-            graphicsObj.addString(str, Math.round(x), Math.round(y));
+            graphicsObj.addString(str, Math.round(x), Math.round(y), charSet);
         } else {
             //Inside Batik's SVG filter operations, you won't get an AFPGraphics2D
             g.drawString(str, x, y);

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/AFPResourceUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/AFPResourceUtil.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/AFPResourceUtil.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/AFPResourceUtil.java Thu Apr  5 16:19:19 2012
@@ -29,8 +29,8 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.fop.afp.AFPConstants;
-import org.apache.fop.afp.modca.ResourceObject;
 import org.apache.fop.afp.modca.AbstractAFPObject.Category;
+import org.apache.fop.afp.modca.ResourceObject;
 import org.apache.fop.afp.parser.MODCAParser;
 import org.apache.fop.afp.parser.UnparsedStructuredField;
 
@@ -92,10 +92,13 @@ public final class AFPResourceUtil {
             throws UnsupportedEncodingException {
         //The first 8 bytes of the field data represent the resource name
         byte[] nameBytes = new byte[8];
-        System.arraycopy(field.getData(), 0, nameBytes, 0, 8);
-        String asciiName;
-        asciiName = new String(nameBytes, AFPConstants.EBCIDIC_ENCODING);
-        return asciiName;
+
+        byte[] fieldData = field.getData();
+        if (fieldData.length < 8) {
+            throw new IllegalArgumentException("Field data does not contain a resource name");
+        }
+        System.arraycopy(fieldData, 0, nameBytes, 0, 8);
+        return new String(nameBytes, AFPConstants.EBCIDIC_ENCODING);
     }
 
     /**
@@ -128,12 +131,13 @@ public final class AFPResourceUtil {
     public static void copyNamedResource(String name,
             final InputStream in, final OutputStream out) throws IOException {
         final MODCAParser parser = new MODCAParser(in);
-        Collection resourceNames = new java.util.HashSet();
+        Collection<String> resourceNames = new java.util.HashSet<String>();
 
         //Find matching "Begin" field
         final UnparsedStructuredField fieldBegin;
         while (true) {
-            UnparsedStructuredField field = parser.readNextStructuredField();
+            final UnparsedStructuredField field = parser.readNextStructuredField();
+
             if (field == null) {
                 throw new IOException("Requested resource '" + name
                         + "' not found. Encountered resource names: " + resourceNames);
@@ -142,8 +146,10 @@ public final class AFPResourceUtil {
             if (field.getSfTypeCode() != TYPE_CODE_BEGIN) { //0xA8=Begin
                 continue; //Not a "Begin" field
             }
-            String resourceName = getResourceName(field);
+            final String resourceName = getResourceName(field);
+
             resourceNames.add(resourceName);
+
             if (resourceName.equals(name)) {
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Start of requested structured field found:\n"
@@ -170,45 +176,35 @@ public final class AFPResourceUtil {
         if (wrapInResource) {
             ResourceObject resourceObject =  new ResourceObject(name) {
                 protected void writeContent(OutputStream os) throws IOException {
-                    copyStructuredFields(name, fieldBegin, parser, out);
+                    copyNamedStructuredFields(name, fieldBegin, parser, out);
                 }
             };
             resourceObject.setType(ResourceObject.TYPE_PAGE_SEGMENT);
             resourceObject.writeToStream(out);
         } else {
-            copyStructuredFields(name, fieldBegin, parser, out);
+            copyNamedStructuredFields(name, fieldBegin, parser, out);
         }
     }
 
-    private static void copyStructuredFields(String name, UnparsedStructuredField fieldBegin,
-            MODCAParser parser, OutputStream out) throws IOException {
-        boolean inRequestedResource;
+    private static void copyNamedStructuredFields(final String name,
+            UnparsedStructuredField fieldBegin, MODCAParser parser,
+            OutputStream out) throws IOException {
 
-        //The "Begin" field first
-        out.write(MODCAParser.CARRIAGE_CONTROL_CHAR);
-        fieldBegin.writeTo(out);
-        UnparsedStructuredField field;
+        UnparsedStructuredField field = fieldBegin;
 
-        //Then the rest of the fields until the corresponding "End" field
-        inRequestedResource = true;
-        do {
-            field = parser.readNextStructuredField();
+        while (true) {
             if (field == null) {
-                break; //Unexpected EOF
-            }
-
-            if (field.getSfTypeCode() == TYPE_CODE_END) {
-                String resourceName = getResourceName(field);
-                if (resourceName.equals(name)) {
-                    inRequestedResource = false; //Signal end of loop
-                }
+                throw new IOException("Ending structured field not found for resource " + name);
             }
             out.write(MODCAParser.CARRIAGE_CONTROL_CHAR);
             field.writeTo(out);
-        } while (inRequestedResource);
-        if (inRequestedResource) {
-            throw new IOException("Ending structured field not found for resource " + name);
+
+            if (field.getSfTypeCode() == TYPE_CODE_END
+                    && fieldBegin.getSfCategoryCode() == field.getSfCategoryCode()
+                    && name.equals(getResourceName(field))) {
+                break;
+            }
+            field = parser.readNextStructuredField();
         }
     }
-
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/DTDEntityResolver.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/DTDEntityResolver.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/DTDEntityResolver.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/DTDEntityResolver.java Thu Apr  5 16:19:19 2012
@@ -22,17 +22,19 @@ package org.apache.fop.afp.util;
 import java.io.IOException;
 import java.net.URL;
 
-import org.apache.fop.afp.fonts.FontRuntimeException;
 import org.xml.sax.EntityResolver;
 import org.xml.sax.InputSource;
 
+import org.apache.fop.afp.fonts.FontRuntimeException;
+
 /**
  * An entity resolver for both DOM and SAX models of the SAX document.
  * <p>
  * The entity resolver only handles queries for the DTD. It will find any URI
  * with a recognised public id and return an {@link org.xml.sax.InputSource}.
  * <p>
- * @author <a href="mailto:joe@exubero.com">Joe Schmetzer</a>
+ *
+ * <p>This work was authored by Joe Schmetzer (joe@exubero.com).</p>
  */
 public class DTDEntityResolver implements EntityResolver {
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/DefaultFOPResourceAccessor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/DefaultFOPResourceAccessor.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/DefaultFOPResourceAccessor.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/DefaultFOPResourceAccessor.java Thu Apr  5 16:19:19 2012
@@ -31,8 +31,6 @@ import javax.xml.transform.stream.Stream
 import org.apache.commons.io.IOUtils;
 
 import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.FopFactory;
-import org.apache.fop.fonts.FontManager;
 
 /**
  * Default implementation of the {@link ResourceAccessor} interface for use inside FOP.

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/StringUtils.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/StringUtils.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/StringUtils.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/afp/util/StringUtils.java Thu Apr  5 16:19:19 2012
@@ -81,4 +81,4 @@ public final class StringUtils {
         }
     }
 
-}
\ No newline at end of file
+}

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FOURIResolver.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FOURIResolver.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FOURIResolver.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FOURIResolver.java Thu Apr  5 16:19:19 2012
@@ -183,7 +183,8 @@ public class FOURIResolver implements ja
         if (source == null) {
             URL absoluteURL = null;
             int hashPos = href.indexOf('#');
-            String fileURL, fragment;
+            String fileURL;
+            String fragment;
             if (hashPos >= 0) {
                 fileURL = href.substring(0, hashPos);
                 fragment = href.substring(hashPos);

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FOUserAgent.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FOUserAgent.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FOUserAgent.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FOUserAgent.java Thu Apr  5 16:19:19 2012
@@ -39,7 +39,8 @@ import org.apache.xmlgraphics.util.UnitC
 
 import org.apache.fop.Version;
 import org.apache.fop.accessibility.Accessibility;
-import org.apache.fop.accessibility.StructureTree;
+import org.apache.fop.accessibility.DummyStructureTreeEventHandler;
+import org.apache.fop.accessibility.StructureTreeEventHandler;
 import org.apache.fop.events.DefaultEventBroadcaster;
 import org.apache.fop.events.Event;
 import org.apache.fop.events.EventBroadcaster;
@@ -47,7 +48,6 @@ import org.apache.fop.events.EventListen
 import org.apache.fop.events.FOPEventListenerProxy;
 import org.apache.fop.events.LoggingEventListener;
 import org.apache.fop.fo.FOEventHandler;
-import org.apache.fop.fonts.FontManager;
 import org.apache.fop.render.Renderer;
 import org.apache.fop.render.RendererFactory;
 import org.apache.fop.render.XMLHandlerRegistry;
@@ -101,8 +101,8 @@ public class FOUserAgent {
     private boolean locatorEnabled = true; // true by default (for error messages).
     private boolean conserveMemoryPolicy = false;
     private EventBroadcaster eventBroadcaster = new FOPEventBroadcaster();
-
-    private StructureTree structureTree;
+    private StructureTreeEventHandler structureTreeEventHandler
+            = DummyStructureTreeEventHandler.INSTANCE;
 
     /** Producer:  Metadata element for the system/software that produces
      * the document. (Some renderers can store this in the document.)
@@ -173,6 +173,9 @@ public class FOUserAgent {
      * @param documentHandler the document handler instance to use
      */
     public void setDocumentHandlerOverride(IFDocumentHandler documentHandler) {
+        if (isAccessibilityEnabled()) {
+            setStructureTreeEventHandler(documentHandler.getStructureTreeEventHandler());
+        }
         this.documentHandlerOverride = documentHandler;
 
     }
@@ -650,6 +653,24 @@ public class FOUserAgent {
     }
 
     /**
+     * Check whether complex script features are enabled.
+     *
+     * @return true if FOP is to use complex script features
+     */
+    public boolean isComplexScriptFeaturesEnabled() {
+        return factory.isComplexScriptFeaturesEnabled();
+    }
+
+    /**
+     * Control whether complex script features should be enabled
+     *
+     * @param useComplexScriptFeatures true if FOP is to use complex script features
+     */
+    public void setComplexScriptFeaturesEnabled(boolean useComplexScriptFeatures) {
+        factory.setComplexScriptFeaturesEnabled ( useComplexScriptFeatures );
+    }
+
+    /**
      * Activates accessibility (for output formats that support it).
      *
      * @param accessibility <code>true</code> to enable accessibility support
@@ -674,24 +695,23 @@ public class FOUserAgent {
     }
 
     /**
-     * Sets the document's structure tree, for use by accessible output formats.
+     * Sets the document's structure tree event handler, for use by accessible
+     * output formats.
      *
-     * @param structureTree a simplified version of the FO tree, retaining only
-     * its logical structure
+     * @param structureTreeEventHandler The structure tree event handler to set
      */
-    public void setStructureTree(StructureTree structureTree) {
-        this.structureTree = structureTree;
+    public void setStructureTreeEventHandler(StructureTreeEventHandler structureTreeEventHandler) {
+        this.structureTreeEventHandler = structureTreeEventHandler;
     }
 
     /**
-     * Returns the document's structure tree, for use by accessible output
-     * formats.
+     * Returns the document's structure tree event handler, for use by
+     * accessible output formats.
      *
-     * @return a simplified version of the FO tree, retaining only its logical
-     * structure
+     * @return The structure tree event handler
      */
-    public StructureTree getStructureTree() {
-        return this.structureTree;
+    public StructureTreeEventHandler getStructureTreeEventHandler() {
+        return this.structureTreeEventHandler;
     }
 }
 

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/Fop.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/Fop.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/Fop.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/Fop.java Thu Apr  5 16:19:19 2012
@@ -24,7 +24,6 @@ import java.io.OutputStream;
 
 import org.xml.sax.helpers.DefaultHandler;
 
-import org.apache.fop.accessibility.Accessibility;
 import org.apache.fop.fo.FOTreeBuilder;
 
 /**
@@ -111,11 +110,7 @@ public class Fop {
         if (foTreeBuilder == null) {
             createDefaultHandler();
         }
-        if (this.foUserAgent.isAccessibilityEnabled()) {
-            return Accessibility.decorateDefaultHandler(this.foTreeBuilder, foUserAgent);
-        } else {
-            return this.foTreeBuilder;
-        }
+        return this.foTreeBuilder;
     }
 
     /**

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FopFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FopFactory.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FopFactory.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FopFactory.java Thu Apr  5 16:19:19 2012
@@ -19,11 +19,11 @@
 
 package org.apache.fop.apps;
 
-import java.awt.color.ColorSpace;
 import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.MalformedURLException;
+import java.net.URI;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -143,6 +143,10 @@ public class FopFactory implements Image
     /** Page width */
     private String pageWidth = FopFactoryConfigurator.DEFAULT_PAGE_WIDTH;
 
+    /** Complex scripts support enabled */
+    private boolean useComplexScriptFeatures
+        = FopFactoryConfigurator.DEFAULT_COMPLEX_SCRIPT_FEATURES;
+
     /** @see #setBreakIndentInheritanceOnReferenceAreaBoundary(boolean) */
     private boolean breakIndentInheritanceOnReferenceAreaBoundary
         = FopFactoryConfigurator.DEFAULT_BREAK_INDENT_INHERITANCE;
@@ -150,7 +154,7 @@ public class FopFactory implements Image
     /** Optional overriding LayoutManagerMaker */
     private LayoutManagerMaker lmMakerOverride = null;
 
-    private Set ignoredNamespaces;
+    private Set<String> ignoredNamespaces;
 
     private FOURIResolver foURIResolver;
 
@@ -164,6 +168,7 @@ public class FopFactory implements Image
         this.fontManager = new FontManager() {
 
             /** {@inheritDoc} */
+            @Override
             public void setFontBaseURL(String fontBase) throws MalformedURLException {
                 super.setFontBaseURL(getFOURIResolver().checkBaseURL(fontBase));
             }
@@ -174,7 +179,7 @@ public class FopFactory implements Image
         this.rendererFactory = new RendererFactory();
         this.xmlHandlers = new XMLHandlerRegistry();
         this.imageHandlers = new ImageHandlerRegistry();
-        this.ignoredNamespaces = new java.util.HashSet();
+        this.ignoredNamespaces = new java.util.HashSet<String>();
     }
 
     /**
@@ -211,6 +216,19 @@ public class FopFactory implements Image
     }
 
     /**
+     * Sets complex script support.
+     * @param value <code>true</code> to enable complex script features,
+     * <code>false</code> otherwise
+     */
+    void setComplexScriptFeaturesEnabled(boolean value) {
+        this.useComplexScriptFeatures = value;
+    }
+
+    boolean isComplexScriptFeaturesEnabled() {
+        return useComplexScriptFeatures;
+    }
+
+    /**
      * Returns a new {@link Fop} instance. FOP will be configured with a default user agent
      * instance.
      * <p>
@@ -380,6 +398,7 @@ public class FopFactory implements Image
      * @throws MalformedURLException if there's a problem with a file URL
      * @deprecated use getFontManager().setFontBaseURL(fontBase) instead
      */
+    @Deprecated
     public void setFontBaseURL(String fontBase) throws MalformedURLException {
         getFontManager().setFontBaseURL(fontBase);
     }
@@ -388,6 +407,7 @@ public class FopFactory implements Image
      * @return the font base URL
      * @deprecated use getFontManager().setFontBaseURL(fontBase) instead
      */
+    @Deprecated
     public String getFontBaseURL() {
         return getFontManager().getFontBaseURL();
     }
@@ -515,6 +535,7 @@ public class FopFactory implements Image
      * @return true if kerning on base 14 fonts is enabled
      * @deprecated use getFontManager().isBase14KerningEnabled() instead
      */
+    @Deprecated
     public boolean isBase14KerningEnabled() {
         return getFontManager().isBase14KerningEnabled();
     }
@@ -524,6 +545,7 @@ public class FopFactory implements Image
      * @param value true if kerning should be activated
      * @deprecated use getFontManager().setBase14KerningEnabled(boolean) instead
      */
+    @Deprecated
     public void setBase14KerningEnabled(boolean value) {
         getFontManager().setBase14KerningEnabled(value);
     }
@@ -651,7 +673,7 @@ public class FopFactory implements Image
      * namespace is in the ignored set.
      * @param namespaceURIs the namespace URIs
      */
-    public void ignoreNamespaces(Collection namespaceURIs) {
+    public void ignoreNamespaces(Collection<String> namespaceURIs) {
         this.ignoredNamespaces.addAll(namespaceURIs);
     }
 
@@ -665,7 +687,7 @@ public class FopFactory implements Image
     }
 
     /** @return the set of namespaces that are ignored by FOP */
-    public Set getIgnoredNamespace() {
+    public Set<String> getIgnoredNamespace() {
         return Collections.unmodifiableSet(this.ignoredNamespaces);
     }
 
@@ -701,6 +723,15 @@ public class FopFactory implements Image
     }
 
     /**
+     * Set the base URI for the user configuration
+     * Useful for programmatic configurations
+     * @param baseURI the base URI
+     */
+    public void setUserConfigBaseURI(URI baseURI) {
+        config.setBaseURI(baseURI);
+    }
+
+    /**
      * Get the user configuration.
      * @return the user configuration
      */
@@ -732,6 +763,7 @@ public class FopFactory implements Image
      * @param useCache use cache or not
      * @deprecated use getFontManager().setUseCache(boolean) instead
      */
+    @Deprecated
     public void setUseCache(boolean useCache) {
         getFontManager().setUseCache(useCache);
     }
@@ -741,6 +773,7 @@ public class FopFactory implements Image
      * @return whether this factory is uses the cache
      * @deprecated use getFontManager().useCache() instead
      */
+    @Deprecated
     public boolean useCache() {
         return getFontManager().useCache();
     }
@@ -750,6 +783,7 @@ public class FopFactory implements Image
      * @return the font cache
      * @deprecated use getFontManager().getFontCache() instead
      */
+    @Deprecated
     public FontCache getFontCache() {
         return getFontManager().getFontCache();
     }
@@ -783,20 +817,13 @@ public class FopFactory implements Image
     }
 
     /**
-     * Create (if needed) and return an ICC ColorSpace instance.
-     *
-     * The ICC profile source is taken from the src attribute of the color-profile FO element.
-     * If the ICC ColorSpace is not yet in the cache a new one is created and stored in the cache.
-     *
-     * The FOP URI resolver is used to try and locate the ICC file.
-     * If that fails null is returned.
-     *
-     * @param baseUri a base URI to resolve relative URIs
-     * @param iccProfileSrc ICC Profile source to return a ColorSpace for
-     * @return ICC ColorSpace object or null if ColorSpace could not be created
+     * Returns the color space cache for this instance.
+     * <p>
+     * Note: this method should not be considered as part of FOP's external API.
+     * @return the color space cache
      */
-    public ColorSpace getColorSpace(String baseUri, String iccProfileSrc) {
-        return colorSpaceCache.get(baseUri, iccProfileSrc);
+    public ColorSpaceCache getColorSpaceCache() {
+        return this.colorSpaceCache;
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FopFactoryConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FopFactoryConfigurator.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FopFactoryConfigurator.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/apps/FopFactoryConfigurator.java Thu Apr  5 16:19:19 2012
@@ -22,6 +22,8 @@ package org.apache.fop.apps;
 import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -67,6 +69,9 @@ public class FopFactoryConfigurator {
     /** Defines the default target resolution (72dpi) for FOP */
     public static final float DEFAULT_TARGET_RESOLUTION = GraphicsConstants.DEFAULT_DPI; //dpi
 
+    /** Defines the default complex script support  */
+    public static final boolean DEFAULT_COMPLEX_SCRIPT_FEATURES = true;
+
     private static final String PREFER_RENDERER = "prefer-renderer";
 
     /** logger instance */
@@ -78,6 +83,9 @@ public class FopFactoryConfigurator {
     /** Fop factory configuration */
     private Configuration cfg = null;
 
+    /** The base URI of the configuration file **/
+    private URI baseURI = null;
+
     /**
      * Default constructor
      * @param factory fop factory
@@ -130,17 +138,23 @@ public class FopFactoryConfigurator {
 
         // base definitions for relative path resolution
         if (cfg.getChild("base", false) != null) {
+            String path = cfg.getChild("base").getValue(null);
+            if (baseURI != null) {
+                path = baseURI.resolve(path).normalize().toString();
+            }
             try {
-                factory.setBaseURL(
-                        cfg.getChild("base").getValue(null));
+                factory.setBaseURL(path);
             } catch (MalformedURLException mfue) {
                 LogUtil.handleException(log, mfue, strict);
             }
         }
         if (cfg.getChild("hyphenation-base", false) != null) {
+            String path = cfg.getChild("hyphenation-base").getValue(null);
+            if (baseURI != null) {
+                path = baseURI.resolve(path).normalize().toString();
+            }
             try {
-                factory.setHyphenBaseURL(
-                        cfg.getChild("hyphenation-base").getValue(null));
+                factory.setHyphenBaseURL(path);
             } catch (MalformedURLException mfue) {
                 LogUtil.handleException(log, mfue, strict);
             }
@@ -154,7 +168,9 @@ public class FopFactoryConfigurator {
         if (hyphPatConfig.length != 0) {
             Map/*<String,String>*/ hyphPatNames = new HashMap/*<String,String>*/();
             for (int i = 0; i < hyphPatConfig.length; ++i) {
-                String lang, country, filename;
+                String lang;
+                String country;
+                String filename;
                 StringBuffer error = new StringBuffer();
                 String location = hyphPatConfig[i].getLocation();
 
@@ -258,8 +274,15 @@ public class FopFactoryConfigurator {
             }
         }
 
+        // configure complex script support
+        Configuration csConfig = cfg.getChild("complex-scripts");
+        if (csConfig != null) {
+            this.factory.setComplexScriptFeaturesEnabled
+                (!csConfig.getAttributeAsBoolean ( "disabled", false ));
+        }
+
         // configure font manager
-        new FontManagerConfigurator(cfg).configure(factory.getFontManager(), strict);
+        new FontManagerConfigurator(cfg, baseURI).configure(factory.getFontManager(), strict);
 
         // configure image loader framework
         configureImageLoading(cfg.getChild("image-loading", false), strict);
@@ -339,6 +362,7 @@ public class FopFactoryConfigurator {
      */
     public void setUserConfig(Configuration cfg) throws FOPException {
         this.cfg = cfg;
+        setBaseURI();
         configure(this.factory);
     }
 
@@ -349,4 +373,34 @@ public class FopFactoryConfigurator {
     public Configuration getUserConfig() {
         return this.cfg;
     }
+
+    /**
+     * @return the baseURI
+     */
+    public URI getBaseURI() {
+        return baseURI;
+    }
+
+    /**
+     * @param baseURI the baseURI to set
+     */
+    public void setBaseURI(URI baseURI) {
+        this.baseURI = baseURI;
+    }
+
+    private void setBaseURI() throws FOPException {
+        String loc = cfg.getLocation();
+        try {
+            if (loc != null && loc.startsWith("file:")) {
+                baseURI = new URI(loc);
+                baseURI = baseURI.resolve(".").normalize();
+            }
+            if (baseURI == null) {
+                baseURI = new File(System.getProperty("user.dir")).toURI();
+            }
+        } catch (URISyntaxException e) {
+            throw new FOPException(e);
+        }
+    }
+
 }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/area/Area.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/area/Area.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/area/Area.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/area/Area.java Thu Apr  5 16:19:19 2012
@@ -24,7 +24,9 @@ import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.apache.fop.traits.BorderProps;
+import org.apache.fop.traits.WritingModeTraitsGetter;
 
 // If the area appears more than once in the output
 // or if the area has external data it is cached
@@ -41,27 +43,6 @@ public class Area extends AreaTreeObject
 
     private static final long serialVersionUID = 6342888466142626492L;
 
-    // stacking directions
-    /**
-     * Stacking left to right
-     */
-    public static final int LR = 0;
-
-    /**
-     * Stacking right to left
-     */
-    public static final int RL = 1;
-
-    /**
-     * Stacking top to bottom
-     */
-    public static final int TB = 2;
-
-    /**
-     * Stacking bottom to top
-     */
-    public static final int BT = 3;
-
     // orientations for reference areas
     /**
      * Normal orientation
@@ -130,16 +111,20 @@ public class Area extends AreaTreeObject
     protected int bpd;
 
     /**
+     * Resolved bidirectional level for area.
+     */
+    protected int bidiLevel = -1;
+
+    /**
      * Traits for this area stored in a HashMap
      */
-    protected Map props = null;
+    protected transient Map<Integer, Object> traits = null;
 
     /**
      * logging instance
      */
     protected static final Log log = LogFactory.getLog(Area.class);
 
-
     /**
      * Get the area class of this area.
      *
@@ -226,6 +211,32 @@ public class Area extends AreaTreeObject
     }
 
     /**
+     * Set the bidirectional embedding level.
+     *
+     * @param bidiLevel the bidirectional embedding level
+     */
+    public void setBidiLevel ( int bidiLevel ) {
+        this.bidiLevel = bidiLevel;
+    }
+
+    /**
+     * Reset the bidirectional embedding level to default
+     * value (-1).
+     */
+    public void resetBidiLevel() {
+        setBidiLevel(-1);
+    }
+
+    /**
+     * Get the bidirectional embedding level.
+     *
+     * @return the bidirectional embedding level
+     */
+    public int getBidiLevel() {
+        return bidiLevel;
+    }
+
+    /**
      * Return the sum of region border- and padding-before
      *
      * @return width in millipoints
@@ -239,7 +250,7 @@ public class Area extends AreaTreeObject
 
         Integer padWidth = (Integer) getTrait(Trait.PADDING_BEFORE);
         if (padWidth != null) {
-            margin += padWidth.intValue();
+            margin += padWidth;
         }
 
         return margin;
@@ -260,7 +271,7 @@ public class Area extends AreaTreeObject
 
         Integer padWidth = (Integer) getTrait(Trait.PADDING_AFTER);
         if (padWidth != null) {
-            margin += padWidth.intValue();
+            margin += padWidth;
         }
 
         return margin;
@@ -280,7 +291,7 @@ public class Area extends AreaTreeObject
 
         Integer padWidth = (Integer) getTrait(Trait.PADDING_START);
         if (padWidth != null) {
-            margin += padWidth.intValue();
+            margin += padWidth;
         }
 
         return margin;
@@ -300,7 +311,7 @@ public class Area extends AreaTreeObject
 
         Integer padWidth = (Integer) getTrait(Trait.PADDING_END);
         if (padWidth != null) {
-            margin += padWidth.intValue();
+            margin += padWidth;
         }
 
         return margin;
@@ -315,7 +326,7 @@ public class Area extends AreaTreeObject
         int margin = 0;
         Integer space = (Integer) getTrait(Trait.SPACE_BEFORE);
         if (space != null) {
-            margin = space.intValue();
+            margin = space;
         }
         return margin;
     }
@@ -329,7 +340,7 @@ public class Area extends AreaTreeObject
         int margin = 0;
         Integer space = (Integer) getTrait(Trait.SPACE_AFTER);
         if (space != null) {
-            margin = space.intValue();
+            margin = space;
         }
         return margin;
     }
@@ -343,7 +354,7 @@ public class Area extends AreaTreeObject
         int margin = 0;
         Integer space = (Integer) getTrait(Trait.SPACE_START);
         if (space != null) {
-            margin = space.intValue();
+            margin = space;
         }
         return margin;
     }
@@ -357,7 +368,7 @@ public class Area extends AreaTreeObject
         int margin = 0;
         Integer space = (Integer) getTrait(Trait.SPACE_END);
         if (space != null) {
-            margin = space.intValue();
+            margin = space;
         }
         return margin;
     }
@@ -378,11 +389,24 @@ public class Area extends AreaTreeObject
      * @param traitCode the trait key
      * @param prop the value of the trait
      */
-    public void addTrait(Object traitCode, Object prop) {
-        if (props == null) {
-            props = new java.util.HashMap(20);
+    public void addTrait(Integer traitCode, Object prop) {
+        if (traits == null) {
+            traits = new java.util.HashMap<Integer, Object>(20);
+        }
+        traits.put(traitCode, prop);
+    }
+
+    /**
+     * Set traits on this area, copying from an existing traits map.
+     *
+     * @param traits the map of traits
+     */
+    public void setTraits ( Map traits ) {
+        if ( traits != null ) {
+            this.traits = new java.util.HashMap ( traits );
+        } else {
+            this.traits = null;
         }
-        props.put(traitCode, prop);
     }
 
     /**
@@ -390,64 +414,73 @@ public class Area extends AreaTreeObject
      *
      * @return the map of traits
      */
-    public Map getTraits() {
-        return this.props;
+    public Map<Integer, Object> getTraits() {
+        return this.traits;
     }
 
     /** @return true if the area has traits */
     public boolean hasTraits() {
-        return (this.props != null);
+        return (this.traits != null);
     }
 
     /**
      * Get a trait from this area.
      *
-     * @param oTraitCode the trait key
+     * @param traitCode the trait key
      * @return the trait value
      */
-    public Object getTrait(Object oTraitCode) {
-        return (props != null ? props.get(oTraitCode) : null);
+    public Object getTrait(Integer traitCode) {
+        return (traits != null ? traits.get(traitCode) : null);
     }
 
     /**
      * Checks whether a certain trait is set on this area.
-     * @param oTraitCode the trait key
+     * @param traitCode the trait key
      * @return true if the trait is set
      */
-    public boolean hasTrait(Object oTraitCode) {
-        return (getTrait(oTraitCode) != null);
+    public boolean hasTrait(Integer traitCode) {
+        return (getTrait(traitCode) != null);
     }
 
     /**
      * Get a boolean trait from this area.
-     * @param oTraitCode the trait key
+     * @param traitCode the trait key
      * @return the trait value
      */
-    public boolean getTraitAsBoolean(Object oTraitCode) {
-        return Boolean.TRUE.equals(getTrait(oTraitCode));
+    public boolean getTraitAsBoolean(Integer traitCode) {
+        return Boolean.TRUE.equals(getTrait(traitCode));
     }
 
     /**
      * Get a trait from this area as an integer.
      *
-     * @param oTraitCode the trait key
+     * @param traitCode the trait key
      * @return the trait value
      */
-    public int getTraitAsInteger(Object oTraitCode) {
-        final Object obj = getTrait(oTraitCode);
+    public int getTraitAsInteger(Integer traitCode) {
+        final Object obj = getTrait(traitCode);
         if (obj instanceof Integer) {
-            return ((Integer)obj).intValue();
+            return (Integer) obj;
         } else {
             throw new IllegalArgumentException("Trait "
-                    + oTraitCode.getClass().getName()
+                    + traitCode.getClass().getName()
                     + " could not be converted to an integer");
         }
     }
 
     /**
+     * Sets the writing mode traits for this area. Default implementation
+     * does nothing.
+     * @param wmtg a WM traits getter
+     */
+    public void setWritingModeTraits(WritingModeTraitsGetter wmtg) {
+    }
+
+    /**
      * {@inheritDoc}
      * @return ipd and bpd of area
-     * */
+     */
+    @Override
     public String toString() {
         StringBuffer sb = new StringBuffer(super.toString());
         sb.append(" {ipd=").append(Integer.toString(getIPD()));
@@ -456,4 +489,3 @@ public class Area extends AreaTreeObject
         return sb.toString();
     }
 }
-

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/area/AreaTreeHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/area/AreaTreeHandler.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/area/AreaTreeHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/area/AreaTreeHandler.java Thu Apr  5 16:19:19 2012
@@ -21,8 +21,8 @@ package org.apache.fop.area;
 
 // Java
 import java.io.OutputStream;
-import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 
 import org.xml.sax.SAXException;
 
@@ -73,6 +73,9 @@ public class AreaTreeHandler extends FOE
     /** The AreaTreeModel in use */
     protected AreaTreeModel model;
 
+    // Flag for controlling complex script features (default: true).
+    private boolean useComplexScriptFeatures = true;
+
     // Keeps track of all meaningful id references
     private IDTracker idTracker;
 
@@ -108,6 +111,8 @@ public class AreaTreeHandler extends FOE
 
         this.idTracker = new IDTracker();
 
+        this.useComplexScriptFeatures = userAgent.isComplexScriptFeaturesEnabled();
+
         if (log.isDebugEnabled()) {
             statistics = new Statistics();
         }
@@ -169,12 +174,22 @@ public class AreaTreeHandler extends FOE
     }
 
     /**
+     * Check whether complex script features are enabled.
+     *
+     * @return true if using complex script features
+     */
+    public boolean isComplexScriptFeaturesEnabled() {
+        return useComplexScriptFeatures;
+    }
+
+    /**
      * Prepare AreaTreeHandler for document processing This is called from
      * FOTreeBuilder.startDocument()
      *
      * @throws SAXException
      *             if there is an error
      */
+    @Override
     public void startDocument() throws SAXException {
         // Initialize statistics
         if (statistics != null) {
@@ -182,6 +197,14 @@ public class AreaTreeHandler extends FOE
         }
     }
 
+    @Override
+    public void startRoot(Root root) {
+        Locale locale = root.getLocale();
+        if (locale != null) {
+            model.setDocumentLocale(locale);
+        }
+    }
+
     /**
      * finish the previous pageSequence
      */
@@ -194,26 +217,31 @@ public class AreaTreeHandler extends FOE
     }
 
     /** {@inheritDoc} */
+    @Override
     public void startPageSequence(PageSequence pageSequence) {
         startAbstractPageSequence(pageSequence);
     }
 
     private void startAbstractPageSequence(AbstractPageSequence pageSequence) {
         rootFObj = pageSequence.getRoot();
+
+        //Before the first page-sequence...
+        if (this.prevPageSeqLM == null) {
+            // extension attachments from fo:root
+            wrapAndAddExtensionAttachments(rootFObj.getExtensionAttachments());
+            // extension attachments from fo:declarations
+            if (rootFObj.getDeclarations() != null) {
+                wrapAndAddExtensionAttachments(
+                        rootFObj.getDeclarations().getExtensionAttachments());
+            }
+        }
+
         finishPrevPageSequence(pageSequence.getInitialPageNumber());
         pageSequence.initPageNumber();
-        // extension attachments from fo:root
-        wrapAndAddExtensionAttachments(rootFObj.getExtensionAttachments());
-        // extension attachments from fo:declarations
-        if (rootFObj.getDeclarations() != null) {
-            wrapAndAddExtensionAttachments(rootFObj.getDeclarations().getExtensionAttachments());
-        }
     }
 
-    private void wrapAndAddExtensionAttachments(List list) {
-        Iterator it = list.iterator();
-        while (it.hasNext()) {
-            ExtensionAttachment attachment = (ExtensionAttachment) it.next();
+    private void wrapAndAddExtensionAttachments(List<ExtensionAttachment> list) {
+        for (ExtensionAttachment attachment : list) {
             addOffDocumentItem(new OffDocumentExtensionAttachment(attachment));
         }
     }
@@ -224,6 +252,7 @@ public class AreaTreeHandler extends FOE
      *
      * @param pageSequence the page sequence ending
      */
+    @Override
     public void endPageSequence(PageSequence pageSequence) {
 
         if (statistics != null) {
@@ -243,11 +272,13 @@ public class AreaTreeHandler extends FOE
     }
 
     /** {@inheritDoc} */
+    @Override
     public void startExternalDocument(ExternalDocument document) {
         startAbstractPageSequence(document);
     }
 
     /** {@inheritDoc} */
+    @Override
     public void endExternalDocument(ExternalDocument document) {
         if (statistics != null) {
             statistics.end();
@@ -282,15 +313,16 @@ public class AreaTreeHandler extends FOE
      *
      * @throws SAXException if there is some error
      */
+    @Override
     public void endDocument() throws SAXException {
 
         finishPrevPageSequence(null);
         // process fox:destination elements
         if (rootFObj != null) {
-            List destinationList = rootFObj.getDestinationList();
+            List<Destination> destinationList = rootFObj.getDestinationList();
             if (destinationList != null) {
                 while (destinationList.size() > 0) {
-                    Destination destination = (Destination) destinationList.remove(0);
+                    Destination destination = destinationList.remove(0);
                     DestinationData destinationData = new DestinationData(destination);
                     addOffDocumentItem(destinationData);
                 }
@@ -305,6 +337,7 @@ public class AreaTreeHandler extends FOE
                     model.handleOffDocumentItem(data);
                 }
             }
+            idTracker.signalIDProcessed(rootFObj.getId());
         }
         model.endDocument();
 
@@ -324,15 +357,15 @@ public class AreaTreeHandler extends FOE
         if (odi instanceof Resolvable) {
             Resolvable res = (Resolvable) odi;
             String[] ids = res.getIDRefs();
-            for (int count = 0; count < ids.length; count++) {
-                List pageVPList = idTracker.getPageViewportsContainingID(ids[count]);
-                if (pageVPList != null) {
-                    res.resolveIDRef(ids[count], pageVPList);
+            for (String id : ids) {
+                List<PageViewport> pageVPList = idTracker.getPageViewportsContainingID(id);
+                if (pageVPList != null && !pageVPList.isEmpty()) {
+                    res.resolveIDRef(id, pageVPList);
                 } else {
                     AreaEventProducer eventProducer = AreaEventProducer.Provider.get(
                             getUserAgent().getEventBroadcaster());
-                    eventProducer.unresolvedIDReference(this, odi.getName(), ids[count]);
-                    idTracker.addUnresolvedIDRef(ids[count], res);
+                    eventProducer.unresolvedIDReference(this, odi.getName(), id);
+                    idTracker.addUnresolvedIDRef(id, res);
                 }
             }
             // check to see if ODI is now fully resolved, if so process it
@@ -363,6 +396,7 @@ public class AreaTreeHandler extends FOE
      * @param pv a page viewport that contains the area with this ID
      * @deprecated use getIDTracker().associateIDWithPageViewport(id, pv) instead
      */
+    @Deprecated
     public void associateIDWithPageViewport(String id, PageViewport pv) {
         idTracker.associateIDWithPageViewport(id, pv);
     }
@@ -375,6 +409,7 @@ public class AreaTreeHandler extends FOE
      * @param id the id of the object being processed
      * @deprecated use getIDTracker().signalPendingID(id) instead
      */
+    @Deprecated
     public void signalPendingID(String id) {
         idTracker.signalPendingID(id);
     }
@@ -387,6 +422,7 @@ public class AreaTreeHandler extends FOE
      * @param id the id of the formatting object which was just finished
      * @deprecated use getIDTracker().signalIDProcessed(id) instead
      */
+    @Deprecated
     public void signalIDProcessed(String id) {
         idTracker.signalIDProcessed(id);
     }
@@ -398,6 +434,7 @@ public class AreaTreeHandler extends FOE
      * @return true if the ID has been resolved
      * @deprecated use getIDTracker().alreadyResolvedID(id) instead
      */
+    @Deprecated
     public boolean alreadyResolvedID(String id) {
         return idTracker.alreadyResolvedID(id);
     }
@@ -408,18 +445,20 @@ public class AreaTreeHandler extends FOE
      * @param pv page viewport whose ID refs to resolve
      * @deprecated use getIDTracker().tryIDResolution(pv) instead
      */
+    @Deprecated
     public void tryIDResolution(PageViewport pv) {
         idTracker.tryIDResolution(pv);
     }
 
     /**
-     * Get the list of page viewports that have an area with a given id.
+     * Get the set of page viewports that have an area with a given id.
      *
      * @param id the id to lookup
      * @return the list of PageViewports
      * @deprecated use getIDTracker().getPageViewportsContainingID(id) instead
      */
-    public List getPageViewportsContainingID(String id) {
+    @Deprecated
+    public List<PageViewport> getPageViewportsContainingID(String id) {
         return idTracker.getPageViewportsContainingID(id);
     }
 
@@ -430,6 +469,7 @@ public class AreaTreeHandler extends FOE
      * @param res the Resolvable object needing the idref to be resolved
      * @deprecated use getIDTracker().addUnresolvedIDRef(idref, res) instead
      */
+    @Deprecated
     public void addUnresolvedIDRef(String idref, Resolvable res) {
         idTracker.addUnresolvedIDRef(idref, res);
     }

Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/area/AreaTreeModel.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/area/AreaTreeModel.java?rev=1309921&r1=1309920&r2=1309921&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/area/AreaTreeModel.java (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/area/AreaTreeModel.java Thu Apr  5 16:19:19 2012
@@ -21,6 +21,7 @@ package org.apache.fop.area;
 
 // Java
 import java.util.List;
+import java.util.Locale;
 
 import org.xml.sax.SAXException;
 
@@ -36,11 +37,11 @@ import org.apache.commons.logging.LogFac
  * the life of the area tree model.
  */
 public class AreaTreeModel {
-    private List/*<PageSequence>*/ pageSequenceList = null;
-    private int currentPageSequenceIndex = -1;
+    private List<PageSequence> pageSequenceList = null;
+    private int currentPageIndex = 0;
+
     /** the current page sequence */
     protected PageSequence currentPageSequence;
-//    private List offDocumentItems = new java.util.ArrayList();
     /** logger instance */
     protected static final Log log = LogFactory.getLog(AreaTreeModel.class);
 
@@ -48,7 +49,7 @@ public class AreaTreeModel {
      * Create a new store pages model
      */
     public AreaTreeModel() {
-        pageSequenceList = new java.util.ArrayList/*<PageSequence>*/();
+        pageSequenceList = new java.util.ArrayList<PageSequence>();
     }
 
     /**
@@ -59,9 +60,11 @@ public class AreaTreeModel {
         if (pageSequence == null) {
             throw new NullPointerException("pageSequence must not be null");
         }
+        if (currentPageSequence != null) {
+            currentPageIndex += currentPageSequence.getPageCount();
+        }
         this.currentPageSequence = pageSequence;
         pageSequenceList.add(currentPageSequence);
-        currentPageSequenceIndex = pageSequenceList.size() - 1;
     }
 
     /**
@@ -70,12 +73,8 @@ public class AreaTreeModel {
      */
     public void addPage(PageViewport page) {
         currentPageSequence.addPage(page);
-        int pageIndex = 0;
-        for (int i = 0; i < currentPageSequenceIndex; i++) {
-            pageIndex += ((PageSequence)pageSequenceList.get(i)).getPageCount();
-        }
-        pageIndex += currentPageSequence.getPageCount() - 1;
-        page.setPageIndex(pageIndex);
+        page.setPageIndex(currentPageIndex
+                + currentPageSequence.getPageCount() - 1);
         page.setPageSequence(currentPageSequence);
     }
 
@@ -113,8 +112,7 @@ public class AreaTreeModel {
      * @return returns the number of pages in a page sequence
      */
     public int getPageCount(int seq) {
-        PageSequence sequence = (PageSequence)pageSequenceList.get(seq - 1);
-        return sequence.getPageCount();
+        return pageSequenceList.get(seq - 1).getPageCount();
     }
 
     /**
@@ -124,7 +122,13 @@ public class AreaTreeModel {
      * @return the PageViewport for the particular page
      */
     public PageViewport getPage(int seq, int count) {
-        PageSequence sequence = (PageSequence)pageSequenceList.get(seq - 1);
-        return sequence.getPage(count);
+        return pageSequenceList.get(seq - 1).getPage(count);
+    }
+
+    /**
+     *
+     * @param locale The locale of the document
+     */
+    public void setDocumentLocale(Locale locale) {
     }
 }



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