diff options
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/luafontloader/fontforge/Unicode/gwwiconv.c')
-rw-r--r-- | Build/source/texk/web2c/luatexdir/luafontloader/fontforge/Unicode/gwwiconv.c | 193 |
1 files changed, 159 insertions, 34 deletions
diff --git a/Build/source/texk/web2c/luatexdir/luafontloader/fontforge/Unicode/gwwiconv.c b/Build/source/texk/web2c/luatexdir/luafontloader/fontforge/Unicode/gwwiconv.c index 70f9e064dc3..4f47a7b2efb 100644 --- a/Build/source/texk/web2c/luatexdir/luafontloader/fontforge/Unicode/gwwiconv.c +++ b/Build/source/texk/web2c/luatexdir/luafontloader/fontforge/Unicode/gwwiconv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2008 by George Williams */ +/* Copyright (C) 2004-2012 by George Williams */ /* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -33,10 +33,6 @@ #include <ustring.h> #include <stdio.h> -#ifdef LUA_FF_LIB -extern void LUAUI_LogError(const char *fmt,...); -#endif - #ifndef HAVE_ICONV_H /* I have written an limited iconv which will convert either to or from unichar_t */ @@ -114,14 +110,16 @@ static enum encoding name_to_enc(const char *encname) { { "mac", e_mac }, { "Macintosh", e_mac }, { "MS-ANSI", e_win }, -#ifdef FROM_CJK_ICONV { "EUC-KR", e_wansung }, { "johab", e_johab }, + { "ISO-2022-KR", e_jiskorean }, + { "ISO-2022-CN", e_jisgb }, { "EUC-CN", e_jisgbpk }, { "big5", e_big5 }, { "big5hkscs", e_big5hkscs }, + { "ISO-2022-JP", e_jis }, + { "ISO-2022-JP-2", e_jis2 }, { "Sjis", e_sjis }, -#endif { "UTF-8", e_utf8 }, { "UTF8", e_utf8 }, { NULL }}; @@ -145,19 +143,9 @@ gww_iconv_t gww_iconv_open(const char *toenc,const char *fromenc) { if ( stuff.from==(enum encoding) -1 || stuff.to==(enum encoding) -1 ) { /*fprintf( stderr, "Unknown encoding\n" );*/ return( (iconv_t)(-1) ); -#ifdef UNICHAR_16 - } else if ( stuff.from!=e_unicode && stuff.to!=e_unicode ) { - fprintf( stderr, "Bad call to gww_iconv_open, neither arg is UCS2\n" ); -return( (iconv_t)(-1) ); -#else } else if ( stuff.from!=e_ucs4 && stuff.to!=e_ucs4 ) { -#ifdef LUA_FF_LIB - LUAUI_LogError("Bad call to gww_iconv_open, neither arg is UCS4 (%s->%s)", fromenc, toenc); -#else - fprintf( stderr, "Bad call to gww_iconv_open, neither arg is UCS4\n" ); -#endif + fprintf( stderr, "Bad call to gww_iconv_open, neither arg is UCS4\n" ); return( (iconv_t)(-1) ); -#endif } ret = galloc(sizeof(struct gww_iconv_t)); @@ -240,7 +228,6 @@ return( (size_t) -1 ); /* Incomplete multi-byte sequence */ } else return( (size_t) -1 ); } -#ifdef TO_CJK_ICONV } else if ( cd->to==e_johab || cd->to==e_big5 || cd->to==e_big5hkscs ) { struct charmap2 *table = cd->to==e_johab ? &johab_from_unicode : cd->to==e_big5 ? &big5_from_unicode : @@ -273,8 +260,6 @@ return( (size_t) -1 ); } else return( (size_t) -1 ); } -#endif -#ifdef TO_CJK_ICONV } else if ( cd->to==e_wansung || cd->to==e_jisgbpk ) { struct charmap2 *table = cd->to==e_wansung ? &ksc5601_from_unicode : &gb2312_from_unicode; @@ -306,8 +291,6 @@ return( (size_t) -1 ); } else return( (size_t) -1 ); } -#endif -#ifdef TO_CJK_ICONV } else if ( cd->to==e_sjis ) { unsigned char *plane1; unsigned short *plane; @@ -344,7 +327,39 @@ return( (size_t) -1 ); } else return( (size_t) -1 ); } -#endif + } else if ( cd->to==e_jis || cd->to==e_jis2 || + cd->to==e_jiskorean || cd->to==e_jisgb ) { + struct charmap2 *table = cd->to==e_jisgb ? &gb2312_from_unicode : + cd->to==e_jiskorean ? &ksc5601_from_unicode : + &jis_from_unicode; + unsigned short *plane; + while ( *inlen>1 && *outlen>1 ) { + int highch, lowch; + if ( endian == end_little ) { + highch = ((unsigned char *) *inbuf)[1], lowch = *(unsigned char *) *inbuf; + } else { + highch = *(unsigned char *) *inbuf, lowch = ((unsigned char *) *inbuf)[1]; + } + if ( highch>=table->first && highch<=table->last && + (plane = table->table[highch])!=NULL && + (ch=plane[lowch])!=0 ) { + if ( ch>=0x8000 ) { + if ( cd->to!=e_jis2 ) +return( (size_t) -1 ); + ch -= 0x8000; + } else { + if ( cd->to==e_jis2 ) +return( (size_t) -1 ); + } + *((*outbuf)++) = (ch>>8); + *((*outbuf)++) = (ch&0xff); + *outlen -= 2; + *inlen -= 2; + *inbuf += 2; + ++char_cnt; + } else +return( (size_t) -1 ); + } } else if ( cd->to==e_utf8 ) { while ( *inlen>1 && *outlen>0 ) { unichar_t uch; @@ -421,7 +436,6 @@ return( (size_t) -1 ); /* Incomplete multi-byte sequence */ } else return( (size_t) -1 ); } -#ifdef TO_CJK_ICONV } else if ( cd->to==e_johab || cd->to==e_big5 || cd->to==e_big5hkscs ) { struct charmap2 *table = cd->to==e_johab ? &johab_from_unicode : cd->to==e_big5 ? &big5_from_unicode : @@ -454,8 +468,6 @@ return( (size_t) -1 ); } else return( (size_t) -1 ); } -#endif -#ifdef TO_CJK_ICONV } else if ( cd->to==e_wansung || cd->to==e_jisgbpk ) { struct charmap2 *table = cd->to==e_wansung ? &ksc5601_from_unicode : &gb2312_from_unicode; @@ -487,8 +499,6 @@ return( (size_t) -1 ); } else return( (size_t) -1 ); } -#endif -#ifdef TO_CJK_ICONV } else if ( cd->to==e_sjis ) { unsigned char *plane1; unsigned short *plane; @@ -525,7 +535,39 @@ return( (size_t) -1 ); } else return( (size_t) -1 ); } -#endif + } else if ( cd->to==e_jis || cd->to==e_jis2 || + cd->to==e_jiskorean || cd->to==e_jisgb ) { + struct charmap2 *table = cd->to==e_jisgb ? &gb2312_from_unicode : + cd->to==e_jiskorean ? &ksc5601_from_unicode : + &jis_from_unicode; + unsigned short *plane; + while ( *inlen>1 && *outlen>1 ) { + int highch, lowch; + if ( endian == end_little ) { + highch = ((unsigned char *) *inbuf)[1], lowch = *(unsigned char *) *inbuf; + } else { + highch = ((unsigned char *) *inbuf)[2], lowch = ((unsigned char *) *inbuf)[3]; + } + if ( highch>=table->first && highch<=table->last && + (plane = table->table[highch])!=NULL && + (ch=plane[lowch])!=0 ) { + if ( ch>=0x8000 ) { + if ( cd->to!=e_jis2 ) +return( (size_t) -1 ); + ch -= 0x8000; + } else { + if ( cd->to==e_jis2 ) +return( (size_t) -1 ); + } + *((*outbuf)++) = (ch>>8); + *((*outbuf)++) = (ch&0xff); + *outlen -= 2; + *inlen -= 4; + *inbuf += 4; + ++char_cnt; + } else +return( (size_t) -1 ); + } } else if ( cd->to==e_utf8 ) { while ( *inlen>1 && *outlen>0 ) { int uch; @@ -592,7 +634,62 @@ return( (size_t) -1 ); *outlen -= sizeof(unichar_t); ++char_cnt; } -#ifdef FROM_CJK_ICONV + } else if ( cd->from==e_jis || cd->from==e_jis2 || + cd->from==e_jiskorean || cd->from==e_jisgb ) { + table = cd->from==e_jisgb ? unicode_from_gb2312 : + cd->from==e_jiskorean ? unicode_from_ksc5601 : + cd->from==e_jis ? unicode_from_jis208 : + unicode_from_jis212; + while ( *inlen>1 && *outlen>1 ) { + unsigned char *ipt = (unsigned char *) *inbuf; + int ch; + if ( *ipt<0x21 || *ipt>0x7e || ipt[1]<0x21 || ipt[1]>0x7e ) +return( (size_t) -1 ); + ch = (*ipt-0x21)*94 + (ipt[1]-0x21); + ch = table[ch]; + *inlen -= 2; + *inbuf = (char *) ipt+2; + if ( endian==end_little ) { + *((*outbuf)++) = ch&0xff; + *((*outbuf)++) = ch>>8; + } else { + *((*outbuf)++) = ch>>8; + *((*outbuf)++) = ch&0xff; + } + *outlen -= sizeof(unichar_t); + ++char_cnt; + } + if ( *inlen==1 && *outlen>0 ) +return( (size_t) -1 ); /* Incomplete multi-byte sequence */ + } else if ( cd->from==e_wansung || cd->from==e_jisgbpk ) { + table = cd->from==e_jisgbpk ? unicode_from_gb2312 : + unicode_from_ksc5601 ; + while ( *inlen>0 && *outlen>1 ) { + unsigned char *ipt = (unsigned char *) *inbuf; + int ch; + if ( *ipt<0x7f ) { + ch = *ipt; + --*inlen; + *inbuf = (char *) ipt+1; + } else { + if ( *ipt<0xa1 || *ipt>0xfe || ipt[1]<0xa1 || ipt[1]>0xfe || + *inlen==1 ) +return( (size_t) -1 ); + ch = (*ipt-0xa1)*94 + (ipt[1]-0xa1); + ch = table[ch]; + *inlen -= 2;; + *inbuf = (char *) ipt+2; + } + if ( endian==end_little ) { + *((*outbuf)++) = ch&0xff; + *((*outbuf)++) = ch>>8; + } else { + *((*outbuf)++) = ch>>8; + *((*outbuf)++) = ch&0xff; + } + *outlen -= sizeof(unichar_t); + ++char_cnt; + } } else if ( cd->from==e_johab || cd->from==e_big5 || cd->from==e_big5hkscs ) { int offset; if ( cd->from==e_big5 ) { @@ -675,7 +772,6 @@ return( (size_t) -1 ); *outlen -= sizeof(unichar_t); ++char_cnt; } -#endif } else if ( cd->from==e_utf8 ) { while ( *inlen>0 && *outlen>sizeof(unichar_t) ) { unsigned char *ipt = (unsigned char *) *inbuf; @@ -746,7 +842,37 @@ return( (size_t) -1 ); *outlen -= sizeof(unichar_t); ++char_cnt; } -#ifdef FROM_CJK_ICONV + } else if ( cd->from==e_jis || cd->from==e_jis2 || + cd->from==e_jiskorean || cd->from==e_jisgb ) { + table = cd->from==e_jisgb ? unicode_from_gb2312 : + cd->from==e_jiskorean ? unicode_from_ksc5601 : + cd->from==e_jis ? unicode_from_jis208 : + unicode_from_jis212; + while ( *inlen>1 && *outlen>1 ) { + unsigned char *ipt = (unsigned char *) *inbuf; + int ch; + if ( *ipt<0x21 || *ipt>0x7e || ipt[1]<0x21 || ipt[1]>0x7e ) +return( (size_t) -1 ); + ch = (*ipt-0x21)*94 + (ipt[1]-0x21); + ch = table[ch]; + *inlen -= 2; + *inbuf = (char *) ipt+2; + if ( endian==end_little ) { + *((*outbuf)++) = 0; + *((*outbuf)++) = 0; + *((*outbuf)++) = ch&0xff; + *((*outbuf)++) = ch>>8; + } else { + *((*outbuf)++) = ch>>8; + *((*outbuf)++) = ch&0xff; + *((*outbuf)++) = 0; + *((*outbuf)++) = 0; + } + *outlen -= sizeof(unichar_t); + ++char_cnt; + } + if ( *inlen==1 && *outlen>0 ) +return( (size_t) -1 ); /* Incomplete multi-byte sequence */ } else if ( cd->from==e_wansung || cd->from==e_jisgbpk ) { table = cd->from==e_jisgbpk ? unicode_from_gb2312 : unicode_from_ksc5601 ; @@ -870,7 +996,6 @@ return( (size_t) -1 ); *outlen -= sizeof(unichar_t); ++char_cnt; } -#endif } else if ( cd->from==e_utf8 ) { while ( *inlen>0 && *outlen>sizeof(unichar_t) ) { unsigned char *ipt = (unsigned char *) *inbuf; |