Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-07

Text height calculation Linux-Qt vs Windows

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Gabor Boros

Hi All,

I need to calculate the height of the displayed text line by line. But got different result than whole text height. With Windows the two result is same with Linux-Qt not.

I have a label with the next caption:
1
2
3
4
5
6

See the calculation code below. With Linux-Qt H1 differs from H2 for example with Open Sans Regular 9. And the autosized height of the above label on Windows is 102 and with Linux-Qt 97. Is this normal or a Linux-Qt bug?

procedure TForm1.FormCreate(Sender: TObject);
var
   R:TRect;
   H1:Integer;
   H2:Integer=0;
   i:Integer;
begin
   R:=Rect(0,0,0,0);
DrawText(Label1.Canvas.Handle,PChar(Label1.Caption),Length(Label1.Caption),R,DT_CALCRECT);
   H1:=R.Bottom;
   Memo1.Text:=Label1.Caption;
   for i:=0 to Memo1.Lines.Count-1 do
    begin
      R:=Rect(0,0,0,0);
DrawText(Label1.Canvas.Handle,PChar(Memo1.Lines[i]),Length(Memo1.Lines[i]),R,DT_CALCRECT);
      Inc(H2,R.Bottom);
    end;
   if H1H2 then Beep;
end;

Gabor

Reply by email