freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Freetype] Question reagarding creating a face (choosefont support)


From: Peter Montgomery
Subject: Re: [Freetype] Question reagarding creating a face (choosefont support)
Date: Wed, 23 Jul 2003 13:03:15 -0700

I sent this on July 8 and it may have fallen through the cracks.  My
apologies if this posts twice.

    Thanks,
    PeterM

------------------------------------------------------

Suki,

> Is it possible to create a face using the LOGFONT struct pointer ( the
return value of ChooseFont() )argument?
>
> The reason I want to do this is that I would like my application to
use the ChooseFont dialog.

Others may know more about this than I do, but I found that the only way
to handle using fonts on a Windows machine with FreeType was to do the
work manually.  The problem is that the LOGFONT struct keeps the details
hidden from view (such as the name of the font file and the path to it),
so it doesn't help you.  In addition, you can't assume anything (like
the directory Windows is installed in, for example) if you want your
program to be robust.  Here are the steps I had to take to create a
list of TrueType only fonts in an application I wanted to be able to run
on Windows 98 to Windows 2000.

1 - Determine what version of Windows you are running on.  Use
"GetVersionEx( )" to find this.

2 - Open the registry to find the list of installed fonts.  The registry
path is dependent on what version of Windows you are running on.  If
it's 98, then the path is:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts\

If it's NT or above, then the path is:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Fonts\

Note that the only difference is "Windows" versus "WindowsNT".

3 - Open the registry and get the list of filenames it has.  The key
name is the font name a human expects to see, while the key value is the
font file name.  You can manually open regedit and look at this info for
yourself to see how it is stored.

4 - Get the path to the font folder.  This code is in Delphi (Pascal),
but most of it is just Win32 API calls  I added a couple of
comments regarding C implementation:

if (NoError) then
 begin
  Path := StrAlloc(MAX_PATH); // Use malloc in C
  SHGetSpecialFolderLocation(Application.Handle, CSIDL_FONTS, PIDL);
  if SHGetPathFromIDList(PIDL, Path) then
    CurrWindowsFontPath := Path;
  SHGetMalloc(AMalloc);
  AMalloc.Free(PIDL);
  StrDispose(Path); // Use free in C
  end;

5 - You now have a list of the filenames for humans, the corresponding
font filenames for FreeType, and the path to the font folder.

At this point you have a couple of options.  In my case, I manually
removed all the fonts that weren't TrueType fonts by searching for
"(TrueType)" and keeping only the fonts that had that sub-string in the
name.  In your case, you might be able to use the "lfFacename" member of
the LOGFONT struct and find if that name is in the registry.  My
assumption is that you would have to parse out the "(TrueType)"
sub-strings to do this as well.

    Thanks,
    PeterM







reply via email to

[Prev in Thread] Current Thread [Next in Thread]