/** 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.
* @param text the text to convert
* @return the conversion
*/
internal 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[((int)b[k]) & 0xff] = 1;
}
break;
}
case BaseFont.FONT_TYPE_CJK: {
int len = text.Length;
if (cjkFont.IsIdentity())
{
foreach (char c in text)
{
cjkTag[c] = 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[k];
}
cjkTag[cjkFont.GetCidCode(val)] = 0;
}
}
b = cjkFont.ConvertToBytes(text);
break;
}
case BaseFont.FONT_TYPE_DOCUMENT: {
b = baseFont.ConvertToBytes(text);
break;
}
case BaseFont.FONT_TYPE_TTUNI: {
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[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 = (int)text[k];
}
metrics = ttu.GetMetricsTT(val);
if (metrics == null)
{
continue;
}
int m0 = metrics[0];
int gl = m0;
if (!longTag.ContainsKey(gl))
{
longTag[gl] = new int[] { m0, metrics[1], val }
}
;
glyph[i++] = (char)m0;
}
}
string s = new String(glyph, 0, i);
b = PdfEncodings.ConvertToBytes(s, CJKFont.CJK_ENCODING);
break;
}
}
return(b);
}