Thread-topic: Determine whether font is monospace or proportional?
Matt,
Thanks you for your response.
To elaborate a bit more, I need to store font information in a file such that I have enough information to: 1) request the same font again when the file is re-loaded, or 2) pick a good substitute if the font is not available. Storing only the font name would probably be OK for #1, but would not work so well for #2. Also, this file format will be cross platform (Windows and Mac). Windows does this for me automatically because, to request a font in Windows, I have to fill out a LOGFONT structure that contains: font name, character set, family, pitch (monospace/proportional width), etc. Windows finds the "best match" by weighing each of the properties I request against the available fonts on the machine (name and character set are most important in Windows and therefore contribute the most weight).
So, I'm looking for a way to find similar information for given font on OS X so that I can persist this information in my file. I asked about monospace vs. proportional width as a starting point with the intention I would move on from there once I found that answer. But I'm not off to a very good start :-). I know nothing about the internals of .ttf files (or other font formats), and to be honest, I had hoped to keep it that way. But it sounds like that may not be possible.
Thanks again.
Chris
________________________________________
From: Matt Deatherage [email@hidden]
Sent: Sunday, March 25, 2007 3:27 AM
Subject: 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
This message is intended only for the use of the individual (s) or entity to which it is addressed and may contain information that is privileged, confidential, and/or proprietary to eInstruction and its affiliates. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution, forwarding or copying of this communication is prohibited without the express permission of the sender. If you have received this communication in error, please notify the sender immediately and delete the original message.
_______________________________________________
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