示例#1
0
        public BakedCharCollection(char firstCodepoint, BakedChar[] characters,
                                   int bakeWidth, int bakeHeight)
        {
            if (characters == null)
            {
                throw new ArgumentNullException("characters");
            }

            Dictionary <char, BakedChar> dictionary = new Dictionary <char, BakedChar>();

            for (int i = 0; i < characters.Length; i++)
            {
                char codepoint = (char)(firstCodepoint + i);
                if (char.IsSurrogate(codepoint))
                {
                    continue;
                }

                BakedChar character = characters[i];
                if (character.IsEmpty)
                {
                    continue;
                }

                dictionary[codepoint] = character;
            }
            Create(dictionary, bakeWidth, bakeHeight);
        }
示例#2
0
        public int BakeFontBitmap(float xScale, float yScale, char firstCodepoint,
            BakedChar[] characters, FontBitmap bitmap)
        {
            if (!bitmap.IsValid) { throw new ArgumentException("bitmap"); }
            if (characters == null) { throw new ArgumentNullException("characters"); }

            return stb_truetype.stbtt_BakeFontBitmap(ref _info, xScale, yScale,
                bitmap.StartPointer, bitmap.Width, bitmap.Height, bitmap.Stride,
                (int)firstCodepoint, characters.Length,
                new FakePtr<BakedChar>() { Array = characters });
        }
示例#3
0
        // generates square textures ... minimalHeight can be used to crop if desired
        public FontBitmap BakeFontBitmap(float pixelHeight, char firstCodepoint,
            BakedChar[] characters, out int minimalHeight)
        {
            int size = 16;
            if (characters.Length == 0) { minimalHeight = 0; return new FontBitmap(0, 0); }

            while (true)
            {
                var bitmap = new FontBitmap(size, size);
                int result = BakeFontBitmap(pixelHeight, firstCodepoint, characters, bitmap);
                if (result > 0) { minimalHeight = result; return bitmap; }

                size *= 2;
            }
        }
示例#4
0
        public BakedCharCollection(char firstCodepoint, BakedChar[] characters,
            int bakeWidth, int bakeHeight)
        {
            if (characters == null) { throw new ArgumentNullException("characters"); }

            Dictionary<char, BakedChar> dictionary = new Dictionary<char, BakedChar>();
            for (int i = 0; i < characters.Length; i++)
            {
                char codepoint = (char)(firstCodepoint + i);
                if (char.IsSurrogate(codepoint)) { continue; }

                BakedChar character = characters[i];
                if (character.IsEmpty) { continue; }

                dictionary[codepoint] = character;
            }
            Create(dictionary, bakeWidth, bakeHeight);
        }
        public FontBitmap BakeFontBitmap(float pixelHeight, char firstCodepoint,
                                         int characterCount, out BakedCharCollection characters, bool shrinkToMinimalHeight)
        {
            if (characterCount < 0)
            {
                throw new ArgumentOutOfRangeException("characterCount");
            }

            var charArray = new BakedChar[characterCount]; int minimalHeight;
            var bitmap = BakeFontBitmap(pixelHeight, firstCodepoint, charArray, out minimalHeight);

            if (shrinkToMinimalHeight)
            {
                bitmap.Height = minimalHeight; bitmap = bitmap.GetTrimmedBitmap();
            }

            characters = new BakedCharCollection(firstCodepoint, charArray, bitmap.Width, bitmap.Height);
            return(bitmap);
        }
示例#6
0
 public int BakeFontBitmap(float pixelHeight, char firstCodepoint,
     BakedChar[] characters, FontBitmap bitmap)
 {
     float scale = GetScaleForPixelHeight(pixelHeight);
     return BakeFontBitmap(scale, scale, firstCodepoint, characters, bitmap);
 }
示例#7
0
        public FontBitmap BakeFontBitmap(float pixelHeight, char firstCodepoint,
            int characterCount, out BakedCharCollection characters, bool shrinkToMinimalHeight)
        {
            if (characterCount < 0) { throw new ArgumentOutOfRangeException("characterCount"); }

            var charArray = new BakedChar[characterCount]; int minimalHeight;
            var bitmap = BakeFontBitmap(pixelHeight, firstCodepoint, charArray, out minimalHeight);
            if (shrinkToMinimalHeight) { bitmap.Height = minimalHeight; bitmap = bitmap.GetTrimmedBitmap(); }

            characters = new BakedCharCollection(firstCodepoint, charArray, bitmap.Width, bitmap.Height);
            return bitmap;
        }