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

Extend NewPage with freeSpace #1648

Open
2S-Software opened this issue Apr 20, 2024 · 3 comments
Open

Extend NewPage with freeSpace #1648

2S-Software opened this issue Apr 20, 2024 · 3 comments
Labels
enhancement New feature or request needs triage

Comments

@2S-Software
Copy link

Use Case

I only want to execute a page break if the free space of the page is less than e.g. 50mm:

[
  pw.Text("First paragraph"),
  // NewPage only needed, if available space is less than 50mm
  pw.NewPage(),
  pw.Text("Second paragraph"),
]

Would it be possible to add a new parameter 'freeSpace' to the existing widget NewPage so that the page break is only executed if the free space is less than specified?

The default value of the new double parameter should be Null or Zero, so that in this case a page break is always generated as before.

Possible implementation idea

I had tried to derive my own widget class of NewPage, but the offsetStart and fullConstraints infos are missing. Perhaps the base class pw.Widget can be enhanced with a function 'newPageNeeded' (with the available space as a parameter). NewPage could then override this new function and would replace the following code in MultiPage.generate in a more generic way:

Existing:

// Create a new page if we don't already have one
if (context == null || child is NewPage) {

New:

if (context == null || child.newPageNeeded(freeSpace)) {
@2S-Software 2S-Software added enhancement New feature or request needs triage labels Apr 20, 2024
@DavBfr
Copy link
Owner

DavBfr commented Apr 22, 2024

Looks good to me. Please provide an implementation PR.

@2S-Software
Copy link
Author

2S-Software commented Apr 23, 2024 via email

@DavBfr
Copy link
Owner

DavBfr commented Apr 23, 2024

THe font files and other assets are downloaded using the makefile.
usually you just run make on Linux. On macOS and Windows you might need to install that program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage
Projects
None yet
Development

No branches or pull requests

2 participants