📄 kanjiinfo.cxx
字号:
#include "KanjiInfo.h" // Main symbol group, corresponds to JIS codes 0x2100KanjiInfo::KANJI KanjiInfo::misc_unicode[] = { #include "codepage/jwp_umis.dat"};KanjiInfo::KANJI KanjiInfo::ext_unicode[] = { #include "codepage/jwp_uext.dat"};// Kanji unicodeKanjiInfo::KANJI KanjiInfo::kanji_unicode[] = { #include "codepage/jwp_ukan.dat"};KanjiInfo::KANJI KanjiInfo::cp1250[128] = { // Eastern Europe code page #include "codepage/jwp_cp1250.dat"};KanjiInfo::KANJI KanjiInfo::cp1251[128] = { // Cyrillic code page #include "codepage/jwp_cp1251.dat"};KanjiInfo::KANJI KanjiInfo::cp1252[128] = { // USA, West Europe code page #include "codepage/jwp_cp1252.dat"};KanjiInfo::KANJI KanjiInfo::cp1253[128] = { // Greek code page #include "codepage/jwp_cp1253.dat"};KanjiInfo::KANJI KanjiInfo::cp1254[128] = { // Turkish code page #include "codepage/jwp_cp1254.dat"};KanjiInfo::KANJI KanjiInfo::cp1255[128] = { // Hebrew code page #include "codepage/jwp_cp1255.dat"};KanjiInfo::KANJI KanjiInfo::cp1256[128] = { // Arabic code page #include "codepage/jwp_cp1256.dat"};KanjiInfo::KANJI KanjiInfo::cp1257[128] = { // Baltic code page #include "codepage/jwp_cp1257.dat"};KanjiInfo::KANJI KanjiInfo::cp1258[128] = { // Vietnamese code page #include "codepage/jwp_cp1258.dat"};
unsigned short KanjiInfo::countKanjiUnicode() {
static unsigned short _kanji_unicode_count =
(sizeof(kanji_unicode)/sizeof(KANJI));
return _kanji_unicode_count;
}
unsigned short KanjiInfo::countMiscUnicode() {
static unsigned short _misc_unicode_count =
(sizeof(misc_unicode)/sizeof(KANJI));
return _misc_unicode_count;
}
unsigned short KanjiInfo::countExtUnicode() {
static unsigned short _ext_unicode_count =
(sizeof(ext_unicode)/sizeof(KANJI));
return _ext_unicode_count;
}
unsigned short KanjiInfo::jis2sjis(unsigned short ch) {
unsigned c1,c2;
c1 = (ch >> 8);
c2 = (ch & 0xff);
c2 += (c1 % 2) ? ((c2 > 95) ? 32 : 31) : 126; // jis code -> sjis code [jis2sjis() from jconv.c]
c1 = ((c1+1) >> 1) + ((c1 < 95) ? 112 : 176); // jis code -> sjis code [jis2sjis() from jconv.c]
return ((c1 << 8) | (c2));
}
unsigned short KanjiInfo::jis2unicode (unsigned short ch) {
if ((ch <= 0x7e)) return (ch); // ASCII
if ((ch >= 0x0080) && (ch <= 0x00ff)) return (ext_unicode[ch-0x80]); // Extended ASCII
if ((ch >= 0x2330) && (ch <= 0x237a)) return (ch-0x2330+0xff10); // Japanese ASCII
if ((ch >= 0x2421) && (ch <= 0x2473)) return (ch-0x2421+0x3041); // Hiragana
if ((ch >= 0x2521) && (ch <= 0x2576)) return (ch-0x2521+0x30a1); // Katakana
if ((ch >= 0x2621) && (ch <= 0x2658)) return (ch-0x2621+0x0391); // Greek
if ((ch >= 0x2721) && (ch <= 0x2771)) return (ch-0x2721+0x0410); // Cyrillic
if ((ch >= 0x3021) && (ch <= 0x7426)) { // Kanji
ch -= 0x3021;
ch = (ch >> 8)*94+(ch&0x00ff);
return (kanji_unicode[ch]);
}
if ((ch >= 0x2121) && (ch <= 0x217e)) return (misc_unicode[ch-0x2121]); // Main symbol group
if ((ch >= 0x2221) && (ch <= 0x227f)) return (misc_unicode[ch-0x2221+94]); // Secondary symbol group
return 0;
}
unsigned short KanjiInfo::sjis2jis (unsigned short ch) {
unsigned short p1,p2;
p1 = ch >> 8;
p2 = ch & 0xff;
sjis2jis (&p1,&p2);
return ((p1 << 8) | p2);
}
unsigned short KanjiInfo::unicode2jis (unsigned short ch) {
int i;
if ((ch <= 0x007e) ) return (ch); // ASCII
if ((ch >= 0x3041) && (ch <= 0x3093)) return (ch-0x3041+0x2421); // Hiragana
if ((ch >= 0x30a1) && (ch <= 0x30f6)) return (ch-0x30a1+0x2521); // Katakana
if ((ch >= 0x0391) && (ch <= 0x03c9)) return (ch-0x0391+0x2621); // Greek
if ((ch >= 0x0410) && (ch <= 0x044f)) return (ch-0x0410+0x2721); // Cyrillic
for (i = 0; i < countKanjiUnicode(); i++) { // The kanji
if (kanji_unicode[i] == ch) {
ch = i/94;
return (((ch+0x30) << 8) | (i-ch*94)+0x21);
}
}
for (i = 0; i < countMiscUnicode(); i++) {
// Symbol and pucntuation (main group)
if (misc_unicode[i] == ch) return ((i >= 94) ? 0x2221+i-94 : 0x2121+i);
}
for (i = 0; i < countExtUnicode(); i++) {
// Extneded ascii codes.
if (ext_unicode[i] == ch) return (i+0x80);
}
if ((ch >= 0xff10) && (ch <= 0xff5a)) return (ch-0xff10+0x2330); // Japanese ASCII.
return (0); // The Japanese ASCII needs to be here because some puncutation is stored within gaps
} // in the JASCII table, and if we move this before the misc codes they will not be found!
void KanjiInfo::sjis2jis (unsigned short *p1,unsigned short *p2) {
unsigned short c1 = *p1;
unsigned short c2 = *p2;
unsigned short adjust = c2 < 159;
unsigned short rowOffset = (c1 < 160) ? 112 : 176;
unsigned short cellOffset = adjust ? ((c2 > 127) ? 32 : 31) : 126;
*p1 = ((c1 - rowOffset) << 1) - adjust;
*p2 -= cellOffset;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -