需要帮助来使用 GDI 显示日语文本 在 Windows XP 中无需安装东亚语言包
我正在编写一个日语测验程序,我不想要求人们安装 Windows XP 的东亚语言包。 我正在使用 GDI+ 来绘制文本。 我尝试下载免费的 Unicode 字体并使用它来绘制文本。 我在我的计算机上测试了它(安装了东亚包),它使用下载的字体正确显示了日语字符,但在另一台没有语言包的计算机上它不起作用。
我正在寻找有关如何开展这项工作的建议。 该程序非常简单,仅使用 Win32 API、GDI+ 和 STL 用 C++ 编写。 如果可能的话,我想只使用这些库。 我确实有 UNICODE #define。
我基本上用于绘制文本的代码粘贴在下面:
#include <gdiplus.h>
using namespace Gdiplus ;
Graphics * gi ;
PrivateFontCollection _fonts ;
_fonts.AddFontFile(fontFilename) ;
Font * currentFont = new Font(fontName, fontSize, FontStyleRegular, UnitPoint, &_fonts) ;
std::wstring text = L"Some text" ;
gi->DrawString(text.c_str(), (INT)text.size(), currentFont, rectangle, &format, &brush) ;
I am writing a Japanese language quiz program and I don't want to require people to install the East Asian language pack for Windows XP. I am using GDI+ for drawing text. I tried downloading a free Unicode font and using that to draw text. I tested it on my computer (with East asian pack installed) and it displayed the Japanese characters correctly using the downloaded font, but on another computer without the language pack it didn't work.
I am looking for suggestions on how to make this work. The program is pretty simple and is written in C++ using only Win32 API, GDI+, and STL. If possible I would like to stick to just these libraries. I do have UNICODE #defined.
The code that I am basically using for drawing text is pasted below:
#include <gdiplus.h>
using namespace Gdiplus ;
Graphics * gi ;
PrivateFontCollection _fonts ;
_fonts.AddFontFile(fontFilename) ;
Font * currentFont = new Font(fontName, fontSize, FontStyleRegular, UnitPoint, &_fonts) ;
std::wstring text = L"Some text" ;
gi->DrawString(text.c_str(), (INT)text.size(), currentFont, rectangle, &format, &brush) ;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决方案相当简单。 由于您不想发送字体,并且不能指望任何可用的字体,因此您必须发送要使用的所有字符的图像。 我建议使用 PNG,因为 JPEG 是针对照片的(很多小渐变)
The solution is fairly easy. Since you don't want to ship the font, and you can't count on any font being available, you will have to ship images of all characters you want to use. I suggest to use PNG, as JPEG is aimed at photos (lots of small gradients)
我错了。 如果您的字体包含日语字符,即使未安装东亚语言包,它也会在 Windows XP 中正确显示。
如果您安装了东亚语言包,并且您的字体不支持日语字符,Windows 将从它认为与您的字体最匹配的两种字体中进行选择。 这让我认为我使用的字体包含日语字符,因为当我在字体和系统字体之间切换时,它会改变字符的绘制方式。
Microsoft 有一个免费安装的日语字体,名为 Meiryo Collection 版本 5.00。 这里还有一个 页面 列出了更多日语字体,列出的字体的唯一问题是许可不明确。
I was wrong. If you have a font that includes Japanese Characters it will display correctly in Windows XP even if East Asian language Pack is not installed.
If you have the East Asian Language Pack installed and if your font doesn't support Japanese characters, Windows will pick from between one of two fonts that it thinks matches your font the closest. This caused me to think that the fonts I was using included Japanese characters since it would change the way the characters were drawn when I switched between my font and the system font.
Microsoft has a free to install Japanese font called Meiryo Collection Version 5.00. Also here is a page listing more Japanese fonts , The only problem with the fonts listed is the licensing is not clear.
还有一种名为 Lucida Sans Unicode 的字体可能有助于缓解问题。
There is also a font called Lucida Sans Unicode which may help to alleviate problems.