/*******************************************************************************
;*******************************************************************************
;**                                                                           **
;**                    COPYRIGHT 2008-2012 NUANCE COMMUNICATIONS              **
;**                                                                           **
;**               NUANCE COMMUNICATIONS PROPRIETARY INFORMATION               **
;**                                                                           **
;**     This software is supplied under the terms of a license agreement      **
;**     or non-disclosure agreement with Nuance Communications and may not     **
;**     be copied or disclosed except in accordance with the terms of that    **
;**     agreement.                                                            **
;**                                                                           **
;**                                                                           **
;*******************************************************************************
;**                                                                           **
;**     FileName: et9kjamo.h                                                  **
;**                                                                           **
;**  Description: Korean XT9 Jamo-Hangul module. header file.                 **
;**               Conforming to the development version of Korean XT9.        **
;**                                                                           **
;*******************************************************************************
;******************************************************************************/

#ifndef ET9KJAMO_H
#define ET9KJAMO_H 1

/* don't mangle the function name if compile under C++ */
#if defined(__cplusplus)
extern "C" {
#endif

#define ET9K_HANGUL_UNI_MIN    ((ET9SYMB)0xAC00)
#define ET9K_HANGUL_UNI_MAX    ((ET9SYMB)0xD7A3)

#define ET9K_INITIAL_UNI_MIN   ((ET9SYMB)0x1100)
#define ET9K_INITIAL_UNI_MAX   ((ET9SYMB)0x1112)
#define ET9K_INITIAL_COUNT     ((ET9U16)19)

#define ET9K_MEDIAL_UNI_MIN    ((ET9SYMB)0x1161)
#define ET9K_MEDIAL_UNI_MAX    ((ET9SYMB)0x1175)
#define ET9K_MEDIAL_COUNT      ((ET9U16)21)

#define ET9K_FINAL_UNI_MIN     ((ET9SYMB)0x11A7)  /* 0x11A7 is the Final "No Final" --- artificial dummy unicode */
#define ET9K_FINAL_UNI_MAX     ((ET9SYMB)0x11C2)
#define ET9K_FINAL_COUNT       ((ET9U16)28)

#define ET9K_CHUNJIIN_UNI_HLINE    ((ET9SYMB)0x1173)
#define ET9K_CHUNJIIN_UNI_VLINE    ((ET9SYMB)0x1175)
#define ET9K_CHUNJIIN_UNI_DOT      ((ET9SYMB)0x119E)  /* single-dot: Chun-ji-in symbol outside the Medial set but may be combined with other Medial symbols */
#define ET9K_CHUNJIIN_UNI_DOTDOT   ((ET9SYMB)0x11A2)  /* double-dot: Chun-ji-in symbol outside the Medial set but may be combined with other Medial symbols */

#define ET9K_MEDIAL_X_FINAL_COUNT  ((ET9U16)588)      /* ET9K_MEDIAL_COUNT  * ET9K_FINAL_COUNT = 588 */
#define ET9K_HANGUL_COUNT          ((ET9U16)11172)    /* ET9K_INITIAL_COUNT * ET9K_MEDIAL_COUNT  * ET9K_FINAL_COUNT = 11172 */

#define ET9K_COMPJAMO_UNI_MIN      ((ET9SYMB)0x3131)
#define ET9K_COMPJAMO_UNI_MAX      ((ET9SYMB)0x318E)


#define ET9K_IS_LOWER_JAMO(c)   ((c) >= 0x1100 && (c) <= 0x11FF)
#define ET9K_IS_UPPER_JAMO(c)   ((c) >= 0xE100 && (c) <= 0xE1FF)

#define ET9K_TO_UPPER_JAMO(c)   (((c) >= 0x1100 && (c) <= 0x11FF)? ((c) ^ 0xF000): (c))
#define ET9K_TO_LOWER_JAMO(c)   (((c) >= 0xE100 && (c) <= 0xE1FF)? ((c) ^ 0xF000): (c))

#define ET9K_HANGUL_JUNGSEONG_EU  ((ET9SYMB)0x1173)
#define ET9K_HANGUL_JUNGSEONG_I   ((ET9SYMB)0x1175)
#define ET9K_MEDIALMAP            ((ET9U32)0xFF8C6800)

#define ET9K_ISINITIALJAMO(c)     ((ET9K_INITIAL_UNI_MIN <= (c)) && ((c) <= ET9K_INITIAL_UNI_MAX))
#define ET9K_ISMEDIALJAMO(c)      (((c) >= ET9K_MEDIAL_UNI_MIN) && ((c) <= ET9K_MEDIAL_UNI_MAX) && (ET9K_MEDIALMAP & (0x80000000 >> ((c) - ET9K_MEDIAL_UNI_MIN))) )
#define ET9K_ISDOT(c)             ((ET9K_CHUNJIIN_UNI_DOT == (c)) || (ET9K_CHUNJIIN_UNI_DOTDOT == (c)) )
#define ET9K_ISVORH(c)            ((ET9K_HANGUL_JUNGSEONG_EU == (c)) || (ET9K_HANGUL_JUNGSEONG_I == (c)) )
#define ET9K_ISKOREANJAMO(c)      (ET9K_ISINITIALJAMO(c) || ET9K_ISMEDIALJAMO(c) || ET9K_ISDOT(c))
#define ET9K_HANGULHASFINALCONSONANT(c)  ((ET9K_HANGUL_UNI_MIN <= (c) && (c) <= ET9K_HANGUL_UNI_MAX) && (((c) - ET9K_HANGUL_UNI_MIN) % ET9K_FINAL_COUNT)) 
#define ET9K_HASINITIAL(pJamoIMF) (pJamoIMF->initialSymbCount > 0)
#define ET9K_HASMEDIAL(pJamoIMF)  (pJamoIMF->medialSymbCount > 0)
#define ET9K_HASFINAL(pJamoIMF)   (pJamoIMF->finalSymbCount > 0)

/*  -IDR-    
                                                                                                                             */
typedef struct JamoMap_s
{
    ET9SYMB sJamo1;
    ET9SYMB sJamo2;
    ET9SYMB sJamoCombo;
} JamoMap;

/*  -IDR-    
                                                                                     */
typedef struct JamoDemap_s
{
    ET9SYMB sJamo1;
    ET9SYMB sJamo2;
} JamoDemap;

/*  -IDR-    
                                                     */
typedef struct JamoIMF_s
{
    ET9SYMB initial;
    ET9SYMB medial;
    ET9SYMB final;
    ET9U8 initialSymbCount;
    ET9U8 medialSymbCount;
    ET9U8 finalSymbCount;
    ET9BOOL bIsMultiSymbMedial;
} JamoIMF;

ET9STATUS ET9FARCALL _ET9K_Jamo2Hangul(const ET9SYMB  * const pJamoStr, 
                                       const ET9U16           wJamoStrLen, 
                                       const ET9U8    * const pbJamoType, 
                                       ET9KHangulWord * const pHangul,
                                       const ET9BOOL          bJoinInitConsonants);

ET9STATUS ET9FARCALL _ET9K_Hangul2Jamo(const ET9SYMB * const pHangulStr, 
                                       const ET9U16          wHangulStrLen, 
                                       ET9SimpleWord * const pJamo, 
                                       const ET9BOOL         bLeadingUpper, 
                                       const ET9BOOL         bToCJI);

ET9BOOL ET9FARCALL _EncodeJamo(const ET9SYMB  * const pJamoStr,
                               const ET9U16           wJamoStrLen,
                               const ET9U8    * const pbJamoType,
                               ET9SimpleWord  * const pOutJamo,
                               ET9U8          * const pbOutJamoType,
                               ET9KHangulWord * const pHangul,
                               const ET9BOOL          bJoinCJI,
                               const ET9BOOL          bJoinInitConsonants);

/* End don't mangle the function name if compile under C++ */
#if defined(__cplusplus)
    }
#endif

#endif  /* #ifndef ET9KJAMO_H */

/* ----------------------------------< eof >--------------------------------- */
