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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
program Fonts; {GDIDemo;}
// version VP à corriger
{$IFDEF VER15}
uses
WinProcs,
WinTypes,
WObjects,
Strings;
{$ENDIF}
{$IFDEF VPASCAL}
{&PMTYPE PM}
uses
Windows,
oWindows,
Strings;
{$ENDIF}
const
MaxNumFonts = 20;
function Min(X, Y: Integer): Integer;
begin
if X > Y then Min := Y else Min := X;
end;
{ TBaseDemoWindow -------------------------------------------------- }
type
PBaseDemoWindow = ^TBaseDemoWindow;
TBaseDemoWindow = object(TWindow)
end;
{ TNoIconWindow ---------------------------------------------------- }
{ TMoveToLineToWindow ---------------------------------------------- }
{ TFontWindow ------------------------------------------------------ }
type
FontInfoRec = record
Handle: HFont;
Height: Byte;
Width: LongInt;
Name: array[0..lf_FaceSize-1] of char;
end;
const
FontUsers: Integer = 0;
var
FontInfo: array[0..MaxNumFonts] of FontInfoRec;
NumFonts: Integer;
TheDC: HDC;
type
PFontWindow = ^TFontWindow;
TFontWindow = object(TBaseDemoWindow)
FontsHeight: LongInt;
FontsWidth: LongInt;
constructor
Init(AParent: PWindowsObject; ATitle: PChar);
procedure
Paint(PaintDC: HDC; var PaintInfo: TPaintStruct); virtual;
procedure
Destroy; virtual;
procedure
WMSize(var Msg: TMessage); virtual wm_First + wm_Size;
end;
function EnumerateFont(var LogFont: TLogFont; TextMetric: PTextMetric;
FontType: Integer; Data: PChar): Integer; export;
var
OldFont: HFont;
begin
FontInfo[NumFonts].Handle := CreateFontIndirect(LogFont);
with LogFont do
begin
FontInfo[NumFonts].Height := lfHeight;
StrCopy(FontInfo[NumFonts].Name, lfFaceName);
OldFont := SelectObject(TheDC, FontInfo[NumFonts].Handle);
{$IFDEF VER15}
FontInfo[NumFonts].Width := Word(
GetTextExtent(TheDC, lfFaceName, StrLen(lfFaceName)));
{$ENDIF}
{$IFDEF VPASCAL}
FontInfo[NumFonts].Width := lf_FaceSize; // à vérifier
{$ENDIF}
SelectObject(TheDC, OldFont);
end;
Inc(NumFonts);
if NumFonts > MaxNumFonts then
EnumerateFont := 0
else
EnumerateFont := 1;
end;
procedure GetFontInfo;
var
EnumProc: TFarProc;
begin
if FontUsers = 0 then
begin
TheDC := GetDC(GetFocus);
NumFonts := 0;
EnumProc := MakeProcInstance(@EnumerateFont, HInstance);
EnumFonts(TheDC, nil, EnumProc, nil);
FreeProcInstance(EnumProc);
ReleaseDC(GetFocus, TheDC);
end;
Inc(FontUsers);
end;
procedure ReleaseFontInfo;
var
I: Integer;
begin
Dec(FontUsers);
if FontUsers = 0 then
for I := 0 to NumFonts - 1 do
DeleteObject(FontInfo[I].Handle);
end;
constructor TFontWindow.Init(AParent: PWindowsObject; ATitle: PChar);
var
I: Integer;
function Max(I, J: LongInt): LongInt;
begin
if I > J then Max := I else Max := J;
end;
begin
TBaseDemoWindow.Init(AParent, ATitle);
GetFontInfo;
Attr.Style := Attr.Style or ws_VScroll or ws_HScroll;
FontsHeight := 0;
FontsWidth := 0;
for I := 0 to NumFonts - 1 do
begin
Inc(FontsHeight, FontInfo[I].Height);
FontsWidth := Max(FontsWidth, FontInfo[I].Width);
end;
Scroller := New(PScroller, Init(@Self, 1, 1, 0, 0));
end;
procedure TFontWindow.Paint(PaintDC: HDC; var PaintInfo: TPaintStruct);
var
I: Integer;
Position: Integer;
begin
Position := 0;
for I := 0 to NumFonts - 1 do
begin
SelectObject(PaintDC, FontInfo[I].Handle);
TextOut(PaintDC, 10, Position, FontInfo[I].Name,
StrLen(FontInfo[I].Name));
Inc(Position, FontInfo[I].Height);
end;
end;
procedure TFontWindow.Destroy;
var
I: Integer;
begin
TBaseDemoWindow.Destroy;
ReleaseFontInfo;
end;
procedure TFontWindow.WMSize(var Msg: TMessage);
begin
TWindow.WMSize(Msg);
if Scroller <> nil then
Scroller^.SetRange(FontsWidth - Msg.lParamLo + 10,
FontsHeight - Msg.lParamHi);
end;
{ TBitBltWindow ---------------------------------------------------- }
{ TArtyWindow ------------------------------------------------------ }
{ TGDIDemoWindow --------------------------------------------------- }
{ TGDIDemoApp ------------------------------------------------------ }
type
TGDIDemoApp = object(TApplication)
procedure InitMainWindow; virtual;
end;
procedure TGDIDemoApp.InitMainWindow;
begin
MainWindow := New(PFontWindow, Init(Nil, 'Fonts Demo'));
end;
var
GDIDemoApp: TGDIDemoApp;
begin
GDIDemoApp.Init('GDIDEMO');
GDIDemoApp.Run;
GDIDemoApp.Done;
end. |
Partager