String CurrentFontName;
bool __stdcall InfoFontProc(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme,
DWORD FontType, TListBox *ListBox1)
{
String fontName = (String)lpelfe->elfFullName;
if(CurrentFontName.LowerCase() == fontName.LowerCase())
{
String fName = "Nazwa: " + fontName;
if(ListBox1->Items->IndexOf(fName))
{
ListBox1->Items->Add(fName);
ListBox1->Items->Add("Styl: " + (String)lpelfe->elfStyle);
/*
NEWTEXTMETRIC TextMetric;
TextMetric = lpntme->ntmTm;
String fType;
switch(TextMetric. ntmFlags)
{
case 64: fType = "TrueType"; break;
default: fType = "OpenType";
}
ListBox1->Items->Add("Typ: " + fType); */
ListBox1->Items->Add("Skryty: " + (String)lpelfe->elfScript);
}
else
ListBox1->Items->Add(" " + (String)lpelfe->elfScript);
}
return true;
}
//---------------------------------------------------------------------------
void TForm1::GetFontName(String sFontFile, String *FontName, TListBox *ListBox1)
{
BOOL removeFont = false;
if(AddFontResource( sFontFile.c_str())) removeFont = true;
WCHAR g_szTypeFaceName[LF_FULLFACESIZE];
typedef BOOL(WINAPI *PGFRI)(LPCWSTR, DWORD *, LPVOID, DWORD);
HINSTANCE hDLL = LoadLibraryW(L"GDI32.DLL");
PGFRI GetFontResourceInfoW = (PGFRI)GetProcAddress(hDLL, "GetFontResourceInfoW");
DWORD dwSize = sizeof(g_szTypeFaceName);
if(!GetFontResourceInfoW( sFontFile.c_str(), &dwSize, g_szTypeFaceName, 1))
{
ShowMessage("Błąd odczytu");
return ;
}
*FontName = (String)g_szTypeFaceName;
CurrentFontName = *FontName;
ListBox1->Items->Clear();
EnumFontFamiliesEx( GetDC(0), NULL, (FONTENUMPROC)InfoFontProc, (LPARAM)ListBox1, 0);
if(removeFont) RemoveFontResource(sFontFile.c_str());
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
OpenDialog1->Options = TOpenOptions() << ofOldStyleDialog;
if(OpenDialog1->Execute())
{
String FontName;
GetFontName( OpenDialog1->FileName, &FontName, ListBox1);
Label1->Caption = FontName;
Label2->Caption = OpenDialog1->FileName;
}
}