检查字体是否支持某些字符 [英] Checking if certain characters are supported by a font
问题描述
但是,我还需要检查UTF-32字符。我想要做的是在unicode.org解析Unihan数据,并忽略Arial Unicode MS不支持的所有字符。我开始在CheckIfCharInFont()方法上工作,通过修改arg来取一个字符串(对于utf-32)并检查它是否是代理对。然后我通过做一个char.ConvertToUtf32(surrogate1,surrogate2)得到Int32,但问题是目前的CheckIfCharInFont()方法只支持Uint16 ...你可以看到我在哪里放置了一个Debugger.Break,这是一个有点的问题。有什么专家可以帮我把这件事情搞清楚吗?
$ b pre
pre $ code> 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();
返回false;
}
value =(UInt16)temp;
// UInt16 value = Convert.ToUInt16(character);
List< FontRange> ranges = GetUnicodeRangesForFont(font);
bool isCharacterPresent = false;
foreach(字符范围在范围内)
{
if(value> = range.Low&& value< = range.High)
{
isCharacterPresent = true;
break;
}
}
返回isCharacterPresent;
自己的东西。也许从规格开始( http://www.microsoft.com/typography/otspec/cmap .htm )
这是这个工具的功能: http://mihai-nita.net/2007/09/08/charmapex-some-kind-of-character-map/
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;
}
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/
这篇关于检查字体是否支持某些字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!