示例#1
0
 public CollectionFont(FontCollectionType fontCollection)
 {
     LatinFont         = fontCollection.LatinFont.Typeface;
     EastAsianFont     = fontCollection.EastAsianFont.Typeface;
     ComplexScriptFont = fontCollection.ComplexScriptFont.Typeface;
     SupplementalFonts = fontCollection.Elements <SupplementalFont>().ToDictionary(sf => sf.Script.ToString(), sf => sf.Typeface.ToString());
 }
示例#2
0
        private static string GetFontFromFontCollection(string scriptTag, FontLang themeTypefaceFontLang,
                                                        FontCollectionType fontCollection)
        {
            if (fontCollection == null)
            {
                return(string.Empty);
            }

            // 假定存在对应的语言的字体,那么获取对应的字体
            // 存放方式如

            /*
             * <a:majorFont xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
             *  <a:latin typeface="Calibri Light" panose="020F0302020204030204" />
             *  <a:ea typeface="" />
             *  <a:cs typeface="" />
             *  <a:font script="Jpan" typeface="MS Pゴシック" />
             *  <a:font script="Hang" typeface="맑은 고딕" />
             *  <a:font script="Hans" typeface="宋体" />
             * </a:majorFont>
             * <a:minorFont xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
             *  <a:latin typeface="Calibri" panose="020F0502020204030204" />
             *  <a:ea typeface="" />
             *  <a:cs typeface="" />
             *  <a:font script="Jpan" typeface="MS Pゴシック" />
             *  <a:font script="Hang" typeface="맑은 고딕" />
             *  <a:font script="Hans" typeface="宋体" />
             * </a:minorFont>
             */

            foreach (var font in fontCollection.Elements <SupplementalFont>())
            {
                // <a:font script="Hang" typeface="맑은 고딕" />
                if (string.Equals(font.Script, scriptTag, StringComparison.OrdinalIgnoreCase))
                {
                    return(font.Typeface);
                }
            }

            // 也就是先尝试获取语言文化的,如果获取不到,就采用对应语言的
            TextFontType textFont = null;

            switch (themeTypefaceFontLang)
            {
            case FontLang.LatinFont:
                textFont = fontCollection.LatinFont;
                break;

            case FontLang.EastAsianFont:
                textFont = fontCollection.EastAsianFont;
                break;

            case FontLang.ComplexScriptFont:
                textFont = fontCollection.ComplexScriptFont;
                break;

            case FontLang.SymbolFont:
                // 特别不处理,为什么?
                // 在 fontCollection 是不存在的 SymbolFont 的
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(themeTypefaceFontLang), themeTypefaceFontLang, null);
            }

            var typeface = textFont?.Typeface?.Value;

            if (!string.IsNullOrEmpty(typeface))
            {
                return(typeface);
            }

            Debug.Assert(false, "找不到字体");

            return(null);
        }