如果操作系统低于Win10,则在使用从右到左语言时,GraphicsPath AddString对字体的支持不足

qak*_*mak 7 .net c# windows gdi+ gdi

我需要generate an image from a string在我的WPF应用程序中显示它.这是我的代码:

// Create Image and generate string on it
ystem.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;
Run Code Online (Sandbox Code Playgroud)

现在这将显示完美windows 10,如下所示:

在windows 10操作系统中

但是,如果操作系统下比Windows 10,这样,如:Windows XP,Windows 7,Windows 8.X,它会显示如下:

在此输入图像描述

不仅是数字,如果我把其他一些字符如:"&&"

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

较低的操作系统仍然显示如下:

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

好像操作系统会自动删除中间的字符.

我知道我在其中使用的字体is not include the number or the character which I put,但Windows 10可以正确显示它.

这是字体:下载字体文件

因为角色不仅会在特定的地方展示,所以I can't split the string, and render it one by one.

所以,我真的很想知道why,也I hope some guys could give me advice to fix this problem when operating system lower than Windows 10.谢谢.

小智 -1

我发现过去有以下问题:

GraphicsPath.AddString() 中具有某些字体和字符的通用 GDI+ 异常

可能在旧版本的 Windows 中您会遇到一些问题,有一个特定知识库的链接可以修复它- 值得尝试:)

顺便说一句,您是否尝试过使用其他字体类型或更改字体类型只是为了检查是否会发生变化。

希望有帮助

阿萨夫