// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Graphics.Sprites; namespace osu.Game.Graphics { public static class OsuFont { /// /// The default font size. /// public const float DEFAULT_FONT_SIZE = 16; /// /// The default font. /// public static FontUsage Default => GetFont(); public static FontUsage Numeric => GetFont(Typeface.Venera, weight: FontWeight.Bold); public static FontUsage Torus => GetFont(Typeface.Torus, weight: FontWeight.Regular); public static FontUsage TorusAlternate => GetFont(Typeface.TorusAlternate, weight: FontWeight.Regular); public static FontUsage Inter => GetFont(Typeface.Inter, weight: FontWeight.Regular); /// /// Retrieves a . /// /// The font typeface. /// The size of the text in local space. For a value of 16, a single line will have a height of 16px. /// The font weight. /// Whether the font is italic. /// Whether all characters should be spaced the same distance apart. /// The . public static FontUsage GetFont(Typeface typeface = Typeface.Torus, float size = DEFAULT_FONT_SIZE, FontWeight weight = FontWeight.Medium, bool italics = false, bool fixedWidth = false) => new FontUsage(GetFamilyString(typeface), size, GetWeightString(typeface, weight), getItalics(italics), fixedWidth); private static bool getItalics(in bool italicsRequested) { // right now none of our fonts support italics. // should add exceptions to this rule if they come up. return false; } /// /// Retrieves the string representation of a . /// /// The . /// The string representation. public static string GetFamilyString(Typeface typeface) { switch (typeface) { case Typeface.Venera: return "Venera"; case Typeface.Torus: return "Torus"; case Typeface.TorusAlternate: return "Torus-Alternate"; case Typeface.Inter: return "Inter"; } return null; } /// /// Retrieves the string representation of a . /// /// The . /// The . /// The string representation of in the specified . public static string GetWeightString(Typeface typeface, FontWeight weight) { if (typeface == Typeface.Torus && weight == FontWeight.Medium) // torus doesn't have a medium; fallback to regular. weight = FontWeight.Regular; return GetWeightString(GetFamilyString(typeface), weight); } /// /// Retrieves the string representation of a . /// /// The family string. /// The . /// The string representation of in the specified . public static string GetWeightString(string family, FontWeight weight) => weight.ToString(); } public static class OsuFontExtensions { /// /// Creates a new by applying adjustments to this . /// /// The base . /// The font typeface. If null, the value is copied from this . /// The text size. If null, the value is copied from this . /// The font weight. If null, the value is copied from this . /// Whether the font is italic. If null, the value is copied from this . /// Whether all characters should be spaced apart the same distance. If null, the value is copied from this . /// The resulting . public static FontUsage With(this FontUsage usage, Typeface? typeface = null, float? size = null, FontWeight? weight = null, bool? italics = null, bool? fixedWidth = null) { string familyString = typeface != null ? OsuFont.GetFamilyString(typeface.Value) : usage.Family; string weightString = weight != null ? OsuFont.GetWeightString(familyString, weight.Value) : usage.Weight; return usage.With(familyString, size, weightString, italics, fixedWidth); } } public enum Typeface { Venera, Torus, TorusAlternate, Inter, } public enum FontWeight { /// /// Equivalent to weight 300. /// Light = 300, /// /// Equivalent to weight 400. /// Regular = 400, /// /// Equivalent to weight 500. /// Medium = 500, /// /// Equivalent to weight 600. /// SemiBold = 600, /// /// Equivalent to weight 700. /// Bold = 700, /// /// Equivalent to weight 900. /// Black = 900 } }