Back to index

im-sdk  12.3.91
hangul.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2003 Sun Microsystems Inc.
00003  *
00004  * This is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  *
00019  * Authors: Karl Park <karl.park@sun.com>
00020  */
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include <config.h>
00024 #endif
00025 
00026 #include <stddef.h>
00027 #include <IMProtocolStruct.h>
00028 
00029 /*
00030   table_prv.h is meant to be included only by this file
00031   Maybe I don't need to have separate header later...
00032 */
00033 
00034 #define TABLE_PRIVATE_DEFINED
00035 #include "table_prv.h"
00036 #include "hangul.h"
00037 
00038 UTFCHAR
00039 hangul_combining_chosung_to_compatibility_jamo (UTFCHAR ch)
00040 {
00041   if (ch < 0x1100 || ch > 0x1112)
00042     return 0;
00043   else
00044     return _combining_chosung_to_compatibility_chosung[ch - 0x1100];
00045 }
00046 
00047 UTFCHAR
00048 hangul_combining_jungsung_to_compatibility_moeum (UTFCHAR ch)
00049 {
00050   if (ch < 0x1161 || ch > 0x1175)
00051     return 0;
00052   else
00053     return _combining_jungsung_to_compatibility_moeum[ch - 0x1161];
00054 }
00055 
00056 UTFCHAR
00057 hangul_combining_jongsung_to_compatibility_jaeum (UTFCHAR ch)     
00058 {
00059   if (ch < 0x11a8 || ch > 0x11c2)
00060     return 0;
00061   else
00062     return _combining_jongsung_to_compatibility_jaeum[ch - 0x11a8];
00063 }
00064 
00065 UTFCHAR
00066 hangul_combining_chosung_to_combining_jongsung (UTFCHAR cchosung)
00067 {
00068   /*
00069     cchosung : compatibility jamo chosung
00070     cjongsung: compatibility jamo jongsung
00071    */
00072   UTFCHAR cjongsung;
00073 
00074   if (cchosung < 0x1100 || cchosung > 0x1112)
00075     cjongsung = 0;
00076   else
00077     cjongsung =
00078       _combining_chosung_to_combining_jongsung[cchosung - 0x1100];
00079 
00080   return cjongsung;
00081 }
00082 
00083 UTFCHAR
00084 hangul_combining_jongsung_to_combining_chosung (UTFCHAR jongsung)
00085 {
00086 #if 0
00087   static UTFCHAR table[] = {
00088     0x1100, 0x1101, 0x1109, 0x1102,
00089     0x110c, 0x1112, 0x1103, 0x1105,
00090     0x1100, 0x1106, 0x1107, 0x1109,
00091     0x1110, 0x1111, 0x1112, 0x1106,
00092     0x1107, 0x1109, 0x1109, 0x110a,
00093     0x110b, 0x110c, 0x110e, 0x110f,
00094     0x1110, 0x1111, 0x1112 
00095   };
00096 #endif
00097   
00098   if (jongsung < 0x11a8 || jongsung > 0x11c2)
00099     return 0;
00100   else
00101     return _combining_jongsung_to_combining_chosung[jongsung - 0x11a8];
00102 }
00103 #if 0
00104 void
00105 hangul_jongseong_decompose (UTFCHAR ch,
00106                          UTFCHAR* return_jongsung, UTFCHAR* return_chosung)
00107 {
00108   if (ch >= 0x11a8 && ch <= 0x11c2) {
00109     *return_jongsung = _combining_coupled_jongsung_decompose[ch - 0x11a8][0];
00110     *return_chosung  = _combining_coupled_jongsung_decompose[ch - 0x11a8][1];
00111   } else {
00112     *return_jongsung = 0;
00113     *return_chosung = 0;
00114   }
00115 }
00116 
00117 UTFCHAR
00118 hangul_jamo_to_syllable (UTFCHAR chosung, UTFCHAR jungsung, UTFCHAR jongsung)
00119 {
00120   static UTFCHAR base_hangul         = 0xac00;
00121   static UTFCHAR base_chosung  = 0x1100;
00122   static UTFCHAR base_jungsung = 0x1161;
00123   static UTFCHAR base_jongsung = 0x11a7;
00124   static int njungsung = 21;
00125   static int njongsung = 28;
00126   UTFCHAR ch;
00127 
00128   if (jongsung == 0)
00129     jongsung = JONGSEONG_FILLER;
00130 
00131   if (chosung  < 0x1100 || chosung  > 0x1112)
00132     return 0;
00133   if (jungsung < 0x1161 || jungsung > 0x1175)
00134     return 0;
00135   if (jongsung < 0x11a7 || jongsung > 0x11c2)
00136     return 0;
00137 
00138   chosung  -= base_chosung;
00139   jungsung -= base_jungsung;
00140   jongsung -= base_jongsung;
00141 
00142   ch = ((chosung * njungsung) + jungsung) * njongsung + jongsung
00143     + base_hangul;
00144   return ch;
00145 }
00146 #endif