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 lb...@apache.org on 2013/08/15 00:35:38 UTC

svn commit: r1514076 [5/5] - in /xmlgraphics/fop/trunk: ./ lib/ src/java/org/apache/fop/complexscripts/fonts/ src/java/org/apache/fop/fonts/ src/java/org/apache/fop/fonts/apps/ src/java/org/apache/fop/fonts/autodetect/ src/java/org/apache/fop/fonts/cff...

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java?rev=1514076&r1=1514075&r2=1514076&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java Wed Aug 14 22:35:37 2013
@@ -43,7 +43,7 @@ public class TTFSubSetFile extends TTFFi
      * Offsets in name table to be filled out by table.
      * The offsets are to the checkSum field
      */
-    private Map<TTFTableName, Integer> offsets = new HashMap<TTFTableName, Integer>();
+    private Map<OFTableName, Integer> offsets = new HashMap<OFTableName, Integer>();
 
     private int checkSumAdjustmentOffset = 0;
     private int locaOffset = 0;
@@ -67,8 +67,8 @@ public class TTFSubSetFile extends TTFFi
     }
 
     /** The dir tab entries in the new subset font. */
-    private Map<TTFTableName, TTFDirTabEntry> newDirTabs
-                        = new HashMap<TTFTableName, TTFDirTabEntry>();
+    private Map<OFTableName, OFDirTabEntry> newDirTabs
+                        = new HashMap<OFTableName, OFDirTabEntry>();
 
     private int determineTableCount() {
         int numTables = 4; //4 req'd tables: head,hhea,hmtx,maxp
@@ -117,29 +117,29 @@ 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);
+        writeTableName(OFTableName.OS2);
 
         if (hasCvt()) {
-            writeTableName(TTFTableName.CVT);
+            writeTableName(OFTableName.CVT);
         }
         if (hasFpgm()) {
-            writeTableName(TTFTableName.FPGM);
+            writeTableName(OFTableName.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);
+        writeTableName(OFTableName.GLYF);
+        writeTableName(OFTableName.HEAD);
+        writeTableName(OFTableName.HHEA);
+        writeTableName(OFTableName.HMTX);
+        writeTableName(OFTableName.LOCA);
+        writeTableName(OFTableName.MAXP);
+        writeTableName(OFTableName.NAME);
+        writeTableName(OFTableName.POST);
         if (hasPrep()) {
-            writeTableName(TTFTableName.PREP);
+            writeTableName(OFTableName.PREP);
         }
-        newDirTabs.put(TTFTableName.TABLE_DIRECTORY, new TTFDirTabEntry(0, currentPos));
+        newDirTabs.put(OFTableName.TABLE_DIRECTORY, new OFDirTabEntry(0, currentPos));
     }
 
