CoreText 相关知识
2013-11-12 16:24
441 查看
目前在研究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 of[code]0indicates that only ligatures essential for proper rendering of text should be used. A value of
1indicates that standard ligatures should be used, and
2indicates that all available ligatures should be used. Which ligatures are standard depends on the script and possibly the font.[/code]
const CFStringRef kCTForegroundColorAttributeName;//CGColor. default is black. const CFStringRef kCTForegroundColorFromContextAttributeName;//上下文字体颜色 CFBoolean, 默认为false。If set, this attribute also determines the color used by[code]kCTUnderlineStyleAttributeName, in which case it overrides the foreground color.[/code]
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。由于字些字母形状的原因经常被连写,故排字员已习惯将它们连写。
相关文章推荐
- EditText的相关知识
- CoreText基本知识
- iOS coretext框架第一章 基础知识
- Android 相关知识 EditText焦点相关问题
- android EditText和输入法相关知识总结
- CoreText绘制基本知识
- Textview相关知识
- jvm内存相关的知识总结
- MAC OSX 字体创建和储存(来自于CoreText翻译 Font Creation and Storage)(二)
- 跨域原理 与 AJAX跨域调用相关知识-CORS和JSONP
- 如何使用MSDN搜索STL相关知识的一个小技巧
- git 相关知识整理
- 前端打印控件lodop的相关使用问题和相关的知识领域
- RAID及相关知识及命令
- cros 相关的知识总结
- 我的个人知识管理工具一览及相关经验技巧
- mysql数据库相关知识总结
- RecipientEditTextView相关类
- sizeof相关知识