~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/intl/uconv/ucvko/nsUnicodeToX11Johab.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * @(#)CharToByteX11Johab.java  1.1 99/08/28
 
3
 *
 
4
 * The contents of this file are subject to the Mozilla Public
 
5
 * License Version 1.1 (the "License"); you may not use this file
 
6
 * except in compliance with the License. You may obtain a copy of
 
7
 * the License at http://www.mozilla.org/MPL/
 
8
 *
 
9
 * Software distributed under the License is distributed on an "AS
 
10
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
11
 * implied. See the License for the specific language governing
 
12
 * rights and limitations under the License.
 
13
 *
 
14
 * The Original Code is CharToByteX11Johab.java
 
15
 *
 
16
 * The Initial Developer of the Original Code is Deogtae Kim
 
17
 * <dtkim@calab.kaist.ac.kr> (98/05/03) and
 
18
 * Based on: Hanterm source code adapted by Jungshik Shin
 
19
 * <jshin@pantheon.yale.edu>
 
20
 *
 
21
 * Contributor(s):
 
22
 *   Deogtae Kim <dtkim@calab.kaist.ac.kr> (99/08/28)
 
23
 *   Jungshik Shin <jshin@pantheon.yale.edu>
 
24
 *   Pierre Phaneuf <pp@ludusdesign.com>
 
25
 *
 
26
 * - Purposes:
 
27
 *   1. Enable displaying all 11,172 Modern hangul syllables with Hanterm
 
28
 *      johab fonts on Unix
 
29
 *   2. Enable displaying some of Unicode 2.0 ancient hangul syllables
 
30
 *      with Hanterm johab fonts on Unix
 
31
 *   3. Enable displaying all of Unicode 2.0 ancient hangul syllables with
 
32
 *      possible future extended Hanterm johab fonts on Unix
 
33
 *
 
34
 * - Installation Instructions:
 
35
 *   1. Install Hanterm Johab fonts and a proper font property file to Unix system.
 
36
 *      (Confer http://calab.kaist.ac.kr/~dtkim/java/)
 
37
 *   2. Make a directory "jdk1.x.x/classes/"
 
38
 *   3. Compile this class into "jdk1.x.x/classes/"
 
39
 *
 
40
 * - Hangule syllable break rule algorithm descriptions:
 
41
 *   The algorithm used here is slightly different from that of the Unicode standard 2.0.
 
42
 *   The standard saids that a (canonical) hangul syllable block is a sequence of leading
 
43
 *   consonants and a sequence of vowels and an optional sequence of trailing
 
44
 *   consonants.
 
45
 *   I think this unncessarily complicate matters.
 
46
 *   So, the algorithm chosen here is:
 
47
 *   A (non-canonical) hangul syllable block is the longest sequence comprised of
 
48
 *   an optional leading consonant and an optional vowel and an optional trailing consonant.
 
49
 *   The skipped leading consonants and vowels are considered as fillers.
 
50
 *   The merit of this algorithm is that any sequence of jamos can be composed validly.
 
51
 */
 
52
#include "nsUnicodeToX11Johab.h"
 
53
#include "nsUCvKODll.h"
 
54
 
 
55
 
 
56
typedef char byte;
 
57
 
 
58
// XPCOM stuff
 
59
NS_IMPL_ADDREF(nsUnicodeToX11Johab)
 
60
NS_IMPL_RELEASE(nsUnicodeToX11Johab)
 
61
nsresult nsUnicodeToX11Johab::QueryInterface(REFNSIID aIID,
 
62
                                          void** aInstancePtr)
 
63
{
 
64
  if (NULL == aInstancePtr) {
 
65
    return NS_ERROR_NULL_POINTER;
 
66
  }
 
67
 
 
68
  *aInstancePtr = NULL;
 
69
 
 
70
  static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
 
71
 
 
72
  if (aIID.Equals(NS_GET_IID(nsIUnicodeEncoder))) {
 
73
    *aInstancePtr = (void*) ((nsIUnicodeEncoder*)this);
 
74
    NS_ADDREF_THIS();
 
75
    return NS_OK;
 
76
  }
 
77
  if (aIID.Equals(NS_GET_IID(nsICharRepresentable))) {
 
78
    *aInstancePtr = (void*) ((nsICharRepresentable*)this);
 
79
    NS_ADDREF_THIS();
 
80
    return NS_OK;
 
81
  }
 
82
  if (aIID.Equals(kISupportsIID)) {
 
83
    *aInstancePtr = (void*) ((nsISupports*)((nsIUnicodeEncoder*)this));
 
84
    NS_ADDREF_THIS();
 
85
    return NS_OK;
 
86
  }
 
87
 
 
88
  return NS_NOINTERFACE;
 
89
}
 
90
 
 
91
 
 
92
NS_IMETHODIMP nsUnicodeToX11Johab::SetOutputErrorBehavior(
 
93
      PRInt32 aBehavior,
 
94
      nsIUnicharEncoder * aEncoder, PRUnichar aChar)
 
95
{
 
96
   return NS_ERROR_NOT_IMPLEMENTED;
 
97
}
 
98
 
 
99
//   1  /*
 
100
//   2   * @(#)CharToByteX11Johab.java  1.0 98/05/03
 
101
//   3   *
 
102
//   4   * Purposes:
 
103
//   5   *   1. Enable displaying all 11,172 Modern hangul syllables with Hanterm
 
104
//   6   *      johab fonts on Unix
 
105
//   7   *   2. Enable displaying some of Unicode 2.0 ancient hangul syllables
 
106
//   8   *      with Hanterm johab fonts on Unix
 
107
//   9   *   3. Enable displaying all of Unicode 2.0 ancient hangul syllables with
 
108
//  10   *      possible future extended Hanterm johab fonts on Unix
 
109
//  11   *
 
110
//  12   * Installation Instructions:
 
111
//  13   * 1. Install Hanterm Johab fonts and a proper font property file to Unix syste
 
112
//  14  m.
 
113
//  15   *    (Confer http://calab.kaist.ac.kr/~dtkim/java/ )
 
114
//  16   * 2. Make a directory "jdk1.x.x/classes/"
 
115
//  17   * 3. Compile this class into "jdk1.x.x/classes/"
 
116
//  18   *
 
117
//  19   * Author: Deogtae Kim <dtkim@calab.kaist.ac.kr>, 98/05/03
 
118
//  20   *
 
119
//  21   * Based on: Hanterm source code adapted by Jungshik Shin <jshin@pantheon.yale.
 
120
//  22  edu>
 
121
//  23   */
 
122
//  24  
 
123
//  25  import sun.io.CharToByteConverter;
 
124
//  26  import sun.io.MalformedInputException;
 
125
//  27  import sun.io.UnknownCharacterException;
 
126
//  28  import sun.io.ConversionBufferFullException;
 
127
//  29  
 
128
//  30  public class CharToByteX11Johab extends CharToByteConverter
 
129
//  31  {
 
130
//  32      int state = START;
 
131
//  33  
 
132
//  34      public static final int START = 0;
 
133
//  35      public static final int LEADING_CONSONANT = 1;
 
134
//  36      public static final int VOWEL = 2;
 
135
//  37  
 
136
//  38      int l = 0x5f; // leading consonant
 
137
//  39      int v = 0;    // vowel
 
138
//  40      int t = 0;    // trailing consonant
 
139
 
 
140
#define START 1
 
141
#define LEADING_CONSONANT 1
 
142
#define VOWEL 2
 
143
 
 
144
// constructor and destroctor
 
145
 
 
146
nsUnicodeToX11Johab::nsUnicodeToX11Johab()
 
147
{
 
148
   Reset();
 
149
   state = START;
 
150
   l = 0x5f;
 
151
   v = 0;
 
152
   t = 0;
 
153
 
 
154
}
 
155
nsUnicodeToX11Johab::~nsUnicodeToX11Johab()
 
156
{
 
157
}
 
158
 
 
159
//  41  
 
160
//  42      /*
 
161
//  43       * This method indicates the charset name for this font.
 
162
//  44       */
 
163
//  45      public String getCharacterEncoding()
 
164
//  46      {
 
165
//  47          return "X11Johab";
 
166
//  48      }
 
167
//  49  
 
168
//  50      /*
 
169
//  51       * This method indicates the range this font covers.
 
170
//  52       */
 
171
//  53      public boolean canConvert(char ch)
 
172
//  54      {
 
173
//  55          if ( 0xac00 <= ch && ch <= 0xd7a3      // Modern hangul syllables
 
174
//  56               || 0x1100 <= ch && ch <= 0x1112   // modern leading consonants (19
 
175
//  57  )
 
176
//  58               || 0x1113 <= ch && ch <= 0x1159   // ancient leading consonants (7
 
177
//  59  1)
 
178
//  60                  && lconBase[ch-0x1100] != 0
 
179
//  61               || ch == 0x115f                   // leading consonants filler
 
180
//  62               || 0x1160 <= ch && ch <= 0x1175   // modern vowels (21)
 
181
//  63               || 0x1176 <= ch && ch <= 0x11a2   // ancient vowels (45)
 
182
//  64                  && vowBase[ch-0x1160] != 0
 
183
//  65               || 0x11a8 <= ch && ch <= 0x11c2   // modern trailing consonants (2
 
184
//  66  7)
 
185
//  67               || 0x11c3 <= ch && ch <= 0x11f9   // ancient trailing consonants (
 
186
//  68  55)
 
187
//  69                  && tconBase[ch-0x11a7] != 0 )
 
188
//  70              return true;
 
189
//  71          return false;
 
190
//  72      }
 
191
 
 
192
#define canConvert(ch) \
 
193
 (((0xac00 <=(ch))&&((ch)<= 0xd7a3))    /* Modern hangul syllables         */\
 
194
   || ((0x1100 <=(ch))&&((ch)<= 0x1112)) /* modern leading consonants (19)  */\
 
195
   || ((0x1113 <=(ch))&&((ch)<= 0x1159) /* ancient leading consonants (71) */\
 
196
       && (lconBase[ch-0x1100] != 0))                                        */\
 
197
   || ((ch) == 0x115f)                 /* leading consonants filler       */\
 
198
   || ((0x1160 <=(ch))&&((ch)<= 0x1175))  /* modern vowels (21)              */\
 
199
   || ((0x1176 <=(ch))&&((ch)<= 0x11a2) /* ancient vowels (45)             */\
 
200
       && (vowBase[(ch)-0x1160] != 0  ))                                        */\
 
201
   || ((0x11a8 <=(ch))&&((ch)<= 0x11c2))/* modern trailing consonants (27) */\
 
202
   || ((0x11c3 <=(ch))&&((ch)<= 0x11f9) /* ancient trailing consonants (55)*/\
 
203
       && (tconBase[(ch)-0x11a7] != 0 )))
 
204
 
 
205
//  73  
 
206
//  74      /*
 
207
//  75       * This method converts the unicode to this font index.
 
208
//  76       * Note: ConversionBufferFullException is not handled
 
209
//  77       *       since this class is only used for character display.
 
210
//  78       */
 
211
//  79      public int convert(char[] input, int inStart, int inEnd,
 
212
//  80                         byte[] output, int outStart, int outEnd)
 
213
//  81          throws MalformedInputException, UnknownCharacterException
 
214
//  82      {
 
215
NS_IMETHODIMP nsUnicodeToX11Johab::Convert(
 
216
      const PRUnichar * input, PRInt32 * aSrcLength,
 
217
      char * output, PRInt32 * aDestLength)
 
218
{
 
219
//  83          charOff = inStart;
 
220
//  84          byteOff = outStart;
 
221
                charOff = byteOff = 0;
 
222
/*  85  */
 
223
/*  86  */      for (; charOff < *aSrcLength; charOff++)
 
224
/*  87  */      {
 
225
/*  88  */          PRUnichar ch = input[charOff];
 
226
/*  89  */          if (0xac00 <= ch && ch <= 0xd7a3)
 
227
/*  90  */          {
 
228
/*  91  */              if ( state != START )
 
229
/*  92  */                  composeHangul(output);
 
230
/*  93  */              ch -= 0xac00;
 
231
/*  94  */              l = (ch / 588);        // 588 = 21*28
 
232
/*  95  */              v = ( ch / 28 ) % 21  + 1;
 
233
/*  96  */              t = ch % 28;
 
234
/*  97  */              composeHangul(output);
 
235
/*  98  */          } else if (0x1100 <= ch && ch <= 0x115f)
 
236
/*  99  */          {  // leading consonants (19 + 71 + 1)
 
237
/* 100  */              if ( state != START )
 
238
/* 101  */                  composeHangul(output);
 
239
/* 102  */              l = ch - 0x1100;
 
240
/* 103  */              state = LEADING_CONSONANT;
 
241
/* 104  */          } else if (1160 <= ch && ch <= 0x11a2)
 
242
/* 105  */          {  // vowels (1 + 21 + 45)
 
243
/* 106  */              v = ch - 0x1160;
 
244
/* 107  */              state = VOWEL;
 
245
/* 108  */          } else if (0x11a8 <= ch && ch <= 0x11f9)
 
246
/* 109  */          {  // modern trailing consonants (27)
 
247
/* 110  */              t = ch - 0x11a7;
 
248
/* 111  */              composeHangul(output);
 
249
// 112              } else
 
250
// 113              {
 
251
// 114                  throw new UnknownCharacterException();
 
252
/* 115  */           }
 
253
/* 116  */       }
 
254
/* 117  */
 
255
/* 118  */       if ( state != START )
 
256
/* 119  */           composeHangul( output );
 
257
/* 120  */
 
258
// 121           return byteOff - outStart;
 
259
// 122       }
 
260
                 *aDestLength = byteOff;
 
261
                 return NS_OK;
 
262
}
 
263
// 123  
 
264
// 124      public int flush(byte output[], int i, int j)
 
265
// 125          throws MalformedInputException
 
266
// 126      {
 
267
NS_IMETHODIMP nsUnicodeToX11Johab::Finish(
 
268
      char * output, PRInt32 * aDestLength)
 
269
{
 
270
/* 127  */      byteOff = 0;
 
271
/* 128  */      PRInt32 len = 0;
 
272
/* 129  */      if ( state != START )
 
273
/* 130  */      {
 
274
/* 131  */          composeHangul( output );
 
275
/* 132  */          len = byteOff;
 
276
/* 133  */      }
 
277
/* 134  */      byteOff = charOff = 0;
 
278
// 135          return len;
 
279
                *aDestLength = len;
 
280
// 136      }
 
281
// 137  
 
282
   return NS_OK;
 
283
}
 
284
 
 
285
//================================================================
 
286
NS_IMETHODIMP nsUnicodeToX11Johab::Reset()
 
287
// 138      public void reset()
 
288
/* 139 */  {
 
289
/* 140 */      byteOff = charOff = 0;
 
290
/* 141 */      state = START;
 
291
/* 142 */      l = 0x5f;
 
292
/* 143 */      v = t = 0;
 
293
               return NS_OK;
 
294
/* 144 */  }
 
295
//================================================================
 
296
// 145  
 
297
// 146      public int getMaxBytesPerChar()
 
298
// 147      {
 
299
// 148          return 6;
 
300
// 149      }
 
301
 
 
302
NS_IMETHODIMP nsUnicodeToX11Johab::GetMaxLength(
 
303
      const PRUnichar * aSrc, PRInt32 aSrcLength,
 
304
      PRInt32 * aDestLength)
 
305
{
 
306
   *aDestLength = (aSrcLength + 1) *  6;
 
307
   return NS_OK;
 
308
}
 
309
//================================================================
 
310
 
 
311
// 150  
 
312
// 151      // The base font index for leading consonants
 
313
// 152  
 
314
// 153      static final short[] lconBase = {
 
315
static const PRUint16 lconBase[] = {
 
316
/* 154 */       // modern leading consonants (19)
 
317
/* 155 */       1, 11, 21, 31, 41, 51,
 
318
/* 156 */       61, 71, 81, 91, 101, 111,
 
319
/* 157 */       121, 131, 141, 151, 161, 171,
 
320
/* 158 */       181, 
 
321
/* 159 */
 
322
/* 160 */       // ancient leading consonants (71 + reserved 5 + filler 1)
 
323
/* 161 */       0, 0, 0, 0, 0, 0,       // \u1113 ~ : 
 
324
/* 162 */       0, 0, 0, 0, 0, 201,     // \u1119 ~ :
 
325
/* 163 */       0, 221, 251, 0, 0, 0,   // \u111f ~ :
 
326
/* 164 */       0, 0, 281, 0, 0, 0,     // \u1125 ~ :
 
327
/* 165 */       191, 0, 211, 0, 231, 0, // \u112b ~ :
 
328
/* 166 */       0, 241, 0, 0, 0, 291,   // \u1131 ~ :
 
329
/* 167 */       0, 0, 0, 0, 0, 0,       // \u1137 ~ :
 
330
/* 168 */       0, 0, 0, 261, 0, 0,     // \u113d ~ :
 
331
/* 169 */       0, 0, 0, 0, 0, 0,       // \u1143 ~ :
 
332
/* 170 */       0, 0, 0, 271, 0, 0,     // \u1149 ~ :
 
333
/* 171 */       0, 0, 0, 0, 0, 0,       // \u114f ~ :
 
334
/* 172 */       0, 0, 0, 0, 301,        // \u1155 ~ :
 
335
/* 173 */       0, 0, 0, 0, 0,          // \u115a ~ : reserved
 
336
/* 174 */       0,                      // \u115f   : leading consonant filler
 
337
/* 175 */  };
 
338
//================================================================
 
339
// 176  
 
340
// 177      // The base font index for vowels
 
341
// 178  
 
342
// 179     static final short[] vowBase = {
 
343
static const PRUint16 vowBase[] = {
 
344
/* 180 */      // modern vowels (filler + 21)
 
345
/* 181 */      0,311,314,317,320,323,   // (Fill), A, AE, YA, YAE, EO
 
346
/* 182 */      326,329,332,335,339,343, // E, YEO, YE, O, WA, WAE
 
347
/* 183 */      347,351,355,358,361,364, // OI, YO, U, WEO, WE, WI
 
348
/* 184 */      367,370,374,378,         // YU, EU, UI, I
 
349
/* 185 */ 
 
350
/* 186 */      // ancient vowels (45)
 
351
/* 187 */      0, 0, 0, 0, 0, 0,        // \u1176 ~ : A-O, A-U, YA-O, YA-YO, EO-O, EO- U
 
352
/* 189 */      0, 0, 0, 0, 0, 0,        // \u117c ~ : EO-EU, YEO-O, YEO-U, O-EO, O-E, O-YE
 
353
/* 191 */      0, 0, 381, 384, 0, 0,    // \u1182 ~ : O-O, O-U, YO-YA, YO-YAE, YO-YEO,  YO-O
 
354
/* 193 */      387, 0, 0, 0, 0, 0,      // \u1188 ~ : YO-I, U-A, U-AE, U-EO-EU, U-YE, U-U
 
355
/* 195 */      0, 0, 0, 390, 393, 0,    // \u118e ~ : YU-A, YU-EO, YU-E, YU-YEO, YU-YE , YU-U
 
356
/* 197 */      396, 0, 0, 0, 0, 0,      // \u1194 ~ : YU-I, EU-U, EU-EU, YI-U, I-A, I- YA
 
357
/* 199 */      0, 0, 0, 0, 399, 0,      // \u119a ~ : I-O, I-U, I-EU, I-ARAEA, ARAEA,   ARAEA-EO
 
358
/* 201 */      0, 402, 0                // \u11a0 ~ : ARAEA-U, ARAEA-I,SSANGARAEA 
 
359
/* 202 */  };
 
360
//================================================================
 
361
// 203  
 
362
// 204      // The base font index for trailing consonants
 
363
// 205  
 
364
// 206      static final short[] tconBase = {
 
365
static const PRUint16 tconBase[] = {
 
366
// 207          // modern trailing consonants (filler + 27)
 
367
/* 208  */      0, 
 
368
/* 209  */      405, 409, 413, 417, 421,
 
369
/* 210  */      425, 429, 433, 437, 441,
 
370
/* 211  */      445, 459, 453, 457, 461,
 
371
/* 212  */      465, 469, 473, 477, 481,
 
372
/* 213  */      485, 489, 493, 497, 501,
 
373
/* 214  */      505, 509,
 
374
// 215          
 
375
// 216          // ancient trailing consonants (55)
 
376
/* 217  */      0, 0, 0, 0, 0, 0,      // \u11c3 ~ :
 
377
/* 218  */      0, 0, 0, 0, 0, 0,      // \u11c9 ~ :
 
378
/* 219  */      0, 0, 0, 0, 0, 0,      // \u11cf ~ :
 
379
/* 220  */      0, 0, 0, 0, 513, 517,  // \u11d5 ~ :
 
380
/* 221  */      0, 0, 0, 0, 0, 0,      // \u11db ~ :
 
381
/* 222  */      0, 0, 0, 0, 0, 0,      // \u11e1 ~ :
 
382
/* 223  */      0, 0, 0, 0, 0, 0,      // \u11e7 ~ :
 
383
/* 224  */      0, 0, 0, 525, 0, 0,    // \u11ed ~ :
 
384
/* 225  */      0, 0, 0, 0, 0, 0,      // \u11f3 ~ :
 
385
/* 226  */      521                    // \u11f9:
 
386
/* 227  */  };
 
387
//================================================================
 
388
// 228  
 
389
// 229      // The mapping from vowels to leading consonant type
 
390
// 230      // in absence of trailing consonant
 
391
// 231  
 
392
// 232      static final short[] lconMap1 = {
 
393
static const PRUint8 lconMap1[] = {
 
394
/* 233  */      0,0,0,0,0,0,     // (Fill), A, AE, YA, YAE, EO
 
395
/* 234  */      0,0,0,1,3,3,     // E, YEO, YE, O, WA, WAE
 
396
/* 235  */      3,1,2,4,4,4,     // OI, YO, U, WEO, WE, WI
 
397
/* 236  */      2,1,3,0,         // YU, EU, UI, I
 
398
// 237  
 
399
// 238          // ancient vowels (45)
 
400
/* 239  */      3, 4, 3, 3, 3, 4,   // \u1176 ~ : A-O, A-U, YA-O, YA-YO, EO-O, EO-U
 
401
/* 240  */      4, 3, 4, 3, 3, 3,   // \u117c ~ : EO-EU, YEO-O, YEO-U, O-EO, O-E, O-YE
 
402
/* 241  */      1, 1, 3, 3, 3, 1,   // \u1182 ~ : O-O, O-U, YO-YA, YO-YAE, YO-YEO, YO-O
 
403
/* 242  */      3, 4, 4, 4, 4, 2,   // \u1188 ~ : YO-I, U-A, U-AE, U-EO-EU, U-YE, U-U
 
404
/* 243  */      3, 3, 3, 3, 3, 2,   // \u118e ~ : YU-A, YU-EO, YU-E, YU-YEO, YU-YE, YU-U
 
405
/* 245  */      4, 2, 2, 4, 0, 0,   // \u1194 ~ : YU-I, EU-U, EU-EU, YI-U, I-A, I-YA
 
406
/* 246  */      3, 4, 3, 0, 1, 3,   // \u119a ~ : I-O, I-U, I-EU, I-ARAEA, ARAEA, ARAEA-EO
 
407
/* 248  */      2, 3, 1             // \u11a0 ~ : ARAEA-U, ARAEA-I, SSANGARAEA
 
408
/* 249  */  };
 
409
//================================================================
 
410
// 250  
 
411
// 251      // The mapping from vowels to leading consonant type
 
412
// 252      // in presence of trailing consonant
 
413
// 253  
 
414
static const PRUint8 lconMap2[] = {
 
415
// 254      static final short[] lconMap2 = {
 
416
/* 255  */      5,5,5,5,5,5,     // (Fill), A, AE, YA, YAE, EO
 
417
/* 256  */      5,5,5,6,8,8,     // E, YEO, YE, O, WA, WAE
 
418
/* 257  */      8,6,7,9,9,9,     // OI, YO, U, WEO, WE, WI
 
419
/* 258  */      7,6,8,5,         // YU, EU, UI, I
 
420
// 259  
 
421
// 260          // ancient vowels (45)
 
422
/* 261  */      8, 9, 8, 8, 8, 9,   // \u1176 ~ : A-O, A-U, YA-O, YA-YO, EO-O, EO-U
 
423
/* 262  */      9, 8, 9, 8, 8, 8,   // \u117c ~ : EO-EU, YEO-O, YEO-U, O-EO, O-E, O-YE
 
424
/* 263  */      6, 6, 8, 8, 8, 6,   // \u1182 ~ : O-O, O-U, YO-YA, YO-YAE, YO-YEO, YO-O
 
425
/* 264  */      8, 9, 9, 9, 9, 7,   // \u1188 ~ : YO-I, U-A, U-AE, U-EO-EU, U-YE, U-U
 
426
/* 265  */      8, 8, 8, 8, 8, 7,   // \u118e ~ : YU-A, YU-EO, YU-E, YU-YEO, YU-YE, Y
 
427
/* 267  */      9, 7, 7, 9, 5, 5,   // \u1194 ~ : YU-I, EU-U, EU-EU, YI-U, I-A, I-YA
 
428
/* 268  */      8, 9, 8, 5, 6, 8,   // \u119a ~ : I-O, I-U, I-EU, I-ARAEA, ARAEA, ARAEA-EO
 
429
/* 270  */      7, 8, 6             // \u11a0 ~ : ARAEA-U, ARAEA-I, SSANGARAEA
 
430
/* 271  */  };
 
431
//================================================================
 
432
// 272  
 
433
// 273      // vowel type ; 1 = o and its alikes, 0 = others            
 
434
// 274      static final short[] vowType = {
 
435
static const PRUint8 vowType[] = {
 
436
/* 275  */      0,0,0,0,0,0,
 
437
/* 276  */      0,0,0,1,1,1,
 
438
/* 277  */      1,1,0,0,0,0,
 
439
/* 278  */      0,1,1,0,
 
440
// 279  
 
441
// 280          // ancient vowels (45)
 
442
/* 281  */      1, 0, 1, 1, 1, 0,   // \u1176 ~ : A-O, A-U, YA-O, YA-YO, EO-O, EO-U
 
443
/* 282  */      0, 1, 0, 1, 1, 1,   // \u117c ~ : EO-EU, YEO-O, YEO-U, O-EO, O-E, O-YE
 
444
/* 283  */      1, 1, 0, 0, 0, 0,   // \u1182 ~ : O-O, O-U, YO-YA, YO-YAE, YO-YEO, YO-O
 
445
/* 284  */      0, 0, 0, 0, 0, 0,   // \u1188 ~ : YO-I, U-A, U-AE, U-EO-EU, U-YE, U-U
 
446
/* 285  */      0, 0, 0, 0, 0, 0,   // \u118e ~ : YU-A, YU-EO, YU-E, YU-YEO, YU-YE, YU-U
 
447
/* 287  */      0, 0, 0, 0, 0, 0,   // \u1194 ~ : YU-I, EU-U, EU-EU, YI-U, I-A, I-YA
 
448
/* 288  */      0, 0, 0, 0, 0, 0,   // \u119a ~ : I-O, I-U, I-EU, I-ARAEA, ARAEA, ARAEA-EO
 
449
/* 290  */      0, 0, 0             // \u11a0 ~ : ARAEA-U, ARAEA-I, SSANGARAEA
 
450
/* 291  */  };
 
451
//================================================================
 
452
// 292  
 
453
// 293      // The mapping from trailing consonants to vowel type
 
454
// 294  
 
455
// 295      static final int[] tconType = {
 
456
static const PRUint8 tconType[] = {
 
457
/* 296  */      0, 1, 1, 1, 2, 1,
 
458
/* 297  */      1, 1, 1, 1, 1, 1,
 
459
/* 298  */      1, 1, 1, 1, 1, 1,
 
460
/* 299  */      1, 1, 1, 1, 1, 1,
 
461
/* 300  */      1, 1, 1, 1,
 
462
// 301  
 
463
// 302          // ancient trailing consonants (55)
 
464
/* 303  */      1, 1, 1, 1, 1, 1,  // \u11c3 ~ :
 
465
/* 304  */      1, 1, 1, 1, 1, 1,  // \u11c9 ~ :
 
466
/* 305  */      1, 1, 1, 1, 1, 1,  // \u11cf ~ :
 
467
/* 306  */      1, 1, 1, 1, 1, 1,  // \u11d5 ~ :
 
468
/* 307  */      1, 1, 1, 1, 1, 1,  // \u11db ~ :
 
469
/* 308  */      1, 1, 1, 1, 1, 1,  // \u11e1 ~ :
 
470
/* 309  */      1, 1, 1, 1, 1, 1,  // \u11e7 ~ :
 
471
/* 310  */      1, 1, 1, 1, 1, 1,  // \u11ed ~ :
 
472
/* 311  */      1, 1, 1, 1, 1, 1,  // \u11f3 ~ :
 
473
/* 312  */      1                  // \u11f9:
 
474
/* 313  */  };
 
475
//================================================================
 
476
// 314  
 
477
// 315      // The mapping from vowels to trailing consonant type
 
478
// 316  
 
479
// 317      static final int[] tconMap = {
 
480
static const PRUint8 tconMap[] = {
 
481
/* 318  */      0, 0, 2, 0, 2, 1,  // (Fill), A, AE, YA, YAE, EO
 
482
/* 319  */      2, 1, 2, 3, 0, 0,  // E, YEO, YE, O, WA, WAE
 
483
/* 320  */      0, 3, 3, 1, 1, 1,  // OI, YO, U, WEO, WE, WI
 
484
/* 321  */      3, 3, 0, 1,        // YU, EU, UI, I
 
485
// 322  
 
486
// 323          // ancient vowels (45)
 
487
/* 324  */      3, 3, 3, 3, 3, 3,   // \u1176 ~ : A-O, A-U, YA-O, YA-YO, EO-O, EO-U
 
488
/* 325  */      3, 3, 3, 1, 0, 0,   // \u117c ~ : EO-EU, YEO-O, YEO-U, O-EO, O-E, O-YE
 
489
/* 326  */      3, 3, 3, 1, 0, 3,   // \u1182 ~ : O-O, O-U, YO-YA, YO-YAE, YO-YEO, YO-O
 
490
/* 327  */      0, 0, 0, 0, 0, 3,   // \u1188 ~ : YO-I, U-A, U-AE, U-EO-EU, U-YE, U-U
 
491
/* 328  */      0, 1, 1, 1, 1, 3,   // \u118e ~ : YU-A, YU-EO, YU-E, YU-YEO, YU-YE, YU- U
 
492
/* 330  */      1, 3, 3, 3, 2, 2,   // \u1194 ~ : YU-I, EU-U, EU-EU, YI-U, I-A, I-YA
 
493
/* 331  */      3, 3, 3, 1, 3, 0,   // \u119a ~ : I-O, I-U, I-EU, I-ARAEA, ARAEA, ARAEA -EO
 
494
/* 333  */      3, 2, 3             // \u11a0 ~ : ARAEA-U, ARAEA-I, SSANGARAEA
 
495
/* 334  */  };
 
496
//================================================================
 
497
// 335  
 
498
// 336      void composeHangul(byte[] output)
 
499
void nsUnicodeToX11Johab::composeHangul(char* output)
 
500
/* 337  */  {
 
501
// 338          int ind;
 
502
                PRUint16 ind;
 
503
/* 339  */ 
 
504
/* 340  */      if ( lconBase[l] != 0 )
 
505
/* 341  */      {   // non-filler and supported by Hanterm Johab fonts
 
506
/* 342  */          ind = lconBase[l] + ( t > 0 ? lconMap2[v] : lconMap1[v] );
 
507
/* 343  */          output[byteOff++] = (byte) (ind / 256);
 
508
/* 344  */          output[byteOff++] = (byte) (ind % 256);
 
509
/* 345  */      }
 
510
/* 346  */
 
511
/* 347  */      if ( vowBase[v] != 0 )
 
512
/* 348  */      {   // non-filler and supported by Hanterm Johab fonts
 
513
/* 349  */          ind = vowBase[v];
 
514
/* 350  */          if ( vowType[v] == 1)
 
515
/* 351  */          {   //'o' and alikes 
 
516
/* 352  */              // GIYEOK and KIEUK got special treatment
 
517
/* 353  */              ind += ( (l == 0 || l == 15) ? 0 : 1)
 
518
/* 354  */                     + (t > 0 ?  2 : 0 );
 
519
/* 355  */          }
 
520
/* 356  */          else
 
521
/* 357  */          { 
 
522
/* 358  */              ind += tconType[t];
 
523
/* 359  */          }
 
524
/* 360  */
 
525
/* 361  */          output[byteOff++] = (byte) (ind / 256);
 
526
/* 362  */          output[byteOff++] = (byte) (ind % 256);
 
527
/* 363  */      }
 
528
/* 364  */
 
529
/* 365  */      if ( tconBase[t] != 0 )  
 
530
/* 366  */      {   // non-filler and supported by Hanterm Johab fonts
 
531
/* 367  */          ind = tconBase[t] + tconMap[v];
 
532
/* 368  */          output[byteOff++] = (byte) (ind / 256);
 
533
/* 369  */          output[byteOff++] = (byte) (ind % 256);
 
534
/* 370  */      } else  if (vowBase[v] == 0) 
 
535
/* 371  */      {   // give one syllable display width since current display width is 0.
 
536
/* 372  */          output[byteOff++] = (byte) 0;
 
537
/* 373  */          output[byteOff++] = (byte) 0;
 
538
/* 374  */      }
 
539
/* 375  */
 
540
/* 376  */      state = START;
 
541
/* 377  */      l = 0x5f;
 
542
/* 378  */      v = t = 0;
 
543
/* 379  */  }
 
544
// 380   }
 
545
// 381  
 
546
 
 
547
NS_IMETHODIMP nsUnicodeToX11Johab::FillInfo(PRUint32* aInfo)
 
548
{
 
549
   // ac00-d7a3
 
550
   PRUint32 b = 0xac00 >> 5;
 
551
   PRUint32 e = 0xd7a3 >> 5;
 
552
   aInfo[ e ] |= (0xFFFFFFFFL >> (31 - ((0xd7a3) & 0x1f)));
 
553
   for( ; b < e ; b++)
 
554
      aInfo[b] |= 0xFFFFFFFFL;
 
555
 
 
556
   PRUnichar i;
 
557
 
 
558
   // 1100-1112
 
559
   for(i=0x1100;i<=0x1112;i++)
 
560
      SET_REPRESENTABLE(aInfo, i);
 
561
   // 1113-1159
 
562
   for(i=0x1113;i<=0x1159;i++)
 
563
      if(lconBase[i-0x1100]!=0)
 
564
         SET_REPRESENTABLE(aInfo, i);
 
565
   // 115f
 
566
   SET_REPRESENTABLE(aInfo, 0x115f);
 
567
   // 1160-1175
 
568
   for(i=0x1160;i<=0x1175;i++)
 
569
      SET_REPRESENTABLE(aInfo, i);
 
570
   // 1176-11a2
 
571
   for(i=0x1176;i<=0x11a2;i++)
 
572
      if(vowBase[i-0x1160]!=0)
 
573
         SET_REPRESENTABLE(aInfo, i);
 
574
   // 11a8-11c2
 
575
   for(i=0x11a8;i<=0x11c2;i++)
 
576
      SET_REPRESENTABLE(aInfo, i);
 
577
   // 11c3-11f9
 
578
   for(i=0x11c3;i<=0x11f9;i++)
 
579
      if(tconBase[i-0x11a7]!=0)
 
580
         SET_REPRESENTABLE(aInfo, i);
 
581
   return NS_OK;
 
582
}