On Oct 30, 2008, at 11:40 , Georg Seifert wrote:
hello,I wonder what is the best way to render images from a font file with a given string. The font is not activated in the system.I came up with:- using Quicklook, but I could only get images with "Ag" (like the icon for font files), not the alphabetic overview I get in the finder. (is there a way to render a sting with it?) - activating the font locally, render the image and deactivate it. (this is a bit overkill I suppose (and I didn’t tried it))- using a framework (like freetype) Any suggestions are appreciated
If it's a regular, supported (but not activated) font file, you can do something like this (this is what I do actually):
#import <Cocoa/Cocoa.h> #import <ApplicationServices/ApplicationServices.h> /* ... */NSString* fontsFolder = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"/Fonts"];
NSURL* fontsURL = [NSURL fileURLWithPath:fontsFolder]; OSStatus status; FSRef fsRef; CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);status = ATSFontActivateFromFileReference(&fsRef, kATSFontContextLocal, kATSFontFormatUnspecified, NULL, kATSOptionFlagsDefault, NULL);
NSFont* myFont = [NSFont fontWithName:@"My Font" size:12.0]; [mWelcomeLabel setFont:myFont]; /* ... */In this example, it assumes that your font files are in the application bundled under the Resources directory in a directory named Fonts, so basically:
/Applications/MyApplication.app/Contents/Resources/Fonts/MyFont.dfontBTW, this call doesn't require linking to the full Carobn framework, nor does it actually activate the font in the Font Book... just for this instance of your application.
HTH, Jason
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]