获得 glyph id 与 Unicode 对照表

简单例子,C#程序,获得 某个TTF字体glyph id 与 Unicode 对照表。代码来自网上,仅供参考。

 

 1 private void buttong2u_Click(object sender, EventArgs e)
 2         {
 3             //glyph id 2 unicode
 4             //将字体的 glyph id 转换成 unicode 编码
 5             var families = Fonts.GetFontFamilies(@"C:\WINDOWS\Fonts\Arial.TTF");
 6 
 7             Dictionary<ushort, int> sumMap = new Dictionary<ushort,int>();
 8 
 9             foreach (var family in families)
10             {
11                 var typefaces = family.GetTypefaces();
12                 foreach (Typeface typeface in typefaces)
13                 {
14                     GlyphTypeface glyph;
15                     typeface.TryGetGlyphTypeface(out glyph);
16                     IDictionary<int, ushort> characterMap = glyph.CharacterToGlyphMap;
17                     characterMap = glyph.CharacterToGlyphMap;
18                     foreach (KeyValuePair<int, ushort> kvp in characterMap)
19                     {
20                         if (!sumMap.ContainsKey(kvp.Value) && !sumMap.ContainsValue(kvp.Key) )
21                             sumMap.Add(kvp.Value, kvp.Key);//调对一下 Value:glyphid / Key:unicode
22                         //Console.WriteLine(String.Format("Unicode:{0:X} / GlyphId:{1:X}", kvp.Key, kvp.Value)); //可以看到,大量的重复
23                     }
24                 }
25             }
26             
27             foreach (KeyValuePair<ushort,int> kvp in sumMap )
28             {
29                 //glyphid / unicode
30                 Console.WriteLine(String.Format("{0:X} / {1:X}", kvp.Key, kvp.Value));
31             }

 

上一篇:C/C++编程笔记:如何在C++中标记字符串?四种方法告诉你


下一篇:C 库函数 - strtok()