Author: leleueri
Date: Tue Apr 17 21:01:40 2012
New Revision: 1327276
URL: http://svn.apache.org/viewvc?rev=1327276&view=rev
Log:
Search glyph information in each CMap of the truetype font.
Modified:
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
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=1327276&r1=1327275&r2=1327276&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
Tue Apr 17 21:01:40 2012
@@ -35,7 +35,7 @@ public class TrueTypeFontContainer exten
* TrueTypeParser object
*/
private TrueTypeFont fontObject = null;
- private CMAPEncodingEntry cmap = null;
+ private CMAPEncodingEntry[] cmaps = null;
private int numberOfLongHorMetrics;
private int unitsPerEm;
@@ -56,88 +56,79 @@ public class TrueTypeFontContainer exten
this.numberOfLongHorMetrics =
this.fontObject.getHorizontalHeader().getNumberOfHMetrics();
}
- void setCMap(CMAPEncodingEntry cmap) {
- this.cmap = cmap;
+ void setCMap(CMAPEncodingEntry[] cmaps) {
+ this.cmaps = cmaps;
}
- @Override
- public void checkCID(int cid) throws GlyphException {
- if (isAlreadyComputedCid(cid)) {
- return;
- }
-
- final float widthProvidedByPdfDictionary =
this.font.getFontWidth(cid);
- float widthInFontProgram ;
-
- int innerFontCid = cid;
- if (cmap.getPlatformEncodingId() == 1 && cmap.getPlatformId()
== 3) {
- try {
- Encoding fontEncoding =
this.font.getFontEncoding();
- String character =
fontEncoding.getCharacter(cid);
- if (character == null) {
- GlyphException e = new
GlyphException(ValidationConstants.ERROR_FONTS_GLYPH_MISSING,
- cid,
- "The character \"" +
cid
- + "\" in the font
program \""
- +
this.font.getBaseFont()
- + "\"is missing from
the Charater Encoding.");
- addKnownCidElement(new GlyphDetail(cid,
e));
- throw e;
- }
-
- char[] characterArray = character.toCharArray();
- if (characterArray.length == 1 ) {
- innerFontCid = (int)characterArray[0];
- } else {
- // TODO OD-PDFA-87 A faire?
- innerFontCid = (int)characterArray[0];
- for (int i = 1; i <
characterArray.length; ++i) {
- if
(cmap.getGlyphId((int)characterArray[i]) == 0) {
- GlyphException e = new
GlyphException(ValidationConstants.ERROR_FONTS_GLYPH_MISSING,
- cid,
- "A
glyph for the character \"" + cid
- + "\"
in the font program \""
- +
this.font.getBaseFont()
- + "\"is
missing. There are " + characterArray.length + " glyph used by this
character...");
- addKnownCidElement(new
GlyphDetail(cid, e));
- throw e;
- }
- }
- }
- } catch (IOException ioe) {
- GlyphException e = new
GlyphException(ValidationConstants.ERROR_FONTS_ENCODING_IO,
- cid,
- "Unable to get the encoding
object from the PDFont object during the validation of cid \"" + cid
- + "\" in the font program \""
- + this.font.getBaseFont()
- + "\".");
- addKnownCidElement(new GlyphDetail(cid, e));
- throw e;
- }
- }
-
- // search glyph
- int glyphId = cmap.getGlyphId(innerFontCid);
- if (glyphId == 0) {
- GlyphException e = new
GlyphException(ValidationConstants.ERROR_FONTS_GLYPH_MISSING,
- cid,
- "Glyph for the character \"" + cid
- + "\" in the font program \""
- + this.font.getBaseFont()
- + "\"is missing.");
- addKnownCidElement(new GlyphDetail(cid, e));
- throw e;
- }
-
- // compute glyph width
- float glypdWidth = glyphWidths[numberOfLongHorMetrics - 1];
- if (glyphId < numberOfLongHorMetrics) {
- glypdWidth = glyphWidths[glyphId];
- }
- widthInFontProgram = ((glypdWidth * 1000) / unitsPerEm);
-
- checkWidthsConsistency(cid, widthProvidedByPdfDictionary,
widthInFontProgram);
- addKnownCidElement(new GlyphDetail(cid));
- }
+ @Override
+ public void checkCID(int cid) throws GlyphException {
+ if (isAlreadyComputedCid(cid)) {
+ return;
+ }
+ for (CMAPEncodingEntry entry : cmaps) {
+ if (checkCID(cid,entry)) {
+ return;
+ }
+ }
+ GlyphException e = new
GlyphException(ValidationConstants.ERROR_FONTS_GLYPH_MISSING,
+ cid,
+ "The character \"" + cid
+ + "\" in the font program \""
+ + this.font.getBaseFont()
+ + "\"is missing from the Charater Encoding.");
+ addKnownCidElement(new GlyphDetail(cid, e));
+ throw e;
+ }
+
+ public boolean checkCID(int cid, CMAPEncodingEntry cmap) throws
GlyphException {
+
+ final float widthProvidedByPdfDictionary = this.font.getFontWidth(cid);
+ float widthInFontProgram ;
+
+ int innerFontCid = cid;
+
+
+ if (cmap.getPlatformEncodingId() == 1 && cmap.getPlatformId() == 3) {
+ try {
+ Encoding fontEncoding = this.font.getFontEncoding();
+ String character = fontEncoding.getCharacter(cid);
+ if (character == null) {
+ return false;
+ }
+
+ char[] characterArray = character.toCharArray();
+ if (characterArray.length == 1 ) {
+ innerFontCid = (int)characterArray[0];
+ } else {
+ // TODO OD-PDFA-87 A faire?
+ innerFontCid = (int)characterArray[0];
+ for (int i = 1; i < characterArray.length; ++i) {
+ if (cmap.getGlyphId((int)characterArray[i]) == 0) {
+ return false;
+ }
+ }
+ }
+ } catch (IOException ioe) {
+ return false;
+ }
+ }
+
+ // search glyph
+ int glyphId = cmap.getGlyphId(innerFontCid);
+ if (glyphId == 0) {
+ return false;
+ }
+
+ // compute glyph width
+ float glypdWidth = glyphWidths[numberOfLongHorMetrics - 1];
+ if (glyphId < numberOfLongHorMetrics) {
+ glypdWidth = glyphWidths[glyphId];
+ }
+
+ widthInFontProgram = ((glypdWidth * 1000) / unitsPerEm);
+ checkWidthsConsistency(cid, widthProvidedByPdfDictionary,
widthInFontProgram);
+ addKnownCidElement(new GlyphDetail(cid));
+ return true;
+ }
}
\ No newline at end of file
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=1327276&r1=1327275&r2=1327276&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
Tue Apr 17 21:01:40 2012
@@ -23,6 +23,8 @@ package org.apache.padaf.preflight.font;
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.fontbox.ttf.CMAPEncodingEntry;
@@ -233,31 +235,30 @@ public class TrueTypeFontValidator exten
* @throws ValidationException
* if the FontProgram doesn't have the expected CMap
*/
- protected CMAPEncodingEntry getCMapOfFontProgram(TrueTypeFont ttf)
+ protected CMAPEncodingEntry[] getCMapOfFontProgram(TrueTypeFont ttf)
throws ValidationException {
CMAPTable cmap = ttf.getCMAP();
if (this.pFontDesc.isSymbolic()) {
- return cmap.getCmaps()[0];
+ return cmap.getCmaps();
} 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;
- }
- }
- } else {
- // ---- Returns the MacRomanEncoding CMap
- for (CMAPEncodingEntry cmapEntry :
cmap.getCmaps()) {
- if ((cmapEntry.getPlatformId() == 1)
- &&
(cmapEntry.getPlatformEncodingId() == 0)) {
- return cmapEntry;
+ List<CMAPEncodingEntry> res = new
ArrayList<CMAPEncodingEntry>();
+ boolean firstIs31 = false;
+ for (CMAPEncodingEntry cmapEntry : cmap.getCmaps()) {
+ // ---- Returns the WinAnsiEncoding CMap
+ if ((cmapEntry.getPlatformId() == 3) &&
(cmapEntry.getPlatformEncodingId() == 1)) {
+ res.add(0,cmapEntry);
+ firstIs31 = true;
+ } else if ((cmapEntry.getPlatformId() == 1)&&
(cmapEntry.getPlatformEncodingId() == 0)) {
+ if (firstIs31) {
+ res.add(1, cmapEntry);
+ } else {
+ res.add(0, cmapEntry);
}
+ } else {
+ res.add(cmapEntry);
}
}
+ return res.toArray(new CMAPEncodingEntry[res.size()]);
}
-
- throw new ValidationException("CMap not found in the TrueType
FontProgam");
}
}