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 2013/05/27 18:58:08 UTC

svn commit: r1486661 - in /pdfbox/branches/1.8: ./ pdfbox/src/main/java/org/apache/pdfbox/ pdfbox/src/main/java/org/apache/pdfbox/cos/ pdfbox/src/main/java/org/apache/pdfbox/pdfparser/ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ pdfbox/src/main/jav...

Author: lehmi
Date: Mon May 27 16:58:07 2013
New Revision: 1486661

URL: http://svn.apache.org/r1486661
Log:
merged the following changes from trunk

PDFBOX-1293 rev. 1480030
PDFBOX-1561 rev. 1469558
PDFBOX-1565 rev. 1467638
PDFBOX-1580 rev. 1477806,1478472
PDFBOX-1581 rev. 1486413
PDFBOX-1583 rev. 1476795
PDFBOX-1586 rev. 1479136,1479287
PDFBOX-1592 rev. 1480000
PDFBOX-1599 rev. 1485781,1486337
PDFBOX-1601 rev. 1484089
PDFBOX-1602 rev. 1484277
PDFBOX-1603 rev. 1485771
PDFBOX-1605 rev. 1484547
PDFBOX-1611 rev. 1486423
PDFBOX-1612 rev. 1486440


Added:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/ColorSpaceLab.java
      - copied unchanged from r1467638, pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/ColorSpaceLab.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingLabColor.java
      - copied unchanged from r1467638, pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingLabColor.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingLabColor.java
      - copied unchanged from r1467638, pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingLabColor.java
    pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocument.java
      - copied unchanged from r1486413, pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocument.java
Modified:
    pdfbox/branches/1.8/   (props changed)
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/Overlay.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSStreamArray.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDObjectStream.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDRectangle.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDIndexed.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDLab.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceDictionary.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuildDataDict.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearance.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/LayerUtility.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFImageWriter.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/Invoke.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColor.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingColor.java
    pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/TestAll.java

Propchange: pdfbox/branches/1.8/
------------------------------------------------------------------------------
  Merged /pdfbox/trunk:r1467638,1476795,1477806,1478472,1479136,1479287,1480000,1480030,1484089,1484277,1484547,1485771,1485781,1486337,1486413,1486423,1486440

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/Overlay.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/Overlay.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/Overlay.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/Overlay.java Mon May 27 16:58:07 2013
@@ -224,12 +224,12 @@ public class Overlay
         collectLayoutPages( overlayCatalog.getAllPages() );
 
         COSDictionary saveGraphicsStateDic = new COSDictionary();
-        saveGraphicsStateStream = new COSStream( saveGraphicsStateDic, pdfDocument.getDocument().getScratchFile() );
+        saveGraphicsStateStream = pdfDocument.getDocument().createCOSStream(saveGraphicsStateDic);
         OutputStream saveStream = saveGraphicsStateStream.createUnfilteredStream();
         saveStream.write( " q\n".getBytes("ISO-8859-1") );
         saveStream.flush();
 
-        restoreGraphicsStateStream = new COSStream( saveGraphicsStateDic, pdfDocument.getDocument().getScratchFile() );
+        restoreGraphicsStateStream = pdfDocument.getDocument().createCOSStream(saveGraphicsStateDic);
         OutputStream restoreStream = restoreGraphicsStateStream.createUnfilteredStream();
         restoreStream.write( " Q\n".getBytes("ISO-8859-1") );
         restoreStream.flush();
@@ -353,7 +353,7 @@ public class Overlay
 
         COSDictionary streamDict = new COSDictionary();
         streamDict.setInt(COSName.LENGTH, baos.size());
-        COSStream output = new COSStream(streamDict, pdfDocument.getDocument().getScratchFile());
+        COSStream output = pdfDocument.getDocument().createCOSStream(streamDict);
         output.setFilters(stream.getFilters());
         OutputStream os = output.createUnfilteredStream();
         baos.writeTo(os);

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java Mon May 27 16:58:07 2013
@@ -71,11 +71,6 @@ public class COSDocument extends COSBase
     private COSDictionary trailer;
     
     /**
-     * Document signature dictionary.
-     */
-    private COSDictionary signDictionary = null;
-    
-    /**
      * Signature interface.
      */
     private SignatureInterface signatureInterface;
@@ -178,10 +173,43 @@ public class COSDocument extends COSBase
      * This will get the scratch file for this document.
      *
      * @return The scratch file.
+     * 
+     * 
      */
     public RandomAccess getScratchFile()
     {
-        return scratchFile;
+        // TODO the direct access to the scratch file should be removed.
+        if (!closed)
+        {
+            return scratchFile;
+        }
+        else
+        {
+            LOG.error("Can't access the scratch file as it is already closed!");
+            return null;
+        }
+    }
+
+    /**
+     * Create a new COSStream using the underlying scratch file.
+     * 
+     * @return the new COSStream
+     */
+    public COSStream createCOSStream()
+    {
+        return new COSStream( getScratchFile() );
+    }
+
+    /**
+     * Create a new COSStream using the underlying scratch file.
+     *
+     * @param dictionary the corresponding dictionary
+     * 
+     * @return the new COSStream
+     */
+    public COSStream createCOSStream(COSDictionary dictionary)
+    {
+        return new COSStream( dictionary, getScratchFile() );
     }
 
     /**

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java Mon May 27 16:58:07 2013
@@ -351,6 +351,10 @@ public final class COSName extends COSBa
     /**
      * A common COSName value.
      */
+    public static final COSName DEFAULT = new COSName( "default" );
+    /**
+     * A common COSName value.
+     */
     public static final COSName D = new COSName( "D" );
     /**
      * A common COSName value.
@@ -600,6 +604,10 @@ public final class COSName extends COSBa
     /**
     * A common COSName value.
     */
+    public static final COSName FIRST = new COSName( "First" );
+    /**
+    * A common COSName value.
+    */
     public static final COSName FIRST_CHAR = new COSName( "FirstChar" );
     /**
      * A common COSName value.

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java Mon May 27 16:58:07 2013
@@ -26,7 +26,7 @@ import org.apache.pdfbox.persistence.uti
 
 /**
  * This represents a string object in a PDF document.
- *
+ * 
  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
  * @version $Revision: 1.30 $
  */
@@ -35,52 +35,50 @@ public class COSString extends COSBase
     /**
      * One of the open string tokens.
      */
-    public static final byte[] STRING_OPEN = new byte[]{ 40 }; //"(".getBytes();
+    public static final byte[] STRING_OPEN = new byte[] { 40 }; // "(".getBytes();
     /**
      * One of the close string tokens.
      */
-    public static final byte[] STRING_CLOSE = new byte[]{ 41 }; //")".getBytes( "ISO-8859-1" );
+    public static final byte[] STRING_CLOSE = new byte[] { 41 }; // ")".getBytes( "ISO-8859-1" );
     /**
      * One of the open string tokens.
      */
-    public static final byte[] HEX_STRING_OPEN = new byte[]{ 60 }; //"<".getBytes( "ISO-8859-1" );
+    public static final byte[] HEX_STRING_OPEN = new byte[] { 60 }; // "<".getBytes( "ISO-8859-1" );
     /**
      * One of the close string tokens.
      */
-    public static final byte[] HEX_STRING_CLOSE = new byte[]{ 62 }; //">".getBytes( "ISO-8859-1" );
+    public static final byte[] HEX_STRING_CLOSE = new byte[] { 62 }; // ">".getBytes( "ISO-8859-1" );
     /**
      * the escape character in strings.
      */
-    public static final byte[] ESCAPE = new byte[]{ 92 }; //"\\".getBytes( "ISO-8859-1" );
+    public static final byte[] ESCAPE = new byte[] { 92 }; // "\\".getBytes( "ISO-8859-1" );
 
     /**
      * CR escape characters.
      */
-    public static final byte[] CR_ESCAPE = new byte[]{ 92, 114 }; //"\\r".getBytes( "ISO-8859-1" );
+    public static final byte[] CR_ESCAPE = new byte[] { 92, 114 }; // "\\r".getBytes( "ISO-8859-1" );
     /**
      * LF escape characters.
      */
