macOS 10.14 Mojave 上 GTK# 中的字体看起来很粗

Fonts in GTK# on macOS 10.14 Mojave looking bold

macOS Mojave 开始出现一些奇怪的情况。我有一个在 macOS 上使用 mono 的 GTK# 应用程序,它 运行 多年来一直很好。现在应用程序中的所有字体开始显示为 bold。我已经创建了一个小型测试应用程序来测试可能的原因,但我不会进一步研究它。

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 macOS 社区版本 7.6.8 和它附带的最新单声道版本 5.12.0.309。

如果我使用

从命令行构建应用程序并 运行 它

mono GtkKeyScan.exe

应用程序的外观如下:

但是如果我从 Visual Studio 运行 应用程序看起来像这样:

如果我 运行 来自终端的应用程序使用较旧版本的 Mono(如 4.2.4 或 4.6.2),应用程序也会以粗体显示。

我的猜测是 Visual Studio 做了一些类似于将 macOS 应用程序捆绑到 .app 中的准备工作,这部分以某种方式破坏了新 macOS 中的字体。

看起来问题与 Mojave 是最后一个支持 32 位应用程序的 macOS 有关。我试过的项目是用 32 位构建的,因为 Windows GTK# 只能在 32 位模式下工作。看起来在新的 Mono 版本中 GTK# 也可以在 64 模式下工作。

因此,当我从命令行启动应用程序时,它以某种方式以 64 位模式运行,尽管该应用程序是在 32 位模式下构建的。 Visual Studio for macOS 在 32 位模式下运行应用程序。

当 运行 在 32 位模式下 macOS 第一次显示该应用程序未针对此 macOS 进行优化并以任何一种方式运行。但在内部,负责文本渲染的 Pango 部分出现了问题。我不确定具体是什么,但是在编译项目时切换到 64 位模式使其工作。