SetTextJustification function (wingdi.h)

The SetTextJustification function specifies the amount of space the system should add to the break characters in a string of text. The space is added when an application calls the TextOut or ExtTextOut functions.

Syntax

BOOL SetTextJustification(
  [in] HDC hdc,
  [in] int extra,
  [in] int count
);

Parameters

[in] hdc

A handle to the device context.

[in] extra

The total extra space, in logical units, to be added to the line of text. If the current mapping mode is not MM_TEXT, the value identified by the nBreakExtra parameter is transformed and rounded to the nearest pixel.

[in] count

The number of break characters in the line.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.

Remarks

The break character is usually the space character (ASCII 32), but it may be defined by a font as some other character. The GetTextMetrics function can be used to retrieve a font's break character.

The TextOut function distributes the specified extra space evenly among the break characters in the line.

The GetTextExtentPoint32 function is always used with the SetTextJustification function. Sometimes the GetTextExtentPoint32 function takes justification into account when computing the width of a specified line before justification, and sometimes it does not. For more details on this, see GetTextExtentPoint32. This width must be known before an appropriate nBreakExtra value can be computed.

SetTextJustification can be used to justify a line that contains multiple strings in different fonts. In this case, each string must be justified separately.

Because rounding errors can occur during justification, the system keeps a running error term that defines the current error value. When justifying a line that contains multiple runs, GetTextExtentPoint automatically uses this error term when it computes the extent of the next run, allowing TextOut to blend the error into the new run. After each line has been justified, this error term must be cleared to prevent it from being incorporated into the next line. The term can be cleared by calling SetTextJustification with nBreakExtra set to zero.

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header wingdi.h (include Windows.h)
Library Gdi32.lib
DLL Gdi32.dll

See also

ExtTextOut

Font and Text Functions

Fonts and Text Overview

GetTextExtentPoint32

GetTextMetrics

TextOut