Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

443 lines
12 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Hangul automata Class
  3. //
  4. // Author: [email protected]
  5. #if !defined (__HAUTOMATA_H__)
  6. #define __HAUTOMATA_H__
  7. // Number of each component
  8. #define NUM_OF_CHOSUNG 19
  9. #define NUM_OF_JUNGSUNG 21
  10. #define NUM_OF_JONGSUNG 28
  11. #define NUM_OF_DOUBLE_CHOSUNG 5
  12. #define NUM_OF_DOUBLE_JUNGSUNG 7
  13. #define NUM_OF_DOUBLE_JONGSUNG_2BEOL 11
  14. #define NUM_OF_DOUBLE_JONGSUNG_3BEOL 13
  15. #define UNICODE_HANGUL_BASE 0xAC00
  16. #define UNICODE_HANGUL_END 0xD7A3
  17. #define UNICODE_HANGUL_COMP_JAMO_START 0x3131
  18. #define UNICODE_HANGUL_COMP_JAMO_VOWEL_START 0x314F
  19. #define UNICODE_HANGUL_COMP_JAMO_END 0x3163
  20. #define UNICODE_HANGUL_COMP_JAMO_START_FILL 0x3130
  21. #define UNICODE_HANGUL_COMP_JAMO_SIOT 0x3145
  22. ///////////////////////////////////////////
  23. // HANGUL Jaso inernal difinitions
  24. // ChoSung
  25. #define _KIYEOK_ 1 // '��'
  26. #define _SSANGKIYEOK_ 2 // '��'
  27. #define _NIEUN_ 3 // '��'
  28. #define _TIKEUT_ 4 // '��'
  29. #define _SSANGTIKEUT_ 5 // '��'
  30. #define _RIEUL_ 6 // '��'
  31. #define _MIEUM_ 7 // '��'
  32. #define _PIEUP_ 8 // '��'
  33. #define _SSANGPIEUP_ 9 // '��'
  34. #define _SIOS_ 10 // '��'
  35. #define _SSANGSIOS_ 11 // '��'
  36. #define _IEUNG_ 12 // '��'
  37. #define _CIEUC_ 13 // '��'
  38. #define _SSANGCIEUC_ 14 // '��'
  39. #define _CHIEUCH_ 15 // '��'
  40. #define _KHIEUKH_ 16 // '��'
  41. #define _THIEUTH_ 17 // '��'
  42. #define _PHIEUPH_ 18 // '��'
  43. #define _HIEUH_ 19 // '��'
  44. // JungSung
  45. #define _A_ 1 // '��'
  46. #define _AE_ 2 // '��'
  47. #define _YA_ 3 // '��'
  48. #define _YAE_ 4 // '��'
  49. #define _EO_ 5 // '��'
  50. #define _E_ 6 // '��'
  51. #define _YEO_ 7 // '��'
  52. #define _YE_ 8 // '��'
  53. #define _O_ 9 // '��'
  54. #define _WA_ 10 // '��'
  55. #define _WAE_ 11 // '��'
  56. #define _OE_ 12 // '��'
  57. #define _YO_ 13 // '��'
  58. #define _U_ 14 // '��'
  59. #define _WEO_ 15 // '��'
  60. #define _WE_ 16 // '��'
  61. #define _WI_ 17 // '��'
  62. #define _YU_ 18 // '��'
  63. #define _EU_ 19 // '��'
  64. #define _YI_ 20 // '��'
  65. #define _I_ 21 // '��'
  66. ////////////////////////////////////////
  67. // JongSung
  68. #define _JONG_KIYEOK_ 1 // '��'
  69. #define _JONG_SSANGKIYEOK_ 2 // '��'
  70. #define _JONG_KIYEOK_SIOS 3
  71. #define _JONG_NIEUN_ 4 // '��'
  72. #define _JONG_NIEUN_CHIEUCH_ 5 // '��'
  73. #define _JONG_NIEUN_HIEUH_ 6 // '��'
  74. #define _JONG_TIKEUT_ 7 // '��'
  75. #define _JONG_RIEUL_ 8 // '��'
  76. #define _JONG_RIEUL_KIYEOK_ 9 // '��'
  77. #define _JONG_RIEUL_MIUM_ 10 // '��'
  78. #define _JONG_RIEUL_PIEUP_ 11 // '��'
  79. #define _JONG_RIEUL_SIOS_ 12 // '��'
  80. #define _JONG_RIEUL_THIEUTH_ 13 // '��'
  81. #define _JONG_RIEUL_PHIEUPH_ 14 // '��'
  82. #define _JONG_RIEUL_HIEUH_ 15 // '��'
  83. #define _JONG_MIEUM_ 16 // '��'
  84. #define _JONG_PIEUP_ 17 // '��'
  85. #define _JONG_PIEUP_SIOS 18 // '��'
  86. #define _JONG_SIOS_ 19 // '��'
  87. #define _JONG_SSANGSIOS_ 20 // '��'
  88. #define _JONG_IEUNG_ 21 // '��'
  89. #define _JONG_CIEUC_ 22 // '��'
  90. #define _JONG_CHIEUCH_ 23 // '��'
  91. #define _JONG_KHIEUKH_ 24 // '��'
  92. #define _JONG_THIEUTH_ 25 // '��'
  93. #define _JONG_PHIEUPH_ 26 // '��'
  94. #define _JONG_HIEUH_ 27 // '��'
  95. //
  96. const int MaxInterimStackSize = 6; // Maximum stack size is 6.
  97. // At most 6 key input
  98. // to complete one Hangul Char.
  99. // ex) ��(3 beolsik)
  100. enum HAutomataReturnState
  101. {
  102. HAUTO_NONHANGULKEY,
  103. HAUTO_COMPOSITION, // Hagul still in interim state.
  104. HAUTO_COMPLETE, // One hangul char completed and have chars
  105. // will takeover as next input.
  106. HAUTO_IMPOSSIBLE
  107. };
  108. const WORD H_HANGUL = 0x8000;
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CHangulAutomata Abstract Class
  111. //
  112. class CHangulAutomata
  113. {
  114. public:
  115. CHangulAutomata() { InitState(); }
  116. // Attributes
  117. public:
  118. // Operations
  119. public:
  120. void InitState()
  121. {
  122. m_CurState = m_NextState = 0;
  123. m_wInternalCode = 0;
  124. m_Chosung = m_Jungsung = m_Jongsung = 0;
  125. m_wcComposition = m_wcComplete = L'\0';
  126. InterimStack.Init();
  127. }
  128. virtual HAutomataReturnState Machine(UINT KeyCode, int iShift) = 0;
  129. virtual BOOL IsInputKey(UINT KeyCode, int iShift) = 0;
  130. virtual BOOL IsHangulKey(UINT KeyCode, int iShift) = 0;
  131. virtual WORD GetKeyMap(UINT KeyCode, int iShift) = 0;
  132. virtual BOOL SetCompositionChar(WCHAR wcComp) = 0;
  133. static WORD GetEnglishKeyMap(UINT KeyCode, int iShift) { return bETable[KeyCode][iShift]; }
  134. BOOL BackSpace();
  135. BOOL MakeComplete();
  136. WCHAR GetCompositionChar() { return m_wcComposition; }
  137. WCHAR GetCompleteChar() { return m_wcComplete; }
  138. // Implementation
  139. public:
  140. virtual ~CHangulAutomata() {}
  141. protected:
  142. void MakeComposition();
  143. BOOL MakeComplete(WORD wcComplete);
  144. WORD FindChosungComb(WORD wPrevCode);
  145. WORD FindJunsungComb(WORD wPrevCode);
  146. virtual WORD FindJonsungComb(WORD wPrevCode) = 0;
  147. void SeparateDJung(LPWORD pJungSung);
  148. void SeparateDJong(LPWORD pJongSung);
  149. virtual HAutomataReturnState Input(WORD InternalCode) = 0;
  150. //
  151. struct InterimStackEntry
  152. {
  153. WORD m_wInternalCode;
  154. WORD m_CurState;
  155. WORD m_Chosung, m_Jungsung, m_Jongsung;
  156. WCHAR m_wcCode;
  157. };
  158. ///////////////////////////////////////////////////////////////////////////
  159. //
  160. class CInterimStack
  161. {
  162. protected:
  163. InterimStackEntry m_StackBuffer[MaxInterimStackSize];
  164. int m_sp; // Stack pointer
  165. public:
  166. CInterimStack() { m_sp = 0; }
  167. ~CInterimStack() {}
  168. void Init() { m_sp = 0; }
  169. void Push(InterimStackEntry& InterimEntry);
  170. void Push(WORD wInternalCode, WORD CurState,
  171. WORD Chosung, WORD Jungsung, WORD Jongsung, WCHAR wcCode);
  172. InterimStackEntry* CInterimStack::Pop()
  173. {
  174. Assert(m_sp > 0);
  175. return &m_StackBuffer[--m_sp];
  176. }
  177. InterimStackEntry* CInterimStack::GetTop()
  178. {
  179. Assert(m_sp > 0);
  180. return &m_StackBuffer[m_sp-1];
  181. }
  182. BOOL IsEmpty() { return m_sp == 0; }
  183. };
  184. ///////////////////////////////////////////////////////////////////////////
  185. CInterimStack InterimStack;
  186. protected:
  187. WORD m_CurState, m_NextState;
  188. WORD m_wInternalCode, m_Chosung, m_Jungsung, m_Jongsung;
  189. WCHAR m_wcComposition;
  190. WCHAR m_wcComplete;
  191. //
  192. const static BYTE bETable[256][2];
  193. const static BYTE Cho2Jong[NUM_OF_CHOSUNG+1];
  194. const static BYTE Jong2Cho[NUM_OF_JONGSUNG];
  195. };
  196. /////////////////////////////////////////////////////////////////////////////
  197. // CHangulAutomata2 Keyboard layout #1 (2 beolsik)
  198. //
  199. class CHangulAutomata2 : public CHangulAutomata
  200. {
  201. public:
  202. CHangulAutomata2() { }
  203. // Attributes
  204. public:
  205. // Operations
  206. public:
  207. HAutomataReturnState Machine(UINT KeyCode, int iShift);
  208. BOOL IsInputKey(UINT KeyCode, int iShift);
  209. BOOL IsHangulKey(UINT KeyCode, int iShift);
  210. WORD GetKeyMap(UINT KeyCode, int iShift);
  211. BOOL SetCompositionChar(WCHAR wcComp);
  212. // Implementation
  213. public:
  214. ~CHangulAutomata2() { }
  215. protected:
  216. WORD FindJonsungComb(WORD wPrevCode);
  217. HAutomataReturnState Input(WORD InternalCode);
  218. protected:
  219. // This enum should be matched with m_NextState
  220. // DO NOT change without changing _Transistion_state !
  221. enum _Transistion_state { FINAL=8, TAKEOVER=9, FIND=10 };
  222. static const WORD m_NextStateTbl[8][5];
  223. static const WORD H_CONSONANT, H_VOWEL, H_DOUBLE, H_ONLYCHO;
  224. static WORD wHTable[256][2];
  225. static BYTE rgbDJongTbl[NUM_OF_DOUBLE_JONGSUNG_2BEOL+1][3];
  226. };
  227. /////////////////////////////////////////////////////////////////////////////
  228. // CHangulAutomata3 Keyboard layout #2 (3 beolsik)
  229. class CHangulAutomata3 : public CHangulAutomata
  230. {
  231. public:
  232. CHangulAutomata3() {}
  233. // Attributes
  234. public:
  235. // Operations
  236. public:
  237. HAutomataReturnState Machine(UINT KeyCode, int iShift);
  238. BOOL IsInputKey(UINT KeyCode, int iShift);
  239. BOOL IsHangulKey(UINT KeyCode, int iShift);
  240. WORD GetKeyMap(UINT KeyCode, int iShift);
  241. BOOL SetCompositionChar(WCHAR wcComp);
  242. // Implementation
  243. public:
  244. ~CHangulAutomata3() { }
  245. protected:
  246. WORD FindJonsungComb(WORD wPrevCode);
  247. HAutomataReturnState Input(WORD InternalCode);
  248. protected:
  249. enum _Transistion_state { FINAL=11, FIND=12 };
  250. static const WORD m_NextStateTbl[11][6];
  251. static const WORD H_CHOSUNG, H_JUNGSUNG, H_JONGSUNG, H_DOUBLE;
  252. static WORD wHTable[256][2];
  253. static BYTE rgbDJongTbl[NUM_OF_DOUBLE_JONGSUNG_3BEOL+1][3];
  254. };
  255. /////////////////////////////////////////////////////////////////////////////
  256. // CHangulAutomata3 Keyboard layout #3 (3 beolsik final)
  257. class CHangulAutomata3Final : public CHangulAutomata3
  258. {
  259. public:
  260. CHangulAutomata3Final() {}
  261. // Attributes
  262. public:
  263. // Operations
  264. public:
  265. HAutomataReturnState Machine(UINT KeyCode, int iShift) ;
  266. BOOL IsInputKey(UINT KeyCode, int iShift);
  267. BOOL IsHangulKey(UINT KeyCode, int iShift);
  268. WORD GetKeyMap(UINT KeyCode, int iShift);
  269. // Implementation
  270. public:
  271. ~CHangulAutomata3Final() { }
  272. protected:
  273. static WORD wHTable[256][2];
  274. };
  275. ///////////////////////////////////////////////////////////////////////////////
  276. // Inline functions
  277. inline
  278. void CHangulAutomata::CInterimStack::Push(InterimStackEntry& InterimEntry)
  279. {
  280. Assert(m_sp<MaxInterimStackSize);
  281. m_StackBuffer[m_sp++] = InterimEntry;
  282. }
  283. inline
  284. void CHangulAutomata::CInterimStack::Push(WORD wInternalCode, WORD CurState,
  285. WORD Chosung, WORD Jungsung, WORD Jongsung, WCHAR wcCode)
  286. {
  287. Assert(m_sp<=5);
  288. m_StackBuffer[m_sp].m_wInternalCode = wInternalCode;
  289. m_StackBuffer[m_sp].m_CurState = CurState;
  290. m_StackBuffer[m_sp].m_Chosung = Chosung;
  291. m_StackBuffer[m_sp].m_Jungsung = Jungsung;
  292. m_StackBuffer[m_sp].m_Jongsung = Jongsung;
  293. m_StackBuffer[m_sp++].m_wcCode = wcCode;
  294. }
  295. // CHangulAutomata2
  296. inline
  297. HAutomataReturnState CHangulAutomata2::Machine(UINT KeyCode, int iShift)
  298. {
  299. return (Input(wHTable[KeyCode][iShift]));
  300. }
  301. inline
  302. BOOL CHangulAutomata2::IsInputKey(UINT KeyCode, int iShift)
  303. {
  304. if (KeyCode<256)
  305. return (wHTable[KeyCode][iShift]);
  306. else
  307. return fFalse;
  308. }
  309. inline
  310. BOOL CHangulAutomata2::IsHangulKey(UINT KeyCode, int iShift)
  311. {
  312. if (KeyCode<256)
  313. return (wHTable[KeyCode][iShift]) & H_HANGUL;
  314. else
  315. return fFalse;
  316. }
  317. inline
  318. WORD CHangulAutomata2::GetKeyMap(UINT KeyCode, int iShift)
  319. {
  320. if (KeyCode<256)
  321. return (wHTable[KeyCode][iShift]);
  322. else
  323. return fFalse;
  324. }
  325. // CHangulAutomata3
  326. inline
  327. HAutomataReturnState CHangulAutomata3::Machine(UINT KeyCode, int iShift)
  328. {
  329. Assert(KeyCode<256);
  330. return (Input(wHTable[KeyCode][iShift]));
  331. }
  332. inline
  333. BOOL CHangulAutomata3::IsInputKey(UINT KeyCode, int iShift)
  334. {
  335. if (KeyCode<256)
  336. return (wHTable[KeyCode][iShift]);
  337. else
  338. return fFalse;
  339. }
  340. inline
  341. BOOL CHangulAutomata3::IsHangulKey(UINT KeyCode, int iShift)
  342. {
  343. if (KeyCode<256)
  344. return (wHTable[KeyCode][iShift]) & H_HANGUL;
  345. else
  346. return fFalse;
  347. }
  348. inline
  349. WORD CHangulAutomata3::GetKeyMap(UINT KeyCode, int iShift)
  350. {
  351. if (KeyCode<256)
  352. return (wHTable[KeyCode][iShift]);
  353. else
  354. return 0;
  355. }
  356. // CHangulAutomata3Final
  357. inline
  358. HAutomataReturnState CHangulAutomata3Final::Machine(UINT KeyCode, int iShift)
  359. {
  360. Assert(KeyCode<256);
  361. return (Input(wHTable[KeyCode][iShift]));
  362. }
  363. inline
  364. BOOL CHangulAutomata3Final::IsInputKey(UINT KeyCode, int iShift)
  365. {
  366. if (KeyCode<256)
  367. return (wHTable[KeyCode][iShift]);
  368. else
  369. return fFalse;
  370. }
  371. inline
  372. BOOL CHangulAutomata3Final::IsHangulKey(UINT KeyCode, int iShift)
  373. {
  374. if (KeyCode<256)
  375. return (wHTable[KeyCode][iShift]) & H_HANGUL;
  376. else
  377. return fFalse;
  378. }
  379. inline
  380. WORD CHangulAutomata3Final::GetKeyMap(UINT KeyCode, int iShift)
  381. {
  382. if (KeyCode<256)
  383. return (wHTable[KeyCode][iShift]);
  384. else
  385. return 0;
  386. }
  387. #endif // !defined (__HAUTOMATA_H__)