参考文章:http://blog.csdn.net/fengsh998/article/details/8691823
目前在研究CoreText相关技术,顺便写一点笔记和心得,由于经验有限,有些东西只是个人的猜想,不一定正确,望指正 。。。
1,对core text框架的一点理解(整理中。。。。)
core text其实只是一个文本布局渲染框架,它并不负责绘制文本,它的主要功能就是设置文本(字符串)的各种绘制属性以及布局信息,如字体、颜色、字形、段落样式等属性以及绘制区域等布局信息,最后通过core graphic框架将文本绘制出来。
在core text中,起关键作用的一个对象是:NSAttributedString(CFAttributedStringRef)和CTFrameRef, AttributedString存储了需要绘制的文本内容,以及文本的绘制属性;CTFrameRef负责管理文本的布局信息。
所以CoreText的使用主要有两个部分:1 创建属性字符串,并且设置属性 NSAttributedString; 2 创建文本绘制区域CTFrameRef。
图文混排:由于CoreText只是一个文本渲染框架,它只负责渲染文本内容,而决然不会去负责图片的绘制。图文混排,以及超链接的实现,其实是先通过特定的方式标记出需要特殊处理的文本,然后通过CTFrameRef计算出目标文本域的位置,然后再进行相应的处理,如绘制背景,设置触摸响应等。
2,core text设置文本属性的属性名解析
String Attribute Name
const CFStringRef kCTCharacterShapeAttributeName;//CFNumberRef对象,默认为0 const CFStringRef kCTFontAttributeName;//字体 CTFont Default is Helvetica 12. 与UIFont的默认值不同 const CFStringRef kCTKernAttributeName;//字符间隔属性,必须是CFNumberRef对象 const CFStringRef kCTLigatureAttributeName;//设置使用连字符属性。CFNumberRef对象,默认为1,表示使用标准的连字。可取值:0,1,2。A value of0
indicates that only ligatures essential for proper rendering of text should be used. A value of1
indicates that standard ligatures should be used, and2
indicates that all available ligatures should be used. Which ligatures are standard depends on the script and possibly the font.
const CFStringRef kCTForegroundColorAttributeName;//CGColor. default is black.
const CFStringRef kCTForegroundColorFromContextAttributeName;//上下文字体颜色 CFBoolean, 默认为false。If set, this attribute also determines the color used bykCTUnderlineStyleAttributeName
, in which case it overrides the foreground color.
const CFStringRef kCTParagraphStyleAttributeName;//段落样式属性。必须是CTParagraphStyle,默认为nil
const CFStringRef kCTStrokeWidthAttributeName;//笔画线条宽度CFNumberRef,默认是0.0f,标准是3.0f
const CFStringRef kCTStrokeColorAttributeName;//笔画颜色,默认为与前景色相同
const CFStringRef kCTSuperscriptAttributeName;//设置字体的上下标属性 必须是CFNumberRef对象 默认为0,-1为下标,1为上标,需要字体支持。
const CFStringRef kCTUnderlineColorAttributeName;//默认与前景色相同 const CFStringRef kCTUnderlineStyleAttributeName;//CFNumberRef(CTUnderlineStyle,CTUnderlineStyleModifiers)
enum{
kCTUnderlineStyleNone = 0x00, kCTUnderlineStyleSingle = 0x01, kCTUnderlineStyleThick = 0x02, kCTUnderlineStyleDouble = 0x09 }; typedef int32_t CTUnderlineStyle;enum{ kCTUnderlinePatternSolid = 0x0000, kCTUnderlinePatternDot = 0x0100, kCTUnderlinePatternDash = 0x0200, kCTUnderlinePatternDashDot = 0x0300, kCTUnderlinePatternDashDotDot = 0x0400 }; typedef int32_t CTUnderlineStyleModifiers;
const CFStringRef kCTVerticalFormsAttributeName;//文字方向,默认为false,表示水平方向。
const CFStringRef kCTGlyphInfoAttributeName;//字体信息属性,必须为CTGlyphInfo对象
const CFStringRef kCTRunDelegateAttributeName//CTRun的代理,必须是CTRunDelegate对象
------------------------------------------以下纯属搬运工----------------------------------
字体的基本知识:
字体(Font):是一系列字号、样式和磅值相同的字符(例如:10磅黑体Palatino)。现多被视为字样的同义词
字面(Face):是所有字号的磅值和格式的综合
字体集(Font family):是一组相关字体(例如:Franklin family包括Franklin Gothic、Fran-klinHeavy和Franklin Compressed)
磅值(Weight):用于描述字体粗度。典型的磅值,从最粗到最细,有极细、细、book、中等、半粗、粗、较粗、极粗
样式(Style):字形有三种形式:Roman type是直体;oblique type是斜体;utakuc type是斜体兼曲线(比Roman type更像书法体)。
x高度(X height):指小写字母的平均高度(以x为基准)。磅值相同的两字母,x高度越大的字母看起来比x高度小的字母要大
Cap高度(Cap height):与x高度相似。指大写字母的平均高度(以C为基准)
下行字母(Descender):例如在字母q中,基线以下的字母部分叫下伸部分
上行字母(Ascender):x高度以上的部分(比如字母b)叫做上伸部分
基线(Baseline):通常在x、v、b、m下的那条线
描边(Stroke):组成字符的线或曲线。可以加粗或改变字符形状
衬线(Serif):用来使字符更可视的一条水平线。如字母左上角和下部的水平线。
无衬线(Sans Serif):可以让排字员不使用衬线装饰。
方形字(Block):这种字体的笔画使字符看起来比无衬线字更显眼,但还不到常见的衬线字的程度。例如Lubalin Graph就是方形字,这种字看起来好像是木头块刻的一样
手写体脚本(Calligraphic script):是一种仿效手写体的字体。例如Murray Hill或者Fraktur字体
艺术字(Decorative):像绘画般的字体
Pi符号(Pisymbol):非标准的字母数字字符的特殊符号。例如Wingdings和Mathematical Pi
连写(Ligature):是一系列连写字母如fi、fl、ffi或ffl。由于字些字母形状的原因经常被连写,故排字员已习惯将它们连写。
![](https://img-my.csdn.net/uploads/201303/18/1363571384_1226.gif)