unit TMS.ServerWizard.PlatformFonts;

{$I bcl.inc}

interface

{$IFDEF DELPHIXE2_LVL}

uses
  Graphics;

type
  TWindowsPlatformFonts = class
  private
    class var
      FSuperHeadingFont,
      FHeadingFont,
      FNormalTextFont,
      FTinyFont : TFont;

    class procedure InitXP;
    class procedure InitVistaOrHigher;
    class function IsVistaOrAbove: Boolean; static;
  public
    class constructor ClassCreate;
    class destructor ClassDestroy;

    class property SuperHeadingFont : TFont read FSuperHeadingFont;
    class property HeadingFont : TFont read FHeadingFont;
    class property NormalTextFont : TFont read FNormalTextFont;
    class property TinyFont : TFont read FTinyFont;
  end;

{$ENDIF}

implementation

{$IFDEF DELPHIXE2_LVL}

uses
  SysUtils, Forms, Winapi.Windows, Winapi.DwmApi;

{ TWindowsFonts }

class constructor TWindowsPlatformFonts.ClassCreate;
begin
  FSuperHeadingFont := TFont.Create;
  FNormalTextFont := TFont.Create;
  FHeadingFont := TFont.Create;
  FTinyFont := TFont.Create;

  if IsVistaOrAbove then
    InitVistaOrHigher
  else
    InitXP;
end;

class constructor TWindowsPlatformFonts.ClassDestroy;
begin
  FSuperHeadingFont.Free;
  FHeadingFont.Free;
  FNormalTextFont.Free;
  FTinyFont.Free;
end;

class function TWindowsPlatformFonts.IsVistaOrAbove : Boolean;
var
  VersionInfo : TOSVersionInfo;
begin
  VersionInfo.dwOSVersionInfoSize := sizeof(VersionInfo);
  GetVersionEx(VersionInfo);
  Result := VersionInfo.dwMajorVersion >= 6;
end;

class procedure TWindowsPlatformFonts.InitXP;
begin
  FNormalTextFont.Assign(Screen.MessageFont);

  FHeadingFont.Assign(Screen.MessageFont);
  FHeadingFont.Style := [fsBold];
  FHeadingFont.Size := FHeadingFont.Size + 1;

  FSuperHeadingFont.Assign(FHeadingFont);
  FSuperHeadingFont.Size := FSuperHeadingFont.Size + 3;

  FTinyFont.Assign(Screen.MessageFont);
  FTinyFont.Size := FTinyFont.Size - 2;
end;

class procedure TWindowsPlatformFonts.InitVistaOrHigher;
begin
  FNormalTextFont := TFont.Create;
  FNormalTextFont.Assign(Screen.MessageFont);

  FHeadingFont := TFont.Create;
  FHeadingFont.Assign(Screen.MessageFont);
  // Segoe UI 12, RGB(0, 51, 153)
  // From http://blog.quppa.net/2011/04/30/windows-theme-fonts/
  FHeadingFont.Size := FHeadingFont.Size + 3;
  FHeadingFont.Color := RGB(0, 51, 153);

  // I think this looks better - it's larger
  FSuperHeadingFont.Assign(FHeadingFont);
  FSuperHeadingFont.Size := FSuperHeadingFont.Size + 3;
  FSuperHeadingFont.Style := FSuperHeadingFont.Style + [fsBold];

  FTinyFont.Assign(Screen.MessageFont);
  FTinyFont.Size := FTinyFont.Size - 2;
end;

{$ENDIF}

end.

