Adding backtracking functionality turns out not to be as simple as I'd
hoped. There are several elements to this:
- tracking on the fly if there are already enough elements created to
fill at least one flow reference area. If that limit is reached return
early and don't let the Knuth algorithm try to distribute the trailing
- after determining the break, you get a PageBreakPosition. With it it
is possible to find the last element in the current block list. Based in
the Position element of that element you have to reset the layout
managers much like this is done in the first-fit approach in CVS HEAD.
This turns out to be one of the more difficult parts as there are helper
elements that don't have so much information on them to do a proper
reset so for the next page the elements are started to be recreated
exactly where the previous page left off. So it may be necessary to
iterate the block list in forward direction until a key element (like a
normal line or block-container with fixed BPD) is found that has enough
information to do the reset. At least we still have nested position
elements so this is not impossible.
- the blocklist is rendered until the PageBreakPosition is reached, the
rest is discarded. Then the process is repeated with the LMs now reset
so they continue generating Knuth elements where the previous
page/column stopped.

One point in all this is also, how well the early-return point can be
determined to minimize the number of discarded elements. To make it even
more complicated (and to optimize) the elements could be reused if it is
determined that the same elements would be produced anyway because the
available IPD is the same for the next part/page.

Writing this stuff down really helps, but my head's giving smoke signs.
Gonna take a break now...

Jeremias Maerki

Reply via email to