GraphicsPath AddString not support enough to the font when use right to left language if operating system lower than Win10

Viewed 478

I need to generate an image from a string in my WPF application, and show it. Here is my code:

// Create Image and generate string on it
System.Windows.Controls.Image img = new System.Windows.Controls.Image();


// This is the font that I need to render
Font DefaultFont = new Font("Oybab Tuz", 40f, System.Drawing.FontStyle.Regular, GraphicsUnit.Pixel);

// Generate image from string
GraphicsPath graphicsPath = new GraphicsPath();

// As you see, the string include Right to left character, also include some other character in the middle
graphicsPath.AddString("سىناق123456789سىناق", DefaultFont.FontFamily, (int)DefaultFont.Style, DefaultFont.Size * 96f / 72f, new PointF(0f, 0f), StringFormat.GenericDefault);

// Turn the string to the image
RectangleF bounds = graphicsPath.GetBounds();

Bitmap bitmap = new Bitmap((int)(bounds.Width + bounds.X), (int)(bounds.Height + bounds.Y));
Graphics graphic = Graphics.FromImage(bitmap);

graphic.FillPath(new SolidBrush(System.Drawing.Color.FromArgb(0x33, 0x00, 0xFF)), graphicsPath);
graphicsPath.Dispose();
graphic.Dispose();


// turn the Image to ImageSource
MemoryStream memoryStream = new MemoryStream();
bitmap.Save(memoryStream, ImageFormat.Png);

img.Source =  (ImageSource)(new ImageSourceConverter()).ConvertFrom(memoryStream);

// Add the image to the window content
this.Content = img;

Now this will display perfectly fine in windows 10, such like this:

In the windows 10 operating system

But, if the operating system lower than Windows 10, such like: Windows XP, Windows 7, Windows 8.X, it will display like this:

enter image description here

Also not only the number, if I put some other character such like :"&&"

"سىناق&&سىناق"

The lower operating system still shows it like:

"سىناق سىناق"

it seems like the operating system auto remove the characters in the middle.

I knew the font which I'm using is not include the number or the character which I put in it, But Windows 10 could display it right.

Here is the font: Download font file

Because the character will not only display in a specific place, so I can't split the string, and render it one by one.

So I really want to know why, also I hope some guys could give me advice to fix this problem when operating system lower than Windows 10. Thank you.

2 Answers
Related