GraphicsUtils.m
changeset 3 8fad19466c59
parent 2 3d3dcc3116d5
child 5 c9f2e0c7359a
     1.1 --- a/GraphicsUtils.m	Wed Apr 02 14:45:33 2008 -0700
     1.2 +++ b/GraphicsUtils.m	Sun Apr 06 19:13:27 2008 -0700
     1.3 @@ -6,6 +6,8 @@
     1.4  //
     1.5  
     1.6  #import "GraphicsUtils.h"
     1.7 +#import "FileUtils.h"
     1.8 +#import <ApplicationServices/ApplicationServices.h>
     1.9  
    1.10  
    1.11  @implementation NSImage (MYUtilities)
    1.12 @@ -241,3 +243,32 @@
    1.13      return r;
    1.14      
    1.15  }
    1.16 +
    1.17 +
    1.18 +OSStatus LoadFontsFromBundle( NSBundle *bundle )
    1.19 +{
    1.20 +    NSString *fontsPath = [[bundle resourcePath] stringByAppendingPathComponent:@"Fonts"];
    1.21 +    if( fontsPath )
    1.22 +        return LoadFontsFromPath(fontsPath);
    1.23 +    else
    1.24 +        return fnfErr;
    1.25 +}
    1.26 +
    1.27 +
    1.28 +OSStatus LoadFontsFromPath( NSString* path )
    1.29 +{
    1.30 +    // Tip of the hat to Buddy Kurz!
    1.31 +    FSRef fsRef;
    1.32 +    OSStatus err = PathToFSRef(path,&fsRef);
    1.33 +    if (err==noErr)
    1.34 +        err = ATSFontActivateFromFileReference(&fsRef,
    1.35 +                                               kATSFontContextLocal,
    1.36 +                                               kATSFontFormatUnspecified,
    1.37 +                                               NULL,
    1.38 +                                               kATSOptionFlagsDefault,
    1.39 +                                               NULL
    1.40 +                                               );
    1.41 +    if( err ) Warn(@"LoadFontsFromPath: Error %i for %@",err,path);
    1.42 +    return err;
    1.43 +}
    1.44 +