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 2011/12/26 18:30:20 UTC

svn commit: r1224778 - in /pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight: ./ contentstream/ font/ helpers/

Author: leleueri
Date: Mon Dec 26 17:30:20 2011
New Revision: 1224778

URL: http://svn.apache.org/viewvc?rev=1224778&view=rev
Log:
[PDFBOX-1195] Font Validation Problem :
- Remove useless control in the CIDFontType2 validation.
- Check the WMode value to know if the WMode is missing from the Dictionary
- manage the CIDToGID map stream.

Added:
    pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CIDToGIDMap.java   (with props)
Modified:
    pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/ValidationConstants.java
    pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/contentstream/ContentStreamWrapper.java
    pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CFFType2FontContainer.java
    pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CompositeFontValidator.java
    pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/helpers/CatalogValidationHelper.java

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/ValidationConstants.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/ValidationConstants.java?rev=1224778&r1=1224777&r2=1224778&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/ValidationConstants.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/ValidationConstants.java Mon Dec 26 17:30:20 2011
@@ -167,6 +167,7 @@ public interface ValidationConstants {
   static String FONT_DICTIONARY_KEY_CMAP_WMODE = "WMode";
   static String FONT_DICTIONARY_KEY_CMAP_USECMAP = "UseCMap";
   static String FONT_DICTIONARY_KEY_CIDSET = "CIDSet";
+  static int FONT_DICTIONARY_DEFAULT_CMAP_WMODE= 0;
 
   static String STREAM_DICTIONARY_KEY_LENGHT = "Length";
   static String STREAM_DICTIONARY_KEY_FILTER = "Filter";

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/contentstream/ContentStreamWrapper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/contentstream/ContentStreamWrapper.java?rev=1224778&r1=1224777&r2=1224778&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/contentstream/ContentStreamWrapper.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/contentstream/ContentStreamWrapper.java Mon Dec 26 17:30:20 2011
@@ -32,13 +32,12 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
-
 import org.apache.padaf.preflight.DocumentHandler;
 import org.apache.padaf.preflight.ValidationException;
 import org.apache.padaf.preflight.ValidationResult.ValidationError;
 import org.apache.padaf.preflight.font.AbstractFontContainer;
-import org.apache.padaf.preflight.font.GlyphException;
 import org.apache.padaf.preflight.font.AbstractFontContainer.State;
+import org.apache.padaf.preflight.font.GlyphException;
 import org.apache.padaf.preflight.utils.ContentStreamEngine;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSDictionary;

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CFFType2FontContainer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CFFType2FontContainer.java?rev=1224778&r1=1224777&r2=1224778&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CFFType2FontContainer.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CFFType2FontContainer.java Mon Dec 26 17:30:20 2011
@@ -21,7 +21,6 @@
 
 package org.apache.padaf.preflight.font;
 
-import org.apache.fontbox.cmap.CMap;
 import org.apache.fontbox.ttf.TrueTypeFont;
 import org.apache.padaf.preflight.ValidationConstants;
 
@@ -32,7 +31,7 @@ public class CFFType2FontContainer exten
 	 * extracted by the TrueTypeParser object
 	 */
 	private TrueTypeFont fontObject = null;
-	private CMap cidToGidMap = null;
+	private CIDToGIDMap cidToGidMap = null;
 
 	private int numberOfLongHorMetrics;
 	private int unitsPerEm;
@@ -84,25 +83,10 @@ public class CFFType2FontContainer exten
 		int glyphIndex = cid;
 
 		if (this.cidToGidMap != null) {
-			byte[] cidAsByteArray = null;
-			if (cid < 256) {
-				cidAsByteArray = new byte[1];
-				cidAsByteArray[0] = (byte) (cid & 0xFF);
-			} else {
-				cidAsByteArray = new byte[1];
-				cidAsByteArray[0] = (byte) ((cid >> 8) & 0xFF);
-				cidAsByteArray[1] = (byte) (cid & 0xFF);
-			}
-
-			String glyphIdAsString = this.cidToGidMap.lookup(cidAsByteArray, 0,	cidAsByteArray.length);
-			// ---- glyphIdAsString should be a Integer
-			// TODO OD-PDFA-4 : A vérifier avec un PDF qui contient une stream pour
-			// CidToGid...
-			try {
-				glyphIndex = Integer.parseInt(glyphIdAsString);
-			} catch (NumberFormatException e) {
+			glyphIndex = cidToGidMap.getGID(cid);
+			if (glyphIndex==cidToGidMap.NOTDEF_GLYPH_INDEX) {
 				GlyphException ge = new GlyphException(ValidationConstants.ERROR_FONTS_GLYPH_MISSING, cid, 
-						"CID " + cid + " isn't linked with a GlyphIndex >> " + glyphIdAsString);
+						"CID " + cid + " can't be found in the cidToGid map");
 				addKnownCidElement(new GlyphDetail(cid, ge));
 				throw ge;
 			}
@@ -114,7 +98,7 @@ public class CFFType2FontContainer exten
 		this.fontObject = fontObject;
 	}
 
-	void setCmap(CMap cmap) {
+	void setCmap(CIDToGIDMap cmap) {
 		this.cidToGidMap = cmap;
 	}
 

Added: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CIDToGIDMap.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CIDToGIDMap.java?rev=1224778&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CIDToGIDMap.java (added)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CIDToGIDMap.java Mon Dec 26 17:30:20 2011
@@ -0,0 +1,66 @@
+/*****************************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ ****************************************************************************/
+
+package org.apache.padaf.preflight.font;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.pdfbox.cos.COSStream;
+
+public class CIDToGIDMap {
+
+	public final int NOTDEF_GLYPH_INDEX = 0;
+	private byte[] map = null;
+	
+	/**
+	 * Copy the unfiltered stream content in a byte array.
+	 * @param stream
+	 * @throws IOException if the stream can't be copied
+	 */
+	public void parseStream(COSStream stream) throws IOException {
+		InputStream is = stream.getUnfilteredStream();
+		ByteArrayOutputStream os = new ByteArrayOutputStream();
+		
+		try {
+			IOUtils.copy(stream.getUnfilteredStream(), os);
+			map  = os.toByteArray();
+		} catch (IOException e) {
+			IOUtils.closeQuietly(is);
+			IOUtils.closeQuietly(os);
+		}
+	}
+	
+	/**
+	 * Return the glyph index according to the CID.
+	 * @param cid
+	 * @return
+	 */
+	public int getGID(int cid) {
+		if (map == null || (cid*2+1) >= map.length) {
+			return NOTDEF_GLYPH_INDEX;
+		}
+		int index = cid*2;
+		return ((map[index]&0xFF)<<8)^(map[index+1]&0xFF);
+	}
+}
\ No newline at end of file

Propchange: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CIDToGIDMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CompositeFontValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CompositeFontValidator.java?rev=1224778&r1=1224777&r2=1224778&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CompositeFontValidator.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CompositeFontValidator.java Mon Dec 26 17:30:20 2011
@@ -55,12 +55,12 @@ public class CompositeFontValidator exte
 	protected COSStream cmap;
 	protected COSBase toUnicode;
 
-	protected CMap cidToGidMap = null;
+	protected CIDToGIDMap cidToGidMap = null;
 
 	protected boolean isIdentityCMap = false;
 
 	public CompositeFontValidator(DocumentHandler handler, COSObject obj)
-	throws ValidationException {
+			throws ValidationException {
 		super(handler, obj);
 	}
 
@@ -83,7 +83,7 @@ public class CompositeFontValidator exte
 				|| (subtype == null || "".equals(subtype))) {
 			this.fontContainer.addError(new ValidationError(
 					ERROR_FONTS_DICTIONARY_INVALID,
-			"Type and/or Subtype keys are missing"));
+					"Type and/or Subtype keys are missing"));
 			return false;
 		}
 
@@ -101,7 +101,7 @@ public class CompositeFontValidator exte
 			// rule
 			this.fontContainer.addError(new ValidationError(
 					ERROR_FONTS_DICTIONARY_INVALID,
-			"BaseFont, Encoding or DescendantFonts keys are missing"));
+					"BaseFont, Encoding or DescendantFonts keys are missing"));
 			return false;
 		}
 
@@ -133,7 +133,7 @@ public class CompositeFontValidator exte
 		if (array == null) {
 			this.fontContainer.addError(new ValidationError(
 					ERROR_FONTS_CIDKEYED_INVALID,
-			"CIDFont is missing from the DescendantFonts array"));
+					"CIDFont is missing from the DescendantFonts array"));
 			return false;
 		}
 		// ---- in PDF 1.4, this array must contain only one element,
@@ -143,7 +143,7 @@ public class CompositeFontValidator exte
 		if (array.size() != 1) {
 			this.fontContainer.addError(new ValidationError(
 					ERROR_FONTS_CIDKEYED_INVALID,
-			"The DescendantFonts array should have one element."));
+					"The DescendantFonts array should have one element."));
 			return false;
 		}
 
@@ -151,7 +151,7 @@ public class CompositeFontValidator exte
 		if (this.cidFont == null) {
 			this.fontContainer
 			.addError(new ValidationError(ERROR_FONTS_CIDKEYED_INVALID,
-			"The DescendantFonts array should have one element with is a dictionary."));
+					"The DescendantFonts array should have one element with is a dictionary."));
 			return false;
 		}
 
@@ -164,7 +164,7 @@ public class CompositeFontValidator exte
 				|| (subtype == null || "".equals(subtype))) {
 			this.fontContainer.addError(new ValidationError(
 					ERROR_FONTS_DICTIONARY_INVALID,
-			"Type and/or Subtype keys are missing"));
+					"Type and/or Subtype keys are missing"));
 			return false;
 		}
 
@@ -174,7 +174,7 @@ public class CompositeFontValidator exte
 		if (!FONT_DICTIONARY_VALUE_FONT.equals(type) || !(isT0 || isT2)) {
 			this.fontContainer.addError(new ValidationError(
 					ERROR_FONTS_DICTIONARY_INVALID,
-			"Type and/or Subtype keys are missing"));
+					"Type and/or Subtype keys are missing"));
 			return false;
 		}
 
@@ -273,8 +273,8 @@ public class CompositeFontValidator exte
 		} else if (COSUtils.isStream(ctog, cDoc)) {
 			try {
 				COSStream ctogMap = COSUtils.getAsStream(ctog, cDoc);
-				this.cidToGidMap = new CMapParser().parse(null, ctogMap
-						.getUnfilteredStream());
+				this.cidToGidMap = new CIDToGIDMap();
+				this.cidToGidMap.parseStream(ctogMap);
 			} catch (IOException e) {
 				// ---- map can be invalid, return a Validation Error
 				this.fontContainer.addError(new ValidationError(
@@ -308,7 +308,7 @@ public class CompositeFontValidator exte
 					.equals(str))) {
 				this.fontContainer.addError(new ValidationError(
 						ERROR_FONTS_CIDKEYED_INVALID,
-				"The CMap is a string but it isn't an Identity-H/V"));
+						"The CMap is a string but it isn't an Identity-H/V"));
 				return false;
 			}
 			isIdentityCMap = true;
@@ -321,7 +321,7 @@ public class CompositeFontValidator exte
 			// ---- CMap type is invalid
 			this.fontContainer.addError(new ValidationError(
 					ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING,
-			"The CMap type is invalid"));
+					"The CMap type is invalid"));
 			return false;
 		}
 		return true;
@@ -340,22 +340,24 @@ public class CompositeFontValidator exte
 	private boolean processCMapAsStream(COSStream aCMap) {
 		COSDocument cDoc = handler.getDocument().getDocument();
 
-		String type = aCMap
-		.getNameAsString(COSName.getPDFName(DICTIONARY_KEY_TYPE));
-		String cmapName = aCMap.getNameAsString(COSName
-				.getPDFName(FONT_DICTIONARY_KEY_CMAP_NAME));
-		COSBase sysinfo = aCMap.getItem(COSName
-				.getPDFName(FONT_DICTIONARY_KEY_CID_SYSINFO));
-		int wmode = aCMap
-		.getInt(COSName.getPDFName(FONT_DICTIONARY_KEY_CMAP_WMODE));
-		COSBase cmapUsed = aCMap.getItem(COSName
-				.getPDFName(FONT_DICTIONARY_KEY_CMAP_USECMAP));
+		String type = aCMap.getNameAsString(COSName.getPDFName(DICTIONARY_KEY_TYPE));
+		String cmapName = aCMap.getNameAsString(COSName.getPDFName(FONT_DICTIONARY_KEY_CMAP_NAME));
+		COSBase sysinfo = aCMap.getItem(COSName.getPDFName(FONT_DICTIONARY_KEY_CID_SYSINFO));
+		int wmode = aCMap.getInt(COSName.getPDFName(FONT_DICTIONARY_KEY_CMAP_WMODE));
+		if (wmode == -1) {
+			/*
+			 * According to the getInt javadoc, -1 is returned if there are no result.
+			 * In the PDF Reference v1.7 p449, we can read that Default value is 0.
+			 */
+			wmode = FONT_DICTIONARY_DEFAULT_CMAP_WMODE;
+		}
+		COSBase cmapUsed = aCMap.getItem(COSName.getPDFName(FONT_DICTIONARY_KEY_CMAP_USECMAP));
 
 		if (!FONT_DICTIONARY_VALUE_TYPE_CMAP.equals(type)) {
 			// ---- CMap type is invalid
 			this.fontContainer.addError(new ValidationError(
 					ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING,
-			"The CMap type is invalid"));
+					"The CMap type is invalid"));
 			return false;
 		}
 
@@ -367,23 +369,22 @@ public class CompositeFontValidator exte
 		if (cmapName == null || "".equals(cmapName) || wmode > 1) {
 			this.fontContainer.addError(new ValidationError(
 					ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING,
-			"Some elements in the CMap dictionary are missing or invalid"));
+					"Some elements in the CMap dictionary are missing or invalid"));
 			return false;
 		}
 
 		try {
 
-			CMap fontboxCMap = new CMapParser().parse(null, aCMap
-					.getUnfilteredStream());
+			CMap fontboxCMap = new CMapParser().parse(null, aCMap.getUnfilteredStream());
 			int wmValue = fontboxCMap.getWMode();
-			String cmnValue = fontboxCMap.getName(); //getCmapEntry("CMapName");
+			String cmnValue = fontboxCMap.getName();
 
 
 			if (wmValue != wmode) {
 
 				this.fontContainer.addError(new ValidationError(
 						ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING,
-				"WMode is inconsistent"));
+						"WMode is inconsistent"));
 				return false;
 			}
 
@@ -391,7 +392,7 @@ public class CompositeFontValidator exte
 
 				this.fontContainer.addError(new ValidationError(
 						ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING,
-				"CMapName is inconsistent"));
+						"CMapName is inconsistent"));
 				return false;
 			}
 
@@ -480,7 +481,7 @@ public class CompositeFontValidator exte
 			if (!(key instanceof COSName)) {
 				this.fontContainer.addError(new ValidationResult.ValidationError(
 						ValidationConstants.ERROR_SYNTAX_DICTIONARY_KEY_INVALID,
-				"Invalid key in The font descriptor"));
+						"Invalid key in The font descriptor"));
 				return false;
 			}
 
@@ -530,12 +531,12 @@ public class CompositeFontValidator exte
 	 * @throws ValidationException
 	 */
 	protected boolean processCIDFontType0(COSBase fontDesc)
-	throws ValidationException {
+			throws ValidationException {
 		COSDictionary fontDescDic = COSUtils.getAsDictionary(fontDesc, handler
 				.getDocument().getDocument());
 		if (fontDescDic == null) {
 			throw new ValidationException(
-			"Unable to process CIDFontType0 because of the font descriptor is invalid.");
+					"Unable to process CIDFontType0 because of the font descriptor is invalid.");
 		}
 		PDFontDescriptorDictionary pfDescriptor = new PDFontDescriptorDictionary(
 				fontDescDic);
@@ -569,7 +570,7 @@ public class CompositeFontValidator exte
 		if (fontName == null) {
 			this.fontContainer.addError(new ValidationResult.ValidationError(
 					ERROR_FONTS_DESCRIPTOR_INVALID,
-			"The FontName in font descriptor is missing"));
+					"The FontName in font descriptor is missing"));
 			return false;
 		}
 
@@ -579,7 +580,7 @@ public class CompositeFontValidator exte
 			this.fontContainer
 			.addError(new ValidationResult.ValidationError(
 					ERROR_FONTS_DESCRIPTOR_INVALID,
-			"The FontName in font descriptor isn't the same as the BaseFont in the Font dictionary"));
+					"The FontName in font descriptor isn't the same as the BaseFont in the Font dictionary"));
 			return false;
 		}
 		return true;
@@ -601,8 +602,8 @@ public class CompositeFontValidator exte
 		PDStream ff3 = pfDescriptor.getFontFile3();
 
 		boolean onlyOne = (ff1 != null && ff2 == null && ff3 == null)
-		|| (ff1 == null && ff2 != null && ff3 == null)
-		|| (ff1 == null && ff2 == null && ff3 != null);
+				|| (ff1 == null && ff2 != null && ff3 == null)
+				|| (ff1 == null && ff2 == null && ff3 != null);
 
 		if ((ff3 == null) || !onlyOne) {
 			this.fontContainer.addError(new ValidationResult.ValidationError(
@@ -628,7 +629,7 @@ public class CompositeFontValidator exte
 				.equals(st))) {
 			this.fontContainer.addError(new ValidationResult.ValidationError(
 					ERROR_FONTS_FONT_FILEX_INVALID,
-			"The FontFile3 stream doesn't have the right Subtype"));
+					"The FontFile3 stream doesn't have the right Subtype"));
 			return false;
 		}
 
@@ -645,7 +646,7 @@ public class CompositeFontValidator exte
 			}
 
 			return checkCIDFontWidths(lCFonts)
-			&& checkFontFileMetaData(pfDescriptor, ff3);
+					&& checkFontFileMetaData(pfDescriptor, ff3);
 		} catch (IOException e) {
 			this.fontContainer.addError(new ValidationResult.ValidationError(
 					ERROR_FONTS_CID_DAMAGED, "The FontFile can't be read"));
@@ -663,7 +664,7 @@ public class CompositeFontValidator exte
 	 * @throws ValidationException
 	 */
 	protected boolean checkTTFontMetrics(TrueTypeFont ttf)
-	throws ValidationException {
+			throws ValidationException {
 		int unitsPerEm = ttf.getHeader().getUnitsPerEm();
 		int[] glyphWidths = ttf.getHorizontalMetrics().getAdvanceWidth();
 		/* In a Mono space font program, the length of the AdvanceWidth array must be one.
@@ -690,7 +691,7 @@ public class CompositeFontValidator exte
 	 * @throws ValidationException
 	 */
 	protected boolean checkCIDFontWidths(List<CFFFont> lCFonts)
-	throws ValidationException {
+			throws ValidationException {
 		// ---- Extract Widths and default Width from the CIDFont dictionary
 		CFFType0FontContainer type0FontContainer = ((CompositeFontContainer)this.fontContainer).getCFFType0();
 		type0FontContainer.setFontObject(lCFonts);
@@ -713,8 +714,8 @@ public class CompositeFontValidator exte
 		PDStream ff3 = pfDescriptor.getFontFile3();
 
 		boolean onlyOne = (ff1 != null && ff2 == null && ff3 == null)
-		|| (ff1 == null && ff2 != null && ff3 == null)
-		|| (ff1 == null && ff2 == null && ff3 != null);
+				|| (ff1 == null && ff2 != null && ff3 == null)
+				|| (ff1 == null && ff2 == null && ff3 != null);
 
 		if ((ff2 == null) || !onlyOne) {
 			this.fontContainer.addError(new ValidationResult.ValidationError(
@@ -732,33 +733,24 @@ public class CompositeFontValidator exte
 			return false;
 		}
 
-		boolean hasLength1 = stream.getInt(COSName
-				.getPDFName(FONT_DICTIONARY_KEY_LENGTH1)) > 0;
-				if (!hasLength1) {
-					this.fontContainer.addError(new ValidationResult.ValidationError(
-							ValidationConstants.ERROR_FONTS_FONT_FILEX_INVALID,
-					"The FontFile is invalid"));
-					return false;
-				}
-
-				// ---- try to load the font using the java.awt.font object.
-				// ---- if the font is invalid, an exception will be thrown
-				TrueTypeFont ttf = null;
-				try {
-					// ---- According to PDF Reference, CIDFontType2 is a TrueType font.
-					// ---- Remark : Java.awt.Font throws exception when a CIDFontType2 is
-					// parsed even if it is valid.
-					ttf = new CIDFontType2Parser(true).parseTTF(new ByteArrayInputStream(ff2
-							.getByteArray()));
-				} catch (Exception e) {
-					// ---- Exceptionally, Exception is catched Here because of damaged font
-					// can throw NullPointer Exception...
-					this.fontContainer.addError(new ValidationResult.ValidationError(
-							ERROR_FONTS_CID_DAMAGED, "The FontFile can't be read"));
-					return false;
-				}
+		// ---- try to load the font using the java.awt.font object.
+		// ---- if the font is invalid, an exception will be thrown
+		TrueTypeFont ttf = null;
+		try {
+			// ---- According to PDF Reference, CIDFontType2 is a TrueType font.
+			// ---- Remark : Java.awt.Font throws exception when a CIDFontType2 is
+			// parsed even if it is valid.
+			ttf = new CIDFontType2Parser(true).parseTTF(new ByteArrayInputStream(ff2
+					.getByteArray()));
+		} catch (Exception e) {
+			// ---- Exceptionally, Exception is catched Here because of damaged font
+			// can throw NullPointer Exception...
+			this.fontContainer.addError(new ValidationResult.ValidationError(
+					ERROR_FONTS_CID_DAMAGED, "The FontFile can't be read"));
+			return false;
+		}
 
-				return checkTTFontMetrics(ttf) && checkFontFileMetaData(pfDescriptor, ff2);
+		return checkTTFontMetrics(ttf) && checkFontFileMetaData(pfDescriptor, ff2);
 	}
 
 	/**
@@ -778,7 +770,7 @@ public class CompositeFontValidator exte
 							.getDocument())) {
 				this.fontContainer.addError(new ValidationResult.ValidationError(
 						ERROR_FONTS_CIDSET_MISSING_FOR_SUBSET,
-				"The CIDSet entry is missing for the Composite Subset"));
+						"The CIDSet entry is missing for the Composite Subset"));
 				return false;
 			}
 		}
@@ -792,12 +784,12 @@ public class CompositeFontValidator exte
 	 * @throws ValidationException
 	 */
 	protected boolean processCIDFontType2(COSBase fontDesc)
-	throws ValidationException {
+			throws ValidationException {
 		COSDictionary fontDescDic = COSUtils.getAsDictionary(fontDesc, handler
 				.getDocument().getDocument());
 		if (fontDescDic == null) {
 			throw new ValidationException(
-			"Unable to process CIDFontType2 because of the font descriptor is invalid.");
+					"Unable to process CIDFontType2 because of the font descriptor is invalid.");
 		}
 		PDFontDescriptorDictionary pfDescriptor = new PDFontDescriptorDictionary(
 				fontDescDic);

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/helpers/CatalogValidationHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/helpers/CatalogValidationHelper.java?rev=1224778&r1=1224777&r2=1224778&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/helpers/CatalogValidationHelper.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/helpers/CatalogValidationHelper.java Mon Dec 26 17:30:20 2011
@@ -387,7 +387,7 @@ public class CatalogValidationHelper ext
 			if (handler.getIccProfileWrapper() == null) {
 				handler.setIccProfileWrapper(new ICCProfileWrapper(iccp));
 			}
-
+			
 			// ---- keep reference to avoid multiple profile definition
 			mapDestOutputProfile.put(new COSObjectKey((COSObject) destOutputProfile),
 					true);