public static byte[] ConvertToBytes(char char1, String encoding) {
if (encoding == null || encoding.Length == 0)
return new byte[]{(byte)char1};
IExtraEncoding extra = (IExtraEncoding)extraEncodings[encoding.ToLower(System.Globalization.CultureInfo.InvariantCulture)];
if (extra != null) {
byte[] b = extra.CharToByte(char1, encoding);
if (b != null)
return b;
}
IntHashtable hash = null;
if (encoding.Equals(BaseFont.WINANSI))
hash = winansi;
else if (encoding.Equals(PdfObject.TEXT_PDFDOCENCODING))
hash = pdfEncoding;
if (hash != null) {
int c = 0;
if (char1 < 128 || (char1 > 160 && char1 <= 255))
c = char1;
else
c = hash[char1];
if (c != 0)
return new byte[]{(byte)c};
else
return new byte[0];
}
Encoding encw = IanaEncodings.GetEncodingEncoding(encoding);
byte[] preamble = encw.GetPreamble();
char[] text = new char[]{char1};
if (preamble.Length == 0)
return encw.GetBytes(text);
byte[] encoded = encw.GetBytes(text);
byte[] total = new byte[encoded.Length + preamble.Length];
Array.Copy(preamble, 0, total, 0, preamble.Length);
Array.Copy(encoded, 0, total, preamble.Length, encoded.Length);
return total;
}