Re: How to get NSFont instance from classic Font ID?
Re: How to get NSFont instance from classic Font ID?
- Subject: Re: How to get NSFont instance from classic Font ID?
- From: Andrew Thompson <email@hidden>
- Date: Sat, 6 Sep 2003 11:26:45 -0400
The only reliable name that you can use to bridge the gap between the
classic FM world and the NSFont world is the Postscript name of the
font.
If you use the regular family name you'll indeed see that you can
convert some fonts but not others, as you've already noticed.
Here's how I go the other way... given an NSFont I have a Category
defined like this:
@interface NSFont (UFIFont)
- (ATSFontRef) toATSFont;
@end
@implementation NSFont (UFIFont)
... etc
- (ATSFontRef) toATSFont {
ATSFontRef result = ATSFontFindFromPostScriptName((CFStringRef)
[self fontName], kATSOptionFlagsDefault);
return (result != kATSFontFamilyRefUnspecified) ? result : nil;
}
If you look up ATSFontRef on developer.apple.com, you'll find functions
to convert from ATSFontRefs to FMFont structures.
You should then be able to figure out a reliable conversion method, but
as I said: the key is to use the Postscript name when you need to
bridge the two worlds.
AbdyT
On Thursday, Sep 4, 2003, at 03:09 America/New_York, Satoshi Matsumoto
wrote:
Hi, all
I need to convert old Classic documents to Cocoa documents. In Classic
documents, the font informantion are recorded in the font ID and
character
size.
I tried to convert classic Font ID to NSFont instance as following...
1) get the family name of oldFontID
FMGetFontFamilyName (oldFontID, str255Name );
2) convert it into unicode nsFontName
nsFontName =[[NSString alloc]
initWithData: [NSData dataWithBytes:&str255Name[0]+1
length:str255Name[0]]
encoding:<default encoding>];
3) get nsFont instance using following NSFontManager method.
nsFont = [[NSFontManager sharedFontManager]
fontWithFamily:nsFontName
traits:0 weight:5
size:charcterSize ];
Above method works for some fonts, but not for every font.
Does anyone know more perfect solution for the classic Font ID
conversion?
Satoshi Matsumoto
-----------------------------------------------------
Satoshi Matsumoto <email@hidden>
816-5 Odake, Odawara, Kanagawa, Japan 256-0802
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
AndyT (lordpixel - the cat who walks through walls)
A little bigger on the inside
(see you later space cowboy ...)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.