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

fix: handle float rounding when extending boxes over page breaks #1559

Merged
merged 1 commit into from
Feb 7, 2022

Conversation

aschmitz
Copy link
Contributor

@aschmitz aschmitz commented Feb 2, 2022

When a box would break over the edge of a page, its height is extended to the bottom of that page (per https://www.w3.org/TR/css-break-3/#box-splitting , primarily to allow backgrounds and borders to continue to the end of the page).

When this happened, sometimes the values that would be calculated for the height of the extended element would be rounded over the calculated height that remained on the page, forcing the entire containing box to wrap to the next page.

Rather than trying to carefully manage the order of operations to try to be safe in IEEE floats for directions, we apply a small "fudge factor": if an element fits very nearly (within a thousandth of a pixel) into the remaining space, it is still accepted.

When a box would break over the edge of a page, its height is extended
to the bottom of that page (per
https://www.w3.org/TR/css-break-3/#box-splitting , primarily to allow
backgrounds and borders to continue to the end of the page).

When this happened, sometimes the values that would be calculated for
the height of the extended element would be rounded *over* the
calculated height that remained on the page, forcing the entire
containing box to wrap to the next page.

Rather than trying to carefully manage the order of operations to try to
be safe in IEEE floats for directions, we apply a small "fudge factor":
if an element fits very nearly (within a thousandth of a pixel) into the
remaining space, it is still accepted.
@liZe
Copy link
Member

liZe commented Feb 7, 2022

Thanks for the pull request!

We’ll just change a bit the workaround to match the ones we already have:

# In some cases (shrink-to-fit result being the preferred width)
# max_x is coming from Pango itself,
# but floating point errors have accumulated:
# width2 = (width + X) - X # in some cases, width2 < width
# Increase the value a bit to compensate and not introduce
# an unexpected line break. The 1e-9 value comes from PEP 485.
max_x *= 1 + 1e-9

@liZe liZe merged commit 2ad7143 into Kozea:master Feb 7, 2022
@liZe liZe added this to the 55.0 milestone Feb 7, 2022
@liZe liZe added the bug Existing features not working as expected label Feb 7, 2022
liZe added a commit that referenced this pull request Feb 20, 2022
@liZe liZe modified the milestones: 55.0, 54.2 Feb 20, 2022
liZe added a commit that referenced this pull request Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants