Hello there, sorry for my English.
I'm programming a tool to edit subtitles. (simple textlines)
For that I need a function that writes a textstring to canvas. Then I want to measure the width of the written text. Because I need the textwidth in pixel for later.
Now I saw that a text looks in every app different.
For example I have these two textlines
Eins zwei drei vier fünf sechs sieben acht neun
...........................................................................
I want them in "Tahoma" and BOLD. Now my problem. In my font (Tahoma, bold) they must have same length AT EVERY CHOOSEN SIZE.
In MSWord (not Wordpad) and Libreoffice and some other apps they are of equal length. (ok, there is a pixel difference at Size 50 but that doesn't matter)
It looks like this in every fontsize:
https://s1.imagebanana.com/file/181009/51gakppp.jpgThat's what I want!
But in Windows Notepad and Freepascal MemoBox it looks something like this:
https://s1.imagebanana.com/file/181009/SPFcJmY7.jpgThe dots in the second line are of different length to the first line. Sometime more, sometimes less depending on the fontsize.
Then I tried draw it on free pascal default canvas with the codeline
Canvas.Font.Quality:= fqAntialiased;
This is better but not good enough.
Then I tried the bgrabitmap-9.9-package and the CanvasBGRA with a TBGRAVectorizedFontRenderer
The result ist this:
https://s1.imagebanana.com/file/181009/huqIPNji.jpgMy function is this:
var
bmp: TBGRABitmap;
begin
a:=26; //FOntsize
bmp := TBGRABitmap.Create(ClientWidth,ClientHeight,ColorToRGB(clBtnFace));
bmp.FontRenderer := TBGRAVectorizedFontRenderer.Create;
bmp.CanvasBGRA.Font.Name := 'Tahoma';
bmp.CanvasBGRA.Font.Quality :=fqFineClearTypeBGR;
bmp.CanvasBGRA.Font.Style:=[fsBold];
bmp.CanvasBGRA.Font.Height:= round(-a* Font.PixelsPerInch/72);
bmp.CanvasBGRA.Brush.Color:=BGRA(255,0,0,255);
bmp.CanvasBGRA.TextOut(0,0,zeile1);
bmp.CanvasBGRA.TextOut(0,80,zeile2);
bmp.Draw(Canvas,0,0);
Form1.Edit1.Text:=IntToStr(bmp.CanvasBGRA.TextWidth(zeile1));
bmp.Free;
end;
Here are the 2 line nearly of equal length in every fontsize (a=12 ... a=45). But not so exact like in MS Word or other apps. But I want them equal.
Is there a better way to get this 2 lines look like in word? Note that I need a solution together with a GetTextwidth-function because later I need the pixelwidth.