-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFonts.pas
79 lines (71 loc) · 2.74 KB
/
Fonts.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
unit Fonts;
{******************************************************************************}
{* Fonts Unit *}
{* Revolutionary Confederation of Anarcho Syndicalists *}
{* Written by: black.rabbit 2012 *}
{******************************************************************************}
interface
uses
Windows, SysUtils, Classes, Messages;
function RegisterFont (const aFileName: String; const doUpdate: Boolean = TRUE) : Integer;
function RegisterFonts (const aDir: String) : Integer;
resourcestring
ERR_REGISTER_FONT = 'Îøèáêà çàãðóçêè øðèôòà ''%s''!';
ERR_REGISTER_FONTS = 'Îøèáêà çàãðóçêè øðèôòîâ èç äèðåêòîðèè ''%s''!';
implementation
uses
Utils;
function RegisterFont (const aFileName: String; const doUpdate: Boolean = TRUE) : Integer;
begin
Result := -1;
try
if not FileExists (aFileName) then
raise Exception.CreateFmt (ERR_FILE_NOT_FOUND,[aFileName]);
Result := AddFontResourceEx ( PChar (aFileName), FR_PRIVATE, NIL );
{ ôóíêöèÿ äîëæíà âåðíóòü èíäåêñ óñòàíîâëåííîãî øðèôòà â ñïèñêå øðèôòîâ }
if not ( Result > 0 ) then
raise Exception.CreateFmt ('Error code: %d',[Result]);
{ îáíîâëÿåì }
if doUpdate then
SendMessage (HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
except on E: Exception do
raise Exception.CreateFmt ('%s#13#10%s',[ Format (ERR_REGISTER_FONT,[aFileName]), E.Message ]);
end;
end;
function RegisterFonts (const aDir: String) : Integer;
var
lst : TStrings;
I : Integer;
begin
Result := 0;
try
lst := TStringList.Create;
try
{ çàãðóæàåì ñïèñîê ôàéëîâ ñî øðèôòàìè }
GetFiles (aDir,lst,TRUE,[ '*.fon',
'*.fnt',
'*.ttf',
'*.ttc',
'*.fot',
'*.otf',
'*.mmm',
'*.pfb',
'*.pfm' ]);
for I := 0 to lst.Count - 1 do
try
{ ðåãèñòðèðóåì øðèôòû }
if ( RegisterFont (lst [I],FALSE) > 0 ) then
Inc (Result);
except
{ èãíîðèðóåì øðèôòû, êîòîðûå íå óäàëîñü çàãðóçèòü }
end;
finally
FreeAndNil (lst);
end;
{ îáíîâëÿåì }
SendMessage (HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
except on E: Exception do
raise Exception.CreateFmt ('%s#13#10%s',[ Format (ERR_REGISTER_FONTS,[aDir]), E.Message ]);
end;
end;
end.