You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2014/05/27 21:00:16 UTC

svn commit: r1597849 - in /pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox: ttf/ util/ util/autodetect/

Author: lehmi
Date: Tue May 27 19:00:15 2014
New Revision: 1597849

URL: http://svn.apache.org/r1597849
Log:
PDFBOX-1689: added font manager to handle local fonts

Added:
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/FontManager.java
      - copied, changed from r1595992, pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/util/FontManager.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/
      - copied from r1595992, pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/util/autodetect/
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/package.html
      - copied unchanged from r1597842, pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/util/autodetect/package.html
Modified:
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/AbstractTTFParser.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/CMAPEncodingEntry.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/CMAPTable.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphData.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/HeaderTable.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/HorizontalHeaderTable.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/HorizontalMetricsTable.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/IndexToLocationTable.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/MaximumProfileTable.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/NamingTable.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/OS2WindowsMetricsTable.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/TTFTable.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/FontFileFinder.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/MacFontDirFinder.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/UnixFontDirFinder.java
    pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/WindowsFontDirFinder.java

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/AbstractTTFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/AbstractTTFParser.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/AbstractTTFParser.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/AbstractTTFParser.java Tue May 27 19:00:15 2014
@@ -19,18 +19,36 @@ package org.apache.fontbox.ttf;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.List;
 
 abstract class AbstractTTFParser {
 	
     protected boolean isEmbedded = false;
+    protected boolean parseOnDemandOnly = false;
+
+    /**
+     * Constructor.
+     * 
+     * @param fontIsEmbedded indicates whether the font is embedded or not.
+     * 
+     */
+    public AbstractTTFParser(boolean fontIsEmbedded)
+    {
+        this(fontIsEmbedded, false);
+    }
+
+    /**
+     * Constructor.
+     * 
+     * @param fontIsEmbedded indicates whether the font is embedded or not.
+     * @param parseOnDemand indicates whether the tables of the font should be parsed on demand only or not.
+     */
+    public AbstractTTFParser(boolean fontIsEmbedded, boolean parseOnDemand)
+    {
+        isEmbedded = fontIsEmbedded;
+        parseOnDemandOnly = parseOnDemand;
+    }
 
-	public AbstractTTFParser(boolean isEmbedded) {
-		this.isEmbedded = isEmbedded;
-	}
-	
     /**
      * Parse a file and get a true type font.
      * @param ttfFile The TTF file.
@@ -85,10 +103,11 @@ abstract class AbstractTTFParser {
             TTFTable table = readTableDirectory( raf );   
             font.addTable( table );
         }
-
-        //need to initialize a couple tables in a certain order
-        parseTables(font, raf);
-
+        // parse tables if wanted
+        if (!parseOnDemandOnly)
+        {
+            parseTables(font, raf);
+        }
         return font;
     }
 
@@ -100,82 +119,42 @@ abstract class AbstractTTFParser {
      */
     protected void parseTables(TrueTypeFont font, TTFDataStream raf)
     throws IOException {
-        List<TTFTable> initialized = new ArrayList<TTFTable>();
+        Iterator<TTFTable> iter = font.getTables().iterator();
+        while (iter.hasNext())
+        {
+            TTFTable table = iter.next();
+            if (!table.getInitialized())
+            {
+                font.initializeTable(table);
+            }
+        }
+
         HeaderTable head = font.getHeader();
         if (head == null) 
         {
             throw new IOException("head is mandatory");
         }
-        raf.seek( head.getOffset() );
-        head.initData( font, raf );
-        initialized.add( head );
-
         HorizontalHeaderTable hh = font.getHorizontalHeader();
         if (hh == null) 
         {
             throw new IOException("hhead is mandatory");
         }
-        raf.seek( hh.getOffset() );
-        hh.initData( font, raf );
-        initialized.add( hh );
-
         MaximumProfileTable maxp = font.getMaximumProfile();
-        if (maxp != null) 
-        {
-            raf.seek( maxp.getOffset() );
-            maxp.initData( font, raf );
-            initialized.add( maxp );
-        } 
-        else 
+        if (maxp == null)
         {
             throw new IOException("maxp is mandatory");
         }
-
         PostScriptTable post = font.getPostScript();
-        if (post != null) {
-            raf.seek( post.getOffset() );
-            post.initData( font, raf );
-            initialized.add( post );
-        } 
-        else if ( !isEmbedded ) 
+        if (post == null && !isEmbedded)
         {
             // in an embedded font this table is optional
             throw new IOException("post is mandatory");
         }
-
         IndexToLocationTable loc = font.getIndexToLocation();
         if (loc == null) 
         {
             throw new IOException("loca is mandatory");
         }
-        raf.seek( loc.getOffset() );
-        loc.initData( font, raf );
-        initialized.add( loc );
-
-        boolean cvt = false, prep = false, fpgm = false;
-        Iterator<TTFTable> iter = font.getTables().iterator();
-        while( iter.hasNext() )
-        {
-            TTFTable table = iter.next();
-            if( !initialized.contains( table ) )
-            {
-                raf.seek( table.getOffset() );
-                table.initData( font, raf );
-            }
-            if (table.getTag().startsWith("cvt")) 
-            {
-                cvt = true;
-            } 
-            else if ("prep".equals(table.getTag())) 
-            {
-                prep = true;
-            } 
-            else if ("fpgm".equals(table.getTag())) 
-            {
-                fpgm = true;
-            }
-        }   
-
         // check others mandatory tables
         if ( font.getGlyph() == null )
         {
@@ -189,23 +168,6 @@ abstract class AbstractTTFParser {
         {
             throw new IOException("hmtx is mandatory");
         }
-
-        if (isEmbedded) {
-            // in a embedded truetype font prep, cvt_ and fpgm tables 
-            // are mandatory
-            if (!fpgm) 
-            {
-                throw new IOException("fpgm is mandatory");
-            }
-            if (!prep)
-            {
-                throw new IOException("prep is mandatory");
-            }
-            if (!cvt) 
-            {
-                throw new IOException("cvt_ is mandatory");
-            }
-        }
     }
 
     private TTFTable readTableDirectory( TTFDataStream raf ) throws IOException

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/CMAPEncodingEntry.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/CMAPEncodingEntry.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/CMAPEncodingEntry.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/CMAPEncodingEntry.java Tue May 27 19:00:15 2014
@@ -37,91 +37,92 @@ public class CMAPEncodingEntry
 	private int[] glyphIdToCharacterCode;
 	private Map<Integer, Integer> characterCodeToGlyphId = new HashMap<Integer, Integer>();
 
-	/**
-	 * This will read the required data from the stream.
-	 * 
-	 * @param ttf The font that is being read.
-	 * @param data The stream to read the data from.
-	 * @throws IOException If there is an error reading the data.
-	 */
-	public void initData( TrueTypeFont ttf, TTFDataStream data ) throws IOException
-	{
-		platformId = data.readUnsignedShort();
-		platformEncodingId = data.readUnsignedShort();
-		subTableOffset = data.readUnsignedInt();
-	}
+    /**
+     * This will read the required data from the stream.
+     * 
+     * @param data The stream to read the data from.
+     * @throws IOException If there is an error reading the data.
+     */
+    public void initData(TTFDataStream data) throws IOException
+    {
+        platformId = data.readUnsignedShort();
+        platformEncodingId = data.readUnsignedShort();
+        subTableOffset = data.readUnsignedInt();
+    }
+
+    /**
+     * This will read the required data from the stream.
+     * 
+     * @param cmap the CMAP this encoding belongs to.
+     * @param numGlyphs number of glyphs.
+     * @param data The stream to read the data from.
+     * @throws IOException If there is an error reading the data.
+     */
+    public void initSubtable(CMAPTable cmap, int numGlyphs, TTFDataStream data) throws IOException
+    {
+        data.seek(cmap.getOffset() + subTableOffset);
+        int subtableFormat = data.readUnsignedShort();
+        long length;
+        long version;
+        if (subtableFormat < 8)
+        {
+            length = data.readUnsignedShort();
+            version = data.readUnsignedShort();
+        }
+        else
+        {
+            // read an other UnsignedShort to read a Fixed32
+            data.readUnsignedShort();
+            length = data.readUnsignedInt();
+            version = data.readUnsignedInt();
+        }
 
-	/**
-	 * This will read the required data from the stream.
-	 * 
-	 * @param ttf The font that is being read.
-	 * @param data The stream to read the data from.
-	 * @throws IOException If there is an error reading the data.
-	 */
-	public void initSubtable( TrueTypeFont ttf, TTFDataStream data ) throws IOException
-	{
-		data.seek( ttf.getCMAP().getOffset() + subTableOffset );
-		int subtableFormat = data.readUnsignedShort();
-		long length;
-		long version;
-		int numGlyphs;
-		if (subtableFormat < 8) {
-			length = data.readUnsignedShort();
-			version = data.readUnsignedShort();
-			numGlyphs = ttf.getMaximumProfile().getNumGlyphs();
-		} else {
-			// read an other UnsignedShort to read a Fixed32
-			data.readUnsignedShort();
-			length = data.readUnsignedInt();
-			version = data.readUnsignedInt();
-			numGlyphs = ttf.getMaximumProfile().getNumGlyphs();         
-		}
-
-		switch (subtableFormat) {
-		case 0:
-			processSubtype0(ttf, data);
-			break;
-		case 2:
-			processSubtype2(ttf, data, numGlyphs);
-			break;
-		case 4:
-			processSubtype4(ttf, data, numGlyphs);
-			break;
-		case 6:
-			processSubtype6(ttf, data, numGlyphs);
-			break;
-		case 8:
-			processSubtype8(ttf, data, numGlyphs);
-			break;
-		case 10:
-			processSubtype10(ttf, data, numGlyphs);
-			break;
-		case 12:
-			processSubtype12(ttf, data, numGlyphs);
-			break;
-		case 13:
-			processSubtype13(ttf, data, numGlyphs); 
-			break;
-		case 14:
-			processSubtype14(ttf, data, numGlyphs);
-			break;
-		default:
-			throw new IOException( "Unknown cmap format:" + subtableFormat );   
-		}
-	}
+        switch (subtableFormat)
+        {
+        case 0:
+            processSubtype0(data);
+            break;
+        case 2:
+            processSubtype2(data, numGlyphs);
+            break;
+        case 4:
+            processSubtype4(data, numGlyphs);
+            break;
+        case 6:
+            processSubtype6(data, numGlyphs);
+            break;
+        case 8:
+            processSubtype8(data, numGlyphs);
+            break;
+        case 10:
+            processSubtype10(data, numGlyphs);
+            break;
+        case 12:
+            processSubtype12(data, numGlyphs);
+            break;
+        case 13:
+            processSubtype13(data, numGlyphs);
+            break;
+        case 14:
+            processSubtype14(data, numGlyphs);
+            break;
+        default:
+            throw new IOException("Unknown cmap format:" + subtableFormat);
+        }
+    }
 
-	/**
-	 * Reads a format 8 subtable.
-	 * @param ttf the TrueTypeFont instance holding the parsed data.
-	 * @param data the data stream of the to be parsed ttf font
-	 * @param numGlyphs number of glyphs to be read
-	 * @throws IOException If there is an error parsing the true type font.
-	 */
-	protected void processSubtype8( TrueTypeFont ttf, TTFDataStream data, int numGlyphs ) 
-			throws IOException {
-		// --- is32 is a 65536 BITS array ( = 8192 BYTES) 
-		int[] is32 = data.readUnsignedByteArray(8192);
-		long nbGroups = data.readUnsignedInt();
+    /**
+     * Reads a format 8 subtable.
+     * 
+     * @param data the data stream of the to be parsed ttf font
+     * @param numGlyphs number of glyphs to be read
+     * @throws IOException If there is an error parsing the true type font.
+     */
+    protected void processSubtype8(TTFDataStream data, int numGlyphs) throws IOException
+    {
+        // --- is32 is a 65536 BITS array ( = 8192 BYTES)
+        int[] is32 = data.readUnsignedByteArray(8192);
+        long nbGroups = data.readUnsignedInt();
 
 		// --- nbGroups shouldn't be greater than 65536
 		if (nbGroups > 65536) {
@@ -176,20 +177,21 @@ public class CMAPEncodingEntry
 		}
 	}
 
-	/**
-	 * Reads a format 10 subtable.
-	 * @param ttf the TrueTypeFont instance holding the parsed data.
-	 * @param data the data stream of the to be parsed ttf font
-	 * @param numGlyphs number of glyphs to be read
-	 * @throws IOException If there is an error parsing the true type font.
-	 */
-	protected void processSubtype10( TrueTypeFont ttf, TTFDataStream data, int numGlyphs ) 
-			throws IOException {
-		long startCode = data.readUnsignedInt();
-		long numChars = data.readUnsignedInt();
-		if (numChars > Integer.MAX_VALUE) {
-			throw new IOException("Invalid number of Characters");
-		}
+    /**
+     * Reads a format 10 subtable.
+     * 
+     * @param data the data stream of the to be parsed ttf font
+     * @param numGlyphs number of glyphs to be read
+     * @throws IOException If there is an error parsing the true type font.
+     */
+    protected void processSubtype10(TTFDataStream data, int numGlyphs) throws IOException
+    {
+        long startCode = data.readUnsignedInt();
+        long numChars = data.readUnsignedInt();
+        if (numChars > Integer.MAX_VALUE)
+        {
+            throw new IOException("Invalid number of Characters");
+        }
 
 		if ( startCode < 0 || startCode > 0x0010FFFF 
 				|| (startCode + numChars) > 0x0010FFFF
@@ -199,22 +201,22 @@ public class CMAPEncodingEntry
 		}   
 	}   
 
-	/**
-	 * Reads a format 12 subtable.
-	 * @param ttf the TrueTypeFont instance holding the parsed data.
-	 * @param data the data stream of the to be parsed ttf font
-	 * @param numGlyphs number of glyphs to be read
-	 * @throws IOException If there is an error parsing the true type font.
-	 */
-	protected void processSubtype12( TrueTypeFont ttf, TTFDataStream data, int numGlyphs ) 
-			throws IOException {
-		long nbGroups = data.readUnsignedInt();
-		glyphIdToCharacterCode = new int[numGlyphs];
-		for (long i = 0; i < nbGroups ; ++i ) 
-		{
-			long firstCode = data.readUnsignedInt();
-			long endCode = data.readUnsignedInt();
-			long startGlyph = data.readUnsignedInt();
+    /**
+     * Reads a format 12 subtable.
+     * 
+     * @param data the data stream of the to be parsed ttf font
+     * @param numGlyphs number of glyphs to be read
+     * @throws IOException If there is an error parsing the true type font.
+     */
+    protected void processSubtype12(TTFDataStream data, int numGlyphs) throws IOException
+    {
+        long nbGroups = data.readUnsignedInt();
+        glyphIdToCharacterCode = new int[numGlyphs];
+        for (long i = 0; i < nbGroups; ++i)
+        {
+            long firstCode = data.readUnsignedInt();
+            long endCode = data.readUnsignedInt();
+            long startGlyph = data.readUnsignedInt();
 
 			if ( firstCode < 0 || firstCode > 0x0010FFFF 
 					|| ( firstCode >= 0x0000D800 && firstCode <= 0x0000DFFF ) ) {
@@ -242,21 +244,21 @@ public class CMAPEncodingEntry
 		}
 	}
 
-	/**
-	 * Reads a format 13 subtable.
-	 * @param ttf the TrueTypeFont instance holding the parsed data.
-	 * @param data the data stream of the to be parsed ttf font
-	 * @param numGlyphs number of glyphs to be read
-	 * @throws IOException If there is an error parsing the true type font.
-	 */
-	protected void processSubtype13( TrueTypeFont ttf, TTFDataStream data, int numGlyphs ) 
-			throws IOException {
-		long nbGroups = data.readUnsignedInt();
-		for (long i = 0; i < nbGroups ; ++i ) 
-		{
-			long firstCode = data.readUnsignedInt();
-			long endCode = data.readUnsignedInt();
-			long glyphId = data.readUnsignedInt();
+    /**
+     * Reads a format 13 subtable.
+     * 
+     * @param data the data stream of the to be parsed ttf font
+     * @param numGlyphs number of glyphs to be read
+     * @throws IOException If there is an error parsing the true type font.
+     */
+    protected void processSubtype13(TTFDataStream data, int numGlyphs) throws IOException
+    {
+        long nbGroups = data.readUnsignedInt();
+        for (long i = 0; i < nbGroups; ++i)
+        {
+            long firstCode = data.readUnsignedInt();
+            long endCode = data.readUnsignedInt();
+            long glyphId = data.readUnsignedInt();
 
 			if (glyphId > numGlyphs) {
 				throw new IOException("CMap contains an invalid glyph index");  
@@ -283,57 +285,57 @@ public class CMAPEncodingEntry
 		}
 	}
 
-	/**
-	 * Reads a format 14 subtable.
-	 * @param ttf the TrueTypeFont instance holding the parsed data.
-	 * @param data the data stream of the to be parsed ttf font
-	 * @param numGlyphs number of glyphs to be read
-	 * @throws IOException If there is an error parsing the true type font.
-	 */
-	protected void processSubtype14( TrueTypeFont ttf, TTFDataStream data, int numGlyphs ) 
-			throws IOException {
-		throw new IOException("CMap subtype 14 not yet implemented");
-	}
-
-	/**
-	 * Reads a format 6 subtable.
-	 * @param ttf the TrueTypeFont instance holding the parsed data.
-	 * @param data the data stream of the to be parsed ttf font
-	 * @param numGlyphs number of glyphs to be read
-	 * @throws IOException If there is an error parsing the true type font.
-	 */
-	protected void processSubtype6( TrueTypeFont ttf, TTFDataStream data, int numGlyphs ) 
-			throws IOException {
-		int firstCode = data.readUnsignedShort();
-		int entryCount = data.readUnsignedShort();
-		glyphIdToCharacterCode = new int[numGlyphs];
-		int[] glyphIdArray = data.readUnsignedShortArray( entryCount );
-		for( int i=0; i<entryCount; i++)
-		{
-			glyphIdToCharacterCode[glyphIdArray[i]] = firstCode+i;
-			characterCodeToGlyphId.put((firstCode+i), glyphIdArray[i]);
-		}
-	}
+    /**
+     * Reads a format 14 subtable.
+     * 
+     * @param data the data stream of the to be parsed ttf font
+     * @param numGlyphs number of glyphs to be read
+     * @throws IOException If there is an error parsing the true type font.
+     */
+    protected void processSubtype14(TTFDataStream data, int numGlyphs) throws IOException
+    {
+        throw new IOException("CMap subtype 14 not yet implemented");
+    }
+
+    /**
+     * Reads a format 6 subtable.
+     * 
+     * @param data the data stream of the to be parsed ttf font
+     * @param numGlyphs number of glyphs to be read
+     * @throws IOException If there is an error parsing the true type font.
+     */
+    protected void processSubtype6(TTFDataStream data, int numGlyphs) throws IOException
+    {
+        int firstCode = data.readUnsignedShort();
+        int entryCount = data.readUnsignedShort();
+        glyphIdToCharacterCode = new int[numGlyphs];
+        int[] glyphIdArray = data.readUnsignedShortArray(entryCount);
+        for (int i = 0; i < entryCount; i++)
+        {
+            glyphIdToCharacterCode[glyphIdArray[i]] = firstCode + i;
+            characterCodeToGlyphId.put((firstCode + i), glyphIdArray[i]);
+        }
+    }
 
-	/**
-	 * Reads a format 4 subtable.
-	 * @param ttf the TrueTypeFont instance holding the parsed data.
-	 * @param data the data stream of the to be parsed ttf font
-	 * @param numGlyphs number of glyphs to be read
-	 * @throws IOException If there is an error parsing the true type font.
-	 */
-	protected void processSubtype4( TrueTypeFont ttf, TTFDataStream data, int numGlyphs ) 
-			throws IOException {
-		int segCountX2 = data.readUnsignedShort();
-		int segCount = segCountX2/2;
-		int searchRange = data.readUnsignedShort();
-		int entrySelector = data.readUnsignedShort();
-		int rangeShift = data.readUnsignedShort();
-		int[] endCount = data.readUnsignedShortArray( segCount );
-		int reservedPad = data.readUnsignedShort();
-		int[] startCount = data.readUnsignedShortArray( segCount );
-		int[] idDelta = data.readUnsignedShortArray( segCount );
-		int[] idRangeOffset = data.readUnsignedShortArray( segCount );
+    /**
+     * Reads a format 4 subtable.
+     * 
+     * @param data the data stream of the to be parsed ttf font
+     * @param numGlyphs number of glyphs to be read
+     * @throws IOException If there is an error parsing the true type font.
+     */
+    protected void processSubtype4(TTFDataStream data, int numGlyphs) throws IOException
+    {
+        int segCountX2 = data.readUnsignedShort();
+        int segCount = segCountX2 / 2;
+        int searchRange = data.readUnsignedShort();
+        int entrySelector = data.readUnsignedShort();
+        int rangeShift = data.readUnsignedShort();
+        int[] endCount = data.readUnsignedShortArray(segCount);
+        int reservedPad = data.readUnsignedShort();
+        int[] startCount = data.readUnsignedShortArray(segCount);
+        int[] idDelta = data.readUnsignedShortArray(segCount);
+        int[] idRangeOffset = data.readUnsignedShortArray(segCount);
 
 		Map<Integer, Integer> tmpGlyphToChar = new HashMap<Integer, Integer>();
 
@@ -390,23 +392,23 @@ public class CMAPEncodingEntry
 		}
 	}
 
-	/**
-	 * Read a format 2 subtable.
-	 * @param ttf the TrueTypeFont instance holding the parsed data.
-	 * @param data the data stream of the to be parsed ttf font
-	 * @param numGlyphs number of glyphs to be read
-	 * @throws IOException If there is an error parsing the true type font.
-	 */
-	protected void processSubtype2( TrueTypeFont ttf, TTFDataStream data, int numGlyphs ) 
-			throws IOException {
-		int[] subHeaderKeys = new int[256];
-		// ---- keep the Max Index of the SubHeader array to know its length
-		int maxSubHeaderIndex = 0;
-		for( int i=0; i<256; i++)
-		{
-			subHeaderKeys[i] = data.readUnsignedShort();
-			maxSubHeaderIndex = Math.max(maxSubHeaderIndex, subHeaderKeys[i]/8);
-		}
+    /**
+     * Read a format 2 subtable.
+     * 
+     * @param data the data stream of the to be parsed ttf font
+     * @param numGlyphs number of glyphs to be read
+     * @throws IOException If there is an error parsing the true type font.
+     */
+    protected void processSubtype2(TTFDataStream data, int numGlyphs) throws IOException
+    {
+        int[] subHeaderKeys = new int[256];
+        // ---- keep the Max Index of the SubHeader array to know its length
+        int maxSubHeaderIndex = 0;
+        for (int i = 0; i < 256; i++)
+        {
+            subHeaderKeys[i] = data.readUnsignedShort();
+            maxSubHeaderIndex = Math.max(maxSubHeaderIndex, subHeaderKeys[i] / 8);
+        }
 
 		// ---- Read all SubHeaders to avoid useless seek on DataSource
 		SubHeader[] subHeaders = new SubHeader[maxSubHeaderIndex + 1]; 
@@ -457,8 +459,7 @@ public class CMAPEncodingEntry
 	 * @param data
 	 * @throws IOException
 	 */
-	protected void processSubtype0( TrueTypeFont ttf, TTFDataStream data ) 
-			throws IOException {
+	protected void processSubtype0( TTFDataStream data ) throws IOException {
 		byte[] glyphMapping = data.read( 256 );
 		glyphIdToCharacterCode = new int[256];
 		for( int i=0;i < glyphMapping.length; i++ )
@@ -518,11 +519,11 @@ public class CMAPEncodingEntry
 	 * @param characterCode
 	 * @return glyphId
 	 */
-        public int getGlyphId(int characterCode)
-        {
-            Integer glyphId = characterCodeToGlyphId.get(characterCode);
-            return glyphId == null ? 0 : glyphId.intValue();
-        }
+	public int getGlyphId(int characterCode)
+	{
+	    Integer glyphId = characterCodeToGlyphId.get(characterCode);
+	    return glyphId == null ? 0 : glyphId.intValue();
+	}
 
 	/**
 	 * Class used to manage CMap - Format 2

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/CMAPTable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/CMAPTable.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/CMAPTable.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/CMAPTable.java Tue May 27 19:00:15 2014
@@ -82,14 +82,14 @@ public class CMAPTable extends TTFTable
         for( int i=0; i< numberOfTables; i++ )
         {
             CMAPEncodingEntry cmap = new CMAPEncodingEntry();
-            cmap.initData( ttf, data );
-            cmaps[i]=cmap;
+            cmap.initData(data);
+            cmaps[i] = cmap;
         }
         for( int i=0; i< numberOfTables; i++ )
         {
-            cmaps[i].initSubtable( ttf, data );
+            cmaps[i].initSubtable(this, ttf.getNumberOfGlyphs(), data);
         }
-        
+        initialized = true;
     }
     /**
      * @return Returns the cmaps.

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphData.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphData.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphData.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphData.java Tue May 27 19:00:15 2014
@@ -24,7 +24,6 @@ import org.apache.fontbox.util.BoundingB
  * A glyph data record in the glyf table.
  * 
  * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
  */
 public class GlyphData
 {
@@ -39,11 +38,11 @@ public class GlyphData
     /**
      * This will read the required data from the stream.
      * 
-     * @param ttf The font that is being read.
+     * @param glyphTable The glyph table this glyph belongs to.
      * @param data The stream to read the data from.
      * @throws IOException If there is an error reading the data.
      */
-    public void initData( TrueTypeFont ttf, TTFDataStream data ) throws IOException
+    public void initData( GlyphTable glyphTable, TTFDataStream data ) throws IOException
     {
         numberOfContours = data.readSignedShort();
         xMin = data.readSignedShort();
@@ -60,7 +59,7 @@ public class GlyphData
         else 
         {
             // create a composite glyph
-            glyphDescription = new GlyfCompositeDescript(data, ttf.getGlyph());
+            glyphDescription = new GlyfCompositeDescript(data, glyphTable);
         }
     }
     

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java Tue May 27 19:00:15 2014
@@ -42,12 +42,11 @@ public class GlyphTable extends TTFTable
      */
     public void initData(TrueTypeFont ttf, TTFDataStream data) throws IOException
     {
-        MaximumProfileTable maxp = ttf.getMaximumProfile();
         IndexToLocationTable loc = ttf.getIndexToLocation();
         // the glyph offsets
         long[] offsets = loc.getOffsets();
         // number of glyphs
-        int numGlyphs = maxp.getNumGlyphs();
+        int numGlyphs = ttf.getNumberOfGlyphs();
         // the end of the glyph table
         long endOfGlyphs = offsets[numGlyphs];
         long offset = getOffset();
@@ -67,7 +66,7 @@ public class GlyphTable extends TTFTable
             }
             glyphs[i] = new GlyphData();
             data.seek(offset + offsets[i]);
-            glyphs[i].initData(ttf, data);
+            glyphs[i].initData(this, data);
         }
         for (int i = 0; i < numGlyphs; i++)
         {
@@ -78,6 +77,7 @@ public class GlyphTable extends TTFTable
                 glyph.getDescription().resolve();
             }
         }
+        initialized = true;
     }
 
     /**

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/HeaderTable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/HeaderTable.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/HeaderTable.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/HeaderTable.java Tue May 27 19:00:15 2014
@@ -23,7 +23,6 @@ import java.util.Calendar;
  * A table in a true type font.
  * 
  * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
  */
 public class HeaderTable extends TTFTable
 {
@@ -76,6 +75,7 @@ public class HeaderTable extends TTFTabl
         fontDirectionHint = data.readSignedShort();
         indexToLocFormat = data.readSignedShort();
         glyphDataFormat = data.readSignedShort();
+        initialized = true;
     }
     /**
      * @return Returns the checkSumAdjustment.

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/HorizontalHeaderTable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/HorizontalHeaderTable.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/HorizontalHeaderTable.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/HorizontalHeaderTable.java Tue May 27 19:00:15 2014
@@ -22,7 +22,6 @@ import java.io.IOException;
  * A table in a true type font.
  * 
  * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
  */
 public class HorizontalHeaderTable extends TTFTable
 {
@@ -75,6 +74,7 @@ public class HorizontalHeaderTable exten
         reserved5 = data.readSignedShort();
         metricDataFormat = data.readSignedShort();
         numberOfHMetrics = data.readUnsignedShort();
+        initialized = true;
     }
     
     /**

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/HorizontalMetricsTable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/HorizontalMetricsTable.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/HorizontalMetricsTable.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/HorizontalMetricsTable.java Tue May 27 19:00:15 2014
@@ -22,7 +22,6 @@ import java.io.IOException;
  * A table in a true type font.
  * 
  * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
  */
 public class HorizontalMetricsTable extends TTFTable
 {
@@ -45,9 +44,8 @@ public class HorizontalMetricsTable exte
     public void initData( TrueTypeFont ttf, TTFDataStream data ) throws IOException
     {
         HorizontalHeaderTable hHeader = ttf.getHorizontalHeader();
-        MaximumProfileTable maxp = ttf.getMaximumProfile();
         int numHMetrics = hHeader.getNumberOfHMetrics();
-        int numGlyphs = maxp.getNumGlyphs();
+        int numGlyphs = ttf.getNumberOfGlyphs();
         
         advanceWidth = new int[ numHMetrics ];
         leftSideBearing = new short[ numHMetrics ];
@@ -63,6 +61,7 @@ public class HorizontalMetricsTable exte
         {
             nonHorizontalLeftSideBearing[i] = data.readSignedShort();
         }
+        initialized = true;
     }
     /**
      * @return Returns the advanceWidth.
@@ -76,6 +75,6 @@ public class HorizontalMetricsTable exte
      */
     public void setAdvanceWidth(int[] advanceWidthValue)
     {
-        this.advanceWidth = advanceWidthValue;
+        advanceWidth = advanceWidthValue;
     }
 }

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/IndexToLocationTable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/IndexToLocationTable.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/IndexToLocationTable.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/IndexToLocationTable.java Tue May 27 19:00:15 2014
@@ -22,7 +22,6 @@ import java.io.IOException;
  * A table in a true type font.
  * 
  * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
  */
 public class IndexToLocationTable extends TTFTable
 {
@@ -46,8 +45,7 @@ public class IndexToLocationTable extend
     public void initData( TrueTypeFont ttf, TTFDataStream data ) throws IOException
     {
         HeaderTable head = ttf.getHeader();
-        MaximumProfileTable maxp = ttf.getMaximumProfile();
-        int numGlyphs = maxp.getNumGlyphs();
+        int numGlyphs = ttf.getNumberOfGlyphs();
         offsets = new long[ numGlyphs +1];
         for( int i=0; i<numGlyphs+1; i++ )
         {
@@ -64,6 +62,7 @@ public class IndexToLocationTable extend
                 throw new IOException( "Error:TTF.loca unknown offset format.");
             }
         }
+        initialized = true;
     }
     /**
      * @return Returns the offsets.
@@ -77,6 +76,6 @@ public class IndexToLocationTable extend
      */
     public void setOffsets(long[] offsetsValue)
     {
-        this.offsets = offsetsValue;
+        offsets = offsetsValue;
     }
 }

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/MaximumProfileTable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/MaximumProfileTable.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/MaximumProfileTable.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/MaximumProfileTable.java Tue May 27 19:00:15 2014
@@ -22,7 +22,6 @@ import java.io.IOException;
  * A table in a true type font.
  * 
  * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
  */
 public class MaximumProfileTable extends TTFTable
 {
@@ -282,5 +281,6 @@ public class MaximumProfileTable extends
         maxSizeOfInstructions = data.readUnsignedShort();
         maxComponentElements = data.readUnsignedShort();
         maxComponentDepth = data.readUnsignedShort();
+        initialized = true;
     }
 }

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/NamingTable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/NamingTable.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/NamingTable.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/NamingTable.java Tue May 27 19:00:15 2014
@@ -25,7 +25,7 @@ import java.util.List;
  * A table in a true type font.
  * 
  * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
+ * 
  */
 public class NamingTable extends TTFTable
 {
@@ -36,6 +36,11 @@ public class NamingTable extends TTFTabl
     
     private List<NameRecord> nameRecords = new ArrayList<NameRecord>();
     
+    private String fontFamily = null;
+    private String fontSubFamily = null;
+    private String psName = null;
+    
+    
     /**
      * This will read the required data from the stream.
      * 
@@ -61,9 +66,12 @@ public class NamingTable extends TTFTabl
             int platform = nr.getPlatformId();
             int encoding = nr.getPlatformEncodingId();
             String charset = "ISO-8859-1";
-            if( platform == 3 && encoding == 1 )
+            boolean isPlatform310 = false;
+            boolean isPlatform10 = false;
+            if( platform == 3 && (encoding == 1 || encoding == 0) )
             {
                 charset = "UTF-16";
+                isPlatform310 = true;
             }
             else if( platform == 2 )
             {
@@ -81,9 +89,39 @@ public class NamingTable extends TTFTabl
                     charset = "ISO-8859-1";
                 }
             }
+            else if ( platform == 1 && encoding == 0)
+            {
+                isPlatform10 = true;
+            }
             String string = data.readString( nr.getStringLength(), charset );
             nr.setString( string );
+            int nameID = nr.getNameId();
+            if (nameID == NameRecord.NAME_FONT_FAMILY_NAME)
+            {
+                // prefer 3,1 or 3,0 platform/encoding use 1,0 as fallback
+                if (isPlatform310 || (isPlatform10 && fontFamily == null))
+                {
+                    fontFamily = string;
+                }
+            }            
+            else if (nameID == NameRecord.NAME_FONT_SUB_FAMILY_NAME)
+            {
+                // prefer 3,1 or 3,0 platform/encoding use 1,0 as fallback
+                if (isPlatform310 || (isPlatform10 && fontSubFamily == null))
+                {
+                    fontSubFamily = string;
+                }
+            }            
+            else if (nameID == NameRecord.NAME_POSTSCRIPT_NAME)
+            {
+                // prefer 3,1 or 3,0 platform/encoding use 1,0 as fallback
+                if (isPlatform310 || (isPlatform10 && psName == null))
+                {
+                    psName = string;
+                }
+            }            
         }
+        initialized = true;
     }
     
     /**
@@ -95,4 +133,35 @@ public class NamingTable extends TTFTabl
     {
         return nameRecords;
     }
+    
+    /**
+     * Returns the font family name.
+     * 
+     * @return the font family name
+     */
+    public String getFontFamily()
+    {
+        return fontFamily;
+    }
+
+    /**
+     * Returns the font sub family name.
+     * 
+     * @return the font sub family name
+     */
+    public String getFontSubFamily()
+    {
+        return fontSubFamily;
+    }
+
+    /**
+     * Returns the postscript name.
+     * 
+     * @return the postscript name
+     */
+    public String getPSName()
+    {
+        return psName;
+    }
+
 }

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/OS2WindowsMetricsTable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/OS2WindowsMetricsTable.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/OS2WindowsMetricsTable.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/OS2WindowsMetricsTable.java Tue May 27 19:00:15 2014
@@ -758,5 +758,6 @@ public class OS2WindowsMetricsTable exte
             codePageRange1 = data.readUnsignedInt();
             codePageRange2 = data.readUnsignedInt();
         }
+        initialized = true;
     }
 }

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java Tue May 27 19:00:15 2014
@@ -53,7 +53,6 @@ public class PostScriptTable extends TTF
      */
     public void initData(TrueTypeFont ttf, TTFDataStream data) throws IOException
     {
-        MaximumProfileTable maxp = ttf.getMaximumProfile();
         formatType = data.read32Fixed();
         italicAngle = data.read32Fixed();
         underlinePosition = data.readSignedShort();
@@ -120,7 +119,7 @@ public class PostScriptTable extends TTF
         }
         else if (formatType == 2.5f)
         {
-            int[] glyphNameIndex = new int[maxp.getNumGlyphs()];
+            int[] glyphNameIndex = new int[ttf.getNumberOfGlyphs()];
             for (int i = 0; i < glyphNameIndex.length; i++)
             {
                 int offset = data.readSignedByte();
@@ -141,6 +140,7 @@ public class PostScriptTable extends TTF
         {
             // no postscript information is provided.
         }
+        initialized = true;
     }
 
     /**

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java Tue May 27 19:00:15 2014
@@ -21,19 +21,38 @@ import java.io.IOException;
  * A true type font file parser.
  * 
  * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.2 $
  */
 public class TTFParser extends AbstractTTFParser
-{   
-    public TTFParser() {
+{
+    /**
+     * Constructor.
+     */
+    public TTFParser()
+    {
         super(false);
     }
-       
-    public TTFParser(boolean isEmbedded) {
+
+    /**
+     * Constructor.
+     *  
+     * @param isEmbedded indicates whether the font is embedded or not.
+     */
+    public TTFParser(boolean isEmbedded)
+    {
         super(isEmbedded);
     }
         
     /**
+     *  Constructor.
+     *  
+     * @param isEmbedded indicates whether the font is embedded or not.
+     * @param parseOnDemand indicates whether the tables of the font should be parsed on demand only or not.
+     */
+    public TTFParser(boolean isEmbedded, boolean parseOnDemand)
+    {
+        super(isEmbedded, parseOnDemand);
+    }
+    /**
      * A simple command line program to test parsing of a TTF file. <br/>
      * usage: java org.pdfbox.ttf.TTFParser &lt;ttf-file&gt;
      * 
@@ -59,7 +78,6 @@ public class TTFParser extends AbstractT
     protected void parseTables(TrueTypeFont font, TTFDataStream raf) throws IOException 
     {
         super.parseTables(font, raf);
-        
         // check others mandatory tables
         if ( font.getCMAP() == null ){
             throw new IOException("cmap is mandatory");

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/TTFTable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/TTFTable.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/TTFTable.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/TTFTable.java Tue May 27 19:00:15 2014
@@ -22,7 +22,6 @@ import java.io.IOException;
  * A table in a true type font.
  * 
  * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
  */
 public class TTFTable 
 {
@@ -30,7 +29,12 @@ public class TTFTable 
     private long checkSum;
     private long offset;
     private long length;
-      
+    
+    /**
+     * Indicates if the table is initialized or not.
+     */
+    protected boolean initialized = false;
+    
     /**
      * @return Returns the checkSum.
      */
@@ -89,6 +93,15 @@ public class TTFTable 
     }
     
     /**
+     * Indicates if the table is already initialized.
+     * 
+     * @return true if the table is initialized
+     */
+    public boolean getInitialized()
+    {
+        return initialized;
+    }
+    /**
      * This will read the required data from the stream.
      * 
      * @param ttf The font that is being read.

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java?rev=1597849&r1=1597848&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java Tue May 27 19:00:15 2014
@@ -19,19 +19,25 @@ package org.apache.fontbox.ttf;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
-
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fontbox.util.autodetect.FontFileFinder;
+
 /**
  * A class to hold true type font information.
  * 
  * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.2 $
  */
 public class TrueTypeFont 
 {
+    private final Log log = LogFactory.getLog(TrueTypeFont.class);
+
     private float version; 
+
+    private int numberOfGlyphs = -1;
     
     private Map<String,TTFTable> tables = new HashMap<String,TTFTable>();
     
@@ -99,7 +105,12 @@ public class TrueTypeFont 
      */
     public NamingTable getNaming()
     {
-        return (NamingTable)tables.get( NamingTable.TAG );
+        NamingTable naming = (NamingTable)tables.get( NamingTable.TAG );
+        if (naming != null && !naming.getInitialized())
+        {
+            initializeTable(naming);
+        }
+        return naming;
     }
     
     /**
@@ -109,7 +120,12 @@ public class TrueTypeFont 
      */
     public PostScriptTable getPostScript()
     {
-        return (PostScriptTable)tables.get( PostScriptTable.TAG );
+        PostScriptTable postscript = (PostScriptTable)tables.get( PostScriptTable.TAG );
+        if (postscript != null && !postscript.getInitialized())
+        {
+            initializeTable(postscript);
+        }
+        return postscript;
     }
     
     /**
@@ -119,7 +135,12 @@ public class TrueTypeFont 
      */
     public OS2WindowsMetricsTable getOS2Windows()
     {
-        return (OS2WindowsMetricsTable)tables.get( OS2WindowsMetricsTable.TAG );
+        OS2WindowsMetricsTable os2WindowsMetrics = (OS2WindowsMetricsTable)tables.get( OS2WindowsMetricsTable.TAG );
+        if (os2WindowsMetrics != null && !os2WindowsMetrics.getInitialized())
+        {
+            initializeTable(os2WindowsMetrics);
+        }
+        return os2WindowsMetrics;
     }
     
     /**
@@ -129,7 +150,12 @@ public class TrueTypeFont 
      */
     public MaximumProfileTable getMaximumProfile()
     {
-        return (MaximumProfileTable)tables.get( MaximumProfileTable.TAG );
+        MaximumProfileTable maximumProfile = (MaximumProfileTable)tables.get( MaximumProfileTable.TAG );
+        if (maximumProfile != null && !maximumProfile.getInitialized())
+        {
+            initializeTable(maximumProfile);
+        }
+        return maximumProfile;
     }
     
     /**
@@ -139,7 +165,12 @@ public class TrueTypeFont 
      */
     public HeaderTable getHeader()
     {
-        return (HeaderTable)tables.get( HeaderTable.TAG );
+        HeaderTable header = (HeaderTable)tables.get( HeaderTable.TAG );
+        if (header != null && !header.getInitialized())
+        {
+            initializeTable(header);
+        }
+        return header;
     }
     
     /**
@@ -149,7 +180,12 @@ public class TrueTypeFont 
      */
     public HorizontalHeaderTable getHorizontalHeader()
     {
-        return (HorizontalHeaderTable)tables.get( HorizontalHeaderTable.TAG );
+        HorizontalHeaderTable horizontalHeader = (HorizontalHeaderTable)tables.get( HorizontalHeaderTable.TAG );
+        if (horizontalHeader != null && !horizontalHeader.getInitialized())
+        {
+            initializeTable(horizontalHeader);
+        }
+        return horizontalHeader;
     }
     
     /**
@@ -159,7 +195,12 @@ public class TrueTypeFont 
      */
     public HorizontalMetricsTable getHorizontalMetrics()
     {
-        return (HorizontalMetricsTable)tables.get( HorizontalMetricsTable.TAG );
+        HorizontalMetricsTable horizontalMetrics = (HorizontalMetricsTable)tables.get( HorizontalMetricsTable.TAG );
+        if (horizontalMetrics != null && !horizontalMetrics.getInitialized())
+        {
+            initializeTable(horizontalMetrics);
+        }
+        return horizontalMetrics;
     }
     
     /**
@@ -169,7 +210,12 @@ public class TrueTypeFont 
      */
     public IndexToLocationTable getIndexToLocation()
     {
-        return (IndexToLocationTable)tables.get( IndexToLocationTable.TAG );
+        IndexToLocationTable indexToLocation = (IndexToLocationTable)tables.get( IndexToLocationTable.TAG );
+        if (indexToLocation != null && !indexToLocation.getInitialized())
+        {
+            initializeTable(indexToLocation);
+        }
+        return indexToLocation;
     }
     
     /**
@@ -179,7 +225,12 @@ public class TrueTypeFont 
      */
     public GlyphTable getGlyph()
     {
-        return (GlyphTable)tables.get( GlyphTable.TAG );
+        GlyphTable glyph = (GlyphTable)tables.get( GlyphTable.TAG );
+        if (glyph != null && !glyph.getInitialized())
+        {
+            initializeTable(glyph);
+        }
+        return glyph;
     }
     
     /**
@@ -189,7 +240,12 @@ public class TrueTypeFont 
      */
     public CMAPTable getCMAP()
     {
-        return (CMAPTable)tables.get( CMAPTable.TAG );
+        CMAPTable cmap = (CMAPTable)tables.get( CMAPTable.TAG );
+        if (cmap != null && !cmap.getInitialized())
+        {
+            initializeTable(cmap);
+        }
+        return cmap;
     }
     
     /**
@@ -205,4 +261,49 @@ public class TrueTypeFont 
     {
        return data.getOriginalData(); 
     }
+    
+    /**
+     * Initialize the given table if necessary.
+     * 
+     * @param table the table to be initialized
+     */
+    public void initializeTable(TTFTable table)
+    {
+        try
+        {
+            // save current position
+            long currentPosition = data.getCurrentPosition();
+            data.seek(table.getOffset());
+            table.initData(this, data);
+            // restore current position
+            data.seek(currentPosition);
+        }
+        catch (IOException exception)
+        {
+            log.error("An error occured when reading table " + table.getTag(), exception);
+        }
+    }
+
+    /**
+     * Returns the number of glyphs (MaximuProfile.numGlyphs).
+     * 
+     * @return the number of glyphs
+     */
+    public int getNumberOfGlyphs()
+    {
+        if (numberOfGlyphs == -1)
+        {
+            MaximumProfileTable maximumProfile = getMaximumProfile();
+            if (maximumProfile != null)
+            {
+                numberOfGlyphs = maximumProfile.getNumGlyphs();
+            }
+            else
+            {
+                // this should never happen
+                numberOfGlyphs = 0;
+            }
+        }
+        return numberOfGlyphs;
+    }
 }

Copied: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/FontManager.java (from r1595992, pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/util/FontManager.java)
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/FontManager.java?p2=pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/FontManager.java&p1=pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/util/FontManager.java&r1=1595992&r2=1597849&rev=1597849&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/util/FontManager.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/FontManager.java Tue May 27 19:00:15 2014
@@ -16,9 +16,10 @@
  */
 package org.apache.fontbox.util;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URL;
+import java.net.URI;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -61,24 +62,26 @@ public class FontManager
         try
         {
             FontFileFinder fontfinder = new FontFileFinder();
-            List<URL> fonts = fontfinder.find();
-            for (URL font : fonts)
+            List<URI> fonts = fontfinder.find();
+            for (URI font : fonts)
             {
-                String fontfilename = font.getPath();
-                if (fontfilename.toLowerCase().endsWith(".ttf"))
+                try
                 {
-                    try
+                    // the URL may contain some escaped characters like spaces
+                    // use the URI to decode such escape sequences
+                    String fontfilename = new File(font).getPath();
+                    if (fontfilename.toLowerCase().endsWith(".ttf"))
                     {
                         analyzeTTF(fontfilename);
                     }
-                    catch (IOException exception)
+                    else
                     {
-                        LOG.debug("Can't read external font: " + fontfilename, exception);
+                        LOG.debug("Unsupported font format for external font: " + fontfilename);
                     }
                 }
-                else
+                catch (IOException exception)
                 {
-                    LOG.debug("Unsupported font format for external font: " + fontfilename);
+                    LOG.debug("Can't read external font: " + font.getPath(), exception);
                 }
             }
             addFontMapping(fontfinder.getCommonTTFMapping(), fontMappingTTF);
@@ -102,13 +105,16 @@ public class FontManager
      */
     private static void analyzeTTF(String ttfFilename) throws IOException
     {
-        TTFParser ttfParser = new TTFParser();
+        TTFParser ttfParser = new TTFParser(false,true);
         TrueTypeFont ttfFont = ttfParser.parseTTF(ttfFilename);
         if (ttfFont != null)
         {
             NamingTable namingTable = ttfFont.getNaming();
-            String normalizedName = normalizeFontname(namingTable.getPSName());
-            ttfFontfiles.put(normalizedName, ttfFilename);
+            if (namingTable != null && namingTable.getPSName() != null)
+            {
+                String normalizedName = normalizeFontname(namingTable.getPSName());
+                ttfFontfiles.put(normalizedName, ttfFilename);
+            }
         }
     }
 
@@ -216,6 +222,8 @@ public class FontManager
     private static void createFontmapping()
     {
         addFontFamilyMapping("ArialNarrow", "Arial", fontMappingTTF);
+        addFontFamilyMapping("CourierNew", "Courier", fontMappingTTF);
+        addFontFamilyMapping("TimesNewRomanPSMT", "TimesNewRoman", fontMappingTTF);
     }
 
     /**
@@ -246,9 +254,10 @@ public class FontManager
             loadFonts();
         }
         String fontfile = null;
-        if (ttfFontfiles.containsKey(fontname))
+        String normalizedFontname = normalizeFontname(fontname);
+        if (ttfFontfiles.containsKey(normalizedFontname))
         {
-            fontfile = ttfFontfiles.get(fontname);
+            fontfile = ttfFontfiles.get(normalizedFontname);
         }
         if (fontfile == null)
         {

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/FontFileFinder.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/FontFileFinder.java?rev=1597849&r1=1595992&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/FontFileFinder.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/FontFileFinder.java Tue May 27 19:00:15 2014
@@ -19,56 +19,24 @@ package org.apache.fontbox.util.autodete
 
 import java.io.File;
 import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Collection;
+import java.net.URI;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.io.DirectoryWalker;
-import org.apache.commons.io.IOCase;
-import org.apache.commons.io.filefilter.FileFilterUtils;
-import org.apache.commons.io.filefilter.IOFileFilter;
-import org.apache.commons.io.filefilter.WildcardFileFilter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 /**
  * Helps to autodetect/locate available operating system fonts. This class is based on a class provided by Apache FOP.
  * see org.apache.fop.fonts.autodetect.FontFileFinder
  */
-public class FontFileFinder extends DirectoryWalker<URL>
+public class FontFileFinder
 {
 
-    /**
-     * logging instance.
-     */
-    private final Log log = LogFactory.getLog(FontFileFinder.class);
-
     private FontDirFinder fontDirFinder = null;
 
     /**
-     * default depth limit of recursion when searching for font files.
-     */
-    public static final int DEFAULT_DEPTH_LIMIT = -1;
-
-    /**
      * Default constructor.
      */
     public FontFileFinder()
     {
-        this(DEFAULT_DEPTH_LIMIT);
-    }
-
-    /**
-     * Constructor.
-     * 
-     * @param depthLimit recursion depth limit
-     * 
-     */
-    public FontFileFinder(int depthLimit)
-    {
-        super(getDirectoryFilter(), getFileFilter(), depthLimit);
     }
 
     private FontDirFinder determineDirFinder()
@@ -92,90 +60,22 @@ public class FontFileFinder extends Dire
     }
 
     /**
-     * Font directory filter. Currently ignores hidden directories.
-     * 
-     * @return IOFileFilter font directory filter
-     */
-    protected static IOFileFilter getDirectoryFilter()
-    {
-        return FileFilterUtils.and(FileFilterUtils.directoryFileFilter(),
-                FileFilterUtils.notFileFilter(FileFilterUtils.prefixFileFilter(".")));
-    }
-
-    /**
-     * Font file filter. Currently searches for files with .ttf, .ttc, .otf, and .pfb extensions.
-     * 
-     * @return IOFileFilter font file filter
-     */
-    protected static IOFileFilter getFileFilter()
-    {
-        return FileFilterUtils.and(FileFilterUtils.fileFileFilter(), new WildcardFileFilter(
-                new String[] { "*.ttf", "*.otf", "*.pfb", "*.ttc" }, IOCase.INSENSITIVE));
-    }
-
-    /**
-     * @param directory directory to handle
-     * @param depth recursion depth
-     * @param results collection
-     * @return whether directory should be handled {@inheritDoc}
-     */
-    @Override
-    protected boolean handleDirectory(File directory, int depth, Collection<URL> results)
-    {
-        return true;
-    }
-
-    /**
-     * @param file file to handle
-     * @param depth recursion depth
-     * @param results collection {@inheritDoc}
-     */
-    @Override
-    protected void handleFile(File file, int depth, Collection<URL> results)
-    {
-        try
-        {
-            // Looks Strange, but is actually recommended over just .URL()
-            results.add(file.toURI().toURL());
-        }
-        catch (MalformedURLException e)
-        {
-            log.debug("MalformedURLException" + e.getMessage());
-        }
-    }
-
-    /**
-     * @param directory the directory being processed
-     * @param depth the current directory level
-     * @param results the collection of results objects {@inheritDoc}
-     */
-    @Override
-    protected void handleDirectoryEnd(File directory, int depth, Collection<URL> results)
-    {
-        if (log.isDebugEnabled())
-        {
-            log.debug(directory + ": found " + results.size() + " font"
-                    + ((results.size() == 1) ? "" : "s"));
-        }
-    }
-
-    /**
      * Automagically finds a list of font files on local system.
      * 
-     * @return List&lt;URL&gt; of font files
+     * @return List&lt;URI&gt; of font files
      * @throws IOException io exception {@inheritDoc}
      */
-    public List<URL> find() throws IOException
+    public List<URI> find() throws IOException
     {
         if (fontDirFinder == null)
         {
             fontDirFinder = determineDirFinder();
         }
         List<File> fontDirs = fontDirFinder.find();
-        List<URL> results = new java.util.ArrayList<URL>();
+        List<URI> results = new java.util.ArrayList<URI>();
         for (File dir : fontDirs)
         {
-            super.walk(dir, results);
+            walk(dir, results);
         }
         return results;
     }
@@ -184,16 +84,16 @@ public class FontFileFinder extends Dire
      * Searches a given directory for font files.
      * 
      * @param dir directory to search
-     * @return list of font files
+     * @return list&lt;URI&gt; of font files
      * @throws IOException thrown if an I/O exception of some sort has occurred
      */
-    public List<URL> find(String dir) throws IOException
+    public List<URI> find(String dir) throws IOException
     {
-        List<URL> results = new java.util.ArrayList<URL>();
+        List<URI> results = new java.util.ArrayList<URI>();
         File directory = new File(dir);
         if (directory.isDirectory())
         {
-            super.walk(directory, results);
+            walk(directory, results);
         }
         return results;
     }
@@ -211,4 +111,59 @@ public class FontFileFinder extends Dire
         }
         return fontDirFinder.getCommonTTFMapping();
     }
+    
+    /**
+     * walk down the driectory tree and search for font files.
+     * 
+     * @param directory the directory to start at
+     * @param results names of all found font files
+     */
+    private void walk(File directory, List<URI> results)
+    {
+        // search for font files recursively in the given directory
+        if (directory.isDirectory())
+        {
+            File[] filelist = directory.listFiles();
+            if (filelist != null)
+            {
+                int numOfFiles = filelist.length;
+                for (int i=0;i<numOfFiles;i++)
+                {
+                    File file = filelist[i];
+                    if (file.isDirectory())
+                    {
+                        // skip hidden directories
+                        if (file.getName().startsWith("."))
+                        {
+                            continue;
+                        }
+                        walk(file, results);
+                    }
+                    else
+                    {
+                        if (checkFontfile(file))
+                        {
+                            results.add(file.toURI());
+                        }
+                    }
+                }
+            }
+        }
+    }
+    
+    /**
+     * Check if the given name belongs to a font file.
+     * 
+     * @param filename the given filename
+     * @return true if the given filename has a typical font file ending
+     */
+    private boolean checkFontfile(File file)
+    {
+        String name = file.getName().toLowerCase();
+        if (name.endsWith(".ttf") || name.endsWith(".otf") || name.endsWith(".pfb") || name.endsWith(".ttc"))
+        {
+            return true;
+        }
+        return false;
+    }
 }

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/MacFontDirFinder.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/MacFontDirFinder.java?rev=1597849&r1=1595992&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/MacFontDirFinder.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/MacFontDirFinder.java Tue May 27 19:00:15 2014
@@ -17,6 +17,8 @@
 
 package org.apache.fontbox.util.autodetect;
 
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -45,8 +47,26 @@ public class MacFontDirFinder extends Na
      */
     public Map<String, String> getCommonTTFMapping()
     {
-        // TODO Auto-generated method stub
-        return null;
+        HashMap<String,String> map = new HashMap<String,String>();
+        map.put("Arial", "Arial");
+        map.put("Arial,Bold", "ArialBold");
+        map.put("Arial,Italic", "ArialItalic");
+        map.put("Arial,BoldItalic", "ArialBoldItalic");
+
+        map.put("TimesNewRoman", "timesnewromanpsmt");
+        map.put("TimesNewRoman,Bold", "timesnewromanpsmtbold");
+        map.put("TimesNewRoman,BoldItalic", "timesnewromanpsmtbolditalic");
+        map.put("TimesNewRoman,Italic", "timesnewromanpsmtitalic");
+        
+        map.put("Courier", "couriernewpsmt");
+        map.put("Courier,Bold", "couriernewpsmtbold");
+        map.put("Courier,Italic", "couriernewpsmtitalic");
+        map.put("Courier,BoldItalic", "couriernewpsmtbolditalic");
+
+        map.put("Symbol", "Symbol");
+        map.put("ZapfDingbats", "ZapfDingbats");
+
+        return Collections.unmodifiableMap(map);
     }
 
 }

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/UnixFontDirFinder.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/UnixFontDirFinder.java?rev=1597849&r1=1595992&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/UnixFontDirFinder.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/UnixFontDirFinder.java Tue May 27 19:00:15 2014
@@ -53,9 +53,9 @@ public class UnixFontDirFinder extends N
         map.put("TimesNewRoman,Bold","LiberationSerif-Bold");
         map.put("TimesNewRoman,Italic","LiberationSerif-Italic");
         map.put("TimesNewRoman","LiberationSerif");
-        map.put("ArialNarrow,BoldItalic","LiberationSans-BoldItalic");
-        map.put("ArialNarrow,Italic","LiberationSans-Italic");
-        map.put("ArialNarrow,Bold","LiberationSans-Bold");
+        map.put("Arial,BoldItalic","LiberationSans-BoldItalic");
+        map.put("Arial,Italic","LiberationSans-Italic");
+        map.put("Arial,Bold","LiberationSans-Bold");
         map.put("Arial","LiberationSans");
         map.put("Symbol", "OpenSymbol");
         map.put("ZapfDingbats", "Dingbats");

Modified: pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/WindowsFontDirFinder.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/WindowsFontDirFinder.java?rev=1597849&r1=1595992&r2=1597849&view=diff
==============================================================================
--- pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/WindowsFontDirFinder.java (original)
+++ pdfbox/branches/1.8/fontbox/src/main/java/org/apache/fontbox/util/autodetect/WindowsFontDirFinder.java Tue May 27 19:00:15 2014
@@ -21,6 +21,8 @@ import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -134,8 +136,26 @@ public class WindowsFontDirFinder implem
      */
     public Map<String, String> getCommonTTFMapping()
     {
-        // TODO Auto-generated method stub
-        return null;
+        HashMap<String,String> map = new HashMap<String,String>();
+        map.put("Arial", "arialmt");
+        map.put("Arial,Bold", "arialmtbold");
+        map.put("Arial,Italic", "arialmtitalic");
+        map.put("Arial,BoldItalic", "arialmtbolditalic");
+
+        map.put("TimesNewRoman", "timesnewromanpsmt");
+        map.put("TimesNewRoman,Bold", "timesnewromanpsmtbold");
+        map.put("TimesNewRoman,BoldItalic", "timesnewromanpsmtbolditalic");
+        map.put("TimesNewRoman,Italic", "timesnewromanpsmtitalic");
+        
+        map.put("Courier", "couriernewpsmt");
+        map.put("Courier,Bold", "couriernewpsmtbold");
+        map.put("Courier,Italic", "couriernewpsmtitalic");
+        map.put("Courier,BoldItalic", "couriernewpsmtbolditalic");
+
+        map.put("Symbol", "symbolmt");
+        map.put("ZapfDingbats", "Wingdings");
+
+        return Collections.unmodifiableMap(map);
     }
 
 }