[翻译] 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! ...
随机推荐
- Kafka(四)Kafka在zookeeper中的存储
一 Kafka在zookeeper中存储结构图 二 分析 2.1 topic注册信息 /brokers/topics/[topic] : 存储某个topic的partitions所有分配信息 [zk: ...
- 【POJ】1286.Necklace of Beads
题解 群论,我们只要找出所有的置换群的所有循环节 具体可参照算法艺术与信息学竞赛 旋转的置换有n个,每一个的循环节个数是gcd(N,i),i的范围是0到N - 1 翻转,对于奇数来说固定一个点,然后剩 ...
- sqoop遇到的问题
我使用的是CDH版本的 这是我的sqoop脚本 sudo -u hive sqoop import --connect jdbc:mysql://xxxx/rom3 --username xxx -- ...
- JavaScript对象参考手册
1.array 属性: constructor 返回原型函数: length 数组个数: prototype 向对象添加属性和方法 方法: concat() 连接两个或多个数组,并返回结果: fill ...
- lnmp 一键安装包
系统需求: CentOS/RHEL/Fedora/Debian/Ubuntu/Raspbian Linux系统 需要5GB以上硬盘剩余空间 需要128MB以上内存(如果为128MB的小内存VPS,Xe ...
- Wannafly挑战赛9 B - 数一数
链接:https://www.nowcoder.com/acm/contest/71/B来源:牛客网 题目描述 设s,t为两个字符串,定义f(s,t) = t的子串中,与s相等的串的个数.如f(&qu ...
- 一个将PDF转word、图片、PPT的在线工具
smallpdf 真的超级棒! https://smallpdf.com/cn
- JAVAEE——宜立方商城02:服务中间件dubbo、工程改造为基于soa架构、商品列表实现
1. 学习计划 第二天:商品列表功能实现 1.服务中间件dubbo 2.工程改造为基于soa架构 3.商品列表查询功能实现. 2. 将工程改造为SOA架构 2.1. 分析 由于宜立方商城是基于soa的 ...
- 内核启动文件系统后第一个执行的文件(inittab启动脚本分析)
Linux 开机脚本启动顺序: 第一步:启动内核 第二步:执行init (配置文件/etc/inittab) 第三步:启动相应的脚本,执行inittab脚本,并且执行里面的脚本/etc/init.d ...
- [ 原创 ] Java基础2--构造方法的继承和重载
1.构造方法的重载是指同一个类中定义不同参数的多个构造方法,已完成不同情况下对象的初始化. 例如: Point(); Point(x); Point(x,y); 2.一个类的若干个构造方法之间可以相互 ...
