MAC OSX 字体创建和储存(来自于CoreText翻译 Font Creation and Storage)(二)
2013-08-20 08:22
369 查看
从一个字体家族和特性中创建一个字体描述符
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;
}
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;
}
相关文章推荐
- MAC 字体创建和储存(来自于CoreText翻译 Font Creation and Storage)(一)
- [翻译] DTCoreText 从HTML文档中创建富文本
- 用Core Text创建简单杂志应用(3)
- 在iOS中UILabel作为一个文本标签,在实现程序中几乎每个页面都会用到UILabel,UILabel的常用属性:textColor(文本颜色),text(文本值),font(文本字体),textA
- CSS3文字与字体:text-overflow 与 word-wrap、@font-face、文本阴影text-shadow
- #259 – 对使用OpenType 字体的文本进行排版(Setting Typography Properties for Text Rendered with an OpenType Font)
- [翻译] Core Text Objective-C Wrapper
- CoreText 轻松设置字体大小,间距,行间距,段间距,算高度
- CoreText基础-字体必修课
- MTK 滚动字体 scrolling_text font size
- Font Configuration and Customization for Open Source Systems - 白皮书翻译和深入
- 谷歌字体(Google Font)初探 [翻译自Google官方文档]
- android:includeFontPadding的使用:清除TextView字体周边空白
- 创建模块化游戏 I(翻译)(Creating Moddable Games with XML and Scripting Part I)
- android:includeFontPadding的使用:清除TextView字体周边空白
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第二章:利用模型类创建视图、控制器和数据库
- preferredFontForTextStyle字体设置之更改
- 谷歌字体(Google Font)初探 [翻译自Google官方文档]
- 字体和文本布局(Fonts and TextLayout)
- [翻译] DFXCoreTextView