How to Print the characterset of a Font?

不想你离开。 提交于 2019-12-08 02:45:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!