IDWriteTextLayout::SetFontWeight method (dwrite.h)

Sets the font weight for text within a text range specified by a DWRITE_TEXT_RANGE structure.

Syntax

HRESULT SetFontWeight(
  DWRITE_FONT_WEIGHT fontWeight,
  DWRITE_TEXT_RANGE  textRange
);

Parameters

fontWeight

Type: DWRITE_FONT_WEIGHT

The font weight to be set for text within the range specified by textRange.

textRange

Type: DWRITE_TEXT_RANGE

Text range to which this change applies.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

The font weight can be set to one of the predefined font weight values provided in the DWRITE_FONT_WEIGHT enumeration or an integer from 1 to 999. Values outside this range will cause the method to fail with an E_INVALIDARG return value.

The following illustration shows an example of Normal and UltraBold weights for the Palatino Linotype typeface.

Illustration of the letter "W" in Normal and UltraBold weights

Examples

The following code illustrates how to set the font weight to bold.


// Set the font weight to bold for the entire string.
DWRITE_TEXT_RANGE textRange = {0, cTextLength_};

if (SUCCEEDED(hr))
{
    hr = pTextLayout_->SetFontWeight(DWRITE_FONT_WEIGHT_BOLD, textRange);
}


Requirements

Requirement Value
Minimum supported client Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header dwrite.h
Library Dwrite.lib
DLL Dwrite.dll

See also

IDWriteTextLayout