Burro

Progress on fixing layout bug

Weekly progress update since 2023-09-29 • 2023-10-05Michael Rees


The major bug is (almost) fixed

I'm happy to share that I've (finally) made some serious headway into fixing the major layout bug that's been holding back the 0.1 release! The code isn't ready to be merged yet, but here's a screenshot showing several standard features, including a line that demonstrates the bugfix.

Screenshot showing several text layout features in combination

In particular, note the fourth paragraph, which is right aligned and changes letter spacing midway through. Previously, this would have caused lots of text to be emitted on top of itself along the right margin. Now, the text is emitted in the right places (across a line break as well!).

New layout method

To make this work, I've reworked the layout algorithm. Now, whenever Burro would have printed the temporary buffer of words to the page, Burro stores the temporary buffer as a series of "emit chunks." These emit chunks are only printed to the page whenever we hit a newline, allowing us to finalize the words on the page. This has several advantages. Of course, it fixes the bug caused by emitting text too early when right aligned. However, it also lets us have more fine-grained control over the space widths, since we track those as emit chunks as well.

In theory, this will allow us to have different space widths in justified text as well, so that .space_width has an impact on justified text.

Merging

This code still has a way to go before it can be merged. For one thing, the code is an absolute mess. It currently has both Words and EmitChunks and converts between the two. Some functions are duplicated to accepted either type, e.g., justified_space_width and justified_space_width_chunked. Once things are cleaned up, I think it should be possible to move the entire algorithm to EmitChunk and remove Word entirely.

Although the demo screenshot above functions, testing the new algorithm on several more complicated features, such as tab stops and horizontal rules, shows that there are still bugs to iron out. I don't think any of that will be too difficult, but it obviously needs to be done before merging.

In other words, I can't wait for layout tests, one of the planned features for 0.2.

Have a comment or want to start a discussion? Please email it to the Burro discussion list!