How to draw unicode string using C# graphics.DrawString

佐手、 提交于 2020-06-12 06:24:09

问题


I'm trying to send khmer script(unicode) string to printer using PrintDocument provided by the .NET framework.

Unfortunately it seems to me that the Graphics.DrawString() does not render khmer script correctly.

Platform: Windows 7 Ultimate
IDE: VS 2010 Ultimate

Here is the sample code:

void printDoc_PrintPage(object sender, PrintPageEventArgs e)
{
  var font = new Font("Khmer UI", 12);
  var text = "សួស្តី"; // "Hello"
  e.Graphics.DrawString(text, font, Brushes.Black, 100, 100);
}

回答1:


mann,
I tested your code on a Form_Paint() handler, and I got exactly what you said.
But when I used this instead:

TextRenderer.DrawText(e.Graphics, text, font, new Point(100, 100), Color.Black);  

It gave me the text the way you wanted it.
Try that on your printDoc_PrintPage().

alt text




回答2:


Thanks Albin and Beemer for your active response.

After a few posts in c# google group. It's been confirmed that there is a bug in GDI+ that incorrectly show certain script ("Khmer" in this case) to a different wording.

A native win32 test application was created to verify the issue with GDI+ DrawString().

A bug report has been submitted to Microsoft Connect: http://connect.microsoft.com/VisualStudio/feedback/details/620081/



来源:https://stackoverflow.com/questions/4116956/how-to-draw-unicode-string-using-c-sharp-graphics-drawstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!