Comment 0 for bug 1578749

Revision history for this message
Mingye Wang (artoria2e5) wrote :

libgdiplus' cairo backend only takes the fontconfig *match* to render glyphs in cairo, with zero considerations for substitutes. This causes significant problems when a developer using WinForms tries to display some CJK glyphs in "Sans", while expecting system-like handling for these bugs. Tofus will show up in such cases if the first candidate generated from `fc-match Sans` is not a font with CJK glyphs.

This modified version of WinForms 'hello world' should be able to show this bug:

```C#
using System;
using System.Drawing;
using System.Windows.Forms;

public class HelloWorld : Form
{
    static public void Main ()
    {
        Application.Run (new HelloWorld ());
    }

    public HelloWorld ()
    {
        Button b = new Button ();
        b.Text = "Tofus? → 我是方框。";
        b.Font = new Font("Sans", 11);
        b.Click += new EventHandler (Button_Click);
        Controls.Add (b);
    }

    private void Button_Click (object sender, EventArgs e)
    {
        MessageBox.Show ("Button Clicked!");
    }
}
```

Note this problem is not limited to "Sans", nor CJK chars -- I am just using these for a common-enough example. In real life developers trying to do cross-platform Winforms development might instead just use the default fonts ("MS Sans Serif" or "Tahoma" on Mono), and still bump into the very same blocks of tofu, perhaps with the emojis sent by their happy users.

A possible workaround is to try the experimental pango backend, but that is really very experimental. There is a pending PR at https://github.com/mono/libgdiplus/pull/39, which is said to be "basically approved" back in 2009. (Yeah, mono devs are getting tired of desktop it seems.)