Windows 表单上的 Unicode 字形未正确组合

Unicode glyphs not combined properly on Windows Forms

问题: Javanese 脚本(使用 Google's Noto Sans Javanese font)在 HTML 上正确呈现和 "combined",但 Windows 表单应用程序(C# .NET,Visual Studio 2017)。

编辑: 我的电脑使用 Windows 7,64 位。

Noto Sans Javanese direct download link (.zip)


使用的字形

有很多情况表明字形没有正确组合,但这是我使用的一个例子:

  1. 爪哇字母 NA,U+A9A4,#43428;
  2. 爪哇邦功,U+A9C0,#43456;
  3. 爪哇字母 TA,U+A9A0,#43424;
  4. 爪哇语元音符号 PEPET,U+A9BC,#43452;

Javanese Script Unicode Specification direct download link (.pdf)


Correct/desired 行为

其中四个字形应该是"combined",成为一个字符

HTML代码:

<html>
<head>
    <meta charset="utf-8">
    <style>
    .javanese {
    font-family: "Noto Sans Javanese";
    font-size: 66px;
    }
    </style>
</head>
<body>
    <div class="javanese">ꦤ꧀ꦠꦼ</div>
    <div class="javanese">&#43428;&#43456;&#43424;&#43452;</div>
</body>
</html>

HTML 结果:


Windows 表单 (C# .NET) 上的呈现不正确

我正在使用 Visual Studio 2017 社区,创建一个 Windows Forms 桌面应用程序。
标签组件使用 "Noto Sans Javenese" 字体。

C#代码:

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.label1.Text = "\uA9A4\uA9C0\uA9A0\uA9BC";
            this.label2.Text = "ꦤ꧀ꦠꦼ"; // Copied from HTML

            // this one is rendered correctly
            // Thai character "ko kai" (U+0E01) and combining characters "mai tho" (U+0E49).
            this.label3.Text = "\u0E01\u0E49\u0E49\u0E49\u0E49\u0E49\u0E49\u0E49\u0E49";
        }
    }
}

C# 结果:


问题

  1. 这种行为的原因是什么?有人可以解释一下吗?
  2. 我应该怎样做才能在 Windows 表单应用程序上正确制作 Javanese 脚本 "combined"?

非常感谢!

我得到的帮助解决这个问题的选项和见解很少。显然,这只是 Windows Forms on Windows 7.

的问题

到目前为止,我的选择是:

  1. 切换到 WPF 应用程序(我认为最好的选择)
  2. 在 Windows 表单中使用 WPF Composite Control
  3. 使用第三方库渲染为位图,例如:HarfBuzz

这里是来源,致谢所有作者:


  1. cheong00 posted a great explanation on a MSDN Thread:

Since Win7 has Unicode 5.1 support only and the character \uA9A4 falls in Unicode 5.2 range, the GDI+ text rendering function may not be able to handle the glyph hints correctly. (I'm not expert on i18n issues, so don't know whether special glyph hint support is needed)

Since IE and other web browsers such as Chrome and Firefox all comes with their own font rendering engine, they're not subject to GDI+ rendering limitations.

Btw, also tested setting "UseCompatibleTextRendering" to true does not help either.

On the other hand, WPF forms does render the text correctly. So consider changing it to WPF application, or replace necessary controls with WinForm hosted WPF controls.


  1. u/GoogleBingLady posted an insight on a Reddit thread:

Font shaping (Bidirectionality, Context-based shaping, ligatures, positioning & reordering) is a very, very complex topic. Although I'd be surprised, it may be that Windows Forms do not support font shaping.

A workaround would be to use a library like HarfBuzz, render the result to a bitmap and then display that bitmap. See http://behdad.org/text/ for details.

In fact, your problem is described here on page 8: http://www.panl10n.net/Presentations/Cambodia/Pema/LocalizationofLinux(Bhutan).pdf

Windows 7 不支持爪哇整形。 Windows 8.1.

中添加了对爪哇语的整形支持