From 86c9503ab268b34f7db0e936da00ee1e5b42df62 Mon Sep 17 00:00:00 2001 From: lay295 Date: Sun, 11 Dec 2022 17:24:25 -0600 Subject: [PATCH] clone font and dont use string literals (C# 11 feature) --- TwitchDownloaderCore/ChatRenderer.cs | 5 +++-- TwitchDownloaderCore/TwitchHelper.cs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/TwitchDownloaderCore/ChatRenderer.cs b/TwitchDownloaderCore/ChatRenderer.cs index e4497950..5e82525a 100644 --- a/TwitchDownloaderCore/ChatRenderer.cs +++ b/TwitchDownloaderCore/ChatRenderer.cs @@ -591,7 +591,7 @@ private void DrawMessage(Comment comment, List sectionImages, List<(Po DrawText(messageBuffer.ToString(), messageFont, true, sectionImages, ref drawPos, defaultPos); messageBuffer.Clear(); } - SKPaint fallbackFont = GetFallbackFont(char.ConvertToUtf32(fragmentChars[j], fragmentChars[j + 1]), renderOptions); + using SKPaint fallbackFont = GetFallbackFont(char.ConvertToUtf32(fragmentChars[j], fragmentChars[j + 1]), renderOptions).Clone(); fallbackFont.Color = renderOptions.MessageColor; DrawText(fragmentChars[j].ToString() + fragmentChars[j + 1].ToString(), fallbackFont, false, sectionImages, ref drawPos, defaultPos); j++; @@ -603,7 +603,7 @@ private void DrawMessage(Comment comment, List sectionImages, List<(Po DrawText(messageBuffer.ToString(), messageFont, true, sectionImages, ref drawPos, defaultPos); messageBuffer.Clear(); } - SKPaint fallbackFont = GetFallbackFont(fragmentChars[j], renderOptions); + using SKPaint fallbackFont = GetFallbackFont(fragmentChars[j], renderOptions).Clone(); fallbackFont.Color = renderOptions.MessageColor; DrawText(fragmentChars[j].ToString(), fallbackFont, true, sectionImages, ref drawPos, defaultPos); } @@ -824,6 +824,7 @@ private void DrawUsername(Comment comment, List sectionImages, ref Poi userPaint.Color = userColor; sectionImageCanvas.DrawText(comment.commenter.display_name + ":", drawPos.X, drawPos.Y, userPaint); drawPos.X += textWidth + renderOptions.WordSpacing; + userPaint.Dispose(); } private static SKColor GenerateUserColor(SKColor userColor, SKColor background_color, ChatRenderOptions renderOptions) diff --git a/TwitchDownloaderCore/TwitchHelper.cs b/TwitchDownloaderCore/TwitchHelper.cs index 86113592..36e6f482 100644 --- a/TwitchDownloaderCore/TwitchHelper.cs +++ b/TwitchDownloaderCore/TwitchHelper.cs @@ -643,7 +643,7 @@ public static async Task GetStreamerName(int id) { RequestUri = new Uri("https://gql.twitch.tv/gql"), Method = HttpMethod.Post, - Content = new StringContent($$$"""{"query":"query{user(id:\"{{{id}}}\"){login}}","variables":{}}""", Encoding.UTF8, "application/json") + Content = new StringContent("{\"query\":\"query{user(id:\\\"" + id.ToString() + "\\\"){login}}\",\"variables\":{}}", Encoding.UTF8, "application/json") }; request.Headers.Add("Client-ID", "kimne78kx3ncx6brgo4mv6wki5h1ko"); string response = await (await httpClient.SendAsync(request)).Content.ReadAsStringAsync();