Thank you to all for your posts and suggestions. I will investigate them one by one.
Apparently TFont returns a default glyph for unsupported characters. TFreeTypeFont has access to the real glyph information , and even has TFreeTypeFont.CharWidthFromUnicode() to get the real glyph width. 0 would be a missing glyph.
This sounds *very* interesting, because it would be a solution for Windows *and* Linux. But I did not manage it to work in a reliable time. This is my code:
uses EasyLazFreeType; {for class 'TFreeTypeFont'}
type CharUTF8 = string[4]; {string for 1 UTF8-char}
s255 = string[255];
function short_PChar(s: s255): PChar;
{converts a short string to PChar}
var sa: ansi;
begin
sa:=s;
exit(PChar(sa));
end;
procedure check_UTF8char_contained(s: CharUTF8);
{checks if an UTF8-character is contained in a Font}
var FTF: TFreeTypeFont;
pc: PChar;
len: single;
uc: cardinal;
charlen: longint;
begin
pc:=short_PChar(s); {convert UTF8 to Unicode: }
uc:=UTF8CodepointToUnicode(pc,charlen);
writeln('uc=', uc);
FTF:=TFreeTypeFont.Create;
// FTF.SetNameAndStyle('Arial',[]);
FTF.Name:='Arial';
len:=FTF.CharWidthFromUnicode(uc); {=> Access Violation}
writeln('len=', len);
FTF.Free;
end;
procedure Test_UTF8char_contained;
begin
check_UTF8char_contained(#$C2#$A7);
check_UTF8char_contained(#$C2#$87);
check_UTF8char_contained(#$E2#$86#$91);
end;
Because I have UTF8-characters like #$C2#$87 or #$E2#$86#$91 and function
'CharWidthFromUnicode' needs Unicode, I tried to convert this via
'UTF8CodepointToUnicode'. I hope this was correct (my knowledge about Unicode is near zero).
Above code throws an Access Violation in procedure TFreeTypeFont.LoadFace in Unit EasyLazFreeType:
procedure TFreeTypeFont.LoadFace;
var errorNum: TT_Error;
familyItem: TCustomFamilyCollectionItem;
fontItem: TCustomFontCollectionItem;
begin
DiscardFace;
if FStream <> nil then
begin
errorNum := TT_Open_Face(FStream,False,FFace);
if errorNum <> TT_Err_Ok then
raise exception.Create('Cannot open font (TT_Error ' + intToStr(errorNum)+') <Stream>');
end else
begin
if Pos(PathDelim, FName) <> 0 then
begin
errorNum := TT_Open_Face(FName,FFace);
if errorNum <> TT_Err_Ok then
raise exception.Create('Cannot open font (TT_Error ' + intToStr(errorNum)+') "'+FName+'"');
end else
begin
familyItem := Collection.Family[FName]; // Access Violation here
if familyItem = nil then
raise exception.Create('Font family not found ("'+FName+'")');
fontItem := familyItem.GetFont(FStyleStr);
if fontItem = nil then
raise exception.Create('Font style not found ("'+FStyleStr+'")');
FFace := fontItem.QueryFace(FontCollectionItemDestroyListener(self,@OnDestroyFontItem));
FFaceItem := fontItem;
end;
end;
FFaceLoaded:= true;
UpdateInstance;
end;
I found no documentaion for Unit EasyLazFreeType in a reliable time.
What I have is a Font-name from var 'Screen.Fonts'. I don't know, where the Font-file resides (on Linux there are a lot of folders with Fonts).
Please help. Meanwhile I will investigate the other suggestions.