diff --git a/ErsatzTV.Core/Graphics/TextGraphicsElement.cs b/ErsatzTV.Core/Graphics/TextGraphicsElement.cs index efe5090cb..6ff335972 100644 --- a/ErsatzTV.Core/Graphics/TextGraphicsElement.cs +++ b/ErsatzTV.Core/Graphics/TextGraphicsElement.cs @@ -33,7 +33,8 @@ public class TextGraphicsElement : BaseGraphicsElement // Background box (ersatztv#732). Element-level, not per-style: the graphics engine renders one // TextBlock into one bitmap, so a single box behind the whole element is the only shape the - // renderer can express. Unset background_color means no box at all -- the pre-#732 behavior. + // renderer can express. Unset background_color means no FILL; a border_color alone still draws + // an outlined box. With neither there is no box and no insets -- the pre-#732 geometry. [YamlMember(Alias = "background_color", ApplyNamingConventions = false)] public string BackgroundColor { get; set; } diff --git a/ErsatzTV.Tests/Infrastructure/Graphics/TextElementBackgroundBoxTests.cs b/ErsatzTV.Tests/Infrastructure/Graphics/TextElementBackgroundBoxTests.cs index 0c86112a9..2e3a45878 100644 --- a/ErsatzTV.Tests/Infrastructure/Graphics/TextElementBackgroundBoxTests.cs +++ b/ErsatzTV.Tests/Infrastructure/Graphics/TextElementBackgroundBoxTests.cs @@ -561,4 +561,97 @@ public class TextElementBackgroundBoxTests HaloPixels(thin).ShouldBeGreaterThan(0, "the style's own halo was not applied"); HaloPixels(thick).ShouldBeGreaterThan(HaloPixels(thin), "halo_width had no effect per style"); } + + private static int PixelsMatching(SKBitmap b, Func predicate) + { + var n = 0; + for (var x = 0; x < b.Width; x++) + { + for (var y = 0; y < b.Height; y++) + { + if (predicate(b.GetPixel(x, y))) + { + n++; + } + } + } + + return n; + } + + // halo_blur is a per-style field too, and the merge loop drops it just as silently as halo_color + // did. Blur spreads the halo over more pixels at lower alpha, so a blurred halo covers more area. + [Test] + public void A_Non_Base_Style_Uses_Its_Own_Halo_Blur() + { + static TextGraphicsElement WithSubBlur(float blur) + { + TextGraphicsElement element = BaseElement(); + element.Styles.Add(new StyleDefinition + { + Name = "sub", + FontFamily = "Roboto", + FontSize = 40, + TextColor = "#FFFFFF", + HaloColor = "#00FF00", + HaloWidth = 3, + HaloBlur = blur + }); + element.Text = "[sub]Hello[/sub]"; + return element; + } + + SKBitmap sharp = Render(WithSubBlur(0)); + SKBitmap blurred = Render(WithSubBlur(5)); + + static bool Greenish(SKColor px) => px.Green > 60 && px.Red < 140 && px.Alpha > 0; + + PixelsMatching(blurred, Greenish) + .ShouldNotBe(PixelsMatching(sharp, Greenish), "halo_blur had no effect per style"); + } + + // FitTextBlock rebuilds every style from scratch on the Scale path. line_height and halo_blur are + // carried across there; without them a scaled element silently loses line spacing and halo blur. + [Test] + public void The_Scale_Path_Preserves_Line_Height() + { + static TextGraphicsElement Scaled(float lineHeight) + { + TextGraphicsElement element = BaseElement(); + element.Text = "The quick brown fox jumps over the lazy dog"; + element.Fit = TextFit.Scale; + element.WidthPercent = 15; + element.Styles[0].LineHeight = lineHeight; + return element; + } + + SKBitmap tight = Render(Scaled(1.0f)); + SKBitmap loose = Render(Scaled(2.5f)); + + loose.Height.ShouldBeGreaterThan(tight.Height, "line_height was dropped by the Scale path"); + } + + [Test] + public void The_Scale_Path_Preserves_Halo_Blur() + { + static TextGraphicsElement Scaled(float blur) + { + TextGraphicsElement element = BaseElement(); + element.Text = "The quick brown fox jumps over the lazy dog"; + element.Fit = TextFit.Scale; + element.WidthPercent = 15; + element.Styles[0].HaloColor = "#00FF00"; + element.Styles[0].HaloWidth = 3; + element.Styles[0].HaloBlur = blur; + return element; + } + + SKBitmap sharp = Render(Scaled(0)); + SKBitmap blurred = Render(Scaled(5)); + + static bool Greenish(SKColor px) => px.Green > 60 && px.Red < 140 && px.Alpha > 0; + + PixelsMatching(blurred, Greenish) + .ShouldNotBe(PixelsMatching(sharp, Greenish), "halo_blur was dropped by the Scale path"); + } } diff --git a/docs/graphics-elements.md b/docs/graphics-elements.md index 79225d58f..518df9875 100644 --- a/docs/graphics-elements.md +++ b/docs/graphics-elements.md @@ -98,7 +98,13 @@ Every one of these overrides the `base_style`'s value when the style declares it did not until #732, so before that a non-base style silently rendered the base style's halo. The seeded `on-now-next.yml` is unaffected because all three of its styles declare the same halo: its rendered bitmap is byte-identical either way (md5 `0663AF1E13C558F4DB99F887318E275D`, 1920x1080, -measured 2026-08-26). A third-party template that varies halo per style will change, correctly. +measured 2026-08-26). + +**This is an operator-visible change and belongs in the release notes.** A custom template whose +non-base style declares its own `halo_color` / `halo_width` / `halo_blur` renders differently after +this version — correctly, but differently. So does one using `line_height` with `text_fit: Scale`: +the Scale path now carries line height through, which changes measured height and therefore where the +element anchors. Halo is drawn by RichTextKit as part of the text, not by the box code — a wide halo **on top of** a background box over-darkens the glyphs, which is why the seeded template cuts it to 1px.