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.

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