有些奇怪的事情开始发生在macOS Mojave上。我有一个使用mono的GTK#应用程序在macOS上运行良好,已经运行了多年。现在应用程序中的所有字体都开始出现粗体。我创建了一个小型测试应用程序来测试可能的原因,但是没有进展。
我正在使用最新的Visual Studio Community for macOS版本7.6.8和随附的最新mono版本5.12.0.309。如果我构建应用程序并使用命令行运行它,使用 " mono GtkKeyScan.exe ",应用程序将如下所示:
我的猜测是Visual Studio做了一些准备工作,类似于将应用程序打包成.macOS的.app文件,这部分在新的macOS中会破坏字体。
using System;
using Gtk;
namespace GtkKeyScan
{
class Program
{
private static Label lblCount;
private static DateTime? scanStart;
static void Main (string [] args)
{
if (Environment.OSVersion.Platform != PlatformID.Unix)
GLib.Thread.Init ();
Application.Init ();
var dlg = new Dialog { WindowPosition = WindowPosition.CenterAlways, WidthRequest = 200 };
lblCount = new Label { Text = "Press key to see the code" };
dlg.VBox.PackStart (lblCount, true, true, 10);
var btnClear = new Button { Label = "Clear", WidthRequest = 110, HeightRequest = 34, CanFocus = false };
btnClear.Clicked += btnClear_Clicked;
dlg.VBox.PackStart (btnClear, false, true, 10);
dlg.KeyPressEvent += ent_KeyPressEvent;
dlg.ShowAll ();
dlg.Run ();
}
static void btnClear_Clicked (object sender, EventArgs e)
{
lblCount.Text = "";
scanStart = null;
}
[GLib.ConnectBefore]
static void ent_KeyPressEvent (object o, KeyPressEventArgs args)
{
if (!string.IsNullOrWhiteSpace (lblCount.Text))
lblCount.Text += "\n";
lblCount.Text += args.Event.Key.ToString ();
if (scanStart == null)
scanStart = DateTime.Now;
else
lblCount.Text += " +" + (int) (DateTime.Now - scanStart.Value).TotalMilliseconds + "ms";
args.RetVal = true;
}
}
}
我正在使用最新的Visual Studio Community for macOS版本7.6.8和随附的最新mono版本5.12.0.309。如果我构建应用程序并使用命令行运行它,使用 " mono GtkKeyScan.exe ",应用程序将如下所示:
但是如果我从Visual Studio运行它,应用程序看起来像这样:
该应用程序在终端中使用旧版本的Mono(如4.2.4或4.6.2)运行时,字体会以粗体显示。我的猜测是Visual Studio做了一些准备工作,类似于将应用程序打包成.macOS的.app文件,这部分在新的macOS中会破坏字体。