Пример #1
0
        private FontStyle SelectEffectiveStyle(string fontName, FontStyle fontStyle)
        {
            FontFamily fontFamily;

            try
            {
                fontFamily = ThemeResolutionService.GetCustomFont(fontName) ?? new FontFamily(fontName);
            }
            catch
            {
                return(FontStyle.Regular);
            }
            FontStyle style = fontStyle;

            if (fontFamily.IsStyleAvailable(style))
            {
                return(style);
            }
            FontStyle        fontStyle1    = FontStyle.Bold | FontStyle.Italic;
            FontStyle        fontStyle2    = style & fontStyle1;
            List <FontStyle> fontStyleList = new List <FontStyle>(4);

            if (fontStyle2 != fontStyle1)
            {
                fontStyleList.Add(FontStyle.Regular);
                fontStyleList.Add(FontStyle.Italic);
                fontStyleList.Add(FontStyle.Bold);
            }
            else
            {
                fontStyleList.Add(fontStyle1);
                fontStyleList.Add(FontStyle.Bold);
                fontStyleList.Add(FontStyle.Italic);
                fontStyleList.Add(FontStyle.Regular);
            }
            fontStyleList.Remove(fontStyle2);
            for (int index = 0; index < fontStyleList.Count; ++index)
            {
                if (fontFamily.IsStyleAvailable(fontStyleList[index]))
                {
                    fontStyle2 = fontStyleList[index];
                    break;
                }
            }
            fontStyle &= FontStyle.Underline | FontStyle.Strikeout;
            return(fontStyle | fontStyle2);
        }