brechtm / rinohtype

The Python document processor
http://www.mos6581.org/rinohtype
GNU Affero General Public License v3.0
499 stars 59 forks source link

rinohtype enters infinite loop when rendering a tall image #283

Open alexfargus opened 3 years ago

alexfargus commented 3 years ago

Trying to render the following .rst with the attached image triggers an infinite loop. I have verified that this issue exists on master.

.. figure:: ./loop.png
    :width: 80%

    This figure triggers an infinite loop while rendering.

loop

I believe that the issue is caused by some combination of the width attribute and the dimensions of the image file. Removing the attribute or changing the image dimensions will work around the issue.

I have tried to find the root cause, but I am having trouble following the rendering logic.

@brechtm can you suggest any tips for figuring out what is going wrong?

brechtm commented 3 years ago

When the image is scaled to 80% of the width, it's height is too large to fit on the page, and rinohtype moves it to the next page where the same thing happens. We need to check whether the image is the first flowable on the page. If it is, we should always place it, even if it exceeds the available height. You can use container.page._empty for this, which is set to False as soon as a flowable has been placed on the page.

brechtm commented 3 years ago

Something similar happens with inline images if they don't fit in the available width (or height, probably).

fdeprey commented 2 years ago

@brechtm We had the same issue already several times.

brechtm commented 2 years ago

I had another look at this. This is already handled for images, but not for figures. That possibly requires some redesign, so it might take a while...