当前位置: 动力学知识库 > 问答 > 编程问答 >

Programatically getting the version of a font in OSX

问题描述:

When you look at information for a font in FontBook in OSX, it lists all kinds of useful information, including Language, Version, Unique name, etc. Is there a nice way to get any/all of this information from objective C? In particular, I want to get the Version of a font.

I know how to make a CTFontDescriptorRef but I don't see any attributes on it that would give me the Version. I've looked similarly at NSFontDescriptor but not found anything, and googling hasn't helped.

I need to do this because the app I work on runs in Chinese, and I know that one font looks better than another as long as I have a "late enough" version of the font installed. So I'd like to use a particular font if the later version is installed, and otherwise fall back to another font.

网友答案:

Well I stumbled upon the answer five minutes after posting. I was basically looking at the wrong place, hoping to find it in CTFontDescriptorRef. It looks like the right place to look is CTFontRef, which you can create from a CTFontDescriptor via CTFontCreateWithFontDescriptor.

Then you can use CTFontCopyAttribute, and a bunch of different things are available, namely kCTFontVersionNameKey.

分享给朋友:
您可能感兴趣的文章:
随机阅读: