#region Using ステートメント
using System.Collections.Generic;
using System.Text;
#endregion
namespace WpfFontPipeline
{
///
/// JISコードで定義されている文字を取得する為のヘルパークラス
/// ここではJIS基本漢字(JIS X 0208)で定義されている文字を返す
/// http://www.asahi-net.or.jp/~ax2s-kmtn/ref/jisx0208.html
///
static class JisCode
{
#region パブリックメソッド
///
/// 記号、特殊記号、148字の取得
///
public static IEnumerable GetSpecialCharacters()
{
var list = new List(148);
AddRow(1, list);
AddJisCodes(0x2220, 0x222e, list);
AddJisCodes(0x223a, 0x2241, list);
AddJisCodes(0x224a, 0x2250, list);
AddJisCodes(0x225c, 0x226a, list);
AddJisCodes(0x2272, 0x2279, list);
AddJisCodes(0x227e, 0x227e, list);
return list;
}
///
/// 全角英数字、62字の取得
///
public static IEnumerable GetLatinLetters()
{
var list = new List(62);
AddJisCodes(0x2330, 0x2339, list);
AddJisCodes(0x2341, 0x235a, list);
AddJisCodes(0x2361, 0x237a, list);
return list;
}
///
/// ひらがな、83字の取得
///
public static IEnumerable GetHiragana()
{
var list = new List(83);
AddJisCodes(0x2421, 0x2473, list);
return list;
}
///
/// カタカナ、86字の取得
///
public static IEnumerable GetKatakana()
{
var list = new List(86);
AddJisCodes(0x2521, 0x2576, list);
return list;
}
///
/// ギリシャ文字、48字の取得
///
public static IEnumerable GetGreekLetters()
{
var list = new List(48);
AddJisCodes(0x2621, 0x2638, list);
AddJisCodes(0x2641, 0x2658, list);
return list;
}
///
/// キリル文字、66字の取得
///
public static IEnumerable GetCyrillicLetters()
{
var list = new List(66);
AddJisCodes(0x2721, 0x2741, list);
AddJisCodes(0x2751, 0x2771, list);
return list;
}
///
/// 罫線文字、32字の取得
///
public static IEnumerable GetBoxDrawingCharacters()
{
var list = new List(32);
AddJisCodes(0x2821, 0x2840, list);
return list;
}
///
/// 第1水準漢字、2,965字の取得
///
public static IEnumerable GetKanjiLevel1()
{
var list = new List(2965);
for (int row = 16; row <= 46; ++row)
{
AddRow(row, list);
}
AddJisCodes(0x4f21, 0x4f53, list);
return list;
}
///
/// 第2水準漢字、3,990字の取得
///
public static IEnumerable GetKanjiLevel2()
{
var list = new List(3390);
for (int row = 48; row <= 83; ++row)
{
AddRow(row, list);
}
AddJisCodes(0x7421, 0x7426, list);
return list;
}
#endregion
#region プライベートメソッド
///
/// 指定した区の文字取得
///
/// 区番号
/// 出力先
private static void AddRow(int row, List list)
{
int offset = 0x2000 + row * 0x100;
AddJisCodes(offset + 0x21, offset + 0x7e, list);
}
///
/// 指定されたJISコード領域の文字取得
///
/// 開始JISコード
/// 終了JISコード
/// 出力先
private static void AddJisCodes(int start, int end, List list)
{
int idx = 0;
buffer[idx++] = 0x1b; // 2バイト文字コードへのエスケープシーケンス
buffer[idx++] = 0x24;
buffer[idx++] = 0x42;
for (int jisCode = start; jisCode <= end; ++jisCode)
{
buffer[idx++] = (byte)((jisCode >> 8) & 0xff);
buffer[idx++] = (byte)(jisCode & 0xff);
}
list.AddRange(encoding.GetChars(buffer, 0, idx));
}
#endregion
#region プライベートフィールド
// JISコードからUnicode変換用のEncoding
static Encoding encoding = Encoding.GetEncoding("iso-2022-jp");
// JISコード格納用バッファ、
// ひとつの区内の96文字+エスケープシーケンス分のサイズ
static byte[] buffer = new byte[16 * 6 * 2 + 3];
#endregion
}
}