Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Determine whether font is monospace or proportional?



On 3/21/07 at 4:53 PM, Chris Branch <email@hidden>
wrote:

> Given a ATSUFontID (for example, obtained via ATSUFindFontFromName()),
> is there a simple way to determine whether the given font is monospace
> or proportional?

No.  This has been another edition of "Simple answers to simple
questions."

---

(Not enough? Dang.)

There is nothing in any of the current font specifications that require
the font designer to say that all glyphs are the same width or not.
There is a "monospaced" font feature, but most fonts probably don't
support it, and it's designed to let you pick between monospaced and
proportional forms anyway.  It becomes more important for cases like
Kana spacing (also a font feature), but you're basically asking the font
system to return data to you -- whether all glyphs have the same width
-- that doesn't exist.)

In theory, you can look at the 'post' table in TrueType fonts and check
for a non-zero "isFixedPitch" value, but you'd have to load the tables
directly and look.  There are other tables that contain similar
information, but not all of them are required in all kinds of fonts, and
even if they are, the information may not be required in that table.

The traditional method, sadly enough, is to get the widths of two glyphs
that shouldn't be anywhere near the same in a proportional font, like
"W" and "!", and see if they're the same (if both glyphs exist, and of
course this means advance widths and not just the actual inked parts of
the glyph).  If the two advance widths are the same, the font is very
likely monospaced.

Until there's a single, universally-adopted font format, currently
scheduled for the 35th day of Never, any other answer is going to be
dependent on the storage and type of the font in question - tables in
TrueType or OpenType fonts may not match old Type 1 fonts, not all fonts
may have all tables, and so on.  So until the 35th of Never, this is
probably the most workable solution, jalopy-like though it may be.

This has been another edition of "I can't believe it still works that
way in 2007."

--
Matt Deatherage                              <email@hidden>
GCSF, Incorporated                      <http://www.macjournals.com>

"Human beings are not animals, and I do not want to see sex and sexual
 differences treated as casually and amorally as dogs and other beasts
 treat them.  I believe this could happen under the E.R.A."  -- Ronald Reagan


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden

References: 
 >Determine whether font is monospace or proportional? (From: Chris Branch <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.