Solved

Extract fontfilename in Delphi

Posted on 2002-06-09
9
452 Views
Last Modified: 2010-05-19
Using in Delphi EnumFontProc or Screen.Fonts it possible to extract the name of the fonts installed in Windows. It possible to extract files name allocated for fonts, and how?
0
Comment
Question by:BujorCristinel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 3

Expert Comment

by:Slavak
ID: 7066318
Why you cannot just read windows font directory?
0
 

Author Comment

by:BujorCristinel
ID: 7066431
I have font name.
To find file name in fonts folder it not very good solution to scan all file.
0
 
LVL 3

Accepted Solution

by:
Slavak earned 50 total points
ID: 7066478
You can try registry:

On win 9x:
 HKLM\Software\Microsoft\Windows\CurrentVersion\Fonts

on win nt:
 HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:BujorCristinel
ID: 7066758
Very nice.
I need registry value for Windows 2000 and Windows XP because I have only win 98.
0
 
LVL 3

Expert Comment

by:Slavak
ID: 7066766
Windows NT/2000/XP from same line: windows NT
0
 
LVL 2

Expert Comment

by:freshman3k
ID: 7067031
Hello!

The following code gets the list of fonts installed ,just place a listbox and a label on a form:

{--------------------}
function EnumFonts(var lp: TEnumLogFont;
  var tm: TNewTextMetric;
  dwType: DWORD;
  lpData: lParam): Integer; stdcall;
begin
  Result := 1;
  with TForm1(lpData), ListBox1 do
  begin
    Items.Add(lp.elfLogFont.lfFaceName);
  end;
end;
{--------------------}
procedure TForm1.FormShow(Sender: TObject);
begin
 EnumFontFamilies(Canvas.Handle,nil,@EnumFonts,Integer(Self));
end;

Good Luck! :-)
0
 
LVL 34

Expert Comment

by:Slick812
ID: 7067786
Hello BujorCristinel , Here's some code that will get Installed Font Names and the File Path for those fonts. It get's the names and paths from the registry, please note that the names for the Fonts are NOT the same names used for font creation (Canvas.Font.Name := FontName), the registry font names may have extra info like "Plain", "Bold", "Unicode" or "Italic" since there is only ONE Font Name in font creation and you pick the weight (Bold, normal) and style (Italic). So if you want to use a font name for font creation use the Screen.Fonts names. I use a ListBox to show the Font's names and Paths. You need to get the display fonts also if you want all the fonts.


procedure TForm1.but_GetFontsClick(Sender: TObject);
var
  FontReg: TRegistry;
  FontFiles, SystemFonts: TStringList;
  i: Integer;
  Str1, Str2, FontPath: String;
begin
FontFiles := TStringList.Create;
SystemFonts := TStringList.Create;
try
  FontReg := TRegistry.Create;
  try
    FontReg.RootKey := HKEY_CURRENT_USER;
    if FontReg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', False) then
      begin
      ListBox1.Clear;
      FontPath := FontReg.ReadString('Fonts')+'\';
      FontReg.CloseKey;
      end else Exit;
    FontReg.RootKey := HKEY_LOCAL_MACHINE;
    if FontReg.OpenKey('\Config\0001\Display\Fonts', False) then
      begin
      FontReg.GetValueNames(SystemFonts);
      for i := 0 to SystemFonts.Count -1 do
        begin
        Str2 := FontReg.ReadString(SystemFonts[i]);
        Str1 := SystemFonts[i];
        Delete(Str1,Pos('(',SystemFonts[i])-1,Length(SystemFonts[i]));
        if Pos('\',Str2) = 0 then
          SystemFonts[i] := Str1+' - '+FontPath+ Str2
          else
          SystemFonts[i] := Str1+' - '+ Str2;
        end;
      FontReg.CloseKey;
      end;
    if Win32Platform = VER_PLATFORM_WIN32_NT then
      Str1 := '\Software\Microsoft\Windows NT\CurrentVersion\Fonts'
      else
      Str1 := '\Software\Microsoft\Windows\CurrentVersion\Fonts';
    if FontReg.OpenKey(Str1, False) then
      begin
      FontReg.GetValueNames(ListBox1.Items);
      for i := 0 to ListBox1.Items.Count -1 do
        FontFiles.Add(FontReg.ReadString(ListBox1.Items[i]));
      FontReg.CloseKey;
      end;
    finally
    FontReg.Free;
    end;

  for i := 0 to ListBox1.Items.Count -1 do
    begin
    Str1 := ListBox1.Items[i];
    Delete(Str1,Pos('(',ListBox1.Items.Strings[i])-1,Length(ListBox1.Items.Strings[i]));
    if Pos('\',FontFiles[i]) = 0 then
    Str1 := Str1+ ' - '+ FontPath+FontFiles[i] else
    Str1 := Str1+ ' - '+FontFiles[i];
    ListBox1.Items[i] := Str1;
    end;
  //ListBox1.Items.Add('  DISPLAY (system) FONTS');
  for i := 0 to SystemFonts.Count -1 do
    ListBox1.Items.Add(SystemFonts[i]);
finally
FontFiles.Free;
SystemFonts.Free;
end;
end;


procedure TForm1.but_ScreenFontsClick(Sender: TObject);
begin
ListBox1.Clear;
ListBox1.Items := Screen.Fonts;
end;
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9010493
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept answer from Slavak

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question