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>
131 lines
5.4 KiB
C#
131 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using AcDream.App.UI;
|
|
using DatReaderWriter;
|
|
using DatReaderWriter.DBObjs;
|
|
using DatReaderWriter.Options;
|
|
using DatReaderWriter.Types;
|
|
using SysEnv = System.Environment;
|
|
|
|
namespace AcDream.App.Tests.UI;
|
|
|
|
/// <summary>
|
|
/// Pins <c>Font.NumHorizontalBorderPixels</c>/<c>NumVerticalBorderPixels</c>
|
|
/// (<c>Font::Serialize @0x00443650</c>) against the real installed DAT, and the
|
|
/// <see cref="UiDatFont"/> plumbing that carries them from
|
|
/// <see cref="UiDatFont.Load"/> onto <see cref="UiDatFont.BorderX"/>/
|
|
/// <see cref="UiDatFont.BorderY"/> — the field this project's font reader
|
|
/// dropped entirely before Campaign CH round 4
|
|
/// (<c>docs/research/2026-08-10-retail-ui-text-style.md</c> §1.4). A repo-wide
|
|
/// grep for <c>BorderPixel</c> returned zero hits before this fix; these tests
|
|
/// are the regression guard against that gap reappearing.
|
|
///
|
|
/// <para>
|
|
/// The live-dat tests follow <see cref="AcDream.App.Tests.UI.RetailCursorCatalogTests"/>'s
|
|
/// pattern: skip (not fail) when the real dats aren't present, so the suite stays
|
|
/// green in environments without the installed game.
|
|
/// </para>
|
|
/// </summary>
|
|
public sealed class UiDatFontBorderPixelTests
|
|
{
|
|
// Measured values — docs/research/2026-08-10-retail-ui-text-style.md §1.3.
|
|
[Theory]
|
|
[InlineData(0x40000000u, 4u, 4u)] // 16px bold serif — chat transcript face
|
|
[InlineData(0x40000001u, 4u, 4u)] // 18px bold serif — SpewBox face (round 4)
|
|
[InlineData(0x40000002u, 3u, 3u)] // 14px bold serif
|
|
[InlineData(0x40000025u, 3u, 3u)] // 11px — the pre-round-4 SpewBox placeholder face
|
|
public void RealDatFont_HasExpectedBorderPixels(uint fontId, uint expectedHorizontal, uint expectedVertical)
|
|
{
|
|
string? datDir = ResolveDatDir();
|
|
if (datDir is null)
|
|
return;
|
|
|
|
using var dats = new DatCollection(datDir, DatAccessType.Read);
|
|
Assert.True(dats.TryGet<Font>(fontId, out Font? font), $"Font 0x{fontId:X8} not found");
|
|
Assert.NotNull(font);
|
|
Assert.Equal(expectedHorizontal, font!.NumHorizontalBorderPixels);
|
|
Assert.Equal(expectedVertical, font.NumVerticalBorderPixels);
|
|
}
|
|
|
|
[Fact]
|
|
public void RealDatFont_EveryFontWithABackgroundAtlas_HasANonZeroBorder()
|
|
{
|
|
// docs/research/2026-08-10-retail-ui-text-style.md §1.2: "every font that
|
|
// has a background atlas has border >= 3, and every font without one has
|
|
// border == 0" — the data-driven dispatch DrawStringDat's outline pass
|
|
// relies on (background plane vs 8-neighbour fallback) is exactly this
|
|
// correlation. Sweep the documented populated range (0x40000000-0x40000032).
|
|
string? datDir = ResolveDatDir();
|
|
if (datDir is null)
|
|
return;
|
|
|
|
using var dats = new DatCollection(datDir, DatAccessType.Read);
|
|
int checkedCount = 0;
|
|
for (uint id = 0x40000000u; id <= 0x40000032u; id++)
|
|
{
|
|
if (!dats.TryGet<Font>(id, out Font? font) || font is null)
|
|
continue;
|
|
checkedCount++;
|
|
|
|
bool hasBackground = font.BackgroundSurfaceDataId != 0;
|
|
bool hasBorder = font.NumHorizontalBorderPixels > 0 || font.NumVerticalBorderPixels > 0;
|
|
Assert.True(
|
|
hasBackground == hasBorder,
|
|
$"Font 0x{id:X8}: hasBackground={hasBackground} but hasBorder={hasBorder}");
|
|
}
|
|
|
|
Assert.True(checkedCount > 10, "expected the documented font sweep to find multiple populated fonts");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Pure plumbing check — no dat, no GL: the <see cref="UiDatFont"/> ctor
|
|
/// stores <paramref name="borderX"/>/<paramref name="borderY"/> verbatim onto
|
|
/// <see cref="UiDatFont.BorderX"/>/<see cref="UiDatFont.BorderY"/>, and existing
|
|
/// callers that omit them (pre-round-4 test fixtures) still default to zero.
|
|
/// </summary>
|
|
[Theory]
|
|
[InlineData(4, 4)]
|
|
[InlineData(3, 3)]
|
|
[InlineData(0, 0)]
|
|
public void Ctor_StoresBorderPixelsVerbatim(int borderX, int borderY)
|
|
{
|
|
var font = new UiDatFont(
|
|
fgTex: 1, fgW: 64, fgH: 64,
|
|
bgTex: 2, bgW: 64, bgH: 64,
|
|
lineHeight: 16f, baselineOffset: 12f,
|
|
glyphs: new Dictionary<char, FontCharDesc>(),
|
|
borderX: borderX, borderY: borderY);
|
|
|
|
Assert.Equal(borderX, font.BorderX);
|
|
Assert.Equal(borderY, font.BorderY);
|
|
}
|
|
|
|
[Fact]
|
|
public void Ctor_OmittedBorderPixels_DefaultToZero()
|
|
{
|
|
// Pins backward compatibility for the existing UiDatFontTests/SpewBoxControllerTests
|
|
// call sites that construct UiDatFont without borderX/borderY.
|
|
var font = new UiDatFont(
|
|
fgTex: 0, fgW: 0, fgH: 0,
|
|
bgTex: 0, bgW: 0, bgH: 0,
|
|
lineHeight: 16f, baselineOffset: 12f,
|
|
glyphs: new Dictionary<char, FontCharDesc>());
|
|
|
|
Assert.Equal(0, font.BorderX);
|
|
Assert.Equal(0, font.BorderY);
|
|
}
|
|
|
|
private static string? ResolveDatDir()
|
|
{
|
|
string? fromEnv = SysEnv.GetEnvironmentVariable("ACDREAM_DAT_DIR");
|
|
if (!string.IsNullOrWhiteSpace(fromEnv) && Directory.Exists(fromEnv))
|
|
return fromEnv;
|
|
|
|
string defaultDir = Path.Combine(
|
|
SysEnv.GetFolderPath(SysEnv.SpecialFolder.UserProfile),
|
|
"Documents",
|
|
"Asheron's Call");
|
|
return Directory.Exists(defaultDir) ? defaultDir : null;
|
|
}
|
|
}
|