WeasyPrint icon indicating copy to clipboard operation
WeasyPrint copied to clipboard

Incorrect absolute positionning when the containing block is a table cell

Open alcinos opened this issue 10 years ago • 5 comments

Here is a small example where the renderer produce an incorrect output: https://gist.github.com/alcinos/a0a88c4ec735e62deacf

The file is correctly rendered by current versions of chrome and firefox.

alcinos avatar Jun 14 '15 18:06 alcinos

Note that I tested it on the latest version available on git, with python2 and python3, with in both cases the same incorrect output

alcinos avatar Jun 14 '15 18:06 alcinos

Could you reduce the test case to be as small as possible while showing the problem, and describe what the problem is? Thanks.

SimonSapin avatar Jun 15 '15 14:06 SimonSapin

Apparently, the issue comes from an incorrect interpretation of the position relative/absolute in td cells. Here is a smaller example: https://gist.github.com/alcinos/140dadd8179a0811f4fe

Firefox renders the previous file as follows: correct

Weasy print miss-interpret the "top:0px" property: incorrect

alcinos avatar Jun 15 '15 16:06 alcinos

As a side note, the rendering is correct when the table is removed and the td replaced by a regular div

alcinos avatar Jun 15 '15 16:06 alcinos

This seems to be caused by / related to the following:

  • the <td> essentially being empty (apart from the absolutely positioned div, which doesn't contribute to the height of the table cell)
  • the table layout algorithm "resetting" the cell's height to auto before laying out its contents (see here: https://github.com/Kozea/WeasyPrint/blob/v60.2/weasyprint/layout/table.py#L145-L147)

This then leads to an issue in block_container_layout, in particular these lines: https://github.com/Kozea/WeasyPrint/blob/v60.2/weasyprint/layout/block.py#L794-L800, where new_box.height gets set to 0 - which presumably breaks positioning the absolute child div.

alexandergitter avatar Jan 11 '24 17:01 alexandergitter