NSFont and the Carbon Font Manager
NSFont and the Carbon Font Manager
- Subject: NSFont and the Carbon Font Manager
- From: Andy <email@hidden>
- Date: Wed, 26 Dec 2001 12:43:38 -0500
Hi all,
Decided it was time to scratch 2 itches at once and make a little font
inspection tool, and actually apply some Cocoa book knowledge to a real program.
Aim of this tool is to be able to determine things like how many
characters a font supports[*] and what format its in. Eventually I want
to support displaying the whole of the larger fonts... the existing
tools seem mostly limited to 256 char/8bit inspection.
So far I'm finding this pretty difficult:
On the cocoa side:
encodingScheme - seems to be complely broken, in that it always returns
"Font Specific". Maybe that's true, but its not very helpful!
mostCompatibleStringEncoding - seems to fare a little better - at least
sometimes it returns "Mac Roman", but give it a Japanese font, or
anything like that, and you just get back garbage (ie, matches none of
the NSStringEncoding constants).
There's really not much you can find out about a font in Cocoa, so I
started to look at making some Carbon FontManager calls.
So I start with the list of Font Names I get back from NSFontManager availableFontFamilies,
convert from Unicode down to a MacRoman pstring (what a hassle! where is
getPString on NSString!?!)... and call FMGetFontFamilyFromName using the
family name
The trouble is that while this works OK for regular western fonts, (eg,
Arial, Impact, Chicago, etc) there's no way to get the Carbon font
family for fonts like Hirigano Maru Gothic - one always gets "not found"
back from the Carbon Font Manager.
If I could get the Carbon representation for these fonts, then I can
give the filename and type (truetype etc) in my app. Cocoa just doesn't
give me this info.
Ideally there'd be a way to get the Carbon FMFontFamily directly from NSFont...
So I did some digging, and I noticed Carbon and Cocoa apps sort and list
fonts differently. Cocoa tends to list all fonts in alphabetical order,
and all names are displayed in Roman form (ie, "Hirigano Mincho" rather
than the Katakana equivalent) on my US English system.
Carbon apps tend to have 3 runs of names ... first all the Roman/Western
fonts, then the CE and CY fonts (central european?) also in Roman form,
then all of the "Eastern" and other script system based fonts, often
with their names displayed in that script. So the Japanese Fonts (other
than Mac OS 9's Osaka) have their names in Japanese Katakana and Kanji.
I'm guessing I can't convert because of these different "canonical"
representations for font family names...
So I looked at NSFont again - none of NSFont displayName, familyName or
fontName seem to give the appropriate conversion to the form Carbon uses :(
Am I missing something or are these APIs as holey as they seem to be?
[*] as an aside, I was somewhat shocked to discover Mac OS X ships with
no fonts capable of displaying the whole unicode range. The Hirigano
Maru Gothic and Hirigano Mincho fonts are very good at 20296 chars each,
but that's short of the full range, no? I mean, the OS can substitute
from multiple fonts to make up the missing chars, but that gives me
uglier results than on Windows, where Arial Unicode is usually available.
--
AndyT (lordpixel - the cat who walks through walls)
A little bigger on the inside
I think we finally found the killer app for Flash: animated stick men