diff --git a/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/HeightIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/HeightIntegrationTests.cs
index 692531e14..615ed7850 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/HeightIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/HeightIntegrationTests.cs
@@ -115,6 +115,29 @@ public void AutoHeight_FollowsTheIntrinsicRatioOfTheWidth()
Assert.AreEqual(40, TestImages.ImageRect(root, "i").Height, Delta);
}
+ [TestMethod]
+ [Spec("css21", "visudet.html#inline-replaced-height")]
+ [Spec("css21", "visudet.html#the-height-property")]
+ public void PercentageHeight_InAnAutoHeightContainingBlock_IsTheIntrinsicHeight()
+ {
+ var root = TestImages.Layout($"
");
+ var r = TestImages.ImageRect(root, "i");
+
+ Assert.AreEqual((40d, 20d), (r.Width, r.Height));
+ }
+
+ [TestMethod]
+ [Spec("css21", "box.html#box-dimensions")]
+ [Spec("css21", "visudet.html#inline-replaced-height")]
+ public void ImageBorderBox_AddsThePaddingAndBordersToTheIntrinsicSize()
+ {
+ var root = TestImages.Layout(
+ $"
");
+ var r = TestImages.ImageRect(root, "i");
+
+ Assert.AreEqual((60d, 36d), (r.Width, r.Height));
+ }
+
[TestMethod]
[Spec("css21", "visudet.html#inline-replaced-height")]
public void BlockImage_AutoHeight_IsTheIntrinsicHeight()
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/HrPlacementTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/HrPlacementTests.cs
index 7d75d1353..48eed8316 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/HrPlacementTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/HrPlacementTests.cs
@@ -53,6 +53,97 @@ public void AFloatedPredecessor_IsNotTheRulesMarginCollapsePartner()
Assert.AreEqual(30, h.Location.Y - a.ActualBottom, Delta);
}
+ [TestMethod]
+ [Spec("html", "rendering.html#the-hr-element-2")]
+ [Spec("css21", "visudet.html#blockwidth")]
+ public void TheRule_StartsAtTheContentEdgeOfItsContainingBlockPlusItsMargin()
+ {
+ var (plain, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ "
"));
+ var (padded, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ "
"));
+ var (indented, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ "
"));
+
+ var p = LayoutHarness.FindById(plain, "h")!;
+ var q = LayoutHarness.FindById(padded, "h")!;
+ var i = LayoutHarness.FindById(indented, "h")!;
+
+ Assert.AreEqual(0, p.Location.X, Delta);
+ Assert.AreEqual(15, q.Location.X, Delta);
+ Assert.AreEqual(20, i.Location.X, Delta);
+ Assert.AreEqual(p.Size.Width, q.Size.Width, Delta);
+ Assert.AreEqual(p.Size.Width - 50, i.Size.Width, Delta);
+ }
+
+ [TestMethod]
+ [Spec("html", "rendering.html#the-hr-element-2")]
+ [Spec("css21", "visudet.html#normal-block")]
+ [DataRow("", 2)]
+ [DataRow("height:10px", 12)]
+ [DataRow("padding:5px 0", 12)]
+ [DataRow("border:3px solid", 6)]
+ public void TheRule_IsAsTallAsItsHeightPaddingAndBorders(string style, double height)
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ $"
"));
+
+ var h = LayoutHarness.FindById(root, "h")!;
+
+ Assert.AreEqual(height, h.ActualBottom - h.Location.Y, 0.01);
+ }
+
+ [Ignore("Gap, see Spec/html.yml")]
+ [TestMethod]
+ [Spec("html", "rendering.html#the-hr-element-2")]
+ public void TheRuleWithoutBorders_HasNoHeight()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ "
"));
+
+ var h = LayoutHarness.FindById(root, "h")!;
+
+ Assert.AreEqual(0, h.ActualBorderTopWidth);
+ Assert.AreEqual(0, h.ActualBottom - h.Location.Y, 0.01);
+ }
+
+ [Ignore("Gap, see Spec/html.yml")]
+ [TestMethod]
+ [Spec("html", "rendering.html#the-hr-element-2")]
+ public void TheRuleWithAZeroTopMargin_SitsAtTheTopOfItsContainingBlock()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ "
"));
+
+ Assert.AreEqual(0, LayoutHarness.FindById(root, "h")!.Location.Y, Delta);
+ }
+
+ [Ignore("Gap, see Spec/html.yml")]
+ [TestMethod]
+ [Spec("html", "rendering.html#the-hr-element-2")]
+ public void AutoWidthRule_BorderBoxFillsTheContainingBlock()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ "
"));
+
+ var h = LayoutHarness.FindById(root, "h")!;
+
+ Assert.AreEqual(200, h.ActualRight - h.Location.X, 0.01);
+ }
+
+ [Ignore("Gap, see Spec/html.yml")]
+ [TestMethod]
+ [Spec("html", "rendering.html#the-hr-element-2")]
+ public void PercentageWidth_IsRelativeToTheContainingBlock()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ "
"));
+
+ var h = LayoutHarness.FindById(root, "h")!;
+
+ Assert.AreEqual(102, h.ActualRight - h.Location.X, 0.01);
+ }
+
[Ignore("Gap, see Spec/css21.yml")]
[TestMethod]
[Spec("css21", "visuren.html#block-formatting")]
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/MinMaxHeightIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/MinMaxHeightIntegrationTests.cs
index e641cab5a..b15d8a15b 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/MinMaxHeightIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/MinMaxHeightIntegrationTests.cs
@@ -32,6 +32,30 @@ public void MaxHeightAppliesWhenNotConflictingWithMinHeight()
Assert.AreEqual(20, box.ActualBottom - box.Location.Y, Delta);
}
+ [TestMethod]
+ [Spec("css21", "visudet.html#min-max-heights")]
+ [Spec("css-sizing-3", "#max-size-properties")]
+ public void MaxHeight_LimitsTheContentBox_PaddingComesOnTop()
+ {
+ var html = LayoutHarness.Wrap("x
y
z
w
");
+ var (root, _) = LayoutHarness.Layout(html);
+ var box = LayoutHarness.FindById(root, "b")!;
+
+ Assert.AreEqual(70, box.ActualBottom - box.Location.Y, Delta);
+ }
+
+ [TestMethod]
+ [Spec("css21", "visudet.html#min-max-heights")]
+ [Spec("css-sizing-3", "#min-size-properties")]
+ public void MinHeightWinsOverConflictingMaxHeight_PaddingComesOnTop()
+ {
+ var html = LayoutHarness.Wrap("x
");
+ var (root, _) = LayoutHarness.Layout(html);
+ var box = LayoutHarness.FindById(root, "b")!;
+
+ Assert.AreEqual(100, box.ActualBottom - box.Location.Y, Delta);
+ }
+
[TestMethod]
[Spec("css21", "visudet.html#the-height-property")]
public void PercentageHeight_AgainstAutoHeightContainingBlock_ComputesToAuto()
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/WidthIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/WidthIntegrationTests.cs
index b32366acd..55fd0b995 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/WidthIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/BoxModel/WidthIntegrationTests.cs
@@ -360,6 +360,66 @@ public void MaxWidth_ScalesDownAnImageKeepingItsRatio()
Assert.AreEqual((20d, 10d), (r.Width, r.Height));
}
+ [TestMethod]
+ [Spec("css21", "visudet.html#min-max-widths")]
+ [Spec("css-sizing-3", "#max-size-properties")]
+ [Spec("css-sizing-4", "#sizing-properties")]
+ public void PercentageMaxWidth_ScalesDownAnImageKeepingItsRatio()
+ {
+ var root = TestImages.Layout($"");
+ var r = TestImages.ImageRect(root, "i");
+
+ Assert.AreEqual((20d, 10d), (r.Width, r.Height));
+ }
+
+ [TestMethod]
+ [Spec("css21", "visudet.html#min-max-widths")]
+ [Spec("css-sizing-3", "#max-size-properties")]
+ [Spec("css-sizing-4", "#sizing-properties")]
+ public void MaxWidthAboveTheImageWidth_HasNoEffect()
+ {
+ var root = TestImages.Layout($"");
+ var r = TestImages.ImageRect(root, "i");
+
+ Assert.AreEqual((40d, 20d), (r.Width, r.Height));
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "visudet.html#min-max-widths")]
+ [Spec("css-sizing-3", "#max-size-properties")]
+ [Spec("css-sizing-4", "#sizing-properties")]
+ public void MaxWidth_LimitsAnImageWithAHeight()
+ {
+ var root = TestImages.Layout($"
");
+ var r = TestImages.ImageRect(root, "i");
+
+ Assert.AreEqual((20d, 30d), (r.Width, r.Height));
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "visudet.html#inline-replaced-width")]
+ [DataRow("width:0")]
+ [DataRow("width:0%")]
+ public void ZeroWidth_MakesTheImageZeroWide(string style)
+ {
+ var root = TestImages.Layout($"");
+
+ Assert.AreEqual(0, TestImages.ImageRect(root, "i").Width, Delta);
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "visudet.html#min-max-widths")]
+ [Spec("css-sizing-3", "#max-size-properties")]
+ public void ZeroMaxWidth_MakesTheImageZeroWide()
+ {
+ var root = TestImages.Layout($"");
+
+ Assert.AreEqual(0, TestImages.ImageRect(root, "i").Width, Delta);
+ }
+
[Ignore("Gap, see Spec/css21.yml")]
[TestMethod]
[Spec("css21", "visudet.html#min-max-widths")]
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Content/RasterImageSizeIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Content/RasterImageSizeIntegrationTests.cs
index 63ab1e415..e65d0e709 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Content/RasterImageSizeIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Content/RasterImageSizeIntegrationTests.cs
@@ -35,6 +35,16 @@ public void RasterImage_IsOneCssPixelPerImagePixel()
Assert.AreEqual(5, image.Words[0].Height, Delta);
}
+ [Ignore("Gap, see Spec/html.yml")]
+ [TestMethod]
+ [Spec("html", "rendering.html#images-3")]
+ public void UnavailableImage_WithWidthAndHeight_TakesThatSizeAtTheStartOfTheLine()
+ {
+ var root = TestImages.Layout("");
+
+ Assert.AreEqual(new RRect(0, 0, 40, 30), TestImages.ImageRect(root, "i"));
+ }
+
private static string PngDataUri(int width, int height)
{
using var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/FixedPositionRepeatsPerPageTest.cs b/Source/Test/HtmlRenderer.IntegrationTest/FixedPositionRepeatsPerPageTest.cs
index bba3ce94b..df7e7b21e 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/FixedPositionRepeatsPerPageTest.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/FixedPositionRepeatsPerPageTest.cs
@@ -6,6 +6,7 @@
using TheArtOfDev.HtmlRenderer.Core;
using TheArtOfDev.HtmlRenderer.Core.Fragments;
using TheArtOfDev.HtmlRenderer.WinForms;
+using static HtmlRenderer.IntegrationTest.TestSupport.Fragments;
namespace TheArtOfDev.HtmlRenderer.IntegrationTest;
@@ -65,6 +66,44 @@ await wrapper.SetHtml(
}
}
+ [TestMethod]
+ [Spec("css-position-3", "#abspos-breaking")]
+ public async Task FixedElementNestedInABlock_GivesTheBlockNoFragmentOnOtherPages()
+ {
+ using var wrapper = new HtmlContainer();
+ await wrapper.SetHtml(
+ """
+
+
+
+
PageHeaderMarker
+ text
+
+
+ """);
+
+ var container = GetInternal(wrapper);
+ container.PageSize = new TheArtOfDev.HtmlRenderer.Adapters.Entities.RSize(300, 100);
+ container.MarginTop = 0;
+ wrapper.MaxSize = new SizeF(300, 0);
+
+ using var bitmap = new Bitmap(300, 2000);
+ using var g = Graphics.FromImage(bitmap);
+ wrapper.PerformLayout(g);
+
+ var tree = container.FragmentTree;
+ Assert.AreEqual(2, tree.Fragmentainers.Count);
+
+ var pagesWithLater = tree.Fragmentainers
+ .Where(f => Flatten(f.Root).Any(x => x.Box.HtmlTag?.TryGetAttribute("id") == "later"))
+ .Select(f => f.SlotIndex)
+ .ToList();
+ CollectionAssert.AreEqual(new[] { 1 }, pagesWithLater);
+
+ foreach (var fragmentainer in tree.Fragmentainers)
+ Assert.AreEqual(1, AllWords(fragmentainer.Root).Count(w => w.Text == "PageHeaderMarker"));
+ }
+
[TestMethod]
[Spec("css21", "visuren.html#fixed-positioning")]
public async Task FixedElement_StillRendersOnce_WithoutARealPageGrid()
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/BlockContentListMarkerTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/BlockContentListMarkerTests.cs
index 72bb43fa0..f82050fdc 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/BlockContentListMarkerTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/BlockContentListMarkerTests.cs
@@ -6,6 +6,7 @@
using TheArtOfDev.HtmlRenderer.Core.Dom;
using TheArtOfDev.HtmlRenderer.Core.Fragments;
using TheArtOfDev.HtmlRenderer.Core.Utils;
+using static HtmlRenderer.IntegrationTest.TestSupport.Fragments;
namespace TheArtOfDev.HtmlRenderer.IntegrationTest.Fragmentation;
@@ -69,6 +70,25 @@ public void AnItemDeferredBeforeItsContentWasEverFlowed_TravelsWholeWithItsMarke
Assert.AreEqual(1, claims[word].Count);
}
+ [TestMethod]
+ public void AnEmptyItemOnThePageBoundary_HasItsMarkerOnTheNextPage()
+ {
+ var html = PaintHarness.Wrap(
+ ""
+ + ""
+ + "after
");
+
+ var (root, container) = PaintHarness.LayoutPaginated(html, pageHeight: 100);
+
+ var item = PaintHarness.FindById(root, "empty")!;
+ var word = item.ListItemBox!.Words.Single();
+ Assert.AreEqual(100, word.Top, 0.5);
+
+ var claims = ClaimsByWord(container);
+ Assert.IsTrue(claims.TryGetValue(word, out var slots), "the marker is claimed by no fragment at all");
+ CollectionAssert.AreEqual(new[] { 1 }, slots);
+ }
+
// ── Helpers ──────────────────────────────────────────────────────────────
private static IEnumerable Walk(CssBox box)
@@ -79,17 +99,6 @@ private static IEnumerable Walk(CssBox box)
yield return d;
}
- private static IEnumerable Flatten(BoxFragment fragment)
- {
- yield return fragment;
- foreach (var child in fragment.Children)
- foreach (var d in Flatten(child))
- yield return d;
- if (fragment.MarkerFragment != null)
- foreach (var d in Flatten(fragment.MarkerFragment))
- yield return d;
- }
-
private static List ListItems(CssBox root) =>
Walk(root).Where(b => b.Display == CssConstants.ListItem).ToList();
@@ -97,7 +106,7 @@ private static List ListItems(CssBox root) =>
private static List FragmentsOf(HtmlContainerInt container, CssBox box) =>
container.FragmentTree!.Fragmentainers
- .SelectMany(f => Flatten(f.Root))
+ .SelectMany(f => FlattenWithMarkers(f.Root))
.Where(f => ReferenceEquals(f.Box, box))
.ToList();
@@ -106,7 +115,7 @@ private static Dictionary> ClaimsByWord(HtmlContainerInt cont
var claims = new Dictionary>(ReferenceEqualityComparer.Instance);
foreach (var fragmentainer in container.FragmentTree!.Fragmentainers)
{
- foreach (var word in Flatten(fragmentainer.Root).SelectMany(f => f.Words))
+ foreach (var word in FlattenWithMarkers(fragmentainer.Root).SelectMany(f => f.Words))
{
if (!claims.TryGetValue(word.Word, out var slots))
claims[word.Word] = slots = new List();
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/EarlyBreakLayoutIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/EarlyBreakLayoutIntegrationTests.cs
index e3bfbba23..d02a8102b 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/EarlyBreakLayoutIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/EarlyBreakLayoutIntegrationTests.cs
@@ -8,6 +8,7 @@
using TheArtOfDev.HtmlRenderer.Core.Dom;
using TheArtOfDev.HtmlRenderer.Core.Fragments;
using TheArtOfDev.HtmlRenderer.WinForms;
+using static HtmlRenderer.IntegrationTest.TestSupport.Fragments;
namespace TheArtOfDev.HtmlRenderer.IntegrationTest.Fragmentation;
@@ -58,14 +59,6 @@ private static IEnumerable Walk(CssBox box)
private static CssBox FindById(CssBox root, string id) =>
Walk(root).FirstOrDefault(b => b.HtmlTag?.TryGetAttribute("id") == id)!;
- private static IEnumerable Flatten(BoxFragment fragment)
- {
- yield return fragment;
- foreach (var child in fragment.Children)
- foreach (var descendant in Flatten(child))
- yield return descendant;
- }
-
/// The gap a translation carries shows up as one line sitting further below its predecessor
/// than the line height accounts for.
private static void AssertLinesAreEvenlySpaced(CssBox card)
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/KeepWithNextIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/KeepWithNextIntegrationTests.cs
index 38eef7db7..05b6c33ef 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/KeepWithNextIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/KeepWithNextIntegrationTests.cs
@@ -6,6 +6,7 @@
using TheArtOfDev.HtmlRenderer.Adapters.Entities;
using TheArtOfDev.HtmlRenderer.Core;
using TheArtOfDev.HtmlRenderer.Core.Dom;
+using TheArtOfDev.HtmlRenderer.Core.Entities;
using TheArtOfDev.HtmlRenderer.WinForms;
namespace TheArtOfDev.HtmlRenderer.IntegrationTest.Fragmentation;
@@ -42,10 +43,19 @@ await wrapper.SetHtml(
container.Location = new RPoint(0, MarginTop);
wrapper.MaxSize = new SizeF(400, 0);
+ // CssBox.PerformLayout reports exceptions instead of throwing them
+ var layoutErrors = new List();
+ wrapper.RenderError += (_, e) =>
+ {
+ if (e.Type == HtmlRenderErrorType.Layout)
+ layoutErrors.Add(e.Message + ": " + e.Exception);
+ };
+
using var bitmap = new Bitmap(400, 60000);
using var g = Graphics.FromImage(bitmap);
wrapper.PerformLayout(g);
+ Assert.IsEmpty(layoutErrors, string.Join("\n", layoutErrors));
return (container.Root!, container);
}
@@ -359,4 +369,55 @@ public async Task BreakBeforeAvoid_OnMovedBox_PullsPrecedingSiblingAlong()
Assert.IsTrue(keepPage >= 1, $"Test setup expects the avoid box to be moved to page 2+, but it is at y={keep.Location.Y}");
Assert.AreEqual(keepPage, container.PageIndexOf(lead.Location.Y));
}
+
+ private static string HeadingAndKeepBox(int keepHeight) =>
+ "Heading
"
+ + "";
+
+ [TestMethod]
+ [Spec("css21", "page.html#allowed-page-breaks")]
+ public async Task HeadingAndMovedBox_FillingAPageExactly_MoveTogether()
+ {
+ var (root, _) = await BuildAsync(HeadingAndKeepBox(960));
+
+ Assert.AreEqual(PageHeight, FindByClass(root, "heading").Location.Y, 0.5);
+ Assert.AreEqual(PageHeight + 40, FindByClass(root, "keep").Location.Y, 0.5);
+ }
+
+ [TestMethod]
+ [Spec("css21", "page.html#allowed-page-breaks")]
+ [Spec("css-break-3", "#unforced-breaks")]
+ public async Task HeadingAndMovedBox_TallerThanAPageTogether_HeadingStaysBehind()
+ {
+ var (root, _) = await BuildAsync(HeadingAndKeepBox(970));
+
+ Assert.AreEqual(900, FindByClass(root, "heading").Location.Y, 0.5);
+ Assert.AreEqual(PageHeight, FindByClass(root, "keep").Location.Y, 0.5);
+ }
+
+ [TestMethod]
+ [Spec("css21", "page.html#allowed-page-breaks")]
+ public async Task BreakAfterAvoid_OnABoxSplitAcrossTheBoundary_DoesNotMoveIt()
+ {
+ var (root, _) = await BuildAsync(
+ "Lead
"
+ + "Next
");
+
+ Assert.AreEqual(900, FindByClass(root, "lead").Location.Y, 0.5);
+ Assert.AreEqual(1050, FindByClass(root, "next").Location.Y, 0.5);
+ }
+
+ [TestMethod]
+ public async Task BreakAfterAvoid_RunStartingBelowThePageTop_IsNotMovedUp()
+ {
+ var (root, _) = await BuildAsync(
+ "A
"
+ + "B
"
+ + "C
",
+ fillerHeight: 1005);
+
+ Assert.AreEqual(1005, FindByClass(root, "a").Location.Y, 0.5);
+ Assert.AreEqual(955, FindByClass(root, "b").Location.Y, 0.5);
+ }
}
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/MonolithicContentLayoutIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/MonolithicContentLayoutIntegrationTests.cs
index 125973c2f..faa28c350 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/MonolithicContentLayoutIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/MonolithicContentLayoutIntegrationTests.cs
@@ -8,6 +8,7 @@
using TheArtOfDev.HtmlRenderer.Core.Dom;
using TheArtOfDev.HtmlRenderer.Core.Fragments;
using TheArtOfDev.HtmlRenderer.WinForms;
+using static HtmlRenderer.IntegrationTest.TestSupport.Fragments;
namespace TheArtOfDev.HtmlRenderer.IntegrationTest.Fragmentation;
@@ -56,14 +57,6 @@ private static IEnumerable Walk(CssBox box)
private static CssBox FindById(CssBox root, string id) =>
Walk(root).FirstOrDefault(b => b.HtmlTag?.TryGetAttribute("id") == id)!;
- private static IEnumerable Flatten(BoxFragment fragment)
- {
- yield return fragment;
- foreach (var child in fragment.Children)
- foreach (var descendant in Flatten(child))
- yield return descendant;
- }
-
private static List FragmentsOf(HtmlContainerInt container, CssBox box) =>
container.FragmentTree!.Fragmentainers.SelectMany(f => Flatten(f.Root)).Where(f => ReferenceEquals(f.Box, box)).ToList();
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/OrphansWidowsIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/OrphansWidowsIntegrationTests.cs
index fa22efe2f..6b38e06f4 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/OrphansWidowsIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/OrphansWidowsIntegrationTests.cs
@@ -413,4 +413,56 @@ public async Task Orphans1Widows1_MatchesDictionaryCssValues_NoEffect_Regression
Assert.IsTrue(oneBefore, "orphans:1 should leave a single line before the break");
Assert.IsTrue(oneAfter, "widows:1 should leave a single line after the break");
}
+
+ private static List LineTops(CssBox box) => box.LineBoxes.Select(l => System.Math.Round(l.LineTop, 1)).ToList();
+
+ // Four 20px text lines and two 40px or 45px images, one per line.
+ private static string ParagraphWithTallLastLines(int imageHeight) =>
+ "Line1 Line2 Line3 Line4"
+ + string.Concat(Enumerable.Repeat($"
", 2))
+ + "
";
+
+ [TestMethod]
+ [Spec("css21", "page.html#break-inside")]
+ public async Task Widows3_ShiftedRunFillsTheNextPageExactly_TakesTheLineAlong()
+ {
+ var (root, _) = await BuildAsync(ParagraphWithTallLastLines(40));
+
+ CollectionAssert.AreEqual(new[] { 0, 20, 40, 100, 120, 160.0 }, LineTops(FindById(root, "p")));
+ }
+
+ [TestMethod]
+ [Spec("css21", "page.html#allowed-page-breaks")]
+ [Spec("css-break-3", "#unforced-breaks")]
+ public async Task Widows3_ShiftedRunWouldOverflowTheNextPage_LeavesTheBreakWhereItIs()
+ {
+ var (root, _) = await BuildAsync(ParagraphWithTallLastLines(45));
+
+ CollectionAssert.AreEqual(new[] { 0, 20, 40, 60, 100, 145.0 }, LineTops(FindById(root, "p")));
+ }
+
+ [TestMethod]
+ [DataRow(4, DisplayName = "4 lines")]
+ [DataRow(5, DisplayName = "5 lines, filling the page exactly")]
+ [Spec("css21", "page.html#break-inside")]
+ public async Task Widows4_ParagraphMovedWhole_StartsAtTheTopOfTheNextPage(int lineCount)
+ {
+ var (root, _) = await BuildAsync("" + Paragraph(lineCount, "widows:4"));
+
+ var expected = Enumerable.Range(0, lineCount).Select(i => 100 + i * LineHeight).ToArray();
+ CollectionAssert.AreEqual(expected, LineTops(FindById(root, "p")));
+ }
+
+ [TestMethod]
+ [Ignore("Gap, see Spec/css-break-3.yml")]
+ [Spec("css21", "page.html#allowed-page-breaks")]
+ [Spec("css-break-3", "#unforced-breaks")]
+ public async Task Orphans6_MoreLinesThanAPageHolds_BreaksWhereThePageIsFull()
+ {
+ var (root, _) = await BuildAsync(Paragraph(12, "orphans:6"), pageHeight: 110);
+
+ CollectionAssert.AreEqual(
+ new[] { 0, 20, 40, 60, 80, 110, 130, 150, 170, 190, 220, 240.0 },
+ LineTops(FindById(root, "p")));
+ }
}
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/PageBreakIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/PageBreakIntegrationTests.cs
index e22cc8600..8b67365d5 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/PageBreakIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/PageBreakIntegrationTests.cs
@@ -254,6 +254,31 @@ public async Task ForcedBreak_MarginAfterBreak_IsPreservedNotTruncated()
"second's own margin-top should be added normally on top of the forced-break relocation, not truncated");
}
+ [TestMethod]
+ [Ignore("Gap, see Spec/css-break-3.yml")]
+ [Spec("css-break-3", "#break-margins")]
+ public async Task ForcedBreak_MarginEndingExactlyAtThePageTop_IsPreserved()
+ {
+ var (root, container) = await BuildAsync(
+ ""
+ + "Second
");
+
+ Assert.AreEqual(container.PageTopOf(1) + 100, FindByClass(root, "second").Location.Y, 0.5);
+ }
+
+ [TestMethod]
+ [Ignore("Gap, see Spec/css21.yml")]
+ [Spec("css21", "page.html#forced")]
+ [Spec("css-break-3", "#forced-breaks")]
+ public async Task ForcedBreak_MarginCrossingThePageBoundary_DoesNotSkipAPage()
+ {
+ var (root, container) = await BuildAsync(
+ ""
+ + "Second
");
+
+ Assert.AreEqual(container.PageTopOf(1) + 150, FindByClass(root, "second").Location.Y, 0.5);
+ }
+
#region Margin truncation before a container's first child (css-break-3 §5.2)
private static string FirstChildDocument(string outerStyle, string margin = "1200px") =>
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/ResumableBlockLayoutIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/ResumableBlockLayoutIntegrationTests.cs
index 0b1d587e2..cb31a3cac 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/ResumableBlockLayoutIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/ResumableBlockLayoutIntegrationTests.cs
@@ -8,6 +8,7 @@
using TheArtOfDev.HtmlRenderer.Core.Dom;
using TheArtOfDev.HtmlRenderer.Core.Fragments;
using TheArtOfDev.HtmlRenderer.WinForms;
+using static HtmlRenderer.IntegrationTest.TestSupport.Fragments;
namespace TheArtOfDev.HtmlRenderer.IntegrationTest.Fragmentation;
@@ -56,14 +57,6 @@ private static IEnumerable Walk(CssBox box)
private static CssBox FindById(CssBox root, string id) =>
Walk(root).FirstOrDefault(b => b.HtmlTag?.TryGetAttribute("id") == id)!;
- private static IEnumerable Flatten(BoxFragment fragment)
- {
- yield return fragment;
- foreach (var child in fragment.Children)
- foreach (var descendant in Flatten(child))
- yield return descendant;
- }
-
private static bool Contains(BoxFragment fragment, CssBox box) =>
ReferenceEquals(fragment.Box, box) || fragment.Children.Any(c => Contains(c, box));
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/StraddlingLineClaimTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/StraddlingLineClaimTests.cs
index 549c1b39c..9f60817a2 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/StraddlingLineClaimTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/StraddlingLineClaimTests.cs
@@ -8,6 +8,7 @@
using TheArtOfDev.HtmlRenderer.Core.Dom;
using TheArtOfDev.HtmlRenderer.Core.Fragments;
using TheArtOfDev.HtmlRenderer.WinForms;
+using static HtmlRenderer.IntegrationTest.TestSupport.Fragments;
namespace TheArtOfDev.HtmlRenderer.IntegrationTest.Fragmentation;
@@ -51,14 +52,6 @@ private static IEnumerable Walk(CssBox box)
yield return d;
}
- private static IEnumerable Flatten(BoxFragment fragment)
- {
- yield return fragment;
- foreach (var child in fragment.Children)
- foreach (var d in Flatten(child))
- yield return d;
- }
-
private static List SlotsClaiming(HtmlContainerInt container, CssRect word) =>
container.FragmentTree!.Fragmentainers
.Where(f => Flatten(f.Root).SelectMany(b => b.Words).Any(w => ReferenceEquals(w.Word, word)))
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/StraddlingListMarkerTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/StraddlingListMarkerTests.cs
index 0321950f7..288482f72 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/StraddlingListMarkerTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/StraddlingListMarkerTests.cs
@@ -7,6 +7,7 @@
using TheArtOfDev.HtmlRenderer.Core.Dom;
using TheArtOfDev.HtmlRenderer.Core.Fragments;
using TheArtOfDev.HtmlRenderer.Core.Utils;
+using static HtmlRenderer.IntegrationTest.TestSupport.Fragments;
namespace TheArtOfDev.HtmlRenderer.IntegrationTest.Fragmentation;
@@ -159,17 +160,6 @@ private static IEnumerable Walk(CssBox box)
yield return d;
}
- private static IEnumerable Flatten(BoxFragment fragment)
- {
- yield return fragment;
- foreach (var child in fragment.Children)
- foreach (var d in Flatten(child))
- yield return d;
- if (fragment.MarkerFragment != null)
- foreach (var d in Flatten(fragment.MarkerFragment))
- yield return d;
- }
-
private static List ListItems(CssBox root) =>
Walk(root).Where(b => b.Display == CssConstants.ListItem).ToList();
@@ -185,7 +175,7 @@ private static List AllWords(CssBox root) =>
/// The pagination slots produced a fragment in, in order.
private static List SlotsOf(HtmlContainerInt container, CssBox box) =>
container.FragmentTree!.Fragmentainers
- .Where(f => Flatten(f.Root).Any(x => ReferenceEquals(x.Box, box)))
+ .Where(f => FlattenWithMarkers(f.Root).Any(x => ReferenceEquals(x.Box, box)))
.Select(f => f.SlotIndex)
.ToList();
@@ -194,7 +184,7 @@ private static Dictionary> ClaimsByWord(HtmlContainerInt cont
var claims = new Dictionary>(ReferenceEqualityComparer.Instance);
foreach (var fragmentainer in container.FragmentTree!.Fragmentainers)
{
- foreach (var word in Flatten(fragmentainer.Root).SelectMany(f => f.Words))
+ foreach (var word in FlattenWithMarkers(fragmentainer.Root).SelectMany(f => f.Words))
{
if (!claims.TryGetValue(word.Word, out var slots))
claims[word.Word] = slots = new List();
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/UnreachedWordClaimTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/UnreachedWordClaimTests.cs
index 27df4f9a0..e39a1c582 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/UnreachedWordClaimTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Fragmentation/UnreachedWordClaimTests.cs
@@ -9,6 +9,7 @@
using TheArtOfDev.HtmlRenderer.Core.Fragments;
using TheArtOfDev.HtmlRenderer.Core.Utils;
using TheArtOfDev.HtmlRenderer.WinForms;
+using static HtmlRenderer.IntegrationTest.TestSupport.Fragments;
namespace TheArtOfDev.HtmlRenderer.IntegrationTest.Fragmentation;
@@ -52,17 +53,6 @@ private static IEnumerable Walk(CssBox box)
yield return d;
}
- private static IEnumerable Flatten(BoxFragment fragment)
- {
- yield return fragment;
- foreach (var child in fragment.Children)
- foreach (var d in Flatten(child))
- yield return d;
- if (fragment.MarkerFragment != null)
- foreach (var d in Flatten(fragment.MarkerFragment))
- yield return d;
- }
-
///
/// Every word the document authored, including list-item markers ( - a
/// field kept separate from , so a plain alone misses it).
@@ -75,7 +65,7 @@ private static List WordsIn(CssBox box) =>
private static List ClaimedWords(HtmlContainerInt container) =>
container.FragmentTree!.Fragmentainers
- .SelectMany(f => Flatten(f.Root))
+ .SelectMany(f => FlattenWithMarkers(f.Root))
.SelectMany(f => f.Words)
.Select(w => w.Word)
.ToList();
@@ -85,7 +75,7 @@ private static string DescribeDoubleClaims(HtmlContainerInt container)
var claims = new Dictionary>(ReferenceEqualityComparer.Instance);
foreach (var fragmentainer in container.FragmentTree!.Fragmentainers)
{
- foreach (var word in Flatten(fragmentainer.Root).SelectMany(f => f.Words))
+ foreach (var word in FlattenWithMarkers(fragmentainer.Root).SelectMany(f => f.Words))
{
if (!claims.TryGetValue(word.Word, out var slots))
claims[word.Word] = slots = new List();
@@ -137,7 +127,7 @@ public async Task TheFirstPage_ClaimsOnlyTheWordsItShows()
var fragmentainers = container.FragmentTree!.Fragmentainers;
Assert.IsTrue(fragmentainers.Count > 1, "the fixture must span more than one page");
- var onFirstPage = Flatten(fragmentainers[0].Root).SelectMany(f => f.Words).ToList();
+ var onFirstPage = FlattenWithMarkers(fragmentainers[0].Root).SelectMany(f => f.Words).ToList();
var authored = WordsIn(root).Count;
Assert.IsTrue(onFirstPage.Count > 0);
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Layout/BoxGenerationIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Layout/BoxGenerationIntegrationTests.cs
index 37b024781..6d1dc46fd 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Layout/BoxGenerationIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Layout/BoxGenerationIntegrationTests.cs
@@ -100,6 +100,83 @@ public void BlockInsideInline_StacksTheInlineContentAroundIt()
Assert.IsGreaterThanOrEqualTo(block.ActualBottom - Delta, after.Top);
}
+ [TestMethod]
+ [Spec("css21", "visuren.html#anonymous-block-level")]
+ public void BlockInsideNestedInlines_SplitsAllOfThemAroundIt()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""));
+
+ var block = LayoutHarness.FindById(root, "block")!;
+ var a = FindWord(root, "a")!;
+ var b = FindWord(root, "b")!;
+ var d = FindWord(root, "d")!;
+ var e = FindWord(root, "e")!;
+
+ Assert.AreEqual(a.Top, b.Top, Delta);
+ Assert.AreEqual(a.Right, b.Left, Delta);
+ Assert.AreEqual(a.Bottom, block.Location.Y, Delta);
+ Assert.AreEqual(0, block.Location.X, Delta);
+ Assert.AreEqual(300, block.Size.Width, Delta);
+ Assert.AreEqual(block.ActualBottom, d.Top, Delta);
+ Assert.AreEqual(0, d.Left, Delta);
+ Assert.AreEqual(d.Top, e.Top, Delta);
+ Assert.AreEqual(d.Right, e.Left, Delta);
+ }
+
+ [TestMethod]
+ [Spec("css21", "visuren.html#anonymous-block-level")]
+ public void TwoBlocksInsideAnInline_SplitItIntoThreeParts()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""));
+
+ var b1 = LayoutHarness.FindById(root, "b1")!;
+ var b2 = LayoutHarness.FindById(root, "b2")!;
+ var a = FindWord(root, "a")!;
+ var c = FindWord(root, "c")!;
+ var e = FindWord(root, "e")!;
+
+ Assert.AreEqual(a.Bottom, b1.Location.Y, Delta);
+ Assert.AreEqual(b1.ActualBottom, c.Top, Delta);
+ Assert.AreEqual(c.Bottom, b2.Location.Y, Delta);
+ Assert.AreEqual(b2.ActualBottom, e.Top, Delta);
+ Assert.AreEqual(0, c.Left, Delta);
+ Assert.AreEqual(0, e.Left, Delta);
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "visuren.html#anonymous-block-level")]
+ public void BlockInsideANestedInline_FollowedByAnotherBlock_KeepsTheDocumentOrder()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""));
+
+ var c = LayoutHarness.FindById(root, "c")!;
+ var e = LayoutHarness.FindById(root, "e")!;
+ var d = FindWord(root, "d")!;
+ var f = FindWord(root, "f")!;
+
+ Assert.AreEqual(c.ActualBottom, d.Top, Delta);
+ Assert.AreEqual(d.Bottom, e.Location.Y, Delta);
+ Assert.AreEqual(e.ActualBottom, f.Top, Delta);
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "visuren.html#anonymous-block-level")]
+ public void InlineHoldingOnlyABlock_KeepsTheDocumentOrder()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""));
+
+ var b = LayoutHarness.FindById(root, "b")!;
+
+ Assert.AreEqual(FindWord(root, "a")!.Bottom, b.Location.Y, Delta);
+ Assert.AreEqual(b.ActualBottom, FindWord(root, "c")!.Top, Delta);
+ }
+
[TestMethod]
[Spec("css21", "visuren.html#anonymous-block-level")]
public void BlockInsideInline_IsNotInsetByTheInlinesBorder()
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Layout/FloatLayoutIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Layout/FloatLayoutIntegrationTests.cs
index b97f56dfa..de80189a8 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Layout/FloatLayoutIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Layout/FloatLayoutIntegrationTests.cs
@@ -389,6 +389,124 @@ public void FloatThatDoesNotFit_IsPlacedAsHighAsPossible()
Assert.AreEqual(50, c.Location.X, Delta);
}
+ [TestMethod]
+ [Spec("css21", "visuren.html#float-position")]
+ public void RightFloat_MarginRight_KeepsItsOuterEdgeAtTheContainingBlockEdge()
+ {
+ var html = LayoutHarness.Wrap(
+ "");
+
+ var (root, _) = LayoutHarness.Layout(html);
+ var f = LayoutHarness.FindById(root, "f")!;
+
+ Assert.AreEqual(140, f.Location.X, Delta);
+ Assert.AreEqual(290, f.ActualRight, Delta);
+ }
+
+ [TestMethod]
+ [Spec("css21", "visuren.html#float-position")]
+ public void LeftFloat_NextToARightFloatWhoseMarginFillsTheLine_MovesBelowIt()
+ {
+ var html = LayoutHarness.Wrap(
+ "");
+
+ var (root, _) = LayoutHarness.Layout(html);
+ var l = LayoutHarness.FindById(root, "l")!;
+
+ Assert.AreEqual(0, l.Location.X, Delta);
+ Assert.AreEqual(40, l.Location.Y, Delta);
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "visuren.html#float-position")]
+ public void LeftFloat_ThatWouldReachIntoAnEarlierRightFloatsMargin_MovesBelowIt()
+ {
+ // b would end at 130, past r's left outer edge at 110
+ var html = LayoutHarness.Wrap(
+ "");
+
+ var (root, _) = LayoutHarness.Layout(html);
+ var b = LayoutHarness.FindById(root, "b")!;
+
+ Assert.AreEqual(0, b.Location.X, Delta);
+ Assert.AreEqual(40, b.Location.Y, Delta);
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "visuren.html#float-position")]
+ public void RightFloat_ThatDoesntFitNextToAnEarlierLeftFloat_MovesBelowIt()
+ {
+ var html = LayoutHarness.Wrap(
+ "");
+
+ var (root, _) = LayoutHarness.Layout(html);
+ var r = LayoutHarness.FindById(root, "r")!;
+
+ Assert.AreEqual(50, r.Location.Y, Delta);
+ Assert.AreEqual(300, r.ActualRight, Delta);
+ }
+
+ [TestMethod]
+ [Spec("css21", "visuren.html#floats")]
+ public void LeftFloat_TextNextToIt_StartsAtItsRightMarginEdge()
+ {
+ var html = LayoutHarness.Wrap(
+ "");
+
+ var (root, _) = LayoutHarness.Layout(html);
+
+ Assert.AreEqual(115, FindWordByText(root, "text")!.Left, Delta);
+ }
+
+ [TestMethod]
+ [Spec("css21", "visuren.html#floats")]
+ public void LeftFloat_EveryLineNextToIt_StartsAtItsRightMarginEdge()
+ {
+ var html = LayoutHarness.Wrap(
+ ""
+ + "aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn
");
+
+ var (root, _) = LayoutHarness.Layout(html);
+ var f = LayoutHarness.FindById(root, "f")!;
+ var lineStarts = LayoutHarness.Descendants(root).SelectMany(b => b.Words)
+ .Where(w => w.Top < f.ActualBottom)
+ .GroupBy(w => w.Top)
+ .Select(line => line.Min(w => w.Left))
+ .ToList();
+
+ Assert.IsGreaterThan(1, lineStarts.Count);
+ foreach (var lineStart in lineStarts)
+ {
+ Assert.AreEqual(110, lineStart, Delta);
+ }
+ }
+
+ [TestMethod]
+ [Spec("css21", "visuren.html#floats")]
+ public void RightFloat_TextNextToIt_EndsBeforeItsLeftMarginEdge()
+ {
+ var html = LayoutHarness.Wrap(
+ ""
+ + "
aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp
");
+
+ var (root, _) = LayoutHarness.Layout(html);
+ var f = LayoutHarness.FindById(root, "f")!;
+ var words = WordsOverlappingVerticalSpan(LayoutHarness.FindById(root, "text")!, f.Location.Y, f.ActualBottom);
+
+ Assert.IsNotEmpty(words);
+ Assert.IsLessThanOrEqualTo(190, words.Max(w => w.Right));
+ }
+
[TestMethod]
[Spec("css21", "visuren.html#float-position")]
public void Float_IsNotHigherThanAnEarlierBlock()
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Layout/NormalFlowIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Layout/NormalFlowIntegrationTests.cs
index ea968bf32..315890eac 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Layout/NormalFlowIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Layout/NormalFlowIntegrationTests.cs
@@ -73,6 +73,81 @@ public void InlineBoxes_AreLaidOutHorizontallyRespectingMarginsBordersAndPadding
Assert.AreEqual(first.Right + 22, second.Left, 2);
}
+ [TestMethod]
+ [Spec("css21", "visuren.html#inline-formatting")]
+ [Spec("css-inline-3", "#line-boxes")]
+ public void InlineBox_EndMarginBorderAndPadding_PushTheFollowingText()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ "abc
"));
+
+ var b = FindWord(root, "b")!;
+ var c = FindWord(root, "c")!;
+ var borderBox = LayoutHarness.FindById(root, "s")!.Rectangles.Values.Single();
+
+ Assert.AreEqual(b.Right + 12, borderBox.Right, Delta);
+ Assert.AreEqual(b.Right + 22, c.Left, Delta);
+ }
+
+ [TestMethod]
+ [Spec("css21", "visuren.html#inline-formatting")]
+ [Spec("css-inline-3", "#line-boxes")]
+ public void InlineBox_StartingOnAWrappedLine_GetsItsStartMarginAndPaddingThere()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ "aaa bbb ccccccc
"));
+
+ var d = LayoutHarness.FindById(root, "d")!;
+ var c = FindWord(root, "ccccccc")!;
+
+ Assert.AreEqual(2, d.LineBoxes.Count);
+ Assert.AreEqual(d.LineBoxes[1].LineTop, c.Top, Delta);
+ Assert.AreEqual(25, c.Left, Delta);
+ }
+
+ [TestMethod]
+ [Spec("css21", "visuren.html#inline-formatting")]
+ public void InlineImage_WrappedToTheNextLine_KeepsItsStartMargin()
+ {
+ var root = TestImages.Layout(
+ $"aaa bbb
})
");
+
+ var d = LayoutHarness.FindById(root, "d")!;
+ var image = LayoutHarness.FindById(root, "i")!.Words.Single();
+
+ Assert.AreEqual(2, d.LineBoxes.Count);
+ Assert.AreEqual(20, image.Left, Delta);
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "visuren.html#inline-formatting")]
+ [Spec("css21", "box.html#box-dimensions")]
+ public void InlineBox_StartingOnAWrappedLine_HasItsBorderEdgeAfterItsStartMargin()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ "aaa bbb ccccccc
"));
+
+ var borderBox = LayoutHarness.FindById(root, "s")!.Rectangles.Values.Single();
+
+ Assert.AreEqual(20, borderBox.X, Delta);
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "visudet.html#inline-non-replaced")]
+ public void InlineBox_BottomPadding_ExtendsItsBorderBoxBelowTheContentArea()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ "a b
"));
+
+ var b = FindWord(root, "b")!;
+ var borderBox = LayoutHarness.FindById(root, "s")!.Rectangles.Values.Single();
+
+ Assert.AreEqual(b.Top, borderBox.Top, Delta);
+ Assert.AreEqual(b.Bottom + 10, borderBox.Bottom, Delta);
+ }
+
[TestMethod]
[Spec("css21", "visuren.html#inline-formatting")]
[Spec("css-inline-3", "#line-boxes")]
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Painting/BackgroundPaintIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Painting/BackgroundPaintIntegrationTests.cs
index 22a7a4259..71c9a8576 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Painting/BackgroundPaintIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Painting/BackgroundPaintIntegrationTests.cs
@@ -3,6 +3,7 @@
using TheArtOfDev.HtmlRenderer.Adapters.Entities;
using TheArtOfDev.HtmlRenderer.Core;
using TheArtOfDev.HtmlRenderer.Core.Dom;
+using TheArtOfDev.HtmlRenderer.Core.Entities;
namespace HtmlRenderer.IntegrationTest.Painting;
@@ -50,6 +51,18 @@ public void BackgroundColorTransparent_PaintsNothing()
Assert.IsFalse(g.Log.OfType().Any());
}
+ [TestMethod]
+ [Spec("css-backgrounds-3", "#background-color")]
+ public void BackgroundColor_OnAZeroWidthBox_PaintsNothing()
+ {
+ var (root, container) = PaintHarness.Layout(PaintHarness.Wrap(
+ ""));
+
+ var g = PaintHarness.PaintBox(container, PaintHarness.FindById(root, "b")!);
+
+ Assert.IsFalse(g.Log.OfType().Any(r => r.Color == Fill));
+ }
+
[TestMethod]
[Spec("css21", "colors.html#background-properties")]
public void BackgroundColorDefault_PaintsNothing()
@@ -337,11 +350,26 @@ public void BackgroundShorthand_ResetsOmittedLonghandsToTheirInitialValues()
Assert.IsFalse(g.Log.OfType().Any(r => r.Color == RColor.Empty));
}
+ [Ignore("Gap, see Spec/css-backgrounds-3.yml")]
+ [TestMethod]
+ [Timeout(5000)]
+ [DataRow("repeat-x")]
+ [DataRow("repeat")]
+ [Spec("css-backgrounds-3", "#background-repeat")]
+ public void BackgroundRepeat_ZeroWidthImageRectangle_DoesNotHang(string repeat)
+ {
+ // The image load callback limits the image to a 0x30 rectangle
+ var g = PaintBackground($"width:100px;height:100px;background-image:url(x.png);background-repeat:{repeat};background-position:right",
+ (_, e) => e.Callback(new MockImage(40, 30), 0, 0, 0, 30));
+
+ Assert.IsFalse(g.Log.OfType().Any(r => r.Color == RColor.Empty));
+ }
+
private static List Fills(RecordingGraphics g) =>
g.Log.OfType().Where(r => r.Color == Fill).ToList();
/// Lays out a div with at the origin, loading images synchronously, and paints it.
- private static RecordingGraphics PaintBackground(string style)
+ private static RecordingGraphics PaintBackground(string style, EventHandler? imageLoad = null)
{
var container = new HtmlContainerInt(new MockAdapter())
{
@@ -350,6 +378,8 @@ private static RecordingGraphics PaintBackground(string style)
PageSize = new RSize(1000, 4000),
AvoidAsyncImagesLoading = true
};
+ if (imageLoad != null)
+ container.ImageLoad += imageLoad;
container.SetHtml(PaintHarness.Wrap($"")).GetAwaiter().GetResult();
using (var layoutGraphics = new RecordingGraphics())
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Painting/BorderRadiusIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Painting/BorderRadiusIntegrationTests.cs
index 741dc5d9e..e4ed5ba5e 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Painting/BorderRadiusIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Painting/BorderRadiusIntegrationTests.cs
@@ -1,4 +1,5 @@
using HtmlRenderer.IntegrationTest.TestSupport;
+using TheArtOfDev.HtmlRenderer.Adapters;
using TheArtOfDev.HtmlRenderer.Adapters.Entities;
using TheArtOfDev.HtmlRenderer.Core.Dom;
@@ -157,6 +158,153 @@ public void BorderRadius_NonOverlappingRadii_AreNotChanged()
Assert.AreEqual(30.0, radii.TLY, 2);
}
+ [TestMethod]
+ [DataRow("80px 40px 0 40px", new[] { 80.0, 40, 0, 40 })]
+ [DataRow("40px 80px 40px 0", new[] { 40.0, 80, 40, 0 })]
+ [DataRow("0 40px 80px 40px", new[] { 0.0, 40, 80, 40 })]
+ [DataRow("40px 0 40px 80px", new[] { 40.0, 0, 40, 80 })]
+ [Spec("css-backgrounds-3", "#corner-overlap")]
+ [Spec("css-borders-4", "#corner-overlap")]
+ public void BorderRadius_OneOversizedCorner_ScalesAllRadiiByTheSmallestRatio(string radius, double[] corners)
+ {
+ // 100x100 box, the two sides at the large corner sum to 120: f = 100 / 120
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ $""));
+ var box = LayoutHarness.FindById(root, "c")!;
+
+ var radii = box.ComputeRadii(new RRect(0, 0, 100, 100));
+
+ var expected = corners.Select(c => c * 100 / 120).ToArray();
+ var x = new[] { radii.TLX, radii.TRX, radii.BRX, radii.BLX };
+ var y = new[] { radii.TLY, radii.TRY, radii.BRY, radii.BLY };
+ for (var i = 0; i < expected.Length; i++)
+ {
+ Assert.AreEqual(expected[i], x[i], 0.01, $"x radius {i}");
+ Assert.AreEqual(expected[i], y[i], 0.01, $"y radius {i}");
+ }
+ }
+
+ [TestMethod]
+ [DataRow("border-top-left-radius", RGraphicsPath.Corner.TopLeft)]
+ [DataRow("border-top-right-radius", RGraphicsPath.Corner.TopRight)]
+ [DataRow("border-bottom-right-radius", RGraphicsPath.Corner.BottomRight)]
+ [DataRow("border-bottom-left-radius", RGraphicsPath.Corner.BottomLeft)]
+ [Spec("css-backgrounds-3", "#corner-clipping")]
+ public void SingleRoundedCorner_ClipsTheBackgroundAtThatCornerOnly(string property, RGraphicsPath.Corner corner)
+ {
+ var g = PaintShapes($"width:100px;height:100px;background-color:rgb(10,20,30);{property}:10px");
+
+ var arc = g.Paths.Single(p => p.Brush == Fill).Arcs.Single();
+ Assert.AreEqual(corner, arc.Corner);
+ Assert.AreEqual(10, arc.RadiusX, Delta);
+ Assert.AreEqual(10, arc.RadiusY, Delta);
+ }
+
+ // The rounded border paths below are stroked along the middle of the border. Where the path meets a
+ // straight side it's exact, around the curve it's off by up to half the border width, see the
+ // corner-shaping gap in Spec/css-backgrounds-3.yml.
+
+ private const double HalfBorder = 2;
+
+ [TestMethod]
+ [Spec("css-backgrounds-3", "#corner-shaping")]
+ public void RoundedBorder_TopAndBottomBordersTakeTheCornerCurves()
+ {
+ // Border box 108x108, 4px borders, 10px radii
+ var g = PaintShapes("width:100px;height:100px;border:4px solid;border-color:rgb(1,0,0) rgb(2,0,0) rgb(3,0,0) rgb(4,0,0);border-radius:10px");
+
+ var top = g.Paths.Single(p => p.Pen == RColor.FromArgb(1, 0, 0));
+ CollectionAssert.AreEqual(new[] { RGraphicsPath.Corner.TopLeft, RGraphicsPath.Corner.TopRight }, top.Arcs.Select(a => a.Corner).ToArray());
+ AssertPoint(2, 10, top.Points[0], 0, HalfBorder);
+ AssertPoint(10, 2, top.Points[1], HalfBorder, 0);
+ AssertPoint(98, 2, top.Points[2], HalfBorder, 0);
+ AssertPoint(106, 10, top.Points[3], 0, HalfBorder);
+
+ var bottom = g.Paths.Single(p => p.Pen == RColor.FromArgb(3, 0, 0));
+ CollectionAssert.AreEqual(new[] { RGraphicsPath.Corner.BottomRight, RGraphicsPath.Corner.BottomLeft }, bottom.Arcs.Select(a => a.Corner).ToArray());
+ AssertPoint(106, 98, bottom.Points[0], 0, HalfBorder);
+ AssertPoint(98, 106, bottom.Points[1], HalfBorder, 0);
+ AssertPoint(10, 106, bottom.Points[2], HalfBorder, 0);
+ AssertPoint(2, 98, bottom.Points[3], 0, HalfBorder);
+
+ // The sides run straight between the curves
+ var right = g.Paths.Single(p => p.Pen == RColor.FromArgb(2, 0, 0));
+ Assert.AreEqual(0, right.Arcs.Count);
+ AssertPoint(106, 10, right.Points[0], 0, HalfBorder);
+ AssertPoint(106, 98, right.Points[1], 0, HalfBorder);
+
+ var left = g.Paths.Single(p => p.Pen == RColor.FromArgb(4, 0, 0));
+ Assert.AreEqual(0, left.Arcs.Count);
+ AssertPoint(2, 98, left.Points[0], 0, HalfBorder);
+ AssertPoint(2, 10, left.Points[1], 0, HalfBorder);
+ }
+
+ [TestMethod]
+ [Spec("css-backgrounds-3", "#corner-shaping")]
+ [Spec("css-backgrounds-3", "#corner-transitions")]
+ public void RoundedBorder_WithoutTopAndBottomBorders_TheSidesTakeTheCornerCurves()
+ {
+ // Border box 108x100, a corner without an adjoining border belongs to the side entirely
+ var g = PaintShapes("width:100px;height:100px;border:4px solid;border-color:rgb(1,0,0) rgb(2,0,0) rgb(3,0,0) rgb(4,0,0);border-top:none;border-bottom:none;border-radius:10px");
+
+ Assert.AreEqual(2, g.Paths.Count);
+
+ var right = g.Paths.Single(p => p.Pen == RColor.FromArgb(2, 0, 0));
+ CollectionAssert.AreEqual(new[] { RGraphicsPath.Corner.TopRight, RGraphicsPath.Corner.BottomRight }, right.Arcs.Select(a => a.Corner).ToArray());
+ AssertPoint(98, 0, right.Points[0], HalfBorder, 0);
+ AssertPoint(106, 10, right.Points[1], 0, 0);
+ AssertPoint(106, 90, right.Points[2], 0, 0);
+ AssertPoint(98, 100, right.Points[3], HalfBorder, 0);
+
+ var left = g.Paths.Single(p => p.Pen == RColor.FromArgb(4, 0, 0));
+ CollectionAssert.AreEqual(new[] { RGraphicsPath.Corner.BottomLeft, RGraphicsPath.Corner.TopLeft }, left.Arcs.Select(a => a.Corner).ToArray());
+ AssertPoint(10, 100, left.Points[0], HalfBorder, 0);
+ AssertPoint(2, 90, left.Points[1], 0, 0);
+ AssertPoint(2, 10, left.Points[2], 0, 0);
+ AssertPoint(10, 0, left.Points[3], HalfBorder, 0);
+ }
+
+ [Ignore("Gap, see Spec/css-backgrounds-3.yml")]
+ [TestMethod]
+ [Spec("css-backgrounds-3", "#corner-shaping")]
+ public void RoundedRightBorderAlone_CurveEndsOnTheMiddleOfTheRightBorder()
+ {
+ // Border box 104x100, no left border
+ var g = PaintShapes("width:100px;height:100px;border-right:4px solid black;border-radius:10px");
+
+ var right = g.Paths.Single(p => p.Pen != null);
+ AssertPoint(102, 10, right.Arcs[0].End, 0, 0);
+ }
+
+ [TestMethod]
+ [DataRow(false, true)]
+ [DataRow(true, false)]
+ public void RoundedBackgroundAndBorder_AreAntiAliasedUnlessAvoided(bool avoid, bool antiAliased)
+ {
+ var g = PaintShapes("width:100px;height:100px;background-color:rgb(10,20,30);border:4px solid black;border-radius:10px", avoid);
+
+ Assert.AreEqual(5, g.Paths.Count);
+ Assert.IsTrue(g.Paths.All(p => p.AntiAliased == antiAliased));
+ Assert.IsFalse(g.AntiAlias, "the previous mode is restored");
+ }
+
+ private static readonly RColor Fill = RColor.FromArgb(10, 20, 30);
+
+ private static ShapeRecordingGraphics PaintShapes(string style, bool avoidGeometryAntialias = false)
+ {
+ var (root, container) = PaintHarness.Layout(PaintHarness.Wrap($""));
+ container.AvoidGeometryAntialias = avoidGeometryAntialias;
+ var g = new ShapeRecordingGraphics();
+ PaintHarness.PaintBox(container, PaintHarness.FindById(root, "c")!, g);
+ return g;
+ }
+
+ private static void AssertPoint(double x, double y, RPoint actual, double xTolerance, double yTolerance)
+ {
+ Assert.AreEqual(x, actual.X, xTolerance + 0.01, $"X of {actual}");
+ Assert.AreEqual(y, actual.Y, yTolerance + 0.01, $"Y of {actual}");
+ }
+
private static CssBox FindDivBox(string css)
{
var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Painting/BorderStylePaintIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Painting/BorderStylePaintIntegrationTests.cs
index ded88db60..2c94443cc 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Painting/BorderStylePaintIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Painting/BorderStylePaintIntegrationTests.cs
@@ -41,8 +41,8 @@ public void InsetAndOutset_DarkenOppositeSides(string style, int topLeft, int bo
var g = PaintHarness.PaintBox(container, PaintHarness.FindById(root, "b")!);
// Painted in the order top, left, bottom, right
- var colors = g.Log.OfType().Select(p => p.Color.R).ToList();
- CollectionAssert.AreEqual(new[] { topLeft, topLeft, bottomRight, bottomRight }, colors.Select(c => (int)c).ToList());
+ var colors = g.Log.OfType().Select(p => p.Color).ToList();
+ CollectionAssert.AreEqual(new[] { topLeft, topLeft, bottomRight, bottomRight }.Select(c => RColor.FromArgb(c, c, c)).ToList(), colors);
}
[Ignore("Gap, see Spec/css21.yml")]
@@ -202,6 +202,31 @@ public void BorderStyleDoubleWithRoundedCorners_FallsBackToASingleUnstripedStrok
Assert.IsFalse(g.Log.OfType().Any());
}
+ [TestMethod]
+ [DataRow("border-top:4px hidden")]
+ [DataRow("border-right:4px hidden")]
+ [DataRow("border-bottom:4px hidden")]
+ [DataRow("border-left:4px hidden")]
+ [DataRow("border-top:0 solid")]
+ [DataRow("border-right:0 solid")]
+ [DataRow("border-bottom:0 solid")]
+ [DataRow("border-left:0 solid")]
+ [DataRow("width:0;border-top:4px solid")]
+ [DataRow("width:0;border-bottom:4px solid")]
+ [Spec("css21", "box.html#border-style-properties")]
+ [Spec("css21", "box.html#border-width-properties")]
+ [Spec("css-backgrounds-3", "#border-style")]
+ [Spec("css-backgrounds-3", "#border-width")]
+ public void HiddenZeroWidthOrEmptyBorder_PaintsNothing(string border)
+ {
+ var (root, container) = PaintHarness.Layout(PaintHarness.Wrap(
+ $""));
+
+ var g = PaintHarness.PaintBox(container, PaintHarness.FindById(root, "b")!);
+
+ Assert.IsFalse(g.Log.Any(c => c is RecordingGraphics.DrawLineCall or RecordingGraphics.DrawPolygonCall));
+ }
+
[TestMethod]
[Spec("css21", "box.html#border-style-properties")]
[Spec("css-backgrounds-3", "#border-style")]
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Painting/CssBackgrounds3Tests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Painting/CssBackgrounds3Tests.cs
index fc782fc5a..fe0d1e3d4 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Painting/CssBackgrounds3Tests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Painting/CssBackgrounds3Tests.cs
@@ -278,8 +278,15 @@ public void AdjoiningInsetBorders_MeetAtTheDiagonal()
{
var g = PaintShapes("width:20px;height:20px;border-style:inset;border-width:10px;border-color:red blue");
- var top = g.Log.OfType().Single(p => p.Points.All(pt => pt.Y <= 10));
+ var polygons = g.Log.OfType().ToList();
+ var top = polygons.Single(p => p.Points.All(pt => pt.Y <= 10));
CollectionAssert.AreEquivalent(new[] { new RPoint(0, 0), new RPoint(40, 0), new RPoint(30, 10), new RPoint(10, 10) }, top.Points);
+ var right = polygons.Single(p => p.Points.All(pt => pt.X >= 30));
+ CollectionAssert.AreEquivalent(new[] { new RPoint(30, 10), new RPoint(40, 0), new RPoint(40, 40), new RPoint(30, 30) }, right.Points);
+ var bottom = polygons.Single(p => p.Points.All(pt => pt.Y >= 30));
+ CollectionAssert.AreEquivalent(new[] { new RPoint(10, 30), new RPoint(30, 30), new RPoint(40, 40), new RPoint(0, 40) }, bottom.Points);
+ var left = polygons.Single(p => p.Points.All(pt => pt.X <= 10));
+ CollectionAssert.AreEquivalent(new[] { new RPoint(0, 0), new RPoint(10, 10), new RPoint(10, 30), new RPoint(0, 40) }, left.Points);
}
[Ignore("Gap, see Spec/css-backgrounds-3.yml")]
@@ -405,47 +412,4 @@ private static ShapeRecordingGraphics PaintShapes(string style)
PaintHarness.PaintBox(container, box, g);
return g;
}
-
- internal sealed record Arc(RPoint End, double RadiusX, double RadiusY);
-
- internal sealed class ShapePath : RGraphicsPath
- {
- public List Points { get; } = [];
- public List Arcs { get; } = [];
- public RColor? Brush { get; set; }
- public RColor? Pen { get; set; }
-
- public override void Start(double x, double y) => Points.Add(new RPoint(x, y));
- public override void LineTo(double x, double y) => Points.Add(new RPoint(x, y));
-
- public override void ArcTo(double x, double y, double radiusX, double radiusY, Corner corner)
- {
- Points.Add(new RPoint(x, y));
- Arcs.Add(new Arc(new RPoint(x, y), radiusX, radiusY));
- }
-
- public override void Dispose() { }
- }
-
- /// Also records the paths, which drops.
- internal sealed class ShapeRecordingGraphics : RecordingGraphics
- {
- public List Paths { get; } = [];
-
- public override RGraphicsPath GetGraphicsPath() => new ShapePath();
-
- public override void DrawPath(RPen pen, RGraphicsPath path)
- {
- var shape = (ShapePath)path;
- shape.Pen = pen is MockPen p ? p.Color : RColor.Empty;
- Paths.Add(shape);
- }
-
- public override void DrawPath(RBrush brush, RGraphicsPath path)
- {
- var shape = (ShapePath)path;
- shape.Brush = brush is MockBrush b ? b.Color : RColor.Empty;
- Paths.Add(shape);
- }
- }
}
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Painting/CssImages3Tests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Painting/CssImages3Tests.cs
index 2a391e0a1..d2925fc73 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Painting/CssImages3Tests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Painting/CssImages3Tests.cs
@@ -14,6 +14,7 @@ public sealed class CssImages3Tests
private static readonly RColor Red = RColor.FromArgb(255, 0, 0);
private static readonly RColor Blue = RColor.FromArgb(0, 0, 255);
+ private static readonly RColor Lime = RColor.FromArgb(0, 255, 0);
[TestMethod]
[Spec("css-images-3", "#url-notation")]
@@ -164,6 +165,86 @@ public void ColorHint_ShiftsTheMidpointOfTheTransition()
Assert.IsTrue(atHint.Position < 0.3, $"half the color at {atHint.Position}");
}
+ [TestMethod]
+ [DataRow("rgb(0,0,0) 20%, 30%, rgb(200,100,40) 60%", new[] { 255, 100, 50, 20 }, new[] { 255, 141, 71, 28 })]
+ [DataRow("rgba(0,0,0,0) 20%, 30%, rgba(0,0,0,1) 60%", new[] { 128, 0, 0, 0 }, new[] { 180, 0, 0, 0 })]
+ [Spec("css-images-3", "#coloring-gradient-line")]
+ [Spec("css-images-4", "#coloring-gradient-line")]
+ public void ColorHint_BlendsAlongTheCurveThroughTheHint(string stops, int[] atHint, int[] atMiddle)
+ {
+ var (_, gradient) = Paint($"");
+
+ // The hint is at H = 1/4 of the transition, the color weight is P^(log_H 0.5) = sqrt(P): 1/2 at the hint, sqrt(1/2) halfway
+ AssertColor(atHint, gradient!.Stops.Single(s => Math.Abs(s.Position - 0.3) < 1e-6).Color);
+ AssertColor(atMiddle, gradient.Stops.Single(s => Math.Abs(s.Position - 0.4) < 1e-6).Color);
+ }
+
+ [Ignore("Gap, see Spec/css-images-3.yml")]
+ [TestMethod]
+ [DataRow("red, blue, 50%")]
+ [DataRow("50%, red, blue")]
+ [Spec("css-images-3", "#color-stop-syntax")]
+ public void ColorHint_OutsideTheColorStops_MakesTheGradientInvalid(string stops)
+ {
+ var (_, gradient) = Paint($"");
+
+ Assert.IsNull(gradient);
+ }
+
+ [TestMethod]
+ [Spec("css-images-3", "#color-stop-syntax")]
+ public void ColorStops_ResolveEm()
+ {
+ var (_, gradient) = Paint("");
+
+ CollectionAssert.AreEqual(new[] { 0.16, 0.32 }, gradient!.Stops.Select(s => Math.Round(s.Position, 3)).ToArray());
+ }
+
+ [TestMethod]
+ [Spec("css-images-3", "#repeating-gradients")]
+ [Spec("css-images-4", "#repeating-gradients")]
+ public void RepeatingLinearGradient_StartingInsideTheLine_RepeatsTheTileBothWays()
+ {
+ var (_, gradient) = Paint("");
+
+ // The same as linear-gradient(red -30px, lime -10px, blue 10px, red 10px, lime 30px, blue 50px, red 50px, ...)
+ var stops = gradient!.Stops;
+ CollectionAssert.AreEqual(new[] { 0.1, 0.5, 0.9 }, stops.Where(s => s.Color == Red).Select(s => Math.Round(s.Position, 3)).ToArray());
+ CollectionAssert.AreEqual(new[] { 0.3, 0.7 }, stops.Where(s => s.Color == Lime).Select(s => Math.Round(s.Position, 3)).ToArray());
+ Assert.AreEqual(0, stops[0].Position);
+ AssertColor(new[] { 255, 0, 128, 128 }, stops[0].Color);
+ Assert.AreEqual(1, stops[^1].Position);
+ AssertColor(new[] { 255, 128, 128, 0 }, stops[^1].Color);
+ }
+
+ [TestMethod]
+ [Spec("css-images-3", "#repeating-gradients")]
+ public void RepeatingLinearGradient_TileSpanningTheLine_IsNotRepeated()
+ {
+ var (_, gradient) = Paint("");
+
+ CollectionAssert.AreEqual(new[] { (Red, 0.0), (Blue, 1.0) }, gradient!.Stops);
+ }
+
+ [Ignore("Gap, see Spec/css-images-3.yml")]
+ [TestMethod]
+ [Spec("css-images-3", "#repeating-gradients")]
+ public void RepeatingLinearGradient_WithAZeroLengthTile_IsTheAverageColor()
+ {
+ var (_, gradient) = Paint("");
+
+ foreach (var stop in gradient!.Stops)
+ AssertColor(new[] { 255, 128, 0, 128 }, stop.Color);
+ }
+
+ private static void AssertColor(int[] argb, RColor actual)
+ {
+ Assert.AreEqual(argb[0], actual.A, 1, $"A of {actual}");
+ Assert.AreEqual(argb[1], actual.R, 1, $"R of {actual}");
+ Assert.AreEqual(argb[2], actual.G, 1, $"G of {actual}");
+ Assert.AreEqual(argb[3], actual.B, 1, $"B of {actual}");
+ }
+
[Ignore("Gap, see Spec/css-images-3.yml")]
[TestMethod]
[Spec("css-images-3", "#coloring-gradient-line")]
@@ -178,13 +259,15 @@ public void ColorsAreInterpolatedPremultiplied()
}
[TestMethod]
+ [DataRow("red, blue, red 60%, blue, red", new[] { 0, 0.3, 0.6, 0.8, 1 })]
+ [DataRow("red 10%, blue, lime, red 70%, blue, lime", new[] { 0.1, 0.3, 0.5, 0.7, 0.85, 1 })]
[Spec("css-images-3", "#color-stop-fixup")]
[Spec("css-images-4", "#color-stop-fixup")]
- public void ColorStopFixup_DefaultsTheEndsAndSpacesStopsEvenly()
+ public void ColorStopFixup_DefaultsTheEndsAndSpacesStopsEvenly(string stops, double[] positions)
{
- var (_, gradient) = Paint("");
+ var (_, gradient) = Paint($"");
- CollectionAssert.AreEqual(new[] { 0, 0.3, 0.6, 0.8, 1 }, gradient!.Stops.Select(s => Math.Round(s.Position, 3)).ToArray());
+ CollectionAssert.AreEqual(positions, gradient!.Stops.Select(s => Math.Round(s.Position, 3)).ToArray());
}
[Ignore("Gap, see Spec/css-images-3.yml")]
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Painting/OutlineStylePaintIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Painting/OutlineStylePaintIntegrationTests.cs
index e61d5240e..977e19a49 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Painting/OutlineStylePaintIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Painting/OutlineStylePaintIntegrationTests.cs
@@ -29,6 +29,30 @@ public void SolidOutline_PaintsAFourSidedRingAroundTheBorderBox()
Assert.AreEqual(2, rects.Count(r => System.Math.Abs(r.Width - 5) < 0.1));
}
+ [TestMethod]
+ [Spec("css21", "ui.html#dynamic-outlines")]
+ [Spec("css-ui-3", "#outline")]
+ [Spec("css-ui-4", "#outline")]
+ public void SolidOutline_RingStartsJustOutsideTheBorderEdge()
+ {
+ // Border box 104x54 at the origin
+ var (root, container) = PaintHarness.Layout(PaintHarness.Wrap(
+ ""));
+
+ var g = PaintHarness.PaintBox(container, PaintHarness.FindById(root, "b")!);
+ var bands = g.Log.OfType().Where(r => r.Color == RColor.FromArgb(51, 51, 51)).ToList();
+
+ // Top and bottom bands span the corners, the side bands fill in between
+ var color = RColor.FromArgb(51, 51, 51);
+ CollectionAssert.AreEquivalent(new[]
+ {
+ new RecordingGraphics.DrawRectCall(color, -5, -5, 114, 5),
+ new RecordingGraphics.DrawRectCall(color, -5, 54, 114, 5),
+ new RecordingGraphics.DrawRectCall(color, -5, 0, 5, 54),
+ new RecordingGraphics.DrawRectCall(color, 104, 0, 5, 54),
+ }, bands);
+ }
+
[Ignore("Gap, see Spec/css-ui-3.yml")]
[TestMethod]
[Spec("css-ui-3", "#outline-style")]
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Positioning/OutOfFlowPositioningIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Positioning/OutOfFlowPositioningIntegrationTests.cs
index 18d9115bd..ab8444507 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Positioning/OutOfFlowPositioningIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Positioning/OutOfFlowPositioningIntegrationTests.cs
@@ -24,6 +24,21 @@ public void PositionAbsolute_HasNoImpactOnLaterSiblings()
Assert.AreEqual(LayoutHarness.FindById(root, "a")!.ActualBottom, LayoutHarness.FindById(root, "b")!.Location.Y, Delta);
}
+ [TestMethod]
+ [Spec("css21", "visuren.html#absolute-positioning")]
+ [Spec("css21", "visudet.html#abs-non-replaced-width")]
+ public void PositionAbsolute_InlineBox_StartsAtItsStaticPositionAndLeavesTheLineAlone()
+ {
+ var html = LayoutHarness.Wrap(
+ "abc
");
+ var (root, _) = LayoutHarness.Layout(html);
+ var a = FindWord(root, "a")!;
+
+ // The static position is where 'b' would start in the flow, its left margin comes on top
+ Assert.AreEqual(a.Right + 30, FindWord(root, "b")!.Left, Delta);
+ Assert.AreEqual(a.Right, FindWord(root, "c")!.Left, Delta);
+ }
+
[TestMethod]
[Spec("css21", "box.html#collapsing-margins")]
public void PositionAbsolute_MarginsDoNotCollapse()
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Tables/AnonymousTableBoxIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Tables/AnonymousTableBoxIntegrationTests.cs
index 8b9799ef8..d8088d2bd 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Tables/AnonymousTableBoxIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Tables/AnonymousTableBoxIntegrationTests.cs
@@ -9,6 +9,66 @@ namespace HtmlRenderer.IntegrationTest.Tables;
[TestClass]
public sealed class AnonymousTableBoxIntegrationTests
{
+ [TestMethod]
+ [Spec("css21", "tables.html#anonymous-boxes")]
+ [Spec("css-tables-3", "#fixup-algorithm")]
+ public void InlineContentOfATable_IsLaidOutInAnAnonymousRowAndCell()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ "text
"));
+
+ AssertInAnonymousCellOfTable(root);
+ }
+
+ [TestMethod]
+ [Spec("css21", "tables.html#anonymous-boxes")]
+ [Spec("css-tables-3", "#fixup-algorithm")]
+ public void InlineContentOfARowGroup_IsLaidOutInAnAnonymousRowAndCell()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""));
+
+ AssertInAnonymousCellOfTable(root);
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "tables.html#anonymous-boxes")]
+ [Spec("css-tables-3", "#fixup-algorithm")]
+ public void NonCellBeforeACellInARow_GetsItsOwnAnonymousCellNextToTheCell()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""));
+
+ var row = FindByClass(root, "r")!;
+ var cell = FindByClass(root, "c")!;
+
+ Assert.AreSame(row, cell.ParentBox);
+ Assert.HasCount(2, row.Boxes);
+ Assert.AreEqual(row.Boxes[0].ActualRight, cell.Location.X, 0.5);
+ Assert.AreEqual(row.Boxes[0].Location.Y, cell.Location.Y, 0.5);
+ }
+
+ /// The span "s" sits in an anonymous cell, inset by the 10px border spacing of table "t".
+ private static void AssertInAnonymousCellOfTable(CssBox root)
+ {
+ var table = FindByClass(root, "t")!;
+ var span = FindByClass(root, "s")!;
+
+ var cell = span.ParentBox!;
+ Assert.IsNull(cell.HtmlTag);
+ Assert.AreEqual(CssConstants.TableCell, cell.Display);
+ Assert.IsNull(cell.ParentBox!.HtmlTag);
+ Assert.AreEqual(CssConstants.TableRow, cell.ParentBox.Display);
+
+ var word = LayoutHarness.Descendants(span).SelectMany(b => b.Words).Single();
+ Assert.AreEqual(table.Location.X + 10, cell.Location.X, 0.5);
+ Assert.AreEqual(table.Location.Y + 10, cell.Location.Y, 0.5);
+ Assert.AreEqual(cell.Location.X, word.Left, 0.5);
+ Assert.AreEqual(word.Width + 20, table.ActualRight - table.Location.X, 0.5);
+ }
+
[Ignore("Gap, see Spec/css21.yml")]
[TestMethod]
[Spec("css21", "tables.html#anonymous-boxes")]
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Tables/StructuralCloneBreakValueBehaviourTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Tables/StructuralCloneBreakValueBehaviourTests.cs
index 2d125c990..7acd5b544 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Tables/StructuralCloneBreakValueBehaviourTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Tables/StructuralCloneBreakValueBehaviourTests.cs
@@ -3,6 +3,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TheArtOfDev.HtmlRenderer.Core.Dom;
using TheArtOfDev.HtmlRenderer.Core.Utils;
+using static HtmlRenderer.IntegrationTest.TestSupport.Fragments;
namespace HtmlRenderer.IntegrationTest.Tables;
@@ -152,13 +153,4 @@ private static string TableDocument(string headerRowCss)
+ $"| Header 1 | Header 2 |
"
+ $"{rows}");
}
-
- private static System.Collections.Generic.IEnumerable Flatten(
- TheArtOfDev.HtmlRenderer.Core.Fragments.BoxFragment fragment)
- {
- yield return fragment;
- foreach (var child in fragment.Children)
- foreach (var descendant in Flatten(child))
- yield return descendant;
- }
}
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Tables/TableSizingIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Tables/TableSizingIntegrationTests.cs
index e4bbaa3bf..9f1ca441f 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Tables/TableSizingIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Tables/TableSizingIntegrationTests.cs
@@ -163,6 +163,155 @@ public void CaptionMinimumWidth_WidensTheTable()
Assert.IsGreaterThan(100, Width(LayoutHarness.FindById(root, "t")!));
}
+ [TestMethod]
+ [Spec("css21", "tables.html#auto-table-layout")]
+ [Spec("css-tables-3", "#computing-column-measures")]
+ public void SpanningCell_TheColumnsItSpansAreTogetherAsWideAsTheCell()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""
+ + "| x | x |
"
+ + "| Supercalifragilisticexpialidocious |
"));
+
+ var s = LayoutHarness.FindById(root, "s")!;
+ var word = LayoutHarness.Descendants(s).SelectMany(b => b.Words).Single().Width;
+
+ Assert.AreEqual(word, Width(s), Delta);
+ Assert.AreEqual(word, Width(LayoutHarness.FindById(root, "a")!) + 4 + Width(LayoutHarness.FindById(root, "b")!), Delta);
+ Assert.AreEqual(word + 2 * 4, Width(LayoutHarness.FindById(root, "t")!), Delta);
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "tables.html#auto-table-layout")]
+ [Spec("css-tables-3", "#computing-column-measures")]
+ public void SpanningCellAfterAnotherCell_DoesNotNarrowThatCellsColumn()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""
+ + "| x | x | x |
"
+ + "| Mississippi | Supercalifragilisticexpialidocious |
"));
+
+ var d = LayoutHarness.FindById(root, "d")!;
+
+ Assert.IsGreaterThanOrEqualTo(LayoutHarness.Descendants(d).SelectMany(b => b.Words).Single().Width - Delta, Width(d));
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "tables.html#auto-table-layout")]
+ [Spec("css-tables-3", "#computing-column-measures")]
+ public void SpanningCellOverAWideColumn_IsAsWideAsItsContent()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""
+ + "| Mississippi | x | x |
"
+ + "| Supercalifragilisticexpialidocious | x |
"));
+
+ var s = LayoutHarness.FindById(root, "s")!;
+
+ Assert.IsGreaterThanOrEqualTo(LayoutHarness.Descendants(s).SelectMany(b => b.Words).Single().Width - Delta, Width(s));
+ }
+
+ [TestMethod]
+ [Spec("css21", "visudet.html#min-max-widths")]
+ [Spec("css-tables-3", "#computing-the-table-width")]
+ public void MaxWidth_LimitsAnAutoWidthTable()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""
+ + "| aaa bbb ccc ddd eee fff ggg hhh iii jjj | "
+ + "aaa bbb ccc ddd eee fff ggg hhh iii jjj |
"));
+
+ Assert.AreEqual(200, Width(LayoutHarness.FindById(root, "t")!), Delta);
+ Assert.AreEqual(100, Width(LayoutHarness.FindById(root, "a")!), Delta);
+ Assert.AreEqual(100, Width(LayoutHarness.FindById(root, "b")!), Delta);
+ }
+
+ [TestMethod]
+ [Spec("css21", "visudet.html#min-max-widths")]
+ [Spec("css-tables-3", "#computing-the-table-width")]
+ public void PercentageMaxWidth_IsRelativeToTheContainingBlock()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""
+ + "| aaa bbb ccc ddd eee fff ggg hhh iii jjj | "
+ + "aaa bbb ccc ddd eee fff ggg hhh iii jjj |
"));
+
+ Assert.AreEqual(200, Width(LayoutHarness.FindById(root, "t")!), Delta);
+ }
+
+ [TestMethod]
+ [Spec("css21", "visudet.html#min-max-widths")]
+ [Spec("css-tables-3", "#distributing-width-to-columns")]
+ public void MaxWidth_ColumnWhoseContentFits_KeepsItsMaxContentWidth()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""
+ + "| a | "
+ + "aaa bbb ccc ddd eee fff ggg hhh iii jjj |
"));
+
+ var a = LayoutHarness.FindById(root, "a")!;
+
+ Assert.AreEqual(LayoutHarness.Descendants(a).SelectMany(b => b.Words).Single().Width, Width(a), 1);
+ Assert.AreEqual(200, Width(a) + Width(LayoutHarness.FindById(root, "b")!), Delta);
+ Assert.AreEqual(200, Width(LayoutHarness.FindById(root, "t")!), Delta);
+ }
+
+ [Ignore("Gap, see Spec/css-tables-3.yml")]
+ [TestMethod]
+ [Spec("css21", "visudet.html#min-max-widths")]
+ [Spec("css-tables-3", "#computing-the-table-width")]
+ public void MaxWidthBelowTheMinimumContentWidth_DoesNotNarrowTheColumns()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""
+ + "| Supercalifragilistic | Supercalifragilistic |
"));
+
+ var a = LayoutHarness.FindById(root, "a")!;
+
+ Assert.AreEqual(LayoutHarness.Descendants(a).SelectMany(b => b.Words).Single().Width, Width(a), 1);
+ }
+
+ [Ignore("Gap, see Spec/css-tables-3.yml")]
+ [TestMethod]
+ [Spec("css21", "tables.html#auto-table-layout")]
+ [Spec("css-tables-3", "#computing-the-table-width")]
+ public void PercentageCellWidthsOverAHundredPercent_DoNotWidenTheTablePastTheContainingBlock()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""));
+
+ Assert.AreEqual(400, Width(LayoutHarness.FindById(root, "t")!), 1);
+ }
+
+ [TestMethod]
+ [Spec("css21", "visudet.html#float-width")]
+ [Spec("css21", "tables.html#separated-borders")]
+ public void FloatAroundATable_IsAsWideAsTheTableWithItsBorderSpacing()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""));
+
+ Assert.AreEqual(130, Width(LayoutHarness.FindById(root, "t")!), Delta);
+ Assert.AreEqual(130, Width(LayoutHarness.FindById(root, "f")!), Delta);
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "visudet.html#float-width")]
+ [Spec("css21", "tables.html#separated-borders")]
+ public void FloatAroundATableWithARowGroup_IsAsWideAsTheTableWithItsBorderSpacing()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ ""));
+
+ Assert.AreEqual(130, Width(LayoutHarness.FindById(root, "f")!), Delta);
+ }
+
[TestMethod]
[Spec("css21", "tables.html#height-layout")]
[Spec("css-tables-3", "#computing-the-table-height")]
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/TestSupport/Fragments.cs b/Source/Test/HtmlRenderer.IntegrationTest/TestSupport/Fragments.cs
new file mode 100644
index 000000000..aaa973f74
--- /dev/null
+++ b/Source/Test/HtmlRenderer.IntegrationTest/TestSupport/Fragments.cs
@@ -0,0 +1,27 @@
+using TheArtOfDev.HtmlRenderer.Core.Fragments;
+
+namespace HtmlRenderer.IntegrationTest.TestSupport;
+
+internal static class Fragments
+{
+ /// and all its descendants, depth first.
+ internal static IEnumerable Flatten(BoxFragment fragment)
+ {
+ yield return fragment;
+ foreach (var child in fragment.Children)
+ foreach (var descendant in Flatten(child))
+ yield return descendant;
+ }
+
+ /// Like , plus each fragment's list marker after its children.
+ internal static IEnumerable FlattenWithMarkers(BoxFragment fragment)
+ {
+ yield return fragment;
+ foreach (var child in fragment.Children)
+ foreach (var descendant in FlattenWithMarkers(child))
+ yield return descendant;
+ if (fragment.MarkerFragment != null)
+ foreach (var descendant in FlattenWithMarkers(fragment.MarkerFragment))
+ yield return descendant;
+ }
+}
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/TestSupport/LayoutHarness.cs b/Source/Test/HtmlRenderer.IntegrationTest/TestSupport/LayoutHarness.cs
index f5c2c0b45..5abfbf5ed 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/TestSupport/LayoutHarness.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/TestSupport/LayoutHarness.cs
@@ -3,6 +3,7 @@
using TheArtOfDev.HtmlRenderer.Adapters.Entities;
using TheArtOfDev.HtmlRenderer.Core;
using TheArtOfDev.HtmlRenderer.Core.Dom;
+using TheArtOfDev.HtmlRenderer.Core.Entities;
using TheArtOfDev.HtmlRenderer.WinForms.Adapters;
namespace HtmlRenderer.IntegrationTest.TestSupport;
@@ -57,11 +58,20 @@ internal static (CssBox Root, HtmlContainerInt Container) Layout(
prepare(container.Root!);
}
+ // CssBox.PerformLayout reports exceptions instead of throwing them
+ var layoutErrors = new List();
+ container.RenderError += (_, e) =>
+ {
+ if (e.Type == HtmlRenderErrorType.Layout)
+ layoutErrors.Add(e.Message + ": " + e.Exception);
+ };
+
using var bitmap = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
using var g = Graphics.FromImage(bitmap);
using var graphics = new GraphicsAdapter(g, false);
container.PerformLayout(graphics);
+ Assert.IsEmpty(layoutErrors, string.Join(Environment.NewLine, layoutErrors));
Assert.IsNotNull(container.Root);
return (container.Root!, container);
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/TestSupport/RecordingGraphics.cs b/Source/Test/HtmlRenderer.IntegrationTest/TestSupport/RecordingGraphics.cs
index cad197738..f1d5d69f0 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/TestSupport/RecordingGraphics.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/TestSupport/RecordingGraphics.cs
@@ -122,3 +122,65 @@ public override void DrawPolygon(RBrush brush, RPoint[] points)
public override void Dispose() { }
}
+
+internal sealed record Arc(RPoint End, double RadiusX, double RadiusY, RGraphicsPath.Corner Corner);
+
+/// A path that records its points and arcs, and the pen or brush it was drawn with.
+internal sealed class ShapePath : RGraphicsPath
+{
+ public List Points { get; } = [];
+ public List Arcs { get; } = [];
+ public RColor? Brush { get; set; }
+ public RColor? Pen { get; set; }
+ public bool AntiAliased { get; set; }
+
+ public override void Start(double x, double y) => Points.Add(new RPoint(x, y));
+ public override void LineTo(double x, double y) => Points.Add(new RPoint(x, y));
+
+ public override void ArcTo(double x, double y, double radiusX, double radiusY, Corner corner)
+ {
+ Points.Add(new RPoint(x, y));
+ Arcs.Add(new Arc(new RPoint(x, y), radiusX, radiusY, corner));
+ }
+
+ public override void Dispose() { }
+}
+
+/// Also records the paths, which drops, and the anti-aliasing mode.
+internal sealed class ShapeRecordingGraphics : RecordingGraphics
+{
+ public List Paths { get; } = [];
+
+ public bool AntiAlias { get; private set; }
+
+ public override RGraphicsPath GetGraphicsPath() => new ShapePath();
+
+ public override object SetAntiAliasSmoothingMode()
+ {
+ var prev = AntiAlias;
+ AntiAlias = true;
+ return prev;
+ }
+
+ public override void ReturnPreviousSmoothingMode(object prevMode)
+ {
+ if (prevMode is bool prev)
+ AntiAlias = prev;
+ }
+
+ public override void DrawPath(RPen pen, RGraphicsPath path)
+ {
+ var shape = (ShapePath)path;
+ shape.Pen = pen is MockPen p ? p.Color : RColor.Empty;
+ shape.AntiAliased = AntiAlias;
+ Paths.Add(shape);
+ }
+
+ public override void DrawPath(RBrush brush, RGraphicsPath path)
+ {
+ var shape = (ShapePath)path;
+ shape.Brush = brush is MockBrush b ? b.Color : RColor.Empty;
+ shape.AntiAliased = AntiAlias;
+ Paths.Add(shape);
+ }
+}
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Text/CssFonts4IntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Text/CssFonts4IntegrationTests.cs
index 3f206763d..c2ab770f8 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Text/CssFonts4IntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Text/CssFonts4IntegrationTests.cs
@@ -112,6 +112,68 @@ public void FontFace_WeightDescriptor_SelectsTheNearestFace(string weight, strin
Assert.AreEqual(expected, font.Name);
}
+ [TestMethod]
+ [Spec("css-fonts-4", "#font-style-matching")]
+ [DataRow("300 450 500 600", 400, 450)]
+ [DataRow("300 500 600", 400, 500)]
+ [DataRow("100 300 600", 400, 300)]
+ [DataRow("600 800", 400, 600)]
+ [DataRow("400 500", 450, 500)]
+ [DataRow("100 200 500", 300, 200)]
+ [DataRow("400 500", 300, 400)]
+ [DataRow("400 700 900", 600, 700)]
+ [DataRow("300 450", 600, 450)]
+ [DataRow("600 700", 800, 700)]
+ [DataRow("100 200 900", 500, 200)]
+ public void FontFace_Weight_FollowsTheFallbackOrder(string faceWeights, int desired, int expected)
+ {
+ var family = $"F4WeightOrder{faceWeights.Replace(" ", "")}x{desired}";
+ var css = string.Concat(faceWeights.Split(' ').Select(w =>
+ $"@font-face {{ font-family: {family}; src: url({FontUri(WeightFaces[int.Parse(w)].File)}); font-weight: {w} }}"));
+
+ var font = FontOf(css, $"x");
+
+ Assert.AreEqual(WeightFaces[expected].Name, font.Name);
+ }
+
+ [TestMethod]
+ [Spec("css-fonts-4", "#font-style-matching")]
+ [DataRow("condensed expanded", "semi-condensed", "condensed")]
+ [DataRow("ultra-condensed semi-expanded", "condensed", "ultra-condensed")]
+ [DataRow("ultra-condensed condensed semi-expanded", "semi-condensed", "condensed")]
+ [DataRow("semi-condensed semi-expanded", "normal", "semi-condensed")]
+ [DataRow("semi-expanded expanded", "semi-condensed", "semi-expanded")]
+ [DataRow("semi-condensed expanded ultra-expanded", "semi-expanded", "expanded")]
+ [DataRow("condensed semi-condensed", "expanded", "semi-condensed")]
+ public void FontFace_Stretch_FollowsTheFallbackOrder(string faceStretches, string desired, string expected)
+ {
+ var family = $"F4StretchOrder{faceStretches.Replace(" ", "").Replace("-", "")}x{desired.Replace("-", "")}";
+ var css = string.Concat(faceStretches.Split(' ').Select(s =>
+ $"@font-face {{ font-family: {family}; src: url({FontUri(StretchFaceFiles[s].File)}); font-stretch: {s} }}"));
+
+ var font = FontOf(css, $"x");
+
+ Assert.AreEqual(StretchFaceFiles[expected].Name, font.Name);
+ }
+
+ [TestMethod]
+ [Spec("css-fonts-4", "#unicode-range-desc")]
+ [DataRow("", "U+30-39", "!!", "22")]
+ [DataRow("U+0-39", "U+30-39", "!!", "22")]
+ [DataRow("U+21-39", "U+21-29", "22", "!!")]
+ public void FontFace_SameDescriptorsWithAnotherUnicodeRange_AreBothKept(string first, string second, string onlyFirst, string both)
+ {
+ var family = $"F4RangeKept{first.Replace("+", "").Replace("-", "")}x{second.Replace("+", "").Replace("-", "")}";
+ string Range(string range) => range.Length == 0 ? "" : $"; unicode-range: {range}";
+ var (root, _) = Layout(
+ $"@font-face {{ font-family: {family}; src: url({FontUri(Sans)}){Range(first)} }}" +
+ $"@font-face {{ font-family: {family}; src: url({FontUri(Mono)}){Range(second)} }}",
+ $"{onlyFirst}{both}");
+
+ Assert.AreEqual("Liberation Sans", Font(TextBox(root, "first")).Name);
+ Assert.AreEqual("Liberation Mono", Font(TextBox(root, "both")).Name);
+ }
+
[Ignore("Gap, see Spec/css-fonts-4.yml")]
[TestMethod]
[Spec("css-fonts-4", "#font-prop-desc")]
@@ -322,6 +384,30 @@ public void XxxLarge_IsLargerThanXxLarge()
Assert.IsGreaterThan(LayoutHarness.FindById(root, "xx")!.ActualFont.Size, LayoutHarness.FindById(root, "xxx")!.ActualFont.Size);
}
+ private static readonly Dictionary WeightFaces = new()
+ {
+ [100] = ("Caveat-Regular.ttf", "Caveat"),
+ [200] = ("DancingScript-Regular.ttf", "Dancing Script"),
+ [300] = ("IndieFlower-Regular.ttf", "Indie Flower"),
+ [400] = ("Pacifico-Regular.ttf", "Pacifico"),
+ [450] = ("LiberationMono-Regular.ttf", "Liberation Mono"),
+ [500] = ("LiberationSans-Regular.ttf", "Liberation Sans"),
+ [600] = ("LiberationSerif-Bold.ttf", "Liberation Serif"),
+ [700] = ("NotoSans-Bold.ttf", "Noto Sans"),
+ [800] = ("NotoSerif-Bold.ttf", "Noto Serif"),
+ [900] = ("ComicNeue-Bold.ttf", "Comic Neue"),
+ };
+
+ private static readonly Dictionary StretchFaceFiles = new()
+ {
+ ["ultra-condensed"] = ("Caveat-Regular.ttf", "Caveat"),
+ ["condensed"] = ("DancingScript-Regular.ttf", "Dancing Script"),
+ ["semi-condensed"] = ("IndieFlower-Regular.ttf", "Indie Flower"),
+ ["semi-expanded"] = ("LiberationMono-Regular.ttf", "Liberation Mono"),
+ ["expanded"] = ("LiberationSans-Regular.ttf", "Liberation Sans"),
+ ["ultra-expanded"] = ("LiberationSerif-Regular.ttf", "Liberation Serif"),
+ };
+
private static string StretchFaces(string family) =>
$"@font-face {{ font-family: {family}; src: url({FontUri(Sans)}); font-stretch: normal }}" +
$"@font-face {{ font-family: {family}; src: url({FontUri(Mono)}); font-stretch: condensed }}";
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Text/TextAlignIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Text/TextAlignIntegrationTests.cs
index bc5ea41d5..b5ea961f5 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Text/TextAlignIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Text/TextAlignIntegrationTests.cs
@@ -83,6 +83,89 @@ public void Justify_MakesAllButTheLastLineFlushWithBothSides()
Assert.IsTrue(lines[1].Max(w => w.Right) < 90, "the last line keeps its natural spacing");
}
+ [TestMethod]
+ [Spec("css21", "text.html#alignment-prop")]
+ [Spec("css21", "text.html#indentation-prop")]
+ [Spec("css-text-3", "#expanding-text")]
+ public void Justify_WithTextIndent_StartsTheFirstLineAtTheIndent()
+ {
+ var lines = Words(""
+ + "aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm nnn ooo ppp qqq rrr
")
+ .GroupBy(w => w.Top).OrderBy(g => g.Key).Select(g => g.OrderBy(w => w.Left).ToList()).ToList();
+
+ Assert.IsGreaterThan(2, lines.Count);
+ Assert.AreEqual(30, lines[0][0].Left, Delta);
+ Assert.AreEqual(0, lines[1][0].Left, Delta);
+
+ foreach (var line in lines.Take(lines.Count - 1))
+ {
+ Assert.AreEqual(200, line[^1].Right, Delta);
+ for (var i = 1; i < line.Count; i++)
+ Assert.IsGreaterThanOrEqualTo(line[i - 1].Right, line[i].Left);
+ }
+ }
+
+ [TestMethod]
+ [Spec("css21", "text.html#alignment-prop")]
+ [Spec("css-text-3", "#text-align-property")]
+ public void Center_InABlockWithEndPaddingAndBorder_CentersInTheContentBox()
+ {
+ var words = Words("aaa bbb
");
+
+ Assert.AreEqual(200 - words.Max(w => w.Right), words.Min(w => w.Left), Delta);
+ }
+
+ [TestMethod]
+ [Spec("css21", "text.html#alignment-prop")]
+ [Spec("css-text-3", "#text-align-property")]
+ public void Center_ImageWithEndPaddingAndBorder_CentersItsBorderBox()
+ {
+ var root = TestImages.Layout(
+ $"})
");
+ var image = TestImages.ImageRect(root, "i");
+
+ Assert.AreEqual(30, image.Width, Delta);
+ Assert.AreEqual(200 - image.Right, image.Left, Delta);
+ }
+
+ [TestMethod]
+ [Spec("css-text-3", "#text-align-property")]
+ [Spec("css-text-4", "#text-align-property")]
+ public void Center_WordWiderThanTheLine_IsStartAligned()
+ {
+ var (root, _) = LayoutHarness.Layout(
+ LayoutHarness.Wrap("aaaaaaaaaaaaaaaaaaaa
"));
+ var word = LayoutHarness.Descendants(root).SelectMany(b => b.Words).Single();
+
+ Assert.AreEqual(0, word.Left, Delta);
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "text.html#alignment-prop")]
+ [Spec("css-text-3", "#text-align-property")]
+ public void Right_InlineBoxEndPaddingAndBorder_StayInsideTheContentBox()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ "aaa bbb
"));
+
+ Assert.AreEqual(200, LayoutHarness.FindById(root, "s")!.Rectangles.Values.Single().Right, Delta);
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "text.html#alignment-prop")]
+ [Spec("css-text-3", "#text-align-property")]
+ public void Center_InlineBoxEndPaddingAndBorder_AreCenteredWithTheLine()
+ {
+ var (root, _) = LayoutHarness.Layout(LayoutHarness.Wrap(
+ "aaa bbb
"));
+
+ var left = LayoutHarness.FindById(root, "p")!.Boxes[0].Words[0].Left;
+ var right = LayoutHarness.FindById(root, "s")!.Rectangles.Values.Single().Right;
+ Assert.AreEqual(left, 200 - right, Delta);
+ }
+
[Ignore("Gap, see Spec/css21.yml")]
[TestMethod]
[Spec("css21", "text.html#alignment-prop")]
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Text/VerticalAlignIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Text/VerticalAlignIntegrationTests.cs
index d6cf7563c..160253fa2 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Text/VerticalAlignIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Text/VerticalAlignIntegrationTests.cs
@@ -25,6 +25,73 @@ private static double GetAlignedTop(string verticalAlign, string? lineHeight = n
return LayoutHarness.Descendants(v).SelectMany(b => b.Words).First().Top;
}
+ ///
+ /// How far the baseline of the generated text after #v sits below the baseline of "base". The
+ /// generated text is used because its words belong to the box with the 'vertical-align' itself.
+ ///
+ private static (double Shift, double ParentFontHeight) GeneratedTextBaselineShift(string afterStyle, string body)
+ {
+ var html = $""
+ + $"{body}
";
+ var (root, _) = LayoutHarness.Layout(html);
+ var words = LayoutHarness.Descendants(root).SelectMany(b => b.Words).ToList();
+ var parent = words.Single(w => w.Text == "base");
+ var generated = words.Single(w => w.Text == "gen");
+
+ var parentBaseline = parent.Top + parent.OwnerBox.ActualFont.UnderlineOffset;
+ var generatedBaseline = generated.Top + generated.OwnerBox.ActualFont.UnderlineOffset;
+ return (generatedBaseline - parentBaseline, parent.OwnerBox.ActualFont.Height);
+ }
+
+ [TestMethod]
+ [Spec("css21", "visudet.html#leading")]
+ [Spec("css-inline-3", "#transverse-alignment")]
+ public void Super_RaisesTheBaselineAboveTheParentsBaseline()
+ {
+ var (shift, parentFontHeight) = GeneratedTextBaselineShift("vertical-align:super", "base ");
+
+ Assert.IsLessThan(0, shift);
+ Assert.IsGreaterThan(-parentFontHeight, shift);
+ }
+
+ [TestMethod]
+ [Spec("css21", "visudet.html#leading")]
+ [Spec("css-inline-3", "#transverse-alignment")]
+ public void Sub_LowersTheBaselineBelowTheParentsBaseline_NextToTallerText()
+ {
+ var (shift, parentFontHeight) = GeneratedTextBaselineShift(
+ "vertical-align:sub", "base Q ");
+
+ Assert.IsGreaterThan(0, shift);
+ Assert.IsLessThan(parentFontHeight, shift);
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "visudet.html#leading")]
+ [Spec("css-inline-3", "#transverse-alignment")]
+ public void Sub_WithASmallerFont_LowersTheBaselineBelowTheParentsBaseline()
+ {
+ var (shift, _) = GeneratedTextBaselineShift("vertical-align:sub;font-size:10px", "base ");
+
+ Assert.IsGreaterThan(0, shift);
+ }
+
+ [Ignore("Gap, see Spec/css21.yml")]
+ [TestMethod]
+ [Spec("css21", "visudet.html#line-height")]
+ [Spec("css-inline-3", "#line-boxes")]
+ public void Super_MakesTheLineBoxTallerInsteadOfStickingOutOfIt()
+ {
+ var html = ""
+ + "base
";
+ var (root, _) = LayoutHarness.Layout(html);
+ var p = LayoutHarness.FindById(root, "p")!;
+ var generated = LayoutHarness.Descendants(root).SelectMany(b => b.Words).Single(w => w.Text == "gen");
+
+ Assert.IsGreaterThanOrEqualTo(p.LineBoxes[0].LineTop, generated.Top);
+ }
+
[Ignore("Gap, see Spec/css21.yml")]
[Spec("css21", "visudet.html#leading")]
[TestMethod]
diff --git a/Source/Test/HtmlRenderer.IntegrationTest/Text/WhiteSpaceLayoutIntegrationTests.cs b/Source/Test/HtmlRenderer.IntegrationTest/Text/WhiteSpaceLayoutIntegrationTests.cs
index 63d696f08..d1fa2e75c 100644
--- a/Source/Test/HtmlRenderer.IntegrationTest/Text/WhiteSpaceLayoutIntegrationTests.cs
+++ b/Source/Test/HtmlRenderer.IntegrationTest/Text/WhiteSpaceLayoutIntegrationTests.cs
@@ -135,6 +135,34 @@ public void PreWrap_PreservesSpacesAndWraps()
Assert.AreEqual(3, words.Where(w => !w.IsSpaces).Select(w => w.Top).Distinct().Count());
}
+ [TestMethod]
+ [Spec("css21", "text.html#white-space-prop")]
+ [Spec("css-text-3", "#white-space-property")]
+ public void NoWrap_InlineThatDoesntFitTheRestOfTheLine_MovesToTheNextLineAsAWhole()
+ {
+ var words = Words("aaa bbb ccc ddd
");
+ var aaa = words.Single(w => w.Text == "aaa");
+ var nowrap = words.Where(w => w.Text is "bbb" or "ccc" or "ddd").ToList();
+
+ Assert.AreEqual(1, nowrap.Select(w => w.Top).Distinct().Count());
+ Assert.IsGreaterThan(aaa.Top, nowrap[0].Top);
+ Assert.AreEqual(0, nowrap[0].Left, 0.5);
+ }
+
+ [TestMethod]
+ [Spec("css-text-3", "#white-space-phase-2")]
+ public void PreWrap_SpacesAtTheEndOfALine_HangInsteadOfWrapping()
+ {
+ var words = Words("aaa bbb ccc ddd
");
+ var ccc = words.Single(w => w.Text == "ccc");
+ var spaces = words.Single(w => w.Text == new string(' ', 20));
+ var ddd = words.Single(w => w.Text == "ddd");
+
+ Assert.AreEqual(ccc.Top, spaces.Top, 0.5);
+ Assert.IsGreaterThan(spaces.Top, ddd.Top);
+ Assert.AreEqual(0, ddd.Left, 0.5);
+ }
+
[TestMethod]
[Spec("css21", "text.html#white-space-prop")]
[Spec("css-text-3", "#white-space-property")]
diff --git a/Source/Test/HtmlRenderer.Test/Css/SyntaxAndDataTypesTests.cs b/Source/Test/HtmlRenderer.Test/Css/SyntaxAndDataTypesTests.cs
index aa09e36bd..d0eb6c583 100644
--- a/Source/Test/HtmlRenderer.Test/Css/SyntaxAndDataTypesTests.cs
+++ b/Source/Test/HtmlRenderer.Test/Css/SyntaxAndDataTypesTests.cs
@@ -518,6 +518,110 @@ public void DoubleQuotedRelativeUrl_ResolvesAgainstTheStyleSheet()
StringAssert.Contains(box.BackgroundImage, new Uri(new Uri(href), "yellow").AbsoluteUri);
}
+ [TestMethod]
+ [Spec("css-syntax-3", "#consume-url-token")]
+ [Spec("css-syntax-3", "#consume-escaped-code-point")]
+ [DataRow(@"url(yel\6C ow)")]
+ [DataRow("url(yel\\6C\tow)")]
+ [DataRow(@"url(yel\00006Cow)")]
+ [DataRow(@"url(ye\6C\6Cow)")]
+ [DataRow(@"url(yel\low)")]
+ [DataRow("url( yellow\t)")]
+ [DataRow("url(\"yel\\6C\r\now\")")]
+ [DataRow("url(\"yel\\6C\now\")")]
+ [DataRow("url('yel\\6C ow')")]
+ public void RelativeUrlWithEscapes_ResolvesTheUnescapedUrlAgainstTheStyleSheet(string value)
+ {
+ var (box, href) = StyledWithFile("style/basic.css", Encoding.UTF8.GetBytes($"#x {{ background-image: {value} }}"));
+
+ StringAssert.Contains(box.BackgroundImage, new Uri(new Uri(href), "yellow").AbsoluteUri);
+ }
+
+ [TestMethod]
+ [Spec("css-syntax-3", "#consume-string-token")]
+ [DataRow("url(\"yel\\\nlow\")")]
+ [DataRow("url('yel\\\r\nlow')")]
+ [DataRow("url('yel\\\flow')")]
+ [DataRow("url('yel\\\rlow')")]
+ public void QuotedUrlWithEscapedNewline_ContinuesTheString(string value)
+ {
+ var (box, href) = StyledWithFile("style/basic.css", Encoding.UTF8.GetBytes($"#x {{ background-image: {value} }}"));
+
+ StringAssert.Contains(box.BackgroundImage, new Uri(new Uri(href), "yellow").AbsoluteUri);
+ }
+
+ [TestMethod]
+ [Spec("css-syntax-3", "#consume-escaped-code-point")]
+ public void HexEscape_EndsAfterSixDigits()
+ {
+ var (box, href) = StyledWithFile("style/basic.css", Encoding.UTF8.GetBytes(@"#x { background-image: url(ye\00006C6ow) }"));
+
+ StringAssert.Contains(box.BackgroundImage, new Uri(new Uri(href), "yel6ow").AbsoluteUri);
+ }
+
+ [TestMethod]
+ [Spec("css-syntax-3", "#consume-escaped-code-point")]
+ [DataRow(@"url(a\0 b)")]
+ [DataRow(@"url(a\D800 b)")]
+ [DataRow(@"url(a\DFFF b)")]
+ [DataRow(@"url(a\110000 b)")]
+ public void HexEscapeOfNullSurrogateOrBeyondUnicode_IsTheReplacementCharacter(string value)
+ {
+ var (box, href) = StyledWithFile("style/basic.css", Encoding.UTF8.GetBytes($"#x {{ background-image: {value} }}"));
+
+ StringAssert.Contains(box.BackgroundImage, new Uri(new Uri(href), "a�b").AbsoluteUri);
+ }
+
+ [TestMethod]
+ [Spec("css-syntax-3", "#consume-escaped-code-point")]
+ public void HexEscapeOfTheLastCodePoint_IsKept()
+ {
+ var (box, href) = StyledWithFile("style/basic.css", Encoding.UTF8.GetBytes(@"#x { background-image: url(a\10FFFF b) }"));
+
+ StringAssert.Contains(box.BackgroundImage, new Uri(new Uri(href), "a" + char.ConvertFromUtf32(0x10FFFF) + "b").AbsoluteUri);
+ }
+
+ [TestMethod]
+ [Spec("css-syntax-3", "#consume-url-token")]
+ [Spec("css-syntax-3", "#consume-string-token")]
+ [DataRow("url(yel'low)")]
+ [DataRow("url(yel\"low)")]
+ [DataRow("url(yel(low)")]
+ [DataRow("url(yel low)")]
+ [DataRow("url(\"yel\nlow\")")]
+ [DataRow("url('yel\rlow')")]
+ [DataRow("url('yel\flow')")]
+ public void BadUrl_IsNotResolvedAgainstTheStyleSheet(string value)
+ {
+ var (box, href) = StyledWithFile("style/basic.css", Encoding.UTF8.GetBytes($"#x {{ background-image: {value} }}"));
+
+ Assert.IsFalse((box.BackgroundImage ?? string.Empty).Contains(new Uri(new Uri(href), ".").AbsoluteUri), box.BackgroundImage);
+ }
+
+ [TestMethod]
+ [Spec("css-values-4", "#url-empty")]
+ [DataRow("url()")]
+ [DataRow("url(\"\")")]
+ public void EmptyUrl_IsNotResolvedAgainstTheStyleSheet(string value)
+ {
+ var (box, href) = StyledWithFile("style/basic.css", Encoding.UTF8.GetBytes($"#x {{ background-image: {value} }}"));
+
+ Assert.IsFalse((box.BackgroundImage ?? string.Empty).Contains(new Uri(new Uri(href), ".").AbsoluteUri), box.BackgroundImage);
+ }
+
+ [TestMethod]
+ [Spec("css21", "syndata.html#uri")]
+ [Spec("css-values-4", "#relative-urls")]
+ [DataRow("")]
+ [DataRow(@" #w { background-image: url(a\41")]
+ public void EveryRelativeUrlInTheStyleSheet_IsResolved(string end)
+ {
+ var css = "#y { background-image: url(first.png) } #z { background: url(bad'url) } #x { background-image: url(yellow) }" + end;
+ var (box, href) = StyledWithFile("style/basic.css", Encoding.UTF8.GetBytes(css));
+
+ StringAssert.Contains(box.BackgroundImage, new Uri(new Uri(href), "yellow").AbsoluteUri);
+ }
+
[TestMethod]
[Spec("css21", "syndata.html#counter")]
[DataRow("counter(c)", "3")]
diff --git a/Source/Test/HtmlRenderer.Test/CssModules/CssColor5Tests.cs b/Source/Test/HtmlRenderer.Test/CssModules/CssColor5Tests.cs
index 00ff0608d..f6c287286 100644
--- a/Source/Test/HtmlRenderer.Test/CssModules/CssColor5Tests.cs
+++ b/Source/Test/HtmlRenderer.Test/CssModules/CssColor5Tests.cs
@@ -74,6 +74,16 @@ public void InvalidColorMix_IsIgnored(string value)
Assert.AreEqual(Green, Color($"green;color:{value}"));
}
+ [TestMethod]
+ [Ignore("Gap, see Spec/css-color-4.yml")]
+ [Spec("css-color-4", "#hex-notation")]
+ [DataRow("color-mix(in srgb, #abg, blue)")]
+ [DataRow("color-mix(in srgb, #12345, blue)")]
+ public void ColorMix_WithAnInvalidHexColor_IsIgnored(string value)
+ {
+ Assert.AreEqual(Green, Color($"green;color:{value}"));
+ }
+
[TestMethod]
[Spec("css-color-5", "#color-mix-percent-norm")]
[Spec("css-color-5", "#color-mix-result")]
diff --git a/Source/Test/HtmlRenderer.Test/CssModules/CssColorTests.cs b/Source/Test/HtmlRenderer.Test/CssModules/CssColorTests.cs
index 65755e560..abca8d9ab 100644
--- a/Source/Test/HtmlRenderer.Test/CssModules/CssColorTests.cs
+++ b/Source/Test/HtmlRenderer.Test/CssModules/CssColorTests.cs
@@ -201,6 +201,16 @@ public void HexAlpha_KeepsItsPrecision(string value)
Assert.AreEqual(0x88, Color(value).A);
}
+ [TestMethod]
+ [Ignore("Gap, see Spec/css-color-4.yml")]
+ [Spec("css-color-4", "#rgb-functions")]
+ [DataRow("rgb(50%, 50%, 50%)")]
+ [DataRow("rgb(50% 50% 50%)")]
+ public void RgbPercentage_RoundsTowardsPositiveInfinity(string value)
+ {
+ Assert.AreEqual(RColor.FromArgb(255, 128, 128, 128), Color(value));
+ }
+
[TestMethod]
[Spec("css-color-4", "#named-colors")]
[Spec("css-color-4", "#untagged")]
diff --git a/Source/Test/HtmlRenderer.Test/Html/CommonMicrosyntaxesTests.cs b/Source/Test/HtmlRenderer.Test/Html/CommonMicrosyntaxesTests.cs
index 03236a5a0..3cadeeebc 100644
--- a/Source/Test/HtmlRenderer.Test/Html/CommonMicrosyntaxesTests.cs
+++ b/Source/Test/HtmlRenderer.Test/Html/CommonMicrosyntaxesTests.cs
@@ -140,6 +140,7 @@ public void LegacyColor_IsParsed(string bgcolor, int r, int g, int b)
[DataRow("#ff000080", 255, 0, 128)]
[DataRow("chucknorris", 192, 0, 0)]
[DataRow("rgb(255,0,0)", 0, 37, 0)]
+ [DataRow("#abg", 0x0a, 0x0b, 0)]
public void LegacyColor_ParsesAnyStringAsHexDigits(string bgcolor, int r, int g, int b)
{
AssertColor(r, g, b, Box($"a
").ActualBackgroundColor);
diff --git a/Source/Test/HtmlRenderer.Test/Html/TableRenderingTests.cs b/Source/Test/HtmlRenderer.Test/Html/TableRenderingTests.cs
index c0aedaaf9..a292d9734 100644
--- a/Source/Test/HtmlRenderer.Test/Html/TableRenderingTests.cs
+++ b/Source/Test/HtmlRenderer.Test/Html/TableRenderingTests.cs
@@ -238,6 +238,35 @@ public void TableAlignLeftAndRight_FloatTheTable()
Assert.AreEqual("right", Box("").Float);
}
+ [TestMethod]
+ [Spec("html", "rendering.html#tables-2")]
+ public void TableAlignCenter_CentersAnAutoWidthTable()
+ {
+ var box = Box("");
+ var width = box.ActualRight - box.Location.X;
+
+ Assert.IsLessThan(100, width);
+ Assert.AreEqual((400 - width) / 2, box.Location.X, 0.5);
+ }
+
+ [TestMethod]
+ [Spec("html", "rendering.html#tables-2")]
+ public void TableAlignRight_PutsAnAutoWidthTableAtTheRightEdge()
+ {
+ var box = Box("");
+
+ Assert.IsLessThan(100, box.ActualRight - box.Location.X);
+ Assert.AreEqual(400, box.ActualRight, 0.5);
+ }
+
+ [TestMethod]
+ [Ignore("Gap, see Spec/html.yml")]
+ [Spec("html", "rendering.html#tables-2")]
+ public void TableAlignRight_WithBorderSpacing_PutsTheTableAtTheRightEdge()
+ {
+ Assert.AreEqual(400, Box("").ActualRight, 0.5);
+ }
+
[TestMethod]
[Ignore("Gap, see Spec/html.yml")]
[Spec("html", "rendering.html#tables-2")]
diff --git a/Source/Test/HtmlRenderer.Test/Parse/CssParserFontFamilyTests.cs b/Source/Test/HtmlRenderer.Test/Parse/CssParserFontFamilyTests.cs
new file mode 100644
index 000000000..6a1f23450
--- /dev/null
+++ b/Source/Test/HtmlRenderer.Test/Parse/CssParserFontFamilyTests.cs
@@ -0,0 +1,47 @@
+using HtmlRenderer.Test.TestSupport;
+using TheArtOfDev.HtmlRenderer.Core.Parse;
+using TheArtOfDev.HtmlRenderer.Core.Utils;
+
+namespace HtmlRenderer.Test.Parse;
+
+[TestClass]
+public sealed class CssParserFontFamilyTests
+{
+ private static string ParseFontFamily(string value)
+ {
+ var adapter = new MockAdapter();
+ adapter.AddFontFamily(new MockFontFamily("Foo Bar"));
+ adapter.AddFontFamily(new MockFontFamily("Baz"));
+ adapter.AddFontFamily(new MockFontFamily("X"));
+ return new CssParser(adapter).ParseFontFamily(value);
+ }
+
+ [TestMethod]
+ [Spec("css21", "fonts.html#font-family-prop")]
+ [DataRow("Baz", "Baz")]
+ [DataRow(" Baz ", "Baz")]
+ [DataRow("Missing, Baz", "Baz")]
+ [DataRow("Missing , Baz", "Baz")]
+ [DataRow("Missing,Baz", "Baz")]
+ [DataRow("'Missing', \"Foo Bar\"", "Foo Bar")]
+ [DataRow("\"Foo Bar\" , Baz", "Foo Bar")]
+ [DataRow("'Foo Bar'\t,Baz", "Foo Bar")]
+ [DataRow("Missing, X", "X")]
+ [DataRow("Foo Bar, Baz", "Foo Bar")]
+ public void FirstAvailableFamily_IsUsed(string value, string expected)
+ {
+ Assert.AreEqual(expected, ParseFontFamily(value));
+ }
+
+ [TestMethod]
+ [Spec("css21", "fonts.html#font-family-prop")]
+ [DataRow("Missing")]
+ [DataRow("Missing,")]
+ [DataRow("Missing, ")]
+ [DataRow("'Missing'")]
+ [DataRow("Ba")]
+ public void NoAvailableFamily_FallsBackToTheDefaultFont(string value)
+ {
+ Assert.AreEqual(CssConstants.DefaultFont, ParseFontFamily(value));
+ }
+}
diff --git a/Source/Test/HtmlRenderer.Test/Parse/CssValueParserColorTests.cs b/Source/Test/HtmlRenderer.Test/Parse/CssValueParserColorTests.cs
new file mode 100644
index 000000000..ed9770f50
--- /dev/null
+++ b/Source/Test/HtmlRenderer.Test/Parse/CssValueParserColorTests.cs
@@ -0,0 +1,146 @@
+using HtmlRenderer.Test.TestSupport;
+using TheArtOfDev.HtmlRenderer.Adapters.Entities;
+using TheArtOfDev.HtmlRenderer.Core.Parse;
+
+namespace HtmlRenderer.Test.Parse;
+
+///
+/// on raw values. The cascade hands it serialized colors, HTML attributes
+/// such as <font color> and bgcolor hand it what the author wrote, which HTML parses with its legacy
+/// color rules instead, see .
+///
+[TestClass]
+public sealed class CssValueParserColorTests
+{
+ private static readonly CssValueParser Parser = new(new MockAdapter());
+
+ private static (bool Valid, RColor Color) Parse(string value)
+ {
+ var valid = Parser.TryGetColor(value, 0, value.Length, out var color);
+ return (valid, color);
+ }
+
+ private static void AssertColor(string value, int a, int r, int g, int b)
+ {
+ var (valid, color) = Parse(value);
+ Assert.IsTrue(valid, value);
+ Assert.AreEqual(RColor.FromArgb(a, r, g, b), color, value);
+ }
+
+ [TestMethod]
+ [Spec("css-color-4", "#hex-notation")]
+ [DataRow("#abc", 0xaa, 0xbb, 0xcc)]
+ [DataRow("#A1f", 0xaa, 0x11, 0xff)]
+ [DataRow("#9F9F9F", 0x9f, 0x9f, 0x9f)]
+ [DataRow("#A9A9A9", 0xa9, 0xa9, 0xa9)]
+ [DataRow("#9A9A9A", 0x9a, 0x9a, 0x9a)]
+ [DataRow("#9a9a9a", 0x9a, 0x9a, 0x9a)]
+ [DataRow("#102030", 0x10, 0x20, 0x30)]
+ public void Hex_ThreeAndSixDigits_AreOpaqueRgb(string value, int r, int g, int b)
+ {
+ AssertColor(value, 255, r, g, b);
+ }
+
+ [TestMethod]
+ [Spec("css-color-4", "#hex-notation")]
+ public void Hex_FourDigits_LastDigitIsAlpha()
+ {
+ AssertColor("#abcd", 0xdd, 0xaa, 0xbb, 0xcc);
+ }
+
+ [TestMethod]
+ [Spec("css-color-4", "#hex-notation")]
+ [DataRow("#")]
+ [DataRow("#1")]
+ [DataRow("#12345")]
+ [DataRow("#ab:")]
+ [DataRow("#ab@")]
+ [DataRow("#ab`")]
+ public void Hex_WrongLengthOrDigit_IsInvalid(string value)
+ {
+ Assert.IsFalse(Parse(value).Valid);
+ }
+
+ [TestMethod]
+ [Spec("css-color-4", "#rgb-functions")]
+ [DataRow("rgb(1,2,3)", 1, 2, 3)]
+ [DataRow("rgb(10, 20, 30)", 10, 20, 30)]
+ [DataRow("rgb( 255 , 128 , 0 )", 255, 128, 0)]
+ [DataRow("rgb(100%, 0%, 0%)", 255, 0, 0)]
+ public void Rgb_LegacySyntax_IsOpaque(string value, int r, int g, int b)
+ {
+ AssertColor(value, 255, r, g, b);
+ }
+
+ [TestMethod]
+ [Spec("css-color-4", "#rgb-functions")]
+ [Spec("css-color-4", "#alpha-syntax")]
+ [DataRow("rgba(10,20,30,0.5)", 128)]
+ [DataRow("rgba(10, 20, 30, .25)", 64)]
+ [DataRow("rgba(10, 20, 30, 0.2)", 51)]
+ [DataRow("rgba(10,20,30,50%)", 128)]
+ [DataRow("rgba(10, 20, 30, 25%)", 64)]
+ [DataRow("rgba(10,20,30,0)", 0)]
+ [DataRow("rgba(10,20,30,1)", 255)]
+ [DataRow("rgba(10,20,30,2)", 255)]
+ [DataRow("rgba(10,20,30,150%)", 255)]
+ public void Rgba_Alpha_IsANumberOrPercentageClampedToOne(string value, int a)
+ {
+ AssertColor(value, a, 10, 20, 30);
+ }
+
+ [TestMethod]
+ [Spec("css-color-4", "#rgb-functions")]
+ [DataRow("rgb(1,2)")]
+ [DataRow("rgb(a,b,c)")]
+ [DataRow("rgb(1234567)")]
+ public void Rgb_MissingOrNonNumericComponent_IsInvalid(string value)
+ {
+ Assert.IsFalse(Parse(value).Valid);
+ }
+
+ [TestMethod]
+ [Spec("css-color-4", "#hsl-to-rgb")]
+ [Spec("css-color-4", "#hue-syntax")]
+ [DataRow("hsl(0,100%,50%)", 255, 255, 0, 0)]
+ [DataRow("hsl(120, 100%, 25%)", 255, 0, 128, 0)]
+ [DataRow("hsl(-120,100%,50%)", 255, 0, 0, 255)]
+ [DataRow("hsl(180deg,100%,50%)", 255, 0, 255, 255)]
+ [DataRow("hsl(0.5turn,100%,50%)", 255, 0, 255, 255)]
+ [DataRow("hsl(200grad,100%,50%)", 255, 0, 255, 255)]
+ [DataRow("hsl(3.14159265rad,100%,50%)", 255, 0, 255, 255)]
+ [DataRow("hsla(240, 100%, 50%, 0.4)", 102, 0, 0, 255)]
+ [DataRow("hsla(0,100%,50%,50%)", 128, 255, 0, 0)]
+ public void Hsl_LegacySyntax_ConvertsToSrgb(string value, int a, int r, int g, int b)
+ {
+ AssertColor(value, a, r, g, b);
+ }
+
+ [TestMethod]
+ [Spec("css-color-4", "#named-colors")]
+ [DataRow("red", 255, 255, 0, 0)]
+ [DataRow("transparent", 0, 0, 0, 0)]
+ public void Keyword_IsValid(string value, int a, int r, int g, int b)
+ {
+ AssertColor(value, a, r, g, b);
+ }
+
+ [TestMethod]
+ [DataRow("")]
+ [DataRow("foo")]
+ [DataRow("light-dark(red)")]
+ public void UnknownOrEmpty_IsInvalid(string value)
+ {
+ Assert.IsFalse(Parse(value).Valid);
+ }
+
+ [TestMethod]
+ [Spec("css-color-5", "#light-dark")]
+ [DataRow("light-dark(red, blue)", 255, 0, 0)]
+ [DataRow("light-dark(#00f, red)", 0, 0, 255)]
+ [DataRow("light-dark(rgb(0, 128, 0), red)", 0, 128, 0)]
+ public void LightDark_ResolvesToTheLightColor(string value, int r, int g, int b)
+ {
+ AssertColor(value, 255, r, g, b);
+ }
+}
diff --git a/Spec/css-backgrounds-3.yml b/Spec/css-backgrounds-3.yml
index 6be862248..bd7451523 100644
--- a/Spec/css-backgrounds-3.yml
+++ b/Spec/css-backgrounds-3.yml
@@ -30,6 +30,7 @@ sections:
gaps:
- The two-value syntax isn't resolved, 'repeat no-repeat' tiles in both directions
- "'space' and 'round' are painted as 'repeat'"
+ - Repeating an image with a zero width or height never ends
'#background-attachment':
title: '2.5 Affixing Images: the background-attachment property'
status: partial
@@ -118,6 +119,7 @@ sections:
status: partial
gaps:
- A rounded border is stroked along the outer radius moved in by half the border width, so it doesn't follow the outer and inner border curves
+ - The curve at the top of the right border ends at the left border's width instead of the right one's
'#corner-clipping':
title: 4.3 Corner Clipping
status: partial
diff --git a/Spec/css-break-3.yml b/Spec/css-break-3.yml
index 112b7fec2..4c12789cb 100644
--- a/Spec/css-break-3.yml
+++ b/Spec/css-break-3.yml
@@ -65,11 +65,13 @@ sections:
gaps:
- A forced break right after a zero-height box that a forced break moved to a page top makes no new page
- "A different 'page' value doesn't force a break"
+ - A box after a forced break whose top margin crosses the page boundary skips a page, see CSS 2.1 13.3.4
'#unforced-breaks':
title: 4.4 Unforced Breaks
status: partial
gaps:
- "'break-after: avoid' doesn't pull a block without text along to the next page, see CSS 2.1 13.3.3"
+ - "An 'orphans' value larger than the lines a page holds isn't dropped, see CSS 2.1 13.3.3"
'#best-breaks':
title: 4.5 Optimizing Unforced Breaks
status: supported
@@ -88,6 +90,7 @@ sections:
- "At a forced break the previous box's 'margin-bottom' isn't truncated, see CSS 2.1 13.3.3"
- The top margin of an hr isn't truncated at an unforced break, see CSS 2.1 13.3.3
- A forced break before the first box of the flow isn't taken, and the margin after it is truncated anyway
+ - A margin after a forced break that by itself reaches the top of the next page is truncated
'#box-splitting':
title: 5.3 Splitting Boxes
status: supported
diff --git a/Spec/css-color-4.yml b/Spec/css-color-4.yml
index c672a25c0..ec495ccff 100644
--- a/Spec/css-color-4.yml
+++ b/Spec/css-color-4.yml
@@ -78,11 +78,13 @@ sections:
gaps:
- Out-of-range values aren't clipped, see CSS 2.1 4.3.6
- rgb() ignores the alpha, see 4.1.2 and 4.2
+ - Percentages are truncated instead of rounded towards +infinity, rgb(50% 50% 50%) is rgb(127 127 127)
'#hex-notation':
title: '5.2 The RGB Hexadecimal Notations: #RRGGBB'
status: partial
gaps:
- "The alpha of 4 and 8 digit hex colors is rounded to two decimals, #f008 gets an alpha of 135 instead of 136"
+ - "A hex color inside a function, e.g. a color-mix() operand, isn't validated, #abg and #12345 are colors"
'#color-keywords':
title: 6 Color Keywords
status: partial
diff --git a/Spec/css-images-3.yml b/Spec/css-images-3.yml
index 37d95d30d..fd7e0d40b 100644
--- a/Spec/css-images-3.yml
+++ b/Spec/css-images-3.yml
@@ -56,6 +56,7 @@ sections:
status: partial
gaps:
- repeating-radial-gradient() isn't painted, see 3.2
+ - A repeating gradient whose first and last color stops share a position repeats a hard edge instead of painting the average color
'#gradient-colors':
title: 3.4 Defining Gradient Color
status: partial
@@ -64,6 +65,7 @@ sections:
status: partial
gaps:
- em positions are resolved against 16px instead of the element's font size
+ - A transition hint before the first or after the last color stop is ignored instead of making the gradient invalid
'#coloring-gradient-line':
title: 3.4.2 Coloring the Gradient Line
status: partial
diff --git a/Spec/css-images-4.yml b/Spec/css-images-4.yml
index eb8516177..e0666f272 100644
--- a/Spec/css-images-4.yml
+++ b/Spec/css-images-4.yml
@@ -131,6 +131,7 @@ sections:
gaps:
- A gradient with a single color stop is accepted but not painted
- "em positions are resolved against 16px, see css-images-3 #color-stop-syntax"
+ - "A transition hint outside the color stops is ignored, see css-images-3 #color-stop-syntax"
'#coloring-gradient-line':
title: 3.5.2 Coloring the Gradient Line
status: partial
diff --git a/Spec/css-inline-3.yml b/Spec/css-inline-3.yml
index 57573eaa1..6a7976740 100644
--- a/Spec/css-inline-3.yml
+++ b/Spec/css-inline-3.yml
@@ -15,6 +15,7 @@ sections:
gaps:
- The start padding, border and margin of an inline box are repeated on every line it's split onto, see CSS 2.1 9.4.2
- A word wider than the line box starts a new line, leaving an empty line above it, see CSS 2.1 9.4.2
+ - Text raised by vertical-align super sticks out above the line box instead of making it taller, see CSS 2.1 10.8
'#line-layout':
title: 2.2 Layout Within Line Boxes
status: partial
@@ -63,7 +64,7 @@ sections:
gaps:
- first, last and the alignment-baseline keywords such as central aren't accepted
- top, bottom, middle, text-top, text-bottom, lengths and percentages align like baseline, see CSS 2.1 10.8.1
- - sub and super both move the text to the top of the line, see CSS 2.1 10.8.1
+ - sub and super only move text directly inside the box, e.g. generated content, and sub can end up above the parent's baseline, see CSS 2.1 10.8.1
'#baseline-source':
title: '4.2.1 Alignment Baseline Source: the baseline-source longhand'
status: unsupported
diff --git a/Spec/css-sizing-3.yml b/Spec/css-sizing-3.yml
index 722679842..21f41dcbe 100644
--- a/Spec/css-sizing-3.yml
+++ b/Spec/css-sizing-3.yml
@@ -32,7 +32,7 @@ sections:
title: '3.1.3 Maximum Size Properties: the max-width, max-height, max-inline-size, and max-block-size properties'
status: partial
gaps:
- - "'max-width' only applies to images and 'max-height' doesn't apply to them, see CSS 2.1 10.4 and 10.7"
+ - "'max-width' only applies to images and tables, 'max-height' doesn't apply to images, see CSS 2.1 10.4 and 10.7"
- "'max-inline-size' and 'max-block-size' are ignored"
'#sizing-values':
title: '3.2 Sizing Values: the , auto | none, stretch, min-content, max-content, and fit-content values'
diff --git a/Spec/css-tables-3.yml b/Spec/css-tables-3.yml
index b7eadafb5..6af2255db 100644
--- a/Spec/css-tables-3.yml
+++ b/Spec/css-tables-3.yml
@@ -27,6 +27,7 @@ sections:
status: partial
gaps:
- Consecutive non-row children don't share one anonymous row, misparented boxes get no anonymous table, see CSS 2.1 17.2.1
+ - The cells that follow a non-cell child of a row are moved into its anonymous cell, see CSS 2.1 17.2.1
'#fixup-boxes':
title: 2.2.2 Characteristics of fixup boxes
status: supported
@@ -135,6 +136,7 @@ sections:
gaps:
- A spanning cell's width is split evenly over its columns instead of in proportion to their widths
- A column group's 'width' doesn't widen its columns, see CSS 2.1 17.5.2.2
+ - A spanning cell can leave a column it doesn't span, or itself, narrower than the content, see CSS 2.1 17.5.2.2
'#width-distribution':
title: 3.9 Available Width Distribution
status: partial
@@ -144,6 +146,8 @@ sections:
gaps:
- "'min-width' on the table is ignored"
- The caption's minimum width doesn't widen the table, see CSS 2.1 17.5.2.2
+ - "A 'max-width' below the minimum content width narrows the columns below it, clipping their content"
+ - Percentage cell widths adding up to more than 100% make an auto width table wider than its containing block
'#width-distribution-principles':
title: 3.9.2 Core distribution principles
status: n/a
diff --git a/Spec/css-text-3.yml b/Spec/css-text-3.yml
index d8b456af0..79e97d448 100644
--- a/Spec/css-text-3.yml
+++ b/Spec/css-text-3.yml
@@ -93,6 +93,7 @@ sections:
- match-parent is ignored
- "justify-all doesn't justify the last line, see #text-align-last-property"
- The initial value acts as left also when direction is rtl, see CSS 2.1 16.2
+ - right and center leave out the end padding and border of an inline box at the end of the line, see CSS 2.1 16.2
'#text-align-all-property':
title: '6.2 Default Text Alignment: the text-align-all property'
status: unsupported
diff --git a/Spec/css21.yml b/Spec/css21.yml
index 573a22f2e..feb2d1201 100644
--- a/Spec/css21.yml
+++ b/Spec/css21.yml
@@ -362,6 +362,7 @@ sections:
status: partial
gaps:
- The first display:none child of an inline-block is moved out of it, next to the anonymous block box around the inline-block
+ - A block in an inline nested in another inline ends up after the content that follows it when an inline holds only the block, or when another block follows later
visuren.html#inline-boxes:
title: 9.2.2 Inline-level elements and inline boxes
status: partial
@@ -402,6 +403,7 @@ sections:
gaps:
- The start padding, border and margin of an inline box are repeated at the start of every line it's split onto
- A word wider than the line box starts a new line, leaving an empty line above it
+ - An inline box whose content only starts on the next line after a wrap gets a border box that begins at the start of that line instead of after its start margin
visuren.html#relative-positioning:
title: 9.4.3 Relative positioning
status: partial
@@ -420,7 +422,9 @@ sections:
status: partial
gaps:
- Successive right floats overlap instead of stacking side by side
- - A float that doesn't fit next to the previous ones moves below the lowest of them instead of as high as possible
+ - A right float overlaps earlier left floats instead of moving below the ones it doesn't fit next to
+ - A left float overlaps the left margin of an earlier right float instead of moving below it, unless that margin reaches the left float's left edge
+ - A left float that doesn't fit next to earlier left floats moves below the lowest of them instead of as high as possible
- A right float in a block narrower than its block formatting context is placed against an earlier right float outside that block, past its containing block's right edge
visuren.html#flow-control:
title: 9.5.2 Controlling flow next to floats
@@ -490,6 +494,7 @@ sections:
status: partial
gaps:
- Widths in units other than px and % are ignored, the image keeps its intrinsic width
+ - A zero 'width' is ignored, the image keeps its intrinsic width
visudet.html#blockwidth:
title: 10.3.3 Block-level, non-replaced elements in normal flow
status: partial
@@ -503,7 +508,9 @@ sections:
- Auto margins compute to 0, a block image is never centered by them
visudet.html#float-width:
title: 10.3.5 Floating, non-replaced elements
- status: supported
+ status: partial
+ gaps:
+ - The shrink-to-fit width of a float around a table with row groups leaves out the border spacing between the columns
visudet.html#float-replaced-width:
title: 10.3.6 Floating, replaced elements
status: supported
@@ -530,7 +537,9 @@ sections:
status: partial
gaps:
- "'min-width' is ignored"
- - "'max-width' only applies to images, it's ignored on non-replaced boxes"
+ - "'max-width' only applies to images and tables, it's ignored on other non-replaced boxes"
+ - "On an image with a 'height', 'max-width' is ignored, the width follows the intrinsic ratio"
+ - "A zero 'max-width' is ignored on an image"
visudet.html#the-height-property:
title: 10.5 Content height
status: partial
@@ -546,6 +555,7 @@ sections:
status: partial
gaps:
- Vertical padding and border of an inline box can push the line's content down and make the line box taller
+ - The border box of an inline box extends below its content by the top padding instead of the bottom padding
visudet.html#inline-replaced-height:
title: 10.6.2 Inline replaced elements, block-level replaced elements in normal flow, 'inline-block' replaced elements in normal flow and floating replaced elements
status: partial
@@ -587,6 +597,7 @@ sections:
- Images are aligned with the top of the line instead of sitting on the baseline
- Vertical margins of an inline-block don't make the line box taller
- "'line-height' on an inline box is ignored, only the block's own 'line-height' sizes the line"
+ - "Text raised by 'vertical-align: super' sticks out above the line box instead of making it taller"
visudet.html#leading:
title: 10.8.1 Leading and half-leading
status: partial
@@ -597,7 +608,8 @@ sections:
- "A percentage line-height computes to 0 instead of a percentage of the font size, so the line gets the height of 'normal'"
- A number is inherited as the parent's computed length instead of the number
- "'vertical-align' top, bottom, middle, text-top, text-bottom, lengths and percentages are treated as 'baseline'"
- - "'vertical-align: sub' and 'super' both move the text to the top of the line"
+ - "'vertical-align: sub' and 'super' only move text directly inside the box, e.g. generated content, the text of an element like stays at the top of the line"
+ - "'vertical-align: sub' lowers the text by half its height from the top of the lowest box on the line, so a subscript in a smaller font ends up above the parent's baseline"
visufx.html#q11.0:
title: 11 Visual effects
status: partial
@@ -726,12 +738,14 @@ sections:
- "'page-break-after: avoid' isn't honored when the next box's first child moves to the next page through margin truncation"
- "At a forced break the previous box's 'margin-bottom' isn't set to 0, it collapses with 'margin-top' at the top of the new page"
- The top margin of an hr isn't set to 0 at an unforced page break
+ - "An 'orphans' value larger than the lines a page holds isn't dropped, the paragraph's lines run past the page bottom and the lines after the next break overlap them"
page.html#forced:
title: 13.3.4 Forced page breaks
status: partial
gaps:
- A forced break before a first child is dropped instead of breaking before its ancestors, which meet at the same margin
- "A forced 'page-break-after' on a last child doesn't break before its parent's next sibling"
+ - A box after a forced break whose top margin crosses the page boundary skips a page, it lands on the page after the next
page.html#best-page-breaks:
title: 13.3.5 "Best" page breaks
status: supported
@@ -842,6 +856,7 @@ sections:
gaps:
- "The initial value acts as 'left' also when 'direction' is 'rtl'"
- "'justify' stretches preserved white space in 'pre' and 'pre-wrap' text"
+ - "'right' and 'center' leave out the end padding and border of an inline box at the end of the line, so they stick out past the content edge"
text.html#decoration:
title: 16.3 Decoration
status: partial
@@ -903,6 +918,7 @@ sections:
- Consecutive children of a table or row group that aren't rows each get their own anonymous row instead of sharing one
- Misparented rows, row groups, columns and captions don't get an anonymous table
- Anonymous wrappers are appended as the parent's last child instead of taking the place of the boxes they wrap
+ - The cells that follow a non-cell child of a row are moved into its anonymous cell
tables.html#columns:
title: 17.3 Columns
status: partial
@@ -943,6 +959,8 @@ sections:
gaps:
- A column group's 'width' doesn't widen its columns
- The caption's minimum width doesn't widen the table
+ - A spanning cell that isn't the first in its row narrows the column before it below its content width
+ - A spanning cell over a column that is already wider than the others can end up narrower than its content
tables.html#height-layout:
title: 17.5.3 Table height algorithms
status: partial
diff --git a/Spec/html.yml b/Spec/html.yml
index 9a1a206a1..8fc571108 100644
--- a/Spec/html.yml
+++ b/Spec/html.yml
@@ -2111,7 +2111,7 @@ sections:
- border gives the table and its cells solid instead of outset and inset borders, border without a value draws none
- rules and frame are ignored
- align=middle and align=absmiddle on rows and cells set vertical-align instead of centering the text
- - table align=left and right set text-align instead of floating, align=center doesn't center a table with a width
+ - table align=left and right set text-align instead of floating, align=right leaves the table short of the right edge by its border spacing, align=center doesn't center a table with a width
- hidden on rows, row groups and columns doesn't collapse them
- A form that's a child of table, thead, tbody, tfoot or tr is displayed
rendering.html#margin-collapsing-quirks:
@@ -2130,9 +2130,12 @@ sections:
title: 15.3.11 The hr element
status: partial
gaps:
- - hr isn't centered, has no vertical margins and isn't gray
+ - hr isn't centered and isn't gray, its margins are 1.1em at the top and 0 at the bottom instead of 0.5em
- align sets text-align instead of the margins
- size sets the height including the borders, noshade is ignored and color doesn't make the border solid
+ - A zero top margin is replaced with 1.1em
+ - Without top and bottom borders and with a height of at most 2px, hr gets 1px solid top and bottom borders
+ - The width leaves out the side borders, an auto width hr is 2px narrower than its containing block and a percentage is resolved against the containing block minus those borders
rendering.html#the-fieldset-and-legend-elements:
title: 15.3.12 The fieldset and legend elements
status: partial
@@ -2154,6 +2157,7 @@ sections:
status: partial
gaps:
- An unavailable image is drawn as an error icon instead of its alt text
+ - An unavailable image with a width and height gets a 2px border around that size and starts 2px left of the line
rendering.html#attributes-for-embedded-content-and-images:
title: 15.4.3 Attributes for embedded content and images
status: partial