Source code of Windows XP (NT5)
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.

175 lines
3.7 KiB

  1. /*
  2. * Text Breaker & Bit stream break array class definition
  3. *
  4. * File: _txtbrk.h
  5. * Create: Mar 29, 1998
  6. * Author: Worachai Chaoweeraprasit (wchao)
  7. *
  8. * Copyright (c) 1998, Microsoft Corporation. All rights reserved.
  9. */
  10. #ifndef _TXTBRK_H
  11. #define _TXTBRK_H
  12. // DEBUG definition
  13. #ifdef BITVIEW
  14. #define BVDEBUG _DEBUG
  15. #define Assert ASSERT
  16. #else
  17. #define BVDEBUG DEBUG
  18. #endif
  19. // The number of buffer breaks before the sync point
  20. #define CWORD_TILLSYNC 3 // Thai wordbreak engine is expected to be in sync within 3 words
  21. #define CCLUSTER_TILLSYNC 1 // Indic cluster is normally in sync in within 1
  22. // Abstract Data type
  23. #define ITEM UINT
  24. // CPU register size
  25. //#define RSIZE (sizeof(ITEM)*8)
  26. #define RSIZE 32
  27. // Mask most/least significant <n> bits
  28. #define MASK_LOW(u, n) ( ((ITEM)(u)) & (1<<(n))-1 )
  29. #define MASK_HIGH(u, n) ~MASK_LOW(u, RSIZE-n)
  30. // BreakArray Exit convention
  31. #ifdef BVDEBUG
  32. #define PUSH_STATE(x,y,z) PushState(x,y,z)
  33. #define VALIDATE(x) Validate(x)
  34. #else
  35. #define PUSH_STATE(x,y,z)
  36. #define VALIDATE(x) x
  37. #endif
  38. // Who put the state?
  39. #define INSERTER 0
  40. #define REMOVER 1
  41. #define COLLAPSER 2
  42. #define REPLACER 3
  43. #ifdef BVDEBUG
  44. typedef struct {
  45. LONG who;
  46. LONG ibGap;
  47. LONG cbGap;
  48. LONG cbBreak;
  49. LONG cbSize;
  50. LONG cp;
  51. LONG cch;
  52. } BVSTATE;
  53. #endif
  54. class CBreakArray : public CArray<ITEM>
  55. {
  56. public:
  57. #ifdef BITVIEW
  58. friend class CBitView;
  59. #endif
  60. CBreakArray();
  61. ~CBreakArray() {}
  62. BOOL IsValid() const { return Count() > 0; }
  63. void CheckArray();
  64. LONG InsertBreak (LONG cp, LONG cch);
  65. LONG RemoveBreak (LONG cp, LONG cch);
  66. LONG ReplaceBreak (LONG cp, LONG cchOld, LONG cchNew);
  67. void ClearBreak (LONG cp, LONG cch);
  68. void SetBreak (LONG cp, BOOL fOn);
  69. BOOL GetBreak (LONG cp);
  70. LONG CollapseGap (void);
  71. private:
  72. // n-Bits shifting methods
  73. void ShUp (LONG iel, LONG cel, LONG n);
  74. void ShDn (LONG iel, LONG cel, LONG n);
  75. // Size (in bits)
  76. LONG _ibGap; // offset from start of array to gap
  77. LONG _cbGap; // gap size
  78. LONG _cbBreak; // number of valid break
  79. LONG _cbSize; // bit array size (excluded the sentinel element)
  80. #ifdef BITVIEW
  81. LONG _cCollapse; // how many time collapse?
  82. #endif
  83. public:
  84. LONG GetCchBreak() { return _cbBreak; }
  85. #ifdef BVDEBUG
  86. LONG GetCbSize() { return _cbSize; }
  87. LONG Validate(LONG cchRet);
  88. void PushState(LONG cp, LONG cch, LONG who);
  89. #endif
  90. #ifdef BITVIEW
  91. LONG SetCollapseCount();
  92. #endif
  93. protected:
  94. #ifdef BVDEBUG
  95. BVSTATE _s;
  96. #endif
  97. LONG AddBreak(LONG cp, LONG cch);
  98. };
  99. #ifndef BITVIEW
  100. /////// Complex script text breaker class
  101. //
  102. // The engine to handle cluster and (dictionary-based) word breaking method
  103. // used by most SouthEast Asian languages such as Thai, Lao, Burmese etc.
  104. //
  105. // Create: Mar 12, 1998
  106. //
  107. enum BREAK_UNIT
  108. {
  109. BRK_WORD = 1,
  110. BRK_CLUSTER = 2,
  111. BRK_BOTH = 3
  112. };
  113. class CTxtBreaker : public ITxNotify
  114. {
  115. public:
  116. CTxtBreaker(CTxtEdit *ped);
  117. ~CTxtBreaker();
  118. // Breaker allocation
  119. BOOL AddBreaker(UINT brkUnit);
  120. // Breaker refreshing
  121. void Refresh();
  122. // Query methods
  123. #ifndef NOCOMPLEXSCRIPTS
  124. BOOL CanBreakCp (BREAK_UNIT brk, LONG cp);
  125. #else
  126. BOOL CanBreakCp (BREAK_UNIT brk, LONG cp) { return FALSE; }
  127. #endif
  128. // ITxNotify methods
  129. virtual void OnPreReplaceRange (LONG cp, LONG cchDel, LONG cchNew,
  130. LONG cpFormatMin, LONG cpFormatMax, NOTIFY_DATA *pNotifyData);
  131. virtual void OnPostReplaceRange (LONG cp, LONG cchDel, LONG cchNew,
  132. LONG cpFormatMin, LONG cpFormatMax, NOTIFY_DATA *pNotifyData);
  133. virtual void Zombie() {};
  134. private:
  135. CTxtEdit* _ped;
  136. CBreakArray* _pbrkWord; // word-break array (per codepoint property)
  137. CBreakArray* _pbrkChar; // cluster-break array (per codepoint property)
  138. };
  139. #endif // !BITVIEW
  140. #endif // _TXTBRK_H