Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Source/HtmlRenderer/Core/Dom/CssLayoutEngineTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -601,11 +601,13 @@ private void EnforceMinimumSize()
/// <param name="g"></param>
private void LayoutCells(RGraphics g)
{
double startx = Math.Max(_tableBox.ClientLeft + GetHorizontalSpacing(), 0);
double starty = Math.Max(_tableBox.ClientTop + GetVerticalSpacing(), 0);
// The -1 spacing of collapsed borders mustn't move the cells out of the container
var origin = _tableBox.HtmlContainer?.Location ?? RPoint.Empty;
double startx = Math.Max(_tableBox.ClientLeft + GetHorizontalSpacing(), origin.X);
double starty = Math.Max(_tableBox.ClientTop + GetVerticalSpacing(), origin.Y);
double cury = starty;
double maxRight = startx;
double maxBottom = 0f;
double maxBottom = starty;
int currentrow = 0;

// HTML's align attribute on the table ends up in text-align
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using HtmlRenderer.IntegrationTest.TestSupport;
using TheArtOfDev.HtmlRenderer.Adapters.Entities;

namespace HtmlRenderer.IntegrationTest.Tables;

[TestClass]
public sealed class TablePlacementIntegrationTests
{
private const double Delta = 1.0;

[TestMethod]
public void Table_InAContainerAboveAndLeftOfTheOrigin_StaysInPlace()
{
var (root, _) = LayoutHarness.Layout(
LayoutHarness.Wrap("<table id='t' style='border-spacing:0'><tr><td id='c' style='padding:0'>x</td></tr></table><p id='p' style='margin:0'>after</p>"),
prepare: r => r.HtmlContainer!.Location = new RPoint(-30, -50));
var table = LayoutHarness.FindById(root, "t")!;
var cell = LayoutHarness.FindById(root, "c")!;

Assert.AreEqual(-30, table.Location.X, Delta);
Assert.AreEqual(-50, table.Location.Y, Delta);
Assert.AreEqual(table.Location.X, cell.Location.X, Delta);
Assert.AreEqual(table.Location.Y, cell.Location.Y, Delta);
Assert.AreEqual(table.ActualBottom, LayoutHarness.FindById(root, "p")!.Location.Y, Delta);
}
}
Loading