// this section parses the font program stream searching for a /Encoding entry
// if it contains an array of values a Type1Encoding will be returned
// if it encoding contains an encoding name the corresponding Encoding will be returned
String line = "";
Type1Encoding encoding = null;
while( (line = in.readLine()) != null)
{
if (extractEncoding)
{
if (line.startsWith("currentdict end")) {
if (encoding != null)
setFontEncoding(encoding);
break;
}
if (line.startsWith("/Encoding"))
{
if(line.contains("array"))
{
StringTokenizer st = new StringTokenizer(line);
// ignore the first token
st.nextElement();
int arraySize = Integer.parseInt(st.nextToken());
encoding = new Type1Encoding(arraySize);
}
// if there is already an encoding, we don't need to
// assign another one
else if (getFontEncoding() == null)
{
StringTokenizer st = new StringTokenizer(line);
// ignore the first token
st.nextElement();
String type1Encoding = st.nextToken();
setFontEncoding(
EncodingManager.INSTANCE.getEncoding(
COSName.getPDFName(type1Encoding)));
break;
}
}
else if (line.startsWith("dup")) {
StringTokenizer st = new StringTokenizer(line.replaceAll("/"," /"));
// ignore the first token
st.nextElement();
int index = Integer.parseInt(st.nextToken());
String name = st.nextToken();
if(encoding == null)
log.warn("Unable to get character encoding. Encoding defintion found without /Encoding line.");
else
encoding.addCharacterEncoding(index, name.replace("/", ""));
}
}
// according to the pdf reference, all font matrices should be same, except for type 3 fonts.
// but obviously there are some type1 fonts with different matrix values, see pdf sample
// attached to PDFBOX-935