From d8ea4547d47522a723cca1bb43f16cbb18f4cd1c Mon Sep 17 00:00:00 2001 From: SG <22363152+SolidifiedGaming@users.noreply.github.com> Date: Tue, 20 Jun 2023 19:20:54 -0400 Subject: [PATCH] Add StringFormat to pixeltext DrawString parameters (squashed PR #3690) * Add StringFormat to DrawString parameters * Revert whitespace changes * Code style nitpicks, cache `StringFormat` --------- Co-authored-by: YoshiRulz --- src/BizHawk.Client.Common/Api/Classes/GuiApi.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs b/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs index ade09ac08d..09626b3f17 100644 --- a/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs @@ -13,6 +13,11 @@ namespace BizHawk.Client.Common { public sealed class GuiApi : IGuiApi { + private static readonly StringFormat PixelTextFormat = new(StringFormat.GenericTypographic) + { + FormatFlags = StringFormatFlags.MeasureTrailingSpaces, + }; + [RequiredService] private IEmulator Emulator { get; set; } @@ -591,15 +596,10 @@ namespace BizHawk.Client.Common } using var g = GetGraphics(surfaceID); var font = new Font(_displayManager.CustomFonts.Families[index], 8, FontStyle.Regular, GraphicsUnit.Pixel); - var sizeOfText = g.MeasureString( - message, - font, - 0, - new StringFormat(StringFormat.GenericTypographic) { FormatFlags = StringFormatFlags.MeasureTrailingSpaces } - ).ToSize(); + var sizeOfText = g.MeasureString(message, font, width: 0, PixelTextFormat).ToSize(); if (backcolor.HasValue) g.FillRectangle(GetBrush(backcolor.Value), new Rectangle(new Point(x, y), sizeOfText + new Size(1, 0))); g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; - g.DrawString(message, font, GetBrush(forecolor ?? _defaultForeground), x, y); + g.DrawString(message, font, GetBrush(forecolor ?? _defaultForeground), x + 1, y, PixelTextFormat); } catch (Exception) {