Search code examples
c#drawstringprintdocument

How to draw unicode string using C# graphics.DrawString


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);
}

Solution

  • 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/