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:
parent
4ee7e4cad7
commit
d8ea4547d4
|
@ -13,6 +13,11 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public sealed class GuiApi : IGuiApi
|
public sealed class GuiApi : IGuiApi
|
||||||
{
|
{
|
||||||
|
private static readonly StringFormat PixelTextFormat = new(StringFormat.GenericTypographic)
|
||||||
|
{
|
||||||
|
FormatFlags = StringFormatFlags.MeasureTrailingSpaces,
|
||||||
|
};
|
||||||
|
|
||||||
[RequiredService]
|
[RequiredService]
|
||||||
private IEmulator Emulator { get; set; }
|
private IEmulator Emulator { get; set; }
|
||||||
|
|
||||||
|
@ -591,15 +596,10 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
using var g = GetGraphics(surfaceID);
|
using var g = GetGraphics(surfaceID);
|
||||||
var font = new Font(_displayManager.CustomFonts.Families[index], 8, FontStyle.Regular, GraphicsUnit.Pixel);
|
var font = new Font(_displayManager.CustomFonts.Families[index], 8, FontStyle.Regular, GraphicsUnit.Pixel);
|
||||||
var sizeOfText = g.MeasureString(
|
var sizeOfText = g.MeasureString(message, font, width: 0, PixelTextFormat).ToSize();
|
||||||
message,
|
|
||||||
font,
|
|
||||||
0,
|
|
||||||
new StringFormat(StringFormat.GenericTypographic) { FormatFlags = StringFormatFlags.MeasureTrailingSpaces }
|
|
||||||
).ToSize();
|
|
||||||
if (backcolor.HasValue) g.FillRectangle(GetBrush(backcolor.Value), new Rectangle(new Point(x, y), sizeOfText + new Size(1, 0)));
|
if (backcolor.HasValue) g.FillRectangle(GetBrush(backcolor.Value), new Rectangle(new Point(x, y), sizeOfText + new Size(1, 0)));
|
||||||
g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
|
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)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue