@@ -26,6 +26,16 @@ CODEC_INIT(big5hkscs)
2626 return 0 ;
2727}
2828
29+ /*
30+ * There are four possible pair unicode -> big5hkscs maps as in HKSCS 2004:
31+ * U+00CA U+0304 -> 8862 (U+00CA alone is mapped to 8866)
32+ * U+00CA U+030C -> 8864
33+ * U+00EA U+0304 -> 88a3 (U+00EA alone is mapped to 88a7)
34+ * U+00EA U+030C -> 88a5
35+ * These are handled by not mapping tables but a hand-written code.
36+ */
37+ static const DBCHAR big5hkscs_pairenc_table [4 ] = {0x8862 , 0x8864 , 0x88a3 , 0x88a5 };
38+
2939ENCODER (big5hkscs )
3040{
3141 while (inleft > 0 ) {
@@ -46,7 +56,27 @@ ENCODER(big5hkscs)
4656 REQUIRE_OUTBUF (2 )
4757
4858 if (c < 0x10000 ) {
49- TRYMAP_ENC (big5hkscs_bmp , code , c );
59+ TRYMAP_ENC (big5hkscs_bmp , code , c ) {
60+ if (code == MULTIC ) {
61+ if (inleft >= 2 &&
62+ ((c & 0xffdf ) == 0x00ca ) &&
63+ (((* inbuf )[1 ] & 0xfff7 ) == 0x0304 )) {
64+ code = big5hkscs_pairenc_table [
65+ ((c >> 4 ) |
66+ ((* inbuf )[1 ] >> 3 )) & 3 ];
67+ insize = 2 ;
68+ }
69+ else if (inleft < 2 &&
70+ !(flags & MBENC_FLUSH ))
71+ return MBERR_TOOFEW ;
72+ else {
73+ if (c == 0xca )
74+ code = 0x8866 ;
75+ else /* c == 0xea */
76+ code = 0x88a7 ;
77+ }
78+ }
79+ }
5080 else TRYMAP_ENC (big5 , code , c );
5181 else return 1 ;
5282 }
@@ -67,7 +97,7 @@ ENCODER(big5hkscs)
6797 return 0 ;
6898}
6999
70- #define BH2S (c1 , c2 ) (((c1) - 0x88 ) * (0xfe - 0x40 + 1) + ((c2) - 0x40))
100+ #define BH2S (c1 , c2 ) (((c1) - 0x87 ) * (0xfe - 0x40 + 1) + ((c2) - 0x40))
71101
72102DECODER (big5hkscs )
73103{
@@ -96,19 +126,19 @@ hkscsdec: TRYMAP_DEC(big5hkscs, decoded, c, IN2) {
96126 int s = BH2S (c , IN2 );
97127 const unsigned char * hintbase ;
98128
99- assert (0x88 <= c && c <= 0xfe );
129+ assert (0x87 <= c && c <= 0xfe );
100130 assert (0x40 <= IN2 && IN2 <= 0xfe );
101131
102- if (BH2S (0x88 , 0x40 ) <= s && s <= BH2S (0xa0 , 0xfe )) {
132+ if (BH2S (0x87 , 0x40 ) <= s && s <= BH2S (0xa0 , 0xfe )) {
103133 hintbase = big5hkscs_phint_0 ;
104- s -= BH2S (0x88 , 0x40 );
134+ s -= BH2S (0x87 , 0x40 );
105135 }
106136 else if (BH2S (0xc6 ,0xa1 ) <= s && s <= BH2S (0xc8 ,0xfe )){
107- hintbase = big5hkscs_phint_11939 ;
137+ hintbase = big5hkscs_phint_12130 ;
108138 s -= BH2S (0xc6 , 0xa1 );
109139 }
110140 else if (BH2S (0xf9 ,0xd6 ) <= s && s <= BH2S (0xfe ,0xfe )){
111- hintbase = big5hkscs_phint_21733 ;
141+ hintbase = big5hkscs_phint_21924 ;
112142 s -= BH2S (0xf9 , 0xd6 );
113143 }
114144 else
@@ -123,7 +153,17 @@ hkscsdec: TRYMAP_DEC(big5hkscs, decoded, c, IN2) {
123153 NEXT (2 , 1 )
124154 }
125155 }
126- else return 2 ;
156+ else {
157+ switch ((c << 8 ) | IN2 ) {
158+ case 0x8862 : WRITE2 (0x00ca , 0x0304 ); break ;
159+ case 0x8864 : WRITE2 (0x00ca , 0x030c ); break ;
160+ case 0x88a3 : WRITE2 (0x00ea , 0x0304 ); break ;
161+ case 0x88a5 : WRITE2 (0x00ea , 0x030c ); break ;
162+ default : return 2 ;
163+ }
164+
165+ NEXT (2 , 2 ) /* all decoded codepoints are pairs, above. */
166+ }
127167 }
128168
129169 return 0 ;
0 commit comments