Hi,
max wrote:What are some/where can I find out about best-practices when implementing good-performing/extendable text components?
Think of it as layers. First layer is a font engine capable of:
- Given a string, a font, a font size and an optional minimum width; telling you where each character would be (e.g. horizontal position of both left and right edge of each character) within a bitmap.
- Given a string, a font, a font size and an optional minimum width; converting a string into an "alpha channel only" bitmap
Note 1: If the optional minimum width is used, the font engine would increase the spacing between characters to ensure the string fills the width. This is mostly needed for "left and right justified" text.
Note 2: The string may include some sort of mark-up; including support for things like font changes, font size changes, bold, italics, underline, etc.
For efficiency, the font engine would have 2 caches. The first cache would hold the width of each character (for a specific font at a specific size) and any information needed for
kerning; and would be used to determine where each character would be within the bitmap. The second cache would hold "pre-rendered" bitmap data for each character (for a specific font at a specific size).
The second layer would be a layout engine. This handles thing like line wrapping, centering text, left and/or right justification, etc. Essentially, it splits a larger string into sub-strings (one sub-string per row of text), then asks the font engine to convert each sub-string into an "alpha channel only" bitmap, applies colour to the bitmaps (if necessary) and combines all of them into a larger (RGBA?) bitmap. Like the font engine, it would also be able to tell you where each character would be within a bitmap (e.g. top and bottom edge of each row from its own data, and horizontal position of left and right edge of each character within each row from the font engine).
Note: The strings used by the layout engine may include some sort of mark-up; which may be a super-set of the markup the font engine excepts (e.g. including additional things that the font engine doesn't accept, like foreground and/or background colour, line breaks, inline images, etc).
The third layer might be (e.g.) something like a "text widget" that handles user input, scroll bars, cut & paste, etc.
Cheers,
Brendan