Re: Using a font without installing it
Re: Using a font without installing it
- Subject: Re: Using a font without installing it
- From: Shaun Wexler <email@hidden>
- Date: Sun, 16 Jan 2005 12:14:19 -0800
On Jan 16, 2005, at 12:43 AM, Stefan Landvogt wrote:
Shauns code that loads all fonts in a certain directory. Call this
method in your AppDelegate...
Be aware, that fonts have also copyright, before you distribute them
with your application.
I learned by the hard way, that Myriad Web Bold is not public domain...
- (void)loadLocalFonts {
NSString *fontsFolder = [[NSBundle mainBundle] resourcePath]; //[
stringByAppendingPathComponent:@"Fonts"];
if (fontsFolder) {
NSURL *fontsURL = [NSURL fileURLWithPath:fontsFolder];
if (fontsURL) {
FSRef fsRef;
FSSpec fsSpec;
(void)CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
OSStatus status = FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL,
NULL, &fsSpec, NULL);
if (noErr == status) {
FMGeneration generationCount = FMGetGeneration();
status = FMActivateFonts(&fsSpec, NULL, NULL,
kFMLocalActivationContext);
generationCount = FMGetGeneration() - generationCount;
}
}
}
}
The generationCount was only necessary because I printed a log message
indicating how many new fonts were installed. You could simplify it to
this:
- (void)loadLocalFonts
{
NSString *fontsFolder;
if ((fontsFolder = [[NSBundle mainBundle] resourcePath])) {
NSURL *fontsURL;
if ((fontsURL = [NSURL fileURLWithPath:fontsFolder])) {
FSRef fsRef;
FSSpec fsSpec;
(void)CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
if (FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec,
NULL) == noErr) {
FMActivateFonts(&fsSpec, NULL, NULL, kFMLocalActivationContext);
}
}
}
}
--
Shaun Wexler
MacFOH
http://www.macfoh.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden