Ich finde es unnötig Fonts in die Resource einzubinden bin da lieber flexibel falls ich ihn doch mal schnell ändern möchte.
Aber wie du sagst jedem das sein.
Ich erstelle den Font indirekt ohne ihn extra zu registrieren und verwende ihn dann.
Besser wäre auch noch den Font Namen selbst zurückzugeben anstatt ihn zu übergeben.
Delphi-Quellcode:
function GDIP_PrivateFontCollection(var FontCollection: Pointer
): GPSTATUS; stdcall;
begin
PrvFontCollection := TGPPrivateFontCollection.Create;
FontCollection := PrvFontCollection.nativeFontCollection;
result:= PrvFontCollection.GetLastStatus;
end;
Delphi-Quellcode:
function GDIP_PrivateAddFontFile(filename: PWideChar
): GPSTATUS; stdcall;
begin
result := PrvFontCollection.AddFontFile(filename);
end;
Delphi-Quellcode:
function GDIP_GdipGetFontCollectionFamilyCount(var count: Integer
): GPSTATUS; stdcall;
begin
count := PrvFontCollection.GetFamilyCount;
result:= PrvFontCollection.GetLastStatus;
end;
Delphi-Quellcode:
function GDIP_FontFamilyCreate(Count: Integer; var pFontFamily: array of TGPFontFamily
): GPSTATUS; stdcall;
var
numFound: Integer;
FontFamily: array of TGPFontFamily;
begin
SetLength(FontFamily, Count + 1);
FontFamily[Count] := TGPFontFamily.Create;
result:= FontFamily[Count].GetLastStatus;
GDIP_GetFamilies(Length(FontFamily), FontFamily, numFound);
pFontFamily[Count] := FontFamily[Count];
end;
Delphi-Quellcode:
function GDIP_GetFamilies(numSought: Integer; out gpfamilies: array of TGPFontFamily;
out numFound: Integer
): GPSTATUS; stdcall;
begin
result := PrvFontCollection.GetFamilies(numSought, gpfamilies, numFound);
end;
Delphi-Quellcode:
function TSkinEngine.LoadPrivateFontCollection(Path: string; var FontCollection: Pointer;
var FontName: string
): GPSTATUS; stdcall;
var
i: integer;
Count: integer;
gFontFamily: array of TGPFontFamily;
begin
Result := GenericError;
if FileExists(Path) then
begin
GDIP_PrivateFontCollection(FontCollection);
GDIP_PrivateAddFontFile(PWideChar(Path));
GDIP_GdipGetFontCollectionFamilyCount(Count);
SetLength(gFontFamily, Count + 1);
for i := 0 to Count - 1 do
GDIP_FontFamilyCreate(i, gFontFamily);
for i := 0 to count - 1 do
// Get the font family name.
gFontFamily[i].GetFamilyName(FontName);
Result := OK;
end;
end;
Bsp.
Delphi-Quellcode:
if not Assigned(TTFCaption) then
GDIP_LoadPrivateFontCollection(SpriteResPath + 'lcd.ttf', TTFCaption, FontCaption);
gruss