DrawText clips bottom of text lazarus / 39-Graphics ---------------------------------------------------------------------- jipété · 2023-09-09 09:29 Hi, found a strange behaviour of DrawText, which clips the last line, see attached image. img_FormPaint2.png Problem better displayed if r2 is removed. img_without-r2.png Code is coming from https://itecnote.com/tecnote/delphi-calculating- size-of-text-before-drawing-to-a-canvas/, where we can see a nice window img_SourceDrawText.png , and adapted for Lazarus with Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {.$R *.dfm}{$R *.lfm}and adding   LCLIntf, LCLType, in the uses section (by the way, what to do to have a new project skeleton which always include these two units in the uses declaration ? Thx). 17 in the title bar is coming from : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     h := DrawText(Canvas.Handle,      PChar(S[i]),      Length(S[i]),      r,    Aligns[Odd(i)] or DT_WORDBREAK or DT_CALCRECT);    Caption := IntToStr(h);and I don't know what's happens, but the line "Glad to hear that!" is 15 px height... So the bottom of the "y" in the green top-right text is also broken. If I enlarge Form1, the second line of the first blue text is concerned, but less than third line when present. If I reduce Form1.Width, it's a disaster. img_four-lines.png (end of text in following post, due to number of images)... ---------------------------------------------------------------------- jipété · 2023-09-09 09:32 ...(end of text) If I reduce more and more, I lost a line in the big blue text : img_8lines-only7visible.png If I remove "or DT_WORDWRAP", al the lines are bottom-clipped, img_no-wordwrap.png Even the so simple first code of the page displays a broken text (last word is missing) : img_FormPaint1.png Thanks for the help. Debian Bullseye 11.7 64bits Gtk2 and FPC 3.2.2 Laz 2.2.6 Same problem with Laz 3.0RC1 +++ Codes, in case of http://404 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormPaint(Sender: TObject);const  S = 'This is a sample text, I think, is it not?';var  r: TRect;begin  r := Rect(10, 10, 60, 60);  DrawText(Canvas.Handle,    PChar(S),    Length(S),    r,    DT_LEFT or DT_WORDBREAK or DT_CALCRECT);   DrawText(Canvas.Handle,    PChar(S),  Length(S),    r,    DT_LEFT or DT_WORDBREAK);end; or Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormPaint(Sender: TObject);const  S: array[0..3] of string = ('Hi! How are you?',    'I am fine, thanks. How are you? How are your kids?',    'Fine!',    'Glad to hear that!');  Colors: array[boolean] of TColor = (clMoneyGreen, clSkyBlue);  Aligns: array[boolean] of integer = (DT_RIGHT, DT_LEFT);var  i, y, MaxWidth, RectWidth: integer;  r, r2: TRect;begin   y := 10;  MaxWidth := ClientWidth div 2;   for i := low(S) to high(S) do  begin     Canvas.Brush.Color := Colors[Odd(i)];     r := Rect(10, y, MaxWidth, 16);    DrawText(Canvas.Handle,      PChar(S[i]),      Length(S[i]),      r,    Aligns[Odd(i)] or DT_WORDBREAK or DT_CALCRECT);     if not Odd(i) then    begin      RectWidth := r.Right - r.Left;      r.Right := ClientWidth - 10;      r.Left := r.Right - RectWidth;    end;     r2 := Rect(r.Left - 4, r.Top - 4, r.Right + 4, r.Bottom + 4);    Canvas.RoundRect(r2, 5, 5);     DrawText(Canvas.Handle,      PChar(S[i]),      Length(S[i]),      r,      Aligns[Odd(i)] or DT_WORDBREAK);     y := r.Bottom + 10;   end; end; procedure TForm1.FormResize(Sender: TObject);begin  Invalidate;end; ---------------------------------------------------------------------- paweld · 2023-09-09 21:18 On lazarus trunk and fpc 3.2-fixes it's OK - tested on Windows 10 and Debian 12 ---------------------------------------------------------------------- jipété · 2023-09-10 08:02 Hello, Thank you for this nice answer. For my part, I will therefore quietly wait for the official release of Laz 3.0. Any idea when this date will arrive? Have a cool sunday, Best regards ---------------------------------------------------------------------- zeljko · 2023-09-10 11:55 This code works fine with gtk2 and gtk3 with trunk lazarus. ---------------------------------------------------------------------- jipété · 2023-09-11 10:38 Quote from: zeljko on September 10, 2023, 01:55:48 pmThis code works fine with gtk2 and gtk3 with trunk lazarus. Quote from: jipété on September 10, 2023, 10:02:07 amFor my part, I will therefore quietly wait for the official release of Laz 3.0. ---------------------------------------------------------------------- jipété · 2024-06-20 16:26 Hi, Quote from: paweld on September 09, 2023, 11:18:35 pmOn lazarus trunk and fpc 3.2-fixes it's OK - tested on Windows 10 and Debian 12 Quote from: zeljko on September 10, 2023, 01:55:48 pmThis code works fine with gtk2 and gtk3 with trunk lazarus. Sorry, boys, but still broken with Laz 3.4... Look at the last line in the big blue rectangle :