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/02 13:36:17 UTC

svn commit: r1209448 - /pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/

Author: leleueri
Date: Fri Dec  2 12:36:16 2011
New Revision: 1209448

URL: http://svn.apache.org/viewvc?rev=1209448&view=rev
Log:
https://issues.apache.org/jira/browse/PDFBOX-1162.
Use the PDFont.getFontWidth(int) method to get the Width of a character declared in the PDF Dictionary.

Modified:
    pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/AbstractFontContainer.java
    pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CFFType0FontContainer.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/font/TrueTypeFontContainer.java
    pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/TrueTypeFontValidator.java
    pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/Type1FontContainer.java
    pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/Type1FontValidator.java

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/AbstractFontContainer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/AbstractFontContainer.java?rev=1209448&r1=1209447&r2=1209448&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/AbstractFontContainer.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/AbstractFontContainer.java Fri Dec  2 12:36:16 2011
@@ -160,8 +160,8 @@ public abstract class AbstractFontContai
 
   protected void checkWidthsConsistency(int cid, float widthProvidedByPdfDictionary, float widthInFontProgram) throws GlyphException {
 	  // a delta of 1/1000 unit is allowed
-	  float epsilon = widthInFontProgram/1000;
-	  if(!(Math.floor(widthInFontProgram-epsilon) <= widthProvidedByPdfDictionary && Math.round(widthInFontProgram+epsilon) >= widthProvidedByPdfDictionary)) {
+	  final float epsilon = widthInFontProgram/1000;
+	  	  if(!(Math.floor(widthInFontProgram-epsilon) <= widthProvidedByPdfDictionary && Math.round(widthInFontProgram+epsilon) >= widthProvidedByPdfDictionary)) {
 		  GlyphException e = new GlyphException(ValidationConstants.ERROR_FONTS_METRICS, cid, 
 				  				"Width of the character \"" + cid 
 				  				+ "\" in the font program \""

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CFFType0FontContainer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CFFType0FontContainer.java?rev=1209448&r1=1209447&r2=1209448&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CFFType0FontContainer.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/CFFType0FontContainer.java Fri Dec  2 12:36:16 2011
@@ -23,10 +23,7 @@ package org.apache.padaf.preflight.font;
 
 import java.io.IOException;
 import java.util.Collection;
-import java.util.LinkedHashMap;
 import java.util.List;
-import java.util.Map;
-
 
 import org.apache.fontbox.cff.CFFFont;
 import org.apache.fontbox.cff.CFFFont.Mapping;
@@ -34,13 +31,6 @@ import org.apache.padaf.preflight.Valida
 
 
 public class CFFType0FontContainer extends AbstractFontContainer {
-	private Map<Integer, Integer> widthsArray = new LinkedHashMap<Integer, Integer>(0);
-	/**
-	 * Represent the missingWidth value of the FontDescriptor dictionary.
-	 * According to the PDF Reference, if this value is missing, the default 
-	 * one is 0.
-	 */
-	private float defaultGlyphWidth = 0;
 	/**
 	 * Object which contains the CFF data extracted by the
 	 * CFFParser object
@@ -58,7 +48,7 @@ public class CFFType0FontContainer exten
 	public void checkCID(int cid) throws GlyphException {
 	  if (isAlreadyComputedCid(cid)) {
 		  return;
-	  }
+	  } 
 
 		// ---- build the font container and keep it in the Handler.
 	  boolean cidFound = false;
@@ -81,13 +71,13 @@ public class CFFType0FontContainer exten
 			throw ge;
 		}
 
-
-		float widthProvidedByPdfDictionary = this.defaultGlyphWidth;
-		if (this.widthsArray.containsKey(cid)) {
-			widthProvidedByPdfDictionary = this.widthsArray.get(cid);
+		final float widthProvidedByPdfDictionary = this.font.getFontWidth(cid);
+		float defaultGlyphWidth = 0;
+		if (this.font.getFontDescriptor() != null) {
+			defaultGlyphWidth = this.font.getFontDescriptor().getMissingWidth();
 		}
+		
 		float widthInFontProgram = 0;
-
 		try {
 			// ---- Search the CID in all CFFFont in the FontProgram
 			for (CFFFont cff : fontObject) {
@@ -103,18 +93,10 @@ public class CFFType0FontContainer exten
 			throw ge;
 		}
 
-		checkWidthsConsistency(cid, widthProvidedByPdfDictionary, widthInFontProgram);
+	  checkWidthsConsistency(cid, widthProvidedByPdfDictionary, widthInFontProgram);
 	  addKnownCidElement(new GlyphDetail(cid));
 	}
 
-	void setWidthsArray(Map<Integer, Integer> widthsArray) {
-		this.widthsArray = widthsArray;
-	}
-
-	void setDefaultGlyphWidth(float defaultGlyphWidth) {
-		this.defaultGlyphWidth = defaultGlyphWidth;
-	}
-
 	void setFontObject(List<CFFFont> fontObject) {
 		this.fontObject = fontObject;
 	}

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=1209448&r1=1209447&r2=1209448&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 Fri Dec  2 12:36:16 2011
@@ -21,31 +21,19 @@
 
 package org.apache.padaf.preflight.font;
 
-import java.util.Arrays;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-
 import org.apache.fontbox.cmap.CMap;
 import org.apache.fontbox.ttf.TrueTypeFont;
 import org.apache.padaf.preflight.ValidationConstants;
 
 
 public class CFFType2FontContainer extends AbstractFontContainer {
-	private Map<Integer, Integer> widthsArray = new LinkedHashMap<Integer, Integer>(0);
-	/**
-	 * Represent the missingWidth value of the FontDescriptor dictionary.
-	 * According to the PDF Reference, if this value is missing, the default 
-	 * one is 0.
-	 */
-	private float defaultGlyphWidth = 0;
 	/**
 	 * Object which contains the TrueType font data (used in the CFFType2 font) 
 	 * extracted by the TrueTypeParser object
 	 */
 	private TrueTypeFont fontObject = null;
 	private CMap cidToGidMap = null;
-	
+
 	private int numberOfLongHorMetrics;
 	private int unitsPerEm;
 	private int[] glyphWidths;
@@ -59,25 +47,21 @@ public class CFFType2FontContainer exten
 
 	@Override
 	public void checkCID(int cid) throws GlyphException {
-	  if (isAlreadyComputedCid(cid)) {
-		  return;
-	  }
-
-		float widthProvidedByPdfDictionary = this.defaultGlyphWidth;
-		if (this.widthsArray.containsKey(cid)) {
-			Integer i = this.widthsArray.get(cid);
-			widthProvidedByPdfDictionary = i.floatValue();
+		if (isAlreadyComputedCid(cid)) {
+			return;
 		}
 
-		int glyphIndex = getGlyphIndex(cid);
-		
+		final float widthProvidedByPdfDictionary = this.font.getFontWidth(cid);
+
+		final int glyphIndex = getGlyphIndex(cid);
+
 		if(this.fontObject.getGlyph().getGlyphs().length <= glyphIndex) {
 			GlyphException ge = new GlyphException(ValidationConstants.ERROR_FONTS_GLYPH_MISSING, cid, 
 					"CID " + cid + " is missing from font \"" + this.font.getBaseFont() + "\"");
-		  addKnownCidElement(new GlyphDetail(cid, ge));
+			addKnownCidElement(new GlyphDetail(cid, ge));
 			throw ge;
 		}
-			
+
 		// glyph exists we can check the width
 		float glypdWidth = glyphWidths[numberOfLongHorMetrics - 1];
 		if (glyphIndex < numberOfLongHorMetrics) {
@@ -85,8 +69,8 @@ public class CFFType2FontContainer exten
 		}
 		float widthInFontProgram = ((glypdWidth * 1000) / unitsPerEm);
 
-	  checkWidthsConsistency(cid, widthProvidedByPdfDictionary, widthInFontProgram);
-	  addKnownCidElement(new GlyphDetail(cid));
+		checkWidthsConsistency(cid, widthProvidedByPdfDictionary, widthInFontProgram);
+		addKnownCidElement(new GlyphDetail(cid));
 	}
 
 	/**
@@ -119,21 +103,13 @@ public class CFFType2FontContainer exten
 			} catch (NumberFormatException e) {
 				GlyphException ge = new GlyphException(ValidationConstants.ERROR_FONTS_GLYPH_MISSING, cid, 
 						"CID " + cid + " isn't linked with a GlyphIndex >> " + glyphIdAsString);
-			  addKnownCidElement(new GlyphDetail(cid, ge));
+				addKnownCidElement(new GlyphDetail(cid, ge));
 				throw ge;
 			}
 		}
 		return glyphIndex;
 	}
 
-	void setPdfWidths(Map<Integer, Integer> widthsArray) {
-		this.widthsArray = widthsArray;
-	}
-
-	void setDefaultGlyphWidth(float defaultGlyphWidth) {
-		this.defaultGlyphWidth = defaultGlyphWidth;
-	}
-
 	void setFontObject(TrueTypeFont fontObject) {
 		this.fontObject = fontObject;
 	}

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=1209448&r1=1209447&r2=1209448&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 Fri Dec  2 12:36:16 2011
@@ -23,10 +23,8 @@ package org.apache.padaf.preflight.font;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import java.util.LinkedHashMap;
 import java.util.List;
 
-
 import org.apache.fontbox.cff.CFFFont;
 import org.apache.fontbox.cff.CFFParser;
 import org.apache.fontbox.cmap.CMap;
@@ -666,8 +664,6 @@ public class CompositeFontValidator exte
 	 */
 	protected boolean checkTTFontMetrics(TrueTypeFont ttf)
 	throws ValidationException {
-		LinkedHashMap<Integer, Integer> widths = getWidthsArray();
-		int defaultWidth = this.cidFont.getInt("DW", 1000);
 		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.
@@ -677,9 +673,7 @@ public class CompositeFontValidator exte
 		 */
 		int numberOfLongHorMetrics = ttf.getHorizontalHeader().getNumberOfHMetrics();
 		CFFType2FontContainer type2FontContainer = ((CompositeFontContainer)this.fontContainer).getCFFType2();
-		type2FontContainer.setPdfWidths(widths);
 		type2FontContainer.setCmap(this.cidToGidMap);
-		type2FontContainer.setDefaultGlyphWidth(defaultWidth);
 		type2FontContainer.setFontObject(ttf);
 		type2FontContainer.setGlyphWidths(glyphWidths);
 		type2FontContainer.setNumberOfLongHorMetrics(numberOfLongHorMetrics);
@@ -698,13 +692,8 @@ public class CompositeFontValidator exte
 	protected boolean checkCIDFontWidths(List<CFFFont> lCFonts)
 	throws ValidationException {
 		// ---- Extract Widths and default Width from the CIDFont dictionary
-		LinkedHashMap<Integer, Integer> widths = getWidthsArray();
-		int defaultWidth = this.cidFont.getInt("DW", 1000);
 		CFFType0FontContainer type0FontContainer = ((CompositeFontContainer)this.fontContainer).getCFFType0();
 		type0FontContainer.setFontObject(lCFonts);
-		type0FontContainer.setDefaultGlyphWidth(defaultWidth);
-		type0FontContainer.setWidthsArray(widths);
-
 		return true;
 	}
 
@@ -773,68 +762,6 @@ public class CompositeFontValidator exte
 	}
 
 	/**
-	 * For a CIDFont the width array, there are two formats of width array :
-	 * <UL>
-	 * <li>C [W1...Wn] : C is an integer specifying a starting CID value and the
-	 * array of n numbers specify widths for n consecutive CIDs.
-	 * <li>Cf Cl W : Defines the same width W for the range Cf to Cl
-	 * </UL>
-	 * This method gets a linked hash map of width where the key is a CID and the
-	 * value is the Width.
-	 * 
-	 * @return
-	 * @throws ValidationException
-	 */
-	protected LinkedHashMap<Integer, Integer> getWidthsArray()
-	throws ValidationException {
-		LinkedHashMap<Integer, Integer> widthsMap = new LinkedHashMap<Integer, Integer>();
-		COSDocument cDoc = handler.getDocument().getDocument();
-		COSBase cBase = this.cidFont.getItem(COSName.getPDFName("W"));
-		COSArray wArr = COSUtils.getAsArray(cBase, cDoc);
-
-		for (int i = 0; i < wArr.size();) {
-
-			int firstCid = wArr.getInt(i);
-
-			if (i + 1 >= wArr.size()) {
-				throw new ValidationException("Invalid format of the W entry");
-			}
-
-			COSBase cb = wArr.getObject(i + 1);
-			if (COSUtils.isArray(cb, cDoc)) {
-
-				// ---- First Format
-				COSArray seqWidths = COSUtils.getAsArray(cb, cDoc);
-				widthsMap.put(firstCid, seqWidths.getInt(0));
-				for (int jw = 1; jw < seqWidths.size(); jw++) {
-					widthsMap.put((firstCid + jw), seqWidths.getInt(jw));
-				}
-
-				i = i + 2;
-
-			} else {
-
-				// ---- Second Format
-				if (i + 2 >= wArr.size()) {
-					throw new ValidationException("Invalid format of the W entry");
-				}
-
-				int lastCid = wArr.getInt(i + 1);
-				int commonWidth = wArr.getInt(i + 2);
-				for (int jw = firstCid; jw <= lastCid; ++jw) {
-					widthsMap.put((firstCid + jw), commonWidth);
-				}
-
-				i = i + 3;
-
-			}
-
-		}
-
-		return widthsMap;
-	}
-
-	/**
 	 * If the embedded font is a subset, the CIDSet entry is mandatory and must be
 	 * a Stream. This method returns true if the CIDSet entry respects conditions,
 	 * otherwise the method returns false and the FontContainer is updated.

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/TrueTypeFontContainer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/TrueTypeFontContainer.java?rev=1209448&r1=1209447&r2=1209448&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/TrueTypeFontContainer.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/TrueTypeFontContainer.java Fri Dec  2 12:36:16 2011
@@ -22,27 +22,14 @@
 package org.apache.padaf.preflight.font;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
 
 import org.apache.fontbox.ttf.CMAPEncodingEntry;
 import org.apache.fontbox.ttf.TrueTypeFont;
 import org.apache.padaf.preflight.ValidationConstants;
-import org.apache.pdfbox.cos.COSInteger;
 import org.apache.pdfbox.encoding.Encoding;
 import org.apache.pdfbox.pdmodel.font.PDFont;
 
 public class TrueTypeFontContainer extends AbstractFontContainer {
-	private List<?> widthsArray = new ArrayList(0);
-	private int firstCharInWidthsArray = 0;
-
-	/**
-	 * Represent the missingWidth value of the FontDescriptor dictionary.
-	 * According to the PDF Reference, if this value is missing, the default 
-	 * one is 0.
-	 */
-	private float defaultGlyphWidth = 0;
 	/**
 	 * Object which contains the TrueType font data extracted by the
 	 * TrueTypeParser object
@@ -58,18 +45,6 @@ public class TrueTypeFontContainer exten
 		super(fd);
 	}
 
-	void setWidthsArray(List<?> widthsArray) {
-		this.widthsArray = widthsArray;
-	}
-
-	void setFirstCharInWidthsArray(int firstCharInWidthsArray) {
-		this.firstCharInWidthsArray = firstCharInWidthsArray;
-	}
-
-	void setDefaultGlyphWidth(float defaultGlyphWidth) {
-		this.defaultGlyphWidth = defaultGlyphWidth;
-	}
-
 	void setFontObjectAndInitializeInnerFields(TrueTypeFont fontObject) {
 		this.fontObject = fontObject;
 		this.unitsPerEm = this.fontObject.getHeader().getUnitsPerEm();
@@ -91,8 +66,7 @@ public class TrueTypeFontContainer exten
 			return;
 		}
 
-		int indexOfWidth = (cid - firstCharInWidthsArray);
-		float widthProvidedByPdfDictionary = this.defaultGlyphWidth;
+		final float widthProvidedByPdfDictionary = this.font.getFontWidth(cid);
 		float widthInFontProgram ;
 
 		int innerFontCid = cid;
@@ -162,12 +136,6 @@ public class TrueTypeFontContainer exten
 		}
 		widthInFontProgram = ((glypdWidth * 1000) / unitsPerEm);
 
-		// search width in the PDF file
-		if (indexOfWidth >= 0 && indexOfWidth < this.widthsArray.size()) {
-			COSInteger w = (COSInteger)this.widthsArray.get(indexOfWidth);
-			widthProvidedByPdfDictionary = w.intValue(); 
-		}
-
 		checkWidthsConsistency(cid, widthProvidedByPdfDictionary, widthInFontProgram);
 		addKnownCidElement(new GlyphDetail(cid));
 	}

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/TrueTypeFontValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/TrueTypeFontValidator.java?rev=1209448&r1=1209447&r2=1209448&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/TrueTypeFontValidator.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/TrueTypeFontValidator.java Fri Dec  2 12:36:16 2011
@@ -23,8 +23,6 @@ package org.apache.padaf.preflight.font;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import java.util.List;
-
 
 import org.apache.commons.io.IOUtils;
 import org.apache.fontbox.ttf.CMAPEncodingEntry;
@@ -36,7 +34,6 @@ import org.apache.padaf.preflight.Valida
 import org.apache.padaf.preflight.ValidationException;
 import org.apache.padaf.preflight.ValidationResult;
 import org.apache.padaf.preflight.ValidationResult.ValidationError;
-import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSObject;
@@ -44,7 +41,6 @@ import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.encoding.Encoding;
 import org.apache.pdfbox.encoding.MacRomanEncoding;
 import org.apache.pdfbox.encoding.WinAnsiEncoding;
-import org.apache.pdfbox.pdmodel.common.COSArrayList;
 import org.apache.pdfbox.pdmodel.common.PDStream;
 
 public class TrueTypeFontValidator extends SimpleFontValidator {
@@ -53,7 +49,7 @@ public class TrueTypeFontValidator exten
 	 * @param obj
 	 */
 	public TrueTypeFontValidator(DocumentHandler handler, COSObject obj)
-	throws ValidationException {
+			throws ValidationException {
 		super(handler, obj);
 	}
 
@@ -126,8 +122,8 @@ public class TrueTypeFontValidator exten
 		PDStream ff2 = pFontDesc.getFontFile2();
 		PDStream ff3 = pFontDesc.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(
@@ -157,32 +153,32 @@ public class TrueTypeFontValidator exten
 				}
 
 				// ---- check the encoding part.
-					if (pFontDesc.isNonSymbolic()) {
-						// ---- only MacRomanEncoding or WinAnsiEncoding are allowed for a non
-						// symbolic font
-						Encoding encodingValue = this.pFont.getFontEncoding();
-						if (encodingValue == null
-								|| !(encodingValue instanceof MacRomanEncoding || encodingValue instanceof WinAnsiEncoding)) {
-							this.fontContainer.addError(new ValidationResult.ValidationError(
-									ValidationConstants.ERROR_FONTS_ENCODING,
-									"The Encoding is invalid for the NonSymbolic TTF"));
-							return false;
-						}
-					} else if (pFontDesc.isSymbolic()) {
-						// ---- For symbolic font, no encoding entry is allowed and only one
-						// encoding entry is expected into the FontFile CMap
-						if (((COSDictionary) this.fDictionary.getCOSObject()).getItem(COSName
-								.getPDFName(FONT_DICTIONARY_KEY_ENCODING)) != null) {
-							this.fontContainer.addError(new ValidationResult.ValidationError(
-									ValidationConstants.ERROR_FONTS_ENCODING,
-									"The Encoding should be missing for the Symbolic TTF"));
-							return false;
-						} // else check the content of the Font CMap (see below)
-
-					} else {
-						// ----- should never happen
-						return true;
+				if (pFontDesc.isNonSymbolic()) {
+					// ---- only MacRomanEncoding or WinAnsiEncoding are allowed for a non
+					// symbolic font
+					Encoding encodingValue = this.pFont.getFontEncoding();
+					if (encodingValue == null
+							|| !(encodingValue instanceof MacRomanEncoding || encodingValue instanceof WinAnsiEncoding)) {
+						this.fontContainer.addError(new ValidationResult.ValidationError(
+								ValidationConstants.ERROR_FONTS_ENCODING,
+								"The Encoding is invalid for the NonSymbolic TTF"));
+						return false;
 					}
+				} else if (pFontDesc.isSymbolic()) {
+					// ---- For symbolic font, no encoding entry is allowed and only one
+					// encoding entry is expected into the FontFile CMap
+					if (((COSDictionary) this.fDictionary.getCOSObject()).getItem(COSName
+							.getPDFName(FONT_DICTIONARY_KEY_ENCODING)) != null) {
+						this.fontContainer.addError(new ValidationResult.ValidationError(
+								ValidationConstants.ERROR_FONTS_ENCODING,
+								"The Encoding should be missing for the Symbolic TTF"));
+						return false;
+					} // else check the content of the Font CMap (see below)
+
+				} else {
+					// ----- should never happen
+					return true;
+				}
 
 				/*
 				 * ---- try to load the font using the TTFParser object. If the font is
@@ -200,8 +196,11 @@ public class TrueTypeFontValidator exten
 								"The Encoding should be missing for the Symbolic TTF"));
 						return false;
 					}
-
-					return checkFontMetrics(ttf) && checkFontFileMetaData(pFontDesc, ff2);
+					
+					((TrueTypeFontContainer)this.fontContainer).setFontObjectAndInitializeInnerFields(ttf);
+					((TrueTypeFontContainer)this.fontContainer).setCMap(getCMapOfFontProgram(ttf));
+					
+					return checkFontFileMetaData(pFontDesc, ff2);
 				} catch (IOException e) {
 					this.fontContainer.addError(new ValidationResult.ValidationError(
 							ValidationConstants.ERROR_FONTS_TRUETYPE_DAMAGED,
@@ -215,38 +214,6 @@ public class TrueTypeFontValidator exten
 	}
 
 	/**
-	 * This method checks the metric consistency. If the validation fails, the
-	 * FontContainer is updated. If the validation is a success, the
-	 * FontContainer.cidKnownByFont map is updated.
-	 * 
-	 * @param ttf
-	 * @return
-	 * @throws IOException
-	 */
-	protected boolean checkFontMetrics(TrueTypeFont ttf) throws IOException,
-	ValidationException {
-
-		int firstChar = pFont.getFirstChar();
-		float defaultGlyphWidth = this.pFontDesc.getMissingWidth();
-
-		List<?> pdfWidths = this.pFont.getWidths();
-		COSArray widths = null;
-		if (pdfWidths instanceof COSArrayList) {
-			widths = ((COSArrayList) pdfWidths).toList();
-		} else {
-			widths = ((COSArray) pdfWidths);
-		}
-
-		((TrueTypeFontContainer)this.fontContainer).setWidthsArray(widths.toList());
-		((TrueTypeFontContainer)this.fontContainer).setFirstCharInWidthsArray(firstChar);
-		((TrueTypeFontContainer)this.fontContainer).setDefaultGlyphWidth(defaultGlyphWidth);
-		((TrueTypeFontContainer)this.fontContainer).setFontObjectAndInitializeInnerFields(ttf);
-		((TrueTypeFontContainer)this.fontContainer).setCMap(getCMapOfFontProgram(ttf));
-
-		return true;
-	}
-
-	/**
 	 * Return the CMap encoding entry to use. This CMap belong to the TrueType
 	 * Font Program.
 	 * 
@@ -267,28 +234,28 @@ public class TrueTypeFontValidator exten
 	 *           if the FontProgram doesn't have the expected CMap
 	 */
 	protected CMAPEncodingEntry getCMapOfFontProgram(TrueTypeFont ttf)
-	throws ValidationException {
+			throws ValidationException {
 		CMAPTable cmap = ttf.getCMAP();
 		if (this.pFontDesc.isSymbolic()) {
 			return cmap.getCmaps()[0];
 		} else {
-				if (this.pFont.getFontEncoding() instanceof WinAnsiEncoding) {
-					for (CMAPEncodingEntry cmapEntry : cmap.getCmaps()) {
-						// ---- Returns the WinAnsiEncoding CMap
-						if ((cmapEntry.getPlatformId() == 3)
-								&& (cmapEntry.getPlatformEncodingId() == 1)) {
-							return cmapEntry;
-						}
+			if (this.pFont.getFontEncoding() instanceof WinAnsiEncoding) {
+				for (CMAPEncodingEntry cmapEntry : cmap.getCmaps()) {
+					// ---- Returns the WinAnsiEncoding CMap
+					if ((cmapEntry.getPlatformId() == 3)
+							&& (cmapEntry.getPlatformEncodingId() == 1)) {
+						return cmapEntry;
 					}
-				} else {
-					// ---- Returns the MacRomanEncoding CMap
-					for (CMAPEncodingEntry cmapEntry : cmap.getCmaps()) {
-						if ((cmapEntry.getPlatformId() == 1)
-								&& (cmapEntry.getPlatformEncodingId() == 0)) {
-							return cmapEntry;
-						}
+				}
+			} else {
+				// ---- Returns the MacRomanEncoding CMap
+				for (CMAPEncodingEntry cmapEntry : cmap.getCmaps()) {
+					if ((cmapEntry.getPlatformId() == 1)
+							&& (cmapEntry.getPlatformEncodingId() == 0)) {
+						return cmapEntry;
 					}
 				}
+			}
 		}
 
 		throw new ValidationException("CMap not found in the TrueType FontProgam");

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/Type1FontContainer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/Type1FontContainer.java?rev=1209448&r1=1209447&r2=1209448&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/Type1FontContainer.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/Type1FontContainer.java Fri Dec  2 12:36:16 2011
@@ -22,22 +22,16 @@
 package org.apache.padaf.preflight.font;
 
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.List;
 
-
 import org.apache.fontbox.cff.CFFFont;
 import org.apache.fontbox.cff.CFFFont.Mapping;
 import org.apache.padaf.preflight.ValidationConstants;
 import org.apache.padaf.preflight.font.type1.Type1;
-import org.apache.pdfbox.cos.COSInteger;
 import org.apache.pdfbox.pdmodel.font.PDFont;
 
 public class Type1FontContainer extends AbstractFontContainer {
 
-	private List<?> widthsArray = new ArrayList(0);
-	private int firstCharInWidthsArray = 0;
-
 	/**
 	 * Represent the missingWidth value of the FontDescriptor dictionary.
 	 * According to the PDF Reference, if this value is missing, the default 
@@ -56,18 +50,6 @@ public class Type1FontContainer extends 
 		super(fd);
 	}
 
-	void setWidthsArray(List<?> widthsArray) {
-		this.widthsArray = widthsArray;
-	}
-
-	void setFirstCharInWidthsArray(int firstCharInWidthsArray) {
-		this.firstCharInWidthsArray = firstCharInWidthsArray;
-	}
-
-	void setDefaultGlyphWidth(float defaultGlyphWidth) {
-		this.defaultGlyphWidth = defaultGlyphWidth;
-	}
-
 	void setFontObject(Type1 fontObject) {
 		this.fontObject = fontObject;
 	}
@@ -82,8 +64,7 @@ public class Type1FontContainer extends 
 			return;
 		}
 
-		int indexOfWidth = (cid - firstCharInWidthsArray);
-		float widthProvidedByPdfDictionary = this.defaultGlyphWidth;
+		final float widthProvidedByPdfDictionary = this.font.getFontWidth(cid);
 
 		int widthInFontProgram =0;
 		try {
@@ -117,11 +98,6 @@ public class Type1FontContainer extends 
 			throw ge;
 		}
 
-		if (indexOfWidth >= 0 && indexOfWidth < this.widthsArray.size()) {
-			COSInteger w = (COSInteger)this.widthsArray.get(indexOfWidth);
-			widthProvidedByPdfDictionary = w.intValue(); 
-		}
-
 		checkWidthsConsistency(cid, widthProvidedByPdfDictionary, widthInFontProgram);
 		addKnownCidElement(new GlyphDetail(cid));
 	}

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/Type1FontValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/Type1FontValidator.java?rev=1209448&r1=1209447&r2=1209448&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/Type1FontValidator.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/padaf/preflight/font/Type1FontValidator.java Fri Dec  2 12:36:16 2011
@@ -25,10 +25,8 @@ import java.awt.Font;
 import java.awt.FontFormatException;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import java.util.LinkedHashMap;
 import java.util.List;
 
-
 import org.apache.commons.io.IOUtils;
 import org.apache.fontbox.cff.CFFFont;
 import org.apache.fontbox.cff.CFFParser;
@@ -39,14 +37,11 @@ import org.apache.padaf.preflight.Valida
 import org.apache.padaf.preflight.font.type1.Type1;
 import org.apache.padaf.preflight.font.type1.Type1Parser;
 import org.apache.padaf.preflight.utils.COSUtils;
-import org.apache.pdfbox.cos.COSArray;
-import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSDocument;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.cos.COSStream;
-import org.apache.pdfbox.pdmodel.common.COSArrayList;
 import org.apache.pdfbox.pdmodel.common.PDStream;
 
 public class Type1FontValidator extends SimpleFontValidator {
@@ -250,22 +245,6 @@ public class Type1FontValidator extends 
 
 			((Type1FontContainer)this.fontContainer).setCFFFontObjects(lCFonts);
 
-
-			List<?> pdfWidths = this.pFont.getWidths();
-			int firstChar = pFont.getFirstChar();
-			float defaultGlyphWidth = pFontDesc.getMissingWidth();
-
-			COSArray widths = null;
-			if (pdfWidths instanceof COSArrayList) {
-				widths = ((COSArrayList) pdfWidths).toList();
-			} else {
-				widths = ((COSArray) pdfWidths);
-			}
-
-			((Type1FontContainer)this.fontContainer).setWidthsArray(widths.toList());
-			((Type1FontContainer)this.fontContainer).setFirstCharInWidthsArray(firstChar);
-			((Type1FontContainer)this.fontContainer).setDefaultGlyphWidth(defaultGlyphWidth);
-
 			return true;
 		} catch (IOException e) {
 			this.fontContainer.addError(new ValidationResult.ValidationError(
@@ -299,21 +278,6 @@ public class Type1FontValidator extends 
 
 			((Type1FontContainer)this.fontContainer).setFontObject(parsedData);
 
-			List<?> pdfWidths = this.pFont.getWidths();
-			int firstChar = pFont.getFirstChar();
-			float defaultGlyphWidth = pFontDesc.getMissingWidth();
-
-			COSArray widths = null;
-			if (pdfWidths instanceof COSArrayList) {
-				widths = ((COSArrayList) pdfWidths).toList();
-			} else {
-				widths = ((COSArray) pdfWidths);
-			}
-
-			((Type1FontContainer)this.fontContainer).setWidthsArray(widths.toList());
-			((Type1FontContainer)this.fontContainer).setFirstCharInWidthsArray(firstChar);
-			((Type1FontContainer)this.fontContainer).setDefaultGlyphWidth(defaultGlyphWidth);
-
 			return true;
 		} catch (IOException e) {
 			throw new ValidationException("Unable to check Type1 metrics due to : "