This is pretty much the exact motivation for the group() feature
that's new in master and scheduled for Prawn 0.6:
http://github.com/sandal/prawn/blob/master/lib/prawn/document.rb#L392
If that's not quite what you're looking for, you should be able to
adapt it for your needs. The big change was the transactional
rendering support that we factored in, which lets you render a block
and then roll it back (for example, if it overflowed onto another
page, as in this example).
Brad
I'm starting to get a picture of what's going on here. But this is
still pretty complicated. It would help if you could reduce it to a
minimal test case (with code and non-confidential data) that explains
the problem and how you're trying to solve it. That way the rest of us
can try tweaking things and can reproduce the errors on our own.
In Prawn terms, what group() does is:
1. Attach itself to its containing bounding box, and intercept any
time that bounding box tries to flow to a new page inside the group()
block.
2. If/when that happens, roll back any of the drawing that has been
done, tell the bounding box to start a new page, and draw again there.
This "tell the bounding box to start a new page" part may be where the
issue comes into play -- the transaction code by itself does not
adjust the y-position, leaving it up to the bounding box to do that.
Take a look at the group() code and ask any questions you might have.
I haven't done anything as complicated as your nested bounding box
example, and I wrote the code for group(), so it's very possible that
this is a bug. :-) Like I said, if you can mock this up in a
pure-Prawn example that the rest of us can run, it will be easier to
see what you're trying to do.
Brad
I'm glad that solved your problem. FYI, there's an undocumented (thus
as-yet unsupported) method called mask() that allows you to execute a
block while preserving the value of a few attributes. Your three lines
after "...some text..." could be written like this:
pdf.mask(:y) { ... do all the stuff from first bounding box / span ... }
I'll caution you again that it's undocumented and unsupported, but
it's probably a more readable option than manually mucking around with
the y attribute.
Brad