DirectWrite API Reference

Interfaces

Core interfaces for interacting with DirectWrite functionality.

IDWriteFactory

interface IDWriteFactory : IUnknown

The main entry point for the DirectWrite API. Used to create various DirectWrite objects.

Methods:
  • CreateTextLayout(...)
  • GetGdiInterop(...)
  • CreateFontCollectionFromFile(...)

IDWriteFontCollection

interface IDWriteFontCollection : IUnknown

Represents a collection of fonts, such as those installed on the system.

IDWriteFont

interface IDWriteFont : IUnknown

Represents a single font in a font family.

IDWriteFontFamily

interface IDWriteFontFamily : IUnknown

Represents a font family, which is a collection of fonts that share a common family name.

IDWriteFontFace

interface IDWriteFontFace : IUnknown

Represents a specific face of a font, allowing access to glyph metrics and other font face properties.

IDWriteGlyphRun

interface IDWriteGlyphRun : IUnknown

Represents a contiguous run of glyphs with the same font face, size, and orientation.

IDWriteGlyphRunAnalysis

interface IDWriteGlyphRunAnalysis : IUnknown

Provides detailed analysis of a glyph run, including glyph placement and shaping results.

IDWriteTextAnalyzer

interface IDWriteTextAnalyzer : IUnknown

Performs text analysis, including script analysis, line breaking, and glyph shaping.

IDWriteTextAnalysis

interface IDWriteTextAnalysis : IUnknown

Represents the results of text analysis, such as script properties and text boundaries.

IDWriteTextCompositor

interface IDWriteTextCompositor : IUnknown

Composes glyphs into lines of text, handling layout and line breaking.

IDWriteTextLayout

interface IDWriteTextLayout : IUnknown

Represents a piece of text with associated layout properties, such as paragraph alignment, font properties, and trimming.

IDWriteTextRenderer

interface IDWriteTextRenderer : IUnknown

An interface implemented by applications to receive drawing commands for text rendering.

IDWriteTextMetrics

interface IDWriteTextMetrics : IUnknown

Contains text layout metrics, such as width, height, and line spacing.

IDWriteLayoutMetrics

interface IDWriteLayoutMetrics : IUnknown

Contains detailed metrics for a text layout, including text bounds and line metrics.

IDWriteInlineObject

interface IDWriteInlineObject : IUnknown

Represents an inline object within text, such as an image or a custom element.

IDWriteColorFont

interface IDWriteColorFont : IUnknown

Represents a font that includes color glyphs.

IDWriteColorFontSet

interface IDWriteColorFontSet : IUnknown

Represents a set of color fonts.

Structs

Data structures used by DirectWrite APIs.

DWRITE_MATRIX

typedef struct DWRITE_MATRIX { FLOAT M11, M12, M21, M22, DX, DY; } DWRITE_MATRIX;

Represents a 3x2 transformation matrix for 2D graphics.

DWRITE_RECT

typedef struct DWRITE_RECT { FLOAT left, top, right, bottom; } DWRITE_RECT;

Represents a rectangle using coordinates of its top-left and bottom-right corners.

DWRITE_FONT_METRICS

typedef struct DWRITE_FONT_METRICS { UINT16 designUnitsPerEm; UINT16 ascent; UINT16 descent; UINT16 lineGap; UINT16 capHeight; UINT16 xHeight; INT16 underlinePosition; UINT16 underlineThickness; INT16 strikethroughPosition; UINT16 strikethroughThickness; } DWRITE_FONT_METRICS;

Contains font-wide metrics that apply to all glyphs in the font.

DWRITE_GLYPH_OFFSET

typedef struct DWRITE_GLYPH_OFFSET { FLOAT dx; FLOAT dy; } DWRITE_GLYPH_OFFSET;

Specifies an offset to apply to a glyph's position.

DWRITE_TEXT_RANGE

typedef struct DWRITE_TEXT_RANGE { UINT32 start; UINT32 length; } DWRITE_TEXT_RANGE;

Specifies a range of text by its starting character index and length.

DWRITE_GLYPH_RUN

typedef struct DWRITE_GLYPH_RUN { IDWriteFontFace* fontFace; FLOAT fontEmSize; UINT32 glyphCount; const UINT16* glyphIndices; FLOAT* glyphAdvances; const DWRITE_GLYPH_OFFSET* glyphOffsets; BOOL isSideways; int bidiLevel; } DWRITE_GLYPH_RUN;

Describes a run of glyphs to be rendered.

DWRITE_LINE_PARAGRAPH

typedef struct DWRITE_LINE_PARAGRAPH { FLOAT line_height; FLOAT paragraph_spacing; } DWRITE_LINE_PARAGRAPH;

Represents metrics for line height and paragraph spacing.

Enums

Enumerated types for various DirectWrite properties.

DWRITE_FONT_WEIGHT

enum DWRITE_FONT_WEIGHT { DWRITE_FONT_WEIGHT_THIN = 100, DWRITE_FONT_WEIGHT_EXTRA_LIGHT = 200, // ... other weights DWRITE_FONT_WEIGHT_NORMAL = 400, DWRITE_FONT_WEIGHT_BOLD = 700, DWRITE_FONT_WEIGHT_BLACK = 900 };

Specifies the boldness of a font.

DWRITE_FONT_STRETCH

enum DWRITE_FONT_STRETCH { DWRITE_FONT_STRETCH_ULTRA_CONDENSED = 50, DWRITE_FONT_STRETCH_EXTRA_CONDENSED = 62, // ... other stretches DWRITE_FONT_STRETCH_NORMAL = 100, DWRITE_FONT_STRETCH_EXTRA_EXPANDED = 150, DWRITE_FONT_STRETCH_ULTRA_EXPANDED = 200 };

Specifies the degree of condensation or expansion of a font.

DWRITE_FONT_STYLE

enum DWRITE_FONT_STYLE { DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STYLE_OBLIQUE, DWRITE_FONT_STYLE_ITALIC };

Specifies the style of a font (normal, italic, or oblique).

DWRITE_GLYPH_ORIENTATION

enum DWRITE_GLYPH_ORIENTATION { DWRITE_GLYPH_ORIENTATION_HORIZONTAL, DWRITE_GLYPH_ORIENTATION_VERTICAL };

Specifies the orientation of a glyph run.

DWRITE_TEXT_ALIGNMENT

enum DWRITE_TEXT_ALIGNMENT { DWRITE_TEXT_ALIGNMENT_LEFT, DWRITE_TEXT_ALIGNMENT_CENTER, DWRITE_TEXT_ALIGNMENT_RIGHT, DWRITE_TEXT_ALIGNMENT_JUSTIFY };

Specifies the horizontal alignment of text within a line.

DWRITE_PARAGRAPH_ALIGNMENT

enum DWRITE_PARAGRAPH_ALIGNMENT { DWRITE_PARAGRAPH_ALIGNMENT_NEAR, DWRITE_PARAGRAPH_ALIGNMENT_CENTER, DWRITE_PARAGRAPH_ALIGNMENT_FAR };

Specifies the vertical alignment of paragraphs within the layout box.

Functions

Top-level functions for DirectWrite.

DWriteCreateFactory

HRESULT DWriteCreateFactory( DWRITE_FACTORY_TYPE factoryType, REFIID iid, IUnknown** factory );

Creates an instance of the DirectWrite factory.

Parameters:
factoryType: DWRITE_FACTORY_TYPE - Specifies the factory type (e.g., shared or isolated).
iid: REFIID - The interface ID of the factory to create.
factory: IUnknown** - A pointer to receive the factory object.
Return Value: HRESULT - Success or failure code.

DWriteGetFontParameters

HRESULT DWriteGetFontParameters( IDWriteFont* font, DWRITE_FONT_PARAMETERS** parameters );

Retrieves parameters for a given font.

Parameters:
font: IDWriteFont* - Pointer to the font object.
parameters: DWRITE_FONT_PARAMETERS** - Pointer to receive font parameters.
Return Value: HRESULT - Success or failure code.

DWriteCreateTextLayout

HRESULT DWriteCreateTextLayout( const WCHAR* string, UINT32 stringLength, IDWriteTextFormat* textFormat, FLOAT maxWidth, FLOAT maxHeight, IDWriteTextLayout** textLayout );

Creates a text layout object for measuring and drawing text.

Parameters:
string: const WCHAR* - The text string to lay out.
stringLength: UINT32 - The length of the text string.
textFormat: IDWriteTextFormat* - The text format to use.
maxWidth: FLOAT - The maximum width of the layout.
maxHeight: FLOAT - The maximum height of the layout.
textLayout: IDWriteTextLayout** - Pointer to receive the created text layout object.
Return Value: HRESULT - Success or failure code.