How do I get the font name from a font file?

前端 未结 3 1185
终归单人心
终归单人心 2021-01-14 15:52

I want to enumerate all the file in the C:\\Windows\\Fonts\\

First I use FindFirst&FindNext to get all the file

Code:



        
3条回答
  •  轮回少年
    2021-01-14 16:52

    The GetFontResourceInfo undocumented function can get the name of the font from a font file.

    Try this sample

    {$APPTYPE CONSOLE}
    
    {$R *.res}
    
    uses
      Windows,
      SysUtils;
    
    
    function GetFontResourceInfo(lpszFilename: PChar; var cbBuffer: DWORD; lpBuffer: PChar; dwQueryType: DWORD): DWORD; stdcall; external 'gdi32.dll' name 'GetFontResourceInfoW';
    
    procedure ListFonts;
    const
      QFR_DESCRIPTION  =1;
    var
      FileRec : TSearchRec;
      cbBuffer : DWORD;
      lpBuffer: array[0..MAX_PATH-1] of Char;
    begin
      if FindFirst('C:\Windows\Fonts\*.*', faNormal, FileRec) = 0 then
      try
        repeat
          cbBuffer:=SizeOf(lpBuffer);
          GetFontResourceInfo(PWideChar('C:\Windows\Fonts\'+FileRec.Name), cbBuffer, lpBuffer, QFR_DESCRIPTION);
          Writeln(Format('%s - %s',[FileRec.Name ,lpBuffer]));
        until FindNext(FileRec) <> 0;
      finally
        FindClose(FileRec);
      end;
    end;
    
    
    begin
      try
       ListFonts;
      except
        on E: Exception do
          Writeln(E.ClassName, ': ', E.Message);
      end;
      Readln;
    end. 
    

    About your second question replace this line

      while pEnumList.Next(0, pidChild, b) = 0 do 
    

    with

      while pEnumList.Next(0, pidChild, celtFetched) = 0 do
    

提交回复
热议问题