OSDN Git Service

ShipLabel.NameのBaseFontを外から与えるようにする
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Mon, 15 Jul 2019 08:25:17 +0000 (17:25 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Mon, 15 Jul 2019 08:28:41 +0000 (17:28 +0900)
KancolleSniffer.Test/ShipLabelTest.cs
KancolleSniffer/MainForm.cs
KancolleSniffer/View/ShipLabel.cs

index 389ac11..9a3cccb 100644 (file)
@@ -224,14 +224,13 @@ namespace KancolleSniffer.Test
                 TestTruncate(data, ShipNameWidth.ShipList);\r
             }\r
 \r
-            private static readonly Font LatinFont = new Font("Tahoma", 8f);\r
-\r
             private static void TestTruncate(TestData data, ShipNameWidth width)\r
             {\r
                 foreach (var zoom in data.Keys)\r
                 {\r
                     SetScaleFactor(zoom);\r
-                    var label = CreateLabel(zoom, width);\r
+                    var label = new ShipLabel.Name(Point.Empty, width);\r
+                    label.Font = ShipLabel.Name.BaseFont;\r
                     for (var i = 0; i < data[zoom].Length; i++)\r
                     {\r
                         var entry = data[zoom][i];\r
@@ -243,31 +242,27 @@ namespace KancolleSniffer.Test
                 }\r
             }\r
 \r
-            private static ShipLabel.Name CreateLabel(int zoom, ShipNameWidth width)\r
-            {\r
-                var label = new ShipLabel.Name(Point.Empty, width) {Parent = new Panel()};\r
-                label.Parent.Font = ZoomFont(label.Parent.Font, zoom);\r
-                ShipLabel.Name.LatinFont = ZoomFont(LatinFont, zoom);\r
-                return label;\r
-            }\r
-\r
             private static void SetScaleFactor(int zoom)\r
             {\r
+                var form = new Form {AutoScaleMode = AutoScaleMode.Font};\r
                 if (zoom == 100)\r
                 {\r
                     Scaler.Factor = new SizeF(1, 1);\r
+                    ShipLabel.Name.BaseFont = form.Font;\r
+                    ShipLabel.Name.LatinFont = LatinFont(100);\r
                     return;\r
                 }\r
-                var form = new Form {AutoScaleMode = AutoScaleMode.Font};\r
                 var prev = form.CurrentAutoScaleDimensions;\r
-                form.Font = ZoomFont(form.Font, zoom);\r
+                form.Font = new Font(form.Font.FontFamily, form.Font.Size * zoom / 100);\r
+                ShipLabel.Name.BaseFont = form.Font;\r
+                ShipLabel.Name.LatinFont = LatinFont(zoom);\r
                 var cur = form.CurrentAutoScaleDimensions;\r
                 Scaler.Factor = new SizeF(cur.Width / prev.Width, cur.Height / prev.Height);\r
             }\r
 \r
-            private static Font ZoomFont(Font font, int zoom)\r
+            private static Font LatinFont(int zoom)\r
             {\r
-                return zoom == 100 ? font : new Font(font.FontFamily, font.Size * zoom / 100);\r
+                return new Font("Tahoma", 8f * zoom / 100);\r
             }\r
         }\r
 \r
index 48a08b5..1942ea9 100644 (file)
@@ -503,7 +503,11 @@ namespace KancolleSniffer
         private void PerformZoom()\r
         {\r
             if (Config.Zoom == 100)\r
+            {\r
+                ShipLabel.Name.BaseFont = Font;\r
+                ShipLabel.Name.LatinFont = LatinFont();\r
                 return;\r
+            }\r
             var prev = CurrentAutoScaleDimensions;\r
             foreach (var control in new Control[]\r
             {\r
@@ -512,17 +516,28 @@ namespace KancolleSniffer
                 contextMenuStripMain, _errorDialog\r
             })\r
             {\r
-                control.Font = new Font(control.Font.FontFamily, control.Font.Size * Config.Zoom / 100);\r
+                control.Font = ZoomFont(control.Font);\r
             }\r
             foreach (var toolTip in new[] {_toolTip, _tooltipCopy})\r
             {\r
-                toolTip.Font = new Font(toolTip.Font.FontFamily, toolTip.Font.Size * Config.Zoom / 100);\r
+                toolTip.Font = ZoomFont(toolTip.Font);\r
             }\r
-            ShipLabel.Name.LatinFont = new Font("Tahoma", 8f * Config.Zoom / 100);\r
+            ShipLabel.Name.BaseFont = Font;\r
+            ShipLabel.Name.LatinFont = LatinFont();\r
             var cur = CurrentAutoScaleDimensions;\r
             Scaler.Factor = Scaler.Scale(cur.Width / prev.Width, cur.Height / prev.Height);\r
         }\r
 \r
+        private Font ZoomFont(Font font)\r
+        {\r
+            return new Font(font.FontFamily, font.Size * Config.Zoom / 100);\r
+        }\r
+\r
+        private Font LatinFont()\r
+        {\r
+            return new Font("Tahoma", 8f * Config.Zoom / 100);\r
+        }\r
+\r
         private void RestoreLocation()\r
         {\r
             if (Config.Location.X == int.MinValue)\r
index c64a01d..45a1c65 100644 (file)
@@ -28,8 +28,6 @@ namespace KancolleSniffer.View
     {\r
         protected Color InitialBackColor;\r
 \r
-        protected Font BaseFont => Parent.Font;\r
-\r
         public override Color BackColor\r
         {\r
             get => base.BackColor;\r
@@ -55,7 +53,8 @@ namespace KancolleSniffer.View
             private SlotStatus _slotStatus;\r
             private readonly ShipNameWidth _defaultWidth;\r
 \r
-            public static Font LatinFont { get; set; } = new Font("Tahoma", 8f);\r
+            public static Font LatinFont { get; set; }\r
+            public static Font BaseFont { get; set; }\r
 \r
             public Name(Point location, ShipNameWidth defaultWidth)\r
             {\r
@@ -152,12 +151,12 @@ namespace KancolleSniffer.View
             {\r
                 var lu = new Regex(@"^\p{Lu}").IsMatch(name);\r
                 var shift = Scaler.ScaleHeight(1);\r
-                if (lu && Font.Equals(BaseFont))\r
+                if (lu && !Font.Equals(LatinFont))\r
                 {\r
                     Location += new Size(0, -shift);\r
                     Font = LatinFont;\r
                 }\r
-                else if (!lu && !Font.Equals(BaseFont))\r
+                else if (!lu && Font.Equals(LatinFont))\r
                 {\r
                     Location += new Size(0, shift);\r
                     Font = BaseFont;\r
@@ -214,7 +213,6 @@ namespace KancolleSniffer.View
             public override void Set(ShipStatus status)\r
             {\r
                 _status = status;\r
-                Font = BaseFont;\r
                 Text = _hpPercent\r
                     ? $"{(int)Floor(status.NowHp * 100.0 / status.MaxHp):D}%"\r
                     : $"{status.NowHp:D}/{status.MaxHp:D}";\r