Unicode 字形未在 Windows 窗体上正确组合 [英] Unicode glyphs not combined properly on Windows Forms

查看:36
本文介绍了Unicode 字形未在 Windows 窗体上正确组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题: Javanese Script(使用

<小时>

在 Windows 窗体 (C# .NET) 上呈现错误

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

C# 代码:

命名空间 WindowsFormsApp1{公共部分类 Form1 :表单{公共 Form1(){初始化组件();this.label1.Text = "\uA9A4\uA9C0\uA9A0\uA9BC";this.label2.Text = "ꦤ꧀ꦠꦼ";//从 HTML 复制//这个是正确渲染的//泰语字符ko kai"(U+0E01)和组合字符mai tho"(U+0E49).this.label3.Text = "\u0E01\u0E49\u0E49\u0E49\u0E49\u0E49\u0E49\u0E49\u0E49";}}}

C# 结果:

<小时>

问题

  1. 这种行为的原因是什么?有人能解释一下吗?
  2. 我应该怎么做才能使 Javanese 脚本在 Windows 窗体应用程序上正确组合"?

非常感谢!

解决方案

我得到了一些选项和见解来帮助解决这个问题.显然,这只是 Windows 7 上的 Windows 窗体的问题.

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

  1. 切换到 WPF 应用程序(我认为是最佳选择)
  2. 使用 Windows 窗体中的 WPF 复合控件
  3. 使用第三方库渲染为位图,例如:HarfBuzz


以下是来源,版权归所有作者所有:


  1. cheong00一个 MSDN 线程:

<块引用>

由于 Win7 仅支持 Unicode 5.1字符 \uA9A4在 Unicode 5.2 范围内,GDI+ 文本渲染功能可能无法正确处理字形提示.(我不是i18n问题的专家,所以不知道是否需要特殊的字形提示支持)

由于 IE 和其他网络浏览器(例如 Chrome 和 Firefox)都带有自己的字体渲染引擎,因此它们不受 GDI+ 渲染限制.

顺便说一句,还测试了设置UseCompatibleTextRendering";设为 true 也无济于事.

另一方面,WPF 表单确实可以正确呈现文本.因此,请考虑将其更改为 WPF 应用程序,或将必要的控件替换为 WinForm 托管的 WPF 控件.


  1. u/GoogleBingLady 发布了关于 Reddit 线程:

<块引用>

字体整形(双向性、基于上下文的整形、连字、定位和重新排序)是一个非常非常复杂的话题.虽然我会感到惊讶,但可能是 Windows 窗体不支持字体整形.

一种解决方法是使用像 HarfBuzz 这样的库,将结果渲染为位图,然后显示该位图.请参阅 http://behdad.org/text/ 了解详情.

事实上,您的问题已在第 8 页描述:http://www.panl10n.net/Presentations/Cambodia/Pema/LocalizationofLinux(Bhutan).pdf

Problem: Javanese Script (using Google's Noto Sans Javanese font) rendered and "combined" properly on HTML, but not on Windows Forms Application (C# .NET, Visual Studio 2017).

Edit: My computer uses Windows 7, 64-bit.

Noto Sans Javanese direct download link (.zip)


Glyphs Used

There are many cases to show that the glyphs are not combined properly, but here's one example I used:

  1. JAVANESE LETTER NA, U+A9A4, #43428;
  2. JAVANESE PANGKON, U+A9C0, #43456;
  3. JAVANESE LETTER TA, U+A9A0, #43424;
  4. JAVANESE VOWEL SIGN PEPET, U+A9BC, #43452;

Javanese Script Unicode Specification direct download link (.pdf)


Correct/desired behaviour

Four of these glyphs should be "combined", becoming one character

HTML code:

<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 result:


Incorrect rendering on Windows Forms (C# .NET)

I am using Visual Studio 2017 Community, creating a Windows Forms Desktop Application.
Label components are using the "Noto Sans Javenese" font.

C# code:

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# result:


Questions

  1. What is the reason of this behavior? Can someone explain?
  2. What should I do to make the Javanese script "combined" correctly on Windows Form Application?

Thank you very much!

解决方案

I have gotten few options and insights to help resolve this problem. Apparently, this is only a problem with Windows Forms on Windows 7.

So far, my options are:

  1. Switch to WPF Application (best option, in my opinion)
  2. Use WPF Composite Control inside Windows Forms
  3. Render as bitmap using third-party libraries, for example: HarfBuzz


Here are the sources, credits goes to all respective authors:


  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

这篇关于Unicode 字形未在 Windows 窗体上正确组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