From c4a3f8db90530a727ffab77c3bb5bb7d782792bf Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期一, 25 八月 2025 15:50:27 +0800
Subject: [PATCH] 上传代码;

---
 HMI.Core/FontSizeConverter.cs |   64 ++++++++++++++++++++++++++++---
 1 files changed, 57 insertions(+), 7 deletions(-)

diff --git a/HMI.Core/FontSizeConverter.cs b/HMI.Core/FontSizeConverter.cs
index 5ff7876..ecadb25 100644
--- a/HMI.Core/FontSizeConverter.cs
+++ b/HMI.Core/FontSizeConverter.cs
@@ -1,14 +1,51 @@
 锘縰sing System;
-using System.Collections.Generic;
 using System.Globalization;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows.Data;
 
 namespace HMI.Core
 {
-    public class CustomFontSizeConverter : IValueConverter
+    public class WidthSizeConverter : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            if (parameter == null) return 15;
+
+            string[] ps = parameter.ToString().Split(',');
+            double size = double.Parse(ps[0]);
+            double baseSize = double.Parse(ps[1]);
+            double min = -1, max = -1;
+
+            if (ps.Length >= 3)
+            {
+                min = double.Parse(ps[2]);
+            }
+            if (ps.Length >= 4)
+            {
+                max = double.Parse(ps[3]);
+            }
+
+            if (value is double width)
+            {
+                double res = CountFontSize(size, width, baseSize);
+                res = min > 0 && res < min ? min : res;
+                res = max > 0 && res > max ? max : res;
+                return res;
+            }
+            return 15;
+        }
+
+        public static double CountFontSize(double size, double limit, double baseSize)
+        {
+            return size * limit / baseSize;
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+    }
+
+    public class HeightSizeConverter : IValueConverter
     {
         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         {
@@ -17,9 +54,22 @@
             string[] ps = parameter.ToString().Split(',');
             int size = int.Parse(ps[0]);
             int baseSize = int.Parse(ps[1]);
-            if (value is double width)
+            double min = -1, max = -1;
+
+            if (ps.Length >= 3)
             {
-                return CountFontSize(size, width, baseSize);
+                min = double.Parse(ps[2]);
+            }
+            if (ps.Length >= 4)
+            {
+                max = double.Parse(ps[3]);
+            }
+            if (value is double height)
+            {
+                double res = CountFontSize(size, height, baseSize);
+                res = min > 0 && res < min ? min : res;
+                res = max > 0 && res > max ? max : res;
+                return res;
             }
             return 15;
         }

--
Gitblit v1.9.1