ScriptShapeOpenType function (usp10.h)

Generates glyphs and visual attributes for a Unicode run with OpenType information. Each run consists of one call to this function.

Syntax

HRESULT ScriptShapeOpenType(
  [in, optional] HDC                  hdc,
  [in, out]      SCRIPT_CACHE         *psc,
  [in, out]      SCRIPT_ANALYSIS      *psa,
  [in]           OPENTYPE_TAG         tagScript,
  [in]           OPENTYPE_TAG         tagLangSys,
  [in, optional] int                  *rcRangeChars,
  [in, optional] TEXTRANGE_PROPERTIES **rpRangeProperties,
  [in]           int                  cRanges,
  [in]           const WCHAR          *pwcChars,
  [in]           int                  cChars,
  [in]           int                  cMaxGlyphs,
  [out]          WORD                 *pwLogClust,
  [out]          SCRIPT_CHARPROP      *pCharProps,
  [out]          WORD                 *pwOutGlyphs,
  [out]          SCRIPT_GLYPHPROP     *pOutGlyphProps,
  [out]          int                  *pcGlyphs
);

Parameters

[in, optional] hdc

Handle to the device context. For more information, see Caching.

[in, out] psc

Pointer to a SCRIPT_CACHE structure identifying the script cache.

[in, out] psa

Pointer to a SCRIPT_ANALYSIS structure obtained from a previous call to ScriptItemizeOpenType. The structure identifies the shaping engine, so that glyphs can be formed correctly.

Alternatively, the application can set this parameter to NULL to receive unfiltered results.

[in] tagScript

An OPENTYPE_TAG structure defining the OpenType script tag for the writing system.

[in] tagLangSys

An OPENTYPE_TAG structure containing the OpenType language tag for the writing system.

[in, optional] rcRangeChars

Array of characters in each range. The number of array elements is indicated by cRanges. The values of the elements of this array add up to the value of cChars.

[in, optional] rpRangeProperties

Array of TEXTRANGE_PROPERTIES structures, each representing one OpenType feature range. The number of structures is indicated by the cRanges parameter. For more information on rpRangeProperties, see the Remarks section.

[in] cRanges

The number of OpenType feature ranges.

[in] pwcChars

Pointer to an array of Unicode characters containing the run.

[in] cChars

Number of characters in the Unicode run.

[in] cMaxGlyphs

Maximum number of glyphs to generate.

[out] pwLogClust

Pointer to a buffer in which this function retrieves an array of logical cluster information. Each array element corresponds to a character in the array of Unicode characters. The value of each element is the offset from the first glyph in the run to the first glyph in the cluster containing the corresponding character. Note that, when the fRTL member of the SCRIPT_ANALYSIS structure is TRUE, the elements decrease as the array is read.

[out] pCharProps

Pointer to a buffer in which this function retrieves an array of character property values, of length indicated by cChars.

[out] pwOutGlyphs

Pointer to a buffer in which this function retrieves an array of glyphs.

[out] pOutGlyphProps

Pointer to a buffer in which this function retrieves an array of attributes for each of the retrieved glyphs. The length of the values equals the value of pcGlyphs. Since one glyph property is indicated per glyph, the value of this parameter indicates the number of elements specified by cMaxGlyphs.

[out] pcGlyphs

Pointer to the location in which this function retrieves the number of glyphs indicated in pwOutGlyphs.

Return value

Returns 0 if successful. The function returns a nonzero HRESULT value if it does not succeed. In all error cases, the content of all output array values is undefined.

Error returns include:

  • E_OUTOFMEMORY. The output buffer length indicated by cMaxGlyphs is insufficient.
  • E_PENDING. The script cache specified by the psc parameter does not contain enough information to shape the string, and the device context has been passed as NULL so that the function is unable to complete the shaping process. The application should set up a correct device context for the run and call this function again with the appropriate context value in hdc and with all other parameters the same.
  • USP_E_SCRIPT_NOT_IN_FONT. The font corresponding to the device context does not support the required script. The application should choose another font, using either ScriptGetCMap or another method to select the font.

Remarks

ScriptShapeOpenType is preferred over the older ScriptShape function. Some advantages of the ScriptShapeOpenType include the following:

  • Parameters directly correspond to OpenType tags in font layout tables.
  • Parameters define features applied to each character.
  • Input is divided into runs. Each run has OpenType properties and consists of a single call to ScriptShapeOpenType.
If this function returns E_OUTOFMEMORY, the application might call ScriptShapeOpenType repeatedly, with successively larger output buffers, until a large enough buffer is provided. The number of glyphs generated by a code point varies according to the script and the font. For a simple script, a Unicode code point might generate a single glyph. However, a complex script font might construct characters from components, and thus generate several times as many glyphs as characters. Also, there are special cases, such as invalid character representations, in which extra glyphs are added to represent the invalid sequence. Therefore, a reasonable guess for the size of the buffer indicated by pwOutGlyphs is 1.5 times the length of the character buffer, plus an additional 16 glyphs for rare cases, for example, invalid sequence representation.

This function can set the fNoGlyphIndex member of the SCRIPT_ANALYSIS structure if the font or operating system cannot support glyph indexes.

The application can call ScriptShapeOpenType to determine if a font supports the characters in a given string. If the function returns S_OK, the application should check the output for missing glyphs. If fLogicalOrder is set to TRUE in the SCRIPT_ANALYSIS structure, the function always generates glyphs in the same order as the original Unicode characters. If fLogicalOrder is set to FALSE, the function generates right-to-left items in reverse order so that ScriptTextOut does not have to reverse them before calling ExtTextOut.

If the eScript member of SCRIPT_ANALYSIS is set to SCRIPT_UNDEFINED, shaping is disabled. In this case, ScriptShapeOpenType displays the glyph that is in the font cmap table. If no glyph is in the table, the function indicates that glyphs are missing.

ScriptShapeOpenType sequences clusters uniformly within the run, and sequences glyphs uniformly within a cluster. It uses the value of the fRTL member of SCRIPT_ANALYSIS, from ScriptItemizeOpenType, to identify if sequencing is left-to-right or right-to-left.

For the rpRangeProperties parameter, the TEXTRANGE_PROPERTIES structure points to an array of OPENTYPE_FEATURE_RECORD structures. This array is used as follows:

  • Each element of the array indicated for rpRangeProperties describes a range.
  • Spans of text sharing particular properties tend to "nest," and nested spans can share OPENTYPE_FEATURE_RECORD information. For example, in the illustration below:
    • The rows of numbers at the top represent ranges, items, and runs, respectively.
    • Each span labeled here with a letter represents a single OpenType feature. The features that fall into each range are stored in the OPENTYPE_FEATURE_RECORD array of that range.
    • For each range, the array of OPENTYPE_FEATURE_RECORD structures corresponds to the letters for the spans that contain that range.
    • In this illustration, range 2 is indirectly associated with the OPENTYPE_FEATURE_RECORD structures for spans A, B, and C. Range 4 is associated only with the structures for spans A and D.
Illustration showing the range, item, run, and feature of each word in a line of text that uses six properties to present eight words
Note  The illustration makes use of many calls to ScriptShapeOpenType, each representing one run.
 
Important  Starting with Windows 8: To maintain the ability to run on Windows 7, a module that uses Uniscribe must specify Usp10.lib before gdi32.lib in its library list.
 

Examples

The following example shows how ScriptShapeOpenType generates a logical cluster array (pwLogClust) from a character array (pwcChars) and a glyph array (pwOutGlyphs). The run has four clusters.

  • First cluster: one character represented by one glyph
  • Second cluster: one character represented by three glyphs
  • Third cluster: three characters represented by one glyph
  • Fourth cluster: two characters represented by three glyphs
The run is described as follows in the character and glyph arrays.

Character array:

  • | c1u1 | c2u1 | c3u1 c3u2 c3u3 | c4u1 c4u2 |
Glyph array:
  • | c1g1 | c2g1 c2g2 c2g3 | c3g1 | c4g1 c4g2 c4g3 |
Notation for the array elements consists of these items:
  • c<n> means cluster n.
  • g<m> means glyph m.
  • u<p> means Unicode code point p.
The generated cluster array stores offsets to the cluster containing the character. Units are expressed in glyphs.
  • | 0 | 1 | 4 4 4 | 5 5 |

Requirements

Requirement Value
Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2008 [desktop apps only]
Target Platform Windows
Header usp10.h
Library Usp10.lib
DLL Usp10.dll
Redistributable Usp10.dll version 1.600 or greater on Windows XP

See also

Displaying Text with Uniscribe

OPENTYPE_FEATURE_RECORD

SCRIPT_ANALYSIS

ScriptItemizeOpenType

ScriptPlaceOpenType

ScriptShape

ScriptTextOut

TEXTRANGE_PROPERTIES

Uniscribe Functions