The previous release of DTCoreText was in February, 7 months ago, so it was about time to release an update for the about 50 commits that were made by community contributors since then.
- ADDED: Support for <p> text-indent
- ADDED: Support width attribute in percent for text attachments
- ADDED: Ability to abort HTML parsing
- ADDED: Archiving
- ADDED: Improved support for macOS
- FIXED: Incorrect file name in import should be DTCSSStylesheet.h
- FIXED: HTML generation with multi-line links
- FIXED: Do not add Apple-converted-space to attributed string when processing custom HTML attributes
- FIXED: Ignore list style shorthands that are not strings
- FIXED: Wrong attributed substring passed to generic custom view when using truncation
- FIXED: Avoid unnecessary drawing of DTAttributedTextContentView if it is being deallocated
- FIXED: Changing properties on DTCoreTextLayoutFrame would not update layout, resulting in incorrect sizing information being returned
I also went through the GitHub Issues and closed all the ones that have neither had any discussion in a long while. Most of them were questions which were long answered or are requests which nobody is willing to implement.
There are two requests/questions which I would like to answer here:
- How about supporting synthetic italics for Chinese?
- How about supporting HTML tables?
iOS TextKit does not have any fonts for showing Chinese glyphs in italic. The effect can be achieved by adding a slanting transform to the font. In fact this is already done during font matching. Why this is not working for Chinese script is a mystery to me. I’m interested if somebody can provide a fix via pull request.
About HTML tables… the problem here is that in order to support that we’d have to do two major things: First we need to parse the HTML tags related to tables (table, td, tr, etc.) into some temporary storage and then we need to build a text attachment from that. The second step would be to generate an image or a custom subview that is able to properly layout and render the table contents.
In all the years I have never met anybody using DTCoreText who would be willing to pay me for implementing that.
The maintenance update is tagged on GitHub and also available via Cocoapods.
How about DTCoreText 2.0?
And actually… there are other changes to DTCoreText which would need to happen before adding any such new features could reasonably be added. I’d rather start working on a successor to DTCoreText 1.x.
To name a few examples of different design choices for a new start:
- Nowadays, I would write it in Swift
- We could still use libxml for parsing HTML but I would make it UIKit-compatible exclusively.
- UILabel and UITextView support attributed strings for many years now, there is simply no good reason to keep using the attributed label from DTCoreText 1.x.
- Text attachment would solely be modelled with NSTextAttachment, including support for asynchronous images.
- Via UITextView we would also get automatic support for Rich Text editing. Instead of using DTRichTextEditor, editing would then be built into iOS and macOS.
- Unfortunately Apple still doesn’t give us support for creating text lists, although iOS seems to internally support NSTextList and NSTextBlock. But we can probably hack around that in a way that is App Store-compatible.
- Using TextKit’s layout facilities it would also finally be possible to have text flow around floating images
I’ve gathered a lot of experience dealing with attributed strings without using DTCoreText, solely relying on built-in functionality. And from that I can tell you that it is possible and worth the effort.
I’d love to have a company sponsor a new start. If you’re interested to help fund it, please get in touch.
Also published on Medium.