-    public static final byte[] LF_ESCAPE = new byte[]{ 92, 110 }; //"\\n".getBytes( "ISO-8859-1" );
+    public static final byte[] LF_ESCAPE = new byte[] { 92, 110 }; // "\\n".getBytes( "ISO-8859-1" );
     /**
      * HT escape characters.
      */
-    public static final byte[] HT_ESCAPE = new byte[]{ 92, 116 }; //"\\t".getBytes( "ISO-8859-1" );
+    public static final byte[] HT_ESCAPE = new byte[] { 92, 116 }; // "\\t".getBytes( "ISO-8859-1" );
     /**
      * BS escape characters.
      */
-    public static final byte[] BS_ESCAPE = new byte[]{ 92, 98 }; //"\\b".getBytes( "ISO-8859-1" );
+    public static final byte[] BS_ESCAPE = new byte[] { 92, 98 }; // "\\b".getBytes( "ISO-8859-1" );
     /**
      * FF escape characters.
      */
-    public static final byte[] FF_ESCAPE = new byte[]{ 92, 102 }; //"\\f".getBytes( "ISO-8859-1" );
-
+    public static final byte[] FF_ESCAPE = new byte[] { 92, 102 }; // "\\f".getBytes( "ISO-8859-1" );
 
     private ByteArrayOutputStream out = null;
     private String str = null;
 
     /**
-     * Forces the string to be serialized in hex form but not literal form, the default is to stream
-     * in literal form.
+     * Forces the string to be serialized in hex form but not literal form, the default is to stream in literal form.
      */
     private boolean forceHexForm = false;
 
@@ -94,78 +92,86 @@ public class COSString extends COSBase
         out = new ByteArrayOutputStream();
     }
 
