Click here to Skip to main content
Click here to Skip to main content

XFontCombo - An OpenType-aware font combobox

By , 26 May 2003
Rate this:
Please Sign up or sign in to vote.

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Hans Dietrich
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.
 
Recently, I have moved to Los Angeles where I am doing consulting and development work.
 
For consulting and custom software development, please see www.hdsoft.org.






Comments and Discussions

 
GeneralThanks... PinmemberPaul Selormey26-May-03 23:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 26 May 2003
Article Copyright 2003 by Hans Dietrich
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid