Preserve replaced box height on relayout#2767
Conversation
|
Hi, Thanks for your PR. Could you please share a sample you’re sure that it shows the issue? You think the test shows the failure, so we can’t be sure that the fix is actually fixing the "right" thing. And it’d be better for the project quality to know why we’re adding lines of code :) |
|
I had one, may take me a bit to track down where it was. I was formating a book for a small device screen - 3.75 x 4.25 inches, IIRC. I should be able to locate it. |
|
@taxilian Thanks for your example, but it’s huge and I can’t reproduce the bug with it. The test included explicitly calls Could you please provide a smaller sample? I tried to find a way to reproduce with the description in your first comment, but I didn’t find a way so far. |
What changed
resolve_percentagesnow preserves an already computed numeric height for block replaced boxes when the containing block height isauto.This prevents a relayout pass from changing a floated replaced box, such as an image, back to
height = 'auto'after replaced-box layout has computed its used height.Why
In documents with floated images and page remakes, a block replaced box can be laid out again after its height has already been resolved from its intrinsic ratio. Resetting that height to the string
autocan leave the box in float exclusion data with a non-numeric height. Later calls tomargin_height()then try to add that string to numeric padding or border values and raise aTypeError.Tests
python -m pytest tests/layout/test_image.py::test_images_auto_height_block_replaced_relayout -qpython -m pytest tests/layout/test_image.py tests/layout/test_float.py -qpython -m ruff check weasyprint/layout/percent.py tests/layout/test_image.pyBackground
I hit this when trying to format a book I use Weasyprint with (hambook.org) for a kindle sized screen. Due to time constraints, the fix, repro case, and PR were all figured out by various AI tools, but as best I can tell it seems reasonable. Could be you know a better fix, but at least the test I think shows the failure; I can upload another repro case if needed.