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 2012/07/16 20:24:54 UTC

svn commit: r1362175 - in /pdfbox/branches/1.7: ./ fontbox/src/main/java/org/apache/fontbox/encoding/ fontbox/src/main/java/org/apache/fontbox/ttf/ jempbox/ parent/ pdfbox/ pdfbox/src/main/java/org/apache/pdfbox/cos/ pdfbox/src/main/java/org/apache/pdf...

Author: lehmi
Date: Mon Jul 16 18:24:53 2012
New Revision: 1362175

URL: http://svn.apache.org/viewvc?rev=1362175&view=rev
Log:
merged the following changes from trunk

PDFBOX-564:  rev. 1346804
PDFBOX-954:  rev. 1356866
PDFBOX-1099: rev. 1350033,rev. 1351132
PDFBOX-1323: rev. 1342924
PDFBOX-1333: rev. 1346891
PDFBOX-1334: rev. 1346902
PDFBOX-1337: rev. 1349167
PDFBOX-1339: rev. 1350113
PDFBOX-1340: rev. 1361723
PDFBOX-1349: rev. 1358739,rev. 1358740
PDFBOX-1353,PDFBOX-1355: rev. 1361738
PDFBOX-1357: rev. 1359845
PDFBOX-1358: rev. 1361698,rev. 1361704
DOAP-file: rev. 1343811
most of rev. 1343778


Added:
    pdfbox/branches/1.7/pdfbox/src/test/java/org/apache/pdfbox/io/TestRandomAccessBuffer.java
      - copied unchanged from r1361698, pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/TestRandomAccessBuffer.java
    pdfbox/branches/1.7/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestTTFParser.java
      - copied unchanged from r1358740, pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestTTFParser.java
Modified:
    pdfbox/branches/1.7/   (props changed)
    pdfbox/branches/1.7/doap_PDFBox.rdf
    pdfbox/branches/1.7/fontbox/src/main/java/org/apache/fontbox/encoding/Encoding.java
    pdfbox/branches/1.7/fontbox/src/main/java/org/apache/fontbox/encoding/MacRomanEncoding.java
    pdfbox/branches/1.7/fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java
    pdfbox/branches/1.7/jempbox/pom.xml
    pdfbox/branches/1.7/parent/pom.xml
    pdfbox/branches/1.7/pdfbox/pom.xml
    pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
    pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/encoding/MacRomanEncoding.java
    pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/encoding/WinAnsiEncoding.java
    pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/exceptions/WrappedException.java
    pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java
    pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
    pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
    pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
    pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
    pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
    pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java
    pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/util/PDFOperator.java
    pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
    pdfbox/branches/1.7/pdfbox/src/test/java/org/apache/pdfbox/TestAll.java
    pdfbox/branches/1.7/preflight/pom.xml
    pdfbox/branches/1.7/xmpbox/pom.xml

Propchange: pdfbox/branches/1.7/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Mon Jul 16 18:24:53 2012
@@ -0,0 +1 @@
+/pdfbox/trunk:1342924,1343811,1346804,1346891,1346902,1349167,1350033,1350113,1351132,1356866,1358739-1358740,1359845,1361698,1361704,1361723,1361738

Modified: pdfbox/branches/1.7/doap_PDFBox.rdf
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/doap_PDFBox.rdf?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/doap_PDFBox.rdf (original)
+++ pdfbox/branches/1.7/doap_PDFBox.rdf Mon Jul 16 18:24:53 2012
@@ -37,6 +37,11 @@
     <release>
       <Version>
         <name>Apache PDFBox</name>
+        <created>2012-05-29</created>
+        <revision>1.7.0</revision>
+      </Version>
+      <Version>
+        <name>Apache PDFBox</name>
         <created>2011-07-02</created>
         <revision>1.6.0</revision>
       </Version>

Modified: pdfbox/branches/1.7/fontbox/src/main/java/org/apache/fontbox/encoding/Encoding.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/fontbox/src/main/java/org/apache/fontbox/encoding/Encoding.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/fontbox/src/main/java/org/apache/fontbox/encoding/Encoding.java (original)
+++ pdfbox/branches/1.7/fontbox/src/main/java/org/apache/fontbox/encoding/Encoding.java Mon Jul 16 18:24:53 2012
@@ -26,6 +26,9 @@ import java.util.Map;
  *
  * @author Ben Litchfield
  * @version $Revision: 1.1 $
