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.

172 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. ITEM* Elem(LONG iel) const;
  63. BOOL IsValid() const { return Count() > 0; }
  64. void CheckArray();
  65. LONG InsertBreak (LONG cp, LONG cch);
  66. LONG RemoveBreak (LONG cp, LONG cch);
  67. LONG ReplaceBreak (LONG cp, LONG cchOld, LONG cchNew);
  68. void ClearBreak (LONG cp, LONG cch);
  69. void SetBreak (LONG cp, BOOL fOn);
  70. BOOL GetBreak (LONG cp);
  71. LONG CollapseGap (void);
  72. private:
  73. // n-Bits shifting methods
  74. void ShUp (LONG iel, LONG cel, LONG n);
  75. void ShDn (LONG iel, LONG cel, LONG n);
  76. // Size (in bits)
  77. LONG _ibGap; // offset from start of array to gap
  78. LONG _cbGap; // gap size
  79. LONG _cbBreak; // number of valid break
  80. LONG _cbSize; // bit array size (excluded the sentinel element)
  81. #ifdef BITVIEW
  82. LONG _cCollapse; // how many time collapse?
  83. #endif
  84. public:
  85. LONG GetCchBreak() { return _cbBreak; }
  86. #ifdef BVDEBUG
  87. LONG GetCbSize() { return _cbSize; }
  88. LONG Validate(LONG cchRet);
  89. void PushState(LONG cp, LONG cch, LONG who);
  90. #endif
  91. #ifdef BITVIEW
  92. LONG SetCollapseCount();
  93. #endif
  94. protected:
  95. #ifdef BVDEBUG
  96. BVSTATE _s;
  97. #endif
  98. LONG AddBreak(LONG cp, LONG cch);
  99. };
  100. #ifndef BITVIEW
  101. /////// Complex script text breaker class
  102. //
  103. // The engine to handle cluster and (dictionary-based) word breaking method
  104. // used by most SouthEast Asian languages such as Thai, Lao, Burmese etc.
  105. //
  106. // Create: Mar 12, 1998
  107. //
  108. enum BREAK_UNIT
  109. {
  110. BRK_WORD = 1,
  111. BRK_CLUSTER = 2,
  112. BRK_BOTH = 3
  113. };
  114. class CTxtBreaker : public ITxNotify
  115. {
  116. public:
  117. CTxtBreaker(CTxtEdit *ped);
  118. ~CTxtBreaker();
  119. // Breaker allocation
  120. BOOL AddBreaker(UINT brkUnit);
  121. // Breaker refreshing
  122. void Refresh();
  123. // Query methods
  124. BOOL CanBreakCp (BREAK_UNIT brk, LONG cp);
  125. // ITxNotify methods
  126. virtual void OnPreReplaceRange (LONG cp, LONG cchDel, LONG cchNew,
  127. LONG cpFormatMin, LONG cpFormatMax);
  128. virtual void OnPostReplaceRange (LONG cp, LONG cchDel, LONG cchNew,
  129. LONG cpFormatMin, LONG cpFormatMax);
  130. virtual void Zombie() {};
  131. private:
  132. CTxtEdit* _ped;
  133. CBreakArray* _pbrkWord; // word-break array (per codepoint property)
  134. CBreakArray* _pbrkChar; // cluster-break array (per codepoint property)
  135. };
  136. #endif // !BITVIEW
  137. #endif // _TXTBRK_H