Code with Finding: |
class DocumentFont {
private void fillMetrics(byte[] touni, IntHashtable widths, int dw) {
try {
PdfContentParser ps = new PdfContentParser(new PRTokeniser(touni));
PdfObject ob = null;
boolean notFound = true;
int nestLevel = 0;
int maxExc = 50;
while ((notFound || nestLevel > 0)) {
try {
ob = ps.readPRObject();
}
catch (Exception ex) {
if (--maxExc < 0)
break;
continue;
}
if (ob == null)
break;
if (ob.type() == PdfContentParser.COMMAND_TYPE) {
if (ob.toString().equals("begin")) {
notFound = false;
nestLevel++;
}
else if (ob.toString().equals("end")) {
nestLevel--;
}
else if (ob.toString().equals("beginbfchar")) {
while (true) {
PdfObject nx = ps.readPRObject();
if (nx.toString().equals("endbfchar"))
break;
String cid = decodeString((PdfString)nx);
String uni = decodeString((PdfString)ps.readPRObject());
if (uni.length() == 1) {
int cidc = cid.charAt(0);
int unic = uni.charAt(uni.length() - 1);
int w = dw;
if (widths.containsKey(cidc))
w = widths.get(cidc);
metrics.put(Integer.valueOf(unic), new int[]{cidc, w});
}
}
}
else if (ob.toString().equals("beginbfrange")) {
while (true) {
PdfObject nx = ps.readPRObject();
if (nx.toString().equals("endbfrange"))
break;
String cid1 = decodeString((PdfString)nx);
String cid2 = decodeString((PdfString)ps.readPRObject());
int cid1c = cid1.charAt(0);
int cid2c = cid2.charAt(0);
PdfObject ob2 = ps.readPRObject();
if (ob2.isString()) {
String uni = decodeString((PdfString)ob2);
if (uni.length() == 1) {
int unic = uni.charAt(uni.length() - 1);
for (; cid1c <= cid2c; cid1c++, unic++) {
int w = dw;
if (widths.containsKey(cid1c))
w = widths.get(cid1c);
metrics.put(Integer.valueOf(unic), new int[]{cid1c, w});
}
}
}
else {
PdfArray a = (PdfArray)ob2;
for (int j = 0; j < a.size(); ++j, ++cid1c) {
String uni = decodeString(a.getAsString(j));
if (uni.length() == 1) {
int unic = uni.charAt(uni.length() - 1);
int w = dw;
if (widths.containsKey(cid1c))
w = widths.get(cid1c);
metrics.put(Integer.valueOf(unic), new int[]{cid1c, w});
}
}
}
}
}
}
}
}
catch (Exception e) {
throw new ExceptionConverter(e);
}
}
}
|