从一个字体家族和特性中创建一个字体描述符
CTFontDescriptorRef CreateFontDescriptorFromFamilyAndTraits(CFStringRef iFamilyName,CTFontSymbolicTraits iTraits,CGFloat iSize)
{
CTFontDescriptorRef descriptor = NULL;
CFMutableDictionaryRef attributes;
assert(iFamilyName != NULL);
//创建一个可变字典存储字体属性
attributes = CFDictionaryCreateMutable(kCFAllocatorDefault,0,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks);
check(attributes != NULL);
if(attributes != NULL)
{
CFMutableDictionaryRef traits;
CFNumberRef symTraits;
//添加一个字体家族到字体属性
CFDictionaryAddValue(attributes,kCTFontFamilyNameAttribute,iFamilyName);
创建属性字典
symTraits = CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt32Type,&iTraits);
check(symTraits != NULL);
if(symTraits != NULL)
{
trais = CFDictionaryCreateMutable(kCFAllocatorDefault,0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionayrValueCallBacks);
check(trais != NULL);
if(traits != NULL)
{
//添加带符号特性到特性字典中
CFDictionaryAddValue(traits,kCTFontSymbolicTrait,symTraits);
//添加特性属性到字典中
CFDictionaryAddValue(traits,kCTFontTraitsAttribute,trais);
CFRelease(traits);
}
CFRelease(symTraits);
}
//使用属性和大小创建字体描述符
descriptor = CTFontDescriptorCreateWithAttributes(attributes);
check(descriptor != NULL);
CFRelease(attributes);
}
//返回字体描述符
return descriptor;
}