DirectWrite API Reference

The DirectWrite API provides a high-quality, high-performance direct-write API for text rendering on Windows.

Core Interfaces

This section covers the fundamental interfaces used for text layout and rendering with DirectWrite.

IDWriteFactory

The factory object is the entry point for all DirectWrite operations. You use it to create other DirectWrite objects.

HRESULT CreateTextFormat( _In_opt_ PCWSTR fontName, _In_opt_ IDWriteFontCollection *fontCollection, _In_ DWRITE_FONT_WEIGHT fontWeight, _In_ DWRITE_FONT_STYLE fontStyle, _In_ DWRITE_FONT_STRETCH fontStretch, _In_ FLOAT fontSize, _In_opt_ PCWSTR localeName, _Out_ IDWriteTextFormat **textFormat );

Creates a text format object that contains font-related properties such as font face, weight, style, and size.

IDWriteTextLayout

Represents a block of text that has been fully analyzed for layout, including line breaks, word wrapping, and text effects.

HRESULT SetMaxTextWidth( _In_ FLOAT maxTextWidth );

Sets the maximum width of the text layout. Text will wrap to the next line if it exceeds this width.

IDWriteTextRenderer

An interface implemented by the application to receive drawing commands for text. This interface is used by IDWriteTextLayout::Draw.

Implementations typically involve methods like DrawGlyphRun, DrawUnderline, and DrawStrikethrough.

Key Concepts

  • Font Fallback: Mechanisms for handling characters that are not present in the requested font.
  • Text Analysis: The process of analyzing text for glyphs, formatting, and layout metrics.
  • Glyph Run: A contiguous sequence of characters that are represented by the same font face, size, and style.

Rendering and Layout

Explore the classes and methods involved in drawing text to the screen.

IDWriteTextAnalyzer

Provides services for text analysis, such as determining script analysis and locale-sensitive string comparison.

IDWritePixelSnapping

Interface for controlling pixel snapping behavior during text rendering.

IDWriteGlyphRunAnalysis

Represents the results of text analysis for a single glyph run.

Typography Features

Leverage advanced typographic features for richer text rendering.

IDWriteTypography

Interface for controlling OpenType typographic features like ligatures, stylistic sets, and alternates.

HRESULT SetCapitals( _In_ DWRITE_FONT_FEATURE_TAG featureTag, _In_ UINT32 value );

Configures font feature settings. For example, to enable small caps.

Related Topics