public int BakeFontBitmap(float pixelHeight, char firstCodepoint,
                                  BakedChar[] characters, FontBitmap bitmap)
        {
            float scale = GetScaleForPixelHeight(pixelHeight);

            return(BakeFontBitmap(scale, scale, firstCodepoint, characters, bitmap));
        }
 public void MakeGlyphBitmapSubpixel(uint glyphIndex,
                                     float xScale, float yScale, float xShift, float yShift,
                                     FontBitmap bitmap)
 {
     if (bitmap.Buffer == null)
     {
         throw new ArgumentNullException("bitmap.Buffer");
     }
     stb_truetype.stbtt_MakeGlyphBitmapSubpixel(ref _info,
                                                bitmap.StartPointer, bitmap.Width, bitmap.Height, bitmap.Stride,
                                                xScale, yScale, xShift, yShift, glyphIndex);
 }
Beispiel #3
0
        public FontBitmap GetResizedBitmap(int width, int height)
        {
            var bitmap = new FontBitmap(width, height);
            int w = Math.Min(width, Width), h = Math.Min(height, Height);

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    bitmap[x, y] = this[x, y];
                }
            }
            return(bitmap);
        }
        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
            }));
        }
        // 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;
            }
        }
 public void MakeGlyphBitmap(int glyphIndex, float xScale, float yScale, FontBitmap bitmap)
 {
     MakeGlyphBitmapSubpixel(glyphIndex, xScale, yScale, 0, 0, bitmap);
 }