From 869d80e93632f871c4ff66e4b17a4c5cc80d0552 Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 17 May 2023 15:21:02 +0800 Subject: [PATCH] =?UTF-8?q?*=20UFontImage:=20=E4=BF=AE=E5=A4=8D=E4=BA=86?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E7=AA=97=E4=BD=93=E5=B1=9E=E6=80=A7=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8=E5=9B=BE=E6=A0=87=E6=98=BE=E7=A4=BA=E4=B8=8D?= =?UTF-8?q?=E5=85=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Common/UGDI.cs | 17 ----------------- SunnyUI/Font/UIFontImage.cs | 10 ++++++++-- SunnyUI/Style/UIDPIScale.cs | 12 +++++++++++- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/SunnyUI/Common/UGDI.cs b/SunnyUI/Common/UGDI.cs index c78361e5..a93fc00a 100644 --- a/SunnyUI/Common/UGDI.cs +++ b/SunnyUI/Common/UGDI.cs @@ -181,23 +181,6 @@ namespace Sunny.UI return region; } - private static Graphics TempGraphics; - - /// - /// 提供一个Graphics,常用于需要计算文字大小时 - /// - /// 大小 - internal static Graphics Graphics() - { - if (TempGraphics == null) - { - Bitmap bmp = new Bitmap(1, 1); - TempGraphics = bmp.Graphics(); - } - - return TempGraphics; - } - /// /// 获取起始颜色到终止颜色之间的渐变颜色 /// diff --git a/SunnyUI/Font/UIFontImage.cs b/SunnyUI/Font/UIFontImage.cs index 779dbf96..c9dd6bb0 100644 --- a/SunnyUI/Font/UIFontImage.cs +++ b/SunnyUI/Font/UIFontImage.cs @@ -22,6 +22,7 @@ * 2021-06-15: V3.0.4 FontAwesomeV5ͼ꣬ع * 2021-06-15: V3.3.5 FontAwesomeV6ͼ꣬ع * 2022-05-16: V3.3.6 عDrawFontImage + * 2022-05-17: V3.3.7 ޸һԱ༭ͼʾȫ ******************************************************************************/ using System; @@ -162,7 +163,10 @@ namespace Sunny.UI { // Font font = GetFont(symbol, symbolSize); - if (font == null) return; + if (font == null) + { + return; + } var symbolValue = GetSymbolValue(symbol); string text = char.ConvertFromUtf32(symbolValue); @@ -317,7 +321,9 @@ namespace Sunny.UI /// С public int GetFontSize(int symbol, int imageSize) { - return BinarySearch(GDI.Graphics(), MinFontSize, MaxFontSize, symbol, imageSize); + using Bitmap bitmap = new Bitmap(48, 48); + using Graphics graphics = Graphics.FromImage(bitmap); + return BinarySearch(graphics, MinFontSize, MaxFontSize, symbol, imageSize); } public int BinarySearch(Graphics graphics, int low, int high, int symbol, int imageSize) diff --git a/SunnyUI/Style/UIDPIScale.cs b/SunnyUI/Style/UIDPIScale.cs index b8aa7dcd..fe3cb83b 100644 --- a/SunnyUI/Style/UIDPIScale.cs +++ b/SunnyUI/Style/UIDPIScale.cs @@ -27,9 +27,19 @@ namespace Sunny.UI { public static class UIDPIScale { + private static float dpiScale = -1; + public static float DPIScale() { - return GDI.Graphics().DpiX / 96.0f / (UIStyles.FontSize / 12.0f); + if (dpiScale > 0) + { + return dpiScale; + } + + using Bitmap bmp = new Bitmap(1, 1); + using Graphics g = bmp.Graphics(); + dpiScale = g.DpiX / 96.0f / (UIStyles.FontSize / 12.0f); + return dpiScale; } public static bool DPIScaleIsOne()