home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Internet 2000 May / MICD_2000_05.iso / CBuilder5 / INSTALL / DATA1.CAB / Program_Built_Files / Include / usp10.h < prev    next >
C/C++ Source or Header  |  2000-02-01  |  80KB  |  1,886 lines

  1. /*++
  2.  
  3.    Copyright (c) 1998-1999 Microsoft Corporation.
  4.  
  5. */
  6.  
  7. #ifndef __usp10__
  8. #pragma option push -b -a8 -pc -A- /*P_O_Push*/
  9. #define __usp10__
  10. #if _MSC_VER > 1000
  11. #pragma once
  12. #endif
  13.  
  14. #include <windows.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18.  
  19.  
  20. ///// Uniscribe build number
  21.  
  22. #define USPBUILD 0306
  23.  
  24.  
  25.  
  26. /////   USP - Unicode Complex Script processor
  27. //
  28. //      Copyright (c) 1996-9, Microsoft Corporation. All rights reserved.
  29.  
  30.  
  31.  
  32.  
  33. /////   SCRIPT
  34. //
  35. //      The SCRIPT enum is an opaque type used internally to identify
  36. //      which shaping engine functions are used to process a given run.
  37. //
  38. //
  39. #define SCRIPT_UNDEFINED  0
  40. //
  41. //p     SCRIPT_UNDEFINED: This is the only public script ordinal. May be
  42. //      forced into the eScript field of a SCRIPT_ANALYSIS to disable shaping.
  43. //      SCRIPT_UNDEFINED is supported by all fonts - ScriptShape will display
  44. //      whatever glyph is defined in the font CMAP table, or, if none, the
  45. //      missing glyph.
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53. /////   USP Status Codes
  54. //
  55. #define USP_E_SCRIPT_NOT_IN_FONT   \
  56.         MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,0x200)    // Script doesn't exist in font
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. /////   SCRIPT_CACHE
  64. //
  65. //      Many script APIs take a combination of HDC and SCRIPT_CACHE parameter.
  66. //
  67. //      A SCRIPT_CACHE is an opaque pointer to a Uniscribe font metric cache
  68. //      structure.
  69.  
  70.  
  71. typedef void *SCRIPT_CACHE;
  72.  
  73.  
  74. //      The client must allocate and retain one SCRIPT_CACHE variable for each
  75. //      character style used. It must be initialised by the client to NULL.
  76. //
  77. //      APIs are passed an HDC and the address of a SCRIPT_CACHE variable.
  78. //      Uniscribe will first attempt to access font data via the SCRIPT_CACHE
  79. //      and will only inspect the HDC if the required data is not already
  80. //      cached.
  81. //
  82. //      The HDC may be passed as NULL. If data required by Uniscribe is
  83. //      already cached, the HDC won't be accessed and operation continues
  84. //      normally.
  85. //
  86. //      If the HDC is passed as NULL, and Uniscribe needs to access it for
  87. //      any reason, Uniscribe will return E_PENDING.
  88. //
  89. //      E_PENDING is returned quickly, allowing the client to avoid time
  90. //      consuming SelectObject calls. The following example applies to all
  91. //      APIs that take a SCRIPT_CACHE and an optional HDC.
  92. //
  93. //c     hr = ScriptShape(NULL, &sc, ..);
  94. //c     if (hr == E_PENDING) {
  95. //c         ... select font into hdc ...
  96. //c         hr = ScriptShape(hdc, &sc, ...);
  97. //c     }
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104. /////   ScriptFreeCache
  105. //
  106. //      The client may free a SCRIPT_CACHE at any time. Uniscribe maintains
  107. //      reference counts in it's font and shaper caches, and frees font data
  108. //      only when all sizes of the font are free, and shaper data only when
  109. //      all fonts it supports are freed.
  110. //
  111. //      The client should free the SCRIPT_CACHE for a style when it discards
  112. //      that style.
  113. //
  114. //      ScriptFreeCache always sets it's parameter to NULL to help avoid
  115. //      mis-referencing.
  116.  
  117.  
  118. HRESULT WINAPI ScriptFreeCache(
  119.     SCRIPT_CACHE   *psc);       //InOut  Cache handle
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126. /////   SCRIPT_CONTROL
  127. //
  128. //      The SCRIPT_CONTROL structure provides itemization control flags to the
  129. //      ScriptItemize function.
  130. //
  131. //
  132. typedef struct tag_SCRIPT_CONTROL {
  133.     DWORD   uDefaultLanguage    :16; // For NADS, also default for context
  134.     DWORD   fContextDigits      :1;  // Means use previous script instead of uDefaultLanguage
  135.  
  136.     // The following flags provide legacy support for GetCharacterPlacement features
  137.     DWORD   fInvertPreBoundDir  :1;  // Reading order of virtual item immediately prior to string
  138.     DWORD   fInvertPostBoundDir :1;  // Reading order of virtual item immediately following string
  139.     DWORD   fLinkStringBefore   :1;  // Equivalent to presence of ZWJ before string
  140.     DWORD   fLinkStringAfter    :1;  // Equivalent to presence of ZWJ after string
  141.     DWORD   fNeutralOverride    :1;  // Causes all neutrals to be strong in the current embedding direction
  142.     DWORD   fNumericOverride    :1;  // Causes all numerals to be strong in the current embedding direction
  143.     DWORD   fLegacyBidiClass    :1;  // Causes plus and minus to be reated as neutrals, slash as a common separator
  144.     DWORD   fReserved           :8;
  145. } SCRIPT_CONTROL;
  146. //
  147. //
  148. //p     uDefaultLanguage: Language to use when Unicode values are ambiguous.
  149. //              Used by numeric processing to select digit shape when
  150. //              fDigitSubstitute (see SCRIPT_STATE) is in force.
  151. //
  152. //p     fContextDigits: Specifies that national digits are chosen according to
  153. //              the nearest previous strong text, rather than using
  154. //              uDefaultLanguage.
  155. //
  156. //p     fInvertPreBoundDir: By default text at the start of the string is
  157. //              laid out as if it follows strong text of the same direction
  158. //              as the base embedding level. Set fInvertPreBoundDir to change
  159. //              the initial context to the opposite of the base embedding
  160. //              level. This flag is for GetCharacterPlacement legacy support.
  161. //
  162. //p     fInvertPostBoundDir: By default text at the end of the string is
  163. //              laid out as if it preceeds strong text of the same direction
  164. //              as the base embedding level. Set fInvertPostBoundDir to change
  165. //              the final context to the opposite of the base embedding
  166. //              level. This flag is for GetCharacterPlacement legacy support.
  167. //
  168. //p     fLinkStringBefore: Causes the first character of the string to be
  169. //              shaped as if were joined to a previous character.
  170. //
  171. //p     fLinkStringAfter: Causes the last character of the string to be
  172. //              shaped as if were joined to a following character.
  173. //
  174. //p     fNeutralOverride: Causes all neutral characters in the string to be
  175. //              treated as if they were strong characters of their enclosing
  176. //              embedding level. This effectively locks neutrals in place,
  177. //              reordering occuring only between neutrals.
  178. //
  179. //p     fNumericOverride: Causes all numeric characters in the string to be
  180. //              treated as if they were strong characters of their enclosing
  181. //              embedding level. This effectively locks numerics in place,
  182. //              reordering occuring only between numerics.
  183. //
  184. //p     fReserved: Reserved. Always initialise to 0.
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191. /////   SCRIPT_STATE
  192. //
  193. //      The SCRIPT_STATE structure is used both to initialise the unicode
  194. //      algorithm state as an input parameter to ScriptItemize, and is also
  195. //      a component of each item analysis returned by ScriptItemize.
  196. //
  197. //
  198. typedef struct tag_SCRIPT_STATE {
  199.     WORD    uBidiLevel         :5;  // Unicode Bidi algorithm embedding level (0-16)
  200.     WORD    fOverrideDirection :1;  // Set when in LRO/RLO embedding
  201.     WORD    fInhibitSymSwap    :1;  // Set by U+206A (ISS), cleared by U+206B (ASS)
  202.     WORD    fCharShape         :1;  // Set by U+206D (AAFS), cleared by U+206C (IAFS)
  203.     WORD    fDigitSubstitute   :1;  // Set by U+206E (NADS), cleared by U+206F (NODS)
  204.     WORD    fInhibitLigate     :1;  // Equiv !GCP_Ligate, no Unicode control chars yet
  205.     WORD    fDisplayZWG        :1;  // Equiv GCP_DisplayZWG, no Unicode control characters yet
  206.     WORD    fArabicNumContext  :1;  // For EN->AN Unicode rule
  207.     WORD    fGcpClusters       :1;  // For Generating Backward Compatible GCP Clusters (legacy Apps)
  208.     WORD    fReserved          :1;
  209.     WORD    fEngineReserved    :2;  // For use by shaping engine
  210. } SCRIPT_STATE;
  211. //
  212. //
  213. //p     uBidiLevel: The embedding level associated with all characters in this
  214. //              run according to the Unicode bidi algorithm. When passed to
  215. //              ScriptItemize, should be initialised to 0 for an LTR base
  216. //              embedding level, or 1 for RTL.
  217. //
  218. //p     fOverrideDirection: TRUE if this level is an override level (LRO/RLO).
  219. //              In an override level, characters are layed out purely
  220. //              left to right, or purely right to left. No reordering of digits
  221. //              or strong characters of opposing direction takes place.
  222. //              Note that this initial value is reset by LRE, RLE, LRO or
  223. //              RLO codes in the string.
  224. //
  225. //p     fInhibitSymSwap: TRUE if the shaping engine is to bypass mirroring of
  226. //              Unicode Mirrored glyphs such as brackets. Set by Unicode
  227. //              character ISS, cleared by ASS.
  228. //
  229. //p     fCharShape: TRUE if character codes in the Arabic Presentation Forms
  230. //              areas of Unicode should be shaped. (Not implemented).
  231. //
  232. //p     fDigitSubstitute: TRUE if character codes U+0030 through U+0039
  233. //              (European digits) are to be substituted by national digits.
  234. //              Set by Unicode NADS, Cleared by NODS.
  235. //
  236. //p     fInhibitLigate: TRUE if ligatures are not to be used in the shaping
  237. //              of Arabic or Hebrew characters.
  238. //
  239. //p     fDisplayZWG: TRUE if control characters are to be shaped as
  240. //              representational glyphs. (Normally, control characters are
  241. //              shaped to the blank glyph and given a width of zero).
  242. //
  243. //p     fArabicNumContext: TRUE indicates prior strong characters were Arabic
  244. //              for the purposes of rule P0 on page 3-19 of 'The Unicode
  245. //              Standard, version 2.0'. Should normally be set TRUE before
  246. //              itemizing an RTL paragraph in an Arabic language, FALSE
  247. //              otherwise.
  248. //
  249. //p     fGcpClusters: For GetCharaterPlacement legacy support only.
  250. //              Initialise to TRUE to request ScriptShape to generate
  251. //              the LogClust array the same way as GetCharacterPlacement
  252. //              does in Arabic and Hebrew Windows95. Affects only Arabic
  253. //              and Hebrew items.
  254. //
  255. //p     fReserved: Reserved. Always initialise to 0.
  256. //
  257. //p     fEngineReserved: Reserved. Always initialise to 0.
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264. /////   SCRIPT_ANALYSIS
  265. //
  266. //      Each analysed item is described by a SCRIPT_ANALYSIS structure.
  267. //      It also includes a copy of the Unicode algorithm state (SCRIPT_STATE).
  268. //
  269. //
  270. typedef struct tag_SCRIPT_ANALYSIS {
  271.     WORD    eScript         :10;    // Shaping engine
  272.     WORD    fRTL            :1;     // Rendering direction
  273.     WORD    fLayoutRTL      :1;     // Set for GCP classes ARABIC/HEBREW and LOCALNUMBER
  274.     WORD    fLinkBefore     :1;     // Implies there was a ZWJ before this item
  275.     WORD    fLinkAfter      :1;     // Implies there is a ZWJ following this item.
  276.     WORD    fLogicalOrder   :1;     // Set by client as input to ScriptShape/Place
  277.     WORD    fNoGlyphIndex   :1;     // Generated by ScriptShape/Place - this item does not use glyph indices
  278.     SCRIPT_STATE s;
  279. } SCRIPT_ANALYSIS;
  280. //
  281. //
  282. //p     eScript: Opaque value identifying which engine Uniscribe will use to
  283. //              Shape, Place and TextOut this item. The value of eScript is
  284. //              undefined, and will change in future releases, but attributes
  285. //              of eScript may be obtained by calling ScriptGetProperties.
  286. //
  287. //p     fRTL: Rendering direction. Normally identical to the parity of the
  288. //              Unicode embedding level, but may differ if overridden by
  289. //              GetCharacterPlacement legacy support.
  290. //
  291. //p     fLayoutRTL: Logical direction - whether conceptually part of a
  292. //              left-to-right sequenece or a right-to-left sequence. Although
  293. //              this is usually the same as fRTL, for a number in a
  294. //              right-to-left run, fRTL is False (because digits are always
  295. //              displayed LTR), but fLayoutRTL is True (because the number is
  296. //              read as part of the right-to-left sequence).
  297. //
  298. //p     fLinkBefore: If set, the shaping engine will shape the first character
  299. //              of this item as if it were joining with a previous character.
  300. //              Set by ScriptItemize, may be overriden before calling ScriptShape.
  301. //
  302. //p     fLinkAfter: If set, the shaping engine will shape the last character
  303. //              of this item as if it were joining with a subsequient character.
  304. //              Set by ScriptItemize, may be overriden before calling ScriptShape.
  305. //
  306. //p     fLogicalOrder: If set, the shaping engine will generate all glyph
  307. //              related arrays in logical order. By default glyph related
  308. //              arrays are in visual order, the first array entry corresponding
  309. //              to the leftmost glyph.
  310. //              Set to FALSE by ScriptItemize, may be overriden before calling
  311. //              ScriptShape.
  312. //
  313. //p     fNoGlyphIndex: May be set TRUE on input to ScriptShape to disable use
  314. //              of glyphs for this item. Additionally, ScriptShape will set it
  315. //              TRUE for hdcs containing symbolic, unrecognised and device fonts.
  316. //              Disabling glyphing disables complex script shaping. When set,
  317. //              shaping and placing for this item is implemented directly by
  318. //              calls to GetTextExtentExPoint and ExtTextOut.
  319. /////   SCRIPT_ITEM
  320. //
  321. //      The SCRIPT_ITEM structure includes a SCRIPT_ANALYSIS with the string
  322. //      ofset of the first character of the item.
  323. //
  324. //
  325. typedef struct tag_SCRIPT_ITEM {
  326.     int              iCharPos;      // Logical offset to first character in this item
  327.     SCRIPT_ANALYSIS  a;
  328. } SCRIPT_ITEM;
  329. //
  330. //
  331. //p     iCharPos: Offset from beginning of itemised string to first character
  332. //              of this item, counted in Unicode codepoints (i.e. words).
  333. //
  334. //p     a: Script analysis structure containing analysis specific to this
  335. //              item, to be passed to ScriptShape, ScriptPlace etc.
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342. /////   ScriptItemize - break text into items
  343. //
  344. //      Breaks a run of unicode into individually shapeable items.
  345. //      Items are delimited by
  346. //
  347. //      o Change of shaping engine
  348. //      o Change of direction
  349. //
  350. //      The client may create multiple runs from each item returned by
  351. //      ScriptItemize, but should not combine multiple items into a single run.
  352. //
  353. //      Later the client will call ScriptShape for each run (when measuring or
  354. //      rendering), and must pass the SCRIPT_ANALYSIS that ScriptItemize
  355. //      returned.
  356.  
  357.  
  358. HRESULT WINAPI ScriptItemize(
  359.     const WCHAR           *pwcInChars,  // In   Unicode string to be itemized
  360.     int                    cInChars,    // In   Codepoint count to itemize
  361.     int                    cMaxItems,   // In   Max length of itemization array
  362.     const SCRIPT_CONTROL  *psControl,   // In   Analysis control (optional)
  363.     const SCRIPT_STATE    *psState,     // In   Initial bidi algorithm state (optional)
  364.     SCRIPT_ITEM           *pItems,      // Out  Array to receive itemization
  365.     int                   *pcItems);    // Out  Count of items processed (optional)
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372. /////
  373. //
  374. //
  375. //      Returns E_INVALIDARG if pwcInChars == NULL or cInChars == 0
  376. //          or pItems == NULL or cMaxItems < 2.
  377. //
  378. //      Returns E_OUTOFMEMORY if the output buffer length (cMaxItems) is
  379. //          insufficient. Note that in this case, as in all error cases, no
  380. //          items have been fully processed so no part of the output array
  381. //          contains defined values.
  382. //
  383. //      If psControl and psState are NULL on entry, ScriptItemize
  384. //      breaks the unicode string purely by character code.  If they are all
  385. //      non-null, it performs a full Unicode bidi analysis.
  386. //
  387. //      ScriptItemize always adds a terminal item to the item analysis array
  388. //      (pItems) such that the length of an item at pItem is always available as:
  389. //
  390. //c     pItem[1].iCharPos - pItem[0].iCharPos
  391. //
  392. //      For this reason, it is invalid to call ScriptItemize with a buffer
  393. //      of less than two SCRIPT_ANALYSIS items.
  394. //
  395. //      To perform a correct Unicode Bidi analysis, the SCRIPT_STATE should
  396. //      be initialised according to the paragraph reading order at paragraph
  397. //      start, and ScriptItemize should be passed the whole paragraph.
  398. //
  399. //      fRTL and fNumeric together provide the same classification as
  400. //      the lpClass output from GetCharacterPlacement.
  401. //
  402. //      European digits U+0030 through U+0039 may be rendered as national
  403. //      digits as follows:
  404. //
  405. //t     fDigitSubstitute | FContextDigits | Digit shapes displayed for Unicode U+0030 through U+0039
  406. //t     ---------------- | -------------- | ------------------------------------
  407. //t     False            | Any            | Western (European / American) digits
  408. //t     True             | False          | As specified in SCRIPT_CONTROL.uDefaultLanguage
  409. //t     True             | True           | As prior strong text, defaulting to SCRIPT_CONTROL.uDefaultLanguage
  410. //
  411. //
  412. //      For fContextDigits, any Western digits (U+0030 - U+0039) encountered
  413. //      before the first strongly directed character are substituted by the
  414. //      traditional digits of the SCRIPT_CONTROL.uDefaultLanguage when that
  415. //      language is written in the same direction as SCRIPT_STATE.uBidiLevel.
  416. //
  417. //      Thus, in a right-to-left string, if SCRIPT_CONTROL.uDefaultLanguage is
  418. //      1 (LANG_ARABIC), then leading Western digits will be substituted by
  419. //      traditional Arabic digits.
  420. //
  421. //      However, also in a right-to-left string, if SCRIPT_CONTROL.uDefaultLanguage
  422. //      is 0x1e (LANG_THAI), then no substitution occurs on leading Western
  423. //      digits because the Thai language is written left-to-right.
  424. //
  425. //      Following strongly directed characters, digits are substituted
  426. //      by the traditional digits associated with the closest prior strongly
  427. //      directed character.
  428. //
  429. //      The left-to-right mark (LRM) and right-to-left mark (RLM) are strong
  430. //      characters whose language depends on the SCRIPT_CONTROL.uDefaultLangauge.
  431. //
  432. //      If SCRIPT_CONTROL.uDefaultLangauge is a left-to-right langauge, then
  433. //      LRM causes subsequent Western digits to be substituted by the
  434. //      traditional digits associated with that language, while Western
  435. //      digits following RLM are not substituted.
  436. //
  437. //      Conversly, if SCRIPT_CONTROL.uDefaultLangauge is a right-to-left
  438. //      langauge, then Western digits following LRM are not substituted, while
  439. //      Western digits following RLM are substituted by the traditional digits
  440. //      associated with that language.
  441. //
  442. //
  443. //
  444. //      Effect of Unicode control characters on SCRIPT_STATE:
  445. //
  446. //t     SCRIPT_STATE flag | Set by | Cleared by
  447. //t     ----------------- | ------   ----------
  448. //t     fDigitSubstitute  |  NADS  |   NODS
  449. //t     fInhibitSymSwap   |  ISS   |   ASS
  450. //t     fCharShape        |  AAFS  |   IAFS
  451. //
  452. //      SCRIPT_STATE.fArabicNumContext controls the Unicode EN->AN rule.
  453. //      It should normally be initialised to TRUE
  454. //      before itemizing an RTL paragraph in an Arabic language, FALSE
  455. //      otherwise.
  456. /////   ScriptLayout
  457. //
  458. //      The ScriptLayout function converts an array of run embedding levels to
  459. //      a map of visual to logical position, and/or logical to visual position.
  460. //
  461. //      pbLevel must contain the embedding levels for all runs on the line,
  462. //      ordered logically.
  463. //
  464. //      On output, piVisualToLogical[0] is the logical index of the run to
  465. //      display at the far left. Subsequent entries should be displayed
  466. //      progressing from left to right.
  467. //
  468. //      piLogicalToVisual[0] is the relative visual position where the first
  469. //      logical run should be displayed - the leftmost display position being zero.
  470. //
  471. //      The caller may request either piLogicalToVisual or piVisualToLogical
  472. //      or both.
  473. //
  474. //      Note: No other input is required since the embedding levels give all
  475. //      necessary information for layout.
  476.  
  477.  
  478. HRESULT WINAPI ScriptLayout(
  479.     int           cRuns,              // In   Number of runs to process
  480.     const BYTE   *pbLevel,            // In   Array of run embedding levels
  481.     int          *piVisualToLogical,  // Out  List of run indices in visual order
  482.     int          *piLogicalToVisual); // Out  List of visual run positions
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489. /////   SCRIPT_JUSTIFY
  490. //
  491. //      The script justification enumeration provides the client with the
  492. //      glyph characteristic information it needs to implement justification.
  493.  
  494.  
  495. typedef enum tag_SCRIPT_JUSTIFY {
  496.     SCRIPT_JUSTIFY_NONE           = 0,   // Justification can't be applied at this glyph
  497.     SCRIPT_JUSTIFY_ARABIC_BLANK   = 1,   // This glyph represents a blank in an Arabic run
  498.     SCRIPT_JUSTIFY_CHARACTER      = 2,   // Inter-character justification point follows this glyph
  499.     SCRIPT_JUSTIFY_RESERVED1      = 3,   // Reserved #1
  500.     SCRIPT_JUSTIFY_BLANK          = 4,   // This glyph represents a blank outside an Arabic run
  501.     SCRIPT_JUSTIFY_RESERVED2      = 5,   // Reserved #2
  502.     SCRIPT_JUSTIFY_RESERVED3      = 6,   // Reserved #3
  503.     SCRIPT_JUSTIFY_ARABIC_NORMAL  = 7,   // Normal Middle-Of-Word glyph that connects to the right (begin)
  504.     SCRIPT_JUSTIFY_ARABIC_KASHIDA = 8,   // Kashida(U+640) in middle of word
  505.     SCRIPT_JUSTIFY_ARABIC_ALEF    = 9,   // Final form of Alef-like (U+627, U+625, U+623, U+632)
  506.     SCRIPT_JUSTIFY_ARABIC_HA      = 10,  // Final form of Ha (U+647)
  507.     SCRIPT_JUSTIFY_ARABIC_RA      = 11,  // Final form of Ra (U+631)
  508.     SCRIPT_JUSTIFY_ARABIC_BA      = 12,  // Middle-Of-Word form of Ba (U+628)
  509.     SCRIPT_JUSTIFY_ARABIC_BARA    = 13,  // Ligature of alike (U+628,U+631)
  510.     SCRIPT_JUSTIFY_ARABIC_SEEN    = 14,  // Highest priority: Initial shape of Seen(U+633) (end)
  511.     SCRIPT_JUSTIFY_RESERVED4      = 15,  // Reserved #4
  512. } SCRIPT_JUSTIFY;
  513.  
  514.  
  515.  
  516. /////   SCRIPT_VISATTR
  517. //
  518. //      The visual (glyph) attribute buffer generated by ScriptShape
  519. //      identifies clusters and justification points:
  520.  
  521.  
  522. typedef struct tag_SCRIPT_VISATTR {
  523.     WORD           uJustification   :4;  // Justification class
  524.     WORD           fClusterStart    :1;  // First glyph of representation of cluster
  525.     WORD           fDiacritic       :1;  // Diacritic
  526.     WORD           fZeroWidth       :1;  // Blank, ZWJ, ZWNJ etc, with no width
  527.     WORD           fReserved        :1;  // General reserved
  528.     WORD           fShapeReserved   :8;  // Reserved for use by shaping engines
  529. } SCRIPT_VISATTR;
  530. //
  531. //
  532. //p     uJustification: Justification class for this glyph. See SCRIPT_JUSTIFY.
  533. //
  534. //p     fClusterStart: Set for the logically first glyph in every cluster,
  535. //          even for clusters containing just one glyph.
  536. //
  537. //p     fDiacritic: Set for glyphs that combine with base characters.
  538. //
  539. //p     fZeroWidth: Set by the shaping engine for some, but not all, zero
  540. //          width characters.
  541.  
  542.  
  543. /////   ScriptShape
  544. //
  545. //      The ScriptShape function takes a Unicode run and generates glyphs and
  546. //      visual attributes.
  547. //
  548. //      The number of glyphs generated varies according to the script and the
  549. //      font. Only for simple scripts and fonts does each Unicode code point
  550. //      generates a single glyph.
  551. //
  552. //      There is no limit on the number of glyphs generated by a codepoint.
  553. //      For example, a sophisticated complex script font might choose to
  554. //      constuct characters from components, and so generate many times as
  555. //      many glyphs as characters.
  556. //
  557. //      There are also special cases like invalid character representations,
  558. //      where extra glyphs are added to represent the invalid sequence.
  559. //
  560. //      A reasonable guess might be to provide a glyph buffer 1.5 times the
  561. //      length of the character buffer, plus a 16 glyph fixed addition for
  562. //      rare cases like invalid sequenece representation.
  563. //
  564. //      If ScriptShape returns E_OUTOFMEMORY it will be necessary to recall
  565. //      it, possibly more than once, until a large enough buffer is found.
  566.  
  567.  
  568. HRESULT WINAPI ScriptShape(
  569.     HDC                 hdc,            // In    Optional (see under caching)
  570.     SCRIPT_CACHE       *psc,            // InOut Cache handle
  571.     const WCHAR        *pwcChars,       // In    Logical unicode run
  572.     int                 cChars,         // In    Length of unicode run
  573.     int                 cMaxGlyphs,     // In    Max glyphs to generate
  574.     SCRIPT_ANALYSIS    *psa,            // InOut Result of ScriptItemize (may have fNoGlyphIndex set)
  575.     WORD               *pwOutGlyphs,    // Out   Output glyph buffer
  576.     WORD               *pwLogClust,     // Out   Logical clusters
  577.     SCRIPT_VISATTR     *psva,           // Out   Visual glyph attributes
  578.     int                *pcGlyphs);      // Out   Count of glyphs generated
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585. /////
  586. //
  587. //      Returns E_OUTOFMEMORY if the output buffer length (cMaxGlyphs) is
  588. //          insufficient. Note that in this case, as in all error cases, the
  589. //          content of the output array is undefined.
  590. //
  591. //      Clusters are sequenced uniformly within the run, as are glyphs within
  592. //      the cluster - the fRTL item flag (from ScriptItemize) identifies
  593. //      whether left to right, or right to left.
  594. //
  595. //      ScriptShape may set the fNoGlyphIndex flag in psa if the font or
  596. //      OS cannot support glyph indices.
  597. //
  598. //      If fLogicalOrder is requested in psa, glyphs will be always be
  599. //      generated in the same order as the original Unicode characters.
  600. //
  601. //      If fLogicalOrder is not set, right to left items are generated in
  602. //      reverse order, so ScriptTextOut does not need to reverse them before
  603. //      calling ExtTextOut.
  604. /////   ScriptPlace
  605. //
  606. //      The ScriptPlace function takes the output of a ScriptShape call and
  607. //      generates glyph advance width and 2D offset information.
  608. //
  609. //      The composite ABC width for the whole item identifies how much the
  610. //      glyphs overhang to the left of the start position and to the right of
  611. //      the length implied by the sum of the advance widths.
  612. //
  613. //      The total advance width of the line is exactly abcA + abcB + abcC.
  614. //
  615. //      abcA and abcC are maintained internally by Uniscribe as proportions
  616. //      of the cell height represented in 8 bits and are thus roughly +/- 1%.
  617. //      The total width returned (as the sum of piAdvance, and as the sum of
  618. //      abcA+abcB+abcC) is accurate to the resolution of the TrueType shaping
  619. //      engine.
  620. //
  621. //      All glyph related arrays are in visual order unless the fLogicalOrder
  622. //      flag is set in psa.
  623.  
  624.  
  625. #ifndef LSDEFS_DEFINED
  626. typedef struct tagGOFFSET {
  627.     LONG  du;
  628.     LONG  dv;
  629. } GOFFSET;
  630. #endif
  631.  
  632.  
  633. HRESULT WINAPI ScriptPlace(
  634.     HDC                     hdc,        // In    Optional (see under caching)
  635.     SCRIPT_CACHE           *psc,        // InOut Cache handle
  636.     const WORD             *pwGlyphs,   // In    Glyph buffer from prior ScriptShape call
  637.     int                     cGlyphs,    // In    Number of glyphs
  638.     const SCRIPT_VISATTR   *psva,       // In    Visual glyph attributes
  639.     SCRIPT_ANALYSIS        *psa,        // InOut Result of ScriptItemize (may have fNoGlyphIndex set)
  640.     int                    *piAdvance,  // Out   Advance wdiths
  641.     GOFFSET                *pGoffset,   // Out   x,y offset for combining glyph
  642.     ABC                    *pABC);      // Out   Composite ABC for the whole run (Optional)
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649. /////   ScriptTextOut
  650. //
  651. //      The ScriptTextOut function takes the output of both ScriptShape and
  652. //      ScriptPlace calls and calls the operating system ExtTextOut function
  653. //      appropriately.
  654. //
  655. //      All arrays are in visual order unless the fLogicalOrder flag is set in
  656. //      psa.
  657.  
  658.  
  659. HRESULT WINAPI ScriptTextOut(
  660.     const HDC               hdc,        // In     OS handle to device context (required)
  661.     SCRIPT_CACHE           *psc,        // InOut  Cache handle
  662.     int                     x,          // In     x,y position for first glyph
  663.     int                     y,          // In
  664.     UINT                    fuOptions,  // In     ExtTextOut options
  665.     const RECT             *lprc,       // In     optional clipping/opaquing rectangle
  666.     const SCRIPT_ANALYSIS  *psa,        // In     Result of ScriptItemize
  667.     const WCHAR            *pwcReserved,// In     Reserved (requires NULL)
  668.     int                     iReserved,  // In     Reserved (requires 0)
  669.     const WORD             *pwGlyphs,   // In     Glyph buffer from prior ScriptShape call
  670.     int                     cGlyphs,    // In     Number of glyphs
  671.     const int              *piAdvance,  // In     Advance widths from ScriptPlace
  672.     const int              *piJustify,  // In     Justified advance widths (optional)
  673.     const GOFFSET          *pGoffset);  // In     x,y offset for combining glyph
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680. /////
  681. //
  682. //      The caller should normally use SetTextAlign(hdc, TA_RIGHT) before
  683. //      calling ScriptTextOut with an RTL item inlogical order.
  684. //
  685. //      The piJustify array provides requested cell widths for each glyph.
  686. //      When the piJustify width of a glyph differs from the unjustified
  687. //      width (in PiAdvance), space is added to or removed from the glyph
  688. //      cell at it's trailing edge. The glyph is always aligned with the
  689. //      leading edge of it's cell. (This rule applies even in visual order.)
  690. //
  691. //      When a glyph cell is extended the extra space is uaually made up by
  692. //      the addition of white space, however for Arabic scripts, the extra
  693. //      space is made up by one or more kashida glyphs, unless the extra space
  694. //      is insufficient for the shortest kashida glyph in the font. (The
  695. //      width of the shortest kashida is available by calling
  696. //      ScriptGetFontProperties.)
  697. //
  698. //      piJustify should only be passed if re-justification of the string is
  699. //      required. Normally pass NULL to this parameter.
  700. //
  701. //      fuOptions may contain ETO_CLIPPED or ETO_OPAQUE (or neither or both).
  702. //
  703. //      Do not use ScriptTextOut to write to a metafile unless you are sure
  704. //      that the metafile will eventually be played back without any font
  705. //      substitution. ScriptTextOut record glyph numbers in the metafile.
  706. //      Since glyph numbers vary considerably from one font to another
  707. //      such a metafile is unlikely to play back correctly when differant
  708. //      fonts are substituted.
  709. //
  710. //      For example when a metafile is played back at a different scale
  711. //      CreateFont requests recorded in the metafile may resolve to bitmap
  712. //      instead of truetype fonts, or if the metafile is played back on
  713. //      a different machine requested fonts may not be installed.//
  714. //
  715. //      To write complex scripts in a metafile in a font independant manner,
  716. //      use ExtTextOut to write the logical characters directly, so that
  717. //      glyph generation and placement does not occur until the text is
  718. //      played back.
  719. /////   ScriptJustify
  720. //
  721. //      ScriptJustify provides a simple minded implementation of multilingual
  722. //      justification.
  723. //
  724. //      Sophisticated text formatters may prefer to generate their own delta
  725. //      dx array by combining their own features with the information returned
  726. //      by ScriptShape in the SCRIPT_VISATTR array.
  727. //
  728. //      ScriptJustify establishes how much adjustment to make at each glyph
  729. //      position on the line. It interprets the SCRIPT_VISATTR array generated
  730. //      by a call to ScriptShape, and gives top priority to kashida, then uses
  731. //      inter word spacing if there's no kashida points, then uses
  732. //      intercharacter spacing if there are no inter-word points.
  733. //
  734. //      The justified advance widths generated in ScriptJustify should be
  735. //      passed to ScriptTextOut in the piJustify paramter.
  736. //
  737. //      ScriptJustify creates a justify array containing updated advance
  738. //      widths for each glyph. Where a glyphs advance width is increased, it
  739. //      is expected that the extra width will be rendered to the right of the
  740. //      glyph, with as white space or, for Arabic text, as kashida.
  741. /////
  742. HRESULT WINAPI ScriptJustify(
  743.     const SCRIPT_VISATTR  *psva,        // In   Collected visual attributes for entire line
  744.     const int             *piAdvance,   // In   Advance widths from ScriptPlace
  745.     int                    cGlyphs,     // In   Size of all arrays
  746.     int                    iDx,         // In   Desired width change, either increase or descrease
  747.     int                    iMinKashida, // In   Minimum length of continuous kashida glyph to generate
  748.     int                   *piJustify);  // Out  Updated advance widths to pass to ScriptTextOut
  749.  
  750.  
  751.  
  752.  
  753.  
  754.  
  755. /////   SCRIPT_LOGATTR
  756. //
  757. //      The SCRIPT_LOGATTR structure describes attributes of logical
  758. //      characters useful when editing and formatting text.
  759. //
  760. //      Note that for wordbreaking and linebreaking, if the first character of
  761. //      the run passed in is not whitespace, the client needs to check whether
  762. //      the last character of the previous run is whitespace to determine if
  763. //      the first character of this run is the start of a word.
  764. //
  765. //
  766. typedef struct tag_SCRIPT_LOGATTR {
  767.     BYTE    fSoftBreak      :1;     // Potential linebreak point
  768.     BYTE    fWhiteSpace     :1;     // A unicode whitespace character, except NBSP, ZWNBSP
  769.     BYTE    fCharStop       :1;     // Valid cursor position (for left/right arrow)
  770.     BYTE    fWordStop       :1;     // Valid cursor position (for ctrl + left/right arrow)
  771.     BYTE    fInvalid        :1;     // Invalid character sequence
  772.     BYTE    fReserved       :3;
  773. } SCRIPT_LOGATTR;
  774. //
  775. //
  776. //p     fSoftBreak: It would be valid to break the line in front of this
  777. //              character. This flag is set on the first character of
  778. //              South-East Asian words. Note that when linebreaking the
  779. //              client would usually also treat any nonblank following a blank
  780. //              as a softbreak position, by inspecting the fWhiteSPace flag
  781. //              below.
  782. //
  783. //p     fWhiteSpace: This character is one of the many Unicode character
  784. //              that are classified as breakable whitespace.
  785. //
  786. //p     fCharStop: Valid cursor position. Set on most characters, but not
  787. //              on codepoints inside Indian and South East Asian character
  788. //              clusters. May be used to implement left and right arrow
  789. //              operation in editors.
  790. //
  791. //p     fWordStop: Valid position following word advance/retire commonly
  792. //              implemented at ctrl/left-arrow and ctrl/right-arrow.
  793. //              May be used to implement ctrl+left and ctrl+right arrow
  794. //              operation in editors. As with fSoftBreak clients should
  795. //              normally also inspect the fWhiteSpace flag and treat the
  796. //              first character after a run of whitespace as the start of a
  797. //              word.
  798. //
  799. //p     fInvalid: Marks characters which form an invalid or undisplayable
  800. //              combination. Scripts which can set this flag have the flag
  801. //              fInvalidLogAttr set in their SCRIPT_PROPERTIES.
  802.  
  803.  
  804.  
  805.  
  806.  
  807.  
  808. /////   ScriptBreak
  809. //
  810. //      The ScriptBreak function returns cursor movement and formatting break
  811. //      positions for an item as an array of SCRIPT_LOGATTRs. To support
  812. //      mixed formatting within a single word correctly, ScriptBreak should
  813. //      be passed whole items as returned by ScriptItemize.
  814. //
  815. //      ScriptBreak does not require an hdc and does not execute glyph shaping.
  816. //
  817. //      The fCharStop flag marks cluster boundaries for those scripts where
  818. //      it is conventional to restrict from moving inside clusters. The same
  819. //      boundaries could also be inferred by inspecting the pLogCLust array
  820. //      returned by ScriptShape, however ScriptBreak is considerably faster in
  821. //      implementation and does not require an hdc to be prepared.
  822. //
  823. //      The fWordStop, fSoftBreak and fWhiteSpace flags are only available
  824. //      through ScriptBreak.
  825. //
  826. //      Most shaping engines that identify invalid sequences do so by setting
  827. //      the fInvalid flag in ScriptBreak. The fInvalidLogAttr flag in
  828. //      ScriptProperties identifies which scripts do this.
  829.  
  830.  
  831. HRESULT WINAPI ScriptBreak(
  832.     const WCHAR            *pwcChars,  // In   Logical unicode item
  833.     int                     cChars,    // In   Length of unicode item
  834.     const SCRIPT_ANALYSIS  *psa,       // In   Result of earlier ScriptItemize call
  835.     SCRIPT_LOGATTR         *psla);     // Out  Logical character attributes
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842. /////   ScriptCPtoX
  843. //
  844. //      The ScriptCPtoX function returns the x offset from the left end
  845. //      (!fLogical) or leading edge (fLogical) of a run to either the leading
  846. //      or the trailing edge of a logical character cluster.
  847. //
  848. //      iCP is the offset of any logical character in the cluster.
  849. //
  850. //      For scripts where the caret may conventionally be placed into the
  851. //      middle of clusters (e.g. Arabic, Hebrew), the returned X may be
  852. //      an interpolated position for any codepoint in the line.
  853. //
  854. //      For scripts where the caret is conventionally snapped to the boundaries
  855. //      of clusters, (e.g. Thai, Indian), the resulting X position will be
  856. //      snapped to the requested edge of the cluster containing CP.
  857.  
  858.  
  859. HRESULT WINAPI ScriptCPtoX(
  860.     int                     iCP,        // In   Logical character position in run
  861.     BOOL                    fTrailing,  // In   Which edge (default - leading)
  862.     int                     cChars,     // In   Count of logical codepoints in run
  863.     int                     cGlyphs,    // In   Count of glyphs in run
  864.     const WORD             *pwLogClust, // In   Logical clusters
  865.     const SCRIPT_VISATTR   *psva,       // In   Visual glyph attributes array
  866.     const int              *piAdvance,  // In   Advance widths
  867.     const SCRIPT_ANALYSIS  *psa,        // In   Script analysis from item attributes
  868.     int                    *piX);       // Out  Resulting X position
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875. /////   ScriptXtoCP
  876. //
  877. //      The ScriptXtoCP function converts an x offset from the left end
  878. //      (!fLogical) or leading edge (fLogical) of a run to a logical
  879. //      character position and a flag that indicates whether the X position
  880. //      fell in the leading or the trailing half of the character.
  881. //
  882. //      For scripts where the cursor may conventionally be placed into the
  883. //      middle of clusters (e.g. Arabic, Hebrew), the returned CP may be
  884. //      for any codepoint in the line, and fTrailing will be either zero
  885. //      or one.
  886. //
  887. //      For scripts where the cursor is conventionally snapped to the
  888. //      boundaries of a cluster, the returned CP is always the position of
  889. //      the logically first codepoint in a cluster, and fTrailing is either
  890. //      zero, or the number of codepoints in the cluster.
  891. //
  892. //      Thus the appropriate cursor position for a mouse hit is always the
  893. //      returned CP plus the value of fTrailing.
  894. //
  895. //      If the X positition passed is not in the item at all, the resulting
  896. //      position will be the trailing edge of character -1 (for X positions
  897. //      before the item), or the leading edge of character 'cChars' (for
  898. //      X positions following the item).
  899.  
  900.  
  901. HRESULT WINAPI ScriptXtoCP(
  902.     int                     iX,             // In   X offset from left of run
  903.     int                     cChars,         // In   Count of logical codepoints in run
  904.     int                     cGlyphs,        // In   Count of glyphs in run
  905.     const WORD             *pwLogClust,     // In   Logical clusters
  906.     const SCRIPT_VISATTR   *psva,           // In   Visual glyph attributes
  907.     const int              *piAdvance,      // In   Advance widths
  908.     const SCRIPT_ANALYSIS  *psa,            // In   Script analysis from item attributes
  909.     int                    *piCP,           // Out  Resulting character position
  910.     int                    *piTrailing);    // Out  Leading or trailing half flag
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917. /////   Relationship between caret positions, justifications points and clusters
  918. //
  919. //
  920. //t     Job                              | Uniscribe support
  921. //t     -------------------------------- | --------------------------------------------------------
  922. //t     Caret move by character cluster  | LogClust or VISATTR.fClusterStart or LOGATTR.fCharStop
  923. //t     Line breaking between characters | LogClust or VISATTR.fClusterStart or LOGATTR.fCharStop
  924. //t     Caret move by word               | LOGATTR.fWordStop
  925. //t     Line breaking between words      | LOGATTR.fWordStop
  926. //t     Justification                    | VISATTR.uJustification
  927. //
  928. //
  929. //
  930. /////   Character clusters
  931. //
  932. //      Character clusters are glyph sequences that cannot be split between
  933. //      lines.
  934. //
  935. //      Some languages (e.g. Thai, Indic) restrict caret placement to points
  936. //      betwen clusters. This applies both to keyboard initiated caret
  937. //      movement (e.g. cursor keys) and pointing and clicking with the mouse
  938. //      (hit testing).
  939. //
  940. //      Uniscribe provides cluster information in both the visual and logical
  941. //      attributes. If you've called ScriptShape you'll find the cluster
  942. //      information represented both by sequences of the same value in the
  943. //      pwLogClust array, and by the fClusterStart flag in the psva
  944. //      SCRIPT_VISATTR array.
  945. //
  946. //      ScriptBreak also returns the fCharStop flag in the SCRIPT_LOGATTR
  947. //      array to identify cluster positions.
  948. //
  949. //
  950. //
  951. /////   Word break points
  952. //
  953. //      Valid positions for moving the caret when moving in whole words are
  954. //      marked by the fWordStop flag returned by ScriptBreak.
  955. //
  956. //      Valid positions for breaking lines between words are marked by the
  957. //      fSoftBreak flag returned by ScriptBreak.
  958. //
  959. //
  960. //
  961. /////   Justification
  962. //
  963. //      Justification space or kashida should be inserted where identified by
  964. //      the uJustificaion field of the SCRIPT_VISATTR.
  965. //
  966. //      When performing inter-character justification, insert extra space
  967. //      only after glyphs marked with uJustify == SCRIPT_JUSTIFY_CHARACTER.
  968. //
  969. //
  970. //
  971. /////   Script specific processing
  972. //
  973. //      Uniscribe provides information about special processing for each
  974. //      script in the SCRIPT_PROPERTIES array.
  975. //
  976. //      Use the following code during initialisation to get a pointer to
  977. //      the SCRIPT_PROPERTIES array:
  978. //
  979. //c     const SCRIPT_PROPERTIES **g_ppScriptProperties; // Array of pointers to properties
  980. //c     int iMaxScript;
  981. //c     HRESULT hr;
  982. //
  983. //c     hr = ScriptGetProperties(&g_ppScriptProperties, &g_iMaxScript);
  984. //
  985. //      Then inspect the properties of the script of an item 'iItem' as follows:
  986. //
  987. //c     hr = ScriptItemize( ... , pItems, ... );
  988. //c     ...
  989. //c     if (g_ppScriptProperties[pItems[iItem].a.eScript]->fNeedsCaretInfo) {
  990. //c         // Use ScriptBreak to restrict the caret from entering clusters (for example).
  991. //c     }
  992. //
  993. //
  994. //      SCRIPT_PROPERTIES.fNeedsCaretInfo
  995. //
  996. //      Caret placement should be restricted to cluster
  997. //      edges for scripts such as Thai and Indian. The fNeedsCaretInfo flag
  998. //      in SCRIPT_PROPERTIES identifies such languages.
  999. //
  1000. //      Note that ScriptXtoCP and ScriptCPtoX automatically apply caret
  1001. //      placement restictions.
  1002. //
  1003. //
  1004. //      SCRIPT_PROPERTIES.fNeedsWordBreaking
  1005. //
  1006. //      For most scripts, word break placement  may be
  1007. //      identified by scanning for characters marked as fWhiteSpace in
  1008. //      SCRIPT_LOGATTR, or for glyphs marked as uJustify ==
  1009. //      SCRIPT_JUSTIFY_BLANK or SCRIPT_JUSTIFY_ARABIC_BLANK in SCRIPT_VISATTR.
  1010. //
  1011. //      For languages such as Thai, it is also necessary to call ScriptBreak,
  1012. //      and include character positions marked as fWordStop in SCRIPT_LOGATTR.
  1013. //      Such scripts are marked as fNeedsWordbreaking in SCRIPT_PROPERTIES.
  1014. //
  1015. //
  1016. //      SCRIPT_PROPERTIES.fNeedsCharacterJustify
  1017. //
  1018. //      Languages such as Thai also require inter-character spacing when
  1019. //      justifying (where uJustify == SCRIPT_JUSTIFY_CHARACTER in the
  1020. //      SCRIPT_VISATTR). Such languages are marked as fNeedsCharacterJustify
  1021. //      in SCRIPT_PROPERTIES.
  1022. //
  1023. //
  1024. //      SCRIPT_PROPERTIES.fAmbiguousCharSet
  1025. //
  1026. //      Many Uniscribe scripts do not correspond directly to 8 bit character
  1027. //      sets. For example Unicode characters in the range U+100 through U+024F
  1028. //      represent extended latin shapes used for many languages, including
  1029. //      those supported by EASTEUROPE_CHARSET, TURKISH_CHARSET and
  1030. //      VIETNAMESE_CHARSET. However many of these characters are supported by
  1031. //      more han one of thsese charsets.
  1032. //      fAmbiguousCharset is set for any script token which could contain
  1033. //      characters from a number of these charsets. In these cases the bCharSet
  1034. //      field may contain ANSI_CHARSET or DEFAULT_CHARSET. The Uniscribe client
  1035. //      will generally need to apply futher processing to determine which charset
  1036. //      to use when requesting a font suitable for this run. For example it
  1037. //      determine that the run consists of multiple languages and split it up
  1038. //      to use a different font for each language.
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045. /////   Notes on ScriptXtoCP and ScriptCPtoX
  1046. //
  1047. //      Both functions work only within runs and require the results of a
  1048. //      previous ScriptShape call.
  1049. //
  1050. //      The client must establish which run a given cursor offset or x
  1051. //      position is within before passing it to ScriptCPtoX or ScriptXtoCP.
  1052. //
  1053. //      Cluster information in the logical cluster array is used to share
  1054. //      the width of a cluster of glyphs equally among the logical characters
  1055. //      they represent.
  1056. //
  1057. //      For example, the lam alif glyph is divided into four areas: the
  1058. //      leading half of the lam, the trailing half of the lam, the leading
  1059. //      half of the alif and the trailing half of the alif.
  1060. //
  1061. //      ScriptXtoCP Understands the caret position conventions of each script.
  1062. //      For Indian and Thai, caret positions are snapped to cluster boundaries,
  1063. //      for Arabic and Hebrew, caret positions are interpolated within clusters.
  1064. //
  1065. //
  1066. /////   Translating mouse hit 'x' offset to caret position
  1067. //
  1068. //      Conventionally, caret position 'cp' may be selected by clicking either
  1069. //      on the trailing half of character 'cp-1' or on the leading half of
  1070. //      character 'cp'. This may easily be implemented as follows:
  1071. //
  1072. //c     int iCharPos;
  1073. //c     int iCaretPos
  1074. //c     int fTrailing;
  1075. //
  1076. //c     ScriptXtoCP(iMouseX, ..., &iCharPos, &fTrailing);
  1077. //c     iCaretPos = iCharPos + fTrailing;
  1078. //
  1079. //      For scripts that snap the caret to cluster boundaries, ScriptXtoCP
  1080. //      returns ftrailing set to either 0, or the width of the cluster in
  1081. //      codepoints. Thus the above code correctly returns only valid
  1082. //      caret positions.
  1083. //
  1084. //
  1085. /////   Displaying the caret in bidi strings
  1086. //
  1087. //      In unidirectional text, the leading edge of a character is at the same
  1088. //      place as the trailing edge of the previous character, so there is no
  1089. //      ambiguity in placing the caret between characters.
  1090. //
  1091. //      In bidirectional text, the caret position between runs of opposing
  1092. //      direction may be ambiguous.
  1093. //
  1094. //      For example in the left to right paragraph 'helloMAALAS', the last
  1095. //      letter of 'hello' immediately preceeds the first letter of 'salaam'.
  1096. //      The best position to display the caret depends on whether it is
  1097. //      considered to follow the 'o' of 'hello', or to preceed the 's' of
  1098. //      'salaam'.
  1099. //
  1100. /////   Commonly used caret positioning conventions
  1101. //
  1102. //t     Situation       | Visual caret placement
  1103. //t     ---------       | -------------------------------------------
  1104. //t     Typing          | Trailing edge of last character typed
  1105. //t     Pasting         | Trailing edge of last character pasted
  1106. //t     Caret advancing | Trailing edge of last character passed over
  1107. //t     Caret retiring  | Leading edge of last character passed over
  1108. //t     Home            | Leading edge of line
  1109. //t     End             | Trailing edge of line
  1110. //
  1111. //      The caret may be positioned as follows:
  1112. //
  1113. //c     if (advancing) {
  1114. //c         ScriptCPtoX(iCharPos-1, TRUE, ..., &iCaretX);
  1115. //c     } else {
  1116. //c         ScriptCPtoX(iCharPos, FALSE, ..., &iCaretX);
  1117. //c     }
  1118. //
  1119. //      Or, more simply, given an fAdvancing BOOL restricted to TRUE or FALSE:
  1120. //
  1121. //c     ScriptCPtoX(iCharPos-fAdvancing, fAdvancing, ..., &iCaretX);
  1122. //
  1123. //      ScriptCPtoX handles out of range positions logically: it returns the
  1124. //      leading edge of the run for iCharPos <0, and the trailing edge of the
  1125. //      run for iCharPos >=length.
  1126. /////   ScriptGetLogicalWidths
  1127. //
  1128. //      Converts visual withs in piAdvance into logical widths,
  1129. //      one per original character, in logical order.
  1130. //
  1131. //      Ligature glyphs widths are divided evenly amongst the characters
  1132. //      they represent.
  1133.  
  1134.  
  1135. HRESULT WINAPI ScriptGetLogicalWidths(
  1136.     const SCRIPT_ANALYSIS  *psa,            // In   Script analysis from item attributes
  1137.     int                     cChars,         // In   Count of logical codepoints in run
  1138.     int                     cGlyphs,        // In   Count of glyphs in run
  1139.     const int              *piGlyphWidth,   // In   Advance widths
  1140.     const WORD             *pwLogClust,     // In   Logical clusters
  1141.     const SCRIPT_VISATTR   *psva,           // In   Visual glyph attributes
  1142.     int                    *piDx);          // Out  Logical widths
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149. /////
  1150. //      ScriptGetLogicalWidths is useful for recording widths in a
  1151. //      font independant manner. By passing the recorded logical widths
  1152. //      to ScriptApplyLogicalWidths, a block of text can be replayed in the
  1153. //      same boundaries with acceptable loss of quality even when the original
  1154. //      font is not available.
  1155. /////   ScriptApplyLogicalWidth
  1156. //
  1157. //      Accepts an array of advance widths in logical order, corresponding
  1158. //      one to one with codepoints, and generates an array of glyph widths
  1159. //      suitable for passing to the piJustify parameter of ScriptTextOut.
  1160. //
  1161. //      ScriptApplyLogicalWidth may be used to reapply logical widths
  1162. //      obtained with ScriptGetLogicalWidths. It may be useful in situations
  1163. //      such as metafiling, where it is necessary to record and reapply
  1164. //      advance width information in a font independant manner.
  1165.  
  1166.  
  1167.  
  1168. HRESULT WINAPI ScriptApplyLogicalWidth(
  1169.     const int              *piDx,        // In     Logical dx array to apply
  1170.     int                     cChars,      // In     Count of logical codepoints in run
  1171.     int                     cGlyphs,     // In     Glyph count
  1172.     const WORD             *pwLogClust,  // In     Logical clusters
  1173.     const SCRIPT_VISATTR   *psva,        // In     Visual attributes from ScriptShape/Place
  1174.     const int              *piAdvance,   // In     Glyph advance widths from ScriptPlace
  1175.     const SCRIPT_ANALYSIS  *psa,         // In     Script analysis from item attributes
  1176.     ABC                    *pABC,        // InOut  Updated item ABC width (optional)
  1177.     int                    *piJustify);  // Out    Resulting glyph advance widths for ScriptTextOut
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184. /////
  1185. //p     piDx: Pointer to an array of dx widths in logical order, one per codepoint.
  1186. //
  1187. //p     cChars: Count of the logical codepoints in the run.
  1188. //
  1189. //p     cGlyphs: Glyph count.
  1190. //
  1191. //p     pwLogClust: Pointer to an array of logical clusters from ScriptShape
  1192. //
  1193. //p     psva: Pointer to an array of visual attributes from ScriptShape and
  1194. //          updated by ScriptPlace.
  1195. //
  1196. //p     piAdvance: Pointer to an array of glyph advance widths from ScriptPlace.
  1197. //
  1198. //p     psa: Pointer to a SCRIPT_ANALYSIS structure from ScriptItemize and
  1199. //          updated by ScriptShape and SriptPlace..
  1200. //
  1201. //p     pABC: Pointer to the run overall ABC width (optional). If present,
  1202. //          when the function is called, it should contain the run ABC width
  1203. //          returned by ScriptPlace; when the function returns, the ABC width
  1204. //          has been updated to match the new widths.
  1205. //
  1206. //p     piJustify:Pointer to an array of the resulting glyph advance widths.
  1207. //          This is suitable for passing to the piJustify parameter of ScriptTextOut.
  1208. /////   ScriptGetCMap
  1209. //
  1210. //      ScriptGetCMap may be used to determine which characters in a run
  1211. //      are supported by the selected font.
  1212. //
  1213. //      It returns glyph indices of Unicode characters according to Truetype
  1214. //      Cmap table, or standard Cmap implemented for old style fonts. The
  1215. //      glyph indices are returned in the same order as the input string.
  1216. //
  1217. //      The caller may scan the returned glyph buffer looking for the default
  1218. //      glyph to determine which characters are not available. (The default
  1219. //      glyph index for the selected font should be determined by calling
  1220. //      ScriptGetFontProperties).
  1221. //
  1222. //      The return value indicates the presence of any missing glyphs.
  1223.  
  1224.  
  1225. #define SGCM_RTL  0x00000001      // Return mirrored glyph for mirrorable Unicode codepoints
  1226.  
  1227.  
  1228. HRESULT WINAPI ScriptGetCMap(
  1229.     HDC             hdc,            // In    Optional (see notes on caching)
  1230.     SCRIPT_CACHE   *psc,            // InOut Address of Cache handle
  1231.     const WCHAR    *pwcInChars,     // In    Unicode codepoint(s) to look up
  1232.     int             cChars,         // In    Number of characters
  1233.     DWORD           dwFlags,        // In    Flags such as SGCM_RTL
  1234.     WORD           *pwOutGlyphs);   // Out   Array of glyphs, one per input character
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241. /////
  1242. //  returns S_OK     - All unicode codepoints were present in the font
  1243. //          S_FALSE  - Some of the Unicode codepoints were mapped to the default glyph
  1244. //          E_HANDLE - font or system does not support glyph indices
  1245. /////   ScriptGetGlyphABCWidth
  1246. //
  1247. //      Returns ABC width of a given glyph.
  1248. //      May be useful for drawing glyph charts. Should not be used for
  1249. //      run of the mill complex script text formatting.
  1250.  
  1251.  
  1252. HRESULT WINAPI ScriptGetGlyphABCWidth(
  1253.     HDC             hdc,            // In    Optional (see notes on caching)
  1254.     SCRIPT_CACHE   *psc,            // InOut Address of Cache handle
  1255.     WORD            wGlyph,         // In    Glyph
  1256.     ABC            *pABC);          // Out   ABC width
  1257.  
  1258.  
  1259.  
  1260.  
  1261.  
  1262.  
  1263. /////
  1264. //  returns S_OK     - Glyph width returned
  1265. //          E_HANDLE - font or system does not support glyph indices
  1266. /////   SCRIPT_PROPERTIES
  1267. //
  1268. typedef struct {
  1269.     DWORD   langid                 :16; // Primary and sublanguage associated with script
  1270.     DWORD   fNumeric               :1;
  1271.     DWORD   fComplex               :1;  // Script requires special shaping or layout
  1272.     DWORD   fNeedsWordBreaking     :1;  // Requires ScriptBreak for word breaking information
  1273.     DWORD   fNeedsCaretInfo        :1;  // Requires caret restriction to cluster boundaries
  1274.     DWORD   bCharSet               :8;  // Charset to use when creating font
  1275.     DWORD   fControl               :1;  // Contains only control characters
  1276.     DWORD   fPrivateUseArea        :1;  // This item is from the Unicode range U+E000 through U+F8FF
  1277.     DWORD   fNeedsCharacterJustify :1;  // Requires inter-character justification
  1278.     DWORD   fInvalidGlyph          :1;  // Invalid combinations generate glyph wgInvalid in the glyph buffer
  1279.     DWORD   fInvalidLogAttr        :1;  // Invalid combinations are marked by fInvalid in the logical attributes
  1280.     DWORD   fCDM                   :1;  // Contains Combining Diacritical Marks
  1281.     DWORD   fAmbiguousCharSet      :1;  // Script does not correspond 1:1 with a charset
  1282.     DWORD   fClusterSizeVaries     :1;  // Measured cluster width depends on adjacent clusters
  1283.     DWORD   fRejectInvalid         :1;  // Invalid combinations should be rejected
  1284. } SCRIPT_PROPERTIES;
  1285. //
  1286. //p     langid: Language associated with this script. When a script is used for many languages,
  1287. //          langid id represents a default language. For example, Western script is represented
  1288. //          by LANG_ENGLISH although it is also used for French, German, Spanish etc.
  1289. //
  1290. //p     fNumeric: Script contains numerics and characters used in conjunction with numerics
  1291. //          by the rules of the Unicode bidirectional algorithm. For example
  1292. //          dollar sign and period are classified as numeric when adjacent to or in between
  1293. //          digits.
  1294. //
  1295. //p     fComplex: Indicates a script that requires complex script handling. If fComplex is false
  1296. //          the script contains no combining characters and requires no contextual shaping or reordering.
  1297. //
  1298. //p     fNeedsWordBreaking: A script, such as Thai, which requires algorithmic wordbreaking.
  1299. //          Use ScriptBreak to obtain a wordbreak points using the standard system wordbreaker.
  1300. //
  1301. //p     fNeedsCaretInfo: A script, such as Thai and Indian, where the caret may not be placed
  1302. //          inside a cluster. To determine valid caret positions inspect the fCharStop flag in the
  1303. //          logical attributes returned by ScriptBreak, or compare adjacent values in the pwLogClust
  1304. //          array returned by ScriptShape.
  1305. //
  1306. //p     bCharSet: Nominal charset associated with script. May be used in a logfont when creating
  1307. //          a font suitable for displaying this script. Note that for new scripts where there
  1308. //          is no charset defined, bCharSet may be innapropriate and DEFAULT_CHARSET should
  1309. //          be used instead - see the description of fAmbiguousCharSet below.
  1310. //
  1311. //p     fControl: contains control characters.
  1312. //
  1313. //p     fPrivateUseArea: The Unicode range U+E000 through U+F8FF.
  1314. //
  1315. //p     fNeedsCharacterJustify: A script, such as Thai, where justification is conventionally
  1316. //          achieved by increasing the space between all letters, not just between words.
  1317. //
  1318. //p     fInvalidGlyph: A script for which ScriptShape generates an invalid glyph
  1319. //          to represent invalid sequences. The glyph index of the invalid glyph for
  1320. //          a particular font may be obtained by calling ScriptGetFontProperties.
  1321. //
  1322. //p     fInvalidLogAttr: A script for which ScriptBreak sets the fInvalid flag
  1323. //          in the logical attributes to mark invalid sequences.
  1324. //
  1325. //p     fCDM: Implies that an item analysed by ScriptItemize included combining
  1326. //          diacritical marks (U+0300 through U+36F).
  1327. //
  1328. //p     fAmbiguousCharSet: No single legacy charset supports this script.
  1329. //          For example the extended Latin Extended-A Unicode range includes
  1330. //          characters from the EASTUROPE_CHARSET, the TURKISH_CHARSET and the
  1331. //          BALTIC_CHARSET. It also contains characters that are not available
  1332. //          in any legacy charset. Use DEFAULT_CHARSET when creating fonts to
  1333. //          display parts of this run.
  1334. //
  1335. //p     fClusterSizeVaries: A script, such as Arabic, where contextual shaping
  1336. //          may cause a string to increase in size when removing characters.
  1337. //
  1338. //p     fRejectInvalid: A script, such as Thai, where invalid sequences conventionally
  1339. //          cause an editor such as notepad to beep, and ignore keypresses.
  1340.  
  1341.  
  1342. /////   ScriptGetProperties
  1343. //
  1344. //      ScriptGetProperties returns the address of a table that maps a
  1345. //      script in a SCRIPT_ANALYSIS uScript field to properties including
  1346. //      the primary language associated with that script, whether it's
  1347. //      numeric and whether it's complex.
  1348.  
  1349.  
  1350. HRESULT WINAPI ScriptGetProperties(
  1351.     const SCRIPT_PROPERTIES ***ppSp,             // Out  Receives pointer to table of pointers to properties indexed by script
  1352.     int                       *piNumScripts);    // Out  Receives number of scripts (valid values are 0 through NumScripts-1)
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359. /////   SCRIPT_FONTPROPERTIES
  1360. //
  1361. typedef struct {
  1362.     int     cBytes;         // Structure length
  1363.     WORD    wgBlank;        // Blank glyph
  1364.     WORD    wgDefault;      // Glyph used for Unicode values not present in the font
  1365.     WORD    wgInvalid;      // Glyph used for invalid character combinations (especially in Thai)
  1366.     WORD    wgKashida;      // Shortest continuous kashida glyph in the font, -1 if doesn't exist
  1367.     int     iKashidaWidth;  // Widths of shortest continuous kashida glyph in the font
  1368. } SCRIPT_FONTPROPERTIES;
  1369.  
  1370.  
  1371. /////   ScriptGetFontProperties
  1372. //
  1373. //      Returns information from the font cache
  1374.  
  1375.  
  1376. HRESULT WINAPI ScriptGetFontProperties(
  1377.     HDC                     hdc,    // In    Optional (see notes on caching)
  1378.     SCRIPT_CACHE           *psc,    // InOut Address of Cache handle
  1379.     SCRIPT_FONTPROPERTIES  *sfp);   // Out   Receives properties for this font
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386. /////   ScriptCacheGetHeight
  1387. //
  1388. //
  1389.  
  1390.  
  1391. HRESULT WINAPI ScriptCacheGetHeight(
  1392.     HDC            hdc,         // In    Optional (see notes on caching)
  1393.     SCRIPT_CACHE  *psc,         // InOut Address of Cache handle
  1394.     long          *tmHeight);   // Out   Receives font height in pixels
  1395.  
  1396.  
  1397.  
  1398.  
  1399.  
  1400.  
  1401. /////   ScriptStringAnalyse
  1402. //
  1403. //
  1404. #define SSA_PASSWORD         0x00000001  // Input string contains a single character to be duplicated iLength times
  1405. #define SSA_TAB              0x00000002  // Expand tabs
  1406. #define SSA_CLIP             0x00000004  // Clip string at iReqWidth
  1407. #define SSA_FIT              0x00000008  // Justify string to iReqWidth
  1408. #define SSA_DZWG             0x00000010  // Provide representation glyphs for control characters
  1409. #define SSA_FALLBACK         0x00000020  // Use fallback fonts
  1410. #define SSA_BREAK            0x00000040  // Return break flags (character and word stops)
  1411. #define SSA_GLYPHS           0x00000080  // Generate glyphs, positions and attributes
  1412. #define SSA_RTL              0x00000100  // Base embedding level 1
  1413. #define SSA_GCP              0x00000200  // Return missing glyphs and LogCLust with GetCharacterPlacement conventions
  1414. #define SSA_HOTKEY           0x00000400  // Replace '&' with underline on subsequent codepoint
  1415. #define SSA_METAFILE         0x00000800  // Write items with ExtTextOutW Unicode calls, not glyphs
  1416. #define SSA_LINK             0x00001000  // Apply FE font linking/association to non-complex text
  1417. #define SSA_HIDEHOTKEY       0x00002000  // Remove first '&' from displayed string
  1418. #define SSA_HOTKEYONLY       0x00002400  // Display underline only.
  1419.  
  1420. #define SSA_FULLMEASURE      0x04000000  // Internal - calculate full width and out the number of chars can fit in iReqWidth.
  1421. #define SSA_LPKANSIFALLBACK  0x08000000  // Internal - enable FallBack for all LPK Ansi calls Except BiDi hDC calls
  1422. #define SSA_PIDX             0x10000000  // Internal
  1423. #define SSA_LAYOUTRTL        0x20000000  // Internal - Used when DC is mirrored
  1424. #define SSA_DONTGLYPH        0x40000000  // Internal - Used only by GDI during metafiling - Use ExtTextOutA for positioning
  1425. #define SSA_NOKASHIDA        0x80000000  // Internal - Used by GCP to justify the non Arabic glyphs only.
  1426. //
  1427. //
  1428. //p     SSA_HOTKEY: Note that SSA_HOTKEY and SSA_HIDEHOTKEY remove the
  1429. //          hotkey '&' character from further processing, so functions
  1430. //          such as ScriptString_pLogAttr return arrays based on a string
  1431. //          which excludes the '&'.
  1432.  
  1433.  
  1434.  
  1435.  
  1436. /////   SCRIPT_TABDEF
  1437. //
  1438. //      Defines tabstop positions for ScriptStringAnalyse (ignored unless SSA_TAB passed)
  1439. //
  1440. typedef struct tag_SCRIPT_TABDEF {
  1441.     int   cTabStops;        // Number of entries in pTabStops array
  1442.     int   iScale;           // Scale factor for pTabStops (see below)
  1443.     int  *pTabStops;        // Pointer to array of one or more tab stops
  1444.     int   iTabOrigin;       // Initial offset for tab stops (logical units)
  1445. } SCRIPT_TABDEF;
  1446. //
  1447. //
  1448. //p     cTabStops: Number of entries in the pTabStops array. If zero, tabstops
  1449. //          are every 8 average character widths. If one, all tabstops are
  1450. //          the length of the first entry in pTabStops. If more than one,
  1451. //          the first cTabStops are as specified in the pTabStops array,
  1452. //          subsequent tabstops are every 8 average characters from the last
  1453. //          tabstop in the array.
  1454. //
  1455. //p     iScale: Scale factor for iTabOrigin and pTabStops entries. Values are
  1456. //          converted to device coordinates by multiplying by iScale then
  1457. //          dividing by 4. If values are already in device units, set iScale to
  1458. //          4. If values are in dialog units, set iScale to the average char
  1459. //          width of the dialog font. If values are multiples of the average
  1460. //          character width for the selected font, set iScale to 0.
  1461. //
  1462. //p     pTabStops: Array of cTabStops entries. Each entry specifies a
  1463. //          tabstop position. Positive values give nearedge alignment,
  1464. //          negative values give faredge alignment.
  1465. //
  1466. //p     iTabOrigin: Tabs are considered to start iTabOrigin before the
  1467. //          beginning of the string. Helps with multiple tabbed
  1468. //          outputs on the same line.
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475. /////   ScriptStringAnalyse
  1476. //
  1477. //      cString - Input string must contain at least one character
  1478. //
  1479. //      hdc - required if SSA_GLYPH requested. Optional for SSA_BREAK.
  1480. //      If present the current font in the hdc is inspected and if a symbolic
  1481. //      font the character string is treated as a single neutral SCRIPT_UNDEFINED item.
  1482. //
  1483. //      Note that the uBidiLevel field in the initial SCRIPT_STATE value
  1484. //      is ignored - the uBidiLevel used is derived from the SSA_RTL
  1485. //      flag in combination with the layout of the hdc.
  1486.  
  1487.  
  1488. typedef void* SCRIPT_STRING_ANALYSIS;
  1489.  
  1490.  
  1491. HRESULT WINAPI ScriptStringAnalyse(
  1492.     HDC                      hdc,       //In  Device context (required)
  1493.     const void              *pString,   //In  String in 8 or 16 bit characters
  1494.     int                      cString,   //In  Length in characters (Must be at least 1)
  1495.     int                      cGlyphs,   //In  Required glyph buffer size (default cString*1.5 + 16)
  1496.     int                      iCharset,  //In  Charset if an ANSI string, -1 for a Unicode string
  1497.     DWORD                    dwFlags,   //In  Analysis required
  1498.     int                      iReqWidth, //In  Required width for fit and/or clip
  1499.     SCRIPT_CONTROL          *psControl, //In  Analysis control (optional)
  1500.     SCRIPT_STATE            *psState,   //In  Analysis initial state (optional)
  1501.     const int               *piDx,      //In  Requested logical dx array
  1502.     SCRIPT_TABDEF           *pTabdef,   //In  Tab positions (optional)
  1503.     const BYTE              *pbInClass, //In  Legacy GetCharacterPlacement character classifications (deprecated)
  1504.  
  1505.     SCRIPT_STRING_ANALYSIS  *pssa);     //Out Analysis of string
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512. /////   ScriptStringFree - free a string analysis
  1513. //
  1514. //
  1515.  
  1516.  
  1517. HRESULT WINAPI ScriptStringFree(
  1518.     SCRIPT_STRING_ANALYSIS *pssa);  //InOut Address of pointer to analysis
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525. /////   ScriptStringSize
  1526. //
  1527. //      returns a pointer to the size (width and height) of an analysed string
  1528. //
  1529. //      Note that the SIZE pointer remains valid only until the
  1530. //      SCRIPT_STRING_ANALYSIS is passed to ScriptStringFree.
  1531.  
  1532.  
  1533. const SIZE* WINAPI ScriptString_pSize(
  1534.     SCRIPT_STRING_ANALYSIS   ssa); 
  1535.  
  1536.  
  1537.  
  1538.  
  1539.  
  1540.  
  1541. /////   ScriptString_pcOutChars
  1542. //
  1543. //      returns pointer to length of string after clipping (requires SSA_CLIP set)
  1544. //
  1545. //      Note that the int pointer remains valid only until the
  1546. //      SCRIPT_STRING_ANALYSIS is passed to ScriptStringFree.
  1547.  
  1548.  
  1549. const int* WINAPI ScriptString_pcOutChars(
  1550.     SCRIPT_STRING_ANALYSIS   ssa); 
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557. /////   ScriptString_pLogAttr
  1558. //
  1559. //      returns pointer to logical attributes buffer in a SCRIPT_STRING_ANALYSIS
  1560. //
  1561. //      Note that the buffer pointer remains valid only until the
  1562. //      SCRIPT_STRING_ANALYSIS is passed to ScriptStringFree.
  1563. //
  1564. //      The logical attribute array contains *ScriptString_pcOutChars(ssa)
  1565. //      entries.
  1566.  
  1567.  
  1568. const SCRIPT_LOGATTR* WINAPI ScriptString_pLogAttr(
  1569.     SCRIPT_STRING_ANALYSIS   ssa); 
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576. /////   ScriptStringGetOrder
  1577. //
  1578. //      Creates an array mapping original character position to glyph position.
  1579. //
  1580. //      Treats clusters as they were in legacy systems - Unless a cluster
  1581. //      contains more glyphs than codepoints, each glyph is referenced at
  1582. //      least once from the puOrder array.
  1583. //
  1584. //      Requires SSA_GLYPHS requested in original ScriptStringAnalyse call.
  1585. //
  1586. //      The puOrder parameter should address a buffer containing room for
  1587. //      at least *ScriptString_pcOutChars(ssa) ints.
  1588.  
  1589.  
  1590. HRESULT WINAPI ScriptStringGetOrder(
  1591.     SCRIPT_STRING_ANALYSIS  ssa,
  1592.     UINT                    *puOrder); 
  1593.  
  1594.  
  1595.  
  1596.  
  1597.  
  1598.  
  1599. /////   ScriptStringCPtoX
  1600. //
  1601. //      Return x coordinate for leading or trailing edge of character icp.
  1602.  
  1603.  
  1604. HRESULT WINAPI ScriptStringCPtoX(
  1605.     SCRIPT_STRING_ANALYSIS  ssa,        //In  String analysis
  1606.     int                     icp,        //In  Caret character position
  1607.     BOOL                    fTrailing,  //In  Which edge of icp
  1608.     int                    *pX);        //Out Corresponding x offset
  1609.  
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615. /////   ScriptStringXtoCP
  1616. //
  1617. //
  1618.  
  1619.  
  1620. HRESULT WINAPI ScriptStringXtoCP(
  1621.     SCRIPT_STRING_ANALYSIS  ssa,            // In
  1622.     int                     iX,             // In
  1623.     int                    *piCh,           // Out
  1624.     int                    *piTrailing);    // Out
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631. /////   ScriptStringGetLogicalWidths
  1632. //
  1633. //      Converts visual withs in psa->piAdvance into logical widths,
  1634. //      one per original character, in logical order.
  1635. //
  1636. //      Requires SSA_GLYPHS requested in original ScriptStringAnalyse call.
  1637. //
  1638. //      The piDx parameter should address a buffer containing room for
  1639. //      at least *ScriptString_pcOutChars(ssa) ints.
  1640.  
  1641.  
  1642. HRESULT WINAPI ScriptStringGetLogicalWidths(
  1643.     SCRIPT_STRING_ANALYSIS  ssa,
  1644.     int                    *piDx); 
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651. /////   ScriptStringValidate
  1652. //
  1653. //      Scans the string analysis for invalid glyphs.
  1654. //
  1655. //      Only glyphs generated by scripts that can generate invalid glyphs
  1656. //      are scanned.
  1657. //
  1658. //      returns S_OK    - no invalid glyphs are present
  1659. //              S_FALSE - one or more invalid glyphs are present
  1660.  
  1661.  
  1662. HRESULT WINAPI ScriptStringValidate(
  1663.     SCRIPT_STRING_ANALYSIS ssa); 
  1664.  
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670. /////   ScriptStringOut
  1671. //
  1672. //      Displays the string generated by a prior ScriptStringAnalyze call,
  1673. //      then optionally adds highlighting corresponding to a logical selection.
  1674. //
  1675. //      Requires SSA_GLYPHS requested in original ScriptStringAnalyse call.
  1676.  
  1677.  
  1678. HRESULT WINAPI ScriptStringOut(
  1679.     SCRIPT_STRING_ANALYSIS ssa,         //In  Analysis with glyphs
  1680.     int              iX,                //In
  1681.     int              iY,                //In
  1682.     UINT             uOptions,          //In  ExtTextOut options
  1683.     const RECT      *prc,               //In  Clipping rectangle (iff ETO_CLIPPED)
  1684.     int              iMinSel,           //In  Logical selection. Set iMinSel>=iMaxSel for no selection
  1685.     int              iMaxSel,           //In
  1686.     BOOL             fDisabled);        //In  If disabled, only the background is highlighted.
  1687.  
  1688.  
  1689.  
  1690.  
  1691.  
  1692.  
  1693. /////
  1694. //      uOptions may nclude only ETO_CLIPPED or ETO_OPAQUE.
  1695. /////   ScriptIsComplex
  1696. //
  1697. //      Determines whether a Unicode string requires complex script processing
  1698. //
  1699. //      The dwFlags parameter may include the following requests
  1700. //
  1701. #define SIC_COMPLEX     1   // Treat complex script letters as complex
  1702. #define SIC_ASCIIDIGIT  2   // Treat digits U+0030 through U+0039 as complex
  1703. #define SIC_NEUTRAL     4   // Treat neutrals as complex
  1704. //
  1705. //      SIC_COMPLEX: Should normally set. Causes complex script letters to
  1706. //      be treated as complex.
  1707. //
  1708. //      SIC_ASCIIDIGIT: Set this flag if the string would be displayed with
  1709. //      digit substitution enabled. If you are following the users NLS
  1710. //      settings using the ScriptRecordDigitSubstitution API, you can pass
  1711. //      scriptDigitSubstitute.DigitSubstitute != SCRIPT_DIGITSUBSTITUTE_NONE.
  1712. //
  1713. //      SIC_NEUTRAL: Set this flag if you may be displaying the string with
  1714. //      right-to-left reading order. When this flag is set, neutral characters
  1715. //      are considered as complex.
  1716. //
  1717. //
  1718. //      Returns S_OK     if string requires complex script processing,
  1719. //              S_FALSE  if string contains only characters laid out side by
  1720. //                       side from left to right.
  1721.  
  1722.  
  1723. HRESULT WINAPI ScriptIsComplex(
  1724.     const WCHAR     *pwcInChars,        //In  String to be tested
  1725.     int              cInChars,          //In  Length in characters
  1726.     DWORD            dwFlags);          //In  Flags (see above)
  1727.  
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733. /////   ScriptRecordDigitSubstitution
  1734. //
  1735. //      Reads NLS native digit and digit substitution settings and records
  1736. //      them in the SCRIPT_DIGITSUBSTITUTE structure.
  1737. //
  1738. //
  1739. typedef struct tag_SCRIPT_DIGITSUBSTITUTE {
  1740.     DWORD  NationalDigitLanguage    :16;   // Language for native substitution
  1741.     DWORD  TraditionalDigitLanguage :16;   // Language for traditional substitution
  1742.     DWORD  DigitSubstitute          :8;    // Substitution type
  1743.     DWORD  dwReserved;                     // Reserved
  1744. } SCRIPT_DIGITSUBSTITUTE;
  1745. //
  1746. //
  1747. //p     NationalDigitLanguage: Standard digits for the selected locale as
  1748. //          defined by the countries standard setting authority.
  1749. //
  1750. //p     TraditionalDigitLangauge: Digits originally used with the locales
  1751. //          script.
  1752. //
  1753. //p     DigitSubstitute: Selects between None, Context, National and
  1754. //          Traditional. See ScriptApplyDigitSubstitution below for
  1755. //          constant definitions.
  1756. //
  1757. //      Although most complex scripts have their own associated digits, many
  1758. //      countries using those scripts use western (so called
  1759. //      'Arabic') digits as their standard. NationalDigitLanguage reflects the
  1760. //      digits used as standard, and is set from
  1761. //      the NLS data for the locale.
  1762. //      On Windows 2000 the national digit langauge can be
  1763. //      adjusted to any digit script with the control panel/regional
  1764. //      options/numbers/Standard digits listbox.
  1765. //
  1766. //      The TraditionalDigitLanguage for a locale is derived directly from the
  1767. //      script used by that locale.
  1768.  
  1769.  
  1770. HRESULT WINAPI ScriptRecordDigitSubstitution(
  1771.     LCID                     Locale,    // In   LOCALE_USER_DEFAULT or desired locale
  1772.     SCRIPT_DIGITSUBSTITUTE  *psds);     // Out  Digit substitution settings
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779. /////
  1780. //p     Locale: NLS locale to be queried. Should usually be set to
  1781. //          LOCALE_USER_DEFAULT. Alternatively may be passed as a locale
  1782. //          combined with LOCALE_NOUSEROVERRIDE to obtain default settings
  1783. //          for a given locale. Note that context digit substitution is
  1784. //          supported only in ARABIC and FARSI locales. In other locales,
  1785. //          context digit is mapped to no substitution.
  1786. //
  1787. //p     psds: Pointer to SCRIPT_DIGITSUBSTITUTE. This structure may be passed
  1788. //          later to ScriptApplyDigitSubstitution.
  1789. //
  1790. //p     returns: E_INVALIDARG if Locale is invalid or not installed. E_POINTER
  1791. //          if psds is NULL. Otherwise S_OK.
  1792. //
  1793. //      For performance reasons, you should not call
  1794. //      ScriptRecordDigitSubstitution frequently. In particular it would be a
  1795. //      considerable overhead to call it every time you call ScriptItemize
  1796. //      or ScriptStringAnalyse.
  1797. //
  1798. //      Instead, you may choose to save the SCRIPT_DIGITSUBSTITUTE
  1799. //      structure, and update it only when you receive a
  1800. //      WM_SETTINGCHANGE message or when a RegNotifyChangeKeyValue
  1801. //      call in a dedicated thread indicates a change in the registry
  1802. //      under HKCU\Control Panel\\International.
  1803. //
  1804. //      The normal way to call this function is simply
  1805. //
  1806. //c     SCRIPT_DIGITSUBSTITUTE sds;
  1807. //c     ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT, &sds);
  1808. //
  1809. //      Then every time you itemize, you'd use the results like this:
  1810. //
  1811. //c     SCRIPT_CONTROL  sc = {0};
  1812. //c     SCRIPT_STATE    ss = {0};
  1813. //
  1814. //c     ScriptApplyDigitSubstitution(&sds, &sc, &ss);
  1815. //
  1816. //
  1817. /////   ScriptApplyDigitSubstitution
  1818. //
  1819. //      Aplies the digit substitution settings recorded in a
  1820. //      SCRIPT_DIGIT_SUBSTITUTE structure to the SCRIPT_CONTROL and
  1821. //      SCRIPT_STATE structures.
  1822. //
  1823. //      The DigitSubstitute field of the SCRIPT_DIGITSUBSTITUTE structure
  1824. //      is normally set by ScriptRecordDigitSubstitution, however it may
  1825. //      be replaced by any one of the following values:
  1826. //
  1827. //
  1828. #define SCRIPT_DIGITSUBSTITUTE_CONTEXT      0  // Substitute to match preceeding letters
  1829. #define SCRIPT_DIGITSUBSTITUTE_NONE         1  // No substitution
  1830. #define SCRIPT_DIGITSUBSTITUTE_NATIONAL     2  // Substitute with official national digits
  1831. #define SCRIPT_DIGITSUBSTITUTE_TRADITIONAL  3  // Substitute with traditional digits of the locale
  1832. //
  1833. //
  1834. //p     SCRIPT_DIGITSUBSTITUTE_CONTEXT: Digits U+0030 - U+0039 will be
  1835. //          substituted according to the language of prior letters. Before
  1836. //          any letters, digits will be substituted according to the
  1837. //          TraditionalDigitLangauge field of the SCRIPT_DIGIT_SUBSTITUTE
  1838. //          structure. This field is normally set to the primary language of
  1839. //          the Locale passed to ScriptRecordDigitSubstitution.
  1840. //
  1841. //p     SCRIPT_DIGITSUBSTITUTE_NONE: Digits will not be substituted. Unicode
  1842. //          values U+0030 to U+0039 will be displayed with Arabic (i.e.
  1843. //          Western) numerals.
  1844. //
  1845. //p     SCRIPT_DIGITSUBSTITUTE_NATIONAL: Digits U+0030 - U+0039 will be
  1846. //          substituted according to the NationalDigitLangauge field of
  1847. //          the SCRIPT_DIGIT_SUBSTITUTE structure. This field is normally
  1848. //          set to the national digits returned for the NLS LCTYPE
  1849. //          LOCALE_SNATIVEDIGITS by ScriptRecordDigitSubstitution.
  1850. //
  1851. //p     SCRIPT_DIGITSUBSTITUTE_TRADITIONAL: Digits U+0030 - U+0039 will be
  1852. //          substituted according to the TraditionalDigitLangauge field of
  1853. //          the SCRIPT_DIGIT_SUBSTITUTE structure. This field is normally
  1854. //          set to the primary language of the Locale passed to
  1855. //          ScriptRecordDigitSubstitution.
  1856.  
  1857.  
  1858. HRESULT WINAPI ScriptApplyDigitSubstitution(
  1859.     const SCRIPT_DIGITSUBSTITUTE  *psds,   // In   Digit substitution settings
  1860.     SCRIPT_CONTROL                *psc,    // Out  Script control structure
  1861.     SCRIPT_STATE                  *pss);   // Out  Script state structure
  1862.  
  1863.  
  1864.  
  1865.  
  1866.  
  1867.  
  1868. /////
  1869. //p     psds: Pointer to SCRIPT_DIGITSUBSTITUTE structure recorded earlier.
  1870. //          If NULL, ScriptApplyDigitSubstitution calls
  1871. //          ScriptRecordDigitSubstitution with LOCALE_USER_DEFAULT.
  1872. //
  1873. //p     psc: SCRIPT_CONTROL structure. The fContextDigits and uDefaultLanguage
  1874. //          fields will be updated.
  1875. //
  1876. //p     pss: SCRIPT_CONTROL structure. The fDigitSubstitute field will be
  1877. //          updated.
  1878. //
  1879. //p     returns: E_INVALIDARG if the DigitSubstitute field of the
  1880. //          SCRIPT_DIGITSUBSTITUTE structure is unrecognised, else S_OK;
  1881. #ifdef __cplusplus
  1882. }
  1883. #endif
  1884. #pragma option pop /*P_O_Pop*/
  1885. #endif
  1886.