This is my example code:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, EasyLazFreeType, TTTypes, lazfreetype;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
aFont: TFreeTypeFont;
Glyph: TFreeTypeGlyph;
GlyphIndex: Integer;
avg:double;
TextStr:string;
CharIdx:integer;
AdvanceMetrics:TT_Glyph_Metrics;
begin
TextStr:='Ciao Ciao';
aFont := TFreeTypeFont.Create;
try
aFont.Name := '/home/tommaso/tmp/UbuntuSans-Italic[wdth,wght].ttf';
//Font.Style:=[ftsBold];
avg:=0;
for CharIdx := 1 to Length(TextStr) do
begin
GlyphIndex := aFont.CharIndex[ord(TextStr[CharIdx])];
Glyph := aFont.Glyph[GlyphIndex];
if Assigned(Glyph) then
begin
if TT_Get_Glyph_Metrics(Glyph.Data, AdvanceMetrics) = 0 then
begin
avg:=avg+AdvanceMetrics.advance*1.8; //(AdvanceMetrics.bbox.yMax-AdvanceMetrics.bbox.yMin);
end;
Glyph.Free;
end;
end;
finally
//aFont.Free;
end;
end;
end.
It works, but if I uncomment aFont.Free; it crashes.
Moreover, if I replace TextStr:= TextStr:='Ciao Ciao'; with TextStr:= TextStr:='Ciao Ciao;;'; it crashes on Glyph.Free;.
Any idea? Could it a bug of EasyLazFreeType?
Thank you