Allow denoting possible split lines
Problem
Somehow I ended up building a pseudo DSL rendered with cetz for an amateur protocol documentation. However, those can end up being quite long when displayed, in this case also being several pages wide for one listing combining all of them in that document.
Possible solution
Implementation of split lines (name up to bikeshedding). Adding a split line at height k
- introduces a guillotine cut, where any drawn or to-be-drawn elements intersecting k on the y axis are split in half
- partitions all drawn elements into "above k" and "below k"
- creates two
contents, one for "above k" and "below k" respectively
Now, if the full drawing does happen to fit on one page, it is unmodified. However, if it doesn't, typst's layouting will hopefully take advantage of there actually being 2 distinct contents which can now be rendered.
This could also be scaled up to any number of split lines.
Tricky edge cases
- Round caps and joins of lines
- Should the cut ends also be round?
- Filled paths
- An additional edge would need to be generated at k
- How would this work with 3D? Or should it just act in "absolute" coordinates?
- When should processing of these split lines happen?
- As soon as they're declared? That'd mean any later added drawings would need to be added to either of the content, or somehow keep track of the splits
- Just buffered up until everything has been drawn? That'd mean it'd be unaffected by rotations, scales, and translations, or is that an advantage?
EDIT: Possible API design
rect((0, 0), (2, 2))
split-opportunity(1)
line((0, 0), (2, 2))
should result in something akin to this if typst takes advantage of the split opportunity/line at the page break (displayed here as dashed):
Other notes
This is slightly insane. Keeping this here anyway for further thoughts and input.
So breaking the canvas across pages if it doesn't fit? You're right it is slightly insane... but the more I think about it the more possible it is...
After all the elements have been processed the canvas does know its final size so it could split the drawables so that each part can fit in the correct space. Two issues I have with this, is how can we find how much space is left and how do we split content?
I don't think giving break hints to the canvas works in the way you think it does btw.
Split content could be drawn two times with a clip mask + an offset. Implementing this should definitely be possible.