cetz-package / cetz

CeTZ: ein Typst Zeichenpaket - A library for drawing stuff with Typst.
https://cetz-package.github.io
GNU Lesser General Public License v3.0
788 stars 35 forks source link

Allow denoting possible split lines #375

Open MultisampledNight opened 8 months ago

MultisampledNight commented 8 months ago

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

  1. introduces a guillotine cut, where any drawn or to-be-drawn elements intersecting k on the y axis are split in half
  2. partitions all drawn elements into "above k" and "below k"
  3. 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

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):

unknown

Other notes

This is slightly insane. Keeping this here anyway for further thoughts and input.

fenjalien commented 8 months ago

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.

johannes-wolf commented 8 months ago

Split content could be drawn two times with a clip mask + an offset. Implementing this should definitely be possible.