CDC::SetTextJustification

Adds space to the break characters in a string.

int SetTextJustification(
   int nBreakExtra,
   int nBreakCount 
);

Параметры

  • nBreakExtra
    Specifies the total extra space to be added to the line of text (in logical units). If the current mapping mode is not MM_TEXT, the value given by this parameter is converted to the current mapping mode and rounded to the nearest device unit.

  • nBreakCount
    Specifies the number of break characters in the line.

Возвращаемое значение

One if the function is successful; otherwise 0.

Заметки

An application can use the GetTextMetrics member functions to retrieve a font's break character.

After the SetTextJustification member function is called, a call to a text-output function (such as TextOut) distributes the specified extra space evenly among the specified number of break characters. The break character is usually the space character (ASCII 32), but may be defined by a font as some other character.

The member function GetTextExtent is typically used with SetTextJustification. GetTextExtent computes the width of a given line before alignment. An application can determine how much space to specify in the nBreakExtra parameter by subtracting the value returned by GetTextExtent from the width of the string after alignment.

The SetTextJustification function can be used to align a line that contains multiple runs in different fonts. In this case, the line must be created piecemeal by aligning and writing each run separately.

Because rounding errors can occur during alignment, the system keeps a running error term that defines the current error. When aligning a line that contains multiple runs, GetTextExtent automatically uses this error term when it computes the extent of the next run. This allows the text-output function to blend the error into the new run.

After each line has been aligned, 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 0.

Требования

Header: afxwin.h

См. также

Основные понятия

CDC Class

CDC Members

Hierarchy Chart

CDC::GetMapMode

CDC::GetTextExtent

CDC::GetTextMetrics

CDC::SetMapMode

CDC::TextOut

SetTextJustification