XML font legs and font-object getters follow 1.12.1 (#1940)

The XML font legs and the font-object getters differed from 1.12.1.

- A font file that fails to load writes nothing and logs `Unable to load font file` (`0x878dc8`, `0x87a4c8`); a font already held skips the load (`0x771502`).
- A FontString's `inherits`/`font=` look in the one font table `CreateFont` fills (`0x783870`) before templates; a miss logs `Couldn't find inherited node`.
- Regions read no `alpha=`; the options window's icon sets it in its OnLoad.
- Justify tokens follow `0x6f1990`: a miss is skipped, the other axis's token zeroes the axis.
- A Font object's default shadow is transparent.
- `GetFont` lists every flag, comma-joined (`0x6f1ad0`); only `THICKOUTLINE` is thick.

No stock screen changes. A byte audit re-derived every address and string.

Fixes #1888
Fixes #1891
Fixes #1921
Fixes #1922
Fixes #1887
Fixes #1919
Fixes #1928
Fixes #1899
Fixes #1905
Fixes #1816
Fixes #1929

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sam Sung
2026-10-18 20:14:21 +07:00
committed by GitHub
parent 3acad6b1b9
commit 2bfbf19e93
24 changed files with 825 additions and 184 deletions
@@ -3042,13 +3042,14 @@
<Anchors><Anchor point="RIGHT"><Offset><AbsDimension x="-3" y="0"/></Offset></Anchor></Anchors>
<Layers>
<Layer level="ARTWORK">
<Texture name="$parentIcon" file="Interface\Buttons\UI-Panel-MinimizeButton-Up" alpha="0.5">
<Texture name="$parentIcon" file="Interface\Buttons\UI-Panel-MinimizeButton-Up">
<Size><AbsDimension x="17" y="17"/></Size>
<Anchors><Anchor point="CENTER"/></Anchors>
</Texture>
</Layer>
</Layers>
<Scripts>
<OnLoad>getglobal(this:GetName() .. "Icon"):SetAlpha(0.5)</OnLoad>
<OnClick>
BenillaOptionsFrameSearchBox:SetText("")
BenillaOptionsFrameSearchBox:ClearFocus()
@@ -203,7 +203,7 @@ pub(super) fn emit(
host.rect.height(),
style.font_height,
spec.height,
style.outline.as_str(),
style.outline.flags_text(style.monochrome),
spec.path.unwrap_or("<none — the fallback face>"),
ebox_geom.unwrap_or_default(),
&draw_text[..draw_text.len().min(60)]
+11 -2
View File
@@ -213,13 +213,22 @@ fn install_addon_asset_resolvers(world: &mut World, script: &mut UiScript) {
if let Some(&cached) = seen.borrow().get(path) {
return cached;
}
let found = font_loose.find(path, LooseOpen::BareNameFirst).is_some()
|| font_chain.lock_recover().contains(path);
let found = font_found(&font_chain, &font_loose, path);
seen.borrow_mut().insert(path.to_string(), found);
found
}));
}
/// Whether a font face's open of `path` finds a file: the loose files by bare name first, then the
/// chain, as `ui_text::engine`'s face loader reads them.
pub(super) fn font_found(
chain: &std::sync::Mutex<benilla_formats::Chain>,
loose: &benilla_assets::LooseFiles,
path: &str,
) -> bool {
loose.find(path, LooseOpen::BareNameFirst).is_some() || chain.lock_recover().contains(path)
}
/// Whether this run wants the player UI: always outside a capture, and in one only when opted in
/// ([`crate::run_mode::capture_ui_opted_in`]), since capture baselines test the world render.
fn ui_wanted(world: &World) -> bool {
@@ -391,6 +391,11 @@ fn search_reflows_live_rows_and_restores_the_page() {
let authored_top: f32 = s
.eval("return BenillaOptionsFrameContainerBodyAudioRowMaster:GetTop()")
.unwrap();
// The clear button's icon rests at half alpha, set by its `OnLoad`: no region reads `alpha=`.
let icon: f32 = s
.eval("return BenillaOptionsFrameSearchBoxClearButtonIcon:GetAlpha()")
.unwrap();
assert!((icon - 0.5).abs() < 0.01, "the clear icon at rest: {icon}");
s.run("BenillaOptionsFrameSearchBox:SetText(\"music\")")
.unwrap();
@@ -2109,6 +2109,40 @@ mod tests {
assert_eq!(failed(&mut glue), Vec::<String>::new(), "the glue");
}
/// An XML font file that does not load is logged and leaves the font as it was (`0x771226`,
/// `0x783eaf`). No stock font the core or the glue declares fails on an install, so a line
/// here is benilla's font probe missing a face the reference opens, which would strip a stock
/// font.
#[test]
fn every_font_file_the_stock_interface_loads_opens() {
let data = benilla_formats::wow_data_or_skip!();
let probe = |s: &mut UiScript| {
let chain = std::sync::Mutex::new(benilla_formats::open_chain(&data).expect("chain"));
let loose = benilla_assets::LooseFiles::install();
s.set_font_probe(Box::new(move |path| {
super::super::lifecycle::font_found(&chain, &loose, path)
}));
};
let failed = |s: &mut UiScript| -> Vec<String> {
s.finish_ui_load_log();
let mut lines: Vec<String> = s.diagnostics().into_iter().map(|d| d.message).collect();
lines.extend(s.take_load_log_writes().iter().map(|w| format!("{w:?}")));
lines.retain(|l| l.contains("Unable to load font file"));
lines
};
let mut core = UiScript::new().expect("VM");
core.set_screen_size(1024.0, 768.0);
probe(&mut core);
super::super::manifest::load_default_ui(&core);
assert_eq!(failed(&mut core), Vec::<String>::new(), "the core");
let mut glue = UiScript::new_glue().expect("VM");
glue.set_screen_size(1024.0, 768.0);
probe(&mut glue);
super::super::glue::load_glue(&mut glue);
assert_eq!(failed(&mut glue), Vec::<String>::new(), "the glue");
}
fn seat_a_player(s: &mut UiScript) {
s.set_unit(
"player",
+3
View File
@@ -76,6 +76,9 @@ impl Rgba8 {
pub const WHITE: Self = Self::rgba(255, 255, 255, 255);
/// `0xff000000`, a FontString's own default shadow (`0x770da1`).
pub const BLACK: Self = Self::rgba(0, 0, 0, 255);
/// `0x00000000`, the default shadow of every font `CSimpleFont`'s constructor builds
/// (`0x783a72`): a `CreateFont` or `<Font>` font and a widget's own.
pub const TRANSPARENT: Self = Self::rgba(0, 0, 0, 0);
pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
Self { r, g, b, a }
+22 -7
View File
@@ -202,10 +202,25 @@ impl Templates {
/// losing the boundaries that per-level state (a texture's wrap flag, `0x76fec6`) follows. A
/// cycle stops at the repeated name.
pub fn inherited_levels(&self, element: &Element) -> Vec<std::rc::Rc<Element>> {
self.inherited_levels_until(element, |_| false)
}
/// [`Self::inherited_levels`], the walk stopping at the first `inherits` that `is_font` claims:
/// a FontString looks the name up as a font first and loads no template once one answers
/// (`0x770f69` → `0x770fb7`), so a template of the same name, and what it inherits, is never a
/// level.
pub fn inherited_levels_until(
&self,
element: &Element,
is_font: impl Fn(&str) -> bool,
) -> Vec<std::rc::Rc<Element>> {
let mut out: Vec<std::rc::Rc<Element>> = Vec::new();
let mut active: Vec<String> = Vec::new();
let mut name = element.attr("inherits").map(str::to_string);
while let Some(n) = name.filter(|n| !n.is_empty()) {
if is_font(&n) {
break;
}
let key = n.to_ascii_lowercase();
if active.contains(&key) {
break;
@@ -457,25 +472,25 @@ pub fn expand(
templates: &dyn Inheritable,
warnings: &mut Vec<String>,
) -> Element {
expand_known(element, templates, &HashSet::new(), warnings)
expand_known(element, templates, &|_| false, warnings)
}
/// [`expand`], skipping without a warning an `inherits` that names a font object: a
/// [`expand`], skipping without a warning an `inherits` that `is_font` claims: a
/// `<FontString inherits="GameFontNormalSmall">` takes a font, applied later, not a template.
pub fn expand_known(
element: &Element,
templates: &dyn Inheritable,
fonts: &HashSet<&str>,
is_font: &dyn Fn(&str) -> bool,
warnings: &mut Vec<String>,
) -> Element {
let mut active = HashSet::new();
expand_inner(element, templates, fonts, warnings, &mut active)
expand_inner(element, templates, is_font, warnings, &mut active)
}
fn expand_inner(
element: &Element,
templates: &dyn Inheritable,
fonts: &HashSet<&str>,
is_font: &dyn Fn(&str) -> bool,
warnings: &mut Vec<String>,
active: &mut HashSet<String>,
) -> Element {
@@ -497,7 +512,7 @@ fn expand_inner(
}
let Some(template) = templates.find(name) else {
// A font object is not an unknown template; it is applied after this.
if !fonts.contains(name) {
if !is_font(name) {
warnings.push(format!(
"unknown template '{name}' referenced by inherits; skipping"
));
@@ -505,7 +520,7 @@ fn expand_inner(
active.remove(name);
continue;
};
let expanded_template = expand_inner(template, templates, fonts, warnings, active);
let expanded_template = expand_inner(template, templates, is_font, warnings, active);
active.remove(name);
base = Some(match base {
None => expanded_template,
+378
View File
@@ -572,3 +572,381 @@ fn a_font_element_reads_its_flags_only_beside_its_own_font_file() {
"Couldn't find inherited font: LevelNoSuchFont"
));
}
const NOPE: &str = r"Fonts\NOPE.TTF";
/// `0x770f40`, `0x783c30`: a `font=` file that fails to load writes nothing, is logged
/// (`0x878dc8`, `0x87a4c8`) and the node goes on to `spacing`, so a FontString or a Font keeps the
/// font it follows, and keeps following it. The font already held skips the load, keeps its
/// spelling and clears the bit (`0x771541`, `0x783e5d` → `0x783ea9`).
#[test]
fn an_xml_font_file_that_fails_to_load_keeps_the_followed_font() {
let mut s = ui();
load_str(
&s,
r#"<Ui><Font name="LoadHeld" font="Fonts\HELD.TTF" virtual="true">
<FontHeight><AbsValue val="10"/></FontHeight>
</Font></Ui>"#,
);
s.set_font_probe(Box::new(|path: &str| {
!path.contains("NOPE") && !path.contains("HELD")
}));
let report = load_str(
&s,
r#"<Ui>
<Font name="LoadParent" font="Fonts\FRIZQT__.TTF" outline="NORMAL" virtual="true">
<FontHeight><AbsValue val="12"/></FontHeight>
</Font>
<Font name="LoadChild" inherits="LoadParent" font="Fonts\NOPE.TTF" spacing="2"
virtual="true">
<FontHeight><AbsValue val="20"/></FontHeight>
</Font>
<Font name="LoadHeldAgain" inherits="LoadHeld" font="fonts\held.ttf" virtual="true">
<FontHeight><AbsValue val="10"/></FontHeight>
</Font>
<Frame name="LoadHost">
<Layers><Layer>
<FontString name="LoadMissed" inherits="LoadParent" font="Fonts\NOPE.TTF"
spacing="3">
<FontHeight><AbsValue val="20"/></FontHeight>
</FontString>
<FontString name="LoadKept" inherits="LoadHeld" font="FONTS\HELD.TTF">
<FontHeight><AbsValue val="10"/></FontHeight>
</FontString>
</Layer></Layers>
</Frame>
</Ui>"#,
);
let font = |s: &UiScript, name: &str| {
s.eval::<String>(&format!(
"local f, h, flags = {name}:GetFont() \
return table.concat({{f, h, flags, {name}:GetSpacing()}}, ' ')"
))
.unwrap()
};
assert_eq!(font(&s, "LoadChild"), r"Fonts\FRIZQT__.TTF 12 OUTLINE 2");
assert_eq!(font(&s, "LoadMissed"), r"Fonts\FRIZQT__.TTF 12 OUTLINE 3");
for line in [
format!("Font LoadChild: Unable to load font file {NOPE}"),
format!("FontString LoadMissed: Unable to load font file {NOPE}"),
] {
assert!(has_line(&report, &line), "{line}: {:?}", report.warnings);
}
assert_eq!(report.warnings.len(), 2, "{:?}", report.warnings);
// Their font bit is still set, so the parent's next font reaches them; the held font's
// string and font cleared theirs.
s.run(r#"LoadParent:SetFont("Fonts\\ARIALN.TTF", 9) LoadHeld:SetFont("Fonts\\ARIALN.TTF", 9)"#)
.unwrap();
assert_eq!(font(&s, "LoadChild"), r"Fonts\ARIALN.TTF 9 2");
assert_eq!(font(&s, "LoadMissed"), r"Fonts\ARIALN.TTF 9 3");
assert!(font(&s, "LoadKept").starts_with(r"Fonts\HELD.TTF 10 "));
assert!(font(&s, "LoadHeldAgain").starts_with(r"Fonts\HELD.TTF 10 "));
}
/// `0x770f69`-`0x770f88`: a FontString's `inherits=` is looked up as a font first, and a hit jumps
/// past the template lookup, so a template of the same name is never a level, on a Button's
/// `<NormalText>` (which links nothing) too.
#[test]
fn a_fontstring_inheriting_a_font_loads_no_template_of_that_name() {
let s = ui();
load_str(
&s,
&format!(
r#"<Ui>{TEST_FONT}
<Font name="LevelBoth" font="Fonts\ARIALN.TTF" virtual="true">
<FontHeight><AbsValue val="14"/></FontHeight>
</Font>
<FontString name="LevelBoth" text="T" justifyH="LEFT" virtual="true">
<Anchors><Anchor point="BOTTOMRIGHT"/></Anchors>
</FontString>
<Frame name="BothHost">
<Size><AbsDimension x="64" y="64"/></Size>
<Layers><Layer>
<FontString name="BothKid" inherits="LevelBoth"/>
<FontString name="BothControl" inherits="LevelTestFont"/>
</Layer></Layers>
</Frame>
<Button name="BothButton">
<NormalText inherits="LevelBoth"/>
</Button>
</Ui>"#
),
);
let got = |expr: &str| {
s.eval::<String>(&format!("return tostring({expr})"))
.unwrap()
};
assert_eq!(got("BothKid:GetText()"), "nil", "no template text");
assert_eq!(got("BothKid:GetFontObject() == LevelBoth"), "true");
assert_eq!(
got("BothKid:GetJustifyH()"),
"CENTER",
"no template justify"
);
assert_eq!(
got("BothKid:GetNumPoints() .. (BothKid:GetPoint(1))"),
got("BothControl:GetNumPoints() .. (BothControl:GetPoint(1))"),
"only the implicit anchor"
);
assert_ne!(
got("BothButton:GetText()"),
"T",
"<NormalText> loads no template either"
);
}
/// `0x783870` is the one font table, which `CreateFont` fills (`0x706077`): a FontString's
/// `font=` and `inherits=` find a font a script made.
#[test]
fn a_fontstring_finds_a_font_made_by_create_font() {
let s = ui();
let report = load_str(
&s,
r#"<Ui>
<Script>CreateFont("LevelLuaFont"):SetFont("Fonts\\ARIALN.TTF", 15)</Script>
<Frame name="LuaFontHost">
<Layers><Layer>
<FontString name="LuaFontKid" font="LevelLuaFont"/>
<FontString name="LuaInheritKid" inherits="levelluafont"/>
</Layer></Layers>
</Frame>
</Ui>"#,
);
for name in ["LuaFontKid", "LuaInheritKid"] {
let (linked, path, height) = s
.eval::<(bool, String, f32)>(&format!(
"local f, h = {name}:GetFont() return {name}:GetFontObject() == LevelLuaFont, f, h"
))
.unwrap();
assert!(linked, "{name} follows the font");
assert_eq!(
(path.as_str(), height),
(r"Fonts\ARIALN.TTF", 15.0),
"{name}"
);
}
assert!(report.warnings.is_empty(), "{:?}", report.warnings);
}
/// `0x770f8a`-`0x770fb1`: an `inherits=` that names neither a font nor a template is logged
/// (`0x8786a8`) whoever owns the string's font, and links nothing. A `<NormalText>` also loads into
/// the button's Normal font (`0x783c30`), which logs its own miss (`0x87a51c`).
#[test]
fn a_fontstring_inheriting_nothing_is_logged() {
let s = ui();
let report = load_str(
&s,
r#"<Ui>
<Frame name="NothingHost">
<Layers><Layer>
<FontString name="NothingKid" inherits="LevelNothing"/>
</Layer></Layers>
</Frame>
<Button name="NothingButton">
<NormalText inherits="LevelNothingToo"/>
</Button>
</Ui>"#,
);
for line in [
"Couldn't find inherited node: LevelNothing",
"Couldn't find inherited node: LevelNothingToo",
"Couldn't find inherited font: LevelNothingToo",
] {
assert!(has_line(&report, line), "{line}: {:?}", report.warnings);
}
assert_eq!(report.warnings.len(), 3, "{:?}", report.warnings);
assert!(s
.eval::<bool>("return NothingKid:GetFontObject() == nil")
.unwrap());
}
/// The one reader of `alpha` (`0x873fe8`) is the frame loader (`0x769a10`): the texture
/// (`0x76fe20`) and FontString (`0x770f40`) loaders never read it.
#[test]
fn a_region_reads_no_alpha() {
let s = ui();
load_str(
&s,
&format!(
r#"<Ui>{TEST_FONT}
<Frame name="AlphaHost" alpha="0.5">
<Layers><Layer>
<Texture name="AlphaTexture" file="Interface\Good" alpha="0.5"/>
<FontString name="AlphaText" inherits="LevelTestFont" alpha="0.25"/>
</Layer></Layers>
</Frame>
</Ui>"#
),
);
let alpha = |name: &str| s.eval::<f32>(&format!("return {name}:GetAlpha()")).unwrap();
assert_eq!(alpha("AlphaTexture"), 1.0);
assert_eq!(alpha("AlphaText"), 1.0);
assert!((alpha("AlphaHost") - 0.5).abs() < 0.01, "a frame reads it");
}
/// `0x783f47`-`0x783fd8`, `0x77129f`-`0x771366`: an XML justify token is matched as `0x6f1990`
/// does. One that matches nothing is skipped and clears no bit, so the axis still follows its
/// font; the other axis's token zeroes the axis; neither raises.
#[test]
fn an_xml_justify_token_is_matched_and_a_miss_skipped() {
let s = ui();
load_str(
&s,
&format!(
r#"<Ui>{TEST_FONT}
<Font name="JustParent" inherits="LevelTestFont" justifyH="LEFT" virtual="true"/>
<Font name="JustBogus" inherits="JustParent" justifyH="BOGUS" justifyV="NOPE"
virtual="true"/>
<Font name="JustCross" inherits="JustParent" justifyH="TOP" justifyV="LEFT"
virtual="true"/>
<Frame name="JustHost">
<Layers><Layer>
<FontString name="JustString" inherits="JustParent" justifyH="BOGUS"/>
<FontString name="JustStringCross" inherits="JustParent" justifyV="RIGHT"/>
</Layer></Layers>
</Frame>
</Ui>"#
),
);
let justify = |name: &str| {
s.eval::<String>(&format!(
"return {name}:GetJustifyH() .. ' ' .. {name}:GetJustifyV()"
))
.unwrap()
};
assert_eq!(justify("JustBogus"), "LEFT MIDDLE");
assert_eq!(justify("JustCross"), "UNKNOWN UNKNOWN");
assert_eq!(justify("JustString"), "LEFT MIDDLE");
assert_eq!(justify("JustStringCross"), "LEFT UNKNOWN");
s.run(r#"JustParent:SetJustifyH("RIGHT")"#).unwrap();
assert_eq!(justify("JustBogus"), "RIGHT MIDDLE", "still following");
assert_eq!(justify("JustString"), "RIGHT MIDDLE", "still following");
assert_eq!(justify("JustCross"), "UNKNOWN UNKNOWN");
}
/// `0x771502`-`0x771541`, `0x783e17`-`0x783e5d`: the held-font shortcut needs the path, the height
/// and the flags all equal; only the flags or only the height differing goes to the load, which a
/// refused file fails (logged, the font kept).
#[test]
fn a_held_font_differing_only_in_height_or_flags_reloads() {
let mut s = ui();
load_str(
&s,
r#"<Ui><Font name="ReloadHeld" font="Fonts\HELD.TTF" virtual="true">
<FontHeight><AbsValue val="10"/></FontHeight>
</Font></Ui>"#,
);
s.set_font_probe(Box::new(|path: &str| !path.contains("HELD")));
let report = load_str(
&s,
r#"<Ui>
<Font name="ReloadFlags" inherits="ReloadHeld" font="Fonts\HELD.TTF" outline="NORMAL"
virtual="true">
<FontHeight><AbsValue val="10"/></FontHeight>
</Font>
<Font name="ReloadHeight" inherits="ReloadHeld" font="Fonts\HELD.TTF" virtual="true">
<FontHeight><AbsValue val="11"/></FontHeight>
</Font>
<Frame name="ReloadHost">
<Layers><Layer>
<FontString name="ReloadFlagsString" inherits="ReloadHeld"
font="Fonts\HELD.TTF" monochrome="1">
<FontHeight><AbsValue val="10"/></FontHeight>
</FontString>
<FontString name="ReloadHeightString" inherits="ReloadHeld"
font="Fonts\HELD.TTF">
<FontHeight><AbsValue val="11"/></FontHeight>
</FontString>
</Layer></Layers>
</Frame>
</Ui>"#,
);
for line in [
r"Font ReloadFlags: Unable to load font file Fonts\HELD.TTF",
r"Font ReloadHeight: Unable to load font file Fonts\HELD.TTF",
r"FontString ReloadFlagsString: Unable to load font file Fonts\HELD.TTF",
r"FontString ReloadHeightString: Unable to load font file Fonts\HELD.TTF",
] {
assert!(has_line(&report, line), "{line}: {:?}", report.warnings);
}
for name in [
"ReloadFlags",
"ReloadHeight",
"ReloadFlagsString",
"ReloadHeightString",
] {
let font = s
.eval::<String>(&format!(
"local f, h, flags = {name}:GetFont() return table.concat({{f, h, flags}}, ' ')"
))
.unwrap();
assert_eq!(font, r"Fonts\HELD.TTF 10 ", "{name} keeps the held font");
}
}
/// `0x770f69`: each level's `inherits` is asked as a font first, so a template chain stops at the
/// font it reaches, and a template of that font's name is never loaded, even down the chain.
#[test]
fn a_template_chain_stops_at_a_font_that_shares_a_templates_name() {
let s = ui();
load_str(
&s,
r#"<Ui>
<Font name="ChainFont" font="Fonts\ARIALN.TTF" virtual="true">
<FontHeight><AbsValue val="14"/></FontHeight>
</Font>
<FontString name="ChainFont" text="FROM_TEMPLATE" justifyV="TOP" virtual="true"/>
<FontString name="ChainMid" inherits="ChainFont" justifyH="RIGHT" virtual="true"/>
<Frame name="ChainHost">
<Layers><Layer>
<FontString name="ChainKid" inherits="ChainMid"/>
</Layer></Layers>
</Frame>
</Ui>"#,
);
let got = |expr: &str| {
s.eval::<String>(&format!("return tostring({expr})"))
.unwrap()
};
assert_eq!(
got("ChainKid:GetText()"),
"nil",
"the same-named template is no level"
);
assert_eq!(got("ChainKid:GetJustifyV()"), "MIDDLE");
assert_eq!(
got("ChainKid:GetJustifyH()"),
"RIGHT",
"the middle template is"
);
assert_eq!(got("ChainKid:GetFontObject() == ChainFont"), "true");
}
/// `0x78a152`-`0x78a18f`: SimpleHTML's `font=` looks in the one font table, which `CreateFont`
/// fills (`0x706077`), and links all four element fonts.
#[test]
fn a_simplehtml_font_finds_a_font_made_by_create_font() {
let s = ui();
let report = load_str(
&s,
r#"<Ui>
<Script>CreateFont("LevelHtmlFont"):SetFont("Fonts\\ARIALN.TTF", 15)</Script>
<SimpleHTML name="LevelHtml" font="LevelHtmlFont">
<Size><AbsDimension x="100" y="100"/></Size>
</SimpleHTML>
</Ui>"#,
);
assert!(report.warnings.is_empty(), "{:?}", report.warnings);
for elem in ["P", "H1", "H2", "H3"] {
let (path, height) = s
.eval::<(String, f32)>(&format!(
"local f, h = LevelHtml:GetFont('{elem}') return f, h"
))
.unwrap();
assert_eq!(
(path.as_str(), height),
(r"Fonts\ARIALN.TTF", 15.0),
"{elem}"
);
}
}
+59 -42
View File
@@ -13,7 +13,8 @@ use std::collections::HashSet;
use mlua::{Function, ObjectLike, Table, Value};
use crate::framexml::{self, Element, ParsedDocument, ScriptRef, TopLevel};
use crate::script::{JustifyH, JustifyV, Outline, UiScript};
use crate::justify;
use crate::script::{Outline, UiScript};
use crate::status;
mod backdrop;
@@ -557,13 +558,9 @@ impl Loader<'_> {
let model = self.model();
let templates = model.framexml_templates.borrow();
// A font object in an inherit chain is skipped, not warned as an unknown template.
let fonts = model.framexml_fonts.borrow();
let font_names: std::collections::HashSet<&str> =
fonts.keys().map(|k| k.as_str()).collect();
let is_font = |name: &str| model.fonts.id(name).is_some();
let mut warns = Vec::new();
let out = framexml::expand_known(el, &*templates, &font_names, &mut warns);
drop(font_names);
drop(fonts);
let out = framexml::expand_known(el, &*templates, &is_font, &mut warns);
drop(templates);
drop(model);
self.report.warnings.extend(warns);
@@ -583,6 +580,20 @@ impl Loader<'_> {
}
}
/// The nodes a FontString's `LoadXML` reads: [`Self::levels`], up to the first `inherits` that
/// names a font, which the string links instead of loading a template (`0x770f69`).
pub(super) fn fontstring_levels<'a>(&self, raw: &'a Element) -> Levels<'a> {
let model = self.model();
let inherited = model
.framexml_templates
.borrow()
.inherited_levels_until(raw, |name| model.fonts.id(name).is_some());
Levels {
inherited,
own: raw,
}
}
/// [`Loader::expand`] for a region, only when `inherits=` names a registered element template:
/// a FontString's `inherits=` usually names a font object, which passes through unwarned.
pub(super) fn expand_region(&mut self, el: &Element) -> Element {
@@ -604,14 +615,7 @@ impl Loader<'_> {
let Some(name) = el.name().map(str::to_string) else {
return;
};
let id = {
let mut model = self.model();
model
.framexml_fonts
.borrow_mut()
.insert(name.clone(), el.clone());
model.fonts.named(&name)
};
let id = self.model().fonts.named(&name);
self.load_font_node(el, id, &name);
// In 1.12 a named `<Font>` is also a Lua global, the object `SetFontObject` takes.
if let Err(e) = crate::script::font::publish(self.lua(), id, &name) {
@@ -625,10 +629,11 @@ impl Loader<'_> {
/// links it to that font (`0x783ce6`; a miss is logged, `0x87a51c`), a `font=` naming a font
/// links it there instead (`0x783d22`), and any other `font=` is a file that needs the node's
/// own first `<FontHeight>` above 0 and sets the flags word whole from `outline=` and
/// `monochrome=` (`0x783db1`-`0x783ea3`); without the height the load stops (`0x783dae`). Then
/// `spacing=` with `atof` (`0x783ee0`), `justifyV`, `justifyH` and each `<Color>` and `<Shadow>`
/// child, the last of each winning. Each attribute is a setter's write, clearing its inherit bit
/// (`0x783ea9`-`0x784100`) and pushing to what already follows the font.
/// `monochrome=` (`0x783db1`-`0x783ea3`) when it loads; without the height the load stops
/// (`0x783dae`). Then `spacing=` with `atof` (`0x783ee0`), `justifyV`, `justifyH` and each
/// `<Color>` and `<Shadow>` child, the last of each winning. Each attribute is a setter's write,
/// clearing its inherit bit (`0x783ea9`-`0x784100`) and pushing to what already follows the
/// font.
pub(super) fn load_font_node(
&mut self,
el: &Element,
@@ -660,12 +665,33 @@ impl Loader<'_> {
let outline = el.attr("outline").map(Outline::parse).unwrap_or_default();
// Any non-empty `monochrome=` sets the flag (`0x783e01`-`0x783e14`), even "false".
let monochrome = el.attr("monochrome").is_some_and(|v| !v.is_empty());
font::set(&mut self.model(), id, FontMask::FONT, |fo| {
fo.font = Some(path.to_string());
fo.height = Some(height);
fo.outline = outline;
fo.monochrome = monochrome;
});
// The font the node already holds (the path ignoring case, the height within 2⁻²²,
// the same flags) is kept as spelled and still clears the bit (`0x783e17`-`0x783e5d`
// → `0x783ea9`); any other loads first (`0x783e7c`). A file that fails is logged
// (`0x87a4c8`) and the node goes on to `spacing`, keeping what it follows.
let mut model = self.model();
let fo = &model.fonts.get(id).block;
let held = fo
.font
.as_deref()
.is_some_and(|p| p.eq_ignore_ascii_case(path))
&& fo
.height
.is_some_and(|h| (h - height).abs() < crate::script::SAME_FONT_HEIGHT)
&& (fo.outline, fo.monochrome) == (outline, monochrome);
if held || crate::script::face_loads(&model, path) {
font::set(&mut model, id, FontMask::FONT, |fo| {
if !held {
fo.font = Some(path.to_string());
fo.height = Some(height);
fo.outline = outline;
fo.monochrome = monochrome;
}
});
} else {
drop(model);
self.status_warning(format!("Font {name}: Unable to load font file {path}"));
}
}
None => {}
}
@@ -676,25 +702,16 @@ impl Loader<'_> {
fo.spacing = Some(sp)
});
}
// Each axis writes its bits of the one justify word (`0x783f90`, `0x783fd8`).
if let Some(j) = el.attr("justifyV").filter(|v| !v.is_empty()) {
let jv = match j.to_ascii_uppercase().as_str() {
"TOP" => JustifyV::Top,
"BOTTOM" => JustifyV::Bottom,
_ => JustifyV::Middle,
// Each axis matches its token as `0x6f1990` does and writes its own bits of the one justify
// word, none for the other axis's token (`0x783f75`-`0x783f7c`, `0x783fbd`-`0x783fc4`); a
// token that matches nothing is skipped and clears no bit (`0x783f6d`, `0x783fb5`).
for (attr, mask) in [("justifyV", justify::V_MASK), ("justifyH", justify::H_MASK)] {
let Some(bits) = el.attr(attr).and_then(justify::parse_bits) else {
continue;
};
font::set(&mut model, id, FontMask::JUSTIFY, |fo| {
fo.justify.get_or_insert_with(Default::default).set_v(jv)
});
}
if let Some(j) = el.attr("justifyH").filter(|v| !v.is_empty()) {
let jh = match j.to_ascii_uppercase().as_str() {
"LEFT" => JustifyH::Left,
"RIGHT" => JustifyH::Right,
_ => JustifyH::Center,
};
font::set(&mut model, id, FontMask::JUSTIFY, |fo| {
fo.justify.get_or_insert_with(Default::default).set_h(jh)
let word = fo.justify.get_or_insert_with(Default::default);
word.0 = justify::set_axis(word.0, mask, bits);
});
}
for child in &el.children {
+53 -49
View File
@@ -60,10 +60,11 @@ impl Loader<'_> {
/// One `<Layer>` region on `wrapper`, created on `level` and loaded: its name (`$parent`
/// expanded, published as a global, read from `raw` alone, `0x6f2751`), then its `LoadXML`
/// level by level ([`Loader::levels`]; `inherits=` may name a region template, in the frames'
/// one registry, `0x6ee500`), then the implicit creation anchor, run after the region's
/// LoadXML as the reference does (`0x7701c0`, `0x771480`); an anchored region is left alone.
/// `None` when the creation raised.
/// level by level ([`Loader::levels`], a FontString's up to a font,
/// [`Loader::fontstring_levels`]; `inherits=` may name a region template, in the frames' one
/// registry, `0x6ee500`), then the implicit creation anchor, run after the region's `LoadXML`
/// as the reference does (`0x7701c0`, `0x771480`); an anchored region is left alone. `None`
/// when the creation raised.
fn build_region(
&mut self,
raw: &Element,
@@ -73,7 +74,11 @@ impl Loader<'_> {
is_texture: bool,
dbg: &str,
) -> Option<Table> {
let levels = self.levels(raw);
let levels = if is_texture {
self.levels(raw)
} else {
self.fontstring_levels(raw)
};
let rname: Option<String> = raw
.name()
.map(|raw| framexml::resolve_name(raw, parent_name));
@@ -122,7 +127,7 @@ impl Loader<'_> {
if !region.tag.eq_ignore_ascii_case("FontString") {
continue;
}
let levels = self.levels(region);
let levels = self.fontstring_levels(region);
let rname: Option<String> = region
.name()
.map(|raw| framexml::resolve_name(raw, parent_name));
@@ -212,13 +217,14 @@ impl Loader<'_> {
}
/// One level of a `<FontString>`'s `LoadXML` (`0x770f40`), after its `inherits` level: an
/// `inherits` font object, the geometry, `hidden`, `text`, the wrap attributes, then, when the
/// `inherits` font object, the geometry, `hidden`, `text`, the wrap attributes (no `alpha`,
/// which only the frame loader reads, `0x769a10`), then, when the
/// string owns its font attributes ([`FontAttrs`], `0x7710db`), `font=`, `spacing`,
/// `justifyV`, `justifyH` and the `<Color>` and `<Shadow>` children, in that order. A `font=`
/// file needs this node's own first `<FontHeight>` above 0 (`0x77112f`-`0x771154`); without
/// one the level reports `0x878e10` and returns (`0x771191`), so nothing after the font is
/// read on it, whatever height a template gave. `with_text` is false for a Button's label,
/// whose text the button sets.
/// read on it, whatever height a template gave. A file that does not load only skips the
/// font. `with_text` is false for a Button's label, whose text the button sets.
pub(super) fn load_fontstring_level(
&mut self,
node: &Element,
@@ -230,13 +236,16 @@ impl Loader<'_> {
) {
let own = attrs == FontAttrs::Own;
// `inherits=` names a font object first (`0x770f69`), linked only when the string owns
// its font attributes (`0x770f72`), else a template, loaded as a level of its own. Any
// other name passes through and is reported: `SetFontObject("")` would clear the font
// object where a bad name warns.
// its font attributes (`0x770f72`), else a template, already loaded as a level of its own
// ([`Loader::fontstring_levels`]). A name that is neither is logged (`0x8786a8`,
// `0x770fa3`), whoever owns the font.
if let Some(name) = node.attr("inherits").filter(|n| !n.is_empty()) {
let template = self.model().framexml_templates.borrow().contains(name);
if own && (self.is_font_object(name) || !template) {
self.set_font_object(wrapper, "inherits", name, dbg);
if self.is_font_object(name) {
if own {
self.set_font_object(wrapper, "inherits", name, dbg);
}
} else if !self.model().framexml_templates.borrow().contains(name) {
self.status_warning(format!("Couldn't find inherited node: {name}"));
}
}
self.apply_geometry(node, wrapper, true, parent_name, dbg);
@@ -245,12 +254,6 @@ impl Loader<'_> {
Some(false) => self.call_region(wrapper, "Show", (), dbg),
None => {}
}
if let Some(a) = node
.attr("alpha")
.and_then(|v| v.trim().parse::<f32>().ok())
{
self.call_region(wrapper, "SetAlpha", a, dbg);
}
// An empty `text` is skipped (`0x77101b`), so a template's text stands. The string's own
// `SetText` (`0x77103a` → `0x771d80`), not Lua's, which raises on a string with no font
// (`0x79d7e5`); `LoadXML` sets the text before the font.
@@ -289,14 +292,17 @@ impl Loader<'_> {
.unwrap_or_default(),
node.attr("monochrome").is_some_and(|v| !v.is_empty()),
);
if let Err(e) = crate::script::apply_font_parts(
self.lua,
wrapper,
Some(path.to_string()),
Some(height),
Some(flags),
) {
self.report.fault(format!("{dbg}: region font attrs: {e}"));
// A file that fails to load is logged (`0x878dc8`, `0x771226`-`0x771251`) and the
// level goes on to `spacing`, the string keeping the font it had.
match crate::script::load_xml_font_file(self.lua, wrapper, path, height, flags) {
Ok(true) => {}
Ok(false) => {
let name = self.object_name(wrapper);
self.status_warning(format!(
"FontString {name}: Unable to load font file {path}"
));
}
Err(e) => self.report.fault(format!("{dbg}: region font attrs: {e}")),
}
}
None => {}
@@ -306,11 +312,17 @@ impl Loader<'_> {
if let Some(sp) = node.attr("spacing").filter(|v| !v.is_empty()) {
self.call_region(wrapper, "SetSpacing", crate::framexml::atof(sp), dbg);
}
if let Some(j) = node.attr("justifyV").filter(|v| !v.is_empty()) {
self.call_region(wrapper, "SetJustifyV", j.to_string(), dbg);
}
if let Some(j) = node.attr("justifyH").filter(|v| !v.is_empty()) {
self.call_region(wrapper, "SetJustifyH", j.to_string(), dbg);
// A justify token is matched first (`0x6f1990`) and one that matches nothing is skipped
// (`0x7712c3`, `0x771327`). A match writes its axis's bits of the justify word inline, none
// for the other axis's token, which zeroes the axis (V `0x7712e1`-`0x7712e7`, H
// `0x771345`-`0x77134b`), and clears the bits the Lua setter clears, so the setter stands in.
for (attr, setter) in [("justifyV", "SetJustifyV"), ("justifyH", "SetJustifyH")] {
if let Some(j) = node
.attr(attr)
.filter(|j| crate::justify::parse_bits(j).is_some())
{
self.call_region(wrapper, setter, j.to_string(), dbg);
}
}
// Each `<Color>` is the text colour (`0x77f750`) and each `<Shadow>` the shadow
// (`0x7722a0`), both local to the string, so they outlast the font object's.
@@ -342,7 +354,8 @@ impl Loader<'_> {
}
/// One level of a `<Texture>`'s `LoadXML` (`0x76fe20`), after its `inherits` level: the
/// geometry, `hidden`, each child in order, then `file=` and `alphaMode`. A `<TexCoords>` sets
/// geometry, `hidden`, each child in order, then `file=` and `alphaMode`, and no `alpha`, which
/// only the frame loader reads (`0x769a10`). A `<TexCoords>` sets
/// all eight coordinates from its own edges over 0, 1, 0, 1, so the last one applied wins whole
/// (`0x76fef5`, `0x76ffe8`), and any edge outside [0, 1] sets the level's wrap flag, which the
/// file load takes (`0x770071`, `0x77012d`); a later `SetTexCoord` leaves it, and `SetTexture`
@@ -362,12 +375,6 @@ impl Loader<'_> {
Some(false) => self.call_region(wrapper, "Show", (), dbg),
None => {}
}
if let Some(a) = node
.attr("alpha")
.and_then(|v| v.trim().parse::<f32>().ok())
{
self.call_region(wrapper, "SetAlpha", a, dbg);
}
let mut wrap = false;
for child in &node.children {
if child.tag.eq_ignore_ascii_case("TexCoords") {
@@ -449,14 +456,12 @@ impl Loader<'_> {
pub(super) fn font_object_through_templates(&self, inherits: &str) -> Option<String> {
const MAX_HOPS: usize = 8;
let model = self.model();
let fonts = model.framexml_fonts.borrow();
let templates = model.framexml_templates.borrow();
// One name, not a comma list: 1.12's lookup has no splitter.
for entry in [inherits] {
let mut name = entry.to_string();
for _ in 0..MAX_HOPS {
if fonts.contains_key(&name) || fonts.keys().any(|k| k.eq_ignore_ascii_case(&name))
{
if model.fonts.id(&name).is_some() {
return Some(name);
}
let Some(next) = templates
@@ -472,12 +477,11 @@ impl Loader<'_> {
None
}
/// Whether `name` is a registered font object: the reference's flat, case-insensitive lookup
/// (`0x783870`, `SStrCmpI`), with no template walk.
/// Whether `name` is a named font object, declared by `<Font>` or made by `CreateFont`: the
/// reference's one font table (`0x783870`, which `CreateFont` fills too, `0x706077`), looked
/// up flat and ignoring case, with no template walk.
pub(super) fn is_font_object(&self, name: &str) -> bool {
let model = self.model();
let fonts = model.framexml_fonts.borrow();
fonts.contains_key(name) || fonts.keys().any(|k| k.eq_ignore_ascii_case(name))
self.model().fonts.id(name).is_some()
}
}
+6 -4
View File
@@ -2396,8 +2396,9 @@ mod loader_tests {
/// state-texture element builds a new region through the `<Layers>` adder (`0x6f26f0`) that the
/// slot store installs, destroying the one it displaces (`0x778fd0` via `0x77900a`, the
/// highlight's `0x779110`, the checked pair's `0x785330`/`0x785440`). So an instance's element
/// keeps nothing of the template's: the fresh region's TexCoords, alpha and BLEND (`0x76fc40`;
/// the highlight keeps its own, `0x7789a4`), and `SetAllPoints` with no anchors (`0x7701c0`).
/// keeps nothing of the template's: the fresh region's TexCoords and BLEND (`0x76fc40`; the
/// highlight keeps its own, `0x7789a4`), and `SetAllPoints` with no anchors (`0x7701c0`). No
/// texture level reads `alpha` (`0x76fe20`), so every alpha stays 1.
#[test]
fn an_instance_state_texture_replaces_the_templates() {
const TAGS: [(&str, &str); 6] = [
@@ -2489,7 +2490,8 @@ mod loader_tests {
"one region per slot, none of the template's left over"
);
// An instance element's own size, anchors and alpha lay the fresh region out.
// An instance element's own size and anchors lay the fresh region out; its `alpha=` is not
// read.
let laid: (i64, String, f32, f32, f32, Vec<f32>) = s
.eval(
r#"local t = LaidOutInst:GetNormalTexture()
@@ -2504,7 +2506,7 @@ mod loader_tests {
"CENTER".to_string(),
20.0,
16.0,
63.0 / 255.0,
1.0,
vec![0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]
)
);
+1 -1
View File
@@ -158,7 +158,7 @@ impl Loader<'_> {
// `SetText` creates the label even with no text, so its layout lands on a real region;
// `text=` is each level's, a global-string key (`0x703bf0`), an empty one skipped
// (`0x77101b`).
let label_levels = self.levels(bt);
let label_levels = self.fontstring_levels(bt);
let mut label = String::new();
for level in &label_levels {
if let Some(raw) = level.attr("text").filter(|t| !t.is_empty()) {
+5 -1
View File
@@ -891,7 +891,11 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
Some(p) => Value::String(lua.create_string(&p)?),
None => Value::Nil,
};
Ok((path, block.height.unwrap_or(0.0), block.outline.as_str()))
Ok((
path,
block.height.unwrap_or(0.0),
block.outline.flags_text(block.monochrome),
))
})?,
)?;
+28 -14
View File
@@ -608,7 +608,11 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
Some(p) => Value::String(lua.create_string(&p)?),
None => Value::Nil,
};
Ok((path, fo.height.unwrap_or(0.0), fo.outline.as_str()))
Ok((
path,
fo.height.unwrap_or(0.0),
fo.outline.flags_text(fo.monochrome),
))
})?,
)?;
@@ -664,6 +668,8 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
)?;
// ── shadow ──────────────────────────────────────────────────────────────────────────────
// An unset shadow is the constructor's transparent black (`0x783a72`), which `GetShadowColor`
// reads (`0x79f910`) and `SetShadowOffset` keeps (`0x79fa4a`-`0x79fa92`).
m.set(
"SetShadowColor",
lua.create_function(
@@ -682,7 +688,7 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
lua.create_function(|lua, this: Table| {
let c = read(lua, &this)?
.shadow
.map_or(crate::color::Rgba8::BLACK, |s| s.color);
.map_or(crate::color::Rgba8::TRANSPARENT, |s| s.color);
Ok(super::object::colour_values(c))
})?,
)?;
@@ -690,7 +696,9 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
"SetShadowOffset",
lua.create_function(|lua, (this, x, y): (Table, f32, f32)| {
edit(lua, &this, FontMask::SHADOW, |fo| {
let color = fo.shadow.map_or(crate::color::Rgba8::BLACK, |s| s.color);
let color = fo
.shadow
.map_or(crate::color::Rgba8::TRANSPARENT, |s| s.color);
fo.shadow = Some(FontShadow {
offset: [x, y],
color,
@@ -724,19 +732,23 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
// ── justification ───────────────────────────────────────────────────────────────────────
// Parsing is [`crate::justify`]'s, shared with the FontString pair: `SStrCmpI` over the whole
// string, no trim. `None` means the font does not specify the axis (inheritance), not a
// cleared axis; a fresh object reads CENTER/MIDDLE, the constructor default `0x212`.
// cleared axis; a fresh object reads CENTER/MIDDLE, the constructor default `0x212`. The other
// axis's token is a write of no bits, zeroing the axis, with the bit cleared and the push
// (`0x79fc5d`-`0x79fc84`).
m.set(
"SetJustifyH",
lua.create_function(|lua, (this, j): (Table, Value)| {
id_of(lua, &this)?;
let parsed = binding_abi::optional_string(lua, &j).map(|j| justify::parse_h(&j));
let jh = match parsed {
Some(justify::Set::To(jh)) => jh,
Some(justify::Set::Clears) => return Ok(()),
let parsed = match binding_abi::optional_string(lua, &j).map(|j| justify::parse_h(&j)) {
Some(p) if p != justify::Set::NoMatch => p,
_ => return Err(justify::usage_h(&binding_abi::name_of(lua, &this))),
};
edit(lua, &this, FontMask::JUSTIFY, |fo| {
fo.justify.get_or_insert_with(Default::default).set_h(jh)
let word = fo.justify.get_or_insert_with(Default::default);
match parsed {
justify::Set::To(jh) => word.set_h(jh),
_ => word.clear_h(),
}
})
})?,
)?;
@@ -750,14 +762,16 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
"SetJustifyV",
lua.create_function(|lua, (this, j): (Table, Value)| {
id_of(lua, &this)?;
let parsed = binding_abi::optional_string(lua, &j).map(|j| justify::parse_v(&j));
let jv = match parsed {
Some(justify::Set::To(jv)) => jv,
Some(justify::Set::Clears) => return Ok(()),
let parsed = match binding_abi::optional_string(lua, &j).map(|j| justify::parse_v(&j)) {
Some(p) if p != justify::Set::NoMatch => p,
_ => return Err(justify::usage_v(&binding_abi::name_of(lua, &this))),
};
edit(lua, &this, FontMask::JUSTIFY, |fo| {
fo.justify.get_or_insert_with(Default::default).set_v(jv)
let word = fo.justify.get_or_insert_with(Default::default);
match parsed {
justify::Set::To(jv) => word.set_v(jv),
_ => word.clear_v(),
}
})
})?,
)?;
+23 -7
View File
@@ -128,6 +128,20 @@ pub(super) enum FontKind {
Instance,
}
impl FontKind {
/// The shadow colour an unset shadow reads: a FontString's own default is opaque black
/// (`0x770da1`), a font instance's the transparent black `CSimpleFont`'s constructor writes
/// (`0x783a72`; the EditBox's `0x779ba8`, the message frames' `0x785700` and `0x78778f`). The
/// EditBox's font and its text string share one record here, so each answers its own default
/// until a set, which the reference pushes to the string too.
fn unset_shadow(self) -> crate::color::Rgba8 {
match self {
FontKind::FontString => crate::color::Rgba8::BLACK,
FontKind::Instance => crate::color::Rgba8::TRANSPARENT,
}
}
}
/// A `SetFont` load's outcome.
#[derive(Clone, Copy, PartialEq, Eq)]
enum Load {
@@ -149,11 +163,15 @@ impl Load {
/// Whether the font load (`0x44d040`, the factory `0x5c1ae0`) finds `path`: never for an empty one
/// (`0x44d059`), else the host's probe, as only the store knows the files; with no probe, any
/// non-empty path loads.
pub(super) fn face_loads(model: &Model, path: &str) -> bool {
/// non-empty path loads. The XML font legs ask it too (`0x771214`, `0x783e7c`).
pub(crate) fn face_loads(model: &Model, path: &str) -> bool {
!path.is_empty() && model.font_probe.as_ref().is_none_or(|probe| probe(path))
}
/// The tolerance both XML font legs read a held height as unchanged within, 2⁻²² (`0x8029d4`, at
/// the FontString's `0x77152a` and the Font's `0x783e4d`).
pub(crate) const SAME_FONT_HEIGHT: f32 = 1.0 / 4_194_304.0;
/// The shared path's verdict (`0x79f210`): no load for a height of 0 or less
/// (`0x79f2f1`-`0x79f2ff`), else [`face_loads`]. A failure writes nothing (`0x79f30f` →
/// `0x79f361`). Borrows the model, so a caller asks before it holds it.
@@ -298,7 +316,7 @@ pub(super) fn install(
None => Value::Nil,
};
let height = d.and_then(|d| d.font_height).unwrap_or(0.0);
let flags = d.map(|d| d.outline).unwrap_or_default().as_str();
let flags = d.map_or("", |d| d.outline.flags_text(d.monochrome));
Ok((path, height, flags))
})?,
)?;
@@ -374,7 +392,7 @@ pub(super) fn install(
.region_data
.get(&rh)
.and_then(|d| d.font_shadow)
.map_or(crate::color::Rgba8::BLACK, |s| s.color);
.map_or(kind.unset_shadow(), |s| s.color);
Ok(super::object::colour_values(c))
})?,
)?;
@@ -385,9 +403,7 @@ pub(super) fn install(
let rh = resolve(lua, &this)?;
let mut model = lua.app_data_mut::<Model>().expect("model");
let d = model.region_data.entry(rh).or_default();
let color = d
.font_shadow
.map_or(crate::color::Rgba8::BLACK, |s| s.color);
let color = d.font_shadow.map_or(kind.unset_shadow(), |s| s.color);
d.font_shadow = Some(FontShadow {
offset: [x, y],
color,
+3 -2
View File
@@ -283,6 +283,7 @@ pub use video_pairs::VIDEO_PAIR_CVARS;
pub use worldmap_arrow::ARROW_MODEL;
pub(crate) use button::{refresh_label_lua, state_font_lua, LabelFont};
pub(crate) use font_block::{face_loads, SAME_FONT_HEIGHT};
pub use inspect::{InspectView, UnitReach};
pub use item_stats::{item_usable, ItemSetView, ItemTemplateView, PlayerReqState};
pub use item_text::ItemTextState;
@@ -310,8 +311,8 @@ pub use quest::{
};
pub use quest_log::{QuestObjectiveView, QuestRecordView, QuestSlotView, QUEST_LOG_SLOTS};
pub(crate) use region::{
apply_font_parts, apply_texture_name, apply_wrap_attrs, implicit_creation_anchor_lua,
install_loaded_texture, load_blend_mode, load_texture_file, load_texture_name,
apply_texture_name, apply_wrap_attrs, implicit_creation_anchor_lua, install_loaded_texture,
load_blend_mode, load_texture_file, load_texture_name, load_xml_font_file,
texture_name_verdict, FileLoad,
};
pub use reputation::{FactionEntry, ReputationSend, ReputationState};
-4
View File
@@ -165,9 +165,6 @@ pub(crate) struct Model {
pub(crate) framexml_debug: std::cell::Cell<i32>,
/// The loads' records for `Logs\FrameXML.log` and the drains the host has yet to write.
pub(crate) load_log: crate::status::LoadLog,
/// The FrameXML font registry, a namespace apart from templates (a font inherits only a font).
pub(crate) framexml_fonts:
std::cell::RefCell<std::collections::HashMap<String, crate::framexml::Element>>,
pub(crate) arena: WidgetArena,
/// Per-frame anchors, size and scale; every live frame has one from creation on.
pub(crate) layout_inputs: HashMap<FrameHandle, LayoutInput>,
@@ -1378,7 +1375,6 @@ impl Model {
exec_context: Default::default(),
framexml_debug: Default::default(),
load_log: Default::default(),
framexml_fonts: Default::default(),
arena: WidgetArena::new(),
layout_inputs: HashMap::new(),
solver: LayoutSolver::new(),
+27 -26
View File
@@ -285,41 +285,42 @@ pub(super) fn clear_texture(model: &mut Model, rh: RegionHandle) {
model.note_art(rh);
}
/// Apply the font parts an XML element supplies (`font=`, `<FontHeight>`, and the flags word of
/// `outline=` and `monochrome=`), any of which may be absent. Not the `SetFont` binding: the
/// reference applies XML fonts in `LoadXML`, and its `SetFont` requires a path and a height
/// (`0x87c69c`). Each part is an explicit set, so it survives a change to the inherited font
/// object; an empty `font=` keeps the inherited face.
pub(crate) fn apply_font_parts(
/// A FontString's XML font file (`font=`, its `<FontHeight>` and the flags word of `outline=` and
/// `monochrome=`) through the string's own `SetFont` (`0x771214` → `0x7714f0`), not the Lua
/// binding. The font it already holds, the path matched ignoring case, the height within 2⁻²² and
/// the same flags, is a success that writes nothing (`0x771502`-`0x771541`); any other goes to the font
/// load (`0x44d040`), whose failure writes nothing (`0x771575`), answered `false`. A success is an
/// explicit set that clears the font bit (`0x77121d`), so it outlasts the followed font object's.
pub(crate) fn load_xml_font_file(
lua: &Lua,
this: &Table,
path: Option<String>,
height: Option<f32>,
flags: Option<(super::Outline, bool)>,
) -> mlua::Result<()> {
path: &str,
height: f32,
(outline, monochrome): (super::Outline, bool),
) -> mlua::Result<bool> {
let rh = region_handle_of(lua, this)?;
let mut model = lua.app_data_mut::<Model>().expect("model");
let held = model.region_data.get(&rh).is_some_and(|d| {
d.font_path
.as_deref()
.is_some_and(|p| p.eq_ignore_ascii_case(path))
&& d.font_height
.is_some_and(|h| (h - height).abs() < super::SAME_FONT_HEIGHT)
&& (d.outline, d.monochrome) == (outline, monochrome)
});
if !held && !super::face_loads(&model, path) {
return Ok(false);
}
let d = model.region_data.entry(rh).or_default();
let mut any = false;
if let Some(p) = path.filter(|p| !p.is_empty()) {
d.font_path = Some(p);
any = true;
}
if let Some(h) = height {
d.font_height = Some(h);
any = true;
}
if let Some((outline, monochrome)) = flags {
if !held {
d.font_path = Some(path.to_string());
d.font_height = Some(height);
d.outline = outline;
d.monochrome = monochrome;
any = true;
}
// A loaded file clears the font bit (`0x77121d`), the face, height and flags being one group.
if any {
d.font_mask.clear(super::FontMask::FONT);
}
d.font_mask.clear(super::FontMask::FONT);
model.touch_measure(rh);
Ok(())
Ok(true)
}
/// A FontString's XML `nonspacewrap` and `maxLines` (`0x77103f`-`0x7710cd`), each written only when
@@ -575,7 +575,7 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
Some(path) => Value::String(lua.create_string(&path)?),
None => Value::Nil,
};
Ok((path, p.font_height, p.outline.as_str()))
Ok((path, p.font_height, p.outline.flags_text(false)))
})?,
)?;
@@ -623,7 +623,7 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
let elem = take_element(&mut rest);
let c = read_font(lua, &this, elem)?
.shadow
.map_or(crate::color::Rgba8::BLACK, |s| s.color);
.map_or(crate::color::Rgba8::TRANSPARENT, |s| s.color);
Ok(crate::script::object::colour_values(c))
})?,
)?;
@@ -635,7 +635,9 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
let x = f32::from_lua(arg(&rest, 0), lua)?;
let y = f32::from_lua(arg(&rest, 1), lua)?;
edit_font(lua, &this, elem, |ef| {
let color = ef.shadow.map_or(crate::color::Rgba8::BLACK, |s| s.color);
let color = ef
.shadow
.map_or(crate::color::Rgba8::TRANSPARENT, |s| s.color);
ef.shadow = Some(FontShadow {
offset: [x, y],
color,
@@ -730,13 +730,41 @@ fn both_tables_speak_one_justify_law() {
"{obj}:SetJustifyH must not trim its argument"
);
// A cross-axis token is in the table and raises nothing. The reference then clears the
// axis; the FontString does too, the `<Font>` object leaves it as it was.
// A cross-axis token is in the table and raises nothing: it zeroes the axis on both
// tables (`0x79fc5d`-`0x79fc75`), which then reads "UNKNOWN".
s.run(&format!("{obj}:SetJustifyH('TOP')")).unwrap();
s.run(&format!("{obj}:SetJustifyV('LEFT')")).unwrap();
assert_eq!(
s.eval::<String>(&format!(
"return {obj}:GetJustifyH() .. ' ' .. {obj}:GetJustifyV()"
))
.unwrap(),
"UNKNOWN UNKNOWN",
"{obj}"
);
}
}
/// `SetJustifyH 0x79fc20` with the other axis's token zeroes the axis, clears the font's own bit
/// and pushes (`0x79fc7c`, `0x79fc84`): a following string reads the cleared axis, and an inheriting
/// font that did it no longer follows its parent's justify.
#[test]
fn a_fonts_cross_axis_justify_clears_the_axis_and_pushes() {
let s = script();
s.run(
"F = CreateFont('CrossAxisF') F:SetFont('Fonts\\FRIZQT__.TTF', 12) F:SetJustifyH('LEFT')
host = CreateFrame('Frame') fs = host:CreateFontString() fs:SetFontObject(F)
A = CreateFont('CrossAxisA') B = CreateFont('CrossAxisB') B:SetFontObject(A)
B:SetJustifyH('TOP') A:SetJustifyH('RIGHT')
F:SetJustifyH('TOP')",
)
.unwrap();
let got = |e: &str| s.eval::<String>(&format!("return {e}")).unwrap();
assert_eq!(got("F:GetJustifyH()"), "UNKNOWN");
assert_eq!(got("fs:GetJustifyH()"), "UNKNOWN", "pushed to the string");
assert_eq!(got("B:GetJustifyH()"), "UNKNOWN", "B no longer follows A");
}
/// `SetFont` is one routine (`0x79f210`) behind three entries, Font `0x7a0270`, FontString
/// `0x79d4f0` and EditBox `0x797210`; a bad argument raises its usage string (`0x87c69c`).
#[test]
@@ -1160,3 +1188,49 @@ fn set_font_reads_and_clears_monochrome() {
assert_eq!(flags_of(&s, "a"), (Outline::Normal, false));
assert_eq!(flags_of(&s, "b"), (Outline::Normal, true));
}
/// `CSimpleFont`'s constructor zeroes the shadow colour (`0x783a72`): a `CreateFont` font, an
/// EditBox's and a message frame's read transparent black, and `SetShadowOffset` keeps it, so a
/// following string takes an invisible shadow. Only a FontString's own default is opaque
/// (`0x770da1`).
#[test]
fn a_fonts_unset_shadow_is_transparent() {
let s = script();
s.run(
"F = CreateFont('UnsetShadowF')
host = CreateFrame('Frame') fs = host:CreateFontString() plain = host:CreateFontString()
eb = CreateFrame('EditBox') mf = CreateFrame('MessageFrame')
smf = CreateFrame('ScrollingMessageFrame') html = CreateFrame('SimpleHTML')",
)
.unwrap();
let alpha = |obj: &str| {
s.eval::<Vec<f32>>(&format!("return {{ {obj}:GetShadowColor() }}"))
.unwrap()
};
for obj in ["F", "eb", "mf", "smf", "html"] {
assert_eq!(alpha(obj), vec![0.0, 0.0, 0.0, 0.0], "{obj}");
}
// SimpleHTML's four element fonts come from the same constructor (`0x789e7c`), and
// `SetShadowOffset` keeps their colour.
s.run("html:SetShadowOffset('H1', 1, -1)").unwrap();
for elem in ["P", "H1", "H2", "H3"] {
let c = s
.eval::<Vec<f32>>(&format!("return {{ html:GetShadowColor('{elem}') }}"))
.unwrap();
assert_eq!(c, vec![0.0, 0.0, 0.0, 0.0], "SimpleHTML {elem}");
}
assert_eq!(
alpha("plain")[3],
crate::color::quant::read32(1.0),
"a FontString's own shadow"
);
s.run("F:SetShadowOffset(1, -1) fs:SetFontObject(F) eb:SetShadowOffset(1, -1)")
.unwrap();
assert_eq!(alpha("F"), vec![0.0, 0.0, 0.0, 0.0]);
assert_eq!(
alpha("fs"),
vec![0.0, 0.0, 0.0, 0.0],
"the follower's shadow"
);
assert_eq!(alpha("eb"), vec![0.0, 0.0, 0.0, 0.0]);
}
@@ -491,7 +491,7 @@ fn button_set_font_returns_nothing_and_is_a_no_op_without_a_label() {
assert_eq!(
s.eval::<String>("local _, _, flags = SFBare:GetFont() return flags")
.unwrap(),
"THICKOUTLINE"
"OUTLINE, THICKOUTLINE"
);
// Both arguments are required (`lua_isstring` + `lua_isnumber`, else the usage error).
assert!(s.run(r#"SFBare:SetFont("Fonts\\SKURRI.TTF")"#).is_err());
@@ -47,7 +47,8 @@ fn set_font_reads_flags_only_from_a_string_or_a_number() {
for &(obj, kind) in KINDS {
for (arg, want) in [
("\"OUTLINE\"", "OUTLINE"),
("\"THICKOUTLINE\"", "THICKOUTLINE"),
("\"THICKOUTLINE\"", "OUTLINE, THICKOUTLINE"),
("\"THICK\"", ""),
("false", ""),
("nil", ""),
("7", ""),
@@ -221,3 +222,61 @@ fn a_fontstrings_refused_load_changes_nothing_and_a_zero_height_frees_its_font()
(None, 0.0, String::new())
);
}
/// `0x6f1a90` ORs in every name of `0x811b10` found as a case-insensitive substring, so `THICK`
/// alone sets nothing, and `GetFont` (`0x6f1ad0`) joins every set bit's name in table order with
/// `", "`. SimpleHTML's element fonts hold no MONOCHROME yet, so it sits out the monochrome rows.
#[test]
fn get_font_joins_every_set_flag_in_table_order() {
let s = receivers();
for &(obj, kind) in KINDS.iter().filter(|(_, kind)| *kind != "SimpleHTML") {
for (arg, want) in [
("MONOCHROME", "MONOCHROME"),
("OUTLINE,MONOCHROME", "OUTLINE, MONOCHROME"),
(
"monochrome thickoutline",
"OUTLINE, THICKOUTLINE, MONOCHROME",
),
("THICK", ""),
] {
s.run(&format!(
"{obj}:SetFont(\"Fonts\\\\FRIZQT__.TTF\", 13, \"{arg}\")"
))
.unwrap();
assert_eq!(flags_of(&s, obj), want, "{kind}: {arg}");
}
}
}
/// The XML legs set the word whole (`0x771194`-`0x771204`, `0x783db1`-`0x783e14`): `THICK` is
/// 5, both outline bits, and a non-empty `monochrome=` adds 2.
#[test]
fn an_xml_thick_monochrome_font_reads_back_every_flag() {
let s = script();
let doc = crate::framexml::parse(
r#"<Ui>
<Font name="XmlFlagsFont" font="Fonts\FRIZQT__.TTF" outline="THICK" monochrome="1"
virtual="true">
<FontHeight><AbsValue val="12"/></FontHeight>
</Font>
<Frame name="XmlFlagsHost">
<Layers><Layer>
<FontString name="XmlFlagsString" font="Fonts\FRIZQT__.TTF" outline="THICK"
monochrome="1">
<FontHeight><AbsValue val="12"/></FontHeight>
</FontString>
</Layer></Layers>
</Frame>
</Ui>"#,
)
.unwrap();
let report = crate::loader::load(&s, &doc, &|_| None);
assert!(report.errors.is_empty(), "{:?}", report.errors);
for obj in ["XmlFlagsFont", "XmlFlagsString"] {
assert_eq!(
flags_of(&s, obj),
"OUTLINE, THICKOUTLINE, MONOCHROME",
"{obj}"
);
}
}
+16 -10
View File
@@ -264,12 +264,13 @@ impl Outline {
}
}
/// Parse a Lua `SetFont` flags string, shared by every `SetFont` (`0x79f210`) and matched by
/// substring against `{0x1 OUTLINE, 0x4 THICKOUTLINE, 0x2 MONOCHROME}` (`0x811b10`): THICK
/// first, since `THICKOUTLINE` contains `OUTLINE`. MONOCHROME is [`monochrome_flag`]'s.
/// Parse a Lua `SetFont` flags string, shared by every `SetFont` (`0x79f210`): `0x6f1a90` ORs in
/// each name of `{0x1 OUTLINE, 0x4 THICKOUTLINE, 0x2 MONOCHROME}` (`0x811b10`) found as a
/// case-insensitive substring (`0x64b540`), so `THICKOUTLINE` sets 0x1 and 0x4 and `THICK`
/// alone sets nothing. MONOCHROME is [`monochrome_flag`]'s.
pub fn flags(s: &str) -> Outline {
let s = s.to_ascii_uppercase();
if s.contains("THICK") {
if s.contains("THICKOUTLINE") {
Outline::Thick
} else if s.contains("OUTLINE") {
Outline::Normal
@@ -278,12 +279,17 @@ impl Outline {
}
}
/// The flags token `GetFont` answers.
pub fn as_str(self) -> &'static str {
match self {
Outline::None => "",
Outline::Normal => "OUTLINE",
Outline::Thick => "THICKOUTLINE",
/// The flags text `GetFont` answers (`0x6f1ad0`): the name of every set bit in `0x811b10`'s
/// order, joined by `", "` (`0x84480c`). A thick outline holds both outline bits, as both
/// readers set it (`0x6f1a90`, the XML `THICK`'s 5 at `0x7711e3`).
pub fn flags_text(self, monochrome: bool) -> &'static str {
match (self, monochrome) {
(Outline::None, false) => "",
(Outline::Normal, false) => "OUTLINE",
(Outline::Thick, false) => "OUTLINE, THICKOUTLINE",
(Outline::None, true) => "MONOCHROME",
(Outline::Normal, true) => "OUTLINE, MONOCHROME",
(Outline::Thick, true) => "OUTLINE, THICKOUTLINE, MONOCHROME",
}
}
}
+6 -6
View File
@@ -643,9 +643,9 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
#### loader
- A `<Script file=>` value with a separator joins the including document's directory, like a bare name. ([`src/loader/mod.rs:425`](../crates/benilla-ui/src/loader/mod.rs#L425))
- Padded to the block's line, so a raise reports a line a reader can find in the file; the reference counts from the body's first line. ([`src/loader/mod.rs:451`](../crates/benilla-ui/src/loader/mod.rs#L451))
- A link that would close a loop is refused and reported; the reference's XML legs (`0x783ce6`, `0x783d22`) check nothing, and the next push down such a loop would never end. ([`src/loader/mod.rs:711`](../crates/benilla-ui/src/loader/mod.rs#L711))
- A `<Script file=>` value with a separator joins the including document's directory, like a bare name. ([`src/loader/mod.rs:426`](../crates/benilla-ui/src/loader/mod.rs#L426))
- Padded to the block's line, so a raise reports a line a reader can find in the file; the reference counts from the body's first line. ([`src/loader/mod.rs:452`](../crates/benilla-ui/src/loader/mod.rs#L452))
- A link that would close a loop is refused and reported; the reference's XML legs (`0x783ce6`, `0x783d22`) check nothing, and the next push down such a loop would never end. ([`src/loader/mod.rs:728`](../crates/benilla-ui/src/loader/mod.rs#L728))
- `<HighlightColor>` and `<DisabledColor>` colour their own fonts; 1.12.1 sends both to the normal colour setter (`0x778aa4`, `0x778ada` call `0x778e20`), so neither could reach its state. ([`src/loader/widgets.rs:250`](../crates/benilla-ui/src/loader/widgets.rs#L250))
#### markup
@@ -670,7 +670,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
- The reference (`0x4abdc0`) admits 9 and reads one dword past its block; we answer 0 because that read is out of bounds. ([`src/script/battlefield_score.rs:292`](../crates/benilla-ui/src/script/battlefield_score.rs#L292))
- `pow(10, n)` is the platform's, where the reference's (`0x73f940`, `fyl2x`) rounds its extended-precision steps at 53 bits, so a power or a fraction term can differ in the last place. ([`src/script/binding_abi.rs:265`](../crates/benilla-ui/src/script/binding_abi.rs#L265))
- The disabled-checked leg (`0x785380`) tests and reloads the checked slot (`[+0x4e0]`, `0x785388`/`0x7853a5`), a copy of the checked leg's (`0x785270`), so in 1.12.1 a check box with a checked texture repaints that one and never gets its disabled-checked texture from a path. benilla tests and reloads the slot the method names. ([`src/script/button.rs:581`](../crates/benilla-ui/src/script/button.rs#L581))
- The slot is read before the handler, where the reference reads it after (`[esi+0x4dc]`), because reading first keeps the borrow simple and no stock handler re-slots its row. ([`src/script/button.rs:1157`](../crates/benilla-ui/src/script/button.rs#L1157))
- The slot is read before the handler, where the reference reads it after (`[esi+0x4dc]`), because reading first keeps the borrow simple and no stock handler re-slots its row. ([`src/script/button.rs:1161`](../crates/benilla-ui/src/script/button.rs#L1161))
- The reference composes the Shortcut with `GetRealZoneText` alone (`0x49efe8`), so in a capital `/leave Trade` sends `Trade - Stormwind City` and leaves nothing; ours uses the join's city-aware name, because the reference's form cannot leave the channel it joined. ([`src/script/channel.rs:480`](../crates/benilla-ui/src/script/channel.rs#L480))
- The frame's bottom-left origin is snapped onto the device grid so the border art blits 1:1; the reference ceils the anchor point itself onto it (`0x7666a0`, `0x766750`). ([`src/script/chat_bubble.rs:476`](../crates/benilla-ui/src/script/chat_bubble.rs#L476))
- No truncation at 255 characters (`0x49f604`), because vmangos refuses a longer line itself (`Chat.cpp:2177`): it is dropped where the reference sends its first 255. ([`src/script/chat_send.rs:23`](../crates/benilla-ui/src/script/chat_send.rs#L23))
@@ -713,7 +713,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
- An addon file whose first binding has no header opens a `HEADER_<addon>` row, where the reference files those rows under the previous file's last header, because under a foreign header the player could not find them. ([`src/script/keybind.rs:297`](../crates/benilla-ui/src/script/keybind.rs#L297))
- The handle's value is the address of a `CGxTex` (`SMemAlloc(0x54)`, `0x594a96`), which benilla cannot reproduce; each texture ranks instead by a creation stamp, one global sequence number taken when its cache key is first created and taken anew once its last region has let go of it (`super::texel::Texels`). ([`src/script/layer_batch.rs:9`](../crates/benilla-ui/src/script/layer_batch.rs#L9))
- A listing that finds no icon stays empty, to be listed again on the next ask, where the reference's dedup then reads below its null list (`0x4f0134`-`0x4f0145`) and faults. ([`src/script/macros.rs:286`](../crates/benilla-ui/src/script/macros.rs#L286))
- The client's Lua has no such bound, as nothing sets a hook (`lua_sethook`, `0x6fba40`, has no caller and no pointer to it), so a load that never ends hangs it. ([`src/script/mod.rs:800`](../crates/benilla-ui/src/script/mod.rs#L800))
- The client's Lua has no such bound, as nothing sets a hook (`lua_sethook`, `0x6fba40`, has no caller and no pointer to it), so a load that never ends hangs it. ([`src/script/mod.rs:801`](../crates/benilla-ui/src/script/mod.rs#L801))
- A path that does not resolve is stored, where the reference raises `Invalid model file: %s` (`0x878b44`), because the file loads asynchronously here and the call cannot know yet. ([`src/script/modelframe.rs:316`](../crates/benilla-ui/src/script/modelframe.rs#L316))
- Benilla plays no pre-rendered movie (#968), so `StartMovie` answers nil, the reference's "could not start" (`0x78d861`), which the stock `MovieFrame_PlayMovie` answers by hiding the frame and so by returning to the login screen. ([`src/script/movieframe.rs:4`](../crates/benilla-ui/src/script/movieframe.rs#L4))
- The reference's free list is FIFO; either keeps every index stable, all an addon can observe. ([`src/script/nameplate.rs:431`](../crates/benilla-ui/src/script/nameplate.rs#L431))
@@ -751,7 +751,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
- The selection clears to 0, because the header the reference re-selects (`0x4d7b42`, reading 1) has no spell id; the stock window's `> 1` test treats 0 and 1 alike. ([`src/script/trainer/mod.rs:197`](../crates/benilla-ui/src/script/trainer/mod.rs#L197))
- A header clears it too, because it has no spell id; the reference stores its `0xffffffff` (`0x4d7b05`) and reads back 1, which the stock window's `> 1` test treats the same as 0. ([`src/script/trainer/mod.rs:871`](../crates/benilla-ui/src/script/trainer/mod.rs#L871))
- Index 0 is a no-op, because one stray call would spend the purse; the reference buys every visible service for any index at or below 0 (`0x4da244`, `0x4d8a70`). ([`src/script/trainer/mod.rs:893`](../crates/benilla-ui/src/script/trainer/mod.rs#L893))
- Kept apart from `Self::vertex_color`, which the reference's `Texture:SetAlpha` (`0x79b580`) rewrites, because the drawn product differs only on a region that sets both, or a gradient and an alpha, which no stock code does, and a FontString's `SetAlpha` then keeps its font colour. ([`src/script/types.rs:384`](../crates/benilla-ui/src/script/types.rs#L384))
- Kept apart from `Self::vertex_color`, which the reference's `Texture:SetAlpha` (`0x79b580`) rewrites, because the drawn product differs only on a region that sets both, or a gradient and an alpha, which no stock code does, and a FontString's `SetAlpha` then keeps its font colour. ([`src/script/types.rs:390`](../crates/benilla-ui/src/script/types.rs#L390))
- UnitCanCooperate answers 1 for a friendly (5 and up) player, because the engine carries no faction templates; the reference resolves their cooperation masks. ([`src/script/unit/bindings.rs:612`](../crates/benilla-ui/src/script/unit/bindings.rs#L612))
- Among whole-name matches ours picks the nearest, because the reference's first-walked pick is order-dependent and reads as a bug. ([`src/script/unit/bindings.rs:1115`](../crates/benilla-ui/src/script/unit/bindings.rs#L1115))
- The reference ends the walk at the first whole-string hit (`0x493ca2`), so its pick follows the object list's order; we rank exact, then longer prefix, then nearest (`Rank::beats`), because the nearest namesake is the better pick, and a full tie goes to the lower guid (`Rank::beats_at`), so the VM's walk and the app's scan pick the same unit whatever order each walks in. ([`src/script/unit/by_name.rs:7`](../crates/benilla-ui/src/script/unit/by_name.rs#L7))