From df4c6b4b32318025696cf0f87ff00b45d4ade933 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 21 May 2015 16:22:48 +1000 Subject: [PATCH] Fix issues with UnsafeString on Windows XP and below. (Unfortunately, I couldn't work around this without having to allocate strings.) --- 2D/Screens/FpsScreen.cs | 6 +++++- 2D/Utils2D.cs | 8 +++++++- 2D/Widgets/TextInputWidget.cs | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/2D/Screens/FpsScreen.cs b/2D/Screens/FpsScreen.cs index e8d19af2e..9b62efd1b 100644 --- a/2D/Screens/FpsScreen.cs +++ b/2D/Screens/FpsScreen.cs @@ -36,7 +36,11 @@ namespace ClassicalSharp { .Append( ref ptr2, "), chunks/s: " ).AppendNum( ref ptr2, Window.ChunkUpdates ) .Append( ref ptr2, ", vertices: " ).AppendNum( ref ptr2, Window.Vertices ); } - fpsTextWidget.SetText( text.value ); + string textString = text.value; + if( Utils2D.needWinXpFix ) + textString = textString.TrimEnd( Utils2D.trimChars ); + + fpsTextWidget.SetText( textString ); maxDelta = 0; accumulator = 0; fpsCount = 0; diff --git a/2D/Utils2D.cs b/2D/Utils2D.cs index af88e47b6..80be40b96 100644 --- a/2D/Utils2D.cs +++ b/2D/Utils2D.cs @@ -12,6 +12,9 @@ namespace ClassicalSharp { static Bitmap measuringBmp; static Graphics measuringGraphics; static Dictionary brushCache = new Dictionary( 16 ); + internal static bool needWinXpFix; + internal static char[] trimChars = { '\0' }; + static Utils2D() { format = StringFormat.GenericTypographic; format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces; @@ -20,6 +23,9 @@ namespace ClassicalSharp { //format.FormatFlags |= StringFormatFlags.NoClip; measuringBmp = new Bitmap( 1, 1 ); measuringGraphics = Graphics.FromImage( measuringBmp ); + measuringGraphics.TextRenderingHint = TextRenderingHint.AntiAlias; + OperatingSystem os = Environment.OSVersion; + needWinXpFix = os.Platform == PlatformID.Win32NT && os.Version.Major < 6; } static SolidBrush GetOrCreateBrush( Color color ) { @@ -33,7 +39,7 @@ namespace ClassicalSharp { return brush; } - const float shadowOffset = 1.3f; + const float shadowOffset = 1.3f; public static Size MeasureSize( string text, Font font, bool shadow ) { SizeF size = measuringGraphics.MeasureString( text, font, Int32.MaxValue, format ); if( shadow ) { diff --git a/2D/Widgets/TextInputWidget.cs b/2D/Widgets/TextInputWidget.cs index 6958c3977..6fec2aab6 100644 --- a/2D/Widgets/TextInputWidget.cs +++ b/2D/Widgets/TextInputWidget.cs @@ -41,6 +41,8 @@ namespace ClassicalSharp { DrawTextArgs caretArgs = new DrawTextArgs( GraphicsApi, "_", Color.White, false ); chatCaretTexture = Utils2D.MakeTextTexture( boldFont, 0, 0, ref caretArgs ); string value = chatInputText.value; + if( Utils2D.needWinXpFix ) + value = value.TrimEnd( Utils2D.trimChars ); if( chatInputText.Empty ) { caretPos = -1;