由于缺少标准字体而崩溃 (VB.NET)
我们的自动崩溃报告系统已开始发送越来越多的此类崩溃报告:
System::Windows::Forms::Application::ThreadException event occured
SENDER: System.Threading.Thread
EXCEPTION: System.ArgumentException
MESSAGE: Font 'Arial' does not support style 'Regular'.
SOURCE: System.Drawing
CALL STACK
at System.Drawing.Font.CreateNativeFont()
at System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
at System.Drawing.Font..ctor(FontFamily family, Single emSize)
at Kernel.EH_FontServer.CreateFont(String family, Single size, FontStyle style) in **
at Kernel.EH_FontServer..cctor() in **
我的印象是 Arial 应该在 Windows 上随处可用,并且当找不到字体时,Windows 会恢复为另一种字体+确实存在的风格。
处理这个问题的正确方法是什么?我的应用程序需要为不同的显示元素定义许多标准字体。到目前为止,我已经对 Arial、Courier New、Comic Sans Serif 和 Times New Roman 进行了硬编码,并且我已经收到了所有这些字体的崩溃报告。
一旦用户安装了缺失的字体,一切就又恢复正常了。
Our automatic crash-report system has started sending in more and more reports of this kind of crash:
System::Windows::Forms::Application::ThreadException event occured
SENDER: System.Threading.Thread
EXCEPTION: System.ArgumentException
MESSAGE: Font 'Arial' does not support style 'Regular'.
SOURCE: System.Drawing
CALL STACK
at System.Drawing.Font.CreateNativeFont()
at System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
at System.Drawing.Font..ctor(FontFamily family, Single emSize)
at Kernel.EH_FontServer.CreateFont(String family, Single size, FontStyle style) in **
at Kernel.EH_FontServer..cctor() in **
I was under the impression that Arial is supposed to be available everywhere on Windows, and, when a Font cannot be found windows would revert to another font+style that does exist.
What is the correct way to handle this? My app needs to define a number of standard fonts for different display elements. So far I've hardcoded Arial, Courier New, Comic Sans Serif and Times New Roman and I've been getting crash report for all of them.
Once the user installs the missing Font, all is well again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
避免这种情况的一种方法是将字体直接嵌入到您的应用程序中。从许可角度来看,像 Arial 这样的核心 TTF 字体应该没问题:
阅读此内容以了解许可规范:
如何将字体嵌入到 VB.NET 应用程序中:
One way to avoid this is to embed the fonts directly into your application. Core TTF fonts like Arial should be okay from a licensing perspective:
Read this for licensing specs:
How to embed fonts into VB.NET apps: