Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

XFontCombo - An OpenType-aware font combobox

0.00/5 (No votes)
26 May 2003 2  
XFontCombo demonstrates the use of IsOpenType(), a function that determines if a font is OpenType

Introduction

I remember when I first saw the italic O appear in font selection dialogs, I thought "What could this be? Is it some kind of open-source font technology?" Then I realized I was looking at a Microsoft product, so I quickly decided it must be something else. In fact, I came to learn that the O stood for OpenType, a universal font format introduced by Microsoft and Adobe in 1996 that combines Microsoft's TrueType and Adobe's Type 1 font technologies. You can learn more about OpenType here.

Of course my next question was "How can you tell if it's OpenType?" The answer lies in diving into the font file. Thanks to the work of Philip Patrick, it is easy to construct a function that will determine if a font is OpenType.

The IsOpenType() Function

IsOpenType() returns TRUE if the specified font file is OpenType. Internally, IsOpenType() reads the font file as a memory-mapped file and scans the tables of the font file for the OpenType marker tag.
/////////////////////////////////////////////////////////////////////////////
//
// IsOpenType()
//
// Purpose:     Determine if font file is OpenType.
//
// Parameters:  lpszFilePath - file path of font file
//
// Returns:     BOOL - TRUE = font file is OpenType
// 

How To Use

To integrate IsOpenType() into your app, you first need to add following files to your project:

  • IsOpenType.cpp
  • IsOpenType.h

If you include IsOpenType.cpp in project that uses precompiled headers, you must change C/C++ Precompiled Headers settings to Not using precompiled headers for IsOpenType.cpp.

Next, include the header file IsOpenType.h in appropriate project files. Now you are ready to start using IsOpenType().

Demo App

The XFontComboTest.exe demo shows how to use IsOpenType() function. Since it is likely you will only have font name (i.e., display name) and not name of font file, you may also need to use my GetFontFile() function.

As a testbed I use Chris Losinger's excellent Font Combo. With addition of IsOpenType(), you can now see which fonts are OpenType. For comparison purposes, I also include button to display standard CFontDialog.

XFontCombo screenshot

Acknowledgments

References

Revision History

Version 1.0 - 2003 May 27

  • Initial public release.

Usage

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here