Text overflows bounding rect
A 2D graphics library written in Delphi Pascal
Brought to you by:
angusj
Hi Angus,
Image32 is just awesome. I'm close to finish that clone of TSpeedButton, but I found a case when the text overflows its bounding rect :
program TestDrawText; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, System.Types, Img32, Img32.Vector, Img32.Draw, Img32.Text, Img32.Fmt.PNG; var FontReader: TFontReader; FontCache: TFontCache; I: TImage32; TextRect: TRect; begin try FontReader := TFontReader.Create('Segoe UI'); FontCache := TFontCache.Create(FontReader, 18); I := TImage32.Create(200, 200); I.Clear(clWhite32); TextRect := Rect(0, 0, 150, 200); DrawText(I, TextRect, 'This is a test, my friend', taCenter, tvaMiddle, FontCache, clBlack32); DrawDashedLine(I, Rectangle(TextRect), [20,10,15,10], nil, 1, clRed32, esPolygon); I.SaveToFile('Text.png'); I.Free; FontCache.Free; FontReader.Free; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end.
You will get the image attached. Could it be related to the space character between "my" and "friend", that gets added to the first line instead of being ignored ?
Thank you,
Hi Pierre.
First, I'm delighted you're finding Image32 so useful.
I can see you're using the latest code in the repository and you have indeed found a bug there.
To fix it ... in the method
TFontCache.GetTextOutline
in Img32.Text about line 2380 you'll find the following block of code ...I'll update the repository shortly (within the next couple of days when I'm back from holiday).
ps: Would you be happy to write a very bried review - see here? 🤞
Can't believe it was so simple :) Thank you very much Angus.