判断当前字体是否支持Unicode字符的简单方法? [英] Easy way to tell if unicode character is supported in current font?

查看:342
本文介绍了判断当前字体是否支持Unicode字符的简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Borland C ++ Builder 2009,并且像这样显示左右箭头:

I'm using Borland C++ Builder 2009 and I display the right and left pointing arrows like so:

Button2->Hint = L"Ctrl+\u2190" ;
Button3->Hint = L"Ctrl+\u2192" ; 

在Windows 7上运行良好,应用程序使用字体 Segoe UI。

This works fine on Windows 7, the application uses font 'Segoe UI'.

在XP上我得到一个正方形而不是箭头,在XP上我使用了字体 Tahoma。
换句话说,提到的Unicode字符在XP的Tahoma中不存在。

On XP I get a square instead of the arrows, I use font 'Tahoma' on XP. In other words mentioned Unicode characters are not present in Tahoma on XP.

是否有一种简便快捷的方法来简单地检查是否支持所请求的Unicode字符在当前使用的字体中?
如果可以,例如,可以将箭头替换为>或<。不完美,但足够好。我不想在这个阶段开始更改字体。

Is there an easy and fast way to simply check if the requested Unicode character is supported in the currently used font ? If so I could, for instance, replace the arrow with '>' or '<'. Not perfect, but good enough. I don't want to start changing fonts at this stage.

我们非常感谢您的帮助。

Your help appreciated.

推荐答案

您可以使用 GetFontUnicodeRanges() 可以查看DC中当前选择的字体支持哪些字符。请注意,此API需要您调用一次以找出缓冲区的大小,然后再次调用它来实际获取数据。

You can use GetFontUnicodeRanges() to see which characters are supported by the font currently selected into the DC. Note that this API requires you to call it once to find out how big the buffer needs to be, and a second time to actually get the data.

DWORD dwSize = GetFontUnicodeRanges(hDC, nullptr);
BYTE* bBuffer = new BYTE[dwSize];
GLYPHSET* pGlyphSet = reinterpret_cast<GLYPHSET*>(bBuffer);
GetFontUnicodeRanges(hDC, pGlyphSet);
// use data in pGlyphSet, then free the buffer
delete[] bBuffer;

GLYPHSET 结构的成员数组名为 ranges ,可让您确定字体支持的字符范围。

The GLYPHSET structure has a member array called ranges which lets you determine the range of characters supported by the font.

这篇关于判断当前字体是否支持Unicode字符的简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