unit FontGF;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1DrawCell(Sender: TObject; Col, Row: Integer;
      Rect: TRect; State: TGridDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  I, J: Integer;
begin
  StringGrid1.ColCount := Screen.Fonts.Count + 1;
  StringGrid1.ColWidths [0] := 50;

  for I := 1 to Screen.Fonts.Count do
  begin
    StringGrid1.Cells [I, 0] := Screen.Fonts.Strings [I-1];
    StringGrid1.Canvas.Font.Name := StringGrid1.Cells [I, 0];
    StringGrid1.Canvas.Font.Size := 32;
    StringGrid1.ColWidths [I] :=
      StringGrid1.Canvas.TextWidth ('AaBbYyZz');
  end;

  StringGrid1.RowCount := 26;
  for I := 1 to 25 do
  begin
    StringGrid1.Cells [0, I] := IntToStr (I+7);
    StringGrid1.RowHeights [I] := 15 + I*2;
    for J := 1 to StringGrid1.ColCount do
      StringGrid1.Cells [J, I] := 'AaBbYyZz'
  end;
  StringGrid1.RowHeights [0] := 25;
end;

procedure TForm1.StringGrid1DrawCell(
  Sender: TObject; Col, Row: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if Col = 0 then
    StringGrid1.Canvas.Font.Name := 'Arial'
  else
    StringGrid1.Canvas.Font.Name := StringGrid1.Cells [Col, 0];
  if Row = 0 then
    StringGrid1.Canvas.Font.Size := 14
  else
    StringGrid1.Canvas.Font.Size := Row + 7;
  if gdSelected in State then
    StringGrid1.Canvas.Brush.Color := rgb(100,250,180)
  else if gdFixed in State then
    StringGrid1.Canvas.Brush.Color := rgb(10,200,50)
  else
    StringGrid1.Canvas.Brush.Color := clWindow;

  StringGrid1.Canvas.TextRect (Rect, Rect.Left, Rect.Top,
    StringGrid1.Cells [Col, Row]);

  if gdFocused in State then
    StringGrid1.Canvas.DrawFocusRect (Rect);

end;

end.
