コード例 #1
0
        public W2DFontStyle(W2DFontFamily family, string id, string name, string fullName, FontStyle style, FontWeight weight)
        {
            _family   = family;
            Id        = id;
            Name      = name;
            FullName  = fullName;
            StyleType = style.AsStyleType();
            Weight    = weight.Weight;

            NativeFontStyle  = style;
            NativeFontWeight = weight;
        }
コード例 #2
0
        public IFontFamily[] Initialize()
        {
            var familyList = new List <W2DFontFamily>();
            var families   = new Dictionary <string, W2DFontFamily>();

            var fontSet = CanvasFontSet.GetSystemFontSet();
            var fonts   = fontSet.Fonts;

            foreach (var fontFace in fonts)
            {
                if (fontFace.FamilyNames.TryGetValue("en-us", out var familyName))
                {
                    if (!families.TryGetValue(familyName, out var family))
                    {
                        family = new W2DFontFamily(familyName);
                        families[familyName] = family;
                        familyList.Add(family);
                    }

                    var postScriptName = familyName;

                    var localizedName = fontFace.GetInformationalStrings(CanvasFontInformation.PostscriptName);
                    var firstKey      = localizedName?.Keys.FirstOrDefault();
                    if (firstKey != null)
                    {
                        postScriptName = localizedName[firstKey];
                    }

                    if (fontFace.FaceNames.TryGetValue("en-us", out var name))
                    {
                        var fullName = familyName;

                        if (!("Regular".Equals(name) || "Plain".Equals(name) || "Normal".Equals(name)))
                        {
                            fullName = string.Format("{0} {1}", familyName, name);
                        }

                        var style = new W2DFontStyle(family, postScriptName, name, fullName, fontFace.Style, fontFace.Weight);
                        family.AddStyle(style);
                    }
                }
            }

            familyList.Sort();

            foreach (var family in familyList)
            {
                family.RemoveDuplicates();
            }

            return(familyList.OfType <IFontFamily>().ToArray());
        }