windowsgdiclippingdrawtext

Right aligned italic text drawn by DrawTextW is clipped on the right side


This code

procedure TForm1.Paint;
var
  r: TRect;
  txt: WideString;
begin
  inherited;
  r := Rect(0, 0, 200, 100);
  txt := 'Lorem ipsum dolor sit amet, consectetur ' +
    'adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore ' +
    'magna aliqua. Ut enim ad';
  DrawTextW(Canvas.Handle, PWideChar(txt), -1, {var} r, DT_RIGHT or DT_WORDBREAK);
end;

produces following output:

Clipped italic text

As you see, the right edge of the text is clipped. It is even worse with numeric characters.

For a single line text a workaround could be to add space character at the end, but for multiline automatically wrapped text there should be another solution, if any. It would be a chore to write text line-by line.

Could you give an advice how to make Windows draw whole letters?


Solution

  • Ok, adding DT_NOCLIP flag seems to solve this "issue".