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 ga...@apache.org on 2012/07/05 22:29:58 UTC

svn commit: r1357883 [4/5] - in /xmlgraphics/fop/branches/fop-1_1: ./ examples/fo/ examples/fo/advanced/ examples/fo/basic/ examples/fo/svg/ examples/fo/tables/ lib/ src/documentation/content/xdocs/ src/documentation/content/xdocs/fo/ src/documentation...

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java Thu Jul  5 20:29:53 2012
@@ -20,8 +20,9 @@
 package org.apache.fop.fonts.truetype;
 
 import java.io.IOException;
-import java.util.Iterator;
+import java.util.HashMap;
 import java.util.Map;
+import java.util.SortedSet;
 
 
 /**
@@ -42,24 +43,18 @@ public class TTFSubSetFile extends TTFFi
      * Offsets in name table to be filled out by table.
      * The offsets are to the checkSum field
      */
-    private int cvtDirOffset = 0;
-    private int fpgmDirOffset = 0;
-    private int glyfDirOffset = 0;
-    private int headDirOffset = 0;
-    private int hheaDirOffset = 0;
-    private int hmtxDirOffset = 0;
-    private int locaDirOffset = 0;
-    private int maxpDirOffset = 0;
-    private int prepDirOffset = 0;
+    private Map<TTFTableName, Integer> offsets = new HashMap<TTFTableName, Integer>();
 
     private int checkSumAdjustmentOffset = 0;
     private int locaOffset = 0;
 
+    /** Stores the glyph offsets so that we can end strings at glyph boundaries */
+    private int[] glyphOffsets;
+
     /**
      * Default Constructor
      */
     public TTFSubSetFile() {
-        this(false, false);
     }
 
     /**
@@ -71,16 +66,9 @@ public class TTFSubSetFile extends TTFFi
         super(useKerning, useAdvanced);
     }
 
-    /**
-     * Initalize the output array
-     */
-    private void init(int size) {
-        output = new byte[size];
-        realSize = 0;
-        currentPos = 0;
-
-        // createDirectory()
-    }
+    /** The dir tab entries in the new subset font. */
+    private Map<TTFTableName, TTFDirTabEntry> newDirTabs
+                        = new HashMap<TTFTableName, TTFDirTabEntry>();
 
     private int determineTableCount() {
         int numTables = 4; //4 req'd tables: head,hhea,hmtx,maxp
@@ -88,7 +76,7 @@ public class TTFSubSetFile extends TTFFi
             throw new UnsupportedOperationException(
                     "OpenType fonts with CFF glyphs are not supported");
         } else {
-            numTables += 2; //1 req'd table: glyf,loca
+            numTables += 5; //5 req'd tables: glyf,loca,post,name,OS/2
             if (hasCvt()) {
                 numTables++;
             }
@@ -119,7 +107,7 @@ public class TTFSubSetFile extends TTFFi
 
         // Create searchRange, entrySelector and rangeShift
         int maxPow = maxPow2(numTables);
-        int searchRange = maxPow * 16;
+        int searchRange = (int) Math.pow(2, maxPow) * 16;
         writeUShort(searchRange);
         realSize += 2;
 
@@ -128,151 +116,122 @@ public class TTFSubSetFile extends TTFFi
 
         writeUShort((numTables * 16) - searchRange);
         realSize += 2;
+        // Create space for the table entries (these must be in ASCII alphabetical order[A-Z] then[a-z])
+        writeTableName(TTFTableName.OS2);
 
-        // Create space for the table entries
         if (hasCvt()) {
-            writeString("cvt ");
-            cvtDirOffset = currentPos;
-            currentPos += 12;
-            realSize += 16;
+            writeTableName(TTFTableName.CVT);
         }
-
         if (hasFpgm()) {
-            writeString("fpgm");
-            fpgmDirOffset = currentPos;
-            currentPos += 12;
-            realSize += 16;
+            writeTableName(TTFTableName.FPGM);
         }
+        writeTableName(TTFTableName.GLYF);
+        writeTableName(TTFTableName.HEAD);
+        writeTableName(TTFTableName.HHEA);
+        writeTableName(TTFTableName.HMTX);
+        writeTableName(TTFTableName.LOCA);
+        writeTableName(TTFTableName.MAXP);
+        writeTableName(TTFTableName.NAME);
+        writeTableName(TTFTableName.POST);
+        if (hasPrep()) {
+            writeTableName(TTFTableName.PREP);
+        }
+        newDirTabs.put(TTFTableName.TABLE_DIRECTORY, new TTFDirTabEntry(0, currentPos));
+    }
 
-        writeString("glyf");
-        glyfDirOffset = currentPos;
-        currentPos += 12;
-        realSize += 16;
-
-        writeString("head");
-        headDirOffset = currentPos;
-        currentPos += 12;
-        realSize += 16;
-
-        writeString("hhea");
-        hheaDirOffset = currentPos;
+    private void writeTableName(TTFTableName tableName) {
+        writeString(tableName.getName());
+        offsets.put(tableName, currentPos);
         currentPos += 12;
         realSize += 16;
+    }
 
-        writeString("hmtx");
-        hmtxDirOffset = currentPos;
-        currentPos += 12;
-        realSize += 16;
 
-        writeString("loca");
-        locaDirOffset = currentPos;
-        currentPos += 12;
-        realSize += 16;
-
-        writeString("maxp");
-        maxpDirOffset = currentPos;
-        currentPos += 12;
-        realSize += 16;
+    private boolean hasCvt() {
+        return dirTabs.containsKey(TTFTableName.CVT);
+    }
 
-        if (hasPrep()) {
-            writeString("prep");
-            prepDirOffset = currentPos;
-            currentPos += 12;
-            realSize += 16;
-        }
+    private boolean hasFpgm() {
+        return dirTabs.containsKey(TTFTableName.FPGM);
     }
 
+    private boolean hasPrep() {
+        return dirTabs.containsKey(TTFTableName.PREP);
+    }
 
     /**
-     * Copy the cvt table as is from original font to subset font
+     * Create an empty loca table without updating checksum
      */
-    private boolean createCvt(FontFileReader in) throws IOException {
-        TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("cvt ");
+    private void createLoca(int size) throws IOException {
+        pad4();
+        locaOffset = currentPos;
+        int dirTableOffset = offsets.get(TTFTableName.LOCA);
+        writeULong(dirTableOffset + 4, currentPos);
+        writeULong(dirTableOffset + 8, size * 4 + 4);
+        currentPos += size * 4 + 4;
+        realSize += size * 4 + 4;
+    }
+
+    private boolean copyTable(FontFileReader in, TTFTableName tableName) throws IOException {
+        TTFDirTabEntry entry = dirTabs.get(tableName);
         if (entry != null) {
             pad4();
-            seekTab(in, "cvt ", 0);
+            seekTab(in, tableName, 0);
             System.arraycopy(in.getBytes((int)entry.getOffset(), (int)entry.getLength()),
                              0, output, currentPos, (int)entry.getLength());
 
-            int checksum = getCheckSum(currentPos, (int)entry.getLength());
-            writeULong(cvtDirOffset, checksum);
-            writeULong(cvtDirOffset + 4, currentPos);
-            writeULong(cvtDirOffset + 8, (int)entry.getLength());
-            currentPos += (int)entry.getLength();
-            realSize += (int)entry.getLength();
+            updateCheckSum(currentPos, (int) entry.getLength(), tableName);
+            currentPos += (int) entry.getLength();
+            realSize += (int) entry.getLength();
             return true;
         } else {
             return false;
-            //throw new IOException("Can't find cvt table");
         }
     }
 
-    private boolean hasCvt() {
-        return dirTabs.containsKey("cvt ");
-    }
-
-    private boolean hasFpgm() {
-        return dirTabs.containsKey("fpgm");
-    }
-
-    private boolean hasPrep() {
-        return dirTabs.containsKey("prep");
+    /**
+     * Copy the cvt table as is from original font to subset font
+     */
+    private boolean createCvt(FontFileReader in) throws IOException {
+        return copyTable(in, TTFTableName.CVT);
     }
 
     /**
      * Copy the fpgm table as is from original font to subset font
      */
     private boolean createFpgm(FontFileReader in) throws IOException {
-        TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("fpgm");
-        if (entry != null) {
-            pad4();
-            seekTab(in, "fpgm", 0);
-            System.arraycopy(in.getBytes((int)entry.getOffset(), (int)entry.getLength()),
-                             0, output, currentPos, (int)entry.getLength());
-            int checksum = getCheckSum(currentPos, (int)entry.getLength());
-            writeULong(fpgmDirOffset, checksum);
-            writeULong(fpgmDirOffset + 4, currentPos);
-            writeULong(fpgmDirOffset + 8, (int)entry.getLength());
-            currentPos += (int)entry.getLength();
-            realSize += (int)entry.getLength();
-            return true;
-        } else {
-            return false;
-        }
+        return copyTable(in, TTFTableName.FPGM);
     }
 
-
-
     /**
-     * Create an empty loca table without updating checksum
+     * Copy the name table as is from the original.
      */
-    private void createLoca(int size) throws IOException {
-        pad4();
-        locaOffset = currentPos;
-        writeULong(locaDirOffset + 4, currentPos);
-        writeULong(locaDirOffset + 8, size * 4 + 4);
-        currentPos += size * 4 + 4;
-        realSize += size * 4 + 4;
+    private boolean createName(FontFileReader in) throws IOException {
+        return copyTable(in, TTFTableName.NAME);
     }
 
+    /**
+     * Copy the OS/2 table as is from the original.
+     */
+    private boolean createOS2(FontFileReader in) throws IOException {
+        return copyTable(in, TTFTableName.OS2);
+    }
 
     /**
      * Copy the maxp table as is from original font to subset font
      * and set num glyphs to size
      */
     private void createMaxp(FontFileReader in, int size) throws IOException {
-        TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("maxp");
+        TTFTableName maxp = TTFTableName.MAXP;
+        TTFDirTabEntry entry = dirTabs.get(maxp);
         if (entry != null) {
             pad4();
-            seekTab(in, "maxp", 0);
+            seekTab(in, maxp, 0);
             System.arraycopy(in.getBytes((int)entry.getOffset(), (int)entry.getLength()),
                              0, output, currentPos, (int)entry.getLength());
             writeUShort(currentPos + 4, size);
 
-            int checksum = getCheckSum(currentPos, (int)entry.getLength());
-            writeULong(maxpDirOffset, checksum);
-            writeULong(maxpDirOffset + 4, currentPos);
-            writeULong(maxpDirOffset + 8, (int)entry.getLength());
+            updateCheckSum(currentPos, (int)entry.getLength(), maxp);
             currentPos += (int)entry.getLength();
             realSize += (int)entry.getLength();
         } else {
@@ -280,28 +239,34 @@ public class TTFSubSetFile extends TTFFi
         }
     }
 
+    private void createPost(FontFileReader in) throws IOException {
+        TTFTableName post = TTFTableName.POST;
+        TTFDirTabEntry entry = dirTabs.get(post);
+        if (entry != null) {
+            pad4();
+            seekTab(in, post, 0);
+            int newTableSize = 32; // This is the post table size with glyphs truncated
+            byte[] newPostTable = new byte[newTableSize];
+            // We only want the first 28 bytes (truncate the glyph names);
+            System.arraycopy(in.getBytes((int) entry.getOffset(), newTableSize),
+                    0, newPostTable, 0, newTableSize);
+            // set the post table to Format 3.0
+            newPostTable[1] = 0x03;
+            System.arraycopy(newPostTable, 0, output, currentPos, newTableSize);
+            updateCheckSum(currentPos, newTableSize, post);
+            currentPos += newTableSize;
+            realSize += newTableSize;
+        } else {
+            throw new IOException("Can't find post table");
+        }
+    }
+
 
     /**
      * Copy the prep table as is from original font to subset font
      */
     private boolean createPrep(FontFileReader in) throws IOException {
-        TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("prep");
-        if (entry != null) {
-            pad4();
-            seekTab(in, "prep", 0);
-            System.arraycopy(in.getBytes((int)entry.getOffset(), (int)entry.getLength()),
-                             0, output, currentPos, (int)entry.getLength());
-
-            int checksum = getCheckSum(currentPos, (int)entry.getLength());
-            writeULong(prepDirOffset, checksum);
-            writeULong(prepDirOffset + 4, currentPos);
-            writeULong(prepDirOffset + 8, (int)entry.getLength());
-            currentPos += (int)entry.getLength();
-            realSize += (int)entry.getLength();
-            return true;
-        } else {
-            return false;
-        }
+        return copyTable(in, TTFTableName.PREP);
     }
 
 
@@ -310,20 +275,17 @@ public class TTFSubSetFile extends TTFFi
      * and fill in size of hmtx table
      */
     private void createHhea(FontFileReader in, int size) throws IOException {
-        TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("hhea");
+        TTFDirTabEntry entry = dirTabs.get(TTFTableName.HHEA);
         if (entry != null) {
             pad4();
-            seekTab(in, "hhea", 0);
-            System.arraycopy(in.getBytes((int)entry.getOffset(), (int)entry.getLength()),
-                             0, output, currentPos, (int)entry.getLength());
-            writeUShort((int)entry.getLength() + currentPos - 2, size);
-
-            int checksum = getCheckSum(currentPos, (int)entry.getLength());
-            writeULong(hheaDirOffset, checksum);
-            writeULong(hheaDirOffset + 4, currentPos);
-            writeULong(hheaDirOffset + 8, (int)entry.getLength());
-            currentPos += (int)entry.getLength();
-            realSize += (int)entry.getLength();
+            seekTab(in, TTFTableName.HHEA, 0);
+            System.arraycopy(in.getBytes((int) entry.getOffset(), (int) entry.getLength()), 0,
+                    output, currentPos, (int) entry.getLength());
+            writeUShort((int) entry.getLength() + currentPos - 2, size);
+
+            updateCheckSum(currentPos, (int) entry.getLength(), TTFTableName.HHEA);
+            currentPos += (int) entry.getLength();
+            realSize += (int) entry.getLength();
         } else {
             throw new IOException("Can't find hhea table");
         }
@@ -337,10 +299,11 @@ public class TTFSubSetFile extends TTFFi
      * in checkSumAdjustmentOffset
      */
     private void createHead(FontFileReader in) throws IOException {
-        TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("head");
+        TTFTableName head = TTFTableName.HEAD;
+        TTFDirTabEntry entry = dirTabs.get(head);
         if (entry != null) {
             pad4();
-            seekTab(in, "head", 0);
+            seekTab(in, head, 0);
             System.arraycopy(in.getBytes((int)entry.getOffset(), (int)entry.getLength()),
                              0, output, currentPos, (int)entry.getLength());
 
@@ -352,11 +315,7 @@ public class TTFSubSetFile extends TTFFi
             output[currentPos + 50] = 0;    // long locaformat
             output[currentPos + 51] = 1;    // long locaformat
 
-            int checksum = getCheckSum(currentPos, (int)entry.getLength());
-            writeULong(headDirOffset, checksum);
-            writeULong(headDirOffset + 4, currentPos);
-            writeULong(headDirOffset + 8, (int)entry.getLength());
-
+            updateCheckSum(currentPos, (int)entry.getLength(), head);
             currentPos += (int)entry.getLength();
             realSize += (int)entry.getLength();
         } else {
@@ -369,30 +328,24 @@ public class TTFSubSetFile extends TTFFi
      * Create the glyf table and fill in loca table
      */
     private void createGlyf(FontFileReader in,
-                            Map glyphs) throws IOException {
-        TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("glyf");
+            Map<Integer, Integer> glyphs) throws IOException {
+        TTFTableName glyf = TTFTableName.GLYF;
+        TTFDirTabEntry entry = dirTabs.get(glyf);
         int size = 0;
-        int start = 0;
+        int startPos = 0;
         int endOffset = 0;    // Store this as the last loca
         if (entry != null) {
             pad4();
-            start = currentPos;
+            startPos = currentPos;
 
             /* Loca table must be in order by glyph index, so build
              * an array first and then write the glyph info and
              * location offset.
              */
-            int[] origIndexes = new int[glyphs.size()];
-
-            Iterator e = glyphs.keySet().iterator();
-            while (e.hasNext()) {
-                Integer origIndex = (Integer)e.next();
-                Integer subsetIndex = (Integer)glyphs.get(origIndex);
-                origIndexes[subsetIndex.intValue()] = origIndex.intValue();
-            }
+            int[] origIndexes = buildSubsetIndexToOrigIndexMap(glyphs);
+            glyphOffsets = new int[origIndexes.length];
 
             for (int i = 0; i < origIndexes.length; i++) {
-                int glyphLength = 0;
                 int nextOffset = 0;
                 int origGlyphIndex = origIndexes[i];
                 if (origGlyphIndex >= (mtxTab.length - 1)) {
@@ -400,46 +353,64 @@ public class TTFSubSetFile extends TTFFi
                 } else {
                     nextOffset = (int)mtxTab[origGlyphIndex + 1].getOffset();
                 }
-                glyphLength = nextOffset - (int)mtxTab[origGlyphIndex].getOffset();
+                int glyphOffset = (int)mtxTab[origGlyphIndex].getOffset();
+                int glyphLength = nextOffset - glyphOffset;
 
+                byte[] glyphData = in.getBytes(
+                        (int)entry.getOffset() + glyphOffset,
+                        glyphLength);
+                int endOffset1 = endOffset;
                 // Copy glyph
                 System.arraycopy(
-                    in.getBytes((int)entry.getOffset() + (int)mtxTab[origGlyphIndex].getOffset(),
-                        glyphLength), 0,
+                    glyphData, 0,
                     output, currentPos,
                     glyphLength);
 
 
                 // Update loca table
-                writeULong(locaOffset + i * 4, currentPos - start);
-                if ((currentPos - start + glyphLength) > endOffset) {
-                    endOffset = (currentPos - start + glyphLength);
+                writeULong(locaOffset + i * 4, currentPos - startPos);
+                if ((currentPos - startPos + glyphLength) > endOffset1) {
+                    endOffset1 = (currentPos - startPos + glyphLength);
                 }
 
+                // Store the glyph boundary positions relative to the start of the font
+                glyphOffsets[i] = currentPos;
                 currentPos += glyphLength;
                 realSize += glyphLength;
 
+
+                endOffset = endOffset1;
             }
 
-            size = currentPos - start;
 
-            int checksum = getCheckSum(start, size);
-            writeULong(glyfDirOffset, checksum);
-            writeULong(glyfDirOffset + 4, start);
-            writeULong(glyfDirOffset + 8, size);
+            size = currentPos - startPos;
+
             currentPos += 12;
             realSize += 12;
+            updateCheckSum(startPos, size + 12, glyf);
 
             // Update loca checksum and last loca index
             writeULong(locaOffset + glyphs.size() * 4, endOffset);
-
-            checksum = getCheckSum(locaOffset, glyphs.size() * 4 + 4);
-            writeULong(locaDirOffset, checksum);
+            int locaSize = glyphs.size() * 4 + 4;
+            int checksum = getCheckSum(output, locaOffset, locaSize);
+            writeULong(offsets.get(TTFTableName.LOCA), checksum);
+            int padSize = (locaOffset + locaSize) % 4;
+            newDirTabs.put(TTFTableName.LOCA,
+                    new TTFDirTabEntry(locaOffset, locaSize + padSize));
         } else {
             throw new IOException("Can't find glyf table");
         }
     }
 
+    private int[] buildSubsetIndexToOrigIndexMap(Map<Integer, Integer> glyphs) {
+        int[] origIndexes = new int[glyphs.size()];
+        for (Map.Entry<Integer, Integer> glyph : glyphs.entrySet()) {
+            int origIndex = glyph.getKey();
+            int subsetIndex = glyph.getValue();
+            origIndexes[subsetIndex] = origIndex;
+        }
+        return origIndexes;
+    }
 
     /**
      * Create the hmtx table by copying metrics from original
@@ -448,8 +419,9 @@ public class TTFSubSetFile extends TTFFi
      * metric (key) to the subset metric (value)
      */
     private void createHmtx(FontFileReader in,
-                            Map glyphs) throws IOException {
-        TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("hmtx");
+                            Map<Integer, Integer> glyphs) throws IOException {
+        TTFTableName hmtx = TTFTableName.HMTX;
+        TTFDirTabEntry entry = dirTabs.get(hmtx);
 
         int longHorMetricSize = glyphs.size() * 2;
         int leftSideBearingSize = glyphs.size() * 2;
@@ -458,10 +430,9 @@ public class TTFSubSetFile extends TTFFi
         if (entry != null) {
             pad4();
             //int offset = (int)entry.offset;
-            Iterator e = glyphs.keySet().iterator();
-            while (e.hasNext()) {
-                Integer origIndex = (Integer)e.next();
-                Integer subsetIndex = (Integer)glyphs.get(origIndex);
+            for (Map.Entry<Integer, Integer> glyph : glyphs.entrySet()) {
+                Integer origIndex = glyph.getKey();
+                Integer subsetIndex = glyph.getValue();
 
                 writeUShort(currentPos + subsetIndex.intValue() * 4,
                             mtxTab[origIndex.intValue()].getWx());
@@ -469,10 +440,7 @@ public class TTFSubSetFile extends TTFFi
                             mtxTab[origIndex.intValue()].getLsb());
             }
 
-            int checksum = getCheckSum(currentPos, hmtxSize);
-            writeULong(hmtxDirOffset, checksum);
-            writeULong(hmtxDirOffset + 4, currentPos);
-            writeULong(hmtxDirOffset + 8, hmtxSize);
+            updateCheckSum(currentPos, hmtxSize, hmtx);
             currentPos += hmtxSize;
             realSize += hmtxSize;
         } else {
@@ -481,43 +449,37 @@ public class TTFSubSetFile extends TTFFi
     }
 
     /**
-     * Returns a subset of the original font.
+     * Reads a font and creates a subset of the font.
      *
      * @param in FontFileReader to read from
      * @param name Name to be checked for in the font file
      * @param glyphs Map of glyphs (glyphs has old index as (Integer) key and
      * new index as (Integer) value)
-     * @return A subset of the original font
      * @throws IOException in case of an I/O problem
      */
-    public byte[] readFont(FontFileReader in, String name,
+    public void readFont(FontFileReader in, String name,
                            Map<Integer, Integer> glyphs) throws IOException {
-
+        fontFile = in;
         //Check if TrueType collection, and that the name exists in the collection
-        if (!checkTTC(in, name)) {
+        if (!checkTTC(name)) {
             throw new IOException("Failed to read font");
         }
 
         //Copy the Map as we're going to modify it
-        Map<Integer, Integer> subsetGlyphs = new java.util.HashMap<Integer, Integer>(glyphs);
+        Map<Integer, Integer> subsetGlyphs = new HashMap<Integer, Integer>(glyphs);
 
         output = new byte[in.getFileSize()];
 
-        readDirTabs(in);
-        readFontHeader(in);
-        getNumGlyphs(in);
-        readHorizontalHeader(in);
-        readHorizontalMetrics(in);
-        readIndexToLocation(in);
+        readDirTabs();
+        readFontHeader();
+        getNumGlyphs();
+        readHorizontalHeader();
+        readHorizontalMetrics();
+        readIndexToLocation();
 
         scanGlyphs(in, subsetGlyphs);
 
-        createDirectory();                // Create the TrueType header and directory
-
-        createHead(in);
-        createHhea(in, subsetGlyphs.size());    // Create the hhea table
-        createHmtx(in, subsetGlyphs);           // Create hmtx table
-        createMaxp(in, subsetGlyphs.size());    // copy the maxp table
+        createDirectory();     // Create the TrueType header and directory
 
         boolean optionalTableFound;
         optionalTableFound = createCvt(in);    // copy the cvt table
@@ -531,6 +493,16 @@ public class TTFSubSetFile extends TTFFi
             // fpgm is optional (used in TrueType fonts only)
             log.debug("TrueType: fpgm table not present. Skipped.");
         }
+        createLoca(subsetGlyphs.size());    // create empty loca table
+        createGlyf(in, subsetGlyphs); //create glyf table and update loca table
+
+        createOS2(in);                          // copy the OS/2 table
+        createHead(in);
+        createHhea(in, subsetGlyphs.size());    // Create the hhea table
+        createHmtx(in, subsetGlyphs);           // Create hmtx table
+        createMaxp(in, subsetGlyphs.size());    // copy the maxp table
+        createName(in);                         // copy the name table
+        createPost(in);                         // copy the post table
 
         optionalTableFound = createPrep(in);    // copy prep table
         if (!optionalTableFound) {
@@ -538,21 +510,59 @@ public class TTFSubSetFile extends TTFFi
             log.debug("TrueType: prep table not present. Skipped.");
         }
 
-        createLoca(subsetGlyphs.size());    // create empty loca table
-        createGlyf(in, subsetGlyphs);       //create glyf table and update loca table
-
         pad4();
         createCheckSumAdjustment();
+    }
 
+    /**
+     * Returns a subset of the fonts (readFont() MUST be called first in order to create the
+     * subset).
+     * @return byte array
+     */
+    public byte[] getFontSubset() {
         byte[] ret = new byte[realSize];
         System.arraycopy(output, 0, ret, 0, realSize);
-
         return ret;
     }
 
+    private void handleGlyphSubset(TTFGlyphOutputStream glyphOut) throws IOException {
+        glyphOut.startGlyphStream();
+        // Stream all but the last glyph
+        for (int i = 0; i < glyphOffsets.length - 1; i++) {
+            glyphOut.streamGlyph(output, glyphOffsets[i],
+                    glyphOffsets[i + 1] - glyphOffsets[i]);
+        }
+        // Stream the last glyph
+        TTFDirTabEntry glyf = newDirTabs.get(TTFTableName.GLYF);
+        long lastGlyphLength = glyf.getLength()
+            - (glyphOffsets[glyphOffsets.length - 1] - glyf.getOffset());
+        glyphOut.streamGlyph(output, glyphOffsets[glyphOffsets.length - 1],
+                (int) lastGlyphLength);
+        glyphOut.endGlyphStream();
+    }
+
+    @Override
+    public void stream(TTFOutputStream ttfOut) throws IOException {
+        SortedSet<Map.Entry<TTFTableName, TTFDirTabEntry>>  sortedDirTabs
+                = sortDirTabMap(newDirTabs);
+        TTFTableOutputStream tableOut = ttfOut.getTableOutputStream();
+        TTFGlyphOutputStream glyphOut = ttfOut.getGlyphOutputStream();
+
+        ttfOut.startFontStream();
+        for (Map.Entry<TTFTableName, TTFDirTabEntry>  entry : sortedDirTabs) {
+            if (entry.getKey().equals(TTFTableName.GLYF)) {
+                    handleGlyphSubset(glyphOut);
+            } else {
+                tableOut.streamTable(output, (int) entry.getValue().getOffset(),
+                            (int) entry.getValue().getLength());
+            }
+        }
+        ttfOut.endFontStream();
+    }
+
     private void scanGlyphs(FontFileReader in, Map<Integer, Integer> subsetGlyphs)
             throws IOException {
-        TTFDirTabEntry glyfTableInfo = (TTFDirTabEntry) dirTabs.get("glyf");
+        TTFDirTabEntry glyfTableInfo = dirTabs.get(TTFTableName.GLYF);
         if (glyfTableInfo == null) {
             throw new IOException("Glyf table could not be found");
         }
@@ -610,20 +620,6 @@ public class TTFSubSetFile extends TTFFi
         output[pos + 1] = b2;
     }
 
-    /**
-     * Appends a ULONG to the output array,
-     * updates currentPos but not realSize
-     */
-    private void writeULong(int s) {
-        byte b1 = (byte)((s >> 24) & 0xff);
-        byte b2 = (byte)((s >> 16) & 0xff);
-        byte b3 = (byte)((s >> 8) & 0xff);
-        byte b4 = (byte)(s & 0xff);
-        writeByte(b1);
-        writeByte(b2);
-        writeByte(b3);
-        writeByte(b4);
-    }
 
     /**
      * Appends a ULONG to the output array,
@@ -641,40 +637,16 @@ public class TTFSubSetFile extends TTFFi
     }
 
     /**
-     * Read a signed short value at given position
-     */
-    private short readShort(int pos) {
-        int ret = readUShort(pos);
-        return (short)ret;
-    }
-
-    /**
-     * Read a unsigned short value at given position
-     */
-    private int readUShort(int pos) {
-        int ret = output[pos];
-        if (ret < 0) {
-            ret += 256;
-        }
-        ret = ret << 8;
-        if (output[pos + 1] < 0) {
-            ret |= output[pos + 1] + 256;
-        } else {
-            ret |= output[pos + 1];
-        }
-
-        return ret;
-    }
-
-    /**
      * Create a padding in the fontfile to align
      * on a 4-byte boundary
      */
     private void pad4() {
-        int padSize = currentPos % 4;
-        for (int i = 0; i < padSize; i++) {
-            output[currentPos++] = 0;
-            realSize++;
+        int padSize = getPadSize(currentPos);
+        if (padSize < 4) {
+            for (int i = 0; i < padSize; i++) {
+                output[currentPos++] = 0;
+                realSize++;
+            }
         }
     }
 
@@ -683,23 +655,25 @@ public class TTFSubSetFile extends TTFFi
      */
     private int maxPow2(int max) {
         int i = 0;
-        while (Math.pow(2, i) < max) {
+        while (Math.pow(2, i) <= max) {
             i++;
         }
 
         return (i - 1);
     }
 
-    private int log2(int num) {
-        return (int)(Math.log(num) / Math.log(2));
-    }
-
 
-    private int getCheckSum(int start, int size) {
-        return (int)getLongCheckSum(start, size);
+    private void updateCheckSum(int tableStart, int tableSize, TTFTableName tableName) {
+        int checksum = getCheckSum(output, tableStart, tableSize);
+        int offset = offsets.get(tableName);
+        int padSize = getPadSize(tableStart +  tableSize);
+        newDirTabs.put(tableName, new TTFDirTabEntry(tableStart, tableSize + padSize));
+        writeULong(offset, checksum);
+        writeULong(offset + 4, tableStart);
+        writeULong(offset + 8, tableSize);
     }
 
-    private long getLongCheckSum(int start, int size) {
+    private static int getCheckSum(byte[] data, int start, int size) {
         // All the tables here are aligned on four byte boundaries
         // Add remainder to size if it's not a multiple of 4
         int remainder = size % 4;
@@ -710,26 +684,19 @@ public class TTFSubSetFile extends TTFFi
         long sum = 0;
 
         for (int i = 0; i < size; i += 4) {
-            int l = (output[start + i] << 24);
-            l += (output[start + i + 1] << 16);
-            l += (output[start + i + 2] << 16);
-            l += (output[start + i + 3] << 16);
-            sum += l;
-            if (sum > 0xffffffff) {
-                sum = sum - 0xffffffff;
+            long l = 0;
+            for (int j = 0; j < 4; j++) {
+                l <<= 8;
+                l |= data[start + i + j] & 0xff;
             }
+            sum += l;
         }
-
-        return sum;
+        return (int) sum;
     }
 
     private void createCheckSumAdjustment() {
-        long sum = getLongCheckSum(0, realSize);
+        long sum = getCheckSum(output, 0, realSize);
         int checksum = (int)(0xb1b0afba - sum);
         writeULong(checkSumAdjustmentOffset, checksum);
     }
-
 }
-
-
-

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/hyphenation/HyphenationTreeCache.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/hyphenation/HyphenationTreeCache.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/hyphenation/HyphenationTreeCache.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/hyphenation/HyphenationTreeCache.java Thu Jul  5 20:29:53 2012
@@ -79,7 +79,7 @@ public class HyphenationTreeCache {
         String userKey = null;
         if (hyphPatNames != null) {
             String key = constructLlccKey(lang, country);
-            key.replace('_', '-');
+            key = key.replace('_', '-');
             userKey = (String) hyphPatNames.get(key);
         }
         return userKey;
@@ -96,7 +96,7 @@ public class HyphenationTreeCache {
 
     /**
      * Notes a key to a hyphenation tree as missing.
-     * This is to avoid searching a second time for a hyphneation pattern file which is not
+     * This is to avoid searching a second time for a hyphenation pattern file which is not
      * available.
      * @param key the key (ex. "de_CH" or "en")
      */
@@ -109,7 +109,7 @@ public class HyphenationTreeCache {
 
     /**
      * Indicates whether a hyphenation file has been requested before but it wasn't available.
-     * This is to avoid searching a second time for a hyphneation pattern file which is not
+     * This is to avoid searching a second time for a hyphenation pattern file which is not
      * available.
      * @param key the key (ex. "de_CH" or "en")
      * @return true if the hyphenation tree is unavailable

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java Thu Jul  5 20:29:53 2012
@@ -41,12 +41,16 @@ public class BalancingColumnBreakingAlgo
      * @param topLevelLM the top level layout manager
      * @param pageProvider the page provider
      * @param layoutListener the layout listener
-     * @param alignment     alignment of the paragraph/page. One of {@link Constants#EN_START},
-     *                  {@link Constants#EN_JUSTIFY}, {@link Constants#EN_CENTER},
-     *                  {@link Constants#EN_END}.
-     *                  For pages, {@link Constants#EN_BEFORE} and {@link Constants#EN_AFTER}
-     *                  are mapped to the corresponding inline properties,
-     *                  {@link Constants#EN_START} and {@link Constants#EN_END}.
+     * @param alignment     alignment of the paragraph/page. One of
+     *   {@link org.apache.fop.fo.Constants#EN_START},
+     *   {@link org.apache.fop.fo.Constants#EN_JUSTIFY},
+     *   {@link org.apache.fop.fo.Constants#EN_CENTER},
+     *   {@link org.apache.fop.fo.Constants#EN_END}.
+     *   For pages, {@link org.apache.fop.fo.Constants#EN_BEFORE} and
+     *   {@link org.apache.fop.fo.Constants#EN_AFTER}
+     *   are mapped to the corresponding inline properties,
+     *   {@link org.apache.fop.fo.Constants#EN_START} and
+     *   {@link org.apache.fop.fo.Constants#EN_END}.
      * @param alignmentLast alignment of the paragraph's last line
      * @param footnoteSeparatorLength length of footnote separator
      * @param partOverflowRecovery  {@code true} if too long elements should be moved to

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/layoutmgr/BreakElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/layoutmgr/BreakElement.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/layoutmgr/BreakElement.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/layoutmgr/BreakElement.java Thu Jul  5 20:29:53 2012
@@ -46,8 +46,11 @@ public class BreakElement extends Unreso
      * Create a new BreakElement for the given {@code position}, {@code penaltyValue}
      * and {@code breakClass}. (Used principally to generate break-possibilities in
      * ranges of content that must be kept together within the context corresponding
-     * to the {@code breakClass}; expected to be one of {@link Constants#EN_AUTO},
-     * {@link Constants#EN_LINE}, {@link Constants#EN_COLUMN} or {@link Constants#EN_PAGE})
+     * to the {@code breakClass}; expected to be one of
+     *   {@link org.apache.fop.fo.Constants#EN_AUTO},
+     *   {@link org.apache.fop.fo.Constants#EN_LINE},
+     *   {@link org.apache.fop.fo.Constants#EN_COLUMN} or
+     *   {@link org.apache.fop.fo.Constants#EN_PAGE})
      * @param position  the corresponding {@link Position}
      * @param penaltyValue  the penalty value
      * @param breakClass    the break class
@@ -64,9 +67,12 @@ public class BreakElement extends Unreso
      * @param position the Position instance needed by the addAreas stage of the LMs.
      * @param penaltyWidth the penalty width
      * @param penaltyValue the penalty value for the penalty element to be constructed
-     * @param breakClass the break class of this penalty (one of {@link Constants#EN_AUTO},
-     * {@link Constants#EN_COLUMN}, {@link Constants#EN_PAGE},
-     * {@link Constants#EN_EVEN_PAGE}, {@link Constants#EN_ODD_PAGE})
+     * @param breakClass the break class of this penalty (one of
+     *   {@link org.apache.fop.fo.Constants#EN_AUTO},
+     *   {@link org.apache.fop.fo.Constants#EN_COLUMN},
+     *   {@link org.apache.fop.fo.Constants#EN_PAGE},
+     *   {@link org.apache.fop.fo.Constants#EN_EVEN_PAGE},
+     *   {@link org.apache.fop.fo.Constants#EN_ODD_PAGE})
      * @param context the layout context which contains the pending conditional elements
      */
     public BreakElement(Position position, int penaltyWidth, int penaltyValue,
@@ -120,9 +126,12 @@ public class BreakElement extends Unreso
     /**
      * Returns the break class of this penalty.
      *
-     * @return one of {@link Constants#EN_AUTO}, {@link Constants#EN_COLUMN},
-     * {@link Constants#EN_PAGE}, {@link Constants#EN_EVEN_PAGE},
-     * {@link Constants#EN_ODD_PAGE}
+     * @return one of
+     *   {@link org.apache.fop.fo.Constants#EN_AUTO},
+     *   {@link org.apache.fop.fo.Constants#EN_COLUMN},
+     *   {@link org.apache.fop.fo.Constants#EN_PAGE},
+     *   {@link org.apache.fop.fo.Constants#EN_EVEN_PAGE},
+     *   {@link org.apache.fop.fo.Constants#EN_ODD_PAGE}.
      */
     public int getBreakClass() {
         return breakClass;
@@ -131,9 +140,12 @@ public class BreakElement extends Unreso
     /**
      * Sets the break class.
      *
-     * @param breakClass one of {@link Constants#EN_AUTO}, {@link Constants#EN_COLUMN},
-     * {@link Constants#EN_PAGE}, {@link Constants#EN_EVEN_PAGE},
-     * {@link Constants#EN_ODD_PAGE}
+     * @param breakClass one of
+     *   {@link org.apache.fop.fo.Constants#EN_AUTO},
+     *   {@link org.apache.fop.fo.Constants#EN_COLUMN},
+     *   {@link org.apache.fop.fo.Constants#EN_PAGE},
+     *   {@link org.apache.fop.fo.Constants#EN_EVEN_PAGE},
+     *   {@link org.apache.fop.fo.Constants#EN_ODD_PAGE}.
      */
     public void setBreakClass(int breakClass) {
         this.breakClass = breakClass;

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/layoutmgr/KnuthPenalty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/layoutmgr/KnuthPenalty.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/layoutmgr/KnuthPenalty.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/layoutmgr/KnuthPenalty.java Thu Jul  5 20:29:53 2012
@@ -72,8 +72,11 @@ public class KnuthPenalty extends KnuthE
      * @param penalty the penalty value of this penalty
      * @param penaltyFlagged is this penalty flagged?
      * @param breakClass the break class of this penalty (one of
-     * {@link Constants#EN_AUTO}, {@link Constants#EN_COLUMN}, {@link Constants#EN_PAGE},
-     * {@link Constants#EN_EVEN_PAGE}, {@link Constants#EN_ODD_PAGE})
+     *   {@link org.apache.fop.fo.Constants#EN_AUTO},
+     *   {@link org.apache.fop.fo.Constants#EN_COLUMN},
+     *   {@link org.apache.fop.fo.Constants#EN_PAGE},
+     *   {@link org.apache.fop.fo.Constants#EN_EVEN_PAGE},
+     *   {@link org.apache.fop.fo.Constants#EN_ODD_PAGE}).
      * @param pos the Position stored in this penalty
      * @param isAuxiliary is this penalty auxiliary?
      */

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/AbstractPDFStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/AbstractPDFStream.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/AbstractPDFStream.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/AbstractPDFStream.java Thu Jul  5 20:29:53 2012
@@ -78,7 +78,7 @@ public abstract class AbstractPDFStream 
      * from outside.
      */
     protected void setupFilterList() {
-        if (!getFilterList().isInitialized()) {
+        if (multipleFiltersAllowed() && !getFilterList().isInitialized()) {
             getFilterList().addDefaultFilters(
                 getDocumentSafely().getFilterMap(),
                 getDefaultFilterName());
@@ -273,4 +273,11 @@ public abstract class AbstractPDFStream 
         //nop: No default implicit filters
     }
 
+    /**
+     * Whether multiple filters can be applied.
+     * @return true if multiple filters allowed
+     */
+    protected boolean multipleFiltersAllowed() {
+        return true;
+    }
 }

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/AlphaRasterImage.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/AlphaRasterImage.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/AlphaRasterImage.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/AlphaRasterImage.java Thu Jul  5 20:29:53 2012
@@ -212,6 +212,10 @@ public class AlphaRasterImage implements
         return null;
     }
 
+    /** {@inheritDoc} */
+    public boolean multipleFiltersAllowed() {
+        return true;
+    }
 }
 
 

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/BitmapImage.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/BitmapImage.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/BitmapImage.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/BitmapImage.java Thu Jul  5 20:29:53 2012
@@ -37,6 +37,8 @@ public class BitmapImage implements PDFI
     private PDFColor transparent = null;
     private String key;
     private PDFDocument pdfDoc;
+    private PDFFilter pdfFilter;
+    private boolean multipleFiltersAllowed = true;
 
     /**
      * Create a bitmap image.
@@ -208,9 +210,23 @@ public class BitmapImage implements PDFI
      * {@inheritDoc}
      */
     public PDFFilter getPDFFilter() {
-        return null;
+        return pdfFilter;
     }
 
-}
+    public void setPDFFilter(PDFFilter pdfFilter) {
+        this.pdfFilter = pdfFilter;
+    }
+
+    /** {@inheritDoc} */
+    public boolean multipleFiltersAllowed() {
+        return multipleFiltersAllowed;
+    }
 
+    /**
+     * Disallows multiple filters.
+     */
+    public void disallowMultipleFilters() {
+        multipleFiltersAllowed = false;
+    }
 
+}

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFColor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFColor.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFColor.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFColor.java Thu Jul  5 20:29:53 2012
@@ -30,7 +30,7 @@ import org.apache.xmlgraphics.java2d.col
  * image. And in this context, only RGB and Gray values are used.
  * <p>
  * Use of this class is discouraged. {@link PDFColorHandler} is now used for in-content color
- * selection. For masked bitmaps, it may be wiser to switch to {@link Color} in the long run.
+ * selection. For masked bitmaps, it may be wiser to switch to {@link java.awt.Color} in the long run.
  */
 public class PDFColor extends PDFPathPaint {
     // could be 3.0 as well.

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFEmbeddedFile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFEmbeddedFile.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFEmbeddedFile.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFEmbeddedFile.java Thu Jul  5 20:29:53 2012
@@ -38,7 +38,10 @@ public class PDFEmbeddedFile extends PDF
         put("Params", params);
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Determine if should encode on the fly.
+     * @return true if should encode on the fly
+     */
     protected boolean isEncodingOnTheFly() {
         //Acrobat doesn't like an indirect /Length object in this case,
         //but only when the embedded file is a PDF file.

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFFactory.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFFactory.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFFactory.java Thu Jul  5 20:29:53 2012
@@ -45,6 +45,7 @@ import org.apache.commons.logging.LogFac
 
 import org.apache.xmlgraphics.java2d.color.ColorUtil;
 import org.apache.xmlgraphics.java2d.color.NamedColorSpace;
+
 import org.apache.xmlgraphics.xmp.Metadata;
 
 import org.apache.fop.fonts.CIDFont;
@@ -1674,8 +1675,8 @@ public class PDFFactory {
                         FontFileReader reader = new FontFileReader(in);
 
                         TTFSubSetFile subset = new TTFSubSetFile();
-                        byte[] subsetFont = subset.readFont(reader,
-                                             mbfont.getTTCName(), mbfont.getUsedGlyphs());
+                        subset.readFont(reader, mbfont.getTTCName(), mbfont.getUsedGlyphs());
+                        byte[] subsetFont = subset.getFontSubset();
                         // Only TrueType CID fonts are supported now
 
                         embeddedFont = new PDFTTFStream(subsetFont.length);

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFImage.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFImage.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFImage.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFImage.java Thu Jul  5 20:29:53 2012
@@ -151,5 +151,13 @@ public interface PDFImage {
      */
     String getFilterHint();
 
+    /**
+     * Indicates whether multiple image filters are allowed; this is implemented because Adobe
+     * Reader does not like multiple FlateDecode filters applied to an image even though that
+     * allowed by the PDF spec; this is probable due to security concerns since many PDF malware
+     * exploits, like zip bombs, make use of a chain of FlateDecode filters.
+     */
+    boolean multipleFiltersAllowed();
+
 }
 

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFImageXObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFImageXObject.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFImageXObject.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFImageXObject.java Thu Jul  5 20:29:53 2012
@@ -166,4 +166,9 @@ public class PDFImageXObject extends PDF
         return pdfimage.getFilterHint();
     }
 
+    /** {@inheritDoc} */
+    protected boolean multipleFiltersAllowed() {
+        return pdfimage.multipleFiltersAllowed();
+    }
+
 }

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFObject.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFObject.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFObject.java Thu Jul  5 20:29:53 2012
@@ -22,7 +22,6 @@ package org.apache.fop.pdf;
 // Java
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.Writer;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -211,11 +210,6 @@ 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()) {
             textBuffer.append(referencePDF());

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFResources.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFResources.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFResources.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/pdf/PDFResources.java Thu Jul  5 20:29:53 2012
@@ -21,9 +21,8 @@ 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.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -46,33 +45,33 @@ public class PDFResources extends PDFDic
     /**
      * /Font objects keyed by their internal name
      */
-    protected Map fonts = new HashMap();
+    protected Map<String, PDFFont> fonts = new LinkedHashMap<String, PDFFont>();
 
     /**
      * Set of XObjects
      */
-    protected Set xObjects = new HashSet();
+    protected Set<PDFXObject> xObjects = new LinkedHashSet<PDFXObject>();
 
     /**
      * Set of patterns
      */
-    protected Set patterns = new HashSet();
+    protected Set<PDFPattern> patterns = new LinkedHashSet<PDFPattern>();
 
     /**
      * Set of shadings
      */
-    protected Set shadings = new HashSet();
+    protected Set<PDFShading> shadings = new LinkedHashSet<PDFShading>();
 
     /**
      * Set of ExtGStates
      */
-    protected Set gstates = new HashSet();
+    protected Set<PDFGState> gstates = new LinkedHashSet<PDFGState>();
 
     /** Map of color spaces (key: color space name) */
-    protected Map colorSpaces = new HashMap();
+    protected Map<PDFName, PDFColorSpace> colorSpaces = new LinkedHashMap<PDFName, PDFColorSpace>();
 
     /** Map of ICC color spaces (key: ICC profile description) */
-    protected Map iccColorSpaces = new HashMap();
+    protected Map<String, PDFICCBasedColorSpace> iccColorSpaces = new LinkedHashMap<String, PDFICCBasedColorSpace>();
 
     /**
      * create a /Resources object.
@@ -168,7 +167,7 @@ public class PDFResources extends PDFDic
             PDFICCBasedColorSpace icc = (PDFICCBasedColorSpace)colorSpace;
             String desc = ColorProfileUtil.getICCProfileDescription(
                     icc.getICCStream().getICCProfile());
-            this.iccColorSpaces.put(desc, colorSpace);
+            this.iccColorSpaces.put(desc, icc);
         }
     }
 
@@ -178,7 +177,7 @@ public class PDFResources extends PDFDic
      * @return the requested color space or null if it wasn't found
      */
     public PDFICCBasedColorSpace getICCColorSpaceByProfileName(String desc) {
-        PDFICCBasedColorSpace cs = (PDFICCBasedColorSpace)this.iccColorSpaces.get(desc);
+        PDFICCBasedColorSpace cs = this.iccColorSpaces.get(desc);
         return cs;
     }
 
@@ -188,7 +187,7 @@ public class PDFResources extends PDFDic
      * @return the requested color space or null if it wasn't found
      */
     public PDFColorSpace getColorSpace(PDFName name) {
-        PDFColorSpace cs = (PDFColorSpace)this.colorSpaces.get(name);
+        PDFColorSpace cs = this.colorSpaces.get(name);
         return cs;
     }
 
@@ -202,28 +201,24 @@ public class PDFResources extends PDFDic
         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();
-                dict.put(fontName, (PDFFont)this.fonts.get(fontName));
+            for (Map.Entry<String, PDFFont> entry : fonts.entrySet()) {
+                dict.put(entry.getKey(), entry.getValue());
             }
             put("Font", dict);
         }
 
         if (!this.shadings.isEmpty()) {
             PDFDictionary dict = new PDFDictionary(this);
-            for (Iterator iter = shadings.iterator(); iter.hasNext();) {
-                PDFShading currentShading = (PDFShading)iter.next();
-                dict.put(currentShading.getName(), currentShading);
+            for (PDFShading shading : shadings) {
+                dict.put(shading.getName(), shading);
             }
             put("Shading", dict);
         }
 
         if (!this.patterns.isEmpty()) {
             PDFDictionary dict = new PDFDictionary(this);
-            for (Iterator iter = patterns.iterator(); iter.hasNext();) {
-                PDFPattern currentPattern = (PDFPattern)iter.next();
-                dict.put(currentPattern.getName(), currentPattern);
+            for (PDFPattern pattern : patterns) {
+                dict.put(pattern.getName(), pattern);
             }
             put("Pattern", dict);
         }
@@ -237,26 +232,23 @@ public class PDFResources extends PDFDic
 
         if (this.xObjects != null && !this.xObjects.isEmpty()) {
             PDFDictionary dict = new PDFDictionary(this);
-            for (Iterator iter = xObjects.iterator(); iter.hasNext();) {
-                PDFXObject xobj = (PDFXObject)iter.next();
-                dict.put(xobj.getName().toString(), xobj);
+            for (PDFXObject xObject : xObjects) {
+                dict.put(xObject.getName().toString(), xObject);
             }
             put("XObject", dict);
         }
 
         if (!this.gstates.isEmpty()) {
             PDFDictionary dict = new PDFDictionary(this);
-            for (Iterator iter = gstates.iterator(); iter.hasNext();) {
-                PDFGState gs = (PDFGState)iter.next();
-                dict.put(gs.getName(), gs);
+            for (PDFGState gstate : gstates) {
+                dict.put(gstate.getName(), gstate);
             }
             put("ExtGState", dict);
         }
 
         if (!this.colorSpaces.isEmpty()) {
             PDFDictionary dict = new PDFDictionary(this);
-            for (Iterator iter = colorSpaces.values().iterator(); iter.hasNext();) {
-                PDFColorSpace colorSpace = (PDFColorSpace)iter.next();
+            for (PDFColorSpace colorSpace : colorSpaces.values()) {
                 dict.put(colorSpace.getName(), colorSpace);
             }
             put("ColorSpace", dict);

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/ImageHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/ImageHandler.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/ImageHandler.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/ImageHandler.java Thu Jul  5 20:29:53 2012
@@ -33,7 +33,8 @@ public interface ImageHandler extends Im
      * Indicates whether the image handler is compatible with the indicated target represented
      * by the rendering context object and with the image to be processed. The image is also
      * passed as a parameter because a handler might not support every subtype of image that is
-     * presented. For example: in the case of {@link ImageXMLDOM}, the image might carry an SVG
+     * presented. For example: in the case of
+     * {@link org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM}, the image might carry an SVG
      * or some other XML format. One handler might only handle SVG but no other XML format.
      * @param targetContext the target rendering context
      * @param image the image to be processed (or null if only to check based on the rendering

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java Thu Jul  5 20:29:53 2012
@@ -58,7 +58,8 @@ import org.apache.fop.render.intermediat
 import org.apache.fop.render.intermediate.IFPainter;
 
 /**
- * {@link IFDocumentHandler} implementation that produces AFP (MO:DCA).
+ * {@link org.apache.fop.render.intermediate.IFDocumentHandler} implementation that
+ * produces AFP (MO:DCA).
  */
 public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
             implements AFPCustomizable {

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMap.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMap.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMap.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMap.java Thu Jul  5 20:29:53 2012
@@ -27,7 +27,7 @@ import org.xml.sax.helpers.AttributesImp
 
 /**
  * This extension allows to include an AFP form map resource. It is implemented as an extension
- * attachment ({@link ExtensionAttachment}).
+ * attachment ({@link org.apache.fop.fo.extensions.ExtensionAttachment}).
  */
 public class AFPIncludeFormMap extends AFPExtensionAttachment {
 

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMapElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMapElement.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMapElement.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/extensions/AFPIncludeFormMapElement.java Thu Jul  5 20:29:53 2012
@@ -32,8 +32,8 @@ import org.apache.fop.fo.PropertyList;
 import org.apache.fop.fo.extensions.ExtensionAttachment;
 
 /**
- * This class extends the {@link ExtensionObj} class. It represents the "include-form-map"
- * extension in the FO tree.
+ * This class extends the {@link org.apache.fop.fo.extensions.ExtensionObj} class.
+ * It represents the "include-form-map" extension in the FO tree.
  */
 public class AFPIncludeFormMapElement extends AbstractAFPExtensionObject {
 

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/extensions/AFPPageOverlay.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/extensions/AFPPageOverlay.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/extensions/AFPPageOverlay.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/afp/extensions/AFPPageOverlay.java Thu Jul  5 20:29:53 2012
@@ -25,7 +25,7 @@ import org.xml.sax.helpers.AttributesImp
 
 /**
  * This extension allows to include an AFP Page Overlay resource. It is implemented as an extension
- * attachment ({@link ExtensionAttachment}).
+ * attachment ({@link org.apache.fop.fo.extensions.ExtensionAttachment}).
  */
 public class AFPPageOverlay extends AFPExtensionAttachment {
 

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java Thu Jul  5 20:29:53 2012
@@ -47,7 +47,8 @@ import org.apache.fop.render.java2d.Java
 import org.apache.fop.render.java2d.Java2DUtil;
 
 /**
- * Abstract {@link IFDocumentHandler} implementation for producing bitmap images.
+ * Abstract {@link org.apache.fop.render.intermediate.IFDocumentHandler} implementation
+ * for producing bitmap images.
  */
 public abstract class AbstractBitmapDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
 

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/bitmap/PNGDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/bitmap/PNGDocumentHandler.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/bitmap/PNGDocumentHandler.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/bitmap/PNGDocumentHandler.java Thu Jul  5 20:29:53 2012
@@ -23,7 +23,8 @@ import org.apache.fop.apps.MimeConstants
 import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
 
 /**
- * {@link IFDocumentHandler} implementation that produces PNG files.
+ * {@link org.apache.fop.render.intermediate.IFDocumentHandler} implementation
+ * that produces PNG files.
  */
 public class PNGDocumentHandler extends AbstractBitmapDocumentHandler {
 

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java Thu Jul  5 20:29:53 2012
@@ -23,7 +23,8 @@ import org.apache.fop.apps.MimeConstants
 import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
 
 /**
- * {@link IFDocumentHandler} implementation that produces TIFF files.
+ * {@link org.apache.fop.render.intermediate.IFDocumentHandler} implementation
+ * that produces TIFF files.
  */
 public class TIFFDocumentHandler extends AbstractBitmapDocumentHandler {
 

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/intermediate/IFContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/intermediate/IFContext.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/intermediate/IFContext.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/intermediate/IFContext.java Thu Jul  5 20:29:53 2012
@@ -145,7 +145,7 @@ public class IFContext {
 
     /**
      * Resets the current structure tree element.
-     * @see #setStructureTreeElement(String)
+     * @see #setStructureTreeElement(StructureTreeElement)
      */
     public void resetStructureTreeElement() {
         setStructureTreeElement(null);
@@ -154,7 +154,7 @@ public class IFContext {
     /**
      * Returns the current structure tree element.
      * @return the structure tree element (or null if no element is active)
-     * @see #setStructureTreeElement(String)
+     * @see #setStructureTreeElement(StructureTreeElement)
      */
     public StructureTreeElement getStructureTreeElement() {
         return this.structureTreeElement;

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/intermediate/IFSerializer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/intermediate/IFSerializer.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/intermediate/IFSerializer.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/intermediate/IFSerializer.java Thu Jul  5 20:29:53 2012
@@ -64,6 +64,15 @@ import org.apache.fop.util.XMLUtil;
 public class IFSerializer extends AbstractXMLWritingIFDocumentHandler
         implements IFConstants, IFPainter, IFDocumentNavigationHandler {
 
+    /**
+     * Intermediate Format (IF) version, used to express an @version attribute
+     * in the root element of the IF document, the initial value of which
+     * is set to '2.0' to signify that something preceded it (but didn't
+     * happen to be marked as such), and that this version is not necessarily
+     * backwards compatible with the unmarked (<2.0) version.
+     */
+    public static final String VERSION = "2.0";
+
     private IFDocumentHandler mimicHandler;
     private int pageSequenceIndex; // used for accessibility
 
@@ -167,7 +176,9 @@ public class IFSerializer extends Abstra
                     DocumentNavigationExtensionConstants.NAMESPACE);
             handler.startPrefixMapping(InternalElementMapping.STANDARD_PREFIX,
                     InternalElementMapping.URI);
-            handler.startElement(EL_DOCUMENT);
+            AttributesImpl atts = new AttributesImpl();
+            addAttribute(atts, "version", VERSION);
+            handler.startElement(EL_DOCUMENT, atts);
         } catch (SAXException e) {
             throw new IFException("SAX error in startDocument()", e);
         }

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/intermediate/IFUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/intermediate/IFUtil.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/intermediate/IFUtil.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/intermediate/IFUtil.java Thu Jul  5 20:29:53 2012
@@ -147,8 +147,8 @@ public final class IFUtil {
 
     /**
      * Sets up the fonts on a document handler. If the document handler provides a configurator
-     * object the configuration from the {@link FopFactory} will be used. Otherwise,
-     * a default font configuration will be set up.
+     * object the configuration from the {@link org.apache.fop.apps.FopFactory} will be used.
+     * Otherwise, a default font configuration will be set up.
      * @param documentHandler the document handler
      * @param fontInfo the font info object (may be null)
      * @throws FOPException if an error occurs while setting up the fonts
@@ -175,8 +175,8 @@ public final class IFUtil {
 
     /**
      * Sets up the fonts on a document handler. If the document handler provides a configurator
-     * object the configuration from the {@link FopFactory} will be used. Otherwise,
-     * a default font configuration will be set up.
+     * object the configuration from the {@link org.apache.fop.apps.FopFactory} will be used.
+     * Otherwise, a default font configuration will be set up.
      * @param documentHandler the document handler
      * @throws FOPException if an error occurs while setting up the fonts
      */

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java Thu Jul  5 20:29:53 2012
@@ -89,7 +89,8 @@ public class ConfiguredFontCollection im
                     font = new CustomFontMetricsMapper(fontMetrics, fontSource);
                 } else {
                     CustomFont fontMetrics = FontLoader.loadFont(
-                            fontFile, null, true, EncodingMode.AUTO,
+                            fontFile, null, true, configFontInfo.getEmbeddingMode(),
+                            EncodingMode.AUTO,
                             configFontInfo.getKerning(),
                             configFontInfo.getAdvanced(), fontResolver);
                     font = new CustomFontMetricsMapper(fontMetrics);

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java Thu Jul  5 20:29:53 2012
@@ -36,7 +36,7 @@ import org.apache.fop.fonts.Typeface;
 
 /**
  * FontMetricsMapper that delegates most methods to an underlying
- * {@link FontMetrics} instance. This class was designed to allow
+ * {@link org.apache.fop.fonts.FontMetrics} instance. This class was designed to allow
  * the underlying {@link Font} to be loaded from a
  * user-configured file not registered in the current graphics environment.
  */

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/java2d/Java2DPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/java2d/Java2DPainter.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/java2d/Java2DPainter.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/java2d/Java2DPainter.java Thu Jul  5 20:29:53 2012
@@ -47,7 +47,8 @@ import org.apache.fop.traits.RuleStyle;
 import org.apache.fop.util.CharUtilities;
 
 /**
- * {@link IFPainter} implementation that paints on a Graphics2D instance.
+ * {@link org.apache.fop.render.intermediate.IFPainter} implementation
+ * that paints on a Graphics2D instance.
  */
 public class Java2DPainter extends AbstractIFPainter {
 

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java Thu Jul  5 20:29:53 2012
@@ -45,7 +45,8 @@ import org.apache.fop.render.java2d.Java
 import org.apache.fop.render.pcl.extensions.PCLElementMapping;
 
 /**
- * {@link IFDocumentHandler} implementation that produces PCL 5.
+ * {@link org.apache.fop.render.intermediate.IFDocumentHandler} implementation
+ * that produces PCL 5.
  */
 public class PCLDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
             implements PCLConstants {

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pcl/PCLPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pcl/PCLPainter.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pcl/PCLPainter.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pcl/PCLPainter.java Thu Jul  5 20:29:53 2012
@@ -58,7 +58,8 @@ import org.apache.fop.traits.RuleStyle;
 import org.apache.fop.util.CharUtilities;
 
 /**
- * {@link IFPainter} implementation that produces PCL 5.
+ * {@link org.apache.fop.render.intermediate.IFPainter} implementation
+ * that produces PCL 5.
  */
 public class PCLPainter extends AbstractIFPainter implements PCLConstants {
 

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java Thu Jul  5 20:29:53 2012
@@ -20,13 +20,16 @@
 package org.apache.fop.render.pdf;
 import java.awt.color.ColorSpace;
 import java.awt.color.ICC_Profile;
+import java.awt.image.IndexColorModel;
 
+import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.xmlgraphics.image.loader.Image;
 import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
 
+import org.apache.fop.pdf.PDFArray;
 import org.apache.fop.pdf.PDFColor;
 import org.apache.fop.pdf.PDFConformanceException;
 import org.apache.fop.pdf.PDFDeviceColorSpace;
@@ -50,7 +53,11 @@ public abstract class AbstractImageAdapt
     /** the image */
     protected Image image;
 
-    private PDFICCStream pdfICCStream = null;
+    private PDFICCStream pdfICCStream;
+
+    private static final int MAX_HIVAL = 255;
+
+    private boolean multipleFiltersAllowed = true;
 
     /**
      * Creates a new PDFImage from an Image instance.
@@ -203,6 +210,68 @@ public abstract class AbstractImageAdapt
     }
 
     /**
+     * This is to be used by populateXObjectDictionary() when the image is palette based.
+     * @param dict the dictionary to fill in
+     * @param icm the image color model
+     */
+    protected void populateXObjectDictionaryForIndexColorModel(PDFDictionary dict, IndexColorModel icm) {
+        PDFArray indexed = new PDFArray(dict);
+        indexed.add(new PDFName("Indexed"));
+        if (icm.getColorSpace().getType() != ColorSpace.TYPE_RGB) {
+            log.warn("Indexed color space is not using RGB as base color space."
+                    + " The image may not be handled correctly." + " Base color space: "
+                    + icm.getColorSpace() + " Image: " + image.getInfo());
+        }
+        indexed.add(new PDFName(toPDFColorSpace(icm.getColorSpace()).getName()));
+        int c = icm.getMapSize();
+        int hival = c - 1;
+        if (hival > MAX_HIVAL) {
+            throw new UnsupportedOperationException("hival must not go beyond " + MAX_HIVAL);
+        }
+        indexed.add(Integer.valueOf(hival));
+        int[] palette = new int[c];
+        icm.getRGBs(palette);
+        ByteArrayOutputStream baout = new ByteArrayOutputStream();
+        for (int i = 0; i < c; i++) {
+            // TODO Probably doesn't work for non RGB based color spaces
+            // See log warning above
+            int entry = palette[i];
+            baout.write((entry & 0xFF0000) >> 16);
+            baout.write((entry & 0xFF00) >> 8);
+            baout.write(entry & 0xFF);
+        }
+        indexed.add(baout.toByteArray());
+
+        dict.put("ColorSpace", indexed);
+        dict.put("BitsPerComponent", icm.getPixelSize());
+
+        Integer index = getIndexOfFirstTransparentColorInPalette(icm);
+        if (index != null) {
+            PDFArray mask = new PDFArray(dict);
+            mask.add(index);
+            mask.add(index);
+            dict.put("Mask", mask);
+        }
+    }
+
+    private static Integer getIndexOfFirstTransparentColorInPalette(IndexColorModel icm) {
+        byte[] alphas = new byte[icm.getMapSize()];
+        byte[] reds = new byte[icm.getMapSize()];
+        byte[] greens = new byte[icm.getMapSize()];
+        byte[] blues = new byte[icm.getMapSize()];
+        icm.getAlphas(alphas);
+        icm.getReds(reds);
+        icm.getGreens(greens);
+        icm.getBlues(blues);
+        for (int i = 0; i < icm.getMapSize(); i++) {
+            if ((alphas[i] & 0xFF) == 0) {
+                return Integer.valueOf(i);
+            }
+        }
+        return null;
+    }
+
+    /**
      * Converts a ColorSpace object to a PDFColorSpace object.
      * @param cs ColorSpace instance
      * @return PDFColorSpace new converted object
@@ -226,5 +295,17 @@ public abstract class AbstractImageAdapt
         return pdfCS;
     }
 
+    /** {@inheritDoc} */
+    public boolean multipleFiltersAllowed() {
+        return multipleFiltersAllowed;
+    }
+
+    /**
+     * Disallows multiple filters.
+     */
+    public void disallowMultipleFilters() {
+        multipleFiltersAllowed = false;
+    }
+
 }
 

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pdf/ImageRenderedAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pdf/ImageRenderedAdapter.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pdf/ImageRenderedAdapter.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/pdf/ImageRenderedAdapter.java Thu Jul  5 20:29:53 2012
@@ -27,8 +27,6 @@ import java.awt.image.RenderedImage;
 import java.io.IOException;
 import java.io.OutputStream;
 
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -36,14 +34,12 @@ import org.apache.xmlgraphics.image.load
 import org.apache.xmlgraphics.ps.ImageEncodingHelper;
 
 import org.apache.fop.pdf.AlphaRasterImage;
-import org.apache.fop.pdf.PDFArray;
 import org.apache.fop.pdf.PDFColor;
 import org.apache.fop.pdf.PDFDeviceColorSpace;
 import org.apache.fop.pdf.PDFDictionary;
 import org.apache.fop.pdf.PDFDocument;
 import org.apache.fop.pdf.PDFFilter;
 import org.apache.fop.pdf.PDFFilterList;
-import org.apache.fop.pdf.PDFName;
 import org.apache.fop.pdf.PDFReference;
 
 /**
@@ -162,30 +158,6 @@ public class ImageRenderedAdapter extend
         return (getImage().getTransparentColor() != null);
     }
 
-    private static Integer getIndexOfFirstTransparentColorInPalette(RenderedImage image) {
-        ColorModel cm = image.getColorModel();
-        if (cm instanceof IndexColorModel) {
-            IndexColorModel icm = (IndexColorModel)cm;
-            //Identify the transparent color in the palette
-            byte[] alphas = new byte[icm.getMapSize()];
-            byte[] reds = new byte[icm.getMapSize()];
-            byte[] greens = new byte[icm.getMapSize()];
-            byte[] blues = new byte[icm.getMapSize()];
-            icm.getAlphas(alphas);
-            icm.getReds(reds);
-            icm.getGreens(greens);
-            icm.getBlues(blues);
-            for (int i = 0;
-                    i < ((IndexColorModel) cm).getMapSize();
-                    i++) {
-                if ((alphas[i] & 0xFF) == 0) {
-                    return Integer.valueOf(i);
-                }
-            }
-        }
-        return null;
-    }
-
     /** {@inheritDoc} */
     @Override
     public PDFColor getTransparentColor() {
@@ -230,54 +202,13 @@ public class ImageRenderedAdapter extend
         }
     }
 
-    private static final int MAX_HIVAL = 255;
-
     /** {@inheritDoc} */
     @Override
     public void populateXObjectDictionary(PDFDictionary dict) {
         ColorModel cm = getEffectiveColorModel();
         if (cm instanceof IndexColorModel) {
-            IndexColorModel icm = (IndexColorModel)cm;
-            PDFArray indexed = new PDFArray(dict);
-            indexed.add(new PDFName("Indexed"));
-
-            if (icm.getColorSpace().getType() != ColorSpace.TYPE_RGB) {
-                log.warn("Indexed color space is not using RGB as base color space."
-                        + " The image may not be handled correctly."
-                        + " Base color space: " + icm.getColorSpace()
-                        + " Image: " + image.getInfo());
-            }
-            indexed.add(new PDFName(toPDFColorSpace(icm.getColorSpace()).getName()));
-            int c = icm.getMapSize();
-            int hival = c - 1;
-            if (hival > MAX_HIVAL) {
-                throw new UnsupportedOperationException("hival must not go beyond " + MAX_HIVAL);
-            }
-            indexed.add(Integer.valueOf(hival));
-            int[] palette = new int[c];
-            icm.getRGBs(palette);
-            ByteArrayOutputStream baout = new ByteArrayOutputStream();
-            for (int i = 0; i < c; i++) {
-                //TODO Probably doesn't work for non RGB based color spaces
-                //See log warning above
-                int entry = palette[i];
-                baout.write((entry & 0xFF0000) >> 16);
-                baout.write((entry & 0xFF00) >> 8);
-                baout.write(entry & 0xFF);
-            }
-            indexed.add(baout.toByteArray());
-            IOUtils.closeQuietly(baout);
-
-            dict.put("ColorSpace", indexed);
-            dict.put("BitsPerComponent", icm.getPixelSize());
-
-            Integer index = getIndexOfFirstTransparentColorInPalette(getImage().getRenderedImage());
-            if (index != null) {
-                PDFArray mask = new PDFArray(dict);
-                mask.add(index);
-                mask.add(index);
-                dict.put("Mask", mask);
-            }
+            IndexColorModel icm = (IndexColorModel) cm;
+            super.populateXObjectDictionaryForIndexColorModel(dict, icm);
         }
     }
 

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/ps/FontResourceCache.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/ps/FontResourceCache.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/ps/FontResourceCache.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/ps/FontResourceCache.java Thu Jul  5 20:29:53 2012
@@ -42,19 +42,20 @@ class FontResourceCache {
     }
 
     /**
-     * Returns the PSResource for the given font key.
+     * Returns the PSFontResource for the given font key.
      * @param key the font key ("F*")
-     * @return the matching PSResource
+     * @return the matching PSFontResource instance
      */
-    public PSResource getPSResourceForFontKey(String key) {
-        PSResource res = null;
+    public PSFontResource getFontResourceForFontKey(String key) {
+        PSFontResource res = null;
         if (this.fontResources != null) {
-            res = (PSResource)this.fontResources.get(key);
+            res = (PSFontResource)this.fontResources.get(key);
         } else {
             this.fontResources = new java.util.HashMap();
         }
         if (res == null) {
-            res = new PSResource(PSResource.TYPE_FONT, getPostScriptNameForFontKey(key));
+            res = PSFontResource.createFontResource(
+                    new PSResource(PSResource.TYPE_FONT, getPostScriptNameForFontKey(key)));
             this.fontResources.put(key, res);
         }
         return res;
@@ -76,9 +77,9 @@ class FontResourceCache {
             throw new IllegalStateException("Font not available: " + key);
         }
         if (postFix == null) {
-            return tf.getFontName();
+            return tf.getEmbedFontName();
         } else {
-            return tf.getFontName() + postFix;
+            return tf.getEmbedFontName() + postFix;
         }
     }
 

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/ps/NativeTextHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/ps/NativeTextHandler.java?rev=1357883&r1=1357882&r2=1357883&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/ps/NativeTextHandler.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/render/ps/NativeTextHandler.java Thu Jul  5 20:29:53 2012
@@ -100,12 +100,6 @@ public class NativeTextHandler implement
         //nop
     }
 
-    /** {@inheritDoc} */
-    public void drawString(String text, float x, float y) throws IOException {
-        // TODO Remove me after removing the deprecated method in TextHandler.
-        throw new UnsupportedOperationException("Deprecated method!");
-    }
-
     /**
      * Draw a string to the PostScript document. The text is painted using
      * text operations.



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