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.

229 lines
5.6 KiB

  1. //// LPK_USP - Interface to Uniscribe String APIs
  2. //
  3. // Dave C Brown (dbrown) 13th December 1997.
  4. //
  5. // Copyright (c) 1996-7, Microsoft Corporation. All rights reserved.
  6. //// LPK_ANA provides the main analysis entrypoint for the script engine
  7. //
  8. // ScriptStringAnalyse creates and returns a structure containing a
  9. // variety of information about the string, optionally including:
  10. //
  11. // Glyphs and glyph attributes
  12. // Glyph positions
  13. // Cursor and word positions
  14. #include "precomp.hxx"
  15. #include "winnlsp.h" // import NlsGetCacheUpdateCount()
  16. extern "C" WINGDIAPI BOOL WINAPI AnyLinkedFonts(); // GDI exports this but doesn't provide a header
  17. ///// LPK.H - Internal header
  18. //
  19. //
  20. //. #include "usp10.h"
  21. //. #include "usp10p.h"
  22. //. #include "lpk_glob.h"
  23. ///// LpkStringAnalyse
  24. //
  25. // Build Uniscribe input flag structures
  26. HRESULT LpkStringAnalyse(
  27. HDC hdc, //In Device context (required)
  28. const void *pString, //In String in 8 or 16 bit characters
  29. int cString, //In Length in characters
  30. int cGlyphs, //In Required glyph buffer size (default cString*3/2 + 1)
  31. int iCharset, //In Charset if an ANSI string, -1 for a Unicode string
  32. DWORD dwFlags, //In Analysis required
  33. int iDigitSubstitute,
  34. int iReqWidth, //In Required width for fit and/or clip
  35. SCRIPT_CONTROL *psControl, //In Analysis control (optional)
  36. SCRIPT_STATE *psState, //In Analysis initial state (optional)
  37. const int *piDx, //In Requested logical dx array
  38. SCRIPT_TABDEF *pTabdef, //In Tab positions (optional)
  39. BYTE *pbInClass, //In Legacy GetCharacterPlacement character classifications (deprecated)
  40. STRING_ANALYSIS **ppsa) { //Out Analysis of string
  41. const SCRIPT_CONTROL emptySc = {0};
  42. const SCRIPT_STATE emptySs = {0};
  43. HRESULT hr;
  44. SCRIPT_CONTROL sc;
  45. SCRIPT_STATE ss;
  46. ULONG ulCsrCacheCount;
  47. SCRIPT_DIGITSUBSTITUTE sds;
  48. ASSERTS(cString!=0, "LpkStringAnalyse: input string must contain at least one character");
  49. TIMEENTRY(LSA, cString);
  50. if (psControl) {
  51. sc = *psControl;
  52. } else {
  53. sc = emptySc;
  54. }
  55. if (psState) {
  56. ss = *psState;
  57. } else {
  58. ss = emptySs;
  59. }
  60. // Check to see if we need to update our NLS cached data
  61. if ((ulCsrCacheCount=NlsGetCacheUpdateCount()) != g_ulNlsUpdateCacheCount) {
  62. TRACE(NLS, ("LPK : Updating NLS cache, lpkNlsCacheCount=%ld, CsrssCacheCount=%ld",
  63. g_ulNlsUpdateCacheCount ,ulCsrCacheCount));
  64. g_ulNlsUpdateCacheCount = ulCsrCacheCount;
  65. // Update the cache now
  66. ReadNLSScriptSettings();
  67. }
  68. // Select required digit substitution
  69. if (iDigitSubstitute < 0) {
  70. // Use NLS digit subtitution as selected by user through control panel
  71. ScriptApplyDigitSubstitution(&g_DigitSubstitute, &sc, &ss);
  72. } else {
  73. // Override digit subtitution
  74. sds = g_DigitSubstitute;
  75. sds.DigitSubstitute = iDigitSubstitute;
  76. ScriptApplyDigitSubstitution(&sds, &sc, &ss);
  77. }
  78. // On Arabic systems, RTL fields start with the ENtoAN rule active.
  79. if ( (dwFlags & SSA_RTL)
  80. && ( g_ACP == 1256
  81. || g_UserPrimaryLanguage == LANG_ARABIC))
  82. {
  83. ss.fArabicNumContext = TRUE;
  84. }
  85. // When font linking is activated, it takes precedence over font fallback
  86. // for non-complex scripts.
  87. if (g_iUseFontLinking == -1) {
  88. g_iUseFontLinking = (int) AnyLinkedFonts();
  89. }
  90. if (g_iUseFontLinking) {
  91. dwFlags |= SSA_LINK;
  92. }
  93. sc.fLegacyBidiClass = TRUE; // All legacy APIs use legacy plus, minus, solidus classifications
  94. //TRACEMSG(("LpkStringAnalyse: g_uLocaleLanguage %d, LANG_ARABIC %d, dwFlags & SSA_RTL %x, ss.fArabicNumContext %x",
  95. // g_uLocaleLanguage, LANG_ARABIC, dwFlags & SSA_RTL, ss.fArabicNumContext));
  96. hr = ScriptStringAnalyse(
  97. hdc,
  98. pString,
  99. cString,
  100. cGlyphs,
  101. iCharset,
  102. dwFlags,
  103. iReqWidth,
  104. &sc,
  105. &ss,
  106. piDx,
  107. pTabdef,
  108. pbInClass,
  109. (SCRIPT_STRING_ANALYSIS*)ppsa);
  110. TIMEEXIT(LSA);
  111. return hr;
  112. }
  113. ///// ftsWordBreak - Support full text search wordbreaker
  114. //
  115. //
  116. // Mar 9,1997 - [wchao]
  117. //
  118. extern "C" BOOL WINAPI ftsWordBreak (
  119. PWSTR pInStr,
  120. INT cchInStr,
  121. PBYTE pResult,
  122. INT cchRes,
  123. INT charset) {
  124. int ich;
  125. int ichRes;
  126. int ichPrev;
  127. HRESULT hr;
  128. STRING_ANALYSIS *psa;
  129. UNREFERENCED_PARAMETER(cchRes) ;
  130. // set up ED structure to prefer BasicAnalysis
  131. //
  132. hr = LpkStringAnalyse(
  133. NULL, pInStr, cchInStr, 0,
  134. charset,
  135. SSA_BREAK,
  136. -1, 0,
  137. NULL, NULL, NULL, NULL, NULL,
  138. &psa);
  139. if (SUCCEEDED(hr)) {
  140. for (ich=1, ichRes=0, ichPrev=0; ich < cchInStr; ich++) {
  141. if (psa->pLogAttr[ich].fSoftBreak) {
  142. pResult[ichRes] = ich - ichPrev;
  143. ichPrev = ich;
  144. ichRes++;
  145. }
  146. }
  147. pResult[ichRes] = 0;
  148. ScriptStringFree((void**)&psa);
  149. } else {
  150. ASSERTHR(hr, ("ftsWordBreak - LpkStringAnalyse"));
  151. }
  152. return TRUE;
  153. }