-    public COSString (boolean isDictionary) {
+    /** 
+     * Constructor.
+     * 
+     * @param isDictionaryValue determines if this string represents a dictionary
+     */
+    public COSString(boolean isDictionaryValue)
+    {
         this();
-        this.isDictionary = isDictionary;
+        isDictionary = isDictionaryValue;
     }
 
-
     /**
      * Explicit constructor for ease of manual PDF construction.
-     *
-     * @param value The string value of the object.
+     * 
+     * @param value
+     *            The string value of the object.
      */
-    public COSString( String value )
+    public COSString(String value)
     {
         try
         {
             boolean unicode16 = false;
             char[] chars = value.toCharArray();
             int length = chars.length;
-            for( int i=0; i<length; i++ )
+            for (int i = 0; i < length; i++)
             {
-                if( chars[i] > 255 )
+                if (chars[i] > 255)
                 {
                     unicode16 = true;
                     break;
                 }
             }
-            if( unicode16 )
+            if (unicode16)
             {
-                byte[] data = value.getBytes( "UTF-16BE" );
-                out = new ByteArrayOutputStream( data.length +2);
-                out.write( 0xFE );
-                out.write( 0xFF );
-                out.write( data );
+                byte[] data = value.getBytes("UTF-16BE");
+                out = new ByteArrayOutputStream(data.length + 2);
+                out.write(0xFE);
+                out.write(0xFF);
+                out.write(data);
             }
             else
             {
                 byte[] data = value.getBytes("ISO-8859-1");
-                out = new ByteArrayOutputStream( data.length );
-                out.write( data );
+                out = new ByteArrayOutputStream(data.length);
+                out.write(data);
             }
         }
         catch (IOException ignore)
         {
             ignore.printStackTrace();
-            //should never happen
+            // should never happen
         }
     }
 
     /**
      * Explicit constructor for ease of manual PDF construction.
-     *
-     * @param value The string value of the object.
+     * 
+     * @param value
+     *            The string value of the object.
      */
-    public COSString( byte[] value )
+    public COSString(byte[] value)
     {
         try
         {
-            out = new ByteArrayOutputStream( value.length );
-            out.write( value );
+            out = new ByteArrayOutputStream(value.length);
+            out.write(value);
         }
         catch (IOException ignore)
         {
             ignore.printStackTrace();
-            //should never happen
+            // should never happen
         }
     }
 
     /**
      * Forces the string to be written in literal form instead of hexadecimal form.
-     *
-     * @param v if v is true the string will be written in literal form, otherwise it will
-     * be written in hexa if necessary.
+     * 
+     * @param v
+     *            if v is true the string will be written in literal form, otherwise it will be written in hexa if
+     *            necessary.
      */
 
     public void setForceLiteralForm(boolean v)
@@ -176,8 +182,9 @@ public class COSString extends COSBase
     /**
      * Forces the string to be written in hexadecimal form instead of literal form.
      * 
-     * @param v if v is true the string will be written in hexadecimal form otherwise it will be written in literal if
-     *          necessary.
+     * @param v
+     *            if v is true the string will be written in hexadecimal form otherwise it will be written in literal if
+     *            necessary.
      */
 
     public void setForceHexForm(boolean v)
@@ -187,45 +194,54 @@ public class COSString extends COSBase
 
     /**
      * This will create a COS string from a string of hex characters.
-     *
-     * @param hex A hex string.
+     * 
+     * @param hex
+     *            A hex string.
      * @return A cos string with the hex characters converted to their actual bytes.
-     * @throws IOException If there is an error with the hex string.
+     * @throws IOException
+     *             If there is an error with the hex string.
      */
-    public static COSString createFromHexString(String hex)
-            throws IOException {
+    public static COSString createFromHexString(String hex) throws IOException
+    {
         return createFromHexString(hex, false);
     }
 
     /**
-     * Creates a COS string from a string of hex characters, optionally
-     * ignoring malformed input.
-     *
-     * @param hex A hex string.
-     * @param force flag to ignore malformed input
+     * Creates a COS string from a string of hex characters, optionally ignoring malformed input.
+     * 
+     * @param hex
+     *            A hex string.
+     * @param force
+     *            flag to ignore malformed input
      * @return A cos string with the hex characters converted to their actual bytes.
-     * @throws IOException If there is an error with the hex string.
+     * @throws IOException
+     *             If there is an error with the hex string.
      */
-    public static COSString createFromHexString(String hex, boolean force)
-            throws IOException {
+    public static COSString createFromHexString(String hex, boolean force) throws IOException
+    {
         COSString retval = new COSString();
-        StringBuilder hexBuffer = new StringBuilder( hex.trim() );
-        //if odd number then the last hex digit is assumed to be 0
-        if( hexBuffer.length() % 2 != 0 )
-        {
-            hexBuffer.append( '0' );
-        }
-        int length = hexBuffer.length(); 
-        for (int i = 0; i < length; i += 2) {
-            try {
-                retval.append(
-                        Integer.parseInt(hexBuffer.substring(i, i + 2), 16));
-            } catch (NumberFormatException e) {
-                if (force) {
+        StringBuilder hexBuffer = new StringBuilder(hex.trim());
+        // if odd number then the last hex digit is assumed to be 0
+        if (hexBuffer.length() % 2 != 0)
+        {
+            hexBuffer.append('0');
+        }
+        int length = hexBuffer.length();
+        for (int i = 0; i < length; i += 2)
+        {
+            try
+            {
+                retval.append(Integer.parseInt(hexBuffer.substring(i, i + 2), 16));
+            }
+            catch (NumberFormatException e)
+            {
+                if (force)
+                {
                     retval.append('?');
-                } else {
-                    IOException exception =
-                            new IOException("Invalid hex string: " + hex);
+                }
+                else
+                {
+                    IOException exception = new IOException("Invalid hex string: " + hex);
                     exception.initCause(e);
                     throw exception;
                 }
@@ -236,17 +252,17 @@ public class COSString extends COSBase
 
     /**
      * This will take this string and create a hex representation of the bytes that make the string.
-     *
+     * 
      * @return A hex string representing the bytes in this string.
      */
     public String getHexString()
     {
-        StringBuilder retval = new StringBuilder( out.size() * 2 );
+        StringBuilder retval = new StringBuilder(out.size() * 2);
         byte[] data = getBytes();
         int length = data.length;
-        for( int i=0; i<length; i++ )
+        for (int i = 0; i < length; i++)
         {
-            retval.append( COSHEXTable.HEX_TABLE[ (data[i]+256)%256 ] );
+            retval.append(COSHEXTable.HEX_TABLE[(data[i] + 256) % 256]);
         }
 
         return retval.toString();
@@ -254,7 +270,7 @@ public class COSString extends COSBase
 
     /**
      * This will get the string that this object wraps.
-     *
+     * 
      * @return The wrapped string.
      */
     public String getString()
@@ -267,38 +283,46 @@ public class COSString extends COSBase
         String encoding = "ISO-8859-1";
         byte[] data = getBytes();
         int start = 0;
-        if( data.length > 2 )
+        if (data.length > 2)
         {
-            if( data[0] == (byte)0xFF && data[1] == (byte)0xFE )
+            if (data[0] == (byte) 0xFF && data[1] == (byte) 0xFE)
             {
                 encoding = "UTF-16LE";
-                start=2;
+                start = 2;
             }
-            else if( data[0] == (byte)0xFE && data[1] == (byte)0xFF )
+            else if (data[0] == (byte) 0xFE && data[1] == (byte) 0xFF)
             {
                 encoding = "UTF-16BE";
-                start=2;
+                start = 2;
             }
         }
         try
         {
-            if (isDictionary && encoding.equals("ISO-8859-1")) {
-                byte [] tmp = getBytes();
+            if (isDictionary && encoding.equals("ISO-8859-1"))
+            {
+                byte[] tmp = getBytes();
                 PdfDocEncoding pde = new PdfDocEncoding();
                 StringBuilder sb = new StringBuilder(tmp.length);
-                for (byte b : tmp) {
-                    sb.append(pde.getCharacter((b+256)%256));
+                for (byte b : tmp)
+                {
+                    final String character = pde.getCharacter((b + 256) % 256);
+                    if (character != null)
+                    {
+                        sb.append(character);
+                    }
                 }
                 retval = sb.toString();
-            } else {
-                retval = new String( getBytes(), start, data.length-start, encoding );
+            }
+            else
+            {
+                retval = new String(getBytes(), start, data.length - start, encoding);
             }
         }
-        catch( IOException e )
+        catch (IOException e)
         {
-            //should never happen
+            // should never happen
             e.printStackTrace();
-            retval = new String( getBytes() );
+            retval = new String(getBytes());
         }
         this.str = retval;
         return retval;
@@ -306,27 +330,31 @@ public class COSString extends COSBase
 
     /**
      * This will append a byte[] to the string.
-     *
-     * @param data The byte[] to add to this string.
-     *
-     * @throws IOException If an IO error occurs while writing the byte.
+     * 
+     * @param data
+     *            The byte[] to add to this string.
+     * 
+     * @throws IOException
+     *             If an IO error occurs while writing the byte.
      */
-    public void append( byte[] data ) throws IOException
+    public void append(byte[] data) throws IOException
     {
-        out.write( data );
+        out.write(data);
         this.str = null;
     }
 
     /**
      * This will append a byte to the string.
-     *
-     * @param in The byte to add to this string.
-     *
-     * @throws IOException If an IO error occurs while writing the byte.
+     * 
+     * @param in
+     *            The byte to add to this string.
+     * 
+     * @throws IOException
+     *             If an IO error occurs while writing the byte.
      */
-    public void append( int in ) throws IOException
+    public void append(int in) throws IOException
     {
-        out.write( in );
+        out.write(in);
         this.str = null;
     }
 
@@ -341,7 +369,7 @@ public class COSString extends COSBase
 
     /**
      * This will get the bytes of the string.
-     *
+     * 
      * @return A byte array that represents the string.
      */
     public byte[] getBytes()
@@ -360,66 +388,68 @@ public class COSString extends COSBase
 
     /**
      * This will output this string as a PDF object.
-     *
-     * @param output The stream to write to.
-     * @throws IOException If there is an error writing to the stream.
+     * 
+     * @param output
+     *            The stream to write to.
+     * @throws IOException
+     *             If there is an error writing to the stream.
      */
-    public void writePDF( OutputStream output ) throws IOException
+    public void writePDF(OutputStream output) throws IOException
     {
         boolean outsideASCII = false;
-        //Lets first check if we need to escape this string.
+        // Lets first check if we need to escape this string.
         byte[] bytes = getBytes();
-        int length = bytes.length; 
-        for( int i=0; i<length && !outsideASCII; i++ )
+        int length = bytes.length;
+        for (int i = 0; i < length && !outsideASCII; i++)
         {
-            //if the byte is negative then it is an eight bit byte and is
-            //outside the ASCII range.
-            outsideASCII = bytes[i] <0;
+            // if the byte is negative then it is an eight bit byte and is
+            // outside the ASCII range.
+            outsideASCII = bytes[i] < 0;
         }
         if (!outsideASCII && !forceHexForm)
         {
             output.write(STRING_OPEN);
-            for( int i=0; i<length; i++ )
+            for (int i = 0; i < length; i++)
             {
-                int b = (bytes[i]+256)%256;
-                switch( b )
+                int b = (bytes[i] + 256) % 256;
+                switch (b)
                 {
                 case '(':
                 case ')':
                 case '\\':
                 {
                     output.write(ESCAPE);
-                    output.write((byte)b);
+                    output.write((byte) b);
                     break;
                 }
-                case 10: //LF
+                case 10: // LF
                 {
-                    output.write( LF_ESCAPE );
+                    output.write(LF_ESCAPE);
                     break;
                 }
                 case 13: // CR
                 {
-                    output.write( CR_ESCAPE );
+                    output.write(CR_ESCAPE);
                     break;
                 }
                 case '\t':
                 {
-                    output.write( HT_ESCAPE );
+                    output.write(HT_ESCAPE);
                     break;
                 }
                 case '\b':
                 {
-                    output.write( BS_ESCAPE );
+                    output.write(BS_ESCAPE);
                     break;
                 }
                 case '\f':
                 {
-                    output.write( FF_ESCAPE );
+                    output.write(FF_ESCAPE);
                     break;
                 }
                 default:
                 {
-                    output.write( (byte)b );
+                    output.write((byte) b);
                 }
                 }
             }
@@ -428,27 +458,27 @@ public class COSString extends COSBase
         else
         {
             output.write(HEX_STRING_OPEN);
-            for(int i=0; i<length; i++ )
+            for (int i = 0; i < length; i++)
             {
-                output.write( COSHEXTable.TABLE[ (bytes[i]+256)%256 ] );
+                output.write(COSHEXTable.TABLE[(bytes[i] + 256) % 256]);
             }
             output.write(HEX_STRING_CLOSE);
         }
     }
 
-
-
     /**
      * visitor pattern double dispatch method.
-     *
-     * @param visitor The object to notify when visiting this object.
+     * 
+     * @param visitor
+     *            The object to notify when visiting this object.
      * @return any object, depending on the visitor implementation, or null
-     * @throws COSVisitorException If an error occurs while visiting this object.
+     * @throws COSVisitorException
+     *             If an error occurs while visiting this object.
      */
     @Override
     public Object accept(ICOSVisitor visitor) throws COSVisitorException
     {
-        return visitor.visitFromString( this );
+        return visitor.visitFromString(this);
     }
 
     /**
@@ -460,8 +490,7 @@ public class COSString extends COSBase
         if (obj instanceof COSString)
         {
             COSString strObj = (COSString) obj;
-            return this.getString().equals(strObj.getString()) 
-                    && this.forceHexForm == strObj.forceHexForm;
+            return this.getString().equals(strObj.getString()) && this.forceHexForm == strObj.forceHexForm;
         }
         return false;
     }
@@ -473,6 +502,6 @@ public class COSString extends COSBase
     public int hashCode()
     {
         int result = getString().hashCode();
-        return result += forceHexForm ? 17 : 0; 
+        return result += forceHexForm ? 17 : 0;
     }
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java Mon May 27 16:58:07 2013
@@ -91,16 +91,28 @@ public class NonSequentialPDFParser exte
     private static final InputStream EMPTY_INPUT_STREAM = new ByteArrayInputStream(new byte[0]);
 
     protected static final int DEFAULT_TRAIL_BYTECOUNT = 2048;
+    /**
+     * EOF-marker.
+     */
     protected static final char[] EOF_MARKER = new char[]
     { '%', '%', 'E', 'O', 'F' };
+    /**
+     * StartXRef-marker.
+     */
     protected static final char[] STARTXREF_MARKER = new char[]
     { 's', 't', 'a', 'r', 't', 'x', 'r', 'e', 'f' };
+    /**
+     * obj-marker.
+     */
     protected static final char[] OBJ_MARKER = new char[]
     { 'o', 'b', 'j' };
 
     private final File pdfFile;
     private final RandomAccessBufferedFileInputStream raStream;
 
+    /**
+     * The security handler.
+     */
     protected SecurityHandler securityHandler = null;
 
     private String keyStoreFilename = null;
@@ -219,12 +231,31 @@ public class NonSequentialPDFParser exte
         password = decryptionPassword;
     }
 
+    /**
+     * Constructor.
+     * 
+     * @param input input stream representing the pdf.
+     * @throws IOException If something went wrong.
+     */
     public NonSequentialPDFParser(InputStream input) throws IOException
     {
+        this(input, null, "");
+    }
+
+    /**
+     * Constructor.
+     * 
+     * @param input input stream representing the pdf.
+     * @param raBuf the buffer to be used for parsing
+     * @param decryptionPassword password to be used for decryption.
+     * @throws IOException If something went wrong.
+     */
+    public NonSequentialPDFParser(InputStream input, RandomAccess raBuf, String decryptionPassword) throws IOException
+    {
         super(EMPTY_INPUT_STREAM, null, false);
         pdfFile = createTmpFile(input);
         raStream = new RandomAccessBufferedFileInputStream(pdfFile);
-        init(pdfFile, null, "");
+        init(pdfFile, raBuf, decryptionPassword);
     }
 
     /**
@@ -234,7 +265,7 @@ public class NonSequentialPDFParser exte
      * 
      * @param input
      * @return
-     * @throws IOException
+     * @throws IOException If something went wrong.
      */
     private File createTmpFile(InputStream input) throws IOException
     {
@@ -287,7 +318,7 @@ public class NonSequentialPDFParser exte
      * can handle linearized pdfs, which will have an xref at the end pointing
      * to an xref at the beginning of the file. Last the root object is parsed.
      * 
-     * @throws IOException
+     * @throws IOException If something went wrong.
      */
     protected void initialParse() throws IOException
     {
@@ -340,7 +371,7 @@ public class NonSequentialPDFParser exte
             if (trailerEntry instanceof COSObject)
             {
                 COSObject tmpObj = (COSObject) trailerEntry;
-                parseObjectDynamically(tmpObj, true);
+                parseObjectDynamically(tmpObj, false);
             }
         }
         // ---- prepare encryption if necessary
@@ -442,7 +473,12 @@ public class NonSequentialPDFParser exte
         return pdfSource.getOffset();
     }
 
-    /** Sets {@link #pdfSource} to start next parsing at given file offset. */
+    /**
+     * Sets {@link #pdfSource} to start next parsing at given file offset.
+     * 
+     * @param fileOffset file offset
+     * @throws IOException If something went wrong.
+     */
     protected final void setPdfSource(long fileOffset) throws IOException
     {
 
@@ -458,7 +494,10 @@ public class NonSequentialPDFParser exte
         // pdfSource.skip( _fileOffset );
     }
 
-    /** Enable handling of alternative pdfSource implementation. */
+    /**
+     * Enable handling of alternative pdfSource implementation.
+     * @throws IOException If something went wrong.
+     */
     protected final void releasePdfSourceInputStream() throws IOException
     {
         // if ( pdfSource != null )
@@ -479,6 +518,9 @@ public class NonSequentialPDFParser exte
      * (within last {@link #DEFAULT_TRAIL_BYTECOUNT} bytes (or range set via
      * {@link #setEOFLookupRange(int)}) and go back to find
      * <code>startxref</code>.
+     * 
+     * @return the offset of StartXref 
+     * @throws IOException If something went wrong.
      */
     protected final long getStartxrefOffset() throws IOException
     {
@@ -590,6 +632,7 @@ public class NonSequentialPDFParser exte
      * Reads given pattern from {@link #pdfSource}. Skipping whitespace at start
      * and end.
      * 
+     * @param pattern pattern to be skipped
      * @throws IOException if pattern could not be read
      */
     protected final void readPattern(final char[] pattern) throws IOException
@@ -688,6 +731,7 @@ public class NonSequentialPDFParser exte
                 try
                 {
                     document.close();
+                    document = null;
                 }
                 catch (IOException ioe)
                 {
@@ -696,6 +740,11 @@ public class NonSequentialPDFParser exte
         }
     }
 
+    /**
+     * Return the pdf file.
+     * 
+     * @return the pdf file
+     */
     protected File getPdfFile()
     {
         return this.pdfFile;
@@ -712,7 +761,9 @@ public class NonSequentialPDFParser exte
             try
             {
                 if (!pdfFile.delete())
+                {
                     LOG.warn("Temporary file '" + pdfFile.getName() + "' can't be deleted");
+                }
             }
             catch (SecurityException e)
             {
@@ -749,7 +800,9 @@ public class NonSequentialPDFParser exte
     {
         PDDocument pdDocument = super.getPDDocument();
         if (securityHandler != null)
+        {
             pdDocument.setSecurityHandler(securityHandler);
+        }
         return pdDocument;
     }
 
@@ -1170,7 +1223,8 @@ public class NonSequentialPDFParser exte
                         // this is not legal
                         // the combination of a dict and the stream/endstream
                         // forms a complete stream object
-                        throw new IOException("Stream not preceded by dictionary (offset: " + offsetOrObjstmObNr + ").");
+                        throw new IOException("Stream not preceded by dictionary (offset: " 
+                        + offsetOrObjstmObNr + ").");
                     }
                     skipSpaces();
                     endObjectKey = readLine();
@@ -1270,7 +1324,14 @@ public class NonSequentialPDFParser exte
     }
 
     // ------------------------------------------------------------------------
-    /** Decrypts given COSString. */
+    /**
+     * Decrypts given COSString.
+     * 
+     * @param str the string to be decrypted
+     * @param objNr the object number
+     * @param objGenNr the object generation number
+     * @throws IOException ff something went wrong
+     */
     protected final void decrypt(COSString str, long objNr, long objGenNr) throws IOException
     {
         try
@@ -1438,7 +1499,10 @@ public class NonSequentialPDFParser exte
             int bytesRead = 0;
             boolean unexpectedEndOfStream = false;
             if (remainBytes == 35090)
+            {
+                // TODO debug system out, to be removed??
                 System.out.println();
+            }
             while (remainBytes > 0)
             {
                 final int readBytes = pdfSource.read(streamCopyBuf, 0,

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java Mon May 27 16:58:07 2013
@@ -234,6 +234,7 @@ public class PDFParser extends BaseParse
             if( document != null )
             {
                 document.close();
+                document = null;
             }
             if( t instanceof IOException )
             {

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Mon May 27 16:58:07 2013
@@ -420,7 +420,7 @@ public class PDDocument implements Pagea
             acroFormDict.setItem(COSName.DR, null);
             // Set empty Appearance-Dictionary
             PDAppearanceDictionary ap = new PDAppearanceDictionary();
-            COSStream apsStream = new COSStream(getDocument().getScratchFile());
+            COSStream apsStream = getDocument().createCOSStream();
             apsStream.createUnfilteredStream();
             PDAppearanceStream aps = new PDAppearanceStream(apsStream);
             COSDictionary cosObject = (COSDictionary)aps.getCOSObject();
@@ -441,6 +441,11 @@ public class PDDocument implements Pagea
 
             for ( COSObject cosObject : cosObjects )
             {
+                if (!annotNotFound && !sigFieldNotFound)
+                {
+                    break;
+                }
+                
                 COSBase base = cosObject.getObject();
                 if (base != null && base instanceof COSDictionary)
                 {
@@ -639,7 +644,7 @@ public class PDDocument implements Pagea
             PDStream src = page.getContents();
             if(src != null)
             {
-                PDStream dest = new PDStream( new COSStream( src.getStream(), document.getScratchFile() ) );
+                PDStream dest = new PDStream( document.createCOSStream());
                 importedPage.setContents( dest );
                 os = dest.createOutputStream();
 
@@ -1242,7 +1247,40 @@ public class PDDocument implements Pagea
     }
 
     /**
-     * This will save this document to the filesystem.
+     * Parses PDF with non sequential parser.
+     *  
+     * @param input stream that contains the document.
+     * @param scratchFile location to store temp PDFBox data for this document
+     *
+     * @return loaded document
+     *
+     * @throws IOException  in case of a file reading or parsing error
+     */
+    public static PDDocument loadNonSeq( InputStream input, RandomAccess scratchFile) throws IOException
+    {
+        return loadNonSeq(input, scratchFile, "");
+    }
+
+    /**
+     * Parses PDF with non sequential parser.
+     *  
+     * @param input stream that contains the document.
+     * @param scratchFile location to store temp PDFBox data for this document
+     * @param password password to be used for decryption
+     *
+     * @return loaded document
+     *
+     * @throws IOException  in case of a file reading or parsing error
+     */
+    public static PDDocument loadNonSeq( InputStream input, RandomAccess scratchFile, String password ) throws IOException
+    {
+        NonSequentialPDFParser parser = new NonSequentialPDFParser( input, scratchFile, password );
+        parser.parse();
+        return parser.getPDDocument();
+    }
+
+    /**
+     * Save the document to a file.
      *
      * @param fileName The file to save as.
      *
@@ -1251,7 +1289,20 @@ public class PDDocument implements Pagea
      */
     public void save( String fileName ) throws IOException, COSVisitorException
     {
-        save( new FileOutputStream( fileName ) );
+        save( new File( fileName ) );
+    }
+
+    /**
+     * Save the document to a file.
+     *
+     * @param file The file to save as.
+     *
+     * @throws IOException If there is an error saving the document.
+     * @throws COSVisitorException If an error occurs while generating the data.
+     */
+    public void save( File file ) throws IOException, COSVisitorException
+    {
+        save( new FileOutputStream( file ) );
     }
 
     /**

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSStreamArray.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSStreamArray.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSStreamArray.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSStreamArray.java Mon May 27 16:58:07 2013
@@ -94,6 +94,7 @@ public class COSStreamArray extends COSS
      * This will get the scratch file associated with this stream.
      *
      * @return The scratch file where this stream is being stored.
+     * 
      */
     public RandomAccess getScratchFile()
     {

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDObjectStream.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDObjectStream.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDObjectStream.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDObjectStream.java Mon May 27 16:58:07 2013
@@ -51,9 +51,9 @@ public class PDObjectStream extends PDSt
      */
     public static PDObjectStream createStream( PDDocument document )
     {
-        COSStream cosStream = new COSStream( document.getDocument().getScratchFile() );
+        COSStream cosStream = document.getDocument().createCOSStream();
         PDObjectStream strm = new PDObjectStream( cosStream );
-        strm.getStream().setName( "Type", "ObjStm" );
+        strm.getStream().setName( COSName.TYPE, "ObjStm" );
         return strm;
     }
 
@@ -64,7 +64,7 @@ public class PDObjectStream extends PDSt
      */
     public String getType()
     {
-        return getStream().getNameAsString( "Type" );
+        return getStream().getNameAsString( COSName.TYPE );
     }
 
     /**
@@ -74,7 +74,7 @@ public class PDObjectStream extends PDSt
      */
     public int getNumberOfObjects()
     {
-        return getStream().getInt( "N", 0 );
+        return getStream().getInt( COSName.N, 0 );
     }
 
     /**
@@ -84,7 +84,7 @@ public class PDObjectStream extends PDSt
      */
     public void setNumberOfObjects( int n )
     {
-        getStream().setInt( "N", n );
+        getStream().setInt( COSName.N, n );
     }
 
     /**
@@ -94,7 +94,7 @@ public class PDObjectStream extends PDSt
      */
     public int getFirstByteOffset()
     {
-        return getStream().getInt( "First", 0 );
+        return getStream().getInt( COSName.FIRST, 0 );
     }
 
     /**
@@ -104,7 +104,7 @@ public class PDObjectStream extends PDSt
      */
     public void setFirstByteOffset( int n )
     {
-        getStream().setInt( "First", n );
+        getStream().setInt( COSName.FIRST, n );
     }
 
     /**

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDRectangle.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDRectangle.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDRectangle.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDRectangle.java Mon May 27 16:58:07 2013
@@ -67,7 +67,7 @@ public class PDRectangle implements COSO
     /**
      * Constructor.
      *
-     * @param box The non PD bouding box.
+     * @param box the bounding box to be used for the rectangle
      */
     public PDRectangle( BoundingBox box )
     {
@@ -85,7 +85,13 @@ public class PDRectangle implements COSO
      */
     public PDRectangle( COSArray array )
     {
-        rectArray = array;
+        float[] values = array.toFloatArray();
+        rectArray = new COSArray();
+        // we have to start with the lower left corner
+        rectArray.add( new COSFloat( Math.min(values[0],values[2] )) );
+        rectArray.add( new COSFloat( Math.min(values[1],values[3] )) );
+        rectArray.add( new COSFloat( Math.max(values[0],values[2] )) );
+        rectArray.add( new COSFloat( Math.max(values[1],values[3] )) );
     }
 
     /**

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java Mon May 27 16:58:07 2013
@@ -67,7 +67,7 @@ public class PDStream implements COSObje
      */
     public PDStream(PDDocument document)
     {
-        stream = new COSStream(document.getDocument().getScratchFile());
+        stream = document.getDocument().createCOSStream();
     }
 
     /**
@@ -116,7 +116,7 @@ public class PDStream implements COSObje
         OutputStream output = null;
         try
         {
-            stream = new COSStream(doc.getDocument().getScratchFile());
+            stream = doc.getDocument().createCOSStream();
             if (filtered)
             {
                 output = stream.createFilteredStream();

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java Mon May 27 16:58:07 2013
@@ -87,12 +87,17 @@ public class PDType0Font extends PDSimpl
             if (descendantFont != null)
             {
                 awtFont = ((PDSimpleFont)descendantFont).getawtFont();
+                if (awtFont != null)
+                {
+                    setIsFontSubstituted(((PDSimpleFont)descendantFont).isFontSubstituted());
+                    /*
+                     * Fix Oracle JVM Crashes.
+                     * Tested with Oracle JRE 6.0_45-b06 and 7.0_21-b11
+                     */
+                    awtFont.canDisplay(1);
+                }
             }
-            if (awtFont != null)
-            {
-                setIsFontSubstituted(((PDSimpleFont)descendantFont).isFontSubstituted());
-            }
-            else
+            if (awtFont == null)
             {
                 awtFont = FontManager.getStandardFont();
                 LOG.info("Using font "+awtFont.getName()

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java Mon May 27 16:58:07 2013
@@ -347,7 +347,8 @@ public class PDType1Font extends PDSimpl
                                     String name = st.nextToken();
                                     if(encoding == null)
                                     {
-                                        log.warn("Unable to get character encoding. Encoding defintion found without /Encoding line.");
+                                        log.warn("Unable to get character encoding. " +
+                                                "Encoding definition found without /Encoding line.");
                                     }
                                     else
                                     {
@@ -369,23 +370,60 @@ public class PDType1Font extends PDSimpl
                         // attached to PDFBOX-935
                         if (line.startsWith("/FontMatrix"))
                         {
-                            String matrixValues = line.substring(line.indexOf("[")+1,line.lastIndexOf("]"));
-                            StringTokenizer st = new StringTokenizer(matrixValues);
-                            COSArray array = new COSArray();
-                            if (st.countTokens() >= 6)
+                            // most likely all matrix values are in the same line than the keyword
+                            if (line.indexOf("[") > -1)
                             {
-                                try 
+                                String matrixValues = line.substring(line.indexOf("[")+1,line.lastIndexOf("]"));
+                                StringTokenizer st = new StringTokenizer(matrixValues);
+                                COSArray array = new COSArray();
+                                if (st.countTokens() >= 6)
                                 {
-                                    for (int i=0;i<6;i++)
+                                    try 
                                     {
-                                        COSFloat floatValue = new COSFloat(Float.parseFloat(st.nextToken()));
+                                        for (int i=0;i<6;i++)
+                                        {
+                                            COSFloat floatValue = new COSFloat(Float.parseFloat(st.nextToken()));
+                                            array.add(floatValue);
+                                        }
+                                    }
+                                    catch (NumberFormatException exception)
+                                    {
+                                        log.error("Can't read the fontmatrix from embedded font file!");
+                                    }
+                                    fontMatrix = new PDMatrix(array);
+                                }
+                            }
+                            else
+                            {
+                                // there are fonts where all values are on a separate line, see PDFBOX-1611
+                                COSArray array = new COSArray();
+                                while((line = in.readLine()) != null)
+                                {
+                                    if (line.startsWith("["))
+                                    {
+                                        continue;
+                                    }
+                                    if (line.endsWith("]"))
+                                    {
+                                        break;
+                                    }
+                                    try
+                                    {
+                                        COSFloat floatValue = new COSFloat(Float.parseFloat(line));
                                         array.add(floatValue);
                                     }
+                                    catch (NumberFormatException exception)
+                                    {
+                                        log.error("Can't read the fontmatrix from embedded font file!");
+                                    }
+                                }
+                                if (array.size() == 6)
+                                {
                                     fontMatrix = new PDMatrix(array);
                                 }
-                                catch (NumberFormatException exception)
+                                else
                                 {
-                                    log.error("Can't read the fontmatrix from embedded font file!");
+                                    log.error("Can't read the fontmatrix from embedded font file, not enough values!");
                                 }
                             }
                         }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDIndexed.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDIndexed.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDIndexed.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDIndexed.java Mon May 27 16:58:07 2013
@@ -317,6 +317,10 @@ public class PDIndexed extends PDColorSp
         if (baseColorModel == null)
         {
             baseColorModel = getBaseColorSpace().createColorModel(bpc);
+            if( baseColorModel.getTransferType() != DataBuffer.TYPE_BYTE )
+            {
+                throw new IOException( "Not implemented" );
+            }
         }
         return baseColorModel;
     }
@@ -333,10 +337,10 @@ public class PDIndexed extends PDColorSp
             // and sometimes there are fewer indexed value than possible
             maxIndex = Math.min(numberOfColorValues-1, highValue);
             byte[] index = getLookupData();
-            if( baseColorModel.getTransferType() != DataBuffer.TYPE_BYTE )
-            {
-                throw new IOException( "Not implemented" );
-            }
+            // despite all definitions there may be less values within the lookup data
+            int numberOfColorValuesFromIndex = (index.length / baseColorModel.getNumComponents())-1;
+            maxIndex = Math.min(maxIndex, numberOfColorValuesFromIndex);
+            // does the colorspace have an alpha channel?
             boolean hasAlpha = baseColorModel.hasAlpha();
             indexNumOfComponents = 3 + ( hasAlpha ? 1 : 0);
             int buffersize = (maxIndex+1) * indexNumOfComponents;
@@ -346,6 +350,7 @@ public class PDIndexed extends PDColorSp
             for( int i = 0; i <= maxIndex; i++ )
             {
                 System.arraycopy(index, i * inData.length, inData, 0, inData.length);
+                // calculate RGB values
                 indexedColorValues[bufferIndex] = (byte)colorModel.getRed(inData);
                 indexedColorValues[bufferIndex+1] = (byte)colorModel.getGreen(inData);
                 indexedColorValues[bufferIndex+2] = (byte)colorModel.getBlue(inData);

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDLab.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDLab.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDLab.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDLab.java Mon May 27 16:58:07 2013
@@ -24,8 +24,11 @@ import org.apache.pdfbox.cos.COSName;
 
 import org.apache.pdfbox.pdmodel.common.PDRange;
 
+import java.awt.Transparency;
 import java.awt.color.ColorSpace;
 import java.awt.image.ColorModel;
+import java.awt.image.ComponentColorModel;
+import java.awt.image.DataBuffer;
 
 import java.io.IOException;
 
@@ -96,7 +99,7 @@ public class PDLab extends PDColorSpace
      */
     protected ColorSpace createColorSpace() throws IOException
     {
-        throw new IOException( "Not implemented" );
+        return new ColorSpaceLab(getWhitepoint(), getBlackPoint(), getARange(), getBRange());
     }
 
     /**
@@ -110,7 +113,13 @@ public class PDLab extends PDColorSpace
      */
     public ColorModel createColorModel( int bpc ) throws IOException
     {
-        throw new IOException( "Not implemented" );
+        int[] nBits = {bpc, bpc, bpc};
+        return new ComponentColorModel( getJavaColorSpace(),
+                   nBits,
+                   false,
+                   false,
+                   Transparency.OPAQUE,
+                   DataBuffer.TYPE_BYTE);
     }
 
     /**
@@ -122,8 +131,6 @@ public class PDLab extends PDColorSpace
      */
     public int getNumberOfComponents() throws IOException
     {
-        //BJL
-        //hmm is this correct, I am not 100% sure.
         return 3;
     }
 

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceDictionary.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceDictionary.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceDictionary.java Mon May 27 16:58:07 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.pdfbox.pdmodel.interactive.annotation;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
@@ -35,6 +37,12 @@ import java.util.Map;
  */
 public class PDAppearanceDictionary implements COSObjectable
 {
+
+    /**
+     * Log instance.
+     */
+    private static final Log LOG = LogFactory.getLog(PDAppearanceDictionary.class);
+
     private COSDictionary dictionary;
 
     /**
@@ -93,15 +101,25 @@ public class PDAppearanceDictionary impl
         {
             COSStream aux = (COSStream) ap;
             ap = new COSDictionary();
-            ((COSDictionary)ap).setItem(COSName.getPDFName( "default" ), aux );
+            ((COSDictionary)ap).setItem(COSName.DEFAULT, aux );
         }
         COSDictionary map = (COSDictionary)ap;
         Map<String, PDAppearanceStream> actuals = new HashMap<String, PDAppearanceStream>();
-        Map retval = new COSDictionaryMap( actuals, map );
+        Map<String, PDAppearanceStream> retval = new COSDictionaryMap<String, PDAppearanceStream>( actuals, map );
         for( COSName asName : map.keySet() )
         {
-            COSStream as = (COSStream)map.getDictionaryObject( asName );
-            actuals.put( asName.getName(), new PDAppearanceStream( as ) );
+            COSBase stream = map.getDictionaryObject( asName );
+            // PDFBOX-1599: this is just a workaround. The given PDF provides "null" as stream 
+            // which leads to a COSName("null") value and finally to a ClassCastExcpetion
+            if (stream instanceof COSStream)
+            {
+                COSStream as = (COSStream)stream;
+                actuals.put( asName.getName(), new PDAppearanceStream( as ) );
+            }
+            else
+            {
+                LOG.debug("non-conformance workaround: ignore null value for appearance stream.");
+            }
         }
         return retval;
     }
@@ -151,15 +169,25 @@ public class PDAppearanceDictionary impl
             {
                 COSStream aux = (COSStream) ap;
                 ap = new COSDictionary();
-                ((COSDictionary)ap).setItem(COSName.getPDFName( "default" ), aux );
+                ((COSDictionary)ap).setItem(COSName.DEFAULT, aux );
             }
             COSDictionary map = (COSDictionary)ap;
             Map<String, PDAppearanceStream> actuals = new HashMap<String, PDAppearanceStream>();
-            retval = new COSDictionaryMap( actuals, map );
+            retval = new COSDictionaryMap<String, PDAppearanceStream>( actuals, map );
             for( COSName asName : map.keySet() )
             {
-                COSStream as = (COSStream)map.getDictionaryObject( asName );
-                actuals.put( asName.getName(), new PDAppearanceStream( as ) );
+                COSBase stream = map.getDictionaryObject( asName );
+                // PDFBOX-1599: this is just a workaround. The given PDF provides "null" as stream 
+                // which leads to a COSName("null") value and finally to a ClassCastExcpetion
+                if (stream instanceof COSStream)
+                {
+                    COSStream as = (COSStream)stream;
+                    actuals.put( asName.getName(), new PDAppearanceStream( as ) );
+                }
+                else
+                {
+                    LOG.debug("non-conformance workaround: ignore null value for appearance stream.");
+                }
             }
         }
         return retval;
@@ -210,16 +238,26 @@ public class PDAppearanceDictionary impl
             {
                 COSStream aux = (COSStream) ap;
                 ap = new COSDictionary();
-                ((COSDictionary)ap).setItem(COSName.getPDFName( "default" ), aux );
+                ((COSDictionary)ap).setItem(COSName.DEFAULT, aux );
             }
             COSDictionary map = (COSDictionary)ap;
             Map<String, PDAppearanceStream> actuals =
                 new HashMap<String, PDAppearanceStream>();
-            retval = new COSDictionaryMap( actuals, map );
+            retval = new COSDictionaryMap<String, PDAppearanceStream>( actuals, map );
             for( COSName asName : map.keySet() )
             {
-                COSStream as = (COSStream)map.getDictionaryObject( asName );
-                actuals.put( asName.getName(), new PDAppearanceStream( as ) );
+                COSBase stream = map.getDictionaryObject( asName );
+                // PDFBOX-1599: this is just a workaround. The given PDF provides "null" as stream 
+                // which leads to a COSName("null") value and finally to a ClassCastExcpetion
+                if (stream instanceof COSStream)
+                {
+                    COSStream as = (COSStream)stream;
+                    actuals.put( asName.getName(), new PDAppearanceStream( as ) );
+                }
+                else
+                {
+                    LOG.debug("non-conformance workaround: ignore null value for appearance stream.");
+                }
             }
         }
         return retval;

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuildDataDict.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuildDataDict.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuildDataDict.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuildDataDict.java Mon May 27 16:58:07 2013
@@ -90,7 +90,7 @@ public class PDPropBuildDataDict impleme
      */
     public void setName(String name)
     {
-        dictionary.setString(COSName.NAME, name);
+        dictionary.setName(COSName.NAME, name);
     }
 
     /**

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearance.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearance.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearance.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAppearance.java Mon May 27 16:58:07 2013
@@ -257,7 +257,7 @@ public class PDAppearance
                 PDAppearanceStream appearanceStream = (PDAppearanceStream)normalAppearance.get( "default" );
                 if( appearanceStream == null )
                 {
-                    COSStream cosStream = new COSStream( acroForm.getDocument().getDocument().getScratchFile() );
+                    COSStream cosStream = acroForm.getDocument().getDocument().createCOSStream();
                     appearanceStream = new PDAppearanceStream( cosStream );
                     appearanceStream.setBoundingBox( widget.getRectangle().createRetranslatedRectangle() );
                     appearance.setNormalAppearance( appearanceStream );

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/LayerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/LayerUtility.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/LayerUtility.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/LayerUtility.java Mon May 27 16:58:07 2013
@@ -83,14 +83,12 @@ public class LayerUtility
     public void wrapInSaveRestore(PDPage page) throws IOException
     {
         COSDictionary saveGraphicsStateDic = new COSDictionary();
-        COSStream saveGraphicsStateStream = new COSStream(saveGraphicsStateDic,
-                getDocument().getDocument().getScratchFile());
+        COSStream saveGraphicsStateStream = getDocument().getDocument().createCOSStream(saveGraphicsStateDic);
         OutputStream saveStream = saveGraphicsStateStream.createUnfilteredStream();
         saveStream.write("q\n".getBytes("ISO-8859-1"));
         saveStream.flush();
 
-        COSStream restoreGraphicsStateStream = new COSStream(saveGraphicsStateDic,
-                getDocument().getDocument().getScratchFile());
+        COSStream restoreGraphicsStateStream = getDocument().getDocument().createCOSStream(saveGraphicsStateDic);
         OutputStream restoreStream = restoreGraphicsStateStream.createUnfilteredStream();
         restoreStream.write("Q\n".getBytes("ISO-8859-1"));
         restoreStream.flush();

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFImageWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFImageWriter.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFImageWriter.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFImageWriter.java Mon May 27 16:58:07 2013
@@ -23,18 +23,14 @@ import java.io.IOException;
 import java.util.List;
 import java.util.Properties;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 
-
 /**
- * This class will take a PDF document and strip out all of the text and ignore the
- * formatting and such.  Please note; it is up to clients of this class to verify that
- * a specific user has the correct permissions to extract text from the
- * PDF document.
- * <p>
- * Patterned after PDFTextStripper.
- *
+ * This class writes single pages of a pdf to a file.
+ * 
  * @author <a href="mailto:DanielWilson@Users.SourceForge.net">Daniel Wilson</a>
  * @version $Revision: 1.1 $
  */
@@ -42,6 +38,11 @@ public class PDFImageWriter extends PDFS
 {
 
     /**
+     * Log instance.
+     */
+    private static final Log LOG = LogFactory.getLog(PDFImageWriter.class);
+
+    /**
      * Instantiate a new PDFImageWriter object.
      */
     public PDFImageWriter()
@@ -49,72 +50,89 @@ public class PDFImageWriter extends PDFS
     }
 
     /**
-     * Instantiate a new PDFImageWriter object.  Loading all of the operator mappings
-     * from the properties object that is passed in.
-     *
-     * @param props The properties containing the mapping of operators to PDFOperator
-     * classes.
-     *
-     * @throws IOException If there is an error reading the properties.
+     * Instantiate a new PDFImageWriter object. Loading all of the operator mappings from the properties object that is
+     * passed in.
+     * 
+     * @param props
+     *            The properties containing the mapping of operators to PDFOperator classes.
+     * 
+     * @throws IOException
+     *             If there is an error reading the properties.
      */
-    public PDFImageWriter( Properties props ) throws IOException
+    public PDFImageWriter(Properties props) throws IOException
     {
-        super( props );
+        super(props);
     }
 
     /**
      * Converts a given page range of a PDF document to bitmap images.
-     * @param document the PDF document
-     * @param imageType the target format (ex. "png")
-     * @param password the password (needed if the PDF is encrypted)
-     * @param startPage the start page (1 is the first page)
-     * @param endPage the end page (set to Integer.MAX_VALUE for all pages)
-     * @param outputPrefix used to construct the filename for the individual images
+     * 
+     * @param document
+     *            the PDF document
+     * @param imageType
+     *            the target format (ex. "png")
+     * @param password
+     *            the password (needed if the PDF is encrypted)
+     * @param startPage
+     *            the start page (1 is the first page)
+     * @param endPage
+     *            the end page (set to Integer.MAX_VALUE for all pages)
+     * @param outputPrefix
+     *            used to construct the filename for the individual images
      * @return true if the images were produced, false if there was an error
-     * @throws IOException if an I/O error occurs
+     * @throws IOException
+     *             if an I/O error occurs
      */
-    public boolean writeImage(PDDocument document, String imageType, String password,
-            int startPage, int endPage, String outputPrefix)
-    throws IOException
+    public boolean writeImage(PDDocument document, String imageType, String password, int startPage, int endPage,
+            String outputPrefix) throws IOException
     {
         int resolution;
         try
         {
             resolution = Toolkit.getDefaultToolkit().getScreenResolution();
         }
-        catch( HeadlessException e )
+        catch (HeadlessException e)
         {
             resolution = 96;
         }
-        return writeImage(document, imageType, password, startPage, endPage, outputPrefix,
-                8, resolution);
+        return writeImage(document, imageType, password, startPage, endPage, outputPrefix, 8, resolution);
     }
 
     /**
      * Converts a given page range of a PDF document to bitmap images.
-     * @param document the PDF document
-     * @param imageFormat the target format (ex. "png")
-     * @param password the password (needed if the PDF is encrypted)
-     * @param startPage the start page (1 is the first page)
-     * @param endPage the end page (set to Integer.MAX_VALUE for all pages)
-     * @param outputPrefix used to construct the filename for the individual images
-     * @param imageType the image type (see {@link BufferedImage}.TYPE_*)
-     * @param resolution the resolution in dpi (dots per inch)
+     * 
+     * @param document
+     *            the PDF document
+     * @param imageFormat
+     *            the target format (ex. "png")
+     * @param password
+     *            the password (needed if the PDF is encrypted)
+     * @param startPage
+     *            the start page (1 is the first page)
+     * @param endPage
+     *            the end page (set to Integer.MAX_VALUE for all pages)
+     * @param outputPrefix
+     *            used to construct the filename for the individual images
+     * @param imageType
+     *            the image type (see {@link BufferedImage}.TYPE_*)
+     * @param resolution
+     *            the resolution in dpi (dots per inch)
      * @return true if the images were produced, false if there was an error
-     * @throws IOException if an I/O error occurs
+     * @throws IOException
+     *             if an I/O error occurs
      */
-    public boolean writeImage(PDDocument document, String imageFormat, String password,
-            int startPage, int endPage, String outputPrefix, int imageType, int resolution)
-    throws IOException
+    public boolean writeImage(PDDocument document, String imageFormat, String password, int startPage, int endPage,
+            String outputPrefix, int imageType, int resolution) throws IOException
     {
         boolean bSuccess = true;
-        List pages = document.getDocumentCatalog().getAllPages();
-        for( int i = startPage - 1; i < endPage && i < pages.size(); i++ )
+        List<PDPage> pages = document.getDocumentCatalog().getAllPages();
+        int pagesSize = pages.size();
+        for (int i = startPage - 1; i < endPage && i < pagesSize; i++)
         {
-            PDPage page = (PDPage)pages.get( i );
+            PDPage page = pages.get(i);
             BufferedImage image = page.convertToImage(imageType, resolution);
             String fileName = outputPrefix + (i + 1);
-            System.out.println( "Writing: " + fileName + "." +imageFormat);
+            LOG.info("Writing: " + fileName + "." + imageFormat);
             bSuccess &= ImageIOUtil.writeImage(image, imageFormat, fileName, imageType, resolution);
         }
         return bSuccess;

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/Invoke.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/Invoke.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/Invoke.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/Invoke.java Mon May 27 16:58:07 2013
@@ -22,6 +22,7 @@ import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject;
 import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
+import org.apache.pdfbox.util.Matrix;
 import org.apache.pdfbox.util.PDFMarkedContentExtractor;
 import org.apache.pdfbox.util.PDFOperator;
 
@@ -53,18 +54,25 @@ public class Invoke extends OperatorProc
 
         Map<String,PDXObject> xobjects = context.getXObjects();
         PDXObject xobject = (PDXObject) xobjects.get(name.getName());
-        if (this.context instanceof PDFMarkedContentExtractor)
+        if (context instanceof PDFMarkedContentExtractor)
         {
-            ((PDFMarkedContentExtractor) this.context).xobject(xobject);
+            ((PDFMarkedContentExtractor) context).xobject(xobject);
         }
 
         if(xobject instanceof PDXObjectForm)
         {
             PDXObjectForm form = (PDXObjectForm)xobject;
             COSStream formContentstream = form.getCOSStream();
+            // if there is an optional form matrix, we have to map the form space to the user space
+            Matrix matrix = form.getMatrix();
+            if (matrix != null) 
+            {
+                Matrix xobjectCTM = matrix.multiply( context.getGraphicsState().getCurrentTransformationMatrix());
+                context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
+            }
             // find some optional resources, instead of using the current resources
             PDResources pdResources = form.getResources();
-            getContext().processSubStream( context.getCurrentPage(), pdResources, formContentstream );
+            context.processSubStream( context.getCurrentPage(), pdResources, formContentstream );
         }
     }
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColor.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColor.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColor.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColor.java Mon May 27 16:58:07 2013
@@ -29,6 +29,7 @@ import org.apache.pdfbox.pdmodel.graphic
 import org.apache.pdfbox.pdmodel.graphics.color.PDICCBased;
 import org.apache.pdfbox.pdmodel.graphics.color.PDCalRGB;
 import org.apache.pdfbox.pdmodel.graphics.color.PDIndexed;
+import org.apache.pdfbox.pdmodel.graphics.color.PDLab;
 import org.apache.pdfbox.pdmodel.graphics.color.PDPattern;
 import org.apache.pdfbox.pdmodel.graphics.color.PDSeparation;
 import org.apache.pdfbox.util.PDFOperator;
@@ -37,7 +38,6 @@ import java.io.IOException;
 /**
  * <p>Set the non stroking color space.</p>
  * 
- * @author <a href="mailto:andreas@lehmi.de">Andreas Lehmkühler</a>
  * @version $Revision: 1.0 $
  */
 public class SetNonStrokingColor extends OperatorProcessor 
@@ -46,7 +46,7 @@ public class SetNonStrokingColor extends
     /**
      * Log instance.
      */
-    private static final Log log = LogFactory.getLog(SetNonStrokingColor.class);
+    private static final Log LOG = LogFactory.getLog(SetNonStrokingColor.class);
 
     /**
      * sc,scn Set color space for non stroking operations.
@@ -96,6 +96,10 @@ public class SetNonStrokingColor extends
             {
                 newOperator = new SetNonStrokingIndexed();
             }
+            else if (colorSpace instanceof PDLab)
+            {
+                newOperator = new SetNonStrokingLabColor();
+            }
 
             if (newOperator != null) 
             {
@@ -104,13 +108,13 @@ public class SetNonStrokingColor extends
             }
             else 
             {
-                log.warn("Not supported colorspace "+colorSpace.getName() 
+                LOG.warn("Not supported colorspace "+colorSpace.getName() 
                         + " within operator "+operator.getOperation());
             }
         }
         else
         {
-            log.warn("Colorspace not found in "+getClass().getName()+".process!!");
+            LOG.warn("Colorspace not found in "+getClass().getName()+".process!!");
         }
     }
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingColor.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingColor.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingColor.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/SetStrokingColor.java Mon May 27 16:58:07 2013
@@ -29,6 +29,7 @@ import org.apache.pdfbox.pdmodel.graphic
 import org.apache.pdfbox.pdmodel.graphics.color.PDICCBased;
 import org.apache.pdfbox.pdmodel.graphics.color.PDCalRGB;
 import org.apache.pdfbox.pdmodel.graphics.color.PDIndexed;
+import org.apache.pdfbox.pdmodel.graphics.color.PDLab;
 import org.apache.pdfbox.pdmodel.graphics.color.PDPattern;
 import org.apache.pdfbox.pdmodel.graphics.color.PDSeparation;
 import org.apache.pdfbox.util.PDFOperator;
@@ -37,7 +38,6 @@ import java.io.IOException;
 /**
  * <p>Set the stroking color space.</p>
  * 
- * @author <a href="mailto:andreas@lehmi.de">Andreas Lehmkühler</a>
  * @version $Revision: 1.0 $
  */
 public class SetStrokingColor extends OperatorProcessor 
@@ -46,7 +46,7 @@ public class SetStrokingColor extends Op
     /**
      * Log instance.
      */
-    private static final Log log = LogFactory.getLog(SetStrokingColor.class);
+    private static final Log LOG = LogFactory.getLog(SetStrokingColor.class);
 
     /**
      * SC,SCN Set color space for stroking operations.
@@ -96,6 +96,10 @@ public class SetStrokingColor extends Op
             {
                 newOperator = new SetStrokingIndexed();
             }
+            else if (colorSpace instanceof PDLab)
+            {
+                newOperator = new SetStrokingLabColor();
+            }
 
             if (newOperator != null) 
             {
@@ -104,13 +108,13 @@ public class SetStrokingColor extends Op
             }
             else
             {
-                log.info("Not supported colorspace "+colorSpace.getName() 
+                LOG.info("Not supported colorspace "+colorSpace.getName() 
                         + " within operator "+operator.getOperation());
             }
         }
         else 
         {
-            log.warn("Colorspace not found in "+getClass().getName()+".process!!");
+            LOG.warn("Colorspace not found in "+getClass().getName()+".process!!");
         }
     }
 }

Modified: pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/TestAll.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/TestAll.java?rev=1486661&r1=1486660&r2=1486661&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/TestAll.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/TestAll.java Mon May 27 16:58:07 2013
@@ -29,6 +29,7 @@ import org.apache.pdfbox.io.TestRandomAc
 import org.apache.pdfbox.io.ccitt.TestCCITTFaxG31DDecodeInputStream;
 import org.apache.pdfbox.io.ccitt.TestPackedBitArray;
 import org.apache.pdfbox.pdmodel.TestFDF;
+import org.apache.pdfbox.pdmodel.TestPDDocument;
 import org.apache.pdfbox.pdmodel.TestPDDocumentCatalog;
 import org.apache.pdfbox.pdmodel.TestPDDocumentInformation;
 import org.apache.pdfbox.pdmodel.common.TestPDNameTreeNode;
@@ -85,6 +86,7 @@ public class TestAll extends TestCase
         suite.addTest( TestCOSString.suite() );
         suite.addTest( TestCOSInteger.suite() );
         suite.addTest( TestCOSFloat.suite() );
+        suite.addTestSuite( TestPDDocument.class );
         suite.addTestSuite( TestPDDocumentCatalog.class );
         suite.addTestSuite( TestPDDocumentInformation.class );
         suite.addTestSuite( org.apache.pdfbox.pdmodel.graphics.optionalcontent.TestOptionalContentGroups.class );