How to Get Detailed Font Information

Hi,

is it possible to get detailed information about a font (ascender, descender, cap height, x height, etc.) and how do I do this?

Cheers
Tobias

Model: G5 dual
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

in what application?

Hm. So there is no »common« way to do this. It’s for InDesign CS2 or Quark 6.5. But both doesn’t support it good enough …

Tobias

Edit: This applies only to AppleScript Studio. If you really need to do this, you might be able to bring your project into Studio and use my solution below.

You can bridge with the methods in NSFont to obtain the functionality you require.

float capHeight = [[NSFont fontWithName:@"Helvetica" size:12.0] capHeight];

becomes

set capHeight to (call method "capHeight" of object (call method "fontWithName:size:" of class "NSFont" with parameters {"Helvetica", 12.0}))

Application Kit NSFont Reference

Thanks for your reply. It looks like this is exactly what I need.
So I have to do this in Studio. Or does this code work even outside Studio?:

set capHeight to (call method "capHeight" of object (call method "fontWithName:size:" of class "NSFont" with parameters {"Helvetica", 12.0}))

Tobias

Unfortunately for your situation, you cannot use the Cocoa/ObjC->AppleScript bridge outside of AppleScript Studio.

You may find it to be fairly easy to transition your script to Studio, but I can’t say that for certain without knowing your script and your level of knowledge/experience.

Additionally, since it’s unlikely that you’ll only want to know one single thing about a font, if you go this way, don’t just copy and paste what I did there and make multiple calls to obtain a font to query for information. Do that once and avoid the overhead. (Also, AppleScript is chatty, and doing this will avoid some of the clutter.)

[code]NSFont *font = [NSFont fontWithName:@“Helvetica” size:12.0];

float capHeight = [font capHeight];
float descender = [font descender];[/code]
becomes:


set theFont to (call method "fontWithName:size:" of class "NSFont" with parameters {"Helvetica", 12.0})

set capHeight to (call method "capHeight" of object theFont)
set descender to (call method "descender" of object theFont)

Another way could be to write a scriptable application in Cocoa. In Cocoa I have easy access to the font information and can pass it to a script.

I’ll think about that way either.
Thanks
Tobias

Honestly, implementing scriptability in a Carbon or Cocoa application is a massive pain in the ass. Do you mean, simply, that your Cocoa application will use NSAppleScript to automate other programs? The two are not the same thing.