ststeiger / PdfSharpCore

Port of the PdfSharp library to .NET Core - largely removed GDI+ (only missing GetFontData - which can be replaced with freetype2)
Other
1.06k stars 235 forks source link

`KeepWithNext` and `KeepTogether` doesn't seem to work if the next element is a table #305

Open colejohnson66 opened 1 year ago

colejohnson66 commented 1 year ago

As the title says, using ParagraphFormat.KeepWithNext and KeepTogether doesn't work if the next element is a table.

We've found that TopDownFormatter.NextElementsDontFit, when checking if the table is kept with the paragraph, the condition below evaluates to true and returns. Skipping over the block and moving to the next line causes the paragraph header to be kept with the table.

https://github.com/ststeiger/PdfSharpCore/blob/8b9076c465123bc195c0d844dcec81eafae4fa3f/MigraDocCore.Rendering/MigraDoc.Rendering/TopDownFormatter.cs#L330-L331

colejohnson66 commented 1 year ago

It seems the area check should be before the keep together/next check. We want to see if the table overflows before seeing if the next item should be computed. Regardless, the table has a rendered size of negative one point, so the overflow calculation never happens.

image

The X and Y values are correct; That's where the table would be if it didn't overflow. 3/4 inch margin on the left, and about 10 inches down the page.