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的更多相关文章

  1. Core Text概述

    本文是我翻译的苹果官方文档<Core Text Overview> Core Text框架是高级的底层文字布局和处理字体的技术.它在Mac OS X v10.5 and iOS 3.2开始 ...

  2. Core Text

    Core Text 本文所涉及的代码你可以在这里下载到 https://github.com/kejinlu/CTTest,包含两个项目,一个Mac的NSTextView的测试项目,一个iOS的Cor ...

  3. CoreText学习(一)Base Objects of Core Text

    最近要做一个读入Word,PDF格式等的文件并且加以编辑的程序,本来以为使用Text Kit结合Text View来打开doc文件是完全没问题的,结果用了各种方法打开要么是数据是nil,要么打开的文字 ...

  4. IOS利用Core Text对文字进行排版 - 转

    原贴地址:http://hi.baidu.com/jwq359699768/blog/item/5df305c893413d0a7e3e6f7b.html core text 这个包默认是没有的,要自 ...

  5. 基于Core Text实现的TXT电子书阅读器

    本篇文章的项目地址基于Core Text实现的TXT电子书阅读器. 最近花了一点时间学习了iOS的底层文字处理的框架Core Text.在网上也参考很多资料,具体的资料在文章最后列了出来,有兴趣的可参 ...

  6. Core Text 入门

    本文所涉及的代码你可以在这里下载到 https://github.com/kejinlu/CTTest,包含两个项目,一个Mac的NSTextView的测试项目,一个iOS的Core Text的测试项 ...

  7. Gradle 1.12用户指南翻译——第四十八章. Wrapper 插件

    本文由CSDN博客貌似掉线翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...

  8. [IOS/翻译]Core Services Layer

    本文是本人自己辛苦翻译的,请转载的朋友注明,翻译于Z.MJun的CSDN的博客 http://blog.csdn.net/Zheng_Paul,感谢. 翻译于2015年10月4日 Core Servi ...

  9. [翻译] FastReport "Text" 对象中使用表达式

    文本对象的最重要的功能之一是它不仅能够显示静态文本还能显示表达式.表达式混合在正常的文本内容中,让我们看一个简单的例子,他是如何工作的.在文件对象的内容中,输入以下字符: Hello, World! ...

随机推荐

  1. .gitignore文件如何编写?

    .gitignore文件即 项目中不需要被追踪(track)且上传到git系统的文件 <1>忽略文件的原则 a.忽略操作系统自动生成的文件,比如缩略图等 b.忽略编译生成的中间文件.可执行 ...

  2. 【BZOJ】1016: [JSOI2008]最小生成树计数

    题解 考虑kruskal 我们都是从边权最小的边开始取,然后连在一起 那我们选出边权最小的一堆边,然后这个图就分成了很多联通块,把每个联通块内部用矩阵树定理算一下生成树个数,再把联通块缩成一个大点,重 ...

  3. 004 Hadoop2.x基础知识

    一:大数据应用 1.Cloudera cloudera公司是Hadoop三大发行商之一,其版本为CDH版本,现在最新的版本是CDH5. 网站:http://archive.cloudera.com/c ...

  4. forkcms 开启调试模式

    You can enable debug mode by adding "SetEnv FORK_DEBUG 1" in your virtualhosts file.

  5. MySQL大事务导致的Insert慢的案例分析

    [问题] 有台MySQL服务器不定时的会出现并发线程的告警,从记录信息来看,有大量insert的慢查询,执行几十秒,等待flushing log,状态query end [初步分析] 从等待资源来看, ...

  6. DMA

    DMA:如果将一串字符串通过串口传送到外设中去,用传统的方法,则CPU将不断的去扫描UTSTAT这个寄存器,在字符发送期间,CPU将不能做任何其他事情.为了解决这个问题,则在诞生了DMA CPU只需要 ...

  7. fiddler 手机装证书

    1: 打开浏览器的地址 输入fiddler 右上方的地址 172.21.14.197:8888 2: 然后点击页面里的 FiddlerRoot certificate 3: 最后验证下   iOS 1 ...

  8. 【推导】【贪心】Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2) D. Riverside Curio

    题意:海平面每天高度会变化,一个人会在每天海平面的位置刻下一道痕迹(如果当前位置没有已经刻划过的痕迹),并且记录下当天比海平面高的痕迹有多少条,记为a[i].让你最小化每天比海平面低的痕迹条数之和. ...

  9. 【最短路Dijistra】【一般堆优化】【配对堆优化】

    突然觉得堆优化$O(log_n)$的复杂度很优啊,然而第n次忘记了$Dijistra$怎么写QAQ发现之前都是用的手写堆,这次用一下$stl$ #include<bits/stdc++.h> ...

  10. py脚本打包exe可执行文件

    python3以上版本打包exe需要扩展软件:cx_freeze 下载地址:http://cx-freeze.sourceforge.net/ 1)安装后在\Python32\Scripts\cxfr ...