检查字体是否支持某些字符
我在 StackOverflow 上找到了这个: 有没有办法以编程方式确定字体文件是否具有特定的 Unicode 字形?
但是,我还需要检查 UTF-32 字符。我想做的是解析 unicode.org 上的 Unihan 数据,并忽略“Arial Unicode MS”不支持的所有字符。我开始研究 CheckIfCharInFont() 方法,方法是修改 arg 以采用字符串(对于 utf-32)并检查它是否是代理对。然后我通过执行 char.ConvertToUtf32(surrogate1, surrogate2) 获得 Int32,但问题是当前的 CheckIfCharInFont() 方法仅支持 Uint16...你可以看到我在哪里放置了“Debugger.Break”,这有点的一个问题。有哪位专家可以帮我解决这个问题吗?
谢谢
public static bool CheckIfCharInFont(string character, Font font)
{
UInt16 value = 0;
int temp = 0;
if (character.Length > 1) //UTF-32
{
temp = char.ConvertToUtf32(character[0], character[1]);
}
else
{
temp = (int)character[0];
}
if (temp > UInt16.MaxValue)
{
Debugger.Break();
return false;
}
value = (UInt16)temp;
//UInt16 value = Convert.ToUInt16(character);
List<FontRange> ranges = GetUnicodeRangesForFont(font);
bool isCharacterPresent = false;
foreach (FontRange range in ranges)
{
if (value >= range.Low && value <= range.High)
{
isCharacterPresent = true;
break;
}
}
return isCharacterPresent;
}
I found this on StackOverflow: Is there a way to programmatically determine if a font file has a specific Unicode Glyph?
However, I need to also check UTF-32 characters. What I am trying to do is parse the Unihan data over at unicode.org and ignore all characters that are not supported by "Arial Unicode MS". I started work on the CheckIfCharInFont() method by modifying the arg to take a string (for utf-32) and checking if it is a surrogare pair. I then get the Int32 by doing a char.ConvertToUtf32(surrogate1, surrogate2), but the problem is the current CheckIfCharInFont() method only supports Uint16... you can see where I placed a "Debugger.Break" that this is a bit of a problem. Any experts out there that can help me figure this thing out?
Thanks
public static bool CheckIfCharInFont(string character, Font font)
{
UInt16 value = 0;
int temp = 0;
if (character.Length > 1) //UTF-32
{
temp = char.ConvertToUtf32(character[0], character[1]);
}
else
{
temp = (int)character[0];
}
if (temp > UInt16.MaxValue)
{
Debugger.Break();
return false;
}
value = (UInt16)temp;
//UInt16 value = Convert.ToUInt16(character);
List<FontRange> ranges = GetUnicodeRangesForFont(font);
bool isCharacterPresent = false;
foreach (FontRange range in ranges)
{
if (value >= range.Low && value <= range.High)
{
isCharacterPresent = true;
break;
}
}
return isCharacterPresent;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你必须做你自己的事情。也许从规范开始(http://www.microsoft.com/typography/otspec/cmap .htm)
这就是这个工具的作用:http://mihai-nita.net/2007/09/08/charmapex-some-kind-of-character-map/
You would have to do your own thing. Maybe starting from the specs (http://www.microsoft.com/typography/otspec/cmap.htm)
It is what this tool does: http://mihai-nita.net/2007/09/08/charmapex-some-kind-of-character-map/