【发布时间】:2019-12-08 14:19:08
【问题描述】:
这是我测试中 csharp 代码的奇怪行为之一。
我使用 DrawString 方法在 Times New Roman 字体下绘制一些 unicode 字符。但是,我可以绘制一些字符,但有些字符只是绘制为空白方块(即不支持的字符。
更详细地说,我可以使用 DrawString 方法毫无问题地绘制 42 (*) 和 43 (+)。
但我不能画9978和9900。9978和9900都是Times New Roman支持的字符。在此处检查字体映射。
https://www.martinstoeckli.ch/fontmap/fontmap.html
供您参考,当我尝试在文本框窗口控件中打印相同的字符时,一切正常。文本框显示所有支持的字符,包括 9978 和 9900。
但是,只是这个DrawString方法在我的测试下是不一致的。为什么我不能使用 DrawString 方法在字体下绘制这些支持的字符?
int unicodeIndex = 10728;
this._provider = new CultureInfo("en-us");
string unicodeString = ((char)unicodeIndex).ToString(_provider);
this.Font = new Font("Times New Roman", 10);
int x = 200;
int y = 200;
SizeF sizef = g.MeasureString(unicodeString+"W", this.Font, new PointF(x, y), _sformat);
int w = Convert.ToInt32(sizef.Width) + 2;
int h = Convert.ToInt32(sizef.Height) + 2;
RectangleF rectf = new RectangleF(x, y-h/2, w, h);
g.DrawString(unicodeString, this.Font, myBrush, rectf, myFormat);
这里有更多线索,因为这似乎是一个棘手的问题。
我目前正在使用安装在我的 Window 上的东亚语言包。 安装在我的窗口上的东亚语言包有没有可能导致这个问题?例如,在中文和日文的本地化窗口中,“Times New Roman”字体可能无法正确调用?只是猜测。
【问题讨论】:
-
9978 是点,9900 是波斯字符。将字体更改为“Tahoma”,然后重试。
-
我改为“Tahoma”,但它不起作用。我只看到空白方块。但是,42 (*) 和 43 (+) 在“Tahoma”字体下工作正常。