为什么基于不存在的 FontFamily 创建字体会起作用?

发布于 2024-12-29 19:42:51 字数 480 浏览 3 评论 0原文

我正在使用 Gdi+ 绘制一些文本,并尝试确保我创建的字体确实存在。我注意到无论我指定什么字体它都可以工作。我有以下代码:

Font font(TEXT("SomeGibberishFOEIHSFUE"), 12, 0, UnitPoint);

if (!font.IsAvailable())
    exit(0);

// draw text

我的系统上没有安装名为 SomeGibberishFOEIHSFUE 的字体,但 IsAvailable 返回 TRUE 并且程序运行并绘制文本使用看起来像 Arial 的字体而不是退出。这是为什么呢?

如果我使用 IsAvailable 错误,我应该使用什么函数来判断 Font 创建是否成功?我还尝试了 GetLastStatus ,它返回 Ok

I am drawing some text with Gdi+ and I'm trying to make sure the Font I create actually exists. I noticed that it was working no matter what font I specified. I have the following code:

Font font(TEXT("SomeGibberishFOEIHSFUE"), 12, 0, UnitPoint);

if (!font.IsAvailable())
    exit(0);

// draw text

I have no font installed on my system called SomeGibberishFOEIHSFUE, but IsAvailable returns TRUE and the program runs and draws the text with a font that looks like Arial instead of exiting. Why is this?

If I am using IsAvailable wrong, what function should I use to tell whether the creation of a Font succeeded or not? I have also tried GetLastStatus which returns Ok.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪少女 2025-01-05 19:42:51

这就是 Windows 字体映射器在工作,如果它无法提供所请求的字体,它总是会找到一种替代字体。如有必要,回退到默认 GUI 字体。您可以改用 FontFamily 类。当您使用其构造函数并传递不存在的字体时,它的 .NET 版本(看起来您正在使用它)将抛出 ArgumentException。它的本机 GDI+ 版本有一个 IsAvailable()方法。是的,有点奇怪的行为,但这在 GDI+ 中并不罕见。

That's the Windows font mapper at work, it will always find a substitute font if it cannot supply the requested one. Falling back to the default GUI font if necessary. You could use the FontFamily class instead. The .NET version of it (looks like you're using it) will throw an ArgumentException when you use its constructor and pass a non-existing font. The native GDI+ version of it has an IsAvailable() method. Yes, kinda screwy behavior but that's not unusual in GDI+.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文