}
private static void parseCid(String cmapName, AbstractCMap cmap, CidLocation location, int level) throws IOException {
if (level >= MAXLEVEL)
return;
PRTokeniser inp = location.getLocation(cmapName);
try {
ArrayList<PdfObject> list = new ArrayList<PdfObject>();
PdfContentParser cp = new PdfContentParser(inp);
int maxExc = 50;
while (true) {
try {
cp.parse(list);
}
catch (Exception ex) {
if (--maxExc < 0)
break;
continue;
}
if (list.isEmpty())
break;
String last = list.get(list.size() - 1).toString();
if (level == 0 && list.size() == 3 && last.equals(DEF)) {
PdfObject key = list.get(0);
if (PdfName.REGISTRY.equals(key))
cmap.setRegistry(list.get(1).toString());
else if (PdfName.ORDERING.equals(key))
cmap.setOrdering(list.get(1).toString());
else if (CMAPNAME.equals(key))
cmap.setName(list.get(1).toString());
else if (PdfName.SUPPLEMENT.equals(key)) {
try {
cmap.setSupplement(((PdfNumber)list.get(1)).intValue());
}
catch (Exception ex) {}
}
}
else if ((last.equals(ENDCIDCHAR) || last.equals(ENDBFCHAR)) && list.size() >= 3) {
int lmax = list.size() - 2;
for (int k = 0; k < lmax; k += 2) {
if (list.get(k) instanceof PdfString) {
cmap.addChar((PdfString)list.get(k), list.get(k + 1));
}
}
}
else if ((last.equals(ENDCIDRANGE) || last.equals(ENDBFRANGE)) && list.size() >= 4) {
int lmax = list.size() - 3;
for (int k = 0; k < lmax; k += 3) {
if (list.get(k) instanceof PdfString && list.get(k + 1) instanceof PdfString) {
cmap.addRange((PdfString)list.get(k), (PdfString)list.get(k + 1), list.get(k + 2));
}
}
}
else if (last.equals(USECMAP) && list.size() == 2 && list.get(0) instanceof PdfName) {
parseCid(PdfName.decodeName(list.get(0).toString()), cmap, location, level + 1);
}
}
}
finally {
inp.close();
}
}