using Content.Client.Resources; using JetBrains.Annotations; using Robust.Client.Graphics; using Robust.Client.ResourceManagement; namespace Content.Client.Stylesheets.Fonts; /// /// This class should have a base type. The whole font system is currently kind of bad and completely temporary. /// This class is just here because it does sort of work. /// TODO: fix (once engine support is added for font properties?) /// /// /// [PublicAPI] public sealed class NotoFontFamilyStack(IResourceCache resCache, string variant = "") { /// /// The primary font path, with string substitution markers. /// /// /// If using the default GetFontPaths function, the substitutions are as follows: /// 0 is the font kind. /// 1 is the font kind with BoldItalic replaced with Bold when it occurs. /// private string _fontPrimary = $"/Fonts/NotoSans{variant}/NotoSans{variant}-{{0}}.ttf"; /// /// The symbols font path, with string substitution markers. /// /// /// If using the default GetFontPaths function, the substitutions are as follows: /// 0 is the font kind. /// 1 is the font kind with BoldItalic replaced with Bold when it occurs. /// private string _fontSymbols = "/Fonts/NotoSans/NotoSansSymbols-{2}.ttf"; /// /// The fallback font path, exactly. (no string substitutions.) /// private string[] _extras = new[] { "/Fonts/NotoSans/NotoSansSymbols2-Regular.ttf" }; public HashSet AvailableKinds = [FontKind.Regular, FontKind.Bold, FontKind.Italic, FontKind.BoldItalic]; /// /// This should return the paths of every font in this stack given the abstract members. /// /// Which font kind to use. /// An array of private string[] GetFontPaths(FontKind kind) { if (!AvailableKinds.Contains(kind)) { if (kind == FontKind.BoldItalic && AvailableKinds.Contains(FontKind.Bold)) { kind = FontKind.Bold; } else { kind = FontKind.Regular; } } var simpleKindStr = kind.SimplifyCompound().AsFileName(); var boldOrRegularStr = kind.RegularOr(FontKind.Bold).AsFileName(); var kindStr = kind.AsFileName(); var fontList = new List() { string.Format(_fontPrimary, kindStr, simpleKindStr, boldOrRegularStr), string.Format(_fontSymbols, kindStr, simpleKindStr, boldOrRegularStr), }; fontList.AddRange(_extras); return fontList.ToArray(); } /// /// Retrieves an in-style font, of the provided size and kind. /// /// Size of the font to provide. /// Optional font kind. Defaults to Regular. /// A Font resource. public Font GetFont(int size, FontKind kind = FontKind.Regular) { //ALDebugTools.AssertContains(AvailableKinds, kind); var paths = GetFontPaths(kind); return resCache.GetFont(paths, size); } }