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.

355 lines
7.9 KiB

  1. /*
  2. * Uniscribe interface (& related classes) class definition
  3. *
  4. * File: _uspi.h
  5. * Create: Jan 10, 1998
  6. * Author: Worachai Chaoweeraprasit (wchao)
  7. *
  8. * Copyright (c) 1998, Microsoft Corporation. All rights reserved.
  9. */
  10. #ifndef _USPI_H
  11. #define _USPI_H
  12. #include "_ls.h"
  13. #include "usp10.h" // Uniscribe SDK protocol
  14. // classes
  15. //
  16. class CFormatRunPtr;
  17. class CMeasurer;
  18. class CTxtEdit;
  19. class CUniscribe;
  20. class CBiDiFSM;
  21. class CTxtBreaker;
  22. #define ALIGN(x) (int)(((x)+3) & ~3) // dword aligning
  23. #define GLYPH_COUNT(c) ((((c)*3)/2)+16)
  24. #define MAX_CLIENT_BUF 512 // size (in byte) of internal buffer
  25. // USP client parameters block
  26. //
  27. #define cli_string 0x00000001
  28. #define cli_psi 0x00000002
  29. #define cli_psla 0x00000004
  30. #define cli_pwgi 0x00000008
  31. #define cli_psva 0x00000010
  32. #define cli_pcluster 0x00000020
  33. #define cli_pidx 0x00000040
  34. #define cli_pgoffset 0x00000080
  35. #define cli_Itemize (cli_string | cli_psi)
  36. #define cli_Break (cli_psla)
  37. #define cli_Shape (cli_pwgi | cli_psva | cli_pcluster)
  38. #define cli_Place (cli_pidx | cli_pgoffset)
  39. #define cli_ShapePlace (cli_Shape | cli_Place)
  40. #ifndef LOCALE_SNATIVEDIGITS
  41. #define LOCALE_SNATIVEDIGITS 0x00000013
  42. #endif
  43. ///// LANG
  44. //
  45. // The following defines are temporary - they will be removed once they
  46. // have been added to the standard NLS header files.
  47. #ifndef LANG_BURMESE
  48. #define LANG_BURMESE 0x55 // Myanmar
  49. #endif
  50. #ifndef LANG_KHMER
  51. #define LANG_KHMER 0x53 // Cambodia
  52. #endif
  53. #ifndef LANG_LAO
  54. #define LANG_LAO 0x54 // Lao
  55. #endif
  56. #ifndef LANG_MONGOLIAN
  57. #define LANG_MONGOLIAN 0x50 // Mongolia
  58. #endif
  59. #ifndef LANG_TIBETAN
  60. #define LANG_TIBETAN 0x51 // Tibet
  61. #endif
  62. #ifndef LANG_URDU
  63. #define LANG_URDU 0x20 // India / Pakistan
  64. #endif
  65. //
  66. // Memory block will contain USPCLIENT -the table of ptrs, as a memory block's header
  67. // followed by subtables then requested data blocks. All things tie together as a
  68. // contiguous data area so client can free the whole thing in one shot.
  69. //
  70. // SI subtable
  71. //
  72. typedef struct tagUSP_CLIENT_SI
  73. {
  74. //
  75. // ScriptItemize's
  76. //
  77. WCHAR* pwchString;
  78. int cchString;
  79. SCRIPT_ITEM* psi;
  80. } USP_CLIENT_SI, *PUSP_CLIENT_SI;
  81. // SB subtable
  82. //
  83. typedef struct tagUSP_CLIENT_SB
  84. {
  85. //
  86. // ScriptBreak's
  87. //
  88. SCRIPT_LOGATTR* psla;
  89. } USP_CLIENT_SB, *PUSP_CLIENT_SB;
  90. // SS & SP subtable
  91. typedef struct tagUSP_CLIENT_SSP
  92. {
  93. //
  94. // ScriptShape's
  95. //
  96. WORD* pwgi;
  97. WORD* pcluster;
  98. SCRIPT_VISATTR* psva;
  99. //
  100. // ScriptPlace's
  101. //
  102. int* pidx;
  103. GOFFSET* pgoffset;
  104. } USP_CLIENT_SSP, *PUSP_CLIENT_SSP;
  105. // header (root) table
  106. //
  107. typedef struct tagUSP_CLIENT
  108. {
  109. PUSP_CLIENT_SI si;
  110. PUSP_CLIENT_SB sb;
  111. PUSP_CLIENT_SSP ssp;
  112. } USP_CLIENT, *PUSP_CLIENT;
  113. // buffer request structure
  114. //
  115. typedef struct tagBUF_REQ
  116. {
  117. int size; // size of requested element
  118. int c; // count of requested element
  119. PVOID* ppv; // ref to ptr of requested buffer
  120. } BUF_REQ;
  121. typedef enum
  122. {
  123. DIGITS_NOTIMPL = 0,
  124. DIGITS_CTX,
  125. DIGITS_NONE,
  126. DIGITS_NATIONAL
  127. } DIGITSHAPE;
  128. #define IsCS(x) (BOOL)((x)==U_COMMA || (x)==U_PERIOD || (x)==U_COLON)
  129. // CUniscribe's internal buffer request flag
  130. //
  131. #define igb_Glyph 1
  132. #define igb_VisAttr 2
  133. #define igb_Pidx 4
  134. // LS Callback's static return buffer
  135. #define celAdvance 32
  136. class CBufferBase
  137. {
  138. public:
  139. CBufferBase(int cbElem) { _cbElem = cbElem; }
  140. void* GetPtr(int cel);
  141. void Release();
  142. protected:
  143. void* _p;
  144. int _cElem;
  145. int _cbElem;
  146. };
  147. template <class ELEM>
  148. class CBuffer : public CBufferBase
  149. {
  150. public:
  151. CBuffer() : CBufferBase(sizeof(ELEM)) {}
  152. ~CBuffer() { Release(); }
  153. ELEM* Get(int cel) { return (ELEM*)GetPtr(cel); }
  154. };
  155. /////// Uniscribe interface object class
  156. //
  157. //
  158. BOOL IsSupportedOS();
  159. class CUniscribe
  160. {
  161. public:
  162. CUniscribe();
  163. ~CUniscribe();
  164. WORD ApplyDigitSubstitution (BYTE bDigitSubstMode);
  165. // public helper functions
  166. //
  167. const SCRIPT_PROPERTIES* GeteProp (WORD eScript);
  168. const CBiDiFSM* GetFSM ();
  169. BOOL CreateClientStruc (BYTE* pbBufIn, LONG cbBufIn, PUSP_CLIENT* ppc, LONG cchString, DWORD dwMask);
  170. void SubstituteDigitShaper (PLSRUN plsrun, CMeasurer* pme);
  171. inline BOOL CacheAllocGlyphBuffers(int cch, int& cGlyphs, WORD*& pwgi, SCRIPT_VISATTR*& psva)
  172. {
  173. cGlyphs = GLYPH_COUNT(cch);
  174. return (pwgi = GetGlyphBuffer(cGlyphs)) && (psva = GetVABuffer(cGlyphs));
  175. }
  176. inline BOOL IsValid()
  177. {
  178. return TRUE;
  179. }
  180. BOOL GetComplexCharSet(const SCRIPT_PROPERTIES* psp, BYTE bCharSetDefault, BYTE& bCharSetOut);
  181. BYTE GetRtlCharSet(CTxtEdit* ped);
  182. // higher level services
  183. //
  184. int ItemizeString (USP_CLIENT* pc, WORD uInitLevel, int* pcItems, WCHAR* pwchString, int cch,
  185. BOOL fUnicodeBidi, WORD wLangId = LANG_NEUTRAL);
  186. int ShapeString (PLSRUN plsrun, SCRIPT_ANALYSIS* psa, CMeasurer* pme, const WCHAR* pwch, int cch,
  187. WORD*& pwgi, WORD* pwlc, SCRIPT_VISATTR*& psva);
  188. int PlaceString (PLSRUN plsrun, SCRIPT_ANALYSIS* psa, CMeasurer* pme, const WORD* pcwgi, int cgi,
  189. const SCRIPT_VISATTR* psva, int* pgdx, GOFFSET* pgduv, ABC* pABC);
  190. int PlaceMetafileString (PLSRUN plsrun, CMeasurer* pme, const WCHAR* pwch, int cch, PINT* ppiDx);
  191. private:
  192. // private helper functions
  193. //
  194. HDC PrepareShapeDC (CMeasurer* pme, HRESULT hrReq, HFONT& hOrgFont);
  195. BYTE GetCDMCharSet(BYTE bCharSetDefault);
  196. DWORD GetNationalDigitLanguage(LCID lcid);
  197. // get callback static buffers
  198. //
  199. SCRIPT_VISATTR* GetVABuffer(int cel) { return _rgva.Get(cel); }
  200. WORD* GetGlyphBuffer(int cel) { return _rgglyph.Get(cel); }
  201. int* GetWidthBuffer(int cel) { return _rgwidth.Get(cel); }
  202. // LS callback (static) buffers
  203. //
  204. CBuffer<WORD> _rgglyph;
  205. CBuffer<int> _rgwidth;
  206. CBuffer<SCRIPT_VISATTR> _rgva;
  207. // pointer to BidiLevel Finite State Machine
  208. CBiDiFSM* _pFSM;
  209. // pointer to script properties resource table
  210. const SCRIPT_PROPERTIES** _ppProp;
  211. WORD _wesNationalDigit; // National digit script ID
  212. BYTE _bCharSetRtl; // Right to left charset to use
  213. BYTE _bCharSetCDM; // CDM charset to use
  214. };
  215. extern CUniscribe* g_pusp;
  216. extern int g_cMaxScript; // Maximum number of script produced by Uniscribe
  217. // Virtual script ID
  218. #define SCRIPT_MAX_COUNT ((WORD)g_cMaxScript)
  219. #define SCRIPT_WHITE SCRIPT_MAX_COUNT + 1
  220. /////// Bidi Finite State Machine class
  221. //
  222. // (detail: bidifsm2.html)
  223. //
  224. // Revise: 12-28-98 (wchao)
  225. //
  226. // inputs class:
  227. #define NUM_FSM_INPUTS 5
  228. typedef enum
  229. {
  230. chLTR = 0,
  231. chRTL,
  232. digitLTR,
  233. digitRTL,
  234. chGround // Neutralize current level down to initial level
  235. } INPUT_CLASS;
  236. // states:
  237. #define NUM_FSM_STATES 6
  238. typedef enum
  239. {
  240. S_A = 0,
  241. S_B,
  242. S_C,
  243. S_X,
  244. S_Y,
  245. S_Z
  246. } STATES;
  247. class CBiDiFSMCell
  248. {
  249. public:
  250. CBiDiLevel _level; // BiDi level
  251. USHORT _uNext; // Offset to the next state relative to FSM start
  252. };
  253. class CBiDiFSM
  254. {
  255. public:
  256. CBiDiFSM (CUniscribe* pusp) { _pusp = pusp; }
  257. ~CBiDiFSM ();
  258. BOOL Init (void);
  259. INPUT_CLASS InputClass (const CCharFormat* pcCF, CTxtPtr* ptp, LONG cchRun) const;
  260. HRESULT RunFSM (CRchTxtPtr* prtp, LONG cRuns, LONG cRunsStart, BYTE bBaseLevel) const;
  261. inline void SetFSMCell (CBiDiFSMCell* pCell, CBiDiLevel* pLevel, USHORT uNext)
  262. {
  263. pCell->_level = *pLevel;
  264. pCell->_uNext = uNext;
  265. }
  266. private:
  267. short _nState; // number of state
  268. short _nInput; // number of input class
  269. CUniscribe* _pusp; // Uniscribe obj associated with
  270. CBiDiFSMCell* _pStart; // start FSM
  271. };
  272. #endif // _USPI_H