Exemplo n.º 1
0
        private void Init(Texture2D texture, FontData fontDesc, float spacing, char?defaultCharacter)
        {
            if (texture == null)
            {
                throw new ArgumentNullException(nameof(texture));
            }

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

            var characterMap = new Dictionary <char, FontGlyph>(fontDesc.Chars.Count);

            foreach (var fontCharacter in fontDesc.Chars)
            {
                var c = (char)fontCharacter.Id;
                characterMap.Add(c, fontCharacter);
            }

            _kerningMap = fontDesc.GenerateKerningMap();

            Characters       = new ReadOnlyDictionary <char, FontGlyph>(characterMap);
            Data             = fontDesc;
            DefaultCharacter = defaultCharacter;
            if (DefaultCharacter.HasValue && !characterMap.ContainsKey(DefaultCharacter.Value))
            {
                throw new ArgumentException("Given default character does not exist in the font.",
                                            nameof(defaultCharacter));
            }

            Spacing     = spacing;
            Texture     = texture;
            LineSpacing = fontDesc.Common.LineHeight;
        }
Exemplo n.º 2
0
        /// <summary> Initializes a new instance of the <see cref="BMFont" /> class. </summary>
        /// <param name="texture">Font texture.</param>
        /// <param name="fontDesc">BMFont description.</param>
        /// <param name="spacing">Text spacing.</param>
        /// <param name="defaultCharacter">CSharacter optionally used for resolving unknown characters.</param>
        /// <exception cref="ArgumentNullException"><paramref name="texture"/> is <see langword="null"/>
        /// -or- <paramref name="fontDesc"/> is <see langword="null"/></exception>
        public BMFont(Texture2D texture, FontData fontDesc, float spacing = 0,
            char? defaultCharacter = ' ')
        {
            if (texture == null) {
                throw new ArgumentNullException(nameof(texture));
            }

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

            Init(texture, fontDesc, spacing, defaultCharacter);
        }
Exemplo n.º 3
0
        /// <summary> Initializes a new instance of the <see cref="BMFont" /> class. </summary>
        /// <param name="texture">Font texture.</param>
        /// <param name="fontDesc">BMFont description.</param>
        /// <param name="spacing">Text spacing.</param>
        /// <param name="defaultCharacter">CSharacter optionally used for resolving unknown characters.</param>
        /// <exception cref="ArgumentNullException"><paramref name="texture"/> is <see langword="null"/>
        /// -or- <paramref name="fontDesc"/> is <see langword="null"/></exception>
        public BMFont(Texture2D texture, FontData fontDesc, float spacing = 0,
                      char?defaultCharacter = ' ')
        {
            if (texture == null)
            {
                throw new ArgumentNullException(nameof(texture));
            }

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

            Init(texture, fontDesc, spacing, defaultCharacter);
        }
Exemplo n.º 4
0
        private void Init(Texture2D texture, FontData fontDesc, float spacing, char? defaultCharacter)
        {
            if (texture == null) {
                throw new ArgumentNullException(nameof(texture));
            }

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

            var characterMap = new Dictionary<char, FontGlyph>(fontDesc.Chars.Count);
            foreach (var fontCharacter in fontDesc.Chars) {
                var c = (char)fontCharacter.Id;
                characterMap.Add(c, fontCharacter);
            }

            _kerningMap = fontDesc.GenerateKerningMap();

            Characters = new ReadOnlyDictionary<char, FontGlyph>(characterMap);
            Data = fontDesc;
            DefaultCharacter = defaultCharacter;
            if (DefaultCharacter.HasValue && !characterMap.ContainsKey(DefaultCharacter.Value)) {
                throw new ArgumentException("Given default character does not exist in the font.",
                    nameof(defaultCharacter));
            }

            Spacing = spacing;
            Texture = texture;
            LineSpacing = fontDesc.Common.LineHeight;
        }