Exemplo n.º 1
0
        public NativeFont_(string name, int height, FontStyle style = default, bool calculateHeightOnScreen = false)
        {
            using var dcs = new ScreenDC_(0);
            int h2 = -AMath.MulDiv(height, Api.GetDeviceCaps(dcs, 90), 72);             //LOGPIXELSY=90

            Handle = Api.CreateFont(h2,
                                    cWeight: style.Has(FontStyle.Bold) ? 700 : 0, //FW_BOLD
                                    bItalic: style.Has(FontStyle.Italic) ? 1 : 0,
                                    bUnderline: style.Has(FontStyle.Underline) ? 1 : 0,
                                    bStrikeOut: style.Has(FontStyle.Strikeout) ? 1 : 0,
                                    iCharSet: 1,
                                    pszFaceName: name);
            if (calculateHeightOnScreen)
            {
                using var dcMem = new CompatibleDC_(dcs);
                var of = Api.SelectObject(dcMem, Handle);
                Api.GetTextExtentPoint32(dcMem, "A", 1, out var z);
                HeightOnScreen = z.height;
                Api.SelectObject(dcMem, of);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Join specified font style names
        /// </summary>
        /// <param name="style">font style flag</param>
        /// <param name="regularText">name for regular style</param>
        /// <param name="italicText">name for italic style</param>
        /// <param name="boldText">name for bold style</param>
        /// <returns>joined font style</returns>
        public static string GetFontStyleName(FontStyle style, string regularText,
                                              string italicText, string boldText)
        {
            List <string> names = new List <string>();

            if (style.Has(FontStyle.Bold))
            {
                names.Add(boldText);
            }
            if (style.Has(FontStyle.Italic))
            {
                names.Add(italicText);
            }

            if (names.Count == 0)
            {
                return(regularText);
            }
            else
            {
                return(string.Join(" ", names.ToArray()));
            }
        }
Exemplo n.º 3
0
        public static string GetFontStyleName(FontStyle style, string regularText,
            string italicText, string boldText)
        {
            List<string> names = new List<string>();

            if (style.Has(FontStyle.Bold))
            {
                names.Add(boldText);
            }
            if (style.Has(FontStyle.Italic))
            {
                names.Add(italicText);
            }

            if (names.Count == 0)
                return regularText;
            else
                return string.Join(" ", names.ToArray());
        }