-    private void writeTableName(TTFTableName tableName) {
+    private void writeTableName(OFTableName tableName) {
         writeString(tableName.getName());
         offsets.put(tableName, currentPos);
         currentPos += 12;
@@ -148,15 +148,15 @@ public class TTFSubSetFile extends TTFFi
 
 
     private boolean hasCvt() {
-        return dirTabs.containsKey(TTFTableName.CVT);
+        return dirTabs.containsKey(OFTableName.CVT);
     }
 
     private boolean hasFpgm() {
-        return dirTabs.containsKey(TTFTableName.FPGM);
+        return dirTabs.containsKey(OFTableName.FPGM);
     }
 
     private boolean hasPrep() {
-        return dirTabs.containsKey(TTFTableName.PREP);
+        return dirTabs.containsKey(OFTableName.PREP);
     }
 
     /**
@@ -165,15 +165,15 @@ public class TTFSubSetFile extends TTFFi
     private void createLoca(int size) throws IOException {
         pad4();
         locaOffset = currentPos;
-        int dirTableOffset = offsets.get(TTFTableName.LOCA);
+        int dirTableOffset = offsets.get(OFTableName.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);
+    private boolean copyTable(FontFileReader in, OFTableName tableName) throws IOException {
+        OFDirTabEntry entry = dirTabs.get(tableName);
         if (entry != null) {
             pad4();
             seekTab(in, tableName, 0);
@@ -193,28 +193,28 @@ public class TTFSubSetFile extends TTFFi
      * Copy the cvt table as is from original font to subset font
      */
     private boolean createCvt(FontFileReader in) throws IOException {
-        return copyTable(in, TTFTableName.CVT);
+        return copyTable(in, OFTableName.CVT);
     }
 
     /**
      * Copy the fpgm table as is from original font to subset font
      */
     private boolean createFpgm(FontFileReader in) throws IOException {
-        return copyTable(in, TTFTableName.FPGM);
+        return copyTable(in, OFTableName.FPGM);
     }
 
     /**
      * Copy the name table as is from the original.
      */
     private boolean createName(FontFileReader in) throws IOException {
-        return copyTable(in, TTFTableName.NAME);
+        return copyTable(in, OFTableName.NAME);
     }
 
     /**
      * Copy the OS/2 table as is from the original.
      */
     private boolean createOS2(FontFileReader in) throws IOException {
-        return copyTable(in, TTFTableName.OS2);
+        return copyTable(in, OFTableName.OS2);
     }
 
     /**
@@ -222,8 +222,8 @@ public class TTFSubSetFile extends TTFFi
      * and set num glyphs to size
      */
     private void createMaxp(FontFileReader in, int size) throws IOException {
-        TTFTableName maxp = TTFTableName.MAXP;
-        TTFDirTabEntry entry = dirTabs.get(maxp);
+        OFTableName maxp = OFTableName.MAXP;
+        OFDirTabEntry entry = dirTabs.get(maxp);
         if (entry != null) {
             pad4();
             seekTab(in, maxp, 0);
@@ -240,8 +240,8 @@ public class TTFSubSetFile extends TTFFi
     }
 
     private void createPost(FontFileReader in) throws IOException {
-        TTFTableName post = TTFTableName.POST;
-        TTFDirTabEntry entry = dirTabs.get(post);
+        OFTableName post = OFTableName.POST;
+        OFDirTabEntry entry = dirTabs.get(post);
         if (entry != null) {
             pad4();
             seekTab(in, post, 0);
@@ -266,7 +266,7 @@ public class TTFSubSetFile extends TTFFi
      * Copy the prep table as is from original font to subset font
      */
     private boolean createPrep(FontFileReader in) throws IOException {
-        return copyTable(in, TTFTableName.PREP);
+        return copyTable(in, OFTableName.PREP);
     }
 
 
@@ -275,15 +275,15 @@ public class TTFSubSetFile extends TTFFi
      * and fill in size of hmtx table
      */
     private void createHhea(FontFileReader in, int size) throws IOException {
-        TTFDirTabEntry entry = dirTabs.get(TTFTableName.HHEA);
+        OFDirTabEntry entry = dirTabs.get(OFTableName.HHEA);
         if (entry != null) {
             pad4();
-            seekTab(in, TTFTableName.HHEA, 0);
+            seekTab(in, OFTableName.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);
+            updateCheckSum(currentPos, (int) entry.getLength(), OFTableName.HHEA);
             currentPos += (int) entry.getLength();
             realSize += (int) entry.getLength();
         } else {
@@ -299,8 +299,8 @@ public class TTFSubSetFile extends TTFFi
      * in checkSumAdjustmentOffset
      */
     private void createHead(FontFileReader in) throws IOException {
-        TTFTableName head = TTFTableName.HEAD;
-        TTFDirTabEntry entry = dirTabs.get(head);
+        OFTableName head = OFTableName.HEAD;
+        OFDirTabEntry entry = dirTabs.get(head);
         if (entry != null) {
             pad4();
             seekTab(in, head, 0);
@@ -329,8 +329,8 @@ public class TTFSubSetFile extends TTFFi
      */
     private void createGlyf(FontFileReader in,
             Map<Integer, Integer> glyphs) throws IOException {
-        TTFTableName glyf = TTFTableName.GLYF;
-        TTFDirTabEntry entry = dirTabs.get(glyf);
+        OFTableName glyf = OFTableName.GLYF;
+        OFDirTabEntry entry = dirTabs.get(glyf);
         int size = 0;
         int startPos = 0;
         int endOffset = 0;    // Store this as the last loca
@@ -393,10 +393,10 @@ public class TTFSubSetFile extends TTFFi
             writeULong(locaOffset + glyphs.size() * 4, endOffset);
             int locaSize = glyphs.size() * 4 + 4;
             int checksum = getCheckSum(output, locaOffset, locaSize);
-            writeULong(offsets.get(TTFTableName.LOCA), checksum);
+            writeULong(offsets.get(OFTableName.LOCA), checksum);
             int padSize = (locaOffset + locaSize) % 4;
-            newDirTabs.put(TTFTableName.LOCA,
-                    new TTFDirTabEntry(locaOffset, locaSize + padSize));
+            newDirTabs.put(OFTableName.LOCA,
+                    new OFDirTabEntry(locaOffset, locaSize + padSize));
         } else {
             throw new IOException("Can't find glyf table");
         }
@@ -420,8 +420,8 @@ public class TTFSubSetFile extends TTFFi
      */
     private void createHmtx(FontFileReader in,
                             Map<Integer, Integer> glyphs) throws IOException {
-        TTFTableName hmtx = TTFTableName.HMTX;
-        TTFDirTabEntry entry = dirTabs.get(hmtx);
+        OFTableName hmtx = OFTableName.HMTX;
+        OFDirTabEntry entry = dirTabs.get(hmtx);
 
         int longHorMetricSize = glyphs.size() * 2;
         int leftSideBearingSize = glyphs.size() * 2;
@@ -457,11 +457,11 @@ public class TTFSubSetFile extends TTFFi
      * new index as (Integer) value)
      * @throws IOException in case of an I/O problem
      */
-    public void readFont(FontFileReader in, String name,
+    public void readFont(FontFileReader in, String name, String header,
                            Map<Integer, Integer> glyphs) throws IOException {
         fontFile = in;
         //Check if TrueType collection, and that the name exists in the collection
-        if (!checkTTC(name)) {
+        if (!checkTTC(header, name)) {
             throw new IOException("Failed to read font");
         }
 
@@ -533,7 +533,7 @@ public class TTFSubSetFile extends TTFFi
                     glyphOffsets[i + 1] - glyphOffsets[i]);
         }
         // Stream the last glyph
-        TTFDirTabEntry glyf = newDirTabs.get(TTFTableName.GLYF);
+        OFDirTabEntry glyf = newDirTabs.get(OFTableName.GLYF);
         long lastGlyphLength = glyf.getLength()
             - (glyphOffsets[glyphOffsets.length - 1] - glyf.getOffset());
         glyphOut.streamGlyph(output, glyphOffsets[glyphOffsets.length - 1],
@@ -543,14 +543,14 @@ public class TTFSubSetFile extends TTFFi
 
     @Override
     public void stream(TTFOutputStream ttfOut) throws IOException {
-        SortedSet<Map.Entry<TTFTableName, TTFDirTabEntry>>  sortedDirTabs
+        SortedSet<Map.Entry<OFTableName, OFDirTabEntry>>  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)) {
+        for (Map.Entry<OFTableName, OFDirTabEntry>  entry : sortedDirTabs) {
+            if (entry.getKey().equals(OFTableName.GLYF)) {
                     handleGlyphSubset(glyphOut);
             } else {
                 tableOut.streamTable(output, (int) entry.getValue().getOffset(),
@@ -562,7 +562,7 @@ public class TTFSubSetFile extends TTFFi
 
     private void scanGlyphs(FontFileReader in, Map<Integer, Integer> subsetGlyphs)
             throws IOException {
-        TTFDirTabEntry glyfTableInfo = dirTabs.get(TTFTableName.GLYF);
+        OFDirTabEntry glyfTableInfo = dirTabs.get(OFTableName.GLYF);
         if (glyfTableInfo == null) {
             throw new IOException("Glyf table could not be found");
         }
@@ -663,11 +663,11 @@ public class TTFSubSetFile extends TTFFi
     }
 
 
-    private void updateCheckSum(int tableStart, int tableSize, TTFTableName tableName) {
+    private void updateCheckSum(int tableStart, int tableSize, OFTableName 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));
+        newDirTabs.put(tableName, new OFDirTabEntry(tableStart, tableSize + padSize));
         writeULong(offset, checksum);
         writeULong(offset + 4, tableStart);
         writeULong(offset + 8, tableSize);

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFCFFStreamType0C.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFCFFStreamType0C.java?rev=1514076&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFCFFStreamType0C.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFCFFStreamType0C.java Wed Aug 14 22:35:37 2013
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * PDFStream for embeddable OpenType CFF fonts.
+ */
+public class PDFCFFStreamType0C extends AbstractPDFFontStream {
+
+    private byte[] cffData;
+    private boolean fullEmbed;
+
+    /**
+     * Main constructor
+     * @param fullEmbed Determines whether the font is fully embedded
+     */
+    public PDFCFFStreamType0C(boolean fullEmbed) {
+        super();
+        this.fullEmbed = fullEmbed;
+    }
+
+    protected int getSizeHint() throws IOException {
+        if (this.cffData != null) {
+            return cffData.length;
+        } else {
+            return 0; //no hint available
+        }
+    }
+
+    /** {@inheritDoc} */
+    protected void outputRawStreamData(OutputStream out) throws IOException {
+        out.write(this.cffData);
+    }
+
+    /** {@inheritDoc} */
+    protected void populateStreamDict(Object lengthEntry) {
+        String type = (fullEmbed) ? "OpenType" : "CIDFontType0C";
+        put("Subtype", new PDFName(type));
+        super.populateStreamDict(lengthEntry);
+    }
+
+    /**
+     * Sets the CFF font data.
+     * @param data the font payload
+     * @param size size of the payload
+     * @throws IOException in case of an I/O problem
+     */
+    public void setData(byte[] data, int size) throws IOException {
+        this.cffData = new byte[size];
+        System.arraycopy(data, 0, this.cffData, 0, size);
+    }
+
+}
+

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFCFFStreamType0C.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFEncryptionJCE.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFEncryptionJCE.java?rev=1514076&r1=1514075&r2=1514076&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFEncryptionJCE.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFEncryptionJCE.java Wed Aug 14 22:35:37 2013
@@ -449,14 +449,13 @@ public final class PDFEncryptionJCE exte
 
     private class Rev5Engine extends InitializationEngine {
 
-        // private SecureRandom random = new SecureRandom();
-        private byte[] userValidationSalt = new byte[8];
-        private byte[] userKeySalt = new byte[8];
-        private byte[] ownerValidationSalt = new byte[8];
-        private byte[] ownerKeySalt = new byte[8];
-        private byte[] ueValue;
-        private byte[] oeValue;
-        private final boolean encryptMetadata;
+        protected byte[] userValidationSalt = new byte[8];
+        protected byte[] userKeySalt = new byte[8];
+        protected byte[] ownerValidationSalt = new byte[8];
+        protected byte[] ownerKeySalt = new byte[8];
+        protected byte[] ueValue;
+        protected byte[] oeValue;
+        protected final boolean encryptMetadata;
 
         Rev5Engine(EncryptionSettings encryptionSettings) {
             super(encryptionSettings);
@@ -563,7 +562,7 @@ public final class PDFEncryptionJCE exte
         /**
          * Algorithm 3.8-2 (page 20, Adobe Supplement to the ISO 32000, BaseVersion: 1.7, ExtensionLevel: 3)
          */
-        private void computeUEValue() {
+        protected void computeUEValue() {
             digest.reset();
             byte[] prepared = preparedUserPassword;
             byte[] concatenated = new byte[prepared.length + 8];
@@ -577,7 +576,7 @@ public final class PDFEncryptionJCE exte
         /**
          * Algorithm 3.9-2 (page 20, Adobe Supplement to the ISO 32000, BaseVersion: 1.7, ExtensionLevel: 3)
          */
-        private void computeOEValue() {
+        protected void computeOEValue() {
             digest.reset();
             byte[] prepared = preparedOwnerPassword;
             byte[] concatenated = new byte[prepared.length + 56];
@@ -615,6 +614,86 @@ public final class PDFEncryptionJCE exte
         }
     }
 
+    private class Rev6Engine extends Rev5Engine {
+
+        private MessageDigest digest384;
+        private MessageDigest digest512;
+
+        Rev6Engine(EncryptionSettings encryptionSettings) {
+            super(encryptionSettings);
+            try {
+                digest384 = MessageDigest.getInstance("SHA-384");
+                digest512 = MessageDigest.getInstance("SHA-512");
+            } catch (NoSuchAlgorithmException e) {
+                throw new UnsupportedOperationException(e.getMessage());
+            }
+        }
+
+        @Override
+        protected void computeUValue() {
+            byte[] userBytes = new byte[16];
+            random.nextBytes(userBytes);
+            System.arraycopy(userBytes, 0, userValidationSalt, 0, 8);
+            System.arraycopy(userBytes, 8, userKeySalt, 0, 8);
+            digest.reset();
+            byte[] prepared = preparedUserPassword;
+            byte[] concatenated = new byte[prepared.length + 8];
+            System.arraycopy(prepared, 0, concatenated, 0, prepared.length);
+            System.arraycopy(userValidationSalt, 0, concatenated, prepared.length, 8);
+            digest.update(concatenated);
+            byte[] block = digest.digest();
+            int blockSize = 32;
+            byte[] key = new byte[16];
+            byte[] iv = new byte[16];
+            int length = prepared.length + blockSize;
+            byte[] data = new byte[length * 64];
+            for (int i = 0; i < 64 || i < data[length * 64 - 1] + 32; i++) {
+                System.arraycopy(block, 0, key, 0, 16);
+                System.arraycopy(block, 16, iv, 0, 16);
+                for (int j = 0; j < 64; j++) {
+                    System.arraycopy(prepared, 0, data, j * length, prepared.length);
+                    System.arraycopy(block, 0, data, j * length + prepared.length, blockSize);
+                }
+                try {
+                    final Cipher cipher = PDFEncryptionJCE.initCipher(key, false, iv);
+                    data = cipher.doFinal(data);
+                } catch (IllegalBlockSizeException e) {
+                    throw new IllegalStateException(e.getMessage());
+                } catch (BadPaddingException e) {
+                    throw new IllegalStateException(e.getMessage());
+                }
+                int sum = 0;
+                for (int k = 0; k < 16; k++) {
+                    sum += data[k];
+                }
+                blockSize = 32 + (sum % 3) * 16;
+                switch (blockSize) {
+                case 32:
+                    digest.reset();
+                    digest.update(data);
+                    block = digest.digest();
+                    break;
+                case 48:
+                    digest384.reset();
+                    digest384.update(data);
+                    block = digest384.digest();
+                    break;
+                case 64:
+                    digest512.reset();
+                    digest512.update(data);
+                    block = digest512.digest();
+                    break;
+                default:
+                    // not possible
+                    break;
+                }
+                length = prepared.length + blockSize;
+                data = new byte[length * 64];
+            }
+        }
+
+    }
+
     private class EncryptionFilter extends PDFFilter {
 
         private int streamNumber;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFactory.java?rev=1514076&r1=1514075&r2=1514076&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFactory.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFactory.java Wed Aug 14 22:35:37 2013
@@ -56,6 +56,8 @@ import org.apache.fop.fonts.SingleByteEn
 import org.apache.fop.fonts.SingleByteFont;
 import org.apache.fop.fonts.Typeface;
 import org.apache.fop.fonts.truetype.FontFileReader;
+import org.apache.fop.fonts.truetype.OFFontLoader;
+import org.apache.fop.fonts.truetype.OTFSubSetFile;
 import org.apache.fop.fonts.truetype.TTFSubSetFile;
 import org.apache.fop.fonts.type1.PFBData;
 import org.apache.fop.fonts.type1.PFBParser;
@@ -1387,15 +1389,15 @@ public class PDFFactory {
                 int firstChar = singleByteFont.getFirstChar();
                 int lastChar = singleByteFont.getLastChar();
                 nonBase14.setWidthMetrics(firstChar,
-                                     lastChar,
-                                     new PDFArray(null, metrics.getWidths()));
+                lastChar,
+                new PDFArray(null, metrics.getWidths()));
 
                 //Handle encoding
                 SingleByteEncoding mapping = singleByteFont.getEncoding();
                 if (singleByteFont.isSymbolicFont()) {
                     //no encoding, use the font's encoding
                     if (forceToUnicode) {
-                        generateToUnicodeCmap(nonBase14, mapping);
+                    generateToUnicodeCmap(nonBase14, mapping);
                     }
                 } else if (PDFEncoding.isPredefinedEncoding(mapping.getName())) {
                     font.setEncoding(mapping.getName());
@@ -1403,7 +1405,7 @@ public class PDFFactory {
                     //believed.
                 } else {
                     Object pdfEncoding = createPDFEncoding(mapping,
-                            singleByteFont.getFontName());
+                    singleByteFont.getFontName());
                     if (pdfEncoding instanceof PDFEncoding) {
                         font.setEncoding((PDFEncoding)pdfEncoding);
                     } else {
@@ -1518,7 +1520,8 @@ public class PDFFactory {
 
         // Check if the font is embeddable
         if (desc.isEmbeddable()) {
-            AbstractPDFStream stream = makeFontFile(desc);
+            AbstractPDFStream stream = makeFontFile(desc, fontPrefix);
+
             if (stream != null) {
                 descriptor.setFontFile(desc.getFontType(), stream);
                 getDocument().registerObject(stream);
@@ -1564,7 +1567,7 @@ public class PDFFactory {
      * @param desc FontDescriptor of the font.
      * @return PDFStream The embedded font file
      */
-    public AbstractPDFStream makeFontFile(FontDescriptor desc) {
+    public AbstractPDFStream makeFontFile(FontDescriptor desc, String fontPrefix) {
         if (desc.getFontType() == FontType.OTHER) {
             throw new IllegalArgumentException("Trying to embed unsupported font type: "
                                                 + desc.getFontType());
@@ -1578,20 +1581,24 @@ public class PDFFactory {
             if (in == null) {
                 return null;
             } else {
-                AbstractPDFStream embeddedFont;
+                AbstractPDFStream embeddedFont = null;
                 if (desc.getFontType() == FontType.TYPE0) {
                     MultiByteFont mbfont = (MultiByteFont) font;
                     FontFileReader reader = new FontFileReader(in);
                     byte[] fontBytes;
+                    String header = OFFontLoader.readHeader(reader);
+                    boolean isCFF = mbfont.isOTFFile();
                     if (font.getEmbeddingMode() == EmbeddingMode.FULL) {
                         fontBytes = reader.getAllBytes();
+                        if (isCFF) {
+                            //Ensure version 1.6 for full OTF CFF embedding
+                            document.setPDFVersion(Version.V1_6);
+                        }
                     } else {
-                        TTFSubSetFile ttfFile = new TTFSubSetFile();
-                        ttfFile.readFont(reader, mbfont.getTTCName(), mbfont.getUsedGlyphs());
-                        fontBytes = ttfFile.getFontSubset();
+                        fontBytes = getFontSubsetBytes(reader, mbfont, header, fontPrefix, desc,
+                                isCFF);
                     }
-                    embeddedFont = new PDFTTFStream(fontBytes.length);
-                    ((PDFTTFStream) embeddedFont).setData(fontBytes, fontBytes.length);
+                    embeddedFont = getFontStream(font, fontBytes, isCFF);
                 } else if (desc.getFontType() == FontType.TYPE1) {
                     PFBParser parser = new PFBParser();
                     PFBData pfb = parser.parsePFB(in);
@@ -1621,6 +1628,32 @@ public class PDFFactory {
         }
     }
 
+    private byte[] getFontSubsetBytes(FontFileReader reader, MultiByteFont mbfont, String header,
+            String fontPrefix, FontDescriptor desc, boolean isCFF) throws IOException {
+        if (isCFF) {
+            OTFSubSetFile otfFile = new OTFSubSetFile();
+            otfFile.readFont(reader, fontPrefix + desc.getEmbedFontName(), header, mbfont);
+            return otfFile.getFontSubset();
+        } else {
+            TTFSubSetFile otfFile = new TTFSubSetFile();
+            otfFile.readFont(reader, mbfont.getTTCName(), header, mbfont.getUsedGlyphs());
+            return otfFile.getFontSubset();
+        }
+    }
+
+    private AbstractPDFStream getFontStream(CustomFont font, byte[] fontBytes, boolean isCFF)
+            throws IOException {
+        AbstractPDFStream embeddedFont;
+        if (isCFF) {
+            embeddedFont = new PDFCFFStreamType0C(font.getEmbeddingMode() == EmbeddingMode.FULL);
+            ((PDFCFFStreamType0C) embeddedFont).setData(fontBytes, fontBytes.length);
+        } else {
+            embeddedFont = new PDFTTFStream(fontBytes.length);
+            ((PDFTTFStream) embeddedFont).setData(fontBytes, fontBytes.length);
+        }
+        return embeddedFont;
+    }
+
     private CustomFont getCustomFont(FontDescriptor desc) {
         Typeface tempFont;
         if (desc instanceof LazyFont) {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFontDescriptor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFontDescriptor.java?rev=1514076&r1=1514075&r2=1514076&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFontDescriptor.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFontDescriptor.java Wed Aug 14 22:35:37 2013
@@ -102,6 +102,8 @@ public class PDFFontDescriptor extends P
     public void setFontFile(FontType subtype, AbstractPDFStream fontfile) {
         if (subtype == FontType.TYPE1) {
             put("FontFile", fontfile);
+        } else if (fontfile instanceof PDFCFFStreamType0C) {
+            put("FontFile3", fontfile);
         } else {
             put("FontFile2", fontfile);
         }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSFontUtils.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSFontUtils.java?rev=1514076&r1=1514075&r2=1514076&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSFontUtils.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSFontUtils.java Wed Aug 14 22:35:37 2013
@@ -29,6 +29,7 @@ import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.fontbox.cff.CFFStandardString;
 
 import org.apache.xmlgraphics.fonts.Glyphs;
 import org.apache.xmlgraphics.ps.DSCConstants;
@@ -50,9 +51,14 @@ import org.apache.fop.fonts.MultiByteFon
 import org.apache.fop.fonts.SingleByteEncoding;
 import org.apache.fop.fonts.SingleByteFont;
 import org.apache.fop.fonts.Typeface;
+import org.apache.fop.fonts.cff.CFFDataReader;
+import org.apache.fop.fonts.cff.CFFDataReader.DICTEntry;
 import org.apache.fop.fonts.truetype.FontFileReader;
+import org.apache.fop.fonts.truetype.OFFontLoader;
+import org.apache.fop.fonts.truetype.OTFFile;
+import org.apache.fop.fonts.truetype.OTFSubSetFile;
+import org.apache.fop.fonts.truetype.OpenFont.PostScriptVersion;
 import org.apache.fop.fonts.truetype.TTFFile;
-import org.apache.fop.fonts.truetype.TTFFile.PostScriptVersion;
 import org.apache.fop.fonts.truetype.TTFOutputStream;
 import org.apache.fop.fonts.truetype.TTFSubSetFile;
 import org.apache.fop.render.ps.fonts.PSTTFOutputStream;
@@ -221,6 +227,7 @@ public class PSFontUtils extends org.apa
 
     private static PSFontResource embedFont(PSGenerator gen, Typeface tf, PSResource fontRes,
             PSEventProducer eventProducer) throws IOException {
+        boolean embeddedFont = false;
         FontType fontType = tf.getFontType();
         PSFontResource fontResource = null;
         if (!(fontType == FontType.TYPE1 || fontType == FontType.TRUETYPE
@@ -232,52 +239,63 @@ public class PSFontUtils extends org.apa
         CustomFont cf = (CustomFont)tf;
         if (isEmbeddable(cf)) {
             InputStream in = getInputStreamOnFont(gen, cf);
-            if (in == null) {
+            if (in != null) {
+                if (fontType == FontType.TYPE0) {
+                    if (((MultiByteFont)tf).isOTFFile()) {
+                        checkPostScriptLevel3(gen, eventProducer, "OpenType CFF");
+                        embedType2CFF(gen, (MultiByteFont) tf, in);
+                    } else {
+                        if (gen.embedIdentityH()) {
+                            checkPostScriptLevel3(gen, eventProducer, "TrueType");
+                            /*
+                             * First CID-keyed font to be embedded; add
+                             * %%IncludeResource: comment for ProcSet CIDInit.
+                             */
+                            gen.includeProcsetCIDInitResource();
+                        }
+                        PSResource cidFontResource;
+                        cidFontResource = embedType2CIDFont(gen,
+                                (MultiByteFont) tf, in);
+                        fontResource = PSFontResource.createFontResource(fontRes,
+                                gen.getProcsetCIDInitResource(), gen.getIdentityHCMapResource(),
+                                cidFontResource);
+                    }
+                }
+                gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE, fontRes);
+                if (fontType == FontType.TYPE1) {
+                    embedType1Font(gen, in);
+                    fontResource = PSFontResource.createFontResource(fontRes);
+                } else if (fontType == FontType.TRUETYPE) {
+                    embedTrueTypeFont(gen, (SingleByteFont) tf, in);
+                    fontResource = PSFontResource.createFontResource(fontRes);
+                } else {
+                    composeType0Font(gen, (MultiByteFont) tf, in);
+                }
+                gen.writeDSCComment(DSCConstants.END_RESOURCE);
+                gen.getResourceTracker().registerSuppliedResource(fontRes);
+                embeddedFont = true;
+            } else {
                 gen.commentln("%WARNING: Could not embed font: " + cf.getEmbedFontName());
                 log.warn("Font " + cf.getEmbedFontName() + " is marked as supplied in the"
                         + " PostScript file but could not be embedded!");
-                gen.writeDSCComment(DSCConstants.INCLUDE_RESOURCE, fontRes);
-                fontResource = PSFontResource.createFontResource(fontRes);
-                return fontResource;
-            }
-            if (fontType == FontType.TYPE0) {
-                if (gen.embedIdentityH()) {
-                    checkPostScriptLevel3(gen, eventProducer);
-                    /*
-                     * First CID-keyed font to be embedded; add
-                     * %%IncludeResource: comment for ProcSet CIDInit.
-                     */
-                    gen.includeProcsetCIDInitResource();
-                }
-                PSResource cidFontResource = embedType2CIDFont(gen,
-                        (MultiByteFont) tf, in);
-                fontResource = PSFontResource.createFontResource(fontRes,
-                        gen.getProcsetCIDInitResource(), gen.getIdentityHCMapResource(),
-                        cidFontResource);
-            }
-            gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE, fontRes);
-            if (fontType == FontType.TYPE1) {
-                embedType1Font(gen, in);
-                fontResource = PSFontResource.createFontResource(fontRes);
-            } else if (fontType == FontType.TRUETYPE) {
-                embedTrueTypeFont(gen, (SingleByteFont) tf, in);
-                fontResource = PSFontResource.createFontResource(fontRes);
-            } else {
-                composeType0Font(gen, (MultiByteFont) tf, in);
             }
-            gen.writeDSCComment(DSCConstants.END_RESOURCE);
-            gen.getResourceTracker().registerSuppliedResource(fontRes);
+        }
+        if (!embeddedFont) {
+            gen.writeDSCComment(DSCConstants.INCLUDE_RESOURCE, fontRes);
+            fontResource = PSFontResource.createFontResource(fontRes);
+            return fontResource;
         }
         return fontResource;
     }
 
-    private static void checkPostScriptLevel3(PSGenerator gen, PSEventProducer eventProducer) {
+    private static void checkPostScriptLevel3(PSGenerator gen, PSEventProducer eventProducer,
+            String fontType) {
         if (gen.getPSLevel() < 3) {
             if (eventProducer != null) {
                 eventProducer.postscriptLevel3Needed(gen);
             } else {
                 throw new IllegalStateException("PostScript Level 3 is"
-                        + " required to use TrueType fonts,"
+                        + " required to use " + fontType + " fonts,"
                         + " configured level is "
                         + gen.getPSLevel());
             }
@@ -415,6 +433,96 @@ public class PSFontUtils extends org.apa
         gen.writeln("] composefont pop");
     }
 
+    private static void embedType2CFF(PSGenerator gen,
+            MultiByteFont font, InputStream fontStream) throws IOException {
+        FontFileReader reader = new FontFileReader(fontStream);
+        String header = OFFontLoader.readHeader(reader);
+        String psName;
+        CFFDataReader cffReader = new CFFDataReader(reader);
+        if (cffReader.getFDSelect() != null) {
+            throw new UnsupportedOperationException("CID-Keyed OTF CFF fonts are not supported"
+                    + " for PostScript output.");
+        }
+
+        byte[] bytes;
+        if (font.getEmbeddingMode() == EmbeddingMode.FULL) {
+            font.setFontName(new String(cffReader.getNameIndex().getValue(0)));
+            psName = font.getEmbedFontName();
+            Map<String, DICTEntry> topDICT = cffReader.getTopDictEntries();
+            int charsetOffset = topDICT.get("charset").getOperands().get(0).intValue();
+            for (int gid = 0; gid < cffReader.getCharStringIndex().getNumObjects(); gid++) {
+                int sid = cffReader.getSIDFromGID(charsetOffset, gid);
+
+                //Check whether the SID falls into the standard string set
+                if (sid < 391) {
+                    font.mapUsedGlyphName(gid,
+                            CFFStandardString.getName(sid));
+                } else {
+                    int index = sid - 391;
+                    if (index < cffReader.getStringIndex().getNumObjects()) {
+                        font.mapUsedGlyphName(gid,
+                                new String(cffReader.getStringIndex().getValue(index)));
+                    } else {
+                        font.mapUsedGlyphName(gid, ".notdef");
+                    }
+                }
+            }
+            bytes = OTFFile.getCFFData(reader);
+        } else {
+            psName = font.getEmbedFontName();
+            OTFSubSetFile otfFile = new OTFSubSetFile();
+            otfFile.readFont(reader, psName, header, font);
+            bytes = otfFile.getFontSubset();
+        }
+
+        gen.writeln("%!PS-Adobe-3.0 Resource-FontSet");
+        gen.writeln("%%DocumentNeedResources:ProcSet(FontSetInit)");
+        gen.writeln("%%Title:(FontSet/" + psName + ")");
+        gen.writeln("%%Version: 1.000");
+        gen.writeln("%%EndComments");
+        gen.writeln("%%IncludeResource:ProcSet(FontSetInit)");
+        gen.writeln("%%BeginResource: FontSet (" + psName + ")");
+        gen.writeln("/FontSetInit /ProcSet findresource begin");
+        //Next line + 1
+        String fontDeclaration = "/" + psName + " " + bytes.length + " StartData";
+        gen.writeln("%%BeginData: " + (fontDeclaration.length() + 1 + bytes.length) + " Binary Bytes");
+        gen.writeln(fontDeclaration);
+        gen.writeByteArr(bytes);
+        gen.writeln("%%EndData");
+        gen.writeln("%%EndResource");
+
+        gen.writeln("/" + psName + ".0.enc [ ");
+        int lengthCount = 0;
+        int charCount = 1;
+        int encodingCount = 0;
+        String line = "";
+        for (int gid : font.getUsedGlyphNames().keySet()) {
+            line += "/" + font.getUsedGlyphNames().get(gid) + " ";
+            lengthCount++;
+            charCount++;
+            if (lengthCount == 8) {
+                gen.writeln(line);
+                line = "";
+                lengthCount = 0;
+            }
+            if (charCount > 256) {
+                encodingCount++;
+                charCount = 1;
+                gen.writeln(line);
+                line = "";
+                lengthCount = 0;
+                gen.writeln("] def");
+                gen.writeln(String.format("/%s.%d %s.%d.enc /%s RE", psName,
+                        encodingCount - 1, psName, encodingCount - 1, psName));
+                gen.writeln("/" + psName + "." + encodingCount + ".enc [ ");
+            }
+        }
+        gen.writeln(line);
+        gen.writeln("] def");
+        gen.writeln(String.format("/%s.%d %s.%d.enc /%s RE", psName, encodingCount,
+                psName, encodingCount, psName));
+    }
+
     private static PSResource embedType2CIDFont(PSGenerator gen,
             MultiByteFont font, InputStream fontStream) throws IOException {
         assert font.getCIDType() == CIDFontType.CIDTYPE2;
@@ -502,17 +610,18 @@ public class PSFontUtils extends org.apa
         }
         gen.writeln(">] def");
         FontFileReader reader = new FontFileReader(fontStream);
+        String header = OFFontLoader.readHeader(reader);
 
         TTFFile ttfFile;
         if (font.getEmbeddingMode() != EmbeddingMode.FULL) {
             ttfFile = new TTFSubSetFile();
-            ttfFile.readFont(reader, font.getTTCName(), font.getUsedGlyphs());
+            //Change the TTFFile to have the abstract method for TTFSubSetFile
+            ((TTFSubSetFile)ttfFile).readFont(reader, font.getTTCName(), header, font.getUsedGlyphs());
         } else {
             ttfFile = new TTFFile();
             ttfFile.readFont(reader, font.getTTCName());
         }
 
-
         createType42DictionaryEntries(gen, font, new CMapSegment[0], ttfFile);
         gen.writeln("CIDFontName currentdict end /CIDFont defineresource pop");
         gen.writeln("end");
@@ -670,7 +779,7 @@ public class PSFontUtils extends org.apa
     private static PSResource defineDerivedTrueTypeFont(PSGenerator gen,
             PSEventProducer eventProducer, String baseFontName, String fontName,
             SingleByteEncoding encoding, CMapSegment[] cmap) throws IOException {
-        checkPostScriptLevel3(gen, eventProducer);
+        checkPostScriptLevel3(gen, eventProducer, "TrueType");
         PSResource res = new PSResource(PSResource.TYPE_FONT, fontName);
         gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE, res);
         gen.commentln("%XGCDependencies: font " + baseFontName);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java?rev=1514076&r1=1514075&r2=1514076&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java Wed Aug 14 22:35:37 2013
@@ -40,6 +40,7 @@ import org.apache.xmlgraphics.image.load
 import org.apache.xmlgraphics.ps.PSGenerator;
 import org.apache.xmlgraphics.ps.PSResource;
 
+import org.apache.fop.fonts.EmbeddingMode;
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontTriplet;
 import org.apache.fop.fonts.LazyFont;
@@ -375,7 +376,13 @@ public class PSPainter extends AbstractI
             }
             Font font = getFontInfo().getFontInstance(triplet, sizeMillipoints);
 
-            useFont(fontKey, sizeMillipoints);
+            PSFontResource res = getDocumentHandler().getPSResourceForFontKey(fontKey);
+            if (tf instanceof MultiByteFont && ((MultiByteFont)tf).isOTFFile()) {
+                generator.writeln("/" + res.getName() + ".0 "
+                        + generator.formatDouble(sizeMillipoints / 1000f) + " F");
+            } else {
+                useFont(fontKey, sizeMillipoints);
+            }
 
             if (dp != null && dp[0] != null) {
                 x += dp[0][0];
@@ -408,7 +415,30 @@ public class PSPainter extends AbstractI
                     }
                 }
             } else {
-                useFont(fontKey, sizeMillipoints);
+                if (tf instanceof MultiByteFont && ((MultiByteFont)tf).isOTFFile()) {
+                    //Analyze string and split up in order to paint in different sub-fonts/encodings
+                    int curEncoding = 0;
+                    for (int i = start; i < textLen; i++) {
+                        char orgChar = text.charAt(i);
+
+                        MultiByteFont mbFont = (MultiByteFont)tf;
+                        int origGlyphIdx = mbFont.findGlyphIndex(orgChar);
+                        int newGlyphIdx = mbFont.getUsedGlyphs().get(origGlyphIdx);
+                        int encoding = newGlyphIdx / 256;
+                        if (encoding != curEncoding) {
+                            if (i != 0) {
+                                writeText(text, start, i - start, letterSpacing, wordSpacing, dp, font, tf,
+                                        true);
+                                start = i;
+                            }
+                            generator.writeln("/" + res.getName() + "." + encoding + " "
+                                    + generator.formatDouble(sizeMillipoints / 1000f) + " F");
+                            curEncoding = encoding;
+                        }
+                    }
+                } else {
+                    useFont(fontKey, sizeMillipoints);
+                }
             }
             writeText(text, start, textLen - start, letterSpacing, wordSpacing, dp, font, tf,
                     tf instanceof MultiByteFont);
@@ -431,12 +461,14 @@ public class PSPainter extends AbstractI
         int lineStart = 0;
         StringBuffer accText = new StringBuffer(initialSize);
         StringBuffer sb = new StringBuffer(initialSize);
+        boolean isOTF = multiByte && ((MultiByteFont)tf).isOTFFile();
         for (int i = start; i < end; i++) {
             char orgChar = text.charAt(i);
             char ch;
             int cw;
             int xGlyphAdjust = 0;
             int yGlyphAdjust = 0;
+
             if (CharUtilities.isFixedWidthSpace(orgChar)) {
                 //Fixed width space are rendered as spaces so copy/paste works in a reader
                 ch = font.mapChar(CharUtilities.SPACE);
@@ -460,11 +492,16 @@ public class PSPainter extends AbstractI
                 xGlyphAdjust -= dp[i + 1][0];
                 yGlyphAdjust += dp[i + 1][1];
             }
-            if (multiByte) {
-                accText.append(HexEncoder.encode(ch));
-            } else {
+            if (!multiByte || isOTF) {
                 char codepoint = (char)(ch % 256);
-                PSGenerator.escapeChar(codepoint, accText); //add character to accumulated text
+                if (isOTF) {
+                    codepoint -= (((MultiByteFont)tf).getEmbeddingMode() == EmbeddingMode.FULL) ? 0 : 1;
+                    accText.append(HexEncoder.encode(codepoint, 2));
+                } else {
+                    PSGenerator.escapeChar(codepoint, accText); //add character to accumulated text
+                }
+            } else {
+                accText.append(HexEncoder.encode(ch));
             }
             if (xGlyphAdjust != 0 || yGlyphAdjust != 0) {
                 needTJ = true;

Added: xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/cff/CFFDataReaderTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/cff/CFFDataReaderTestCase.java?rev=1514076&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/cff/CFFDataReaderTestCase.java (added)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/cff/CFFDataReaderTestCase.java Wed Aug 14 22:35:37 2013
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fonts.cff;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Random;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.fontbox.cff.CFFDataInput;
+
+import org.apache.fop.fonts.cff.CFFDataReader.CFFIndexData;
+import org.apache.fop.fonts.cff.CFFDataReader.DICTEntry;
+import org.apache.fop.fonts.truetype.OTFSubSetFile;
+
+import static org.junit.Assert.assertEquals;
+
+public class CFFDataReaderTestCase {
+    private CFFDataReader cffReader;
+
+    /**
+     * Initializes the CFFDataReader for testing purposes
+     */
+    @Before
+    public void setUp() {
+        cffReader = new CFFDataReader();
+    }
+
+    /**
+     * Parses a test dictionary to verify whether the stored data is read correctly.
+     * @throws IOException
+     */
+    @Test
+    public void parseDictData() throws IOException {
+        byte[] testDictData = prepareDictData();
+        Map<String, DICTEntry> testTopDict = cffReader.parseDictData(testDictData);
+        validateDictData(testTopDict);
+    }
+
+    private byte[] prepareDictData() {
+        byte[] testDictData = new byte[0];
+        //Version
+        testDictData = OTFSubSetFile.concatArray(testDictData, OTFSubSetFile.createNewRef(
+                392, new int[] { 0 }, -1));
+        //Notice
+        testDictData = OTFSubSetFile.concatArray(testDictData, OTFSubSetFile.createNewRef(
+                393, new int[] { 1 }, -1));
+        //Copyright
+        testDictData = OTFSubSetFile.concatArray(testDictData, OTFSubSetFile.createNewRef(
+                394, new int[] { 12, 0 }, -1));
+        //FullName
+        testDictData = OTFSubSetFile.concatArray(testDictData, OTFSubSetFile.createNewRef(
+                395, new int[] { 2 }, -1));
+        //FamilyName
+        testDictData = OTFSubSetFile.concatArray(testDictData, OTFSubSetFile.createNewRef(
+                396, new int[] { 3 }, -1));
+        //Weight
+        testDictData = OTFSubSetFile.concatArray(testDictData, OTFSubSetFile.createNewRef(
+                397, new int[] { 4 }, -1));
+        //isFixedPitch (boolean = false)
+        testDictData = OTFSubSetFile.concatArray(testDictData, OTFSubSetFile.createNewRef(
+                0, new int[] { 12, 1 }, -1));
+        //FontBBox
+        testDictData = OTFSubSetFile.concatArray(testDictData, OTFSubSetFile.createNewRef(
+                -50, new int[0], -1));
+        testDictData = OTFSubSetFile.concatArray(testDictData, OTFSubSetFile.createNewRef(
+                -40, new int[0], -1));
+        testDictData = OTFSubSetFile.concatArray(testDictData, OTFSubSetFile.createNewRef(
+                100, new int[0], -1));
+        testDictData = OTFSubSetFile.concatArray(testDictData, OTFSubSetFile.createNewRef(
+                120, new int[] { 5 }, -1));
+        //charset
+        testDictData = OTFSubSetFile.concatArray(testDictData, OTFSubSetFile.createNewRef(
+                1234, new int[] { 15 }, -1));
+        //CharStrings
+        testDictData = OTFSubSetFile.concatArray(testDictData, OTFSubSetFile.createNewRef(
+                3654, new int[] { 17 }, -1));
+        //Private
+        testDictData = OTFSubSetFile.concatArray(testDictData, OTFSubSetFile.createNewRef(
+                11454, new int[] { 18 }, -1));
+        return testDictData;
+    }
+
+    private void validateDictData(Map<String, DICTEntry> dictMap) {
+        //SID Values (numbers)
+        assertEquals(dictMap.get("version").getOperands().get(0).intValue(), 392);
+        assertEquals(dictMap.get("Notice").getOperands().get(0).intValue(), 393);
+        assertEquals(dictMap.get("Copyright").getOperands().get(0).intValue(), 394);
+        assertEquals(dictMap.get("FullName").getOperands().get(0).intValue(), 395);
+        assertEquals(dictMap.get("FamilyName").getOperands().get(0).intValue(), 396);
+        assertEquals(dictMap.get("Weight").getOperands().get(0).intValue(), 397);
+        //Boolean comparison
+        assertEquals(dictMap.get("isFixedPitch").getOperands().get(0).intValue(), 0);
+        //Array comparison
+        int[] fontBBox = { -50, -40, 100, 120 };
+        DICTEntry fontBBoxEntry = dictMap.get("FontBBox");
+        for (int i = 0;i < fontBBoxEntry.getOperands().size();i++) {
+            assertEquals(fontBBoxEntry.getOperands().get(i).intValue(), fontBBox[i]);
+        }
+        //Multi-byte offset (number)
+        assertEquals(dictMap.get("charset").getOperands().get(0).intValue(), 1234);
+        assertEquals(dictMap.get("CharStrings").getOperands().get(0).intValue(), 3654);
+        //Larger offset
+        assertEquals(dictMap.get("Private").getOperands().get(0).intValue(), 11454);
+    }
+
+    /**
+     * Tests the parsing of an example byte data index structure
+     * @throws IOException
+     */
+    @Test
+    public void testIndexParsing() throws IOException {
+        byte[] testIndex = {
+                0, 5,   //Number of objects
+                1,      //Offset size
+                1,      //Offsets...
+                5,
+                12,
+                24,
+                27,
+                32
+        };
+        Random randGen = new Random();
+        byte[] data = new byte[31];
+        for (int i = 0;i < data.length;i++) {
+            data[i] = (byte)randGen.nextInt(255);
+        }
+        testIndex = OTFSubSetFile.concatArray(testIndex, data);
+        CFFIndexData indexData = cffReader.readIndex(new CFFDataInput(testIndex));
+        assertEquals(indexData.getNumObjects(), 5);
+        assertEquals(indexData.getOffSize(), 1);
+        assertEquals(indexData.getOffsets().length, 6);
+        assertEquals(indexData.getOffsets()[5], 32);
+    }
+}

Propchange: xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/cff/CFFDataReaderTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/GlyfTableTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/GlyfTableTestCase.java?rev=1514076&r1=1514075&r2=1514076&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/GlyfTableTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/GlyfTableTestCase.java Wed Aug 14 22:35:37 2013
@@ -148,14 +148,15 @@ public class GlyfTableTestCase {
 
     private void setupSubsetReader(Map<Integer, Integer> glyphs) throws IOException {
         TTFSubSetFile fontFile = new TTFSubSetFile();
-        fontFile.readFont(originalFontReader, "Deja", glyphs);
+        String header = OFFontLoader.readHeader(subsetReader);
+        fontFile.readFont(originalFontReader, "Deja", header, glyphs);
         byte[] subsetFont = fontFile.getFontSubset();
         InputStream intputStream = new ByteArrayInputStream(subsetFont);
         subsetReader = new FontFileReader(intputStream);
     }
 
     private void readLoca() throws IOException {
-        DirData loca = getTableData("loca");
+        DirData loca = getTableData(OFTableName.LOCA.getName());
         int numberOfGlyphs = (int) (loca.length - 4) / 4;
         glyphOffsets = new long[numberOfGlyphs];
         subsetReader.seekSet(loca.offset);
@@ -166,7 +167,7 @@ public class GlyfTableTestCase {
     }
 
     private int[] retrieveIndicesOfComposedGlyphs() throws IOException {
-        DirData glyf = getTableData("glyf");
+        DirData glyf = getTableData(OFTableName.GLYF.getName());
         int[] composedGlyphIndices = new int[glyphOffsets.length];
 
         for (int i = 0; i < glyphOffsets.length; i++) {

Added: xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/OTFFileTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/OTFFileTestCase.java?rev=1514076&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/OTFFileTestCase.java (added)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/OTFFileTestCase.java Wed Aug 14 22:35:37 2013
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fonts.truetype;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class OTFFileTestCase {
+    protected OTFFile sourceSansProBold;
+    protected FontFileReader sourceSansReader = null;
+    protected OTFFile alexBrush;
+    protected FontFileReader alexBrushReader = null;
+
+    /**
+     * Initializes fonts used for the testing of reading OTF CFF
+     * @throws IOException
+     */
+    @Before
+    public void setUp() throws Exception {
+        sourceSansProBold = new OTFFile();
+        InputStream sourceSansStream = new FileInputStream("test/resources/fonts/otf/SourceSansProBold.otf");
+        sourceSansReader = new FontFileReader(sourceSansStream);
+        String sourceSansHeader = OFFontLoader.readHeader(sourceSansReader);
+        sourceSansProBold.readFont(sourceSansReader, sourceSansHeader);
+        sourceSansStream.close();
+
+        InputStream alexBrushStream = new FileInputStream("test/resources/fonts/otf/AlexBrushRegular.otf");
+        alexBrush = new OTFFile();
+        alexBrushReader = new FontFileReader(alexBrushStream);
+        String carolynaHeader = OFFontLoader.readHeader(alexBrushReader);
+        alexBrush.readFont(alexBrushReader, carolynaHeader);
+        alexBrushStream.close();
+    }
+
+    /**
+     * Tests the font names being read from the file
+     */
+    @Test
+    public void testFontNames() {
+        assertTrue(sourceSansProBold.getFamilyNames().contains("Source Sans Pro"));
+        assertTrue(alexBrush.getFamilyNames().contains("Alex Brush"));
+    }
+
+    /**
+     * Tests the number of glyphs and a select number of widths from each font
+     */
+    @Test
+    public void testGlyphNumberAndWidths() {
+        assertEquals(824, sourceSansProBold.numberOfGlyphs);
+        assertEquals(256, alexBrush.numberOfGlyphs);
+
+        int[] gids = {32, 42, 44, 47};
+        int[] sourceSansWidths = {516, 555, 572, 383};
+        for (int i = 0;i < gids.length;i++) {
+            assertEquals(sourceSansWidths[i], sourceSansProBold.getWidths()[gids[i]]);
+        }
+        int[] carolynaWidths = {842, 822, 658, 784};
+        for (int i = 0;i < gids.length;i++) {
+            assertEquals(carolynaWidths[i], alexBrush.getWidths()[gids[i]]);
+        }
+    }
+}

Propchange: xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/OTFFileTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java?rev=1514076&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java (added)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java Wed Aug 14 22:35:37 2013
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fonts.truetype;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.fontbox.cff.CFFDataInput;
+import org.apache.fontbox.cff.CFFFont;
+import org.apache.fontbox.cff.CFFParser;
+import org.apache.fontbox.cff.IndexData;
+import org.apache.fontbox.cff.Type2CharStringParser;
+
+import org.apache.fop.fonts.cff.CFFDataReader;
+import org.apache.fop.fonts.cff.CFFDataReader.CFFIndexData;
+import org.apache.fop.fonts.cff.CFFDataReader.DICTEntry;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class OTFSubSetFileTestCase extends OTFFileTestCase {
+
+    CFFDataReader cffReaderSourceSans;
+    private OTFSubSetFile sourceSansSubset;
+    private byte[] sourceSansData;
+    CFFDataReader cffReaderHeitiStd;
+
+    public OTFSubSetFileTestCase() throws IOException {
+        super();
+    }
+
+    /**
+     * Initialises the test by creating the font subset. A CFFDataReader is
+     * also created based on the subset data for use in the tests.
+     * @throws IOException
+     */
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+
+        Map<Integer, Integer> glyphs = new HashMap<Integer, Integer>();
+        for (int i = 0; i < 256; i++) {
+            glyphs.put(i, i);
+        }
+
+        sourceSansSubset = new OTFSubSetFile();
+        String sourceSansHeader = OFFontLoader.readHeader(sourceSansReader);
+        sourceSansSubset.readFont(sourceSansReader, "SourceSansProBold", sourceSansHeader, glyphs);
+        sourceSansData = sourceSansSubset.getFontSubset();
+        cffReaderSourceSans = new CFFDataReader(sourceSansData);
+    }
+
+    /**
+     * Validates the CharString data against the original font
+     * @throws IOException
+     */
+    @Test
+    public void testCharStringIndex() throws IOException {
+        assertEquals(256, cffReaderSourceSans.getCharStringIndex().getNumObjects());
+        assertTrue(checkCorrectOffsets(cffReaderSourceSans.getCharStringIndex()));
+        validateCharStrings(cffReaderSourceSans);
+    }
+
+    private boolean checkCorrectOffsets(CFFIndexData indexData) {
+        int last = 0;
+        for (int i = 0;i < indexData.getOffsets().length;i++) {
+            if (indexData.getOffsets()[i] < last) {
+                return false;
+            }
+            last = indexData.getOffsets()[i];
+        }
+        return true;
+    }
+
+    private void validateCharStrings(CFFDataReader cffReader) throws IOException {
+        CFFFont sourceSansOriginal = sourceSansProBold.fileFont;
+        Map<String, byte[]> origCharStringData = sourceSansOriginal.getCharStringsDict();
+        IndexData origGlobalIndex = sourceSansOriginal.getGlobalSubrIndex();
+        IndexData origLocalIndex = sourceSansOriginal.getLocalSubrIndex();
+
+        CFFDataInput globalSubrs = new CFFDataInput(cffReader.getGlobalIndexSubr().getByteData());
+        CFFDataInput localSubrs = new CFFDataInput(cffReader.getLocalIndexSubr().getByteData());
+
+        IndexData globalIndexData = CFFParser.readIndexData(globalSubrs);
+        IndexData localIndexData = CFFParser.readIndexData(localSubrs);
+
+        CFFIndexData charStrings = cffReader.getCharStringIndex();
+        for (int i = 0;i < charStrings.getNumObjects();i++) {
+            byte[] charData = charStrings.getValue(i);
+            Type2CharStringParser parser = new Type2CharStringParser();
+
+            byte[] origCharData = origCharStringData.get(origCharStringData.keySet().toArray(
+                    new String[0])[i]);
+            List<Object> origSeq = parser.parse(origCharData, origGlobalIndex, origLocalIndex);
+
+            List<Object> subsetSeq = parser.parse(charData, globalIndexData, localIndexData);
+
+            //Validates the subset glyph render routines against the originals
+            assertEquals(origSeq, subsetSeq);
+        }
+    }
+
+    /**
+     * Validates the String index data and size
+     * @throws IOException
+     */
+    @Test
+    public void testStringIndex() throws IOException {
+        assertEquals(164, cffReaderSourceSans.getStringIndex().getNumObjects());
+        assertTrue(checkCorrectOffsets(cffReaderSourceSans.getStringIndex()));
+        assertEquals("Amacron", new String(cffReaderSourceSans.getStringIndex().getValue(5)));
+        assertEquals("Edotaccent", new String(cffReaderSourceSans.getStringIndex().getValue(32)));
+        assertEquals("uni0122", new String(cffReaderSourceSans.getStringIndex().getValue(45)));
+    }
+
+    /**
+     * Validates the Top Dict data
+     * @throws IOException
+     */
+    @Test
+    public void testTopDictData() throws IOException {
+        Map<String, DICTEntry> topDictEntries = cffReaderSourceSans.parseDictData(
+                cffReaderSourceSans.getTopDictIndex().getData());
+        assertEquals(10, topDictEntries.size());
+    }
+}

Propchange: xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/OTFSubSetFileTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFFileTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFFileTestCase.java?rev=1514076&r1=1514075&r2=1514076&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFFileTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFFileTestCase.java Wed Aug 14 22:35:37 2013
@@ -26,7 +26,7 @@ import java.util.Map;
 
 import org.junit.Test;
 
-import org.apache.fop.fonts.truetype.TTFFile.PostScriptVersion;
+import org.apache.fop.fonts.truetype.OpenFont.PostScriptVersion;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
@@ -55,14 +55,16 @@ public class TTFFileTestCase {
         dejavuTTFFile = new TTFFile();
         InputStream dejaStream = new FileInputStream("test/resources/fonts/ttf/DejaVuLGCSerif.ttf");
         dejavuReader = new FontFileReader(dejaStream);
-        dejavuTTFFile.readFont(dejavuReader);
+        String dejavuHeader = OFFontLoader.readHeader(dejavuReader);
+        dejavuTTFFile.readFont(dejavuReader, dejavuHeader);
         dejaStream.close();
 
         InputStream droidStream = new FileInputStream("test/resources/fonts/ttf/DroidSansMono.ttf");
 
         droidmonoTTFFile = new TTFFile();
         droidmonoReader = new FontFileReader(droidStream);
-        droidmonoTTFFile.readFont(droidmonoReader);
+        String droidmonoHeader = OFFontLoader.readHeader(droidmonoReader);
+        droidmonoTTFFile.readFont(droidmonoReader, droidmonoHeader);
         droidStream.close();
     }
 
@@ -93,8 +95,10 @@ public class TTFFileTestCase {
     @Test
     public void testCheckTTC() throws IOException {
         // DejaVu is not a TTC, thus this returns true
-        assertTrue(dejavuTTFFile.checkTTC(""));
-        assertTrue(droidmonoTTFFile.checkTTC(""));
+        String dejavuHeader = OFFontLoader.readHeader(dejavuReader);
+        assertTrue(dejavuTTFFile.checkTTC(dejavuHeader, ""));
+        String droidmonoHeader = OFFontLoader.readHeader(droidmonoReader);
+        assertTrue(droidmonoTTFFile.checkTTC(droidmonoHeader, ""));
         /*
          * Cannot reasonably test the rest of this method without an actual truetype collection
          * because all methods in FontFileReader are "final" and thus mocking isn't possible.

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java?rev=1514076&r1=1514075&r2=1514076&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java Wed Aug 14 22:35:37 2013
@@ -34,7 +34,7 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertTrue;
 
 /**
- * Test case for {@link TTFFontLoader}.
+ * Test case for {@link OFFontLoader}.
  */
 public class TTFFontLoaderTestCase {
 
@@ -49,12 +49,12 @@ public class TTFFontLoaderTestCase {
         boolean embedded = false;
         boolean useKerning = true;
 
-        TTFFontLoader fontLoader = new TTFFontLoader(absoluteFilePath, fontName, embedded,
+        OFFontLoader fontLoader = new OFFontLoader(absoluteFilePath, fontName, embedded,
                 EmbeddingMode.AUTO, EncodingMode.AUTO, useKerning, useComplexScriptFeatures, resourceResolver);
         assertTrue(fontLoader.getFont().hasKerningInfo());
         useKerning = false;
 
-        fontLoader = new TTFFontLoader(absoluteFilePath, fontName, embedded, EmbeddingMode.AUTO,
+        fontLoader = new OFFontLoader(absoluteFilePath, fontName, embedded, EmbeddingMode.AUTO,
                 EncodingMode.AUTO, useKerning, useComplexScriptFeatures, resourceResolver);
         assertFalse(fontLoader.getFont().hasKerningInfo());
     }

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFSubSetFileTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFSubSetFileTestCase.java?rev=1514076&r1=1514075&r2=1514076&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFSubSetFileTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFSubSetFileTestCase.java Wed Aug 14 22:35:37 2013
@@ -55,7 +55,8 @@ public class TTFSubSetFileTestCase exten
         for (int i = 0; i < 255; i++) {
             glyphs.put(i, i);
         }
-        ttfSubset.readFont(dejavuReader, "DejaVu", glyphs);
+        String header = OFFontLoader.readHeader(dejavuReader);
+        ttfSubset.readFont(dejavuReader, "DejaVu", header, glyphs);
         subset = ttfSubset.getFontSubset();
     }
     /**
@@ -68,7 +69,9 @@ public class TTFSubSetFileTestCase exten
     public void testReadFont3Args() throws IOException {
 
         ByteArrayInputStream byteArray = new ByteArrayInputStream(subset);
-        dejavuTTFFile.readFont(new FontFileReader(byteArray));
+        FontFileReader reader = new FontFileReader(byteArray);
+        String header = OFFontLoader.readHeader(reader);
+        dejavuTTFFile.readFont(reader, header);
         // Test a couple arbitrary values
         assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(-1576), dejavuTTFFile.getFontBBox()[0]);
         assertEquals(dejavuTTFFile.getFullName(), "DejaVu LGC Serif");

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFTableNameTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFTableNameTestCase.java?rev=1514076&r1=1514075&r2=1514076&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFTableNameTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/fonts/truetype/TTFTableNameTestCase.java Wed Aug 14 22:35:37 2013
@@ -37,37 +37,37 @@ public class TTFTableNameTestCase {
      */
     @Test
     public void testGetName() throws IllegalAccessException {
-        assertEquals("tableDirectory", TTFTableName.TABLE_DIRECTORY.getName());
-        assertEquals("EBDT", TTFTableName.EBDT.getName());
-        assertEquals("EBLC", TTFTableName.EBLC.getName());
-        assertEquals("EBSC", TTFTableName.EBSC.getName());
-        assertEquals("FFTM", TTFTableName.FFTM.getName());
-        assertEquals("GDEF", TTFTableName.GDEF.getName());
-        assertEquals("GPOS", TTFTableName.GPOS.getName());
-        assertEquals("GSUB", TTFTableName.GSUB.getName());
-        assertEquals("LTSH", TTFTableName.LTSH.getName());
-        assertEquals("OS/2", TTFTableName.OS2.getName());
-        assertEquals("PCLT", TTFTableName.PCLT.getName());
-        assertEquals("VDMX", TTFTableName.VDMX.getName());
-        assertEquals("cmap", TTFTableName.CMAP.getName());
-        assertEquals("cvt ", TTFTableName.CVT.getName());
-        assertEquals("fpgm", TTFTableName.FPGM.getName());
-        assertEquals("gasp", TTFTableName.GASP.getName());
-        assertEquals("glyf", TTFTableName.GLYF.getName());
-        assertEquals("hdmx", TTFTableName.HDMX.getName());
-        assertEquals("head", TTFTableName.HEAD.getName());
-        assertEquals("hhea", TTFTableName.HHEA.getName());
-        assertEquals("hmtx", TTFTableName.HMTX.getName());
-        assertEquals("kern", TTFTableName.KERN.getName());
-        assertEquals("loca", TTFTableName.LOCA.getName());
-        assertEquals("maxp", TTFTableName.MAXP.getName());
-        assertEquals("name", TTFTableName.NAME.getName());
-        assertEquals("post", TTFTableName.POST.getName());
-        assertEquals("prep", TTFTableName.PREP.getName());
-        assertEquals("vhea", TTFTableName.VHEA.getName());
-        assertEquals("vmtx", TTFTableName.VMTX.getName());
+        assertEquals("tableDirectory", OFTableName.TABLE_DIRECTORY.getName());
+        assertEquals("EBDT", OFTableName.EBDT.getName());
+        assertEquals("EBLC", OFTableName.EBLC.getName());
+        assertEquals("EBSC", OFTableName.EBSC.getName());
+        assertEquals("FFTM", OFTableName.FFTM.getName());
+        assertEquals("GDEF", OFTableName.GDEF.getName());
+        assertEquals("GPOS", OFTableName.GPOS.getName());
+        assertEquals("GSUB", OFTableName.GSUB.getName());
+        assertEquals("LTSH", OFTableName.LTSH.getName());
+        assertEquals("OS/2", OFTableName.OS2.getName());
+        assertEquals("PCLT", OFTableName.PCLT.getName());
+        assertEquals("VDMX", OFTableName.VDMX.getName());
+        assertEquals("cmap", OFTableName.CMAP.getName());
+        assertEquals("cvt ", OFTableName.CVT.getName());
+        assertEquals("fpgm", OFTableName.FPGM.getName());
+        assertEquals("gasp", OFTableName.GASP.getName());
+        assertEquals("glyf", OFTableName.GLYF.getName());
+        assertEquals("hdmx", OFTableName.HDMX.getName());
+        assertEquals("head", OFTableName.HEAD.getName());
+        assertEquals("hhea", OFTableName.HHEA.getName());
+        assertEquals("hmtx", OFTableName.HMTX.getName());
+        assertEquals("kern", OFTableName.KERN.getName());
+        assertEquals("loca", OFTableName.LOCA.getName());
+        assertEquals("maxp", OFTableName.MAXP.getName());
+        assertEquals("name", OFTableName.NAME.getName());
+        assertEquals("post", OFTableName.POST.getName());
+        assertEquals("prep", OFTableName.PREP.getName());
+        assertEquals("vhea", OFTableName.VHEA.getName());
+        assertEquals("vmtx", OFTableName.VMTX.getName());
         // make sure it works with other table names
-        TTFTableName test = TTFTableName.getValue("test");
+        OFTableName test = OFTableName.getValue("test");
         assertEquals("test", test.getName());
     }
 
@@ -78,34 +78,34 @@ public class TTFTableNameTestCase {
      */
     @Test
     public void testGetValue() throws IllegalAccessException {
-        assertEquals(TTFTableName.EBDT, TTFTableName.getValue("EBDT"));
-        assertEquals(TTFTableName.EBLC, TTFTableName.getValue("EBLC"));
-        assertEquals(TTFTableName.EBSC, TTFTableName.getValue("EBSC"));
-        assertEquals(TTFTableName.FFTM, TTFTableName.getValue("FFTM"));
-        assertEquals(TTFTableName.LTSH, TTFTableName.getValue("LTSH"));
-        assertEquals(TTFTableName.OS2, TTFTableName.getValue("OS/2"));
-        assertEquals(TTFTableName.PCLT, TTFTableName.getValue("PCLT"));
-        assertEquals(TTFTableName.VDMX, TTFTableName.getValue("VDMX"));
-        assertEquals(TTFTableName.CMAP, TTFTableName.getValue("cmap"));
-        assertEquals(TTFTableName.CVT, TTFTableName.getValue("cvt "));
-        assertEquals(TTFTableName.FPGM, TTFTableName.getValue("fpgm"));
-        assertEquals(TTFTableName.GASP, TTFTableName.getValue("gasp"));
-        assertEquals(TTFTableName.GLYF, TTFTableName.getValue("glyf"));
-        assertEquals(TTFTableName.HDMX, TTFTableName.getValue("hdmx"));
-        assertEquals(TTFTableName.HEAD, TTFTableName.getValue("head"));
-        assertEquals(TTFTableName.HHEA, TTFTableName.getValue("hhea"));
-        assertEquals(TTFTableName.HMTX, TTFTableName.getValue("hmtx"));
-        assertEquals(TTFTableName.KERN, TTFTableName.getValue("kern"));
-        assertEquals(TTFTableName.LOCA, TTFTableName.getValue("loca"));
-        assertEquals(TTFTableName.MAXP, TTFTableName.getValue("maxp"));
-        assertEquals(TTFTableName.NAME, TTFTableName.getValue("name"));
-        assertEquals(TTFTableName.POST, TTFTableName.getValue("post"));
-        assertEquals(TTFTableName.PREP, TTFTableName.getValue("prep"));
-        assertEquals(TTFTableName.VHEA, TTFTableName.getValue("vhea"));
-        assertEquals(TTFTableName.VMTX, TTFTableName.getValue("vmtx"));
+        assertEquals(OFTableName.EBDT, OFTableName.getValue("EBDT"));
+        assertEquals(OFTableName.EBLC, OFTableName.getValue("EBLC"));
+        assertEquals(OFTableName.EBSC, OFTableName.getValue("EBSC"));
+        assertEquals(OFTableName.FFTM, OFTableName.getValue("FFTM"));
+        assertEquals(OFTableName.LTSH, OFTableName.getValue("LTSH"));
+        assertEquals(OFTableName.OS2, OFTableName.getValue("OS/2"));
+        assertEquals(OFTableName.PCLT, OFTableName.getValue("PCLT"));
+        assertEquals(OFTableName.VDMX, OFTableName.getValue("VDMX"));
+        assertEquals(OFTableName.CMAP, OFTableName.getValue("cmap"));
+        assertEquals(OFTableName.CVT, OFTableName.getValue("cvt "));
+        assertEquals(OFTableName.FPGM, OFTableName.getValue("fpgm"));
+        assertEquals(OFTableName.GASP, OFTableName.getValue("gasp"));
+        assertEquals(OFTableName.GLYF, OFTableName.getValue("glyf"));
+        assertEquals(OFTableName.HDMX, OFTableName.getValue("hdmx"));
+        assertEquals(OFTableName.HEAD, OFTableName.getValue("head"));
+        assertEquals(OFTableName.HHEA, OFTableName.getValue("hhea"));
+        assertEquals(OFTableName.HMTX, OFTableName.getValue("hmtx"));
+        assertEquals(OFTableName.KERN, OFTableName.getValue("kern"));
+        assertEquals(OFTableName.LOCA, OFTableName.getValue("loca"));
+        assertEquals(OFTableName.MAXP, OFTableName.getValue("maxp"));
+        assertEquals(OFTableName.NAME, OFTableName.getValue("name"));
+        assertEquals(OFTableName.POST, OFTableName.getValue("post"));
+        assertEquals(OFTableName.PREP, OFTableName.getValue("prep"));
+        assertEquals(OFTableName.VHEA, OFTableName.getValue("vhea"));
+        assertEquals(OFTableName.VMTX, OFTableName.getValue("vmtx"));
         // Test that we can store a random table name and it will not fail or throw an error.
-        TTFTableName test = TTFTableName.getValue("random");
-        assertTrue(test instanceof TTFTableName);
+        OFTableName test = OFTableName.getValue("random");
+        assertTrue(test instanceof OFTableName);
     }
 
     /**
@@ -115,10 +115,10 @@ public class TTFTableNameTestCase {
      */
     @Test
     public void testHashCode() throws IllegalAccessException {
-        TTFTableName a = TTFTableName.getValue("testObject");
-        TTFTableName b = TTFTableName.getValue("testObject");
+        OFTableName a = OFTableName.getValue("testObject");
+        OFTableName b = OFTableName.getValue("testObject");
         assertTrue(a.hashCode() == b.hashCode());
-        TTFTableName c = TTFTableName.getValue("fail");
+        OFTableName c = OFTableName.getValue("fail");
         assertFalse(a.hashCode() == c.hashCode());
     }
 
@@ -134,15 +134,15 @@ public class TTFTableNameTestCase {
     @Test
     public void testEquals() throws IllegalAccessException {
         // Reflexivity
-        TTFTableName a = TTFTableName.getValue("test");
+        OFTableName a = OFTableName.getValue("test");
         assertTrue(a.equals(a));
         // Symmetry
-        TTFTableName b = TTFTableName.getValue("test");
+        OFTableName b = OFTableName.getValue("test");
         assertTrue(a.equals(b));
         assertTrue(b.equals(a));
         // Transitivity (tested with symmetry)
         // Consistency (test that a == b is true and that a == c fails)
-        TTFTableName c = TTFTableName.getValue("fail");
+        OFTableName c = OFTableName.getValue("fail");
         for (int i = 0; i < 100; i++) {
             assertTrue(a.equals(b));
             assertFalse(a.equals(c));

Added: xmlgraphics/fop/trunk/test/resources/fonts/otf/AlexBrushRegular.otf
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/resources/fonts/otf/AlexBrushRegular.otf?rev=1514076&view=auto
==============================================================================
Binary file - no diff available.

Propchange: xmlgraphics/fop/trunk/test/resources/fonts/otf/AlexBrushRegular.otf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: xmlgraphics/fop/trunk/test/resources/fonts/otf/SourceSansProBold.otf
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/resources/fonts/otf/SourceSansProBold.otf?rev=1514076&view=auto
==============================================================================
Binary file - no diff available.

Propchange: xmlgraphics/fop/trunk/test/resources/fonts/otf/SourceSansProBold.otf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



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