[翻译] Core Text Objective-C Wrapper
Core Text Objective-C Wrapper
https://github.com/akosma/CoreTextWrapper
Introduction(介绍)
One of the most promising and mysterious new frameworks introduced in iOS 3.2 is Core Text. Apple defines Core Text as a “text drawing engine”, which allows Mac (and now iPad) apps to render rich text on any graphics context. Strings drawn with Core Text feature lots of custom settings such as detailed font information, columns, variable line and paragraph heights and several different attributes, which designers and font aficionados surely understand much better than I do. Many new apps have been using this framework since the release of the iPad, particularly newspapers and ebook reader applications, rendering gorgeous text in custom fonts, many of them not available natively in iOS. This framework is also used in lifestyle and corporate applications, too, where using a custom font is sometimes required to match the specifications of brands and trademarks.
在 iOS 3.2 的时候,出现了一个功能强大但又神秘莫测的新框架 Core Text。苹果将 Core Text 定义为“绘制文本的引擎”,允许 Mac (如今也包括了 iPad)的应用程序在任何的绘图上下文中渲染富文本。用 Core Text 绘制的文本拥有非常多的定制特性,比如复杂的字体信息,列数,变化的行数以及段落的高度,还有许多其他的特性。那些开发者以及开发字体的人想必比我更了解 Core Text 的用武之地。许多新应用已经用上了这个框架,尤其是那些报纸或者电子书阅读器的应用。这个框架也同样用在一些生活类以及社团类的应用当中,因为这些应用有时候需要匹配一些特殊的字符与标记。

It is very important to understand that Core Text is really just a text drawing engine to be used on top of Quartz (Core Graphics), to render rich text on any graphics context. Core Text cannot be used to create a rich text editor, for example, so don’t expect to extend UITextView with it. But you can use it to draw any kind of rich text on screen, which can make you avoid using UIWebView instances for that.
Core Text 只是一个文本绘制的引擎,是在 Quartz 的上层封装的,他可以用来在任何的绘图上下文中渲染富文本,了解这一点非常重要。Core Text 是不能被用来当做富文本的编辑器来使用的。例如,不要指望靠 Core Text 来扩展 UITextView 。但是,你可以用它绘制任何形式的富文本,避免你使用 UIWebView 来做这些工作。
Features(特性)
One of the most interesting capabilities of Core Text is being able to render text in several columns. However, Core Text is a C-based framework, and I think that understanding and using the concepts and structures required to render text in columns can be particularly tricky. To make the my life and that of my fellow developers easier, this project contains a small set of Objective-C classes that encapsulate the creation of framesetters, attributed strings and other constructions, and takes care of the creation of several columns, as well as the division of the text in several pages if required.
Core Text 一个非常有意思的特性就是能够将文本分成几列来渲染。然而,Core Text 是基于 C 语言的框架,所以,我觉得,了解那些能够把文本渲染成几列的方法将会十分有难度。为了让我自己少走弯路以及服务于广大的开发者,这个项目包含了一系列的 OC 封装的类,他们封装了frame设置相关的内容,带有特殊属性的字符串以及一些结构,以及小心处理了分列的特性,同时也包括了如何把文本分成几页。
The API interface is very simple (on purpose) and I’m pretty sure you’ll be able to integrate it very easily in your own projects, particularly if you look at the sample project where the classes are used. I’ve also added a category for UIFont, that returns the associated CTFontRef pointer, in a similar fashion to UIImage, which is able to return a pointer to the underlying CGImageRef pointer. It also allows to create a CTFontRef from any font embedded in the application bundle. I am puzzled that the framework designers haven’t included this by default in UIKit.
这些 API 接口非常的简单,我十分确定,你能十分轻易的将它融入到你的项目当中,尤其是你研究了那些包含了这些类使用方法的 demo 。我给 UIFont 添加了一个类目,他是用来返回一个相关联的 CTFontRef 的指针,类似于 UIImage 那样子。它允许你从嵌入到文件当中的字体文件引出指针。我都有点奇怪,为何这个框架的设计者竟然没有把这个特性加入到 UIKit 中。
What’s next(接下来要做的)
A future extension I’d like to add would be a couple of categories to parse simple RTF or HTML strings (to start with, probably just with bold and italic text) and create the appropriate attributed string from it; there’s a couple of AppKit extensions to NSAttributedString that do exactly that, but for the moment they are only available in the Mac version of Cocoa, and I haven’t found anything similar for iOS yet.
下一个版本中,我将添加一些类目用来解析简单的 RTF 或者 HTML 字符串,并能将他们渲染成富文本。实际上有着很多的 AppKit 扩展了 NSAttributedString ,都可以完成那些功能了,但是,此刻,他们仅仅针对与 Mac ,我还没发现任何与 iOS 相关的呢。
附录:
本人修改的源码地址: http://pan.baidu.com/s/1mgsilS0
[翻译] Core Text Objective-C Wrapper的更多相关文章
- Core Text概述
本文是我翻译的苹果官方文档<Core Text Overview> Core Text框架是高级的底层文字布局和处理字体的技术.它在Mac OS X v10.5 and iOS 3.2开始 ...
- Core Text
Core Text 本文所涉及的代码你可以在这里下载到 https://github.com/kejinlu/CTTest,包含两个项目,一个Mac的NSTextView的测试项目,一个iOS的Cor ...
- CoreText学习(一)Base Objects of Core Text
最近要做一个读入Word,PDF格式等的文件并且加以编辑的程序,本来以为使用Text Kit结合Text View来打开doc文件是完全没问题的,结果用了各种方法打开要么是数据是nil,要么打开的文字 ...
- IOS利用Core Text对文字进行排版 - 转
原贴地址:http://hi.baidu.com/jwq359699768/blog/item/5df305c893413d0a7e3e6f7b.html core text 这个包默认是没有的,要自 ...
- 基于Core Text实现的TXT电子书阅读器
本篇文章的项目地址基于Core Text实现的TXT电子书阅读器. 最近花了一点时间学习了iOS的底层文字处理的框架Core Text.在网上也参考很多资料,具体的资料在文章最后列了出来,有兴趣的可参 ...
- Core Text 入门
本文所涉及的代码你可以在这里下载到 https://github.com/kejinlu/CTTest,包含两个项目,一个Mac的NSTextView的测试项目,一个iOS的Core Text的测试项 ...
- Gradle 1.12用户指南翻译——第四十八章. Wrapper 插件
本文由CSDN博客貌似掉线翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...
- [IOS/翻译]Core Services Layer
本文是本人自己辛苦翻译的,请转载的朋友注明,翻译于Z.MJun的CSDN的博客 http://blog.csdn.net/Zheng_Paul,感谢. 翻译于2015年10月4日 Core Servi ...
- [翻译] FastReport "Text" 对象中使用表达式
文本对象的最重要的功能之一是它不仅能够显示静态文本还能显示表达式.表达式混合在正常的文本内容中,让我们看一个简单的例子,他是如何工作的.在文件对象的内容中,输入以下字符: Hello, World! ...
随机推荐
- 20169211《Linux内核原理及分析》第十二周作业
Collabtive 系统 SQL 注入实验 实验介绍 SQL注入漏洞的代码注入技术,利用web应用程序和数据库服务器之间的接口.通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串, ...
- 安卓代码混淆(Android Studio)
Proguard是安卓提供的方便开发者对代码和apk进行保护和精简的工具,可在SDK/tools文件夹下找到. proguard的作用 : 1,代码混淆 2,精简代码,删掉没有用到的代码,减小ap ...
- Picasso:开启大前端的未来
“道生一,一生二,二生三,三生万物.” —— <道德经> Picasso是大众点评移动研发团队自研的高性能跨平台动态化框架,经过两年多的孕育和发展,目前在美团多个事业群已经实现了大规模的应 ...
- JAVAEE——宜立方商城07:Linux上搭建Solr服务、数据库导入索引库、搜索功能的实现
1. 学习计划 1.Solr服务搭建 2.Solrj使用测试 3.把数据库中的数据导入索引库 4.搜索功能的实现 2. Solr服务搭建 2.1. Solr的环境 Solr是java开发. 需要安装j ...
- C# 非模式窗体show()和模式窗体showdialog()的区别
对话框不是模式就是无模式的.模式对话框,在可以继续操作应用程序的其他部分之前,必须被关闭(隐藏或卸载).例如,如果一个对话框,在可以切换到其它窗 体或对话框之前要求先单击"确定"或 ...
- Revit二次开发示例:DeleteDimensions
在本例中,创建一个命令,实现删除所选中的尺寸标注. #region Namespaces using System; using System.Collections.Generic; using S ...
- Fiddler手机抓包,相关细节回顾
目录 0. 准备工作 1. Fiddler配置 2. iPhone配置 3. 抓包示例 上篇Fiddler教程,我们教了大家Fiddler安装配置及如何使用Fiddler进行基本的Http抓包及模拟请 ...
- 用Python开始机器学习(3:数据拟合与广义线性回归)
机器学习中的预测问题通常分为2类:回归与分类. 简单的说回归就是预测数值,而分类是给数据打上标签归类. 本文讲述如何用Python进行基本的数据拟合,以及如何对拟合结果的误差进行分析. 本例中使用一个 ...
- sublime3176注册码破解汉化及常用插件
官方网站下载地址:https://www.sublimetext.com/3 破解软件下载地址:https://www.lanzous.com/i1a7zfi 破解软件下载地址备用:https://d ...
- [BZOJ4881][Lydsy1705月赛]线段游戏
首先冷静一下看清问题的本质,是将整个数列分成两个递增子序列. 那么由Dilworth定理得,无解当且仅当数列的最长下降子序列的长度>2,先特判掉. 然后就有一些比较厉害的做法:http://ww ...