+ * 
+ * @deprecated no longer needed by fontbox
+ * 
  */
 public abstract class Encoding
 {

Modified: pdfbox/branches/1.7/fontbox/src/main/java/org/apache/fontbox/encoding/MacRomanEncoding.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/fontbox/src/main/java/org/apache/fontbox/encoding/MacRomanEncoding.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/fontbox/src/main/java/org/apache/fontbox/encoding/MacRomanEncoding.java (original)
+++ pdfbox/branches/1.7/fontbox/src/main/java/org/apache/fontbox/encoding/MacRomanEncoding.java Mon Jul 16 18:24:53 2012
@@ -21,6 +21,8 @@ package org.apache.fontbox.encoding;
  *
  * @author Ben Litchfield
  * @version $Revision: 1.1 $
+ * 
+ * @deprecated no longer needed by fontbox
  */
 public class MacRomanEncoding extends Encoding
 {

Modified: pdfbox/branches/1.7/fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java (original)
+++ pdfbox/branches/1.7/fontbox/src/main/java/org/apache/fontbox/ttf/PostScriptTable.java Mon Jul 16 18:24:53 2012
@@ -18,8 +18,6 @@ package org.apache.fontbox.ttf;
 
 import java.io.IOException;
 
-import org.apache.fontbox.encoding.MacRomanEncoding;
-
 /**
  * A table in a true type font.
  * 
@@ -40,6 +38,57 @@ public class PostScriptTable extends TTF
     private String[] glyphNames = null;
     
     /**
+     * The 258 standard mac glyph names a used in 'post' format 1 and 2.
+     */
+    private static final int NUMBER_OF_MAC_GLYPHS = 258;
+    
+    private static final String[] MAC_GLYPH_NAMES = new String[] 
+    { 
+        ".notdef",".null", "nonmarkingreturn", "space", "exclam", "quotedbl",
+            "numbersign", "dollar", "percent", "ampersand", "quotesingle",
+            "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen",
+            "period", "slash", "zero", "one", "two", "three", "four", "five",
+            "six", "seven", "eight", "nine", "colon", "semicolon", "less",
+            "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F",
+            "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
+            "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash",
+            "bracketright", "asciicircum", "underscore", "grave", "a", "b",
+            "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
+            "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft",
+            "bar", "braceright", "asciitilde", "Adieresis", "Aring",
+            "Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis", "aacute",
+            "agrave", "acircumflex", "adieresis", "atilde", "aring",
+            "ccedilla", "eacute", "egrave", "ecircumflex", "edieresis",
+            "iacute", "igrave", "icircumflex", "idieresis", "ntilde", "oacute",
+            "ograve", "ocircumflex", "odieresis", "otilde", "uacute", "ugrave",
+            "ucircumflex", "udieresis", "dagger", "degree", "cent", "sterling",
+            "section", "bullet", "paragraph", "germandbls", "registered",
+            "copyright", "trademark", "acute", "dieresis", "notequal", "AE",
+            "Oslash", "infinity", "plusminus", "lessequal", "greaterequal",
+            "yen", "mu", "partialdiff", "summation", "product", "pi",
+            "integral", "ordfeminine", "ordmasculine", "Omega", "ae", "oslash",
+            "questiondown", "exclamdown", "logicalnot", "radical", "florin",
+            "approxequal", "Delta", "guillemotleft", "guillemotright",
+            "ellipsis", "nonbreakingspace", "Agrave", "Atilde", "Otilde", "OE",
+            "oe", "endash", "emdash", "quotedblleft", "quotedblright",
+            "quoteleft", "quoteright", "divide", "lozenge", "ydieresis",
+            "Ydieresis", "fraction", "currency", "guilsinglleft",
+            "guilsinglright", "fi", "fl", "daggerdbl", "periodcentered",
+            "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex",
+            "Ecircumflex", "Aacute", "Edieresis", "Egrave", "Iacute",
+            "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex",
+            "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", "dotlessi",
+            "circumflex", "tilde", "macron", "breve", "dotaccent", "ring",
+            "cedilla", "hungarumlaut", "ogonek", "caron", "Lslash", "lslash",
+            "Scaron", "scaron", "Zcaron", "zcaron", "brokenbar", "Eth", "eth",
+            "Yacute", "yacute", "Thorn", "thorn", "minus", "multiply",
+            "onesuperior", "twosuperior", "threesuperior", "onehalf",
+            "onequarter", "threequarters", "franc", "Gbreve", "gbreve",
+            "Idotaccent", "Scedilla", "scedilla", "Cacute", "cacute", "Ccaron",
+            "ccaron", "dcroat" 
+    };
+
+    /**
      * A tag that identifies this table type.
      */
     public static final String TAG = "post";
@@ -63,8 +112,6 @@ public class PostScriptTable extends TTF
         maxMemType42 = data.readUnsignedInt();
         mimMemType1 = data.readUnsignedInt();
         maxMemType1 = data.readUnsignedInt();
-        MacRomanEncoding encoding = new MacRomanEncoding();
-        
         
         if( formatType == 1.0f )
         {
@@ -72,15 +119,8 @@ public class PostScriptTable extends TTF
              * This TrueType font file contains exactly the 258 glyphs in the standard 
              * Macintosh TrueType.
              */
-            glyphNames = new String[258];
-            for( int i=0; i<glyphNames.length; i++)
-            {
-                String name = encoding.getName( i );
-                if( name != null )
-                {
-                    glyphNames[i] = name;
-                }
-            }
+            glyphNames = new String[NUMBER_OF_MAC_GLYPHS];
+            System.arraycopy(MAC_GLYPH_NAMES, 0, glyphNames, 0, NUMBER_OF_MAC_GLYPHS);
         }
         else if( formatType == 2.0f )
         {
@@ -94,15 +134,16 @@ public class PostScriptTable extends TTF
                 glyphNameIndex[i] = index;
                 // PDFBOX-808: Index numbers between 32768 and 65535 are
                 // reserved for future use, so we should just ignore them
-                if (index <= 32767) {
+                if (index <= 32767) 
+                {
                     maxIndex = Math.max( maxIndex, index );
                 }
             }
             String[] nameArray = null;
-            if( maxIndex >= 258 )
+            if( maxIndex >= NUMBER_OF_MAC_GLYPHS )
             {
-                nameArray = new String[ maxIndex-258 +1 ];
-                for( int i=0; i<maxIndex-258+1; i++ )
+                nameArray = new String[ maxIndex-NUMBER_OF_MAC_GLYPHS +1 ];
+                for( int i=0; i<maxIndex-NUMBER_OF_MAC_GLYPHS+1; i++ )
                 {
                     int numberOfChars = data.read();
                     nameArray[i]=data.readString( numberOfChars );
@@ -111,13 +152,13 @@ public class PostScriptTable extends TTF
             for( int i=0; i<numGlyphs; i++ )
             {
                 int index = glyphNameIndex[i];
-                if( index < 258 )
+                if( index < NUMBER_OF_MAC_GLYPHS )
                 {
-                    glyphNames[i] = encoding.getName( index );
+                    glyphNames[i] = MAC_GLYPH_NAMES[index];
                 }
-                else if( index >= 258 && index <= 32767 )
+                else if( index >= NUMBER_OF_MAC_GLYPHS && index <= 32767 )
                 {
-                    glyphNames[i] = nameArray[index-258];
+                    glyphNames[i] = nameArray[index-NUMBER_OF_MAC_GLYPHS];
                 }
                 else
                 {
@@ -138,7 +179,7 @@ public class PostScriptTable extends TTF
             glyphNames = new String[glyphNameIndex.length];
             for( int i=0; i<glyphNames.length; i++)
             {
-                String name = encoding.getName( glyphNameIndex[i] );
+                String name = MAC_GLYPH_NAMES[glyphNameIndex[i]];
                 if( name != null )
                 {
                     glyphNames[i] = name;

Modified: pdfbox/branches/1.7/jempbox/pom.xml
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/jempbox/pom.xml?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/jempbox/pom.xml (original)
+++ pdfbox/branches/1.7/jempbox/pom.xml Mon Jul 16 18:24:53 2012
@@ -49,16 +49,7 @@
       <plugin>
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
-        <version>2.0.0</version>
         <extensions>true</extensions>
-        <configuration>
-          <instructions>
-            <Export-Package>
-              org.apache.jempbox.xmp*;version=${project.version}
-            </Export-Package>
-            <Bundle-DocURL>${project.url}</Bundle-DocURL>
-          </instructions>
-        </configuration>
       </plugin>
     </plugins>
   </build>

Modified: pdfbox/branches/1.7/parent/pom.xml
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/parent/pom.xml?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/parent/pom.xml (original)
+++ pdfbox/branches/1.7/parent/pom.xml Mon Jul 16 18:24:53 2012
@@ -35,6 +35,11 @@
   <name>PDFBox parent</name>
   <inceptionYear>2002</inceptionYear>
 
+  <organization>
+    <name>The Apache Software Foundation</name>
+    <url>http://pdfbox.apache.org</url>
+  </organization>
+
   <issueManagement>
     <system>jira</system>
     <url>https://issues.apache.org/jira/browse/PDFBOX</url>
@@ -113,7 +118,7 @@
           <plugin>
             <groupId>org.apache.felix</groupId>
             <artifactId>maven-bundle-plugin</artifactId>
-            <version>2.3.4</version>
+            <version>2.3.7</version>
           </plugin>
       </plugins>
     </pluginManagement>

Modified: pdfbox/branches/1.7/pdfbox/pom.xml
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/pdfbox/pom.xml?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/pdfbox/pom.xml (original)
+++ pdfbox/branches/1.7/pdfbox/pom.xml Mon Jul 16 18:24:53 2012
@@ -130,9 +130,8 @@
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
         <extensions>true</extensions>
-        <configuration>
+          <configuration>
           <instructions>
-            <Bundle-DocURL>http://pdfbox.apache.org/</Bundle-DocURL>
             <Include-Resource>
               {maven-resources},
               META-INF=target/maven-shared-archive-resources/META-INF,

Modified: pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java (original)
+++ pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java Mon Jul 16 18:24:53 2012
@@ -577,7 +577,9 @@ public class COSDocument extends COSBase
             for( COSObject next : parser.getObjects() )
             {
                 COSObjectKey key = new COSObjectKey( next );
-                if(objectPool.get(key) == null || objectPool.get(key).getObject() == null)
+                if ( objectPool.get(key) == null || objectPool.get(key).getObject() == null ||
+                     // xrefTable stores negated objNr of objStream for objects in objStreams
+                     (xrefTable.containsKey( key ) && xrefTable.get( key ) == - objStream.getObjectNumber().longValue()) )  
                 {
                     COSObject obj = getObjectFromPool(key);
                     obj.setObject(next.getObject());

Modified: pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/encoding/MacRomanEncoding.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/encoding/MacRomanEncoding.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/encoding/MacRomanEncoding.java (original)
+++ pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/encoding/MacRomanEncoding.java Mon Jul 16 18:24:53 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.pdfbox.encoding;
 
+import java.io.IOException;
+
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
 
@@ -248,6 +250,19 @@ public class MacRomanEncoding extends En
         addCharacterEncoding( 0172, "z" );
         addCharacterEncoding( 060, "zero" );
     }
+    
+    public String getName( int code ) throws IOException
+  	{
+  		if (!codeToName.containsKey(code) && code == 0312) {
+  				/*
+  				 * The space character is also encoded as 0312 in MacRoman and 0240 in WinAnsi. 
+  				 * The meaning of this duplicate code is "nonbreaking space" but it is 
+  				 * typographically the same as space. 
+  				 */
+  				return "space";
+  		}
+  		return codeToName.get( code );
+  	}
 
     /**
      * Convert this standard java object to a COS object.

Modified: pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/encoding/WinAnsiEncoding.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/encoding/WinAnsiEncoding.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/encoding/WinAnsiEncoding.java (original)
+++ pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/encoding/WinAnsiEncoding.java Mon Jul 16 18:24:53 2012
@@ -263,13 +263,30 @@ public class WinAnsiEncoding extends Enc
 	public String getName( int code ) throws IOException
 	{
 		if (!codeToName.containsKey(code) && code > 040) {
-			/*
-			 * According to the PDFReference Appendix D :
-			 * In WinAnsiEncoding, all unused codes greater than 40 map to the bullet character. 
-			 * However, only code 0225 is specifically assigned to the bullet character;
-			 * other codes are subject to future reassignment
-			 */
-			return "bullet";
+			switch (code) {
+			case 0240:
+				/*
+				 * The space character is also encoded as 0312 in MacRoman and 0240 in WinAnsi. 
+				 * The meaning of this duplicate code is "nonbreaking space" but it is 
+				 * typographically the same as space. 
+				 */
+				return "space";
+			case 0255:
+				/*
+				 * The hyphen character is also encoded as 0255 in WinAnsi. 
+				 * The meaning of this duplicate code is "soft hyphen" but it is 
+				 * typographically the same as hyphen. 
+				 */
+				return "hyphen";
+			default:
+				/*
+				 * According to the PDFReference Appendix D :
+				 * In WinAnsiEncoding, all unused codes greater than 40 map to the bullet character. 
+				 * However, only code 0225 is specifically assigned to the bullet character;
+				 * other codes are subject to future reassignment
+				 */
+				return "bullet";
+			}
 		}
 		return codeToName.get( code );
 	}

Modified: pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/exceptions/WrappedException.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/exceptions/WrappedException.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/exceptions/WrappedException.java (original)
+++ pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/exceptions/WrappedException.java Mon Jul 16 18:24:53 2012
@@ -16,18 +16,17 @@
  */
 package org.apache.pdfbox.exceptions;
 
-import java.io.PrintStream;
 
 /**
  * An exception that that holds a sub exception.
  *
  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
  * @version $Revision: 1.2 $
+ * 
+ * @deprecated  java.lang.Exception itself has wrapper capabilities since Java 1.4
  */
 public class WrappedException extends Exception
 {
-    private Exception wrapped = null;
-
     /**
      * constructor comment.
      *
@@ -35,27 +34,6 @@ public class WrappedException extends Ex
      */
     public WrappedException( Exception e )
     {
-        wrapped = e;
-    }
-
-    /**
-     * Gets the wrapped exception message.
-     *
-     * @return A message indicating the exception.
-     */
-    public String getMessage()
-    {
-        return wrapped.getMessage();
-    }
-
-    /**
-     * Prints this throwable and its backtrace to the specified print stream.
-     *
-     * @param s <code>PrintStream</code> to use for output
-     */
-    public void printStackTrace(PrintStream s)
-    {
-        super.printStackTrace( s );
-        wrapped.printStackTrace( s );
+        super( e );
     }
 }

Modified: pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java (original)
+++ pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java Mon Jul 16 18:24:53 2012
@@ -17,29 +17,46 @@
 package org.apache.pdfbox.io;
 
 import java.io.IOException;
+import java.util.ArrayList;
 
 /**
- * An interface to allow PDF files to be stored completely in memory.
+ * An implementation of the RandomAccess interface to store a pdf in memory.
+ * The data will be stored in 16kb chunks organized in an ArrayList.  
  *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.2 $
  */
 public class RandomAccessBuffer implements RandomAccess
 {
-
-    private byte[] buffer;
+    // chunk size is 16kb
+    private static final int BUFFER_SIZE = 16384;
+    // list containing all chunks
+    private ArrayList<byte[]> bufferList = null;
+    // current chunk
+    private byte[] currentBuffer;
+    // current pointer to the whole buffer
     private long pointer;
+    // current pointer for the current chunk
+    private long currentBufferPointer;
+    // size of the whole buffer
     private long size;
+    // current chunk list index
+    private int bufferListIndex;
+    // maximum chunk list index
+    private int bufferListMaxIndex;
 
     /**
      * Default constructor.
      */
     public RandomAccessBuffer()
     {
-        // starting with a 16kb buffer
-        buffer = new byte[16384];
+        // starting with one chunk
+        bufferList = new ArrayList<byte[]>();
+        currentBuffer = new byte[BUFFER_SIZE];
+        bufferList.add(currentBuffer);
         pointer = 0;
+        currentBufferPointer = 0;
         size = 0;
+        bufferListIndex = 0;
+        bufferListMaxIndex = 0;
     }
 
     /**
@@ -47,9 +64,12 @@ public class RandomAccessBuffer implemen
      */
     public void close() throws IOException
     {
-        buffer = null;
+        currentBuffer = null;
+        bufferList.clear();
         pointer = 0;
+        currentBufferPointer = 0;
         size = 0;
+        bufferListIndex = 0;
     }
 
     /**
@@ -57,7 +77,11 @@ public class RandomAccessBuffer implemen
      */
     public void seek(long position) throws IOException
     {
-        this.pointer = position;
+        pointer = position;
+        // calculate the chunk list index
+        bufferListIndex = (int)(position / BUFFER_SIZE);
+        currentBufferPointer = position % BUFFER_SIZE;
+        currentBuffer = bufferList.get(bufferListIndex);
     }
 
     /**
@@ -69,7 +93,20 @@ public class RandomAccessBuffer implemen
         {
             return -1;
         }
-        return buffer[(int)pointer++] & 0xff;
+        if (currentBufferPointer >= BUFFER_SIZE)
+        {
+            if (bufferListIndex >= bufferListMaxIndex)
+            {
+                return -1;
+            }
+            else
+            {
+                currentBuffer = bufferList.get(++bufferListIndex);
+                currentBufferPointer = 0;
+            }
+        }
+        pointer++;
+        return currentBuffer[(int)currentBufferPointer++] & 0xff;
     }
 
     /**
@@ -82,7 +119,35 @@ public class RandomAccessBuffer implemen
             return 0;
         }
         int maxLength = (int) Math.min(length, this.size-pointer);
-        System.arraycopy(buffer, (int) pointer, b, offset, maxLength);
+        long remainingBytes = BUFFER_SIZE - currentBufferPointer;
+        if (maxLength >= remainingBytes)
+        {
+            // copy the first bytes from the current buffer
+            System.arraycopy(currentBuffer, (int)currentBufferPointer, b, offset, (int)remainingBytes);
+            int newOffset = offset + (int)remainingBytes;
+            long remainingBytes2Read = length - remainingBytes;
+            // determine how many buffers are needed to get the remaining amount bytes
+            int numberOfArrays = (int)remainingBytes2Read / BUFFER_SIZE;
+            for (int i=0;i<numberOfArrays;i++) 
+            {
+                nextBuffer();
+                System.arraycopy(currentBuffer, 0, b, newOffset, BUFFER_SIZE);
+                newOffset += BUFFER_SIZE;
+            }
+            remainingBytes2Read = remainingBytes2Read % BUFFER_SIZE;
+            // are there still some bytes to be read?
+            if (remainingBytes2Read > 0)
+            {
+                nextBuffer();
+                System.arraycopy(currentBuffer, 0, b, newOffset, (int)remainingBytes2Read);
+                currentBufferPointer += remainingBytes2Read;
+            }
+        }
+        else
+        {
+            System.arraycopy(currentBuffer, (int)currentBufferPointer, b, offset, maxLength);
+            currentBufferPointer += maxLength;
+        }
         pointer += maxLength;
         return maxLength;
     }
@@ -100,15 +165,16 @@ public class RandomAccessBuffer implemen
      */
     public void write(int b) throws IOException
     {
-        if (pointer >= buffer.length)
+        if (currentBufferPointer >= BUFFER_SIZE) 
         {
-            if (pointer >= Integer.MAX_VALUE) 
+            if (pointer + BUFFER_SIZE >= Integer.MAX_VALUE) 
             {
                 throw new IOException("RandomAccessBuffer overflow");
             }
-            buffer = expandBuffer(buffer, (int)Math.min(2L * buffer.length, Integer.MAX_VALUE));
+            expandBuffer();
         }
-        buffer[(int)pointer++] = (byte)b;
+        currentBuffer[(int)currentBufferPointer++] = (byte)b;
+        pointer++;
         if (pointer > this.size)
         {
             this.size = pointer;
@@ -120,17 +186,43 @@ public class RandomAccessBuffer implemen
      */
     public void write(byte[] b, int offset, int length) throws IOException
     {
-        long newSize = pointer+length;
-        if (newSize >= buffer.length)
+        long newSize = pointer + length;
+        long remainingBytes = BUFFER_SIZE - currentBufferPointer;
+        if (length >= remainingBytes)
         {
             if (newSize > Integer.MAX_VALUE) 
             {
                 throw new IOException("RandomAccessBuffer overflow");
             }
-            newSize = Math.min(Math.max(2L * buffer.length, newSize), Integer.MAX_VALUE);
-            buffer = expandBuffer(buffer, (int)newSize);
+            // copy the first bytes to the current buffer
+            System.arraycopy(b, offset, currentBuffer, (int)currentBufferPointer, (int)remainingBytes);
+            int newOffset = offset + (int)remainingBytes;
+            long remainingBytes2Write = length - remainingBytes;
+            // determine how many buffers are needed for the remaining bytes
+            int numberOfNewArrays = (int)remainingBytes2Write / BUFFER_SIZE;
+            for (int i=0;i<numberOfNewArrays;i++) 
+            {
+                expandBuffer();
+                System.arraycopy(b, newOffset, currentBuffer, (int)currentBufferPointer, BUFFER_SIZE);
+                newOffset += BUFFER_SIZE;
+            }
+            // are there still some bytes to be written?
+            remainingBytes2Write -= numberOfNewArrays * BUFFER_SIZE;
+            if (remainingBytes2Write >= 0)
+            {
+                expandBuffer();
+                if (remainingBytes2Write > 0)
+                {
+                    System.arraycopy(b, newOffset, currentBuffer, (int)currentBufferPointer, (int)remainingBytes2Write);
+                }
+                currentBufferPointer = remainingBytes2Write;
+            }
+        }
+        else
+        {
+            System.arraycopy(b, offset, currentBuffer, (int)currentBufferPointer, length);
+            currentBufferPointer += length;
         }
-        System.arraycopy(b, offset, buffer, (int)pointer, length);
         pointer += length;
         if (pointer > this.size)
         {
@@ -139,17 +231,32 @@ public class RandomAccessBuffer implemen
     }
 
     /**
-     * expand the given buffer to the new size.
-     * 
-     * @param buffer the given buffer
-     * @param newSize the new size
-     * @return the expanded buffer
-     * 
-     */
-    private byte[] expandBuffer(byte[] buffer, int newSize) 
-    {
-        byte[] expandedBuffer = new byte[newSize];
-        System.arraycopy(buffer, 0, expandedBuffer, 0, buffer.length);
-        return expandedBuffer;
+     * create a new buffer chunk and adjust all pointers and indices.
+     */
+    private void expandBuffer() 
+    {
+        if (bufferListMaxIndex > bufferListIndex)
+        {
+            // there is already an existing chunk
+            nextBuffer();
+        }
+        else
+        {
+            // create a new chunk and add it to the buffer
+            currentBuffer = new byte[BUFFER_SIZE];
+            bufferList.add(currentBuffer);
+            currentBufferPointer = 0;
+            bufferListMaxIndex++;
+            bufferListIndex++;
+        }
+    }
+
+    /**
+     * switch to the next buffer chunk and reset the buffer pointer.
+     */
+    private void nextBuffer() 
+    {
+        currentBufferPointer = 0;
+        currentBuffer = bufferList.get(++bufferListIndex);
     }
 }

Modified: pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java (original)
+++ pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java Mon Jul 16 18:24:53 2012
@@ -18,6 +18,7 @@ package org.apache.pdfbox.pdfparser;
 
 import java.io.BufferedInputStream;
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -39,6 +40,7 @@ import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.cos.COSString;
+import org.apache.pdfbox.exceptions.WrappedIOException;
 
 import org.apache.pdfbox.persistence.util.COSObjectKey;
 
@@ -52,6 +54,9 @@ import org.apache.pdfbox.persistence.uti
 public abstract class BaseParser
 {
 
+    /** system property allowing to define size of push back buffer */
+    public static final String PROP_PUSHBACK_SIZE = "org.apache.pdfbox.baseParser.pushBackSize";
+
     /**
      * Log instance.
      */
@@ -157,7 +162,7 @@ public abstract class BaseParser
             throws IOException
     {
         this.pdfSource = new PushBackInputStream(
-                new BufferedInputStream(input, 16384),  4096);
+                new BufferedInputStream(input, 16384),  Integer.getInteger( PROP_PUSHBACK_SIZE, 65536 ) );
         this.forceParsing = forceParsingValue;
     }
 
@@ -487,6 +492,68 @@ public abstract class BaseParser
                     out.write( strmBuf, 0, readCount );
                     left -= readCount;
                 }
+                
+                // in order to handle broken documents we test if 'endstream' is reached
+                // if not, length value possibly was wrong, fall back to scanning for endstream
+                
+                // fill buffer with next bytes and test for 'endstream' (with leading whitespaces)
+                int readCount = pdfSource.read( strmBuf, 0, 20 );
+                if ( readCount > 0 )
+                {
+                    boolean foundEndstream    = false;
+                    int     nextEndstreamCIdx = 0;
+                    for ( int cIdx = 0; cIdx < readCount; cIdx++ )
+                    {
+                        final int ch = strmBuf[ cIdx ] & 0xff; 
+                        if ( ch == ENDSTREAM[ nextEndstreamCIdx ] )
+                        {
+                            if ( ++nextEndstreamCIdx >= ENDSTREAM.length )
+                            {
+                                foundEndstream = true;
+                                break;
+                            }
+                        }
+                        else if ( ( nextEndstreamCIdx > 0 ) || ( ! isWhitespace( ch ) ) )
+                        {
+                            // not found
+                            break;
+                        }
+                    }
+                    
+                    // push back test bytes
+                    pdfSource.unread( strmBuf, 0, readCount );
+                    
+                    // if 'endstream' was not found fall back to scanning
+                    if ( ! foundEndstream )
+                    {
+                        LOG.warn( "Specified stream length " + length + " is wrong. Fall back to reading stream until 'endstream'." );
+                        
+                        // push back all read stream bytes
+                        out.flush();    // we got a buffered stream wrapper around filteredStream thus first flush to underlying stream
+                        InputStream writtenStreamBytes = stream.getFilteredStream();
+                        ByteArrayOutputStream     bout = new ByteArrayOutputStream( length );
+                        
+                        while ( ( readCount = writtenStreamBytes.read( strmBuf ) ) >= 0 )
+                        {
+                            bout.write( strmBuf, 0, readCount );
+                        }
+                        try
+                        {
+                            pdfSource.unread( bout.toByteArray() );
+                        }
+                        catch ( IOException ioe )
+                        {
+                            throw new WrappedIOException( "Could not push back " + bout.size() + 
+                                                          " bytes in order to reparse stream. " +
+                                                          "Try increasing push back buffer using system property " +
+                                                          PROP_PUSHBACK_SIZE, ioe );
+                        }
+                        // create new filtered stream
+                        out = stream.createFilteredStream( streamLength );
+                        // scan until we find endstream:
+                        readUntilEndStream( out );
+                    }
+                }
             }
             
             skipSpaces();

Modified: pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java (original)
+++ pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java Mon Jul 16 18:24:53 2012
@@ -480,6 +480,11 @@ public abstract class PDFont implements 
     protected String cmapEncoding( int code, int length, boolean isCIDFont, CMap sourceCmap ) throws IOException
     {
         String retval = null;
+        // there is not sourceCmap if this is a descendant font
+        if (sourceCmap == null)
+        {
+            sourceCmap = cmap;
+        }
         if (sourceCmap != null)
         {
             retval = sourceCmap.lookup(code, length);

Modified: pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java (original)
+++ pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java Mon Jul 16 18:24:53 2012
@@ -451,7 +451,7 @@ public abstract class PDSimpleFont exten
             {
                 try 
                 {
-                    toUnicodeCmap = parseCmap(null, ((COSStream)toUnicode).getUnfilteredStream());
+                    toUnicodeCmap = parseCmap( resourceRootCMAP, ((COSStream)toUnicode).getUnfilteredStream());
                 }
                 catch(IOException exception) 
                 {

Modified: pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java (original)
+++ pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java Mon Jul 16 18:24:53 2012
@@ -16,6 +16,20 @@
  */
 package org.apache.pdfbox.pdmodel.font;
 
+import java.awt.Font;
+import java.awt.FontFormatException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.fontbox.ttf.CMAPEncodingEntry;
@@ -25,35 +39,21 @@ import org.apache.fontbox.ttf.GlyphTable
 import org.apache.fontbox.ttf.HeaderTable;
 import org.apache.fontbox.ttf.HorizontalHeaderTable;
 import org.apache.fontbox.ttf.HorizontalMetricsTable;
-import org.apache.fontbox.ttf.NamingTable;
 import org.apache.fontbox.ttf.NameRecord;
+import org.apache.fontbox.ttf.NamingTable;
 import org.apache.fontbox.ttf.OS2WindowsMetricsTable;
 import org.apache.fontbox.ttf.PostScriptTable;
 import org.apache.fontbox.ttf.TTFParser;
 import org.apache.fontbox.ttf.TrueTypeFont;
-
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.encoding.Encoding;
+import org.apache.pdfbox.encoding.WinAnsiEncoding;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.common.PDStream;
-import org.apache.pdfbox.encoding.WinAnsiEncoding;
 import org.apache.pdfbox.util.ResourceLoader;
 
-import java.awt.Font;
-import java.awt.FontFormatException;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
 /**
  * This is the TrueType implementation of fonts.
  *
@@ -152,15 +152,47 @@ public class PDTrueTypeFont extends PDSi
      */
     public static PDTrueTypeFont loadTTF( PDDocument doc, InputStream stream ) throws IOException
     { 
-        PDTrueTypeFont retval = new PDTrueTypeFont();
-        PDFontDescriptorDictionary fd = new PDFontDescriptorDictionary();
-        retval.setFontDescriptor( fd );
+        return PDTrueTypeFont.loadTTF(doc,stream,new WinAnsiEncoding());
+    }
+
+    /**
+     * This will load a TTF to be embedded into a document.
+     *
+     * @param doc The PDF document that will hold the embedded font.
+     * @param stream a ttf input stream.
+     * @param enc The font encoding.
+     * @return a PDTrueTypeFont instance.
+     * @throws IOException If there is an error loading the data.
+     */
+    public static PDTrueTypeFont loadTTF( PDDocument doc, InputStream stream, Encoding enc ) throws IOException
+    { 
         PDStream fontStream = new PDStream(doc, stream, false );
         fontStream.getStream().setInt( COSName.LENGTH1, fontStream.getByteArray().length );
         fontStream.addCompression();
+        //only support winansi encoding right now, should really
+        //just use Identity-H with unicode mapping
+        return PDTrueTypeFont.loadTTF(fontStream,enc);
+    }
+
+    /**
+     * This will load a TTF to be embedded into a document.
+     *
+     * @param fontStream a ttf input stream.
+     * @param enc The font encoding.
+     * @return a PDTrueTypeFont instance.
+     * @throws IOException If there is an error loading the data.
+     */
+    public static PDTrueTypeFont loadTTF( PDStream fontStream, Encoding enc ) throws IOException
+    { 
+        PDTrueTypeFont retval = new PDTrueTypeFont();
+        retval.setFontEncoding( enc );
+        retval.setEncoding(enc.getCOSObject());
+
+        PDFontDescriptorDictionary fd = new PDFontDescriptorDictionary();
+        retval.setFontDescriptor( fd );
         fd.setFontFile2( fontStream );
         // As the stream was close within the PDStream constructor, we have to recreate it
-        stream = fontStream.createInputStream();
+        InputStream stream = fontStream.createInputStream();
         try
         {
             retval.loadDescriptorDictionary(fd, stream); 
@@ -169,10 +201,6 @@ public class PDTrueTypeFont extends PDSi
         {
             stream.close();
         }
-        //only support winansi encoding right now, should really
-        //just use Identity-H with unicode mapping
-        retval.setFontEncoding( new WinAnsiEncoding() );
-        retval.setEncoding(COSName.WIN_ANSI_ENCODING);
         return retval;
     }
 
@@ -285,15 +313,15 @@ public class PDTrueTypeFont extends PDSi
             HeaderTable header = ttf.getHeader();
             PDRectangle rect = new PDRectangle();
             float scaling = 1000f/header.getUnitsPerEm();
-            rect.setLowerLeftX( header.getXMin() * 1000f/header.getUnitsPerEm() );
-            rect.setLowerLeftY( header.getYMin() * 1000f/header.getUnitsPerEm() );
-            rect.setUpperRightX( header.getXMax() * 1000f/header.getUnitsPerEm() );
-            rect.setUpperRightY( header.getYMax() * 1000f/header.getUnitsPerEm() );
+            rect.setLowerLeftX( header.getXMin() * scaling );
+            rect.setLowerLeftY( header.getYMin() * scaling );
+            rect.setUpperRightX( header.getXMax() * scaling );
+            rect.setUpperRightY( header.getYMax() * scaling );
             fd.setFontBoundingBox( rect );
 
             HorizontalHeaderTable hHeader = ttf.getHorizontalHeader();
-            fd.setAscent( hHeader.getAscender() * 1000f/header.getUnitsPerEm() );
-            fd.setDescent( hHeader.getDescender() * 1000f/header.getUnitsPerEm() );
+            fd.setAscent( hHeader.getAscender() * scaling );
+            fd.setDescent( hHeader.getDescender() * scaling );
 
             GlyphTable glyphTable = ttf.getGlyph();
             GlyphData[] glyphs = glyphTable.getGlyphs();
@@ -303,20 +331,20 @@ public class PDTrueTypeFont extends PDSi
             fd.setItalicAngle( ps.getItalicAngle() );
 
             String[] names = ps.getGlyphNames();
+            
             if( names != null )
             {
                 for( int i=0; i<names.length; i++ )
                 {
-                    //if we have a capital H then use that, otherwise use the
+                     //if we have a capital H then use that, otherwise use the
                     //tallest letter
                     if( names[i].equals( "H" ) )
                     {
-                        fd.setCapHeight( (glyphs[i].getBoundingBox().getUpperRightY()* 1000f)/
-                                         header.getUnitsPerEm() );
+                        fd.setCapHeight( glyphs[i].getBoundingBox().getUpperRightY()/scaling );
                     }
                     if( names[i].equals( "x" ) )
                     {
-                        fd.setXHeight( (glyphs[i].getBoundingBox().getUpperRightY()* 1000f)/header.getUnitsPerEm() );
+                        fd.setXHeight( glyphs[i].getBoundingBox().getUpperRightY()/scaling );
                     }
                 }
             }
@@ -325,44 +353,62 @@ public class PDTrueTypeFont extends PDSi
             //this is close enough and I am told it doesn't usually get used.
             fd.setStemV( (fd.getFontBoundingBox().getWidth() * .13f) );
 
-
             CMAPTable cmapTable = ttf.getCMAP();
             CMAPEncodingEntry[] cmaps = cmapTable.getCmaps();
-            int[] glyphToCCode = null;
+            CMAPEncodingEntry uniMap = null;
+            
             for( int i=0; i<cmaps.length; i++ )
             {
                 if( cmaps[i].getPlatformId() == CMAPTable.PLATFORM_WINDOWS) 
                 {
                     int platformEncoding = cmaps[i].getPlatformEncodingId();
-                    if ( (isSymbolic && CMAPTable.ENCODING_SYMBOL == platformEncoding)
-                            ||CMAPTable.ENCODING_UNICODE == platformEncoding )
+                    if ( CMAPTable.ENCODING_UNICODE == platformEncoding )
                     {
-                        glyphToCCode = cmaps[i].getGlyphIdToCharacterCode();
+                        uniMap = cmaps[i];
                         break;
                     }
                 }
             }
-            int firstChar = os2.getFirstCharIndex();
-            int maxWidths = glyphToCCode.length;
+
+            Map<Integer, String> codeToName = this.getFontEncoding().getCodeToNameMap();
+             
+            int firstChar = Collections.min(codeToName.keySet());
+            int lastChar = Collections.max(codeToName.keySet());
+            
             HorizontalMetricsTable hMet = ttf.getHorizontalMetrics();
             int[] widthValues = hMet.getAdvanceWidth();
-            List<Float> widths = new ArrayList<Float>(maxWidths);
-            float zero = 250;
-            for( int i=0; i<maxWidths; i++ )
+            int nWidths=lastChar-firstChar+1;
+            List<Float> widths = new ArrayList<Float>(nWidths);
+            // width of the .notdef character.
+            Float zero = Float.valueOf(widthValues[0]*scaling);
+            for( int i=0; i<nWidths; i++ )
             {
                 widths.add( zero );
             }
-            for( int i=0; i<maxWidths; i++ )
-            {
-                if(glyphToCCode[i]-firstChar < widths.size() && glyphToCCode[i]-firstChar >= 0 
-                        && widths.get( glyphToCCode[i]-firstChar) == zero )
+            // Encoding singleton to have acces to the chglyph name to
+            // unicode cpoint point mapping of Adobe's glyphlist.txt
+            Encoding glyphlist = WinAnsiEncoding.INSTANCE;
+
+            // A character code is mapped to a glyph name via the provided
+            // font encoding. Afterwards, the glyph name is translated to a
+            // glyph ID.
+            // For details, see PDFReference16.pdf, Section 5.5.5, p.401
+            //
+            for (Entry<Integer, String> e : codeToName.entrySet()) 
+            {
+                String name = e.getValue();
+                // pdf code to unicode by glyph list.
+                String c = glyphlist.getCharacter(name);
+                int charCode = c.codePointAt(0);
+                int gid = uniMap.getGlyphId(charCode);
+                if (gid != 0) 
                 {
-                    widths.set( glyphToCCode[i]-firstChar, widthValues[i]*scaling );
+                    widths.set( e.getKey().intValue()-firstChar,widthValues[gid]*scaling );
                 }
             }
             setWidths( widths );
-            setFirstChar( isSymbolic ? 0 : firstChar );
-            setLastChar( isSymbolic ? widths.size() : firstChar + widths.size()-1 );
+            setFirstChar( firstChar );
+            setLastChar( lastChar );
         }
         finally
         {

Modified: pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java (original)
+++ pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java Mon Jul 16 18:24:53 2012
@@ -27,7 +27,7 @@ import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 
 /**
- * This is implementation of the Type0 Font. 
+ * This is implementation of the Type0 Font.
  * See <a href="https://issues.apache.org/jira/browse/PDFBOX-605">PDFBOX-605</a>
  * for the related improvement issue.
  *
@@ -66,7 +66,7 @@ public class PDType0Font extends PDSimpl
         descendantFontDictionary = (COSDictionary)getDescendantFonts().getObject( 0 );
         if (descendantFontDictionary != null)
         {
-            try 
+            try
             {
                 descendantFont = PDFontFactory.createFont( descendantFontDictionary );
             }
@@ -84,11 +84,15 @@ public class PDType0Font extends PDSimpl
     {
         if (awtFont == null)
         {
-            if (descendantFont != null) 
+            if (descendantFont != null)
             {
                 awtFont = ((PDSimpleFont)descendantFont).getawtFont();
             }
-            if (awtFont == null)
+            if (awtFont != null)
+            {
+                setIsFontSubstituted(((PDSimpleFont)descendantFont).isFontSubstituted());
+            }
+            else
             {
                 awtFont = FontManager.getStandardFont();
                 LOG.info("Using font "+awtFont.getName()
@@ -98,7 +102,7 @@ public class PDType0Font extends PDSimpl
         }
         return awtFont;
     }
-    
+
     /**
      * This will get the fonts bounding box.
      *
@@ -154,7 +158,7 @@ public class PDType0Font extends PDSimpl
     {
         return descendantFont.getAverageFontWidth();
     }
- 
+
     private COSArray getDescendantFonts()
     {
         if (descendantFontArray == null)
@@ -163,11 +167,11 @@ public class PDType0Font extends PDSimpl
         }
         return descendantFontArray;
     }
-    
+
     /**
      * {@inheritDoc}
      */
-    public float getFontWidth( int charCode ) 
+    public float getFontWidth( int charCode )
     {
         return descendantFont.getFontWidth(charCode);
     }
@@ -180,25 +184,25 @@ public class PDType0Font extends PDSimpl
         {
             retval = super.encode(c, offset, length);
         }
-        
+
         if (retval == null)
         {
             int result = cmap.lookupCID(c, offset, length);
-            if (result != -1) 
+            if (result != -1)
             {
-                retval = descendantFont.cmapEncoding(result, 2, true, cmap);
+                retval = descendantFont.cmapEncoding(result, 2, true, null);
             }
         }
         return retval;
     }
 
     /**
-     * 
+     *
      * Provides the descendant font.
      * @return the descendant font.
-     * 
+     *
      */
-    protected PDFont getDescendantFont() 
+    protected PDFont getDescendantFont()
     {
         return descendantFont;
     }

Modified: pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java (original)
+++ pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java Mon Jul 16 18:24:53 2012
@@ -156,7 +156,7 @@ public class PDFMergerUtility
      */
     public void addSources(List<InputStream> sourcesList)
     {
-        this.sources.addAll(sources);
+        this.sources.addAll(sourcesList);
     }
 
     /**

Modified: pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/util/PDFOperator.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/util/PDFOperator.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/util/PDFOperator.java (original)
+++ pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/util/PDFOperator.java Mon Jul 16 18:24:53 2012
@@ -16,9 +16,7 @@
  */
 package org.apache.pdfbox.util;
 
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * This class represents an Operator in the content stream.
@@ -32,7 +30,8 @@ public class PDFOperator
     private byte[] imageData;
     private ImageParameters imageParameters;
 
-    private static Map operators = Collections.synchronizedMap( new HashMap() );
+    /** map for singleton operator objects; use {@link ConcurrentHashMap} for better scalability with multiple threads */
+    private final static ConcurrentHashMap<String,PDFOperator> operators = new ConcurrentHashMap<String, PDFOperator>();
 
     /**
      * Constructor.
@@ -65,11 +64,16 @@ public class PDFOperator
         }
         else
         {
-            operation = (PDFOperator)operators.get( operator );
+            operation = operators.get( operator );
             if( operation == null )
             {
-                operation = new PDFOperator( operator );
-                operators.put( operator, operation );
+                // another thread may has already added an operator of this kind
+                // make sure that we get the same operator
+                operation = operators.putIfAbsent( operator, new PDFOperator( operator ) );
+                if ( operation == null )
+                {
+                    operation = operators.get( operator );
+                }
             }
         }
 

Modified: pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java (original)
+++ pdfbox/branches/1.7/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java Mon Jul 16 18:24:53 2012
@@ -598,6 +598,11 @@ public class PDFStreamEngine
      */
     public Map<String,PDFont> getFonts()
     {
+        if ( streamResourcesStack.isEmpty() )
+        {
+            return Collections.emptyMap();
+        }
+        
         return streamResourcesStack.peek().getFonts();
     }
     /**

Modified: pdfbox/branches/1.7/pdfbox/src/test/java/org/apache/pdfbox/TestAll.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/pdfbox/src/test/java/org/apache/pdfbox/TestAll.java?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/pdfbox/src/test/java/org/apache/pdfbox/TestAll.java (original)
+++ pdfbox/branches/1.7/pdfbox/src/test/java/org/apache/pdfbox/TestAll.java Mon Jul 16 18:24:53 2012
@@ -25,6 +25,7 @@ import org.apache.pdfbox.cos.TestCOSInte
 import org.apache.pdfbox.cos.TestCOSString;
 import org.apache.pdfbox.filter.TestFilters;
 import org.apache.pdfbox.io.TestIOUtils;
+import org.apache.pdfbox.io.TestRandomAccessBuffer;
 import org.apache.pdfbox.io.ccitt.TestCCITTFaxG31DDecodeInputStream;
 import org.apache.pdfbox.io.ccitt.TestPackedBitArray;
 import org.apache.pdfbox.pdmodel.TestFDF;
@@ -89,6 +90,7 @@ public class TestAll extends TestCase
         suite.addTest( org.apache.pdfbox.pdmodel.common.function.TestFunctions.suite() );
 
         suite.addTestSuite( TestIOUtils.class );
+        suite.addTestSuite( TestRandomAccessBuffer.class );
         suite.addTestSuite( TestImageIOUtils.class );
         suite.addTestSuite( TestPackedBitArray.class );
         suite.addTestSuite( TestCCITTFaxG31DDecodeInputStream.class );

Modified: pdfbox/branches/1.7/preflight/pom.xml
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/preflight/pom.xml?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/preflight/pom.xml (original)
+++ pdfbox/branches/1.7/preflight/pom.xml Mon Jul 16 18:24:53 2012
@@ -25,7 +25,7 @@
   <name>Apache Preflight</name>
   <description>
       The Apache Preflight library is an open source Java tool that implements 
-      a parser compliant with the ISO-19005 specification. Preflight is a 
+      a parser compliant with the ISO-19005 (PDF/A) specification. Preflight is a 
       subproject of Apache PDFBox.
   </description>
 
@@ -90,11 +90,13 @@
       <plugin>
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
-        <version>2.0.0</version>
         <extensions>true</extensions>
         <configuration>
           <instructions>
+	    <!--
             <Export-Package>org.apache.padaf.preflight.javacc|org.apache.padaf.preflight.javacc.*</Export-Package>
+            TODO The above seems wrong, but the default should probably be refined.
+            -->
           </instructions>
         </configuration>
       </plugin>

Modified: pdfbox/branches/1.7/xmpbox/pom.xml
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.7/xmpbox/pom.xml?rev=1362175&r1=1362174&r2=1362175&view=diff
==============================================================================
--- pdfbox/branches/1.7/xmpbox/pom.xml (original)
+++ pdfbox/branches/1.7/xmpbox/pom.xml Mon Jul 16 18:24:53 2012
@@ -68,7 +68,7 @@
     <dependency>
     	<groupId>org.apache.pdfbox</groupId>
     	<artifactId>pdfbox</artifactId>
-    	<version>${project.Version}</version>
+    	<version>${project.version}</version>
     	<type>bundle</type>
     	<scope>compile</scope>
     </dependency>
@@ -79,7 +79,6 @@
       <plugin>
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
-        <version>2.0.0</version>
         <extensions>true</extensions>
       </plugin>
     </plugins>