• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Image from font file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Image from font file


  • Subject: Re: Image from font file
  • From: Georg Seifert <email@hidden>
  • Date: Thu, 30 Oct 2008 21:32:37 +0100

Thanks for your answer. I found this with google, too.

The problem is, I want to build somthing like a font preview app. So it needs to be fast and may happen with 10 or even 50 fonts at once. And it may conflict with activated fonts.

Georg

Am 30.10.2008 um 20:22 schrieb Jason Coco:


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.dfont

BTW, 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

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Image from font file
      • From: Jason Coco <email@hidden>
References: 
 >Image from font file (From: Georg Seifert <email@hidden>)
 >Re: Image from font file (From: Jason Coco <email@hidden>)

  • Prev by Date: Re: Can I put UTIs in NSFilesPromisePboardType promise drag array?
  • Next by Date: NSTask and get results
  • Previous by thread: Re: Image from font file
  • Next by thread: Re: Image from font file
  • Index(es):
    • Date
    • Thread