mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 22:59:15 +02:00
TurboPower_ipro: Optimize function FindFontName. Remember previous values.
This commit is contained in:
parent
de52e5bc44
commit
c9e4a59c62
@ -26,7 +26,7 @@ function MinI2(const I1, I2: Integer) : Integer;
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Translations, LazUTF8,
|
Translations, LazUTF8,
|
||||||
IpConst,IpUtils;
|
IpConst,IpUtils;
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -593,6 +593,11 @@ begin
|
|||||||
SetLength(Result, n);
|
SetLength(Result, n);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
var // Remember previous in/out values for function FindFontName.
|
||||||
|
PrevFontList1, PrevResult1: string;
|
||||||
|
PrevFontList2, PrevResult2: string;
|
||||||
|
|
||||||
function FindFontName(const AFontList: string): string;
|
function FindFontName(const AFontList: string): string;
|
||||||
|
|
||||||
function CheckFonts(ATestFontList: array of String): String;
|
function CheckFonts(ATestFontList: array of String): String;
|
||||||
@ -609,37 +614,44 @@ function FindFontName(const AFontList: string): string;
|
|||||||
|
|
||||||
var
|
var
|
||||||
L: TStringList;
|
L: TStringList;
|
||||||
|
S: String;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
|
// Optimize 2 previous calls having the same parameter value.
|
||||||
|
if AFontList = PrevFontList1 then
|
||||||
|
Exit(PrevResult1)
|
||||||
|
else
|
||||||
|
if AFontList = PrevFontList2 then
|
||||||
|
Exit(PrevResult2);
|
||||||
|
|
||||||
|
Result := '';
|
||||||
L := TStringList.Create;
|
L := TStringList.Create;
|
||||||
try
|
try
|
||||||
L.CommaText := AFontList;
|
L.CommaText := AFontList;
|
||||||
for i:=0 to L.Count-1 do begin
|
for i:=0 to L.Count-1 do begin
|
||||||
Result := L[i];
|
S := L[i];
|
||||||
if Screen.Fonts.IndexOf(Result) > -1 then
|
if Screen.Fonts.IndexOf(S) > -1 then
|
||||||
exit;
|
Result := S
|
||||||
if SameText(Result, 'sans-serif') then begin
|
else
|
||||||
Result := Checkfonts(['Arial', 'Helvetica', 'Liberation Sans']);
|
if SameText(S, 'sans-serif') then
|
||||||
if Result = '' then
|
Result := Checkfonts(['Arial', 'Helvetica', 'Liberation Sans'])
|
||||||
Result := Screen.MenuFont.Name;
|
else
|
||||||
exit;
|
if SameText(S, 'serif') then
|
||||||
end else
|
Result := CheckFonts(['Times', 'Times New Roman', 'Liberation Serif'])
|
||||||
if SameText(Result, 'serif') then begin
|
else
|
||||||
Result := CheckFonts(['Times', 'Times New Roman', 'Liberation Serif']);
|
if SameText(S, 'monospace') then
|
||||||
if Result = '' then
|
|
||||||
Result := Screen.MenuFont.Name;
|
|
||||||
exit;
|
|
||||||
end else
|
|
||||||
if SameText(Result, 'monospace') then begin
|
|
||||||
Result := CheckFonts(['Courier New', 'Courier', 'Liberation Mono']);
|
Result := CheckFonts(['Courier New', 'Courier', 'Liberation Mono']);
|
||||||
if Result = '' then
|
if Result <> '' then
|
||||||
Result := Screen.MenuFont.Name;
|
Break;
|
||||||
exit;
|
|
||||||
end else
|
|
||||||
Result := Screen.MenuFont.Name;
|
|
||||||
end;
|
end;
|
||||||
|
if Result = '' then // Unknown or CheckFonts returned ''.
|
||||||
|
Result := Screen.MenuFont.Name;
|
||||||
finally
|
finally
|
||||||
L.Free;
|
L.Free;
|
||||||
|
PrevFontList2 := PrevFontList1;
|
||||||
|
PrevResult2 := PrevResult1;
|
||||||
|
PrevFontList1 := AFontList;
|
||||||
|
PrevResult1 := Result;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user