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.
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.
Acknowledgments
References
Revision History
Version 1.0 - 2003 May 27
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.