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.
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.