feat(chat): retail text style — two-plane glyph outlines, authored SpewBox/chat styles

Campaign CH round 4, user-gate items 1+2. Root cause: retail ships a
second (background) glyph atlas per font, dilated 2px on every side,
plus two border-pixel scalars (Font.NumHorizontalBorderPixels/
NumVerticalBorderPixels) that acdream's font reader never read — so
even the pre-existing outline parameter drew almost nothing once
enabled. Landed together (either half alone is a no-op or a
regression):

- UiDatFont carries BorderX/BorderY from the DAT font resource.
- UiRenderContext.DrawStringDat inflates the background blit's source
  and destination rect by that margin and restructures into retail's
  exact two-pass whole-string outline-then-fill model
  (UIElement_Text::DrawSelf), plus the 8-neighbour +-1px fallback for
  fonts with no background atlas. Corrects the stale "property 0xd"
  comment to the real ids, 0x21 (Outline) / 0x22 (OutlineColor).
- LayoutDesc property 0x21/0x22 import (ElementInfo.Outline/
  OutlineColor, LayoutImporter.ReadState, ElementReader.Merge/
  ApplyCanonicalLegacyProjection, DatWidgetFactory.BuildText) so every
  authored-outline element across the DAT set is correct at once.
- SpewBox: RetailFontId corrected from a round-3 heuristic
  (0x40000025) to the actually-authored 0x40000001 (18px bold serif),
  Outline=true set on the controller's UiText. Fill colour stays the
  user-gate-round-1-pinned yellow — font atlases are alpha-only
  (PFID_A8), so there is no baked shading that could explain the
  screenshot's gold as anything other than the outline itself.
- Chat transcript: default fill now seeds from its authored
  ARGB(255,204,204,204) instead of an unrelated color-table slot
  (ChatTranscriptRenderer.BuildLines takes the transcript's own
  DefaultColor as a parameter); the 34-entry LogTextType table is
  untouched, and every existing CH1 conformance test stays green
  unmodified.

Regenerated the committed chat_2100006f.json fixture from the real
installed DAT, confirming end to end (not by missing-field default)
that the transcript carries no outline.

Tests: font-reader border fields + inflation math pinned against the
real DAT font, two-pass draw ordering/tint/inflation via a new
TextRenderer.DebugSpriteSegmentVerts test seam, property 0x21/0x22
import at both the ElementReader.Merge and StateDesc-property layers,
SpewBox font/outline, and the chat default-shade seed with the color
table proven untouched.

Full Release suite: 12,610 passed / 4 skipped / 0 failed
(AcDream.slnx, complete solution).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-10 19:28:34 +02:00
parent 5b54387b8e
commit bcc34ee301
22 changed files with 1995 additions and 105 deletions

View file

@ -45,22 +45,43 @@ internal static class ChatTranscriptRenderer
/// advancing for lines actually appended to THIS window's own scroll
/// (<c>AppendStringInfoWithFont</c> only runs for displayed lines).
/// </param>
/// <param name="defaultColor">
/// The transcript element's own base fill color — retail's
/// <c>m_curFontColor</c> BEFORE any <c>AppendTextWithFont</c> call ever
/// tints it, i.e. the value <c>DoFontReset</c> seeds from the element's
/// authored LayoutDesc property <c>0x1B</c> (style <c>0x10000372</c>:
/// <c>ARGB(255,204,204,204)</c> for the main chat transcript). Campaign
/// CH round 4 (<c>docs/research/2026-08-10-retail-ui-text-style.md</c>
/// §5.2 Fix 5): this used to be hardcoded to
/// <c>RetailChatColorTable.TryGetColor(0x00u, ...)</c> (colorGreen) —
/// the color table's OWN default-slot color, not the ELEMENT's authored
/// default. The two are unrelated: the table governs the per-message
/// <c>LogTextType</c> tint (untouched by this parameter — every message
/// with an in-range type still resolves its own table color exactly as
/// before), while <paramref name="defaultColor"/> is only the carried-
/// forward seed for a line whose type falls OUTSIDE the table's 34
/// entries (matching retail's out-of-range "leave <c>m_curFontColor</c>
/// unchanged" rule — see <see cref="RetailChatColorTable"/>'s own doc).
/// Callers pass their transcript's <see cref="UiText.DefaultColor"/>.
/// </param>
public static List<UiText.Line> BuildLines(
IReadOnlyList<FormattedLine> detailed,
float maxW,
Func<string, float> measure,
Func<uint, bool>? accept)
Func<uint, bool>? accept,
Vector4 defaultColor)
{
var result = new List<UiText.Line>(detailed.Count);
if (detailed.Count == 0)
return result;
// Retail's font-color state (m_curFontColor) persists across every
// line actually appended to this window — an out-of-range LogTextType
// leaves it unchanged rather than reverting to a default (color-table
// doc §3.2). Seed the carry with retail's own unfilled-slot default
// (colorGreen, index 0x00).
RetailChatColorTable.TryGetColor(0x00u, out Vector4 currentColor);
// Retail's font-color state (m_curFontColor) persists across every line
// actually appended to this window — an out-of-range LogTextType leaves it
// unchanged rather than reverting to a color-table default (color-table doc
// §3.2). Seed the carry with the ELEMENT's own authored default fill
// (defaultColor), matching retail's DoFontReset — not the color table's
// unrelated index-0x00 slot.
Vector4 currentColor = defaultColor;
foreach (FormattedLine d in detailed)
{
if (accept is not null && !accept(d.LogTextType))

View file

@ -697,7 +697,8 @@ public sealed class ChatWindowController : IRetainedWindowStateController, IReta
// no more accept:null "no user filter" placeholder.
bool Accept(uint logTextType) => _windowFilters.ShouldDisplay(
ChatWindowState.MainWindowId, ChatWindowState.BroadcastTargetWindow, logTextType);
var result = ChatTranscriptRenderer.BuildLines(detailed, maxW, measure, Accept);
var result = ChatTranscriptRenderer.BuildLines(
detailed, maxW, measure, Accept, Transcript.DefaultColor);
return StoreTranscriptLayout(result, revision, filter, maxW, datFont, debugFont);
}

View file

@ -612,6 +612,10 @@ public static class DatWidgetFactory
FontColorPalette = ElementReader.ReadEffectiveColorPalette(
info,
0x1Bu),
// Outline from dat property 0x21 (BoolBaseProperty). Default false — matches
// ElementInfo.Outline's own default, so this is a no-op for the ~99% of text
// elements that don't author it.
Outline = info.Outline,
};
t.ConfigureDatState(info);
@ -622,6 +626,12 @@ public static class DatWidgetFactory
if (info.FontColor.HasValue)
t.DefaultColor = info.FontColor.Value;
// Outline color from dat property 0x22 (ColorBaseProperty). Only 9 elements in the
// whole DAT set author a non-black value; when absent, UiText's own ctor default
// (black, matching retail's m_curOutlineColor default) already applies.
if (info.OutlineColor.HasValue)
t.OutlineColor = info.OutlineColor.Value;
if (ResolveAuthoredString(info, stringResolve) is { Length: > 0 } authored)
t.LinesProvider = () => [new UiText.Line(authored, t.DefaultColor)];

View file

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Numerics;
using AcDream.App.UI;
namespace AcDream.App.UI.Layout;
@ -108,6 +109,26 @@ public sealed class ElementInfo
/// </summary>
public Vector4? FontColor;
/// <summary>
/// Outline flag from dat <c>Properties[0x21]</c> (<c>BoolBaseProperty</c>). Retail
/// <c>UIElement_Text::SetOutline @0x0046a81c</c> / <c>m_bitField &amp; 0x10</c>.
/// Default false (ctor <c>m_bitField=0x300</c> clears the outline bit) — outlining is
/// opt-in per element. Propagated in <see cref="ElementReader.Merge"/> with the same
/// "derived wins when true" rule used for <see cref="FontDid"/>.
/// </summary>
public bool Outline;
/// <summary>
/// Outline color from dat <c>Properties[0x22]</c> (<c>ColorBaseProperty</c>). Retail
/// <c>m_curOutlineColor</c>, ctor default <c>RGBAColor_Black</c>
/// (<c>UIElement_Text::UIElement_Text @0x004686cb</c>). Null means "not authored" —
/// the factory then leaves the widget at its own black default
/// (<see cref="UiRenderContext.DefaultOutlineColor"/>). Propagated in
/// <see cref="ElementReader.Merge"/> with the same "non-null derived wins" rule used
/// for <see cref="FontColor"/>.
/// </summary>
public Vector4? OutlineColor;
/// <summary>
/// Sprite per state: state name → (RenderSurface file id, DrawMode int).
/// The <c>""</c> key represents the unnamed DirectState (<c>ElementDesc.StateDesc</c>).
@ -307,6 +328,12 @@ public static class ElementReader
// FontColor: derived wins when it has an explicit (non-null) color; otherwise inherit the base.
// Null means "dat carried no 0x1B property" — so null-derived does NOT override a non-null base.
FontColor = derived.FontColor ?? base_.FontColor,
// Outline: derived wins when true (the dat property 0x21 was present and read as
// true); otherwise inherit the base. False-derived never overrides a true base —
// matching the FontDid/HJustify "non-default wins" convention.
Outline = derived.Outline || base_.Outline,
// OutlineColor: same "non-null derived wins" rule as FontColor.
OutlineColor = derived.OutlineColor ?? base_.OutlineColor,
// DefaultStateName: derived wins if set; otherwise inherit the base's default.
DefaultStateName = !string.IsNullOrEmpty(derived.DefaultStateName) ? derived.DefaultStateName : base_.DefaultStateName,
// This helper merges one element snapshot only. LayoutImporter separately
@ -384,6 +411,33 @@ public static class ElementReader
info.FontColor = new Vector4(c.Red / 255f, c.Green / 255f, c.Blue / 255f, alpha);
}
}
// Outline (0x21): BoolBaseProperty. Retail SetOutline @0x0046a81c / m_bitField & 0x10.
if (info.TryGetEffectiveProperty(0x21u, out var outline)
&& outline.Kind == UiPropertyKind.Bool)
{
info.Outline = outline.BoolValue;
}
// OutlineColor (0x22): ColorBaseProperty (matches FontColor's Array-tolerant read —
// no authored 0x22 is currently array-wrapped, but the fallback costs nothing).
// Retail m_curOutlineColor, ctor default RGBAColor_Black.
if (info.TryGetEffectiveProperty(0x22u, out var outlineColor))
{
UiPropertyValue? outlineColorValue = outlineColor.Kind == UiPropertyKind.Color
? outlineColor
: outlineColor.Kind == UiPropertyKind.Array
&& outlineColor.ArrayValue.Count > 0
&& outlineColor.ArrayValue[0].Kind == UiPropertyKind.Color
? outlineColor.ArrayValue[0]
: null;
if (outlineColorValue is not null)
{
var c = outlineColorValue.ColorValue;
float alpha = c.Alpha == 0 ? 1f : c.Alpha / 255f;
info.OutlineColor = new Vector4(c.Red / 255f, c.Green / 255f, c.Blue / 255f, alpha);
}
}
}
/// <summary>

View file

@ -277,7 +277,8 @@ public sealed class FloatingChatWindowController : IRetainedPanelController
bool Accept(uint logTextType) => windowFilters.ShouldDisplay(
WindowId, ChatWindowState.BroadcastTargetWindow, logTextType);
var result = ChatTranscriptRenderer.BuildLines(detailed, maxW, measure, Accept);
var result = ChatTranscriptRenderer.BuildLines(
detailed, maxW, measure, Accept, Transcript.DefaultColor);
_cachedTranscriptRevision = revision;
_cachedFilter = filter;

View file

@ -559,6 +559,27 @@ public static class LayoutImporter
float a = c.Alpha == 0 ? 1f : c.Alpha / 255f;
info.FontColor = new System.Numerics.Vector4(c.Red / 255f, c.Green / 255f, c.Blue / 255f, a);
}
// Outline (0x21): BoolBaseProperty. Retail SetOutline @0x0046a81c / m_bitField &
// 0x10. Only update while still at the default (false); derived-wins handled in
// ElementReader.Merge — same "only update if still at default" pattern as HJustify.
if (!info.Outline
&& sd.Properties.TryGetValue(0x21u, out var outlineRaw)
&& outlineRaw is BoolBaseProperty outlineBool)
{
info.Outline = outlineBool.Value;
}
// OutlineColor (0x22): ColorBaseProperty. Retail m_curOutlineColor, ctor default
// RGBAColor_Black. Only read when not already set — same pattern as FontColor.
if (info.OutlineColor is null
&& sd.Properties.TryGetValue(0x22u, out var outlineColorRaw)
&& outlineColorRaw is ColorBaseProperty outlineColorProp)
{
var oc = outlineColorProp.Value;
float oa = oc.Alpha == 0 ? 1f : oc.Alpha / 255f;
info.OutlineColor = new System.Numerics.Vector4(oc.Red / 255f, oc.Green / 255f, oc.Blue / 255f, oa);
}
}
}