How to read the 'Title' property in the Details tab of a FONT TRUE TYPE file?

Asked

Viewed 308 times

2

I’m developing a small application that reads a . MDB, of which there are source names. Then I check if these sources are installed, if not, install them. But I have to know the Font Title name that is inside the Properties/Date screen to know exactly the source to be inserted. Since I have file name = "x.ttf" and name in detail tab "x.ttf", ai ok works well , but when I have "x.ttf" = file name and "xx.ttf" on the property there goes all wrong.

  • Is that it? http://www.delphipages.com/forum/showthread.php?t=171299 (see Chris' suggestion).

1 answer

2

It is worth answering to have the history and in case in the future someone needs.

The simplest way is to install, check and uninstall, thus having access to the source name. Routine:

Function NomedaFonte(Font: WideString):WideString;
type
  TGetFontResourceInfoW = function(Name: PWideChar; var BufSize: Cardinal;
    Buffer: pointer; InfoType: Cardinal): LongBool; stdcall;
var
  naf, k, y: integer;
  gfri: TGetFontResourceInfoW;
  lf: array of TLogFontW;
  lfsz: Cardinal;
  hfnt: HFONT;
  Nome: WideString;
begin
  gfri := GetProcAddress(GetModuleHandle('gdi32.dll'), 'GetFontResourceInfoW');
  if @gfri = nil then
    raise Exception.Create('GetFontResourceInfoW in gdi32.dll não funciona.');
  if LowerCase(ExtractFileExt(Font)) = '.pfm' then
    Font := Font + '|' + ChangeFileExt(Font, '.pfb');
  naf := AddFontResourceW(PWideChar(Font)); //carrega fonte
  try
    if naf > 0 then
    begin
      SetLength(lf, naf);
      lfsz := naf * SizeOf(TLogFontW);
      if not gfri(PWideChar(Font), lfsz, @lf[0], 2) then
        raise Exception.Create('GetFontResourceInfoW não pode ser chamado.');
      y := 0;
      naf := lfsz div SizeOf(TLogFont);
      for k := 0 to naf - 1 do
      begin
        hfnt := CreateFontIndirectW(lf[k]);
        try
          Nome := lf[k].lfFaceName; //Pega nome da fonte
          Result := Nome;
        finally
          DeleteObject(hfnt);
        end;
      end;
    end;
  finally
    RemoveFontResourceW(PWideChar(Font)); //Descarrega fonte
  end;
end;

Source(in German).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.