Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BitmapFont" /> class.
        /// </summary>
        /// <param name="fontName">The font name.</param>
        /// <param name="fontSize">The font size.</param>
        /// <param name="fontStyle">The font style.</param>
        /// <param name="characters">The included characters.</param>
        public BitmapFont(string fontName, float fontSize, FontStyle fontStyle, string characters)
        {
            if (fontName == null)
            {
                throw new ArgumentNullException(nameof(fontName));
            }

            if (characters == null)
            {
                throw new ArgumentNullException(nameof(characters));
            }

            if (characters.Length == 0)
            {
                throw new ArgumentException("Font must include at least one character.", nameof(characters));
            }

            Array.Sort(this.characters = characters.ToCharArray());
            this.glyphs = new BitmapGlyph[this.characters.Length];
            this.whitespace = new BitmapGlyph(this.Texture, null, null) { Width = 0, Height = 0, MinU = 0, MinV = 0, MaxU = 0, MaxV = 0 };

            var font = new Font(fontName, fontSize, fontStyle);
            var lineHeight = font.GetHeight();
            var descent = font.GetDescentHeight();
            var baseline = descent * DescentFactor;
            var ascent = (lineHeight - baseline) * AscentFactor;

            this.LineHeight = lineHeight;
            this.Ascent = ascent;
            this.Descent = descent;
            this.Baseline = baseline;
            this.Ready = this.Load(font); // <- Load will dispose of the font.
        }