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/11/17 15:31:03 UTC

svn commit: r1542735 [3/4] - in /pdfbox/branches/1.8: ./ fontbox/src/main/java/org/apache/fontbox/ttf/ pdfbox/src/main/java/org/apache/pdfbox/filter/ pdfbox/src/main/java/org/apache/pdfbox/io/ pdfbox/src/main/java/org/apache/pdfbox/pdfparser/ pdfbox/sr...

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorState.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorState.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorState.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorState.java Sun Nov 17 14:31:02 2013
@@ -30,9 +30,9 @@ import org.apache.pdfbox.pdmodel.graphic
 
 /**
  * This class represents a color space and the color value for that colorspace.
- *
+ * 
  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.7 $
+ * 
  */
 public class PDColorState implements Cloneable
 {
@@ -43,32 +43,25 @@ public class PDColorState implements Clo
     private static final Log LOG = LogFactory.getLog(PDColorState.class);
 
     /**
-     * The default color that can be set to replace all colors in
-     * {@link ICC_ColorSpace ICC color spaces}.
-     *
+     * The default color that can be set to replace all colors in {@link ICC_ColorSpace ICC color spaces}.
+     * 
      * @see #setIccOverrideColor(Color)
      */
-    private static volatile Color iccOverrideColor =
-        Color.getColor("org.apache.pdfbox.ICC_override_color");
+    private static volatile Color iccOverrideColor = Color.getColor("org.apache.pdfbox.ICC_override_color");
 
     /**
-     * Sets the default color to replace all colors in
-     * {@link ICC_ColorSpace ICC color spaces}. This will work around
-     * a potential JVM crash caused by broken native ICC color manipulation
-     * code in the Sun class libraries.
+     * Sets the default color to replace all colors in {@link ICC_ColorSpace ICC color spaces}. This will work around a
+     * potential JVM crash caused by broken native ICC color manipulation code in the Sun class libraries.
      * <p>
      * The default override can be specified by setting the color code in
-     * <code>org.apache.pdfbox.ICC_override_color</code> system property
-     * (see {@link Color#getColor(String)}. If this system property is not
-     * specified, then the override is not enabled unless this method is
-     * explicitly called.
-     *
-     * @param color ICC override color,
-     *              or <code>null</code> to disable the override
+     * <code>org.apache.pdfbox.ICC_override_color</code> system property (see {@link Color#getColor(String)}. If this
+     * system property is not specified, then the override is not enabled unless this method is explicitly called.
+     * 
+     * @param color ICC override color, or <code>null</code> to disable the override
      * @see <a href="https://issues.apache.org/jira/browse/PDFBOX-511">PDFBOX-511</a>
      * @since Apache PDFBox 0.8.1
      */
-    public static void setIccOverrideColor(Color color) 
+    public static void setIccOverrideColor(Color color)
     {
         iccOverrideColor = color;
     }
@@ -78,9 +71,9 @@ public class PDColorState implements Clo
     private PDPatternResources pattern = null;
 
     /**
-     * Cached Java AWT color based on the current color space and value.
-     * The value is cleared whenever the color space or value is set.
-     *
+     * Cached Java AWT color based on the current color space and value. The value is cleared whenever the color space
+     * or value is set.
+     * 
      * @see #getJavaColor()
      */
     private Color color = null;
@@ -88,11 +81,11 @@ public class PDColorState implements Clo
 
     /**
      * Default constructor.
-     *
+     * 
      */
     public PDColorState()
     {
-        setColorSpaceValue( new float[] {0});
+        setColorSpaceValue(new float[] { 0 });
     }
 
     /**
@@ -101,22 +94,22 @@ public class PDColorState implements Clo
     public Object clone()
     {
         PDColorState retval = new PDColorState();
-        retval.colorSpace = this.colorSpace;
+        retval.colorSpace = colorSpace;
         retval.colorSpaceValue.clear();
-        retval.colorSpaceValue.addAll( this.colorSpaceValue );
+        retval.colorSpaceValue.addAll(colorSpaceValue);
         retval.setPattern(getPattern());
         return retval;
     }
 
     /**
      * Returns the Java AWT color based on the current color space and value.
-     *
+     * 
      * @return current Java AWT color
      * @throws IOException if the current color can not be created
      */
     public Color getJavaColor() throws IOException
     {
-        if (color == null && colorSpaceValue.size() > 0) 
+        if (color == null && colorSpaceValue.size() > 0)
         {
             color = createColor();
         }
@@ -125,7 +118,7 @@ public class PDColorState implements Clo
 
     /**
      * Returns the Java AWT paint based on the current pattern.
-     *
+     * 
      * @param pageHeight the height of the current page
      * @return current Java AWT paint
      * 
@@ -133,7 +126,7 @@ public class PDColorState implements Clo
      */
     public Paint getPaint(int pageHeight) throws IOException
     {
-        if (paint == null && pattern != null) 
+        if (paint == null && pattern != null)
         {
             paint = pattern.getPaint(pageHeight);
         }
@@ -142,6 +135,7 @@ public class PDColorState implements Clo
 
     /**
      * Create the current color from the colorspace and values.
+     * 
      * @return The current awt color.
      * @throws IOException If there is an error creating the color.
      */
@@ -150,44 +144,49 @@ public class PDColorState implements Clo
         float[] components = colorSpaceValue.toFloatArray();
         try
         {
-            if( colorSpace.getName().equals(PDDeviceRGB.NAME) && components.length == 3 )
+            String csName = colorSpace.getName();
+            if (PDDeviceRGB.NAME.equals(csName) && components.length == 3)
             {
-                //for some reason, when using RGB and the RGB colorspace
-                //the new Color doesn't maintain exactly the same values
-                //I think some color conversion needs to take place first
-                //for now we will just make rgb a special case.
-                return new Color( components[0], components[1], components[2] );
+                // for some reason, when using RGB and the RGB colorspace
+                // the new Color doesn't maintain exactly the same values
+                // I think some color conversion needs to take place first
+                // for now we will just make rgb a special case.
+                return new Color(components[0], components[1], components[2]);
+            }
+            else if (PDLab.NAME.equals(csName))
+            {
+                // transform the color values from Lab- to RGB-space
+                float[] csComponents = colorSpace.getJavaColorSpace().toRGB(components);
+                return new Color(csComponents[0], csComponents[1], csComponents[2]);
             }
             else
             {
-                if (components.length == 1) 
+                if (components.length == 1)
                 {
-                    if (colorSpace.getName().equals(PDSeparation.NAME))
+                    if (PDSeparation.NAME.equals(csName))
                     {
-                        //Use that component as a single-integer RGB value
-                        return new Color((int)components[0]);
+                        // Use that component as a single-integer RGB value
+                        return new Color((int) components[0]);
                     }
-                    if (colorSpace.getName().equals(PDDeviceGray.NAME))
+                    if (PDDeviceGray.NAME.equals(csName))
                     {
-                        // Handling DeviceGray as a special case as with JVM 1.5.0_15 
-                        // and maybe others printing on Windows fails with an 
+                        // Handling DeviceGray as a special case as with JVM 1.5.0_15
+                        // and maybe others printing on Windows fails with an
                         // ArrayIndexOutOfBoundsException when selecting colors
                         // and strokes e.g. sun.awt.windows.WPrinterJob.setTextColor
-                        return new Color(components[0],components[0],components[0]);
+                        return new Color(components[0], components[0], components[0]);
                     }
                 }
                 Color override = iccOverrideColor;
                 ColorSpace cs = colorSpace.getJavaColorSpace();
                 if (cs instanceof ICC_ColorSpace && override != null)
                 {
-                    LOG.warn(
-                            "Using an ICC override color to avoid a potential"
-                            + " JVM crash (see PDFBOX-511)");
+                    LOG.warn("Using an ICC override color to avoid a potential" + " JVM crash (see PDFBOX-511)");
                     return override;
                 }
                 else
                 {
-                    return new Color( cs, components, 1f );
+                    return new Color(cs, components, 1f);
                 }
             }
         }
@@ -197,42 +196,44 @@ public class PDColorState implements Clo
         catch (Exception e)
         {
             Color cGuess;
-            String sMsg = "Unable to create the color instance "
-                    + Arrays.toString(components) + " in color space "
+            String sMsg = "Unable to create the color instance " + Arrays.toString(components) + " in color space "
                     + colorSpace + "; guessing color ... ";
             try
             {
-                switch(components.length)
+                switch (components.length)
                 {
-                    case 1://Use that component as a single-integer RGB value
-                        cGuess = new Color((int)components[0]);
-                        sMsg += "\nInterpretating as single-integer RGB";
-                        break;
-                    case 3: //RGB
-                        cGuess = new Color(components[0],components[1],components[2]);
-                        sMsg += "\nInterpretating as RGB";
-                        break;
-                    case 4: //CMYK
-                        //do a rough conversion to RGB as I'm not getting the CMYK to work.
-                        //http://www.codeproject.com/KB/applications/xcmyk.aspx
-                        float r, g, b, k;
-                        k = components[3];
-
-                        r = components[0] * (1f - k) + k;
-                        g = components[1] * (1f - k) + k;
-                        b = components[2] * (1f - k) + k;
-                    
-                        r = (1f - r);
-                        g = (1f - g);
-                        b = (1f - b);
-                                
-                        cGuess = new Color( r,g,b );
-                        sMsg += "\nInterpretating as CMYK";
-                        break;
-                    default:
-                        
-                        sMsg += "\nUnable to guess using " + components.length + " components; using black instead";
-                         cGuess = Color.BLACK;
+                case 1:// Use that component as a single-integer RGB value
+                    cGuess = new Color((int) components[0]);
+                    sMsg += "\nInterpretating as single-integer RGB";
+                    break;
+                case 3: // RGB
+                    cGuess = new Color(components[0], components[1], components[2]);
+                    sMsg += "\nInterpretating as RGB";
+                    break;
+                case 4: // CMYK
+                    // do a rough conversion to RGB as I'm not getting the CMYK to work.
+                    // http://www.codeproject.com/KB/applications/xcmyk.aspx
+                    float r,
+                    g,
+                    b,
+                    k;
+                    k = components[3];
+
+                    r = components[0] * (1f - k) + k;
+                    g = components[1] * (1f - k) + k;
+                    b = components[2] * (1f - k) + k;
+
+                    r = (1f - r);
+                    g = (1f - g);
+                    b = (1f - b);
+
+                    cGuess = new Color(r, g, b);
+                    sMsg += "\nInterpretating as CMYK";
+                    break;
+                default:
+
+                    sMsg += "\nUnable to guess using " + components.length + " components; using black instead";
+                    cGuess = Color.BLACK;
                 }
             }
             catch (Exception e2)
@@ -247,19 +248,18 @@ public class PDColorState implements Clo
     }
 
     /**
-     * Constructor with an existing color set.  Default colorspace is PDDeviceGray.
-     *
+     * Constructor with an existing color set. Default colorspace is PDDeviceGray.
+     * 
      * @param csValues The color space values.
      */
-    public PDColorState( COSArray csValues )
+    public PDColorState(COSArray csValues)
     {
         colorSpaceValue = csValues;
     }
 
-
     /**
      * This will get the current colorspace.
-     *
+     * 
      * @return The current colorspace.
      */
     public PDColorSpace getColorSpace()
@@ -269,7 +269,7 @@ public class PDColorState implements Clo
 
     /**
      * This will set the current colorspace.
-     *
+     * 
      * @param value The new colorspace.
      */
     public void setColorSpace(PDColorSpace value)
@@ -281,8 +281,8 @@ public class PDColorState implements Clo
     }
 
     /**
-     * This will get the color space values.  Either 1 for gray or 3 for RGB.
-     *
+     * This will get the color space values. Either 1 for gray or 3 for RGB.
+     * 
      * @return The colorspace values.
      */
     public float[] getColorSpaceValue()
@@ -291,8 +291,8 @@ public class PDColorState implements Clo
     }
 
     /**
-     * This will get the color space values.  Either 1 for gray or 3 for RGB.
-     *
+     * This will get the color space values. Either 1 for gray or 3 for RGB.
+     * 
      * @return The colorspace values.
      */
     public COSArray getCOSColorSpaceValue()
@@ -302,12 +302,12 @@ public class PDColorState implements Clo
 
     /**
      * This will update the colorspace values.
-     *
+     * 
      * @param value The new colorspace values.
      */
     public void setColorSpaceValue(float[] value)
     {
-        colorSpaceValue.setFloatArray( value );
+        colorSpaceValue.setFloatArray(value);
         // Clear color cache and current pattern
         color = null;
         pattern = null;
@@ -315,7 +315,7 @@ public class PDColorState implements Clo
 
     /**
      * This will get the current pattern.
-     *
+     * 
      * @return The current pattern.
      */
     public PDPatternResources getPattern()
@@ -325,7 +325,7 @@ public class PDColorState implements Clo
 
     /**
      * This will update the current pattern.
-     *
+     * 
      * @param patternValue The new pattern.
      */
     public void setPattern(PDPatternResources patternValue)
@@ -334,5 +334,5 @@ public class PDColorState implements Clo
         // Clear color cache
         color = null;
     }
-    
+
 }

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=1542735&r1=1542734&r2=1542735&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 Sun Nov 17 14:31:02 2013
@@ -16,6 +16,14 @@
  */
 package org.apache.pdfbox.pdmodel.graphics.color;
 
+import java.awt.color.ColorSpace;
+import java.awt.image.ColorModel;
+import java.awt.image.DataBuffer;
+import java.awt.image.IndexColorModel;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSInteger;
@@ -24,20 +32,11 @@ import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.cos.COSString;
 
-import java.awt.color.ColorSpace;
-import java.awt.image.ColorModel;
-import java.awt.image.DataBuffer;
-import java.awt.image.IndexColorModel;
-
-import java.io.InputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
 /**
  * This class represents an Indexed color space.
- *
+ * 
  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.4 $
+ * 
  */
 public class PDIndexed extends PDColorSpace
 {
@@ -56,7 +55,7 @@ public class PDIndexed extends PDColorSp
 
     private PDColorSpace baseColorspace = null;
     private ColorModel baseColorModel = null;
-    
+
     /**
      * The lookup data as byte array.
      */
@@ -65,35 +64,40 @@ public class PDIndexed extends PDColorSp
     private byte[] indexedColorValues;
     private int indexNumOfComponents;
     private int maxIndex;
-    
+
+    /**
+     * Indexed color values are always 8bit based.
+     */
+    private static final int INDEXED_BPC = 8;
+
     /**
      * Constructor, default DeviceRGB, hival 255.
      */
     public PDIndexed()
     {
         array = new COSArray();
-        array.add( COSName.INDEXED );
-        array.add( COSName.DEVICERGB );
-        array.add( COSInteger.get( 255 ) );
-        array.add( org.apache.pdfbox.cos.COSNull.NULL );
+        array.add(COSName.INDEXED);
+        array.add(COSName.DEVICERGB);
+        array.add(COSInteger.get(255));
+        array.add(org.apache.pdfbox.cos.COSNull.NULL);
     }
 
     /**
      * Constructor.
-     *
+     * 
      * @param indexedArray The array containing the indexed parameters
      */
-    public PDIndexed( COSArray indexedArray )
+    public PDIndexed(COSArray indexedArray)
     {
         array = indexedArray;
     }
 
     /**
-     * This will return the number of color components.  This will return the
-     * number of color components in the base color.
-     *
+     * This will return the number of color components. This will return the number of color components in the base
+     * color.
+     * 
      * @return The number of components in this color space.
-     *
+     * 
      * @throws IOException If there is an error getting the number of color components.
      */
     public int getNumberOfComponents() throws IOException
@@ -103,7 +107,7 @@ public class PDIndexed extends PDColorSp
 
     /**
      * This will return the name of the color space.
-     *
+     * 
      * @return The name of the color space.
      */
     public String getName()
@@ -113,9 +117,9 @@ public class PDIndexed extends PDColorSp
 
     /**
      * Create a Java colorspace for this colorspace.
-     *
+     * 
      * @return A color space that can be used for Java AWT operations.
-     *
+     * 
      * @throws IOException If there is an error creating the color space.
      */
     protected ColorSpace createColorSpace() throws IOException
@@ -125,107 +129,106 @@ public class PDIndexed extends PDColorSp
 
     /**
      * Create a Java color model for this colorspace.
-     *
+     * 
      * @param bpc The number of bits per component.
-     *
+     * 
      * @return A color model that can be used for Java AWT operations.
-     *
+     * 
      * @throws IOException If there is an error creating the color model.
      */
-    public ColorModel createColorModel( int bpc ) throws IOException
+    public ColorModel createColorModel(int bpc) throws IOException
     {
         return createColorModel(bpc, -1);
     }
 
     /**
      * Create a Java color model for this colorspace including the given mask value.
-     *
-     * @param bpc The number of bits per component.
+     * 
+     * @param bpc The number of bits per component of the indexed color model.
      * @param mask the mask value, -1 indicates no mask
-     *
+     * 
      * @return A color model that can be used for Java AWT operations.
-     *
+     * 
      * @throws IOException If there is an error creating the color model.
      */
-    public ColorModel createColorModel( int bpc, int mask ) throws IOException
+    public ColorModel createColorModel(int bpc, int mask) throws IOException
     {
-        ColorModel colorModel = getBaseColorModel(bpc);
+        ColorModel colorModel = getBaseColorModel(INDEXED_BPC);
         calculateIndexedColorValues(colorModel, bpc);
         if (mask > -1)
         {
-            return new IndexColorModel(bpc, maxIndex+1, indexedColorValues, 0, colorModel.hasAlpha(), mask);
+            return new IndexColorModel(bpc, maxIndex + 1, indexedColorValues, 0, colorModel.hasAlpha(), mask);
         }
         else
         {
-            return new IndexColorModel(bpc, maxIndex+1, indexedColorValues, 0, colorModel.hasAlpha());
+            return new IndexColorModel(bpc, maxIndex + 1, indexedColorValues, 0, colorModel.hasAlpha());
         }
     }
 
     /**
      * This will get the color space that acts as the index for this color space.
-     *
+     * 
      * @return The base color space.
-     *
+     * 
      * @throws IOException If there is error creating the base color space.
      */
     public PDColorSpace getBaseColorSpace() throws IOException
     {
         if (baseColorspace == null)
         {
-            COSBase base = array.getObject( 1 );
-            baseColorspace = PDColorSpaceFactory.createColorSpace( base );
+            COSBase base = array.getObject(1);
+            baseColorspace = PDColorSpaceFactory.createColorSpace(base);
         }
         return baseColorspace;
     }
 
     /**
      * This will set the base color space.
-     *
+     * 
      * @param base The base color space to use as the index.
      */
-    public void setBaseColorSpace( PDColorSpace base )
+    public void setBaseColorSpace(PDColorSpace base)
     {
-        array.set( 1, base.getCOSObject() );
+        array.set(1, base.getCOSObject());
         baseColorspace = base;
     }
 
     /**
      * Get the highest value for the lookup.
-     *
+     * 
      * @return The hival entry.
      */
     public int getHighValue()
     {
-        return ((COSNumber)array.getObject( 2 )).intValue();
+        return ((COSNumber) array.getObject(2)).intValue();
     }
 
     /**
-     * This will set the highest value that is allowed.  This cannot be higher
-     * than 255.
-     *
+     * This will set the highest value that is allowed. This cannot be higher than 255.
+     * 
      * @param high The highest value for the lookup table.
      */
-    public void setHighValue( int high )
+    public void setHighValue(int high)
     {
-        array.set( 2, high );
+        array.set(2, high);
     }
 
     /**
      * This will perform a lookup into the color lookup table.
-     *
+     * 
      * @param lookupIndex The zero-based index into the table, should not exceed the high value.
      * @param componentNumber The component number, probably 1,2,3,3.
-     *
+     * 
      * @return The value that was from the lookup table.
-     *
+     * 
      * @throws IOException If there is an error looking up the color.
      */
-    public int lookupColor( int lookupIndex, int componentNumber ) throws IOException
+    public int lookupColor(int lookupIndex, int componentNumber) throws IOException
     {
         PDColorSpace baseColor = getBaseColorSpace();
         byte[] data = getLookupData();
         int numberOfComponents = baseColor.getNumberOfComponents();
-        return (data[lookupIndex*numberOfComponents + componentNumber]+256)%256;
+        return (data[lookupIndex * numberOfComponents + componentNumber] + 256) % 256;
     }
 
     /**
@@ -236,35 +239,35 @@ public class PDIndexed extends PDColorSp
      */
     public byte[] getLookupData() throws IOException
     {
-        if ( lookupData == null)
+        if (lookupData == null)
         {
-            COSBase lookupTable = array.getObject( 3 );
-            if( lookupTable instanceof COSString )
+            COSBase lookupTable = array.getObject(3);
+            if (lookupTable instanceof COSString)
             {
-                lookupData = ((COSString)lookupTable).getBytes();
+                lookupData = ((COSString) lookupTable).getBytes();
             }
-            else if( lookupTable instanceof COSStream )
+            else if (lookupTable instanceof COSStream)
             {
-                //Data will be small so just load the whole thing into memory for
-                //easier processing
-                COSStream lookupStream = (COSStream)lookupTable;
+                // Data will be small so just load the whole thing into memory for
+                // easier processing
+                COSStream lookupStream = (COSStream) lookupTable;
                 InputStream input = lookupStream.getUnfilteredStream();
                 ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
-                byte[] buffer = new byte[ 1024 ];
+                byte[] buffer = new byte[1024];
                 int amountRead;
-                while( (amountRead = input.read(buffer, 0, buffer.length)) != -1 )
+                while ((amountRead = input.read(buffer, 0, buffer.length)) != -1)
                 {
-                    output.write( buffer, 0, amountRead );
+                    output.write(buffer, 0, amountRead);
                 }
                 lookupData = output.toByteArray();
             }
-            else if( lookupTable == null )
+            else if (lookupTable == null)
             {
                 lookupData = new byte[0];
             }
             else
             {
-                throw new IOException( "Error: Unknown type for lookup table " + lookupTable );
+                throw new IOException("Error: Unknown type for lookup table " + lookupTable);
             }
         }
         return lookupData;
@@ -272,25 +275,26 @@ public class PDIndexed extends PDColorSp
 
     /**
      * This will set a color in the color lookup table.
-     *
+     * 
      * @param lookupIndex The zero-based index into the table, should not exceed the high value.
      * @param componentNumber The component number, probably 1,2,3,3.
      * @param color The color that will go into the table.
-     *
+     * 
      * @throws IOException If there is an error looking up the color.
      */
-    public void setLookupColor( int lookupIndex, int componentNumber, int color ) throws IOException
+    public void setLookupColor(int lookupIndex, int componentNumber, int color) throws IOException
     {
         PDColorSpace baseColor = getBaseColorSpace();
         int numberOfComponents = baseColor.getNumberOfComponents();
         byte[] data = getLookupData();
-        data[lookupIndex*numberOfComponents + componentNumber] = (byte)color;
-        COSString string = new COSString( data );
-        array.set( 3, string );
+        data[lookupIndex * numberOfComponents + componentNumber] = (byte) color;
+        COSString string = new COSString(data);
+        array.set(3, string);
     }
 
     /**
      * Returns the components of the color for the given index.
+     * 
      * @param index the index of the color value
      * @return COSArray with the color components
      * @throws IOException If the tint function is not supported
@@ -298,33 +302,33 @@ public class PDIndexed extends PDColorSp
     public float[] calculateColorValues(int index) throws IOException
     {
         // TODO bpc != 8 ??
-        calculateIndexedColorValues(getBaseColorModel(8), 8);
+        calculateIndexedColorValues(getBaseColorModel(INDEXED_BPC), 8);
         float[] colorValues = null;
         if (index < maxIndex)
         {
             int bufferIndex = index * indexNumOfComponents;
             colorValues = new float[indexNumOfComponents];
-            for (int i=0; i < indexNumOfComponents; i++)
+            for (int i = 0; i < indexNumOfComponents; i++)
             {
-                colorValues[i] = (float)indexedColorValues[bufferIndex+i];
+                colorValues[i] = (float) indexedColorValues[bufferIndex + i];
             }
         }
         return colorValues;
     }
-    
+
     private ColorModel getBaseColorModel(int bpc) throws IOException
     {
         if (baseColorModel == null)
         {
             baseColorModel = getBaseColorSpace().createColorModel(bpc);
-            if( baseColorModel.getTransferType() != DataBuffer.TYPE_BYTE )
+            if (baseColorModel.getTransferType() != DataBuffer.TYPE_BYTE)
             {
-                throw new IOException( "Not implemented" );
+                throw new IOException("Not implemented");
             }
         }
         return baseColorModel;
     }
-    
+
     private void calculateIndexedColorValues(ColorModel colorModel, int bpc) throws IOException
     {
         if (indexedColorValues == null)
@@ -335,28 +339,28 @@ public class PDIndexed extends PDColorSp
             int highValue = getHighValue();
             // choose the correct size, sometimes there are more indexed values than needed
             // and sometimes there are fewer indexed value than possible
-            maxIndex = Math.min(numberOfColorValues-1, highValue);
+            maxIndex = Math.min(numberOfColorValues - 1, highValue);
             byte[] index = getLookupData();
             // despite all definitions there may be less values within the lookup data
-            int numberOfColorValuesFromIndex = (index.length / baseColorModel.getNumComponents())-1;
+            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;
+            indexNumOfComponents = 3 + (hasAlpha ? 1 : 0);
+            int buffersize = (maxIndex + 1) * indexNumOfComponents;
             indexedColorValues = new byte[buffersize];
             byte[] inData = new byte[baseColorModel.getNumComponents()];
             int bufferIndex = 0;
-            for( int i = 0; i <= maxIndex; i++ )
+            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);
-                if(hasAlpha)
+                indexedColorValues[bufferIndex] = (byte) colorModel.getRed(inData);
+                indexedColorValues[bufferIndex + 1] = (byte) colorModel.getGreen(inData);
+                indexedColorValues[bufferIndex + 2] = (byte) colorModel.getBlue(inData);
+                if (hasAlpha)
                 {
-                    indexedColorValues[bufferIndex+3] = (byte)colorModel.getAlpha(inData);
+                    indexedColorValues[bufferIndex + 3] = (byte) colorModel.getAlpha(inData);
                 }
                 bufferIndex += indexNumOfComponents;
             }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDCcitt.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDCcitt.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDCcitt.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDCcitt.java Sun Nov 17 14:31:02 2013
@@ -18,6 +18,7 @@ package org.apache.pdfbox.pdmodel.graphi
 
 import java.awt.Transparency;
 import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
 import java.awt.image.DataBufferByte;
 import java.awt.image.IndexColorModel;
 import java.awt.image.WritableRaster;
@@ -37,14 +38,16 @@ import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.io.RandomAccess;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.common.PDStream;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
+import org.apache.pdfbox.pdmodel.graphics.color.PDIndexed;
 
 /**
  * An image class for CCITT Fax.
- *
+ * 
  * @author <a href="ben@benlitchfield.com">Ben Litchfield</a>
  * @author paul king
- * @version $Revision: 1.6 $
+ * 
  */
 public class PDCcitt extends PDXObjectImage
 {
@@ -53,13 +56,13 @@ public class PDCcitt extends PDXObjectIm
 
     static
     {
-        FAX_FILTERS.add( COSName.CCITTFAX_DECODE.getName() );
-        FAX_FILTERS.add( COSName.CCITTFAX_DECODE_ABBREVIATION.getName() );
+        FAX_FILTERS.add(COSName.CCITTFAX_DECODE.getName());
+        FAX_FILTERS.add(COSName.CCITTFAX_DECODE_ABBREVIATION.getName());
     }
 
     /**
      * Standard constructor.
-     *
+     * 
      * @param ccitt The PDStream that already contains all ccitt information.
      */
     public PDCcitt(PDStream ccitt)
@@ -70,38 +73,37 @@ public class PDCcitt extends PDXObjectIm
 
     /**
      * Construct from a tiff file.
-     *
+     * 
      * @param doc The document to create the image as part of.
      * @param raf The random access TIFF file which contains a suitable CCITT compressed image
      * @throws IOException If there is an error reading the tiff data.
      */
 
-    public PDCcitt( PDDocument doc, RandomAccess raf ) throws IOException
+    public PDCcitt(PDDocument doc, RandomAccess raf) throws IOException
     {
-        super( new PDStream(doc),"tiff");
-        // super( new PDStream( doc, null, true ), "tiff" );
+        super(new PDStream(doc), "tiff");
 
         COSDictionary decodeParms = new COSDictionary();
 
         COSDictionary dic = getCOSStream();
 
-        extractFromTiff(raf, getCOSStream().createFilteredStream(),decodeParms);
+        extractFromTiff(raf, getCOSStream().createFilteredStream(), decodeParms);
 
-        dic.setItem( COSName.FILTER, COSName.CCITTFAX_DECODE);
-        dic.setItem( COSName.SUBTYPE, COSName.IMAGE);
-        dic.setItem( COSName.TYPE, COSName.XOBJECT );
-        dic.setItem( COSName.DECODE_PARMS, decodeParms);
-
-        setBitsPerComponent( 1 );
-        setColorSpace( new PDDeviceGray() );
-        setWidth( decodeParms.getInt(COSName.COLUMNS) );
-        setHeight( decodeParms.getInt(COSName.ROWS) );
+        dic.setItem(COSName.FILTER, COSName.CCITTFAX_DECODE);
+        dic.setItem(COSName.SUBTYPE, COSName.IMAGE);
+        dic.setItem(COSName.TYPE, COSName.XOBJECT);
+        dic.setItem(COSName.DECODE_PARMS, decodeParms);
+
+        setBitsPerComponent(1);
+        setColorSpace(new PDDeviceGray());
+        setWidth(decodeParms.getInt(COSName.COLUMNS));
+        setHeight(decodeParms.getInt(COSName.ROWS));
 
     }
 
     /**
      * Returns an image of the CCITT Fax, or null if TIFFs are not supported. (Requires additional JAI Image filters )
-     *
+     * 
      * {@inheritDoc}
      */
     public BufferedImage getRGBImage() throws IOException
@@ -111,19 +113,19 @@ public class PDCcitt extends PDXObjectIm
         COSDictionary decodeParms = null;
         if (decodeP instanceof COSDictionary)
         {
-            decodeParms = (COSDictionary)decodeP;
+            decodeParms = (COSDictionary) decodeP;
         }
         else if (decodeP instanceof COSArray)
         {
             int index = 0;
             // determine the index for the CCITT-filter
             COSBase filters = stream.getFilters();
-            if (filters instanceof COSArray) 
+            if (filters instanceof COSArray)
             {
-                COSArray filterArray = (COSArray)filters;
+                COSArray filterArray = (COSArray) filters;
                 while (index < filterArray.size())
                 {
-                    COSName filtername = (COSName)filterArray.get(index);
+                    COSName filtername = (COSName) filterArray.get(index);
                     if (COSName.CCITTFAX_DECODE.equals(filtername))
                     {
                         break;
@@ -131,7 +133,7 @@ public class PDCcitt extends PDXObjectIm
                     index++;
                 }
             }
-            decodeParms =  (COSDictionary)((COSArray)decodeP).getObject(index);
+            decodeParms = (COSDictionary) ((COSArray) decodeP).getObject(index);
         }
         int cols = decodeParms.getInt(COSName.COLUMNS, 1728);
         int rows = decodeParms.getInt(COSName.ROWS, 0);
@@ -147,39 +149,65 @@ public class PDCcitt extends PDXObjectIm
             rows = Math.max(rows, height);
         }
         boolean blackIsOne = decodeParms.getBoolean(COSName.BLACK_IS_1, false);
-
-        BufferedImage image = new BufferedImage(cols, rows, BufferedImage.TYPE_BYTE_BINARY);
-        WritableRaster raster = image.getRaster();
-        DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
-        byte[] bufferData = buffer.getData();
+        // maybe a decode array is defined
+        COSArray decode = getDecode();
+        if (decode != null && decode.getInt(0) == 1)
+        {
+            // [1.0, 0.0] -> invert the "color" values
+            blackIsOne = !blackIsOne;
+        }
+        byte[] bufferData = null;
+        ColorModel colorModel = null;
+        PDColorSpace colorspace = getColorSpace();
+        // most likely there is no colorspace as a CCITT-filter uses 1-bit values mapped to black/white
+        // in some rare cases other colorspaces maybe used such as an indexed colorspace, see PDFBOX-1638
+        if (colorspace instanceof PDIndexed)
+        {
+            PDIndexed csIndexed = (PDIndexed) colorspace;
+            COSBase maskArray = getMask();
+            if (maskArray != null && maskArray instanceof COSArray)
+            {
+                colorModel = csIndexed.createColorModel(1, ((COSArray) maskArray).getInt(0));
+            }
+            else
+            {
+                colorModel = csIndexed.createColorModel(1);
+            }
+        }
+        else
+        {
+            byte[] map = new byte[] { (byte) 0x00, (byte) 0xFF };
+            colorModel = new IndexColorModel(1, map.length, map, map, map, Transparency.OPAQUE);
+        }
+        WritableRaster raster = colorModel.createCompatibleWritableRaster(cols, rows);
+        DataBufferByte buffer = (DataBufferByte) raster.getDataBuffer();
+        bufferData = buffer.getData();
         IOUtils.populateBuffer(stream.getUnfilteredStream(), bufferData);
+        BufferedImage image = new BufferedImage(colorModel, raster, false, null);
         if (!blackIsOne)
         {
-            //Inverting the bitmap
-            //Note the previous approach with starting from an IndexColorModel didn't work
-            //reliably. In some cases the image wouldn't be painted for some reason.
-            //So a safe but slower approach was taken.
+            // Inverting the bitmap
+            // Note the previous approach with starting from an IndexColorModel didn't work
+            // reliably. In some cases the image wouldn't be painted for some reason.
+            // So a safe but slower approach was taken.
             invertBitmap(bufferData);
         }
-        
         /*
          * If we have an image mask we need to add an alpha channel to the data
          */
-        if(hasMask())
+        if (hasMask())
         {
-	        byte map[] = new byte[] {(byte)0x00, (byte)0xff};
-	    	IndexColorModel  cm = new IndexColorModel(1, map.length, map, map, map, Transparency.OPAQUE);
-	    	 raster = cm.createCompatibleWritableRaster( image.getWidth(), image.getHeight() );
-	         buffer = (DataBufferByte)raster.getDataBuffer();
-	        bufferData = buffer.getData();
-	
-	        byte array[] = ((DataBufferByte)image.getData().getDataBuffer()).getData();
-	        System.arraycopy( array, 0,bufferData, 0,
-	                (array.length<bufferData.length?array.length: bufferData.length) );
-	        BufferedImage indexed = new BufferedImage(cm, raster, false, null);
-	        image = indexed;
+            byte[] map = new byte[] { (byte) 0x00, (byte) 0xff };
+            IndexColorModel cm = new IndexColorModel(1, map.length, map, map, map, Transparency.OPAQUE);
+            raster = cm.createCompatibleWritableRaster(cols, rows);
+            bufferData = ((DataBufferByte) raster.getDataBuffer()).getData();
+
+            byte[] array = ((DataBufferByte) image.getData().getDataBuffer()).getData();
+            System.arraycopy(array, 0, bufferData, 0,
+                    (array.length < bufferData.length ? array.length : bufferData.length));
+            BufferedImage indexed = new BufferedImage(cm, raster, false, null);
+            image = indexed;
         }
-        
         return applyMasks(image);
     }
 
@@ -187,29 +215,27 @@ public class PDCcitt extends PDXObjectIm
     {
         for (int i = 0, c = bufferData.length; i < c; i++)
         {
-            bufferData[i] = (byte)(~bufferData[i] & 0xFF);
+            bufferData[i] = (byte) (~bufferData[i] & 0xFF);
         }
     }
 
     /**
      * This writes a tiff to out.
-     *
+     * 
      * {@inheritDoc}
      */
     public void write2OutputStream(OutputStream out) throws IOException
     {
         // We should use another format than TIFF to get rid of the TiffWrapper
-        InputStream data = new TiffWrapper(
-                getPDStream().getPartiallyFilteredStream( FAX_FILTERS ),
-                getCOSStream());
+        InputStream data = new TiffWrapper(getPDStream().getPartiallyFilteredStream(FAX_FILTERS), getCOSStream());
         IOUtils.copy(data, out);
     }
 
     /**
      * Extract the ccitt stream from the tiff file.
-     *
-     * @param raf  - TIFF File
-     * @param os   - Stream to write raw ccitt data two
+     * 
+     * @param raf - TIFF File
+     * @param os - Stream to write raw ccitt data two
      * @param parms - COSDictionary which the encoding parameters are added to
      * @throws IOException If there is an error reading/writing to/from the stream
      */
@@ -225,15 +251,15 @@ public class PDCcitt extends PDXObjectIm
             {
                 throw new IOException("Not a valid tiff file");
             }
-            //ensure that endianess is either M or I
+            // ensure that endianess is either M or I
             if (endianess != 'M' && endianess != 'I')
             {
                 throw new IOException("Not a valid tiff file");
             }
             int magicNumber = readshort(endianess, raf);
-            if( magicNumber != 42)
+            if (magicNumber != 42)
             {
-                throw new  IOException("Not a valid tiff file");
+                throw new IOException("Not a valid tiff file");
             }
 
             // Relocate to the first set of tags
@@ -241,7 +267,7 @@ public class PDCcitt extends PDXObjectIm
 
             int numtags = readshort(endianess, raf);
 
-            //    The number 50 is somewhat arbitary, it just stops us load up junk from somewhere and tramping on
+            // The number 50 is somewhat arbitary, it just stops us load up junk from somewhere and tramping on
             if (numtags > 50)
             {
                 throw new IOException("Not a valid tiff file");
@@ -252,11 +278,11 @@ public class PDCcitt extends PDXObjectIm
             // The only parm which might change as a result of other options is K, so
             // We'll deal with that as a special;
 
-            int k=-1000; // Default Non CCITT compression
-            int dataoffset=0;
-            int datalength=0;
+            int k = -1000; // Default Non CCITT compression
+            int dataoffset = 0;
+            int datalength = 0;
 
-            for (int i=0; i < numtags; i++)
+            for (int i = 0; i < numtags; i++)
             {
                 int tag = readshort(endianess, raf);
                 int type = readshort(endianess, raf);
@@ -270,102 +296,102 @@ public class PDCcitt extends PDXObjectIm
                 {
                     switch (type)
                     {
-                        case 1:
-                        {
-                            val = val >> 24;
-                            break; // byte value
-                        }
-                        case 3:
-                        {
-                            val = val >> 16;
-                            break; // short value
-                        }
-                        case 4:
-                        {
-                            break; // long value
-                        }
-                        default:
-                        {
-                            //do nothing
-                        }
+                    case 1:
+                    {
+                        val = val >> 24;
+                        break; // byte value
                     }
-                }
-                switch (tag)
-                {
-                    case 256:
+                    case 3:
                     {
-                        parms.setInt(COSName.COLUMNS,val);
-                        break;
+                        val = val >> 16;
+                        break; // short value
                     }
-                    case 257:
+                    case 4:
                     {
-                        parms.setInt(COSName.ROWS,val);
-                        break;
+                        break; // long value
                     }
-                    case 259:
+                    default:
                     {
-                        if (val == 4)
-                        {
-                            k=-1;
-                        }
-                        if (val == 3)
-                        {
-                            k=0;
-                        }
-                        break;  // T6/T4 Compression
+                        // do nothing
                     }
-                    case 262:
+                    }
+                }
+                switch (tag)
+                {
+                case 256:
+                {
+                    parms.setInt(COSName.COLUMNS, val);
+                    break;
+                }
+                case 257:
+                {
+                    parms.setInt(COSName.ROWS, val);
+                    break;
+                }
+                case 259:
+                {
+                    if (val == 4)
                     {
-                        if (val == 1)
-                        {
-                            parms.setBoolean(COSName.BLACK_IS_1, true);
-                        }
-                        break;
+                        k = -1;
                     }
-                    case 273:
+                    if (val == 3)
                     {
-                        if (count == 1)
-                        {
-                            dataoffset=val;
-                        }
-                        break;
+                        k = 0;
                     }
-                    case 279:
+                    break; // T6/T4 Compression
+                }
+                case 262:
+                {
+                    if (val == 1)
                     {
-                        if (count == 1)
-                        {
-                            datalength=val;
-                        }
-                        break;
+                        parms.setBoolean(COSName.BLACK_IS_1, true);
                     }
-                    case 292:
+                    break;
+                }
+                case 273:
+                {
+                    if (count == 1)
                     {
-                        if (val == 1)
-                        {
-                            k=50;  // T4 2D - arbitary K value
-                        }
-                        break;
+                        dataoffset = val;
                     }
-                    case 324:
+                    break;
+                }
+                case 279:
+                {
+                    if (count == 1)
                     {
-                        if (count == 1)
-                        {
-                            dataoffset=val;
-                        }
-                        break;
+                        datalength = val;
                     }
-                    case 325:
+                    break;
+                }
+                case 292:
+                {
+                    if (val == 1)
                     {
-                        if (count == 1)
-                        {
-                            datalength=val;
-                        }
-                        break;
+                        k = 50; // T4 2D - arbitary K value
                     }
-                    default:
+                    break;
+                }
+                case 324:
+                {
+                    if (count == 1)
                     {
-                        //do nothing
+                        dataoffset = val;
                     }
+                    break;
+                }
+                case 325:
+                {
+                    if (count == 1)
+                    {
+                        datalength = val;
+                    }
+                    break;
+                }
+                default:
+                {
+                    // do nothing
+                }
                 }
             }
 
@@ -378,16 +404,16 @@ public class PDCcitt extends PDXObjectIm
                 throw new IOException("First image in tiff is not a single tile/strip");
             }
 
-            parms.setInt(COSName.K,k);
+            parms.setInt(COSName.K, k);
 
             raf.seek(dataoffset);
 
             byte[] buf = new byte[8192];
             int amountRead = -1;
-            while( (amountRead = raf.read( buf,0, Math.min(8192,datalength) )) > 0 )
+            while ((amountRead = raf.read(buf, 0, Math.min(8192, datalength))) > 0)
             {
                 datalength -= amountRead;
-                os.write( buf, 0, amountRead );
+                os.write(buf, 0, amountRead);
             }
 
         }
@@ -415,25 +441,23 @@ public class PDCcitt extends PDXObjectIm
         return (raf.read() << 24) | (raf.read() << 16) | (raf.read() << 8) | raf.read();
     }
 
-
     /**
-     * Extends InputStream to wrap the data from the CCITT Fax with a suitable TIFF Header.
-     * For details see www.tiff.org, which contains useful information including pointers to the
-     * TIFF 6.0 Specification
-     *
+     * Extends InputStream to wrap the data from the CCITT Fax with a suitable TIFF Header. For details see
+     * www.tiff.org, which contains useful information including pointers to the TIFF 6.0 Specification
+     * 
      */
     private class TiffWrapper extends InputStream
     {
 
-        private int currentOffset;     // When reading, where in the tiffheader are we.
-        private byte[] tiffheader;      // Byte array to store tiff header data
+        private int currentOffset; // When reading, where in the tiffheader are we.
+        private byte[] tiffheader; // Byte array to store tiff header data
         private InputStream datastream; // Original InputStream
 
         private TiffWrapper(InputStream rawstream, COSDictionary options)
         {
-                buildHeader(options);
-                currentOffset=0;
-                datastream = rawstream;
+            buildHeader(options);
+            currentOffset = 0;
+            datastream = rawstream;
         }
 
         // Implement basic methods from InputStream
@@ -444,6 +468,7 @@ public class PDCcitt extends PDXObjectIm
         {
             return false;
         }
+
         /**
          * {@inheritDoc}
          */
@@ -454,7 +479,7 @@ public class PDCcitt extends PDXObjectIm
 
         /**
          * For simple read, take a byte from the tiffheader array or pass through.
-         *
+         * 
          * {@inheritDoc}
          */
         public int read() throws IOException
@@ -467,9 +492,9 @@ public class PDCcitt extends PDXObjectIm
         }
 
         /**
-         * For read methods only return as many bytes as we have left in the header
-         * if we've exhausted the header, pass through to the InputStream of the raw CCITT data.
-         *
+         * For read methods only return as many bytes as we have left in the header if we've exhausted the header, pass
+         * through to the InputStream of the raw CCITT data.
+         * 
          * {@inheritDoc}
          */
         public int read(byte[] data) throws IOException
@@ -491,10 +516,10 @@ public class PDCcitt extends PDXObjectIm
         }
 
         /**
-         * For read methods only return as many bytes as we have left in the header
-         * if we've exhausted the header, pass through to the InputStream of the raw CCITT data.
-         *
-         *  {@inheritDoc}
+         * For read methods only return as many bytes as we have left in the header if we've exhausted the header, pass
+         * through to the InputStream of the raw CCITT data.
+         * 
+         * {@inheritDoc}
          */
         public int read(byte[] data, int off, int len) throws IOException
         {
@@ -510,14 +535,14 @@ public class PDCcitt extends PDXObjectIm
             }
             else
             {
-                return datastream.read(data,off,len);
+                return datastream.read(data, off, len);
             }
         }
 
         /**
-         * When skipping if any header data not yet read, only allow to skip what we've in the buffer
-         * Otherwise just pass through.
-         *
+         * When skipping if any header data not yet read, only allow to skip what we've in the buffer Otherwise just
+         * pass through.
+         * 
          * {@inheritDoc}
          */
         public long skip(long n) throws IOException
@@ -535,12 +560,10 @@ public class PDCcitt extends PDXObjectIm
         }
 
         // Static data for the beginning of the TIFF header
-        private final byte[] basicHeader = {
-                'I','I',42,0,8,0,0,0,       // File introducer and pointer to first IFD
-                0,0};                       // Number of tags start with two
-
+        private final byte[] basicHeader = { 'I', 'I', 42, 0, 8, 0, 0, 0, // File introducer and pointer to first IFD
+                0, 0 }; // Number of tags start with two
 
-        private int additionalOffset;      // Offset in header to additional data
+        private int additionalOffset; // Offset in header to additional data
 
         // Builds up the tiffheader based on the options passed through.
         private void buildHeader(COSDictionary options)
@@ -548,16 +571,16 @@ public class PDCcitt extends PDXObjectIm
 
             final int numOfTags = 10; // The maximum tags we'll fill
             final int maxAdditionalData = 24; // The maximum amount of additional data
-                                                // outside the IFDs. (bytes)
+                                              // outside the IFDs. (bytes)
 
             // The length of the header will be the length of the basic header (10)
             // plus 12 bytes for each IFD, 4 bytes as a pointer to the next IFD (will be 0)
             // plus the length of the additional data
 
-            int ifdSize = 10 + (12 * numOfTags ) + 4;
+            int ifdSize = 10 + (12 * numOfTags) + 4;
             tiffheader = new byte[ifdSize + maxAdditionalData];
-            java.util.Arrays.fill(tiffheader,(byte)0);
-            System.arraycopy(basicHeader,0,tiffheader,0,basicHeader.length);
+            java.util.Arrays.fill(tiffheader, (byte) 0);
+            System.arraycopy(basicHeader, 0, tiffheader, 0, basicHeader.length);
 
             // Additional data outside the IFD starts after the IFD's and pointer to the next IFD (0)
             additionalOffset = ifdSize;
@@ -579,26 +602,26 @@ public class PDCcitt extends PDXObjectIm
             }
             COSBase dicOrArrayParms = options.getDictionaryObject(COSName.DECODE_PARMS);
             COSDictionary decodeParms = null;
-            if( dicOrArrayParms instanceof COSDictionary )
+            if (dicOrArrayParms instanceof COSDictionary)
             {
-                decodeParms = (COSDictionary)dicOrArrayParms;
+                decodeParms = (COSDictionary) dicOrArrayParms;
             }
             else
             {
-                COSArray parmsArray = (COSArray)dicOrArrayParms;
-                if( parmsArray.size() == 1 )
+                COSArray parmsArray = (COSArray) dicOrArrayParms;
+                if (parmsArray.size() == 1)
                 {
-                    decodeParms = (COSDictionary)parmsArray.getObject( 0 );
+                    decodeParms = (COSDictionary) parmsArray.getObject(0);
                 }
                 else
                 {
-                    //else find the first dictionary with Row/Column info and use that.
-                    for( int i=0; i<parmsArray.size() && decodeParms == null; i++ )
+                    // else find the first dictionary with Row/Column info and use that.
+                    for (int i = 0; i < parmsArray.size() && decodeParms == null; i++)
                     {
-                        COSDictionary dic = (COSDictionary)parmsArray.getObject( i );
-                        if (dic != null &&
-                                ( dic.getDictionaryObject(COSName.COLUMNS) != null ||
-                                        dic.getDictionaryObject(COSName.ROWS) != null))
+                        COSDictionary dic = (COSDictionary) parmsArray.getObject(i);
+                        if (dic != null
+                                && (dic.getDictionaryObject(COSName.COLUMNS) != null || dic
+                                        .getDictionaryObject(COSName.ROWS) != null))
                         {
                             decodeParms = dic;
                         }
@@ -614,15 +637,15 @@ public class PDCcitt extends PDXObjectIm
                 {
                     blackis1 = 1;
                 }
-                int k = decodeParms.getInt(COSName.K, 0);  // Mandatory parm
+                int k = decodeParms.getInt(COSName.K, 0); // Mandatory parm
                 if (k < 0)
                 {
-                    //T6
+                    // T6
                     comptype = 4;
                 }
                 if (k > 0)
                 {
-                    //T4 2D
+                    // T4 2D
                     comptype = 3;
                     t4options = 1;
                 }
@@ -641,7 +664,7 @@ public class PDCcitt extends PDXObjectIm
 
             addTag(256, cols); // Columns
             addTag(257, rows); // Rows
-            addTag(259, comptype);    // T6
+            addTag(259, comptype); // T6
             addTag(262, blackis1); // Photometric Interpretation
             addTag(273, tiffheader.length); // Offset to start of image data - updated below
             addTag(279, options.getInt(COSName.LENGTH)); // Length of image data
@@ -656,52 +679,51 @@ public class PDCcitt extends PDXObjectIm
 
         /* Tiff types 1 = byte, 2=ascii, 3=short, 4=ulong 5=rational */
 
-        private void addTag(int tag,long value)
+        private void addTag(int tag, long value)
         {
-        // Adds a tag of type 4 (ulong)
+            // Adds a tag of type 4 (ulong)
             int count = ++tiffheader[8];
-            int offset = (count-1)*12 + 10;
-            tiffheader[offset]=(byte)(tag & 0xff);
-            tiffheader[offset+1]=(byte)((tag>>8) & 0xff);
-            tiffheader[offset+2]=4;  // Type Long
-            tiffheader[offset+4]=1;  // One Value
-            tiffheader[offset+8]=(byte)(value & 0xff);
-            tiffheader[offset+9]=(byte)((value>>8) & 0xff);
-            tiffheader[offset+10]=(byte)((value>>16) & 0xff);
-            tiffheader[offset+11]=(byte)((value>>24) & 0xff);
+            int offset = (count - 1) * 12 + 10;
+            tiffheader[offset] = (byte) (tag & 0xff);
+            tiffheader[offset + 1] = (byte) ((tag >> 8) & 0xff);
+            tiffheader[offset + 2] = 4; // Type Long
+            tiffheader[offset + 4] = 1; // One Value
+            tiffheader[offset + 8] = (byte) (value & 0xff);
+            tiffheader[offset + 9] = (byte) ((value >> 8) & 0xff);
+            tiffheader[offset + 10] = (byte) ((value >> 16) & 0xff);
+            tiffheader[offset + 11] = (byte) ((value >> 24) & 0xff);
         }
 
         private void addTag(int tag, short value)
         {
             // Adds a tag of type 3 (short)
             int count = ++tiffheader[8];
-            int offset = (count-1)*12 + 10;
-            tiffheader[offset]=(byte)(tag & 0xff);
-            tiffheader[offset+1]=(byte)((tag>>8) & 0xff);
-            tiffheader[offset+2]=3;  // Type Short
-            tiffheader[offset+4]=1;  // One Value
-            tiffheader[offset+8]=(byte)(value & 0xff);
-            tiffheader[offset+9]=(byte)((value>>8) & 0xff);
+            int offset = (count - 1) * 12 + 10;
+            tiffheader[offset] = (byte) (tag & 0xff);
+            tiffheader[offset + 1] = (byte) ((tag >> 8) & 0xff);
+            tiffheader[offset + 2] = 3; // Type Short
+            tiffheader[offset + 4] = 1; // One Value
+            tiffheader[offset + 8] = (byte) (value & 0xff);
+            tiffheader[offset + 9] = (byte) ((value >> 8) & 0xff);
         }
 
         private void addTag(int tag, String value)
         {
             // Adds a tag of type 2 (ascii)
             int count = ++tiffheader[8];
-            int offset = (count-1)*12 + 10;
-            tiffheader[offset]=(byte)(tag & 0xff);
-            tiffheader[offset+1]=(byte)((tag>>8) & 0xff);
-            tiffheader[offset+2]=2;  // Type Ascii
+            int offset = (count - 1) * 12 + 10;
+            tiffheader[offset] = (byte) (tag & 0xff);
+            tiffheader[offset + 1] = (byte) ((tag >> 8) & 0xff);
+            tiffheader[offset + 2] = 2; // Type Ascii
             int len = value.length() + 1;
-            tiffheader[offset+4]=(byte)(len & 0xff);
-            tiffheader[offset+8]=(byte)(additionalOffset & 0xff);
-            tiffheader[offset+9]=(byte)((additionalOffset>>8) & 0xff);
-            tiffheader[offset+10]=(byte)((additionalOffset>>16) & 0xff);
-            tiffheader[offset+11]=(byte)((additionalOffset>>24) & 0xff);
+            tiffheader[offset + 4] = (byte) (len & 0xff);
+            tiffheader[offset + 8] = (byte) (additionalOffset & 0xff);
+            tiffheader[offset + 9] = (byte) ((additionalOffset >> 8) & 0xff);
+            tiffheader[offset + 10] = (byte) ((additionalOffset >> 16) & 0xff);
+            tiffheader[offset + 11] = (byte) ((additionalOffset >> 24) & 0xff);
             try
             {
-                System.arraycopy(value.getBytes("US-ASCII"), 0,
-                        tiffheader, additionalOffset, value.length());
+                System.arraycopy(value.getBytes("US-ASCII"), 0, tiffheader, additionalOffset, value.length());
             }
             catch (UnsupportedEncodingException e)
             {
@@ -714,23 +736,23 @@ public class PDCcitt extends PDXObjectIm
         {
             // Adds a tag of type 5 (rational)
             int count = ++tiffheader[8];
-            int offset = (count-1)*12 + 10;
-            tiffheader[offset]=(byte)(tag & 0xff);
-            tiffheader[offset+1]=(byte)((tag>>8) & 0xff);
-            tiffheader[offset+2]=5;  // Type Rational
-            tiffheader[offset+4]=1;  // One Value
-            tiffheader[offset+8]=(byte)(additionalOffset & 0xff);
-            tiffheader[offset+9]=(byte)((additionalOffset>>8) & 0xff);
-            tiffheader[offset+10]=(byte)((additionalOffset>>16) & 0xff);
-            tiffheader[offset+11]=(byte)((additionalOffset>>24) & 0xff);
-            tiffheader[additionalOffset++]=(byte) ((numerator) & 0xFF);
-            tiffheader[additionalOffset++]=(byte) ((numerator>>8) & 0xFF);
-            tiffheader[additionalOffset++]=(byte) ((numerator>>16) & 0xFF);
-            tiffheader[additionalOffset++]=(byte) ((numerator>>24) & 0xFF);
-            tiffheader[additionalOffset++]=(byte) ((denominator) & 0xFF);
-            tiffheader[additionalOffset++]=(byte) ((denominator>>8) & 0xFF);
-            tiffheader[additionalOffset++]=(byte) ((denominator>>16) & 0xFF);
-            tiffheader[additionalOffset++]=(byte) ((denominator>>24) & 0xFF);
+            int offset = (count - 1) * 12 + 10;
+            tiffheader[offset] = (byte) (tag & 0xff);
+            tiffheader[offset + 1] = (byte) ((tag >> 8) & 0xff);
+            tiffheader[offset + 2] = 5; // Type Rational
+            tiffheader[offset + 4] = 1; // One Value
+            tiffheader[offset + 8] = (byte) (additionalOffset & 0xff);
+            tiffheader[offset + 9] = (byte) ((additionalOffset >> 8) & 0xff);
+            tiffheader[offset + 10] = (byte) ((additionalOffset >> 16) & 0xff);
+            tiffheader[offset + 11] = (byte) ((additionalOffset >> 24) & 0xff);
+            tiffheader[additionalOffset++] = (byte) ((numerator) & 0xFF);
+            tiffheader[additionalOffset++] = (byte) ((numerator >> 8) & 0xFF);
+            tiffheader[additionalOffset++] = (byte) ((numerator >> 16) & 0xFF);
+            tiffheader[additionalOffset++] = (byte) ((numerator >> 24) & 0xFF);
+            tiffheader[additionalOffset++] = (byte) ((denominator) & 0xFF);
+            tiffheader[additionalOffset++] = (byte) ((denominator >> 8) & 0xFF);
+            tiffheader[additionalOffset++] = (byte) ((denominator >> 16) & 0xFF);
+            tiffheader[additionalOffset++] = (byte) ((denominator >> 24) & 0xFF);
         }
     }
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMap.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMap.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMap.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDPixelMap.java Sun Nov 17 14:31:02 2013
@@ -178,24 +178,23 @@ public class PDPixelMap extends PDXObjec
 
         try
         {
-            int width = getWidth();
-            int height = getHeight();
-            int bpc = getBitsPerComponent();
-
             byte[] array = getPDStream().getByteArray();
             if (array.length == 0)
             {
                 LOG.error("Something went wrong ... the pixelmap doesn't contain any data.");
                 return null;
             }
-            // Get the ColorModel right
+            int width = getWidth();
+            int height = getHeight();
+            int bpc = getBitsPerComponent();
+
             PDColorSpace colorspace = getColorSpace();
             if (colorspace == null)
             {
                 LOG.error("getColorSpace() returned NULL.");
                 return null;
             }
-
+            // Get the ColorModel right
             ColorModel cm = null;
             if (colorspace instanceof PDIndexed)
             {

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObject.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObject.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObject.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObject.java Sun Nov 17 14:31:02 2013
@@ -119,6 +119,20 @@ public abstract class PDXObject implemen
      */
     public static PDXObject createXObject( COSBase xobject ) throws IOException
     {
+        PDXObject retval = commonXObjectCreation(xobject, false);
+        return retval;
+    }
+
+    /**
+     * Create the correct xobject from the cos base.
+     *
+     * @param xobject The cos level xobject to create.
+     * @param isthumb specify if the xobject represent a Thumbnail Image (in this case, the subtype null must be considered as an Image)
+     * @return a pdmodel xobject
+     * @throws IOException If there is an error creating the xobject.
+     */
+    protected static PDXObject commonXObjectCreation(COSBase xobject, boolean isThumb)
+    {
         PDXObject retval = null;
         if( xobject == null )
         {
@@ -128,7 +142,8 @@ public abstract class PDXObject implemen
         {
             COSStream xstream = (COSStream)xobject;
             String subtype = xstream.getNameAsString( COSName.SUBTYPE );
-            if( subtype.equals( PDXObjectImage.SUB_TYPE ) )
+            // according to the PDF Reference : a thumbnail subtype must be Image if it is not null
+            if( PDXObjectImage.SUB_TYPE.equals( subtype ) || (subtype == null && isThumb))
             {
                 PDStream image = new PDStream( xstream );
                 // See if filters are DCT or JPX otherwise treat as Bitmap-like
@@ -157,7 +172,7 @@ public abstract class PDXObject implemen
                     retval = new PDPixelMap(image);
                 }
             }
-            else if( subtype.equals( PDXObjectForm.SUB_TYPE ) )
+            else if( PDXObjectForm.SUB_TYPE.equals( subtype ) )
             {
                 retval = new PDXObjectForm( xstream );
             }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectImage.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectImage.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectImage.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectImage.java Sun Nov 17 14:31:02 2013
@@ -91,6 +91,20 @@ public abstract class PDXObjectImage ext
     }
 
     /**
+     * Create the correct thumbnail from the cos base.
+     *
+     * @param xobject The cos level xobject to create.
+     *
+     * @return a pdmodel xobject
+     * @throws IOException If there is an error creating the xobject.
+     */
+    public static PDXObject createThumbnailXObject( COSBase xobject ) throws IOException
+    {
+        PDXObject retval = commonXObjectCreation(xobject, true);
+        return retval;
+    }
+    
+    /**
      * Returns an java.awt.Image, that can be used for display etc.
      *
      * @return This PDF object as an AWT image.

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/TextNormalize.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/TextNormalize.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/TextNormalize.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/TextNormalize.java Sun Nov 17 14:31:02 2013
@@ -19,52 +19,55 @@ package org.apache.pdfbox.util;
 import java.util.HashMap;
 
 /**
- * This class allows a caller to normalize text in various ways.
- * It will load the ICU4J jar file if it is defined on the classpath.
+ * This class allows a caller to normalize text in various ways. It will load the ICU4J jar file if it is defined on the
+ * classpath.
  * 
  * @author <a href="mailto:carrier@digital-evidence.org">Brian Carrier</a>
- * @version $Revision: 1.0 $
+ * 
  */
-public class TextNormalize 
+public class TextNormalize
 {
     private ICU4JImpl icu4j = null;
-    private static final HashMap DIACHASH = new HashMap();
+    private static final HashMap<Integer, String> DIACHASH = new HashMap<Integer, String>();
     private String outputEncoding;
 
+    static
+    {
+        populateDiacHash();
+    }
+
     /**
      * 
      * @param encoding The Encoding that the text will eventually be written as (or null)
      */
-    public TextNormalize(String encoding) 
+    public TextNormalize(String encoding)
     {
         findICU4J();
-        populateDiacHash();
-        this.outputEncoding = encoding;
+        outputEncoding = encoding;
     }
 
-    private void findICU4J() 
+    private void findICU4J()
     {
         // see if we can load the icu4j classes from the classpath
-        try 
+        try
         {
             this.getClass().getClassLoader().loadClass("com.ibm.icu.text.Bidi");
             this.getClass().getClassLoader().loadClass("com.ibm.icu.text.Normalizer");
             icu4j = new ICU4JImpl();
-        } 
-        catch (ClassNotFoundException e) 
+        }
+        catch (ClassNotFoundException e)
         {
             icu4j = null;
         }
     }
+
     /*
-     * Adds non-decomposing diacritics to the hash with their related
-     * combining character. These are values that the unicode spec claims
-     * are equivalent but are not mapped in the form NFKC normalization method.
-     * Determined by going through the Combining Diacritical Marks section of 
-     * the Unicode spec and identifying which characters are not mapped to by 
-     * the normalization. 
+     * Adds non-decomposing diacritics to the hash with their related combining character. These are values that the
+     * unicode spec claims are equivalent but are not mapped in the form NFKC normalization method. Determined by going
+     * through the Combining Diacritical Marks section of the Unicode spec and identifying which characters are not
+     * mapped to by the normalization.
      */
-    private void populateDiacHash()
+    private static void populateDiacHash()
     {
         DIACHASH.put(new Integer(0x0060), "\u0300");
         DIACHASH.put(new Integer(0x02CB), "\u0300");
@@ -100,74 +103,70 @@ public class TextNormalize 
     }
 
     /**
-     * Takes a line of text in presentation order and converts it to logical order.
-     * For most text other than Arabic and Hebrew, the presentation and logical
-     * orders are the same. However, for Arabic and Hebrew, they are different and
-     * if the text involves both RTL and LTR text then the Unicode BIDI algorithm
-     * must be used to determine how to map between them.  
+     * Takes a line of text in presentation order and converts it to logical order. For most text other than Arabic and
+     * Hebrew, the presentation and logical orders are the same. However, for Arabic and Hebrew, they are different and
+     * if the text involves both RTL and LTR text then the Unicode BIDI algorithm must be used to determine how to map
+     * between them.
      * 
      * @param str Presentation form of line to convert (i.e. left most char is first char)
      * @param isRtlDominant true if the PAGE has a dominant right to left ordering
      * @return Logical form of string (or original string if ICU4J library is not on classpath)
      */
-    public String makeLineLogicalOrder(String str, boolean isRtlDominant) 
+    public String makeLineLogicalOrder(String str, boolean isRtlDominant)
     {
-        if (icu4j != null) 
+        if (icu4j != null)
         {
             return icu4j.makeLineLogicalOrder(str, isRtlDominant);
         }
-        else 
+        else
         {
             return str;
         }
     }
 
     /**
-     * Normalize the presentation forms of characters in the string.
-     * For example, convert the single "fi" ligature to "f" and "i".
+     * Normalize the presentation forms of characters in the string. For example, convert the single "fi" ligature to
+     * "f" and "i".
      * 
      * @param str String to normalize
      * @return Normalized string (or original string if ICU4J library is not on classpath)
      */
-    public String normalizePres(String str) 
+    public String normalizePres(String str)
     {
-        if (icu4j != null) 
+        if (icu4j != null)
         {
             return icu4j.normalizePres(str);
         }
-        else 
+        else
         {
             return str;
         }
     }
-    
+
     /**
-     * Normalize the diacritic, for example, 
-     * convert non-combining diacritic characters to their combining
-     * counterparts. 
+     * Normalize the diacritic, for example, convert non-combining diacritic characters to their combining counterparts.
      * 
-     * @param str String to normalize 
+     * @param str String to normalize
      * @return Normalized string (or original string if ICU4J library is not on classpath)
      */
     public String normalizeDiac(String str)
     {
         /*
-         * Unicode contains special combining forms of the diacritic characters
-         * and we want to use these. 
+         * Unicode contains special combining forms of the diacritic characters and we want to use these.
          */
-        if(outputEncoding != null && outputEncoding.toUpperCase().startsWith("UTF"))
+        if (outputEncoding != null && outputEncoding.toUpperCase().startsWith("UTF"))
         {
             Integer c = new Integer(str.charAt(0));
             // convert the characters not defined in the Unicode spec
-            if(DIACHASH.containsKey(c))
+            if (DIACHASH.containsKey(c))
             {
-                return (String)DIACHASH.get(c);
+                return (String) DIACHASH.get(c);
             }
-            else if (icu4j != null) 
+            else if (icu4j != null)
             {
                 return icu4j.normalizeDiac(str);
             }
-            else 
+            else
             {
                 return str;
             }

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConstants.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConstants.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConstants.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConstants.java Sun Nov 17 14:31:02 2013
@@ -940,11 +940,7 @@ public interface PreflightConstants
      * a category has an invalid value in one property description (must be internal or external)
      */
     String ERROR_METADATA_CATEGORY_PROPERTY_INVALID = "7.5.1";
-
-    /**
-     * the infor dictionary is corrupt or value can't be read
-     */
-    String ERROR_METADATA_DICT_INFO_CORRUPT = "7.12";
+    
     /**
      * Error about PDF processing : that is not necessary a specific PDF/A validation error
      * but a PDF specification requirement that isn't respected.
@@ -954,4 +950,8 @@ public interface PreflightConstants
      * A Mandatory element is missing
      */
     String ERROR_PDF_PROCESSING_MISSING = "8.1";
+    /**
+     * the infor dictionary is corrupt or value can't be read
+     */
+    String ERROR_METADATA_DICT_INFO_CORRUPT = "7.12";
 }

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java Sun Nov 17 14:31:02 2013
@@ -165,7 +165,7 @@ public class PreflightDocument extends P
         Collection<String> processes = config.getProcessNames();
         for (String name : processes)
         {
-            ContextHelper.validateElement(context, name);
+                ContextHelper.validateElement(context, name);
         }
     }
 

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/action/ActionManagerFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/action/ActionManagerFactory.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/action/ActionManagerFactory.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/action/ActionManagerFactory.java Sun Nov 17 14:31:02 2013
@@ -40,7 +40,7 @@ import static org.apache.pdfbox.prefligh
 import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_TYPE;
 import static org.apache.pdfbox.preflight.PreflightConstants.DICTIONARY_KEY_ADDITIONAL_ACTION;
 import static org.apache.pdfbox.preflight.PreflightConstants.DICTIONARY_KEY_OPEN_ACTION;
-
+import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -53,6 +53,7 @@ import org.apache.pdfbox.cos.COSDocument
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.persistence.util.COSObjectKey;
+import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.exception.ValidationException;
 import org.apache.pdfbox.preflight.utils.COSUtils;
@@ -176,7 +177,7 @@ public class ActionManagerFactory
         }
         else
         {
-            throw new ValidationException("Action entry isn't an instance of COSDictionary");
+            ctx.addValidationError(new ValidationError(PreflightConstants.ERROR_ACTION_INVALID_TYPE, "Action entry isn't an instance of COSDictionary"));
         }
     }
 

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/content/ContentStreamWrapper.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/content/ContentStreamWrapper.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/content/ContentStreamWrapper.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/content/ContentStreamWrapper.java Sun Nov 17 14:31:02 2013
@@ -43,6 +43,7 @@ import org.apache.pdfbox.pdmodel.font.PD
 import org.apache.pdfbox.pdmodel.graphics.PDGraphicsState;
 import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
 import org.apache.pdfbox.pdmodel.text.PDTextState;
+import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.ValidationException;

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type3FontValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type3FontValidator.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type3FontValidator.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type3FontValidator.java Sun Nov 17 14:31:02 2013
@@ -276,7 +276,7 @@ public class Type3FontValidator extends 
      */
     private void checkCharProcsAndMetrics() throws ValidationException
     {
-        List<Float> widths = font.getWidths();
+        List<Integer> widths = font.getWidths();
         if (widths == null || widths.isEmpty())
         {
             this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID,
@@ -460,7 +460,8 @@ public class Type3FontValidator extends 
                     }
                     catch (IOException e)
                     {
-                        throw new ValidationException("Unable to valid the Type3 : " + e.getMessage());
+                        context.addValidationError(new ValidationError(PreflightConstants.ERROR_FONTS_DAMAGED,
+                                "Unable to valid the Type3 : " + e.getMessage()));
                     }
                 }
             }

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java?rev=1542735&r1=1542734&r2=1542735&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java Sun Nov 17 14:31:02 2013
@@ -361,8 +361,8 @@ public class PreflightParser extends Non
         while (true)
         {
             // just after the xref<EOL> there are an integer
-            int currObjID = 0; // first obj id
-            int count = 0; // the number of objects in the xref table
+            long currObjID = 0; // first obj id
+            long count = 0; // the number of objects in the xref table
 
             long offset = pdfSource.getOffset();
             String line = readLine();
@@ -379,8 +379,8 @@ public class PreflightParser extends Non
                         "Cross reference subsection header is invalid"));
                 // reset pdfSource cursor to read xref information
                 pdfSource.seek(offset);
-                currObjID = readInt(); // first obj id
-                count = readInt(); // the number of objects in the xref table
+                currObjID = readObjectNumber(); // first obj id
+                count = readLong(); // the number of objects in the xref table
             }
 
             skipSpaces();
@@ -678,7 +678,7 @@ public class PreflightParser extends Non
                 // ---- go to object start
                 setPdfSource(offsetOrObjstmObNr);
                 // ---- we must have an indirect object
-                int readObjNr = 0;
+                long readObjNr = 0;
                 int readObjGen = 0;
 
                 long offset = pdfSource.getOffset();
@@ -697,8 +697,8 @@ public class PreflightParser extends Non
 
                     // reset pdfSource cursor to read object information
                     pdfSource.seek(offset);
-                    readObjNr = readInt();
-                    readObjGen = readInt();
+                    readObjNr = readObjectNumber();
+                    readObjGen = readGenerationNumber();
                     skipSpaces(); // skip spaces between Object Generation number and the 'obj' keyword 
                     for (char c : OBJ_MARKER)
                     {