private void SearchCharacter()
{
string targetCharacter = "\u207B";
foreach (FontFamily fontFamily in Fonts.SystemFontFamilies)
{
GlyphTypeface glyphTypeface;
if (TryLoadGlyphTypeface(fontFamily, out glyphTypeface))
{
if (glyphTypeface.CharacterToGlyphMap.ContainsKey(targetCharacter[0]))
{
Console.WriteLine($"The font \"{fontFamily}\" contains the character \"{targetCharacter}\".");
}
else
{
Console.WriteLine($"The font \"{fontFamily}\" does not contain the character \"{targetCharacter}\".");
}
}
else
{
Console.WriteLine($"Failed to load the font \"{fontFamily}\".");
}
}
}
static bool TryLoadGlyphTypeface(FontFamily fontFamily, out GlyphTypeface glyphTypeface)
{
glyphTypeface = null;
try
{
Typeface typeface = new Typeface(fontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
return typeface.TryGetGlyphTypeface(out glyphTypeface);
}
catch
{
return false;
}
}
此代码由chatGPT生成,本人优化debug,示例字符是u207B,即上标减号