Papyrix, being some ereader (specifically Xteink X3/X4) firmware, must fit the paragraphs you wish to read onscreen! So today I'll continue my study of its text-wrapping code!
Naturally I'll be wanting to port this code for my "merephone" project, so your SMS texts fit onscreen.
A faster codepath that can scale to excessively large paragraphs iterates over batches of parsed words, with an abort-callback checked in each iteration.
1/?
Until no words are left in this fast-path it grabs a maximum number of words to wrap in a recursive layout-object & recurses into these layout-methods, reclaims any words not laid out, & propagates completions or errors.
The core layout logic may involve validating that there's words to layout, constructing some lookuptables, iterating over all words, reformatting results into chosen line breaks & reversing that array, & falls back to single-word per line.
2/?