[Lazarus] Text height calculation Linux-Qt vs Windows

Gabor Boros gaborboros at yahoo.com
Wed Jul 27 12:30:29 CEST 2016


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 H1<>H2 then Beep;
end;

Gabor


More information about the Lazarus mailing list