• 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: Jason Coco <email@hidden>
  • Date: Thu, 30 Oct 2008 15:22:17 -0400


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

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: Georg Seifert <email@hidden>
References: 
 >Image from font file (From: Georg Seifert <email@hidden>)

  • Prev by Date: Re: Porting from Windows to Mac
  • Next by Date: Re: Can I put UTIs in NSFilesPromisePboardType promise drag array?
  • Previous by thread: Image from font file
  • Next by thread: Re: Image from font file
  • Index(es):
    • Date
    • Thread