private void checkCharProcsAndMetrics() throws ValidationException
{
List<Integer> widths = getWidths(font);
if (widths == null || widths.isEmpty())
{
this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID,
"The Witdhs array is unreachable"));
return;
}
COSDictionary charProcs = COSUtils.getAsDictionary(fontDictionary.getItem(COSName.CHAR_PROCS), cosDocument);
if (charProcs == null)
{
this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID,
"The CharProcs element isn't a dictionary"));
return;
}
int fc = font.getCOSObject().getInt(COSName.FIRST_CHAR, -1);
int lc = font.getCOSObject().getInt(COSName.LAST_CHAR, -1);
/*
* wArr length = (lc - fc) + 1 and it is an array of int.
* If FirstChar is greater than LastChar, the validation
* will fail because of the array will have an expected size <= 0.
*/
int expectedLength = (lc - fc) + 1;
if (widths.size() != expectedLength)
{
this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID,
"The length of Witdhs array is invalid. Expected : \"" + expectedLength + "\" Current : \""
+ widths.size() + "\""));
return;
}
// Check width consistency
for (int i = 0; i < expectedLength; i++)
{
int code = fc + i;
float width = widths.get(i);
PDType3CharProc charProc = getCharProc(code);
if (charProc != null)
{
try
{
float fontProgramWidth = getWidthFromCharProc(charProc);
if (width == fontProgramWidth)
{
// Glyph is OK, we keep the CID.
this.fontContainer.markAsValid(code);
}
else
{
GlyphException glyphEx = new GlyphException(ERROR_FONTS_METRICS, code,
"The character with CID\"" + code + "\" should have a width equals to " + width);
this.fontContainer.markAsInvalid(code, glyphEx);
}
}
catch (ContentStreamException e)
{
// TODO spaces/isartor-6-2-3-3-t02-fail-h.pdf --> si ajout de l'erreur dans le container le test
// echoue... pourquoi si la font est utilisée ca devrait planter???
this.context.addValidationError(new ValidationError(((ContentStreamException) e).getErrorCode(), e
.getMessage()));
return;
}
catch (IOException e)
{
this.fontContainer.push(new ValidationError(ERROR_FONTS_TYPE3_DAMAGED,
"The CharProcs references an element which can't be read"));
return;
}
}
}