DrawText with clip on results in subsequent paint operations failing
Original Reporter info from Mantis: sekelsenmat
-
Reporter name: Felipe Monteiro de Carvalho
Original Reporter info from Mantis: sekelsenmat
- Reporter name: Felipe Monteiro de Carvalho
Description:
After many hours debugging I found that apparently the Cocoa function to save/restore DC doesn't save/restore the clip region, and subsequent paint operations outside the text area will fail.
Minimal test case to reproduce:
procedure TForm1.FormCreate(Sender: TObject);
begin
F_TreeListView := TBitmap.Create;
F_TreeListView.SetSize(400, 400);
end;
procedure TForm1.FormPaint(Sender: TObject);
var
F_StripedOddColor, F_StripedEvenColor: TColor;
temp: TRect;
flags: longint;
lStr: string = '10 - 0 = 10';
begin
F_StripedOddColor := clWindow;
F_StripedEvenColor := $00E0FFFF;
F_TreeListView.canvas.Brush.Color := F_StripedEvenColor;
F_TreeListView.Canvas.FillRect(rect(0,20,F_TreeListView.width,40));
flags := DT_NOPREFIX or DT_SINGLELINE or DT_VCENTER or DT_END_ELLIPSIS or DT_LEFT;
temp := Rect(170, 18, 270, 34);
LCLIntf.DrawText(F_TreeListView.canvas.Handle, PChar(lStr), length(lStr), temp, flags);
// The operations bellow will not paint
F_TreeListView.canvas.Brush.Color := F_StripedOddColor;
F_TreeListView.Canvas.FillRect(rect(0,40,F_TreeListView.width,60));
F_TreeListView.canvas.Brush.Color := F_StripedEvenColor;
F_TreeListView.Canvas.FillRect(rect(0,60,F_TreeListView.width,80));
Canvas.Draw(0, 0, F_TreeListView);
end;
This appeared in TreeListView as only the first line being painted.
Mantis conversion info:
- Mantis ID: 28015
- Fixed in version: 1.5 (SVN)
- Fixed in revision: 48917 (#c9dce2ea)