Click here to Skip to main content
15,867,453 members
Articles / Multimedia / GDI
Article

XFontCombo - An OpenType-aware font combobox

Rate me:
Please Sign up or sign in to vote.
4.79/5 (19 votes)
26 May 2003CPOL2 min read 76.3K   1.7K   31   5
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
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

 
GeneralKEY_ALL_ACCESS Pin
John R. Shaw2-Jun-03 9:59
John R. Shaw2-Jun-03 9:59 
GeneralRe: KEY_ALL_ACCESS Pin
Hans Dietrich4-Jun-03 16:06
mentorHans Dietrich4-Jun-03 16:06 
GeneralRe: KEY_ALL_ACCESS Pin
John R. Shaw5-Jun-03 2:16
John R. Shaw5-Jun-03 2:16 

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

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