diff --git a/crates/benilla-app/assets/ui/OptionsFrame.xml b/crates/benilla-app/assets/ui/OptionsFrame.xml
index f37ec7837..8f0738da4 100644
--- a/crates/benilla-app/assets/ui/OptionsFrame.xml
+++ b/crates/benilla-app/assets/ui/OptionsFrame.xml
@@ -3042,13 +3042,14 @@
-
+
+ getglobal(this:GetName() .. "Icon"):SetAlpha(0.5)
BenillaOptionsFrameSearchBox:SetText("")
BenillaOptionsFrameSearchBox:ClearFocus()
diff --git a/crates/benilla-app/src/ui_script/extract/text.rs b/crates/benilla-app/src/ui_script/extract/text.rs
index c569e5681..feb21daac 100644
--- a/crates/benilla-app/src/ui_script/extract/text.rs
+++ b/crates/benilla-app/src/ui_script/extract/text.rs
@@ -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(""),
ebox_geom.unwrap_or_default(),
&draw_text[..draw_text.len().min(60)]
diff --git a/crates/benilla-app/src/ui_script/lifecycle.rs b/crates/benilla-app/src/ui_script/lifecycle.rs
index d69c2584e..3ecb4429c 100644
--- a/crates/benilla-app/src/ui_script/lifecycle.rs
+++ b/crates/benilla-app/src/ui_script/lifecycle.rs
@@ -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,
+ 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 {
diff --git a/crates/benilla-app/src/ui_script/options_tests.rs b/crates/benilla-app/src/ui_script/options_tests.rs
index 2957ac570..ff1f6171f 100644
--- a/crates/benilla-app/src/ui_script/options_tests.rs
+++ b/crates/benilla-app/src/ui_script/options_tests.rs
@@ -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();
diff --git a/crates/benilla-app/src/ui_script/reference_ui.rs b/crates/benilla-app/src/ui_script/reference_ui.rs
index d686bf140..e279d13fe 100644
--- a/crates/benilla-app/src/ui_script/reference_ui.rs
+++ b/crates/benilla-app/src/ui_script/reference_ui.rs
@@ -2109,6 +2109,40 @@ mod tests {
assert_eq!(failed(&mut glue), Vec::::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 {
+ s.finish_ui_load_log();
+ let mut lines: Vec = 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::::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::::new(), "the glue");
+ }
+
fn seat_a_player(s: &mut UiScript) {
s.set_unit(
"player",
diff --git a/crates/benilla-ui/src/color.rs b/crates/benilla-ui/src/color.rs
index 1abb66044..723829981 100644
--- a/crates/benilla-ui/src/color.rs
+++ b/crates/benilla-ui/src/color.rs
@@ -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 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 }
diff --git a/crates/benilla-ui/src/framexml.rs b/crates/benilla-ui/src/framexml.rs
index 0e1d0112a..119f7da7c 100644
--- a/crates/benilla-ui/src/framexml.rs
+++ b/crates/benilla-ui/src/framexml.rs
@@ -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> {
+ 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> {
let mut out: Vec> = Vec::new();
let mut active: Vec = 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,
) -> 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
/// `` 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,
) -> 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,
active: &mut HashSet,
) -> 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,
diff --git a/crates/benilla-ui/src/loader/level_tests.rs b/crates/benilla-ui/src/loader/level_tests.rs
index adfd9845f..56a07a529 100644
--- a/crates/benilla-ui/src/loader/level_tests.rs
+++ b/crates/benilla-ui/src/loader/level_tests.rs
@@ -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#"
+
+ "#,
+ );
+ s.set_font_probe(Box::new(|path: &str| {
+ !path.contains("NOPE") && !path.contains("HELD")
+ }));
+ let report = load_str(
+ &s,
+ r#"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "#,
+ );
+ let font = |s: &UiScript, name: &str| {
+ s.eval::(&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
+/// `` (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#"{TEST_FONT}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "#
+ ),
+ );
+ let got = |expr: &str| {
+ s.eval::(&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",
+ " 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#"
+
+
+
+
+
+
+
+ "#,
+ );
+ 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 `` 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#"
+
+
+
+
+
+
+ "#,
+ );
+ 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::("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#"{TEST_FONT}
+
+
+
+
+
+
+ "#
+ ),
+ );
+ let alpha = |name: &str| s.eval::(&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#"{TEST_FONT}
+
+
+
+
+
+
+
+
+
+ "#
+ ),
+ );
+ let justify = |name: &str| {
+ s.eval::(&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#"
+
+ "#,
+ );
+ s.set_font_probe(Box::new(|path: &str| !path.contains("HELD")));
+ let report = load_str(
+ &s,
+ r#"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "#,
+ );
+ 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::(&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#"
+
+
+
+
+
+
+
+
+
+
+ "#,
+ );
+ let got = |expr: &str| {
+ s.eval::(&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#"
+
+
+
+
+ "#,
+ );
+ 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}"
+ );
+ }
+}
diff --git a/crates/benilla-ui/src/loader/mod.rs b/crates/benilla-ui/src/loader/mod.rs
index 14f2ee86d..293cdce78 100644
--- a/crates/benilla-ui/src/loader/mod.rs
+++ b/crates/benilla-ui/src/loader/mod.rs
@@ -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 `` 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 `` 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 `` and ``
- /// 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
+ /// `` and `` 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 {
diff --git a/crates/benilla-ui/src/loader/regions.rs b/crates/benilla-ui/src/loader/regions.rs
index df6cc90d1..bba218b38 100644
--- a/crates/benilla-ui/src/loader/regions.rs
+++ b/crates/benilla-ui/src/loader/regions.rs
@@ -60,10 +60,11 @@ impl Loader<'_> {
/// One `` 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
{
- let levels = self.levels(raw);
+ let levels = if is_texture {
+ self.levels(raw)
+ } else {
+ self.fontstring_levels(raw)
+ };
let rname: Option = 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 = region
.name()
.map(|raw| framexml::resolve_name(raw, parent_name));
@@ -212,13 +217,14 @@ impl Loader<'_> {
}
/// One level of a ``'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 `` and `` children, in that order. A `font=`
/// file needs this node's own first `` 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::().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 `` is the text colour (`0x77f750`) and each `` 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 ``'s `LoadXML` (`0x76fe20`), after its `inherits` level: the
- /// geometry, `hidden`, each child in order, then `file=` and `alphaMode`. A `` sets
+ /// geometry, `hidden`, each child in order, then `file=` and `alphaMode`, and no `alpha`, which
+ /// only the frame loader reads (`0x769a10`). A `` 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::().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 {
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 `` 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()
}
}
diff --git a/crates/benilla-ui/src/loader/tests.rs b/crates/benilla-ui/src/loader/tests.rs
index 7498aa5dd..eeb1978f0 100644
--- a/crates/benilla-ui/src/loader/tests.rs
+++ b/crates/benilla-ui/src/loader/tests.rs
@@ -2396,8 +2396,9 @@ mod loader_tests {
/// state-texture element builds a new region through the `` 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) = 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]
)
);
diff --git a/crates/benilla-ui/src/loader/widgets.rs b/crates/benilla-ui/src/loader/widgets.rs
index 11168fae9..88f5467d9 100644
--- a/crates/benilla-ui/src/loader/widgets.rs
+++ b/crates/benilla-ui/src/loader/widgets.rs
@@ -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()) {
diff --git a/crates/benilla-ui/src/script/button.rs b/crates/benilla-ui/src/script/button.rs
index 13c5d4ee7..87cd65698 100644
--- a/crates/benilla-ui/src/script/button.rs
+++ b/crates/benilla-ui/src/script/button.rs
@@ -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),
+ ))
})?,
)?;
diff --git a/crates/benilla-ui/src/script/font.rs b/crates/benilla-ui/src/script/font.rs
index 8b4381e7f..a6dcda7a0 100644
--- a/crates/benilla-ui/src/script/font.rs
+++ b/crates/benilla-ui/src/script/font.rs
@@ -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(),
+ }
})
})?,
)?;
diff --git a/crates/benilla-ui/src/script/font_block.rs b/crates/benilla-ui/src/script/font_block.rs
index 1a50b693c..0ea17a64f 100644
--- a/crates/benilla-ui/src/script/font_block.rs
+++ b/crates/benilla-ui/src/script/font_block.rs
@@ -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::().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,
diff --git a/crates/benilla-ui/src/script/mod.rs b/crates/benilla-ui/src/script/mod.rs
index 66bffa92a..07b1a6adf 100644
--- a/crates/benilla-ui/src/script/mod.rs
+++ b/crates/benilla-ui/src/script/mod.rs
@@ -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};
diff --git a/crates/benilla-ui/src/script/model.rs b/crates/benilla-ui/src/script/model.rs
index 9655cd420..eae1cd9d7 100644
--- a/crates/benilla-ui/src/script/model.rs
+++ b/crates/benilla-ui/src/script/model.rs
@@ -165,9 +165,6 @@ pub(crate) struct Model {
pub(crate) framexml_debug: std::cell::Cell,
/// 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>,
pub(crate) arena: WidgetArena,
/// Per-frame anchors, size and scale; every live frame has one from creation on.
pub(crate) layout_inputs: HashMap,
@@ -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(),
diff --git a/crates/benilla-ui/src/script/region.rs b/crates/benilla-ui/src/script/region.rs
index a2c2b823b..c2fe64ca9 100644
--- a/crates/benilla-ui/src/script/region.rs
+++ b/crates/benilla-ui/src/script/region.rs
@@ -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=`, ``, 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 `` 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,
- height: Option,
- flags: Option<(super::Outline, bool)>,
-) -> mlua::Result<()> {
+ path: &str,
+ height: f32,
+ (outline, monochrome): (super::Outline, bool),
+) -> mlua::Result {
let rh = region_handle_of(lua, this)?;
let mut model = lua.app_data_mut::().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
diff --git a/crates/benilla-ui/src/script/simplehtml/mod.rs b/crates/benilla-ui/src/script/simplehtml/mod.rs
index 2802b1648..e010c42df 100644
--- a/crates/benilla-ui/src/script/simplehtml/mod.rs
+++ b/crates/benilla-ui/src/script/simplehtml/mod.rs
@@ -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,
diff --git a/crates/benilla-ui/src/script/tests/font_object.rs b/crates/benilla-ui/src/script/tests/font_object.rs
index 84060def7..26093b866 100644
--- a/crates/benilla-ui/src/script/tests/font_object.rs
+++ b/crates/benilla-ui/src/script/tests/font_object.rs
@@ -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 `` 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::(&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::(&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::>(&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::>(&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]);
+}
diff --git a/crates/benilla-ui/src/script/tests/reference_surface.rs b/crates/benilla-ui/src/script/tests/reference_surface.rs
index ebfff2b88..ef63bec35 100644
--- a/crates/benilla-ui/src/script/tests/reference_surface.rs
+++ b/crates/benilla-ui/src/script/tests/reference_surface.rs
@@ -491,7 +491,7 @@ fn button_set_font_returns_nothing_and_is_a_no_op_without_a_label() {
assert_eq!(
s.eval::("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());
diff --git a/crates/benilla-ui/src/script/tests/set_font_args.rs b/crates/benilla-ui/src/script/tests/set_font_args.rs
index 5987f8dbd..0acd55855 100644
--- a/crates/benilla-ui/src/script/tests/set_font_args.rs
+++ b/crates/benilla-ui/src/script/tests/set_font_args.rs
@@ -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#"
+
+
+
+
+
+
+
+
+
+
+ "#,
+ )
+ .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}"
+ );
+ }
+}
diff --git a/crates/benilla-ui/src/script/types.rs b/crates/benilla-ui/src/script/types.rs
index e7e194b18..382099b03 100644
--- a/crates/benilla-ui/src/script/types.rs
+++ b/crates/benilla-ui/src/script/types.rs
@@ -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",
}
}
}
diff --git a/docs/DEVIATIONS.md b/docs/DEVIATIONS.md
index a1a23505d..9b71d92bf 100644
--- a/docs/DEVIATIONS.md
+++ b/docs/DEVIATIONS.md
@@ -643,9 +643,9 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
#### loader
-- A `