#include "xttversion.h"
#if 0
static char const * const releaseID =
_XTT_RELEASE_NAME;
#endif
#include "xttcommon.h"
#include "xttcap.h"
#include "xttcconv.h"
#include "xttcconvP.h"
typedef enum
{
JISX0208
} CharSetMagic;
static CharSetRelation const charSetRelations[] = {
{ "jisx0208", NULL, NULL, JISX0208, { 0x21, 0x7e, 0x21, 0x74, 0x2121 } },
{ "gt", NULL, NULL, JISX0208, { 0x21, 0x7e, 0x21, 0x74, 0x2121 } },
{ NULL, NULL, NULL, 0, { 0, 0, 0, 0, 0 } }
};
CODECONV_TEMPLATE(cc_jisx0208_to_win_ucs2);
CODECONV_TEMPLATE(cc_jisx0208_to_sjis);
CODECONV_TEMPLATE(cc_jisx0208_to_std_ucs2);
CODECONV_CALLBACK_TEMPLATE(cb_jisx0208_to_ucs2);
static MapIDRelation const mapIDRelations[] = {
{ JISX0208, EPlfmMS, EEncMSUnicode,
cc_jisx0208_to_win_ucs2,
cb_jisx0208_to_ucs2 },
{ JISX0208, EPlfmISO, EEncISO10646,
cc_jisx0208_to_std_ucs2,
cb_jisx0208_to_ucs2 },
{ JISX0208, EPlfmUnicode, EEncAny,
cc_jisx0208_to_std_ucs2,
cb_jisx0208_to_ucs2 },
{ JISX0208, EPlfmApple, EEncAppleJapanese,
cc_jisx0208_to_sjis,
NULL },
{ JISX0208, EPlfmMS, EEncMSShiftJIS,
cc_jisx0208_to_sjis,
NULL },
{ -1, 0, 0, NULL, NULL }
};
STD_ENTRYFUNC_TEMPLATE(JISX0208_entrypoint)
CODECONV_CALLBACK_TEMPLATE(cb_jisx0208_to_ucs2)
{
SPropRecValContainer contRecValue;
if (SPropRecValList_search_record(charSetHints->refListPropRecVal,
&contRecValue,
"EncodingOptions")) {
char const *str =
SPropContainer_value_str(contRecValue);
if (tolower(*str) == 'm') {
refCodeConverterInfo->ptrCodeConverter = cc_jisx0208_to_win_ucs2;
} else if (tolower(*str) == 'i') {
refCodeConverterInfo->ptrCodeConverter = cc_jisx0208_to_std_ucs2;
}
}
}
ft_char_code_t
cc_jisx0208_to_sjis(ft_char_code_t idx)
{
unsigned c1, c2, d1, d2;
c1 = (idx >> 8) & 0xff;
c2 = idx & 0xff;
d1 = ((c1 + 1) >> 1) + (c1 < 0x5f ? 0x70 : 0xb0);
d2 = c2 + ((c1 & 1) ? (c2 < 0x60 ? 0x1f : 0x20) : 0x7e);
return (d1<<8) + d2;
}
ft_char_code_t
cc_jisx0208_to_std_ucs2(ft_char_code_t codeSrc)
{
ucs2_t codeDst;
switch (codeSrc) {
case 0x2140:
codeDst = 0x005c;
break;
case 0x2141:
codeDst = 0x301c;
break;
case 0x2142:
codeDst = 0x2016;
break;
case 0x215d:
codeDst = 0x2212;
break;
case 0x2171:
codeDst = 0x00a2;
break;
case 0x2172:
codeDst = 0x00a3;
break;
case 0x224c:
codeDst = 0x00ac;
break;
default:
return cc_jisx0208_to_win_ucs2(codeSrc);
}
return codeDst;
}