From 7eb714d38faa9b33240c226b0e71bb6c13c97ccf Mon Sep 17 00:00:00 2001 From: Southbridge <7013162+southbridge-fur@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:24:34 -0500 Subject: [PATCH] Monospace Support for Rich Text (#33830) * Initial Commit * Moved all this to SS14 on it's own * Added prototype validation --- Content.Client/Paper/UI/PaperWindow.xaml.cs | 4 ++- .../UserInterface/RichText/MonoTag.cs | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 Content.Client/UserInterface/RichText/MonoTag.cs diff --git a/Content.Client/Paper/UI/PaperWindow.xaml.cs b/Content.Client/Paper/UI/PaperWindow.xaml.cs index 3522aabc66a7da..9086145f83fced 100644 --- a/Content.Client/Paper/UI/PaperWindow.xaml.cs +++ b/Content.Client/Paper/UI/PaperWindow.xaml.cs @@ -9,6 +9,7 @@ using Robust.Client.UserInterface.XAML; using Robust.Shared.Utility; using Robust.Client.UserInterface.RichText; +using Content.Client.UserInterface.RichText; using Robust.Shared.Input; namespace Content.Client.Paper.UI @@ -43,7 +44,8 @@ public sealed partial class PaperWindow : BaseWindow typeof(BulletTag), typeof(ColorTag), typeof(HeadingTag), - typeof(ItalicTag) + typeof(ItalicTag), + typeof(MonoTag) }; public event Action? OnSaved; diff --git a/Content.Client/UserInterface/RichText/MonoTag.cs b/Content.Client/UserInterface/RichText/MonoTag.cs new file mode 100644 index 00000000000000..aee41c324af1bb --- /dev/null +++ b/Content.Client/UserInterface/RichText/MonoTag.cs @@ -0,0 +1,34 @@ +using System.Linq; +using Robust.Client.ResourceManagement; +using Robust.Client.UserInterface.RichText; +using Robust.Shared.IoC; +using Robust.Shared.Prototypes; +using Robust.Shared.Utility; + +namespace Content.Client.UserInterface.RichText; + +/// +/// Sets the font to a monospaced variant +/// +public sealed class MonoTag : IMarkupTag +{ + [ValidatePrototypeId] public const string MonoFont = "Monospace"; + + [Dependency] private readonly IResourceCache _resourceCache = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + + public string Name => "mono"; + + /// + public void PushDrawContext(MarkupNode node, MarkupDrawingContext context) + { + var font = FontTag.CreateFont(context.Font, node, _resourceCache, _prototypeManager, MonoFont); + context.Font.Push(font); + } + + /// + public void PopDrawContext(MarkupNode node, MarkupDrawingContext context) + { + context.Font.Pop(); + } +}