获取字体的支持的字符 - 在C# [英] Get supported characters of a font - in C#

查看:582
本文介绍了获取字体的支持的字符 - 在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与我需要使用一个应用程序的日文字符支持第三方字体。每当一个字符不会用该字体的支持下,经常看到矩形(默认字符)绘制。显然,并非所有的日文字符支持,因为如果我试着画出我们的翻译办公室给我们的翻译,也有很多的矩形。

I have a third party font with support for japanese characters which I need to use for an application. Whenever a character is not supported by this font, the often seen rectangle ("default character") is drawn. Obviously not all japanese characters are supported, because if I try to draw the translations that our translation office gave us, there are a lot of rectangles.

我需要的时候使用了不支持的字符被通知,这样我就可以改变字体为这一个字符(如Word做它)或实施其他一些反应了这一点。

I need to be notified whenever a not supported character is used, so that I can change the font for this single character (like Word does it) or implement some other reaction to that.

任何想法?如果我能提取从TTF文件UNI code字符列表,那么我将能够检查使用的字符是否通过此列表覆盖。但我怎么能这样做呢?

Any ideas? If I could extract a list of unicode characters from the TTF file, then I would be able to check whether a used character is covered by this list. But how can I do so?

推荐答案

根据这个答案

请务必参考presentationCore.dll

Be sure to reference PresentationCore.dll

尝试使用这种code:

Try using this code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;

namespace fontChecker
{
    class Program
    {
        static void Main(string[] args)
        {
            var families = Fonts.GetFontFamilies(@"C:\WINDOWS\Fonts\Arial.TTF");
            foreach (FontFamily family in families)
            {
                var typefaces = family.GetTypefaces();
                foreach (Typeface typeface in typefaces)
                {
                    GlyphTypeface glyph;
                    typeface.TryGetGlyphTypeface(out glyph);
                    IDictionary<int, ushort> characterMap = glyph.CharacterToGlyphMap;

                    foreach (KeyValuePair<int, ushort> kvp in characterMap)
                    {
                        Console.WriteLine(String.Format("{0}:{1}", kvp.Key, kvp.Value));
                    }

                }
            }
        }
    }
}

输出的图像删除,由于ImageShack与广告取代旧,删除的图像。

Output image removed due to ImageShack replacing old, deleted image with an advert.

这篇关于获取字体的支持的字符 - 在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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