I was hoping there would be a way to add Complex Text support with minimal changes to the existing text system. Unfortunately, due to the way Uniscribe (Window’s Complex Text API) works, this simply isn’t possible. Since this would require a complete overhaul I started thinking about what other kinds of features a next gen text system should support. I came up with two basic goals: support complex text, support functionality similar to Microsoft WordPad/Apple TextEdit.
I think these goals can be achieved through the following architecture:
Attributed String -> Script Processor -> Paragraph Processor -> Rectangle Processor -> Text Renderer
Attributed String
- Add font, color, paragraph attributes to a string as character ranges
Script Processor
- Determine the Glyphs for a string
- Determines where line breaks can occur
- Determines where word breaks can occur
- Provide caret information
Paragraph Processor
- Applies paragraph attributes before line breaking (indentation, tab stops)
- Performs line breaking (word wrap)
- Applies paragraph attributes after line breaking (alignment, line spacing)
Rectangle Processor
- Determine rectangles for highlighted text, selected text, underlined text, strikethrough text
Text Renderer
- Draw Rectangles
- Draw Text
- Draw Caret
Mac OS X is the easiest platform to support since Core Text can act as both the Script and Paragraph Processor.
Attributed String -> Core Text -> Rectangle Processor -> Text Renderer
Supporting Windows (XP+) is more involved:
Attributed String -> Uniscribe -> Paragraph Processor -> Rectangle Processor -> Text Renderer
The Linux/Multi-Platform solution look similar:
Attributed String -> Harfbuzz+FreeType -> Paragraph Processor -> Rectangle Processor -> Text Renderer
