如何打印字体的特征集? [英] How to Print the characterset of a Font?

查看:148
本文介绍了如何打印字体的特征集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从互联网上下载了一种字体.现在,我要打印该字体的字符集.我得到了该字体的CFCharacterSetRef.但是我不知道如何打印CFCharacterSetRef.这是我的编码.

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);  

对于打印alphanumericCharacterSet,我将像这样使用.

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.

推荐答案

CFCharacterSetRefNSCharacterSet *是免费的桥接,所以您快到了.将第二个片段的第一行替换为:

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);

…而你在那里.

请记住,NSCharacterSet可以包含Unicode字符(即,索引大于256).根据您要在此处执行的操作,这可能会或可能不会重要.

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.

这篇关于如何打印字体的特征集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