Why TFontDialog gives less fonts than Screen.Fonts?
Asked Answered
I

2

4

I am wondering why TFontDialog gives less fonts than Screen.Fonts? (For example, the Arial* font, the Comic font, etc, does not show in TFontDialog)

It also seems that the font list given by TFontDialog is the same as WordPad, whereas the font list given by Screen.Fonts is basically the same as Word.

Thank you very much for your insights!

PS: Delphi XE, Windows 7

PS: related SO topics:

  1. Too many fonts when enumerating with EnumFontFamiliesEx function
  2. Finding System Fonts with Delphi
  3. How to use external fonts?

PS: related web pages:

  1. TFontDialog to show all Fonts @ borland.newsgroups.archived
  2. TFontDialog to show all Fonts @ delphigroups

sys app

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm2 = class(TForm)
    lst1: TListBox;
    dlgFont1: TFontDialog;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
begin
  lst1.Items.AddStrings(Screen.Fonts);
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  dlgFont1.Device := fdBoth;
  if dlgFont1.Execute then
  begin

  end;
end;

end.    
Irenics answered 2/7, 2012 at 19:54 Comment(3)
There's a chance that you get different results using different values for dlgFont1.Device. Try fdScreen and fdPrinter and then compare the lists again.Levkas
@Levkas The Device property is ignored on modern Windows (I think)Supposition
@Levkas No difference using different values for dlgFont1.Device.Irenics
D
6

Screen.Fonts returns all installed fonts, including hidden fonts as administrated in Registry\HKCU\Software\Microsoft\Windows NT\CurrentVersion\Font Management\Inactive Fonts. (Source) Apparently, TFontDialog does not display these hidden fonts.

Furthermore, some fonts listed in Screen.Fonts are not mentioned in the Font combo box of TFontDialog, but are added to the Font style combo box. Take Arial for example: the Font style lists 10 items, which seems to be the combination of the fonts Arial, Arial Black and Arial Narrow.

Directed answered 3/7, 2012 at 1:0 Comment(1)
Thank you very much for your insightful comments! I can now manipulate that registry key, OR walk through the control panel, to show my favorite fonts in TFontDialog & WordPad! :)Irenics
E
2

Different APIs, different results. Screen.Fonts uses EnumFontFamiliesEx(), which returns all installed fonts. TFontDialog uses ChooseFont() instead, which only displays the fonts that are compatible with the TFontDialog.Font and TFontDialog.Options properties.

Essene answered 2/7, 2012 at 20:43 Comment(1)
Thank you very much for your time! Could you help to elaborate compatible with TFontDialog.Font and TFontDialog.Options? I mean, is it possible to have TFontDialog give the same as Screen.Fonts suggests?Irenics

© 2022 - 2024 — McMap. All rights reserved.