Coder Social home page Coder Social logo

alexisod / coretextwrapper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from akosma/coretextwrapper

1.0 1.0 0.0 151 KB

An Objective-C wrapper around Core Text for creating multi-column text and loading custom fonts

Home Page: http://akosma.com/2010/07/08/core-text-objective-c-wrapper/

License: BSD 3-Clause "New" or "Revised" License

coretextwrapper's Introduction

Core Text Objective-C Wrapper

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.

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.

Features

One of the most interesting capabilities of Core Text is being able to render text in several columns. However, Core Test 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.

The API interface is very simple (in 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.

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.

Thanks

The following people have helped this project grow, with pull requests, comments or bug reports:

  • Jared Crawford contributed support for shadows in AKOCustomFontLabel.
  • Christian Menschel contributed the AKOMultiColumnTextViewDataSource protocol to add custom views in the text columns.

License

The code, as usual, is available through with BSD license (see the LICENSE file), so feel free to use it and even contribute bug fixes or enhancements if you want. The font embedded in the project is Polsku Regula, available through the Open Font Library.org. The project requires Xcode 3.2.3 and the iOS SDK 4.0, and it creates a simple application that works on the iPad (iOS 3.2). As usual, use it at your own risk. Enjoy!

coretextwrapper's People

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.