byte[] convertToBytes(String text) {
byte b[] = null;
switch (fontType) {
case BaseFont.FONT_TYPE_T3:
return baseFont.convertToBytes(text);
case BaseFont.FONT_TYPE_T1:
case BaseFont.FONT_TYPE_TT: {
b = baseFont.convertToBytes(text);
int len = b.length;
for (int k = 0; k < len; ++k)
shortTag[b[k] & 0xff] = 1;
break;
}
case BaseFont.FONT_TYPE_CJK: {
int len = text.length();
for (int k = 0; k < len; ++k)
cjkTag.put(cjkFont.getCidCode(text.charAt(k)), 0);
b = baseFont.convertToBytes(text);
break;
}
case BaseFont.FONT_TYPE_DOCUMENT: {
b = baseFont.convertToBytes(text);
break;
}
case BaseFont.FONT_TYPE_TTUNI: {
try {
int len = text.length();
int metrics[] = null;
char glyph[] = new char[len];
int i = 0;
if (symbolic) {
b = PdfEncodings.convertToBytes(text, "symboltt");
len = b.length;
for (int k = 0; k < len; ++k) {
metrics = ttu.getMetricsTT(b[k] & 0xff);
if (metrics == null)
continue;
longTag.put(new Integer(metrics[0]), new int[]{metrics[0], metrics[1], ttu.getUnicodeDifferences(b[k] & 0xff)});
glyph[i++] = (char)metrics[0];
}
}
else {
for (int k = 0; k < len; ++k) {
int val;
if (Utilities.isSurrogatePair(text, k)) {
val = Utilities.convertToUtf32(text, k);
k++;
}
else {
val = text.charAt(k);
}
metrics = ttu.getMetricsTT(val);
if (metrics == null)
continue;
int m0 = metrics[0];
Integer gl = new Integer(m0);
if (!longTag.containsKey(gl))
longTag.put(gl, new int[]{m0, metrics[1], val});
glyph[i++] = (char)m0;
}
}
String s = new String(glyph, 0, i);
b = s.getBytes(CJKFont.CJK_ENCODING);
}
catch (UnsupportedEncodingException e) {
throw new ExceptionConverter(e);
}
break;
}
}
return b;
}
Converts the text into bytes to be placed in the document.
The conversion is done according to the font and the encoding and the characters
used are stored. |