View Full Version : Retrieve the filename of a QFont

31st December 2009, 15:29

I am doing an exporter of ttf files to our internal engine format. I am using a QFontComboBox to let the graphics choose the font he want convert and do a simple preview with a QTextEdit.

I am using Freetype to do the conversion, that why I try to use the QFont::freetypeFace method, but it doesn't work on Windows.

For the moment I build the file name with the font family name, but it doesn't work for all fonts.

It might possible to load all fonts of the C:/Windows/Fonts with freetype and check if one have the same family name, but this solution is dirty and slow.

Edit :
Some ttf files contains only one face, that why some font are in many tff files (i.e. arial.ttf for "Arial Regular", ariali.ttf for "Arial Italic", etc.).
The problem is ttf files don't have any convention on the file name format.

I also need to be able to get the right file with font style (bold, italic,...).

Can I find some information in the register base of Windows for making the relation between the font and the file name?

5th January 2010, 21:19
I finaly scan this table from the register table :
HKLM\Software\Microsoft\Windows\CurrentVersion\Fon ts

31st August 2010, 08:12
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts
I find it in windows xp

8th September 2010, 05:12
QSettings settings("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
QStringList list = settings.allKeys();

for(int i=0;i<list.size();i++)
QString key = list.at(i);
QString text = settings.value(key).toString();
QStringList keys = key.split(" & ");
QString last = keys.last();
keys[keys.size()-1] = last.left(last.indexOf(" ("));
for(int j=0;j<keys.size();j++)
index.insert(keys[j], j);
name.insert(keys[j], text);

you can use it as

QString family = ui->fontComboBox->currentText();
QString path("C:/WINDOWS/Fonts/");
int in = index[family];
FT_New_Face(library, path.toUtf8(), in, &face)