2010-04-24 11 views

Respuesta

10

Parece que CTFontManagerCreateFontDescriptorsFromURL es la sustitución del texto principal.

+2

y hace que para [código más corta que la ruta núcleo de gráficos] (https: //gist.github. com/1696100). –

18

Usted puede obtener una CTFontRef de un archivo de fuente por ir a través de un CGFontRef:

CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("/path/to/font"), kCFURLPOSIXPathStyle, false); 
CGDataProviderRef dataProvider = CGDataProviderCreateWithURL(url); 
CGFontRef theCGFont = CGFontCreateWithDataProvider(dataProvider); 
CTFontRef theCTFont = CTFontCreateWithGraphicsFont(theCGFont); 
CFRelease(theCGFont); 
CFRelease(dataProvider); 
CFRelease(url); 

// do something with the CTFontRef here 

CFRelease(theCTFont); 
+0

Esto no funciona en Snow Leopard (confirmado por Apple) y debe usar 'ATSFontActivateFromMemory()' solo en esa versión de OS X. – trojanfoe

+0

No se puede confirmar esto. Funciona bien aquí en Snow Leopard. – Andreas

4
NSURL *fontURL = [[NSBundle mainBundle] URLForResource:@"Crystal" withExtension:@"ttf"]; 
    assert(fontURL); 
    CFErrorRef error = NULL; 
    if (!CTFontManagerRegisterFontsForURL((__bridge CFURLRef)fontURL, kCTFontManagerScopeProcess, &error)) 
    { 
     CFShow(error); 
     abort(); 
    } 
+1

esto funcionó para mí, ¡gracias! – MiMo

Cuestiones relacionadas