Implement native text face selection

This commit is contained in:
gamer147
2026-07-28 14:16:24 -04:00
parent a991d5699c
commit f885ac4189
12 changed files with 270 additions and 33 deletions

View File

@@ -9,6 +9,32 @@ using Xunit;
public class AdvTextOpsTests
{
[Fact]
public void SetFontFaceFlowsIntoLiveAndRetainedTextStyles()
{
var table = OpcodeTableJson.Load(Paths.OpcodesJson);
static Operand I(long value) => new(0, value);
static Operand S(int index) => new(2, index);
var script = ScriptAssembler.Assemble(table, "ADV_FONT_FACE",
new List<(int, Operand[])>
{
(0x1a5, new[] { S(0) }),
(0x6e, new[] { I(0), S(2) }),
(0x1a5, new[] { S(1) }),
(0x6e, new[] { I(0), S(3) }),
(0x2, Array.Empty<Operand>()),
}, new[] { " 明朝", " ゴシック", "mincho", "gothic" });
var host = new RecordingHost();
var vm = new VirtualMachine(script, table, host);
vm.Run();
Assert.Equal(new[] { " 明朝", " ゴシック" },
host.LiveTextRuns.Select(run => run.Run.Style.FontFace));
Assert.Equal(new[] { " 明朝", " ゴシック" },
vm.TextHistory.Records.Select(record => record.Style.FontFace));
}
[Fact]
public void TextCursorAndDrawStringReachHostWithLocalStringPointer()
{

View File

@@ -17,7 +17,7 @@ public class HistoryPresentationOpsTests
history.DefineLayout(1, 640, 160, 80, 430);
history.AppendMetadata(9, 2, AdvTextStyle.Default);
history.AppendText(0, 10, "retained dialogue", new AdvTextStyle(24, 8, false,
0xffffff, 0x606060, 3, 1, 1, 9));
0xffffff, 0x606060, 3, 1, 1, 9, " 明朝"));
history.ResetLayout(1);
history.AppendText(0, 11, "next group", AdvTextStyle.Default);
history.SetRecordingEnabled(false);
@@ -42,9 +42,9 @@ public class HistoryPresentationOpsTests
Assert.Equal((4, 0, "retained dialogue"),
(render.LayoutSlot, render.FirstRecordIndex, render.Text));
Assert.Equal(new AdvTextLayoutSnapshot(4, 600, 150, 65, 150, 45, 42, 600, 150), render.Layout);
Assert.Equal((24, 0xffffffL, 0x606060L, 8),
Assert.Equal((24, 0xffffffL, 0x606060L, 8, " 明朝"),
(render.Style.PrimaryFontSize, render.Style.TextColor, render.Style.EffectColor,
render.Style.LineSpacing));
render.Style.LineSpacing, render.Style.FontFace));
}
[Fact]

View File

@@ -27,9 +27,10 @@ public readonly record struct AdvTextStyle(
int RenderMode,
int EffectOffsetX,
int EffectOffsetY,
int LineSpacing)
int LineSpacing,
string FontFace)
{
public static AdvTextStyle Default => new(0, 0, false, 0, 0, 0, 0, 0, 6);
public static AdvTextStyle Default => new(0, 0, false, 0, 0, 0, 0, 0, 6, "");
}
/// <summary>A stable snapshot of the layout state associated with a retained record.</summary>

View File

@@ -2269,6 +2269,7 @@ public sealed class VirtualMachine
case "end-text-line":
TextHistory.EndLine((int)Read(a[0]), _advTextStyle); return pc + 1;
case "set-font":
_advTextStyle = _advTextStyle with { FontFace = ReadStr(a[0]) }; return pc + 1;
case "comment": case "display-furigana": case "dev_ukn":
return pc + 1;
case "create-texture": // 0x1f8 (slot)(w)(h) — allocate a blank surface at the slot