Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No splitting performed when nesting non-splittable within splittable PLVBox #28

Open
hwanders opened this issue Apr 29, 2023 · 3 comments
Assignees

Comments

@hwanders
Copy link

hwanders commented Apr 29, 2023

Info: I'm using ph-pdf-layout 7.0.0.

When creating a splittable PLVBox and adding some large non-splittable PLVBoxes as rows, the calculations for vertical splitting seems to go wrong (or at least behaves in a way which I did not expect).
This culminates in a debug message Cannot split because no vertical splittable elements are contained and an error of the form The value of 'StartTop' must be >= 0! The current value is: <negative number>.

By debugging I can see that the PLVBox elements do have too many rows (in m_aRows) which do not fit on the page such that fCurY becomes negative.

I guess, the problem lies in AbstractPLVBox.splitElementVert(...) which uses containsAnyVertSplittableElement() to determine whether splitting can be performed. My expectation is that splitting should be done if each contained row fits in the available height, even if those rows' contents are not splittable.

I have found that there is also a simple workaround for this: just wrap the inner (non-splittable) PLVBox with another splittable one which only contains that inner box.

This is a simple reproduction of the error, the workaround is added as comment in the loop:

public static void main(String[] args) throws Exception {
  var font = new FontSpec(PreloadFont.REGULAR, 10);
  var pageSet = new PLPageSet(new SizeSpec(100, 700));

  var list = new PLVBox(); // splittable
  pageSet.addElement(list);

  for (var i = 0; i < 3; i++) {
    var subList = new PLVBox().setVertSplittable(false); // non-splittable
    subList.addRow(new PLText("test", font).setExactHeight(700));
    list.addRow(subList); // workaround: list.addRow(new PLVBox(subList));
  }

  var pdf = new PageLayoutPDF().addPageSet(pageSet);
  // The following throws an "Internal error" with reason
  // "The value of 'StartTop' must be >= 0! The current value is: -700.0"
  pdf.renderTo(new ByteArrayOutputStream());
}
@phax phax self-assigned this Apr 29, 2023
@phax phax added the bug label Apr 29, 2023
@hwanders
Copy link
Author

To reformulate my expectation: I think if the PLVBox's rows are not vert-splittable themselves, it should consider the rows as whole elements and try to split those.

@hwanders
Copy link
Author

hwanders commented Apr 30, 2023

I just played around a bit with the source code and just removing the block checking for vert-splittable elements did work in my case.

Probably the code is there for some reason, but after removing the code (and making the tests deterministic by using fixed date/time values and seeds for Random), all generated PDFs files remain exactly the same, so at least no existing tests are breaking. On the other hand, the block is never entered in any of the tests.

Copy link

stale bot commented Jan 7, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 7, 2024
@phax phax added pinned and removed wontfix labels Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants