|
| 1 | +using System.Linq; |
| 2 | +using Robust.Client.AutoGenerated; |
| 3 | +using Robust.Client.UserInterface; |
| 4 | +using Robust.Client.UserInterface.Controls; |
| 5 | +using Robust.Client.UserInterface.CustomControls; |
| 6 | +using Robust.Client.UserInterface.XAML; |
| 7 | +using Robust.Shared.IoC; |
| 8 | +using Robust.Shared.Maths; |
| 9 | +using Robust.Shared.Utility; |
| 10 | + |
| 11 | +namespace Robust.Client.Graphics.FontManagement; |
| 12 | + |
| 13 | +[GenerateTypedNameReferences] |
| 14 | +internal sealed partial class SystemFontDebugWindow : DefaultWindow |
| 15 | +{ |
| 16 | + private static readonly int[] ExampleFontSizes = [8, 12, 16, 24, 36]; |
| 17 | + private const string ExampleString = "The quick brown fox jumps over the lazy dog"; |
| 18 | + |
| 19 | + [Dependency] private readonly ISystemFontManager _systemFontManager = default!; |
| 20 | + |
| 21 | + public SystemFontDebugWindow() |
| 22 | + { |
| 23 | + IoCManager.InjectDependencies(this); |
| 24 | + RobustXamlLoader.Load(this); |
| 25 | + |
| 26 | + var buttonGroup = new ButtonGroup(); |
| 27 | + |
| 28 | + foreach (var group in _systemFontManager.SystemFontFaces.GroupBy(k => k.FamilyName).OrderBy(k => k.Key)) |
| 29 | + { |
| 30 | + var fonts = group.ToArray(); |
| 31 | + SelectorContainer.AddChild(new Selector(this, buttonGroup, group.Key, fonts)); |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + private void SelectFontFamily(ISystemFontFace[] fonts) |
| 36 | + { |
| 37 | + FamilyLabel.Text = fonts[0].FamilyName; |
| 38 | + |
| 39 | + FaceContainer.RemoveAllChildren(); |
| 40 | + |
| 41 | + foreach (var font in fonts) |
| 42 | + { |
| 43 | + var exampleContainer = new BoxContainer |
| 44 | + { |
| 45 | + Orientation = BoxContainer.LayoutOrientation.Vertical, |
| 46 | + Margin = new Thickness(8) |
| 47 | + }; |
| 48 | + |
| 49 | + foreach (var size in ExampleFontSizes) |
| 50 | + { |
| 51 | + var fontInstance = font.Load(size); |
| 52 | + |
| 53 | + var richTextLabel = new RichTextLabel |
| 54 | + { |
| 55 | + Stylesheet = new Stylesheet([ |
| 56 | + StylesheetHelpers.Element<RichTextLabel>().Prop("font", fontInstance) |
| 57 | + ]), |
| 58 | + }; |
| 59 | + richTextLabel.SetMessage(FormattedMessage.FromUnformatted(ExampleString)); |
| 60 | + exampleContainer.AddChild(richTextLabel); |
| 61 | + } |
| 62 | + |
| 63 | + FaceContainer.AddChild(new BoxContainer |
| 64 | + { |
| 65 | + Orientation = BoxContainer.LayoutOrientation.Vertical, |
| 66 | + Children = |
| 67 | + { |
| 68 | + new RichTextLabel |
| 69 | + { |
| 70 | + Text = $""" |
| 71 | + {font.FullName} |
| 72 | + Family: "{font.FamilyName}", face: "{font.FaceName}", PostScript = "{font.PostscriptName}" |
| 73 | + Weight: {font.Weight} ({(int) font.Weight}), slant: {font.Slant} ({(int) font.Slant}), width: {font.Width} ({(int) font.Width}) |
| 74 | + """, |
| 75 | + }, |
| 76 | + exampleContainer |
| 77 | + }, |
| 78 | + Margin = new Thickness(0, 0, 0, 8) |
| 79 | + }); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + private sealed class Selector : Control |
| 84 | + { |
| 85 | + public Selector(SystemFontDebugWindow window, ButtonGroup group, string family, ISystemFontFace[] fonts) |
| 86 | + { |
| 87 | + var button = new Button |
| 88 | + { |
| 89 | + Text = family, |
| 90 | + Group = group, |
| 91 | + ToggleMode = true |
| 92 | + }; |
| 93 | + AddChild(button); |
| 94 | + |
| 95 | + button.OnPressed += _ => window.SelectFontFamily(fonts); |
| 96 | + } |
| 97 | + } |
| 98 | +} |
0 commit comments