예제 #1
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());
        }
예제 #2
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }
            if (obj.GetType() != typeof(W2DFontStyle))
            {
                return(false);
            }
            W2DFontStyle other = (W2DFontStyle)obj;

            return(Id == other.Id);
        }
예제 #3
0
 internal void AddStyle(W2DFontStyle style)
 {
     _fontStyles = null;
     _styleList.Add(style);
 }