Forum > LazUtils
EasyLazFreeType - what does TextWidth() return?
(1/1)
Graeme:
I somehow need to find out the width of a text string. I can't link to LCL or generate a FPCanvas bitmap. I only have access to the TTF files.
In the LazUtils there is a easylazfreetype.pas unit, and I'm trying to figure out the works of the TFreeTypeFont.TextWidth() method.
Using the following program I get two results of 8 and 23 - but what do those values represent? Points, Pixels?
If the result is in pixels, where do you specify the Font Size? I never specified a font point size in my example code, and obvious different font sizes will produce different pixel sizes for text width.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project1; {$mode objfpc}{$h+} uses Classes, SysUtils, EasyLazFreeType, LazFreeTypeFontCollection; var s: string; fc: TFreeTypeFontCollection; lTTF: TFreeTypeFont;begin s := 'abc'; fc := TFreeTypeFontCollection.Create; if not fc.AddFile('/data/devel/Wisa/fpcpackages/fppdf/tests/fonts/DejaVuSans.ttf') then writeln('Failed to load font'); lTTF := fc.Family['DejaVu Sans'].Font[0].CreateFont; // returns 8 writeln(Trunc(lTTF.TextWidth('$'))); // returns 23 writeln(Trunc(lTTF.TextWidth('abc'))); lTTF.Free; fc.Free;end.
FTurtle:
--- Quote from: Graeme on January 21, 2016, 04:43:37 pm ---If the result is in pixels, where do you specify the Font Size? I never specified a font point size in my example code, and obvious different font sizes will produce different pixel sizes for text width.
--- End quote ---
I think should be some default value.
Why not specify your own value?
Graeme:
Thanks FTurtle. Only afterwards I delved into the code and noticed that the constructor sets a default PointSize of 10, and that there is an actually PointSize and PixelSize property.
Navigation
[0] Message Index