Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   nombre de archivo de una fuente TTF (https://www.clubdelphi.com/foros/showthread.php?t=74039)

Gimli 27-05-2011 10:33:08

nombre de archivo de una fuente TTF
 
Hola, me gustaría saber como obtener el nombre del archivo .ttf a partir del nombre (string) de la fuente.
Es decir:
Arial > arial.ttf
Timer New Roman > times.ttf

Luego la copiare a otro directorio para adjuntarla con la aplicación pero eso es otro historia... uso Delphi 7

Gracias

ecfisa 27-05-2011 16:39:49

Hola Gimli.

Código Delphi [-]
...
uses Registry;

function GetFileNameFont(const FontName: string): string;
const
  RGFONTS='\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts';
var
  Reg: TRegistry;
  Valor: TStrings;
  i : Integer;
  Esta: Boolean;
begin
  Reg:= TRegistry.Create;
  try
    Reg.RootKey:= HKEY_LOCAL_MACHINE;
    if not Reg.OpenKey(RGFONTS, False) then
      raise Exception.Create('Error leyendo clave de registro')
    else
    begin
      Valor:= TStringList.Create;
      try
        Reg.GetValueNames(Valor);
        Esta:= False;
        i:= 0;
        Result:= '';
        while not Esta and (i < Valor.Count) do
        begin
          Result:= Reg.ReadString(Valor[i]);
          if Copy(Valor[i],1,Length(FontName))=FontName then
            Esta:= True;
          Inc(i);
        end;
        if not Esta then
          Result:= '';     // devuelve cadena vacía si no lo encontró
      finally
        Valor.Free;
      end;
    end;
  finally
    Reg.Free;
  end;
end;

Ejemplo de llamada:
Código Delphi [-]
  ShowMessage(GetFileNameFont('Times New Roman'));

Saludos.


La franja horaria es GMT +2. Ahora son las 13:18:12.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi