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 <OSSYoshiRulz@gmail.com>
This commit is contained in:
SG 2023-06-20 19:20:54 -04:00 committed by GitHub
parent 4ee7e4cad7
commit d8ea4547d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

View File

@ -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)
{