4

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);
}
3
  • How does it appear then? Commented Nov 7, 2010 at 8:21
  • how do you define "not correctly" ? Commented Nov 7, 2010 at 8:32
  • instead of displaying "សួស្តី" you would see "សួស្​តី" Commented Nov 7, 2010 at 8:35

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

7 Comments

That because Graphics class use GDI+ and TextRenderer class use GDI to do the rendering. Unfortunately TextRenderer class does not support for printing. msdn.microsoft.com/en-us/library/ms171753.aspx
Hi sir, I accept your recommend. But when I try your code, I am very difficult to set location in New Point(100,100). It means that can I set New Point as Milimeter of Document. Let say, I want to print on A4 paper. How can I print to the point that I want.
@Sopolin -- you'll have to calculate that. You need to convert millimeters into pixels. By default, there are 72 pixels per inch. There are 25.4mm per inch, which means the resolution is 72 pixels per 25.4mm. Therefore, for example, if you want to start drawing at 50mm, then you need to draw at pixel 142, as calculated by 50 * (72/25.4).
Thank you sir, but I still can't because I use Paper A4 to print text out. It shows different location, even though I print what you have guide me. Let say, I print (x,y) in milimeter (17,35) convert to pixels (x,y) (48,99). It doesn't print text to location on paper that I want.
@Sopolin -- Are you factoring in the margins of the paper? Make sure you don't have any margin settings there that shift your numbers over. And the question is, where does the (17,35) show? Too far to the bottom? Too far to the right? How much off is it?
|
1

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.