|
| 1 | +using System.Linq; |
| 2 | +using HtmlRenderer.IntegrationTest.TestSupport; |
| 3 | +using TheArtOfDev.HtmlRenderer.Adapters.Entities; |
| 4 | + |
| 5 | +namespace HtmlRenderer.IntegrationTest.Painting; |
| 6 | + |
| 7 | +/// <summary> |
| 8 | +/// Ported from PeachPDF.Tests' OutlineStylePaintIntegrationTests.cs, adapted to this fork's new (and more |
| 9 | +/// limited) <c>OutlineDrawHandler</c> - see that class's remarks for exactly what's implemented: a plain |
| 10 | +/// rectangular ring for <c>solid</c>/<c>auto</c> only, no <c>outline-offset</c> (this fork's CSS-OM has no |
| 11 | +/// such property to read a value from), and every other style (<c>dotted</c>/<c>dashed</c>/<c>double</c>/ |
| 12 | +/// <c>groove</c>/<c>ridge</c>/<c>inset</c>/<c>outset</c>) paints nothing, same as <c>none</c>. |
| 13 | +/// </summary> |
| 14 | +[DoNotParallelize] |
| 15 | +[TestClass] |
| 16 | +public sealed class OutlineStylePaintIntegrationTests |
| 17 | +{ |
| 18 | + [TestMethod] |
| 19 | + public void SolidOutline_PaintsAFourSidedRingAroundTheBorderBox() |
| 20 | + { |
| 21 | + var (root, container) = PaintHarness.Layout(PaintHarness.Wrap( |
| 22 | + "<div id='b' style='width:100px;height:50px;outline:5px solid rgb(51,51,51)'>x</div>")); |
| 23 | + var div = PaintHarness.FindById(root, "b")!; |
| 24 | + |
| 25 | + var g = PaintHarness.PaintBox(container, div); |
| 26 | + var rects = g.Log.OfType<RecordingGraphics.DrawRectCall>() |
| 27 | + .Where(r => r.Color == RColor.FromArgb(51, 51, 51)).ToList(); |
| 28 | + |
| 29 | + Assert.AreEqual(4, rects.Count, "expected one filled rect per side of the outline ring"); |
| 30 | + |
| 31 | + // Two of the four bands are 5px tall (top/bottom, spanning the full outer width including |
| 32 | + // corners) and two are 5px wide (left/right, spanning just the box's own height) - regardless of |
| 33 | + // which order OutlineDrawHandler emits them in. |
| 34 | + Assert.AreEqual(2, rects.Count(r => System.Math.Abs(r.Height - 5) < 0.1)); |
| 35 | + Assert.AreEqual(2, rects.Count(r => System.Math.Abs(r.Width - 5) < 0.1)); |
| 36 | + } |
| 37 | + |
| 38 | + [Ignore("outline-style:auto cannot be parsed at all on this fork: Map.LineStyles (Core/CssEngine/Model/" + |
| 39 | + "Map.cs), the shared keyword table outline-style's converter reuses from border-style, has no " + |
| 40 | + "\"auto\" entry - adding one there would also make it a legal (but spec-invalid) border-style " + |
| 41 | + "value, so this needs its own dedicated converter rather than a shared-map edit, which is out of " + |
| 42 | + "scope for this pass. OutlineDrawHandler.Draw's own \"style == Auto\" check is consequently dead " + |
| 43 | + "code today - reachable only by setting the property programmatically, never via CSS text.")] |
| 44 | + [TestMethod] |
| 45 | + public void OutlineAuto_PaintsTheSameAsSolid() |
| 46 | + { |
| 47 | + var (root, container) = PaintHarness.Layout(PaintHarness.Wrap( |
| 48 | + "<div id='b' style='width:100px;height:50px;outline:5px auto rgb(51,51,51)'>x</div>")); |
| 49 | + var div = PaintHarness.FindById(root, "b")!; |
| 50 | + |
| 51 | + var g = PaintHarness.PaintBox(container, div); |
| 52 | + var rects = g.Log.OfType<RecordingGraphics.DrawRectCall>() |
| 53 | + .Where(r => r.Color == RColor.FromArgb(51, 51, 51)).ToList(); |
| 54 | + |
| 55 | + Assert.AreEqual(4, rects.Count); |
| 56 | + } |
| 57 | + |
| 58 | + [TestMethod] |
| 59 | + public void OutlineColorUnset_FallsBackToCurrentColor() |
| 60 | + { |
| 61 | + var (root, container) = PaintHarness.Layout(PaintHarness.Wrap( |
| 62 | + "<div id='b' style='width:100px;height:50px;color:rgb(10,20,30);outline-style:solid;outline-width:5px'>x</div>")); |
| 63 | + var div = PaintHarness.FindById(root, "b")!; |
| 64 | + |
| 65 | + var g = PaintHarness.PaintBox(container, div); |
| 66 | + var rects = g.Log.OfType<RecordingGraphics.DrawRectCall>().ToList(); |
| 67 | + |
| 68 | + Assert.AreEqual(4, rects.Count); |
| 69 | + Assert.IsTrue(rects.All(r => r.Color == RColor.FromArgb(10, 20, 30))); |
| 70 | + } |
| 71 | + |
| 72 | + [TestMethod] |
| 73 | + public void Outline_PaintsAfterBorder() |
| 74 | + { |
| 75 | + // Paint-order: DrawBoxBorders runs, then OutlineDrawHandler - the outline's draw calls must come |
| 76 | + // after the border's in the recording. |
| 77 | + var (root, container) = PaintHarness.Layout(PaintHarness.Wrap( |
| 78 | + "<div id='b' style='width:100px;height:50px;border:3px solid rgb(1,2,3);outline:5px solid rgb(4,5,6)'>x</div>")); |
| 79 | + var div = PaintHarness.FindById(root, "b")!; |
| 80 | + |
| 81 | + var g = PaintHarness.PaintBox(container, div); |
| 82 | + |
| 83 | + var borderIndex = g.Log.FindIndex(c => c is RecordingGraphics.DrawLineCall line && line.Color == RColor.FromArgb(1, 2, 3)); |
| 84 | + var outlineIndex = g.Log.FindIndex(c => c is RecordingGraphics.DrawRectCall rect && rect.Color == RColor.FromArgb(4, 5, 6)); |
| 85 | + |
| 86 | + Assert.IsTrue(borderIndex >= 0 && outlineIndex >= 0); |
| 87 | + Assert.IsTrue(outlineIndex > borderIndex, "outline must paint after (on top of) the border"); |
| 88 | + } |
| 89 | + |
| 90 | + [TestMethod] |
| 91 | + [DataRow("none")] |
| 92 | + [DataRow("hidden")] |
| 93 | + public void OutlineStyleNoneOrHidden_PaintsNothing(string style) |
| 94 | + { |
| 95 | + var (root, container) = PaintHarness.Layout(PaintHarness.Wrap( |
| 96 | + $"<div id='b' style='width:100px;height:50px;outline:5px {style} rgb(51,51,51)'>x</div>")); |
| 97 | + var div = PaintHarness.FindById(root, "b")!; |
| 98 | + |
| 99 | + var g = PaintHarness.PaintBox(container, div); |
| 100 | + |
| 101 | + Assert.IsFalse(g.Log.OfType<RecordingGraphics.DrawRectCall>().Any(r => r.Color == RColor.FromArgb(51, 51, 51))); |
| 102 | + } |
| 103 | + |
| 104 | + [TestMethod] |
| 105 | + public void ZeroWidthOutline_PaintsNothing() |
| 106 | + { |
| 107 | + var (root, container) = PaintHarness.Layout(PaintHarness.Wrap( |
| 108 | + "<div id='b' style='width:100px;height:50px;outline:0 solid rgb(51,51,51)'>x</div>")); |
| 109 | + var div = PaintHarness.FindById(root, "b")!; |
| 110 | + |
| 111 | + var g = PaintHarness.PaintBox(container, div); |
| 112 | + |
| 113 | + Assert.IsFalse(g.Log.OfType<RecordingGraphics.DrawRectCall>().Any(r => r.Color == RColor.FromArgb(51, 51, 51))); |
| 114 | + } |
| 115 | + |
| 116 | + [Ignore("outline-offset is not implemented on this fork: the CSS-OM here has no OutlineOffsetProperty at " + |
| 117 | + "all (confirmed - no PropertyNames.OutlineOffset, no case in PropertyFactory), so there is no value " + |
| 118 | + "for OutlineDrawHandler to read; the ring always sits flush against the border-box edge instead of " + |
| 119 | + "the requested 10px further out.")] |
| 120 | + [TestMethod] |
| 121 | + public void OutlineOffset_PushesTheRingFurtherFromTheBorderBox() |
| 122 | + { |
| 123 | + var (root, container) = PaintHarness.Layout(PaintHarness.Wrap( |
| 124 | + "<div id='b' style='width:100px;height:50px;outline:5px solid rgb(51,51,51);outline-offset:10px'>x</div>")); |
| 125 | + var div = PaintHarness.FindById(root, "b")!; |
| 126 | + |
| 127 | + var g = PaintHarness.PaintBox(container, div); |
| 128 | + var borderBox = div.Rectangles.Values.Single(); |
| 129 | + var top = g.Log.OfType<RecordingGraphics.DrawRectCall>().First(r => r.Color == RColor.FromArgb(51, 51, 51)); |
| 130 | + |
| 131 | + Assert.AreEqual(borderBox.Y - 10 - 5, top.Y, 0.1); |
| 132 | + } |
| 133 | +} |
0 commit comments