![]() |
Multimedia »
GDI »
Fonts
Intermediate
License: The Code Project Open License (CPOL)
XFont - Get font name and file informationBy Hans DietrichXFont retrieves the name of the font file from the regsitry, and the font name from the font file |
VC6Win2K, WinXP, GDI, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
GetFontFile() in a previous article. This article presents a new non-MFC version of GetFontFile() and also GetFontProperties(), which together allow you to find the name of the font or the name of the font file.
First, let me acknowledge the work of Philip Patrick, who researched the font file format to come up with GetFontProperties(). I have taken his code and removed the MFC dependencies, added Unicode support, and converted the CFile file I/O to a memory-mapped file.
/////////////////////////////////////////////////////////////////////////////// // // GetFontFile() // // Purpose: Find the name of font file from the font name // // Parameters: lpszFontName - name of font // lpszDisplayName - pointer to buffer where font display name // will be copied // nDisplayNameSize - size of display name buffer in TCHARs // lpszFontFile - pointer to buffer where font file name // will be copied // nFontFileSize - size of font file buffer in TCHARs // // Returns: BOOL - TRUE = success // // Notes: This is *not* a foolproof method for finding the name of a // font file. If a font has been installed in a normal manner, // and if it is in the Windows "Font" directory, then this method // will probably work. It will probably work for most screen // fonts and TrueType fonts. However, this method might not work // for fonts that are created or installed dynamically, or that // are specific to a particular device, or that are not installed // into the font directory. //
/////////////////////////////////////////////////////////////////////////////// // // GetFontProperties() // // Purpose: Get font name from font file // // Parameters: lpszFilePath - file path of font file // lpFontPropsX - pointer to font properties struct // // Returns: BOOL - TRUE = success //
To integrate XFont into your app, you first need to add following files to your project:
If you include XFont in project that uses precompiled headers, you must change C/C++ Precompiled Headers settings to Not using precompiled headers for XFont.cpp.
Next, include the header file XFont.h in appropriate project files. Now you are ready to start using XFont. The two XFont functions are demonstrated fully in the XFont demo app.
GetFontProperties
CFile file I/O to memory mapped file
GetFontFile routine GetFontFile and GetFontProperties This software is released into the public domain. You are free to use it in any way you like. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 21 May 2003 Editor: Sean Ewington |
Copyright 2003 by Hans Dietrich Everything else Copyright © CodeProject, 1999-2009 Web20 | Advertise on the Code Project |