I am having an issue with the TextRect function. Not sure if it is me or a bug in FPC.
Lazarus 4.99 (rev main_4_99-813-g9eb9286e45) FPC 3.3.1 x86_64-linux-qt5
Free Pascal Compiler version 3.3.1-17259-g904c25745c-dirty [2025/01/09] for x86_64
I am drawing rectangles then text to a TBitmap - here is a minimal example:
procedure TForm1.FormShow(Sender: TObject);
var
bmpGrid: TBitmap;
cols, rows, boxw, boxh: Integer;
canvasTextStyle: TTextStyle;
boxRect: TRect;
begin
bmpGrid := TBitmap.Create;
bmpGrid.Width := 1200;
bmpGrid.Height := 1200;
with bmpGrid.Canvas do
begin
Clear;
Pen.Width := 1;
Pen.Style := psInsideframe;
Font.Color := clWhite;
canvasTextStyle := TextStyle;
canvasTextStyle.Opaque := False;
boxw := bmpGrid.Width div 6;
boxh := bmpGrid.Height div 6;
for rows := 0 to 5 do
for cols := 0 to 5 do
begin
Brush.Color := RGBToColor(Random(127),Random(127),Random(127));
Pen.Color := RGBToColor(Random(127),Random(127),Random(127));
boxRect := Rect(cols*boxw, rows*boxh, cols*boxw+boxw, rows*boxh+boxh);
Rectangle(boxRect);
Inc(boxRect.Left,8);
Dec(boxRect.Right,8);
Inc(boxRect.Top,8);
Dec(boxRect.Bottom,8);
TextRect(boxRect,0,0,'hello',canvasTextStyle);
end;
end;
bmpGrid.SaveToFile('/tmp/canvas.bmp');
end;
The attachments show when compiling to linux gtk2 and qt5 with compiler optimization level set to -O1 and -O2 as per the filename.
You can see varied results. One out if the four seems correct but if I add more draw commands then it fails too.
Is this something that I need to report as a bug (if so then please provide details on the procedure) or am I doing things wrong?