问题
I have downloaded a font from the internet. Now I want to Print the Characterset of that font. I got the CFCharacterSetRef of that font. But I don't know how to print that CFCharacterSetRef. This is my coding.
NSString *fontFilePath=@"/Volumes/Work/Mac/Fonts/FONT FOLDER/AngelicWar";
CFStringRef aCFString = (CFStringRef)fontFilePath;
CTFontRef fontRef = CTFontCreateWithName(aCFString, 0.0,NULL);
CFCharacterSetRef charRef=CTFontCopyCharacterSet (fontRef);
For Printing the alphanumericCharacterSet I will use like this.
NSCharacterSet *characterset = [NSCharacterSet alphanumericCharacterSet];
unichar idx;
for( idx = 0; idx < 256; idx++ )
{
if ([characterset characterIsMember: idx])
{
if ( isprint(idx) ) {
NSLog(@"%c",idx);
}
else {
printf( "%02x ", idx);
}
}
}
But I don't know to modify this code to print the characterset of that font.
回答1:
CFCharacterSetRef
and NSCharacterSet *
are toll-free bridged, so you're nearly there. Replace the first line of your second snippet with:
NSCharacterSet *characterset = (NSCharacterSet *) CTFontCopyCharacterSet (fontRef);
…and you're there.
Keep in mind that NSCharacterSet can contain Unicode characters (i.e, with indexes above 256). Depending on what you're trying to do here, this may or may not matter.
来源:https://stackoverflow.com/questions/6991686/how-to-print-the-characterset-of-a-font