粗体字体呈现错误

时间:2014-12-01 20:14:16

标签: c# wpf windows winforms

当我尝试渲染中文字符串时,如试标记好不好Graphics.DrawString绘制它

enter image description here

即使我将字体链接更改为SimSun。另一方面,TextRenderer可以工作,但在使用粗体字体时无法呈现可读字符串。似乎没有正确的方法来呈现粗体字符串。

enter image description here

更详细地描述了该问题here。我做错了什么,或者Windows不支持在UI中使用一些粗体字符串的专业外观可本地化应用程序?

重现问题的代码适用于带有两个PictureBox的Windows窗体应用程序:

    const string combined = "测试标记好不好This is a aber long";

    private void cFontSize_ValueChanged(object sender, EventArgs e)
    {
        Bitmap bmp = new Bitmap(750, 140);
        Font f = new Font("Arial", (float)cFontSize.Value, IsBold ? FontStyle.Bold : FontStyle.Regular);

        using (var g = Graphics.FromImage(bmp))
        {
            g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

            // Rendering with a Background Color solves the issue but 
            // this would produce boxes of white or black color in the displayed image which looks even worse
            TextRenderer.DrawText(g, combined, f, new Point(0, 0), FontColor);
        }
        cPictureBox.Image = bmp;

        Bitmap bmp2 = new Bitmap(750, 140);

        using (var g = Graphics.FromImage(bmp2))
        {
            g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
            g.DrawString(combined, f, FontBrush, 0, 0);
        }

        cPicture2.Image = bmp2;
    }

更新1:

当我将字体链接设置添加到HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ FontLink \ SystemLink

Arial Bold
   SIMSUNB.TTC,SimSun Bold
   MSGOTHIC.TTC,MS UI Gothic

然后Graphics.DrawString现在看起来不错了,现在TextRender会出现问题。重新启动应用程序后,现在两个输出看起来都是字体确定好的,尽管TextRenderer仍然存在粗体字体由于黑色抗锯齿而变得不可读的问题。我将重新启动机器以检查任何缓存效果。

0 个答案:

没有答案