Beispiel #1
0
        GlyphBitmap GetGlyphBitmapFromBitmapFont(ushort glyphIndex)
        {
            //not found=> create a new one
            if (_typeface.IsBitmapFont)
            {
                //try load
                using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                {
                    //load actual bitmap font
                    Glyph glyph = _typeface.GetGlyph(glyphIndex);
                    _typeface.ReadBitmapContent(glyph, ms);

                    using (MemBitmap memBitmap = MemBitmapExt.LoadBitmap(ms))
                    {
                        //bitmap that are load may be larger than we need
                        //so we need to scale it to specfic size

                        float target_advW = _typeface.GetAdvanceWidthFromGlyphIndex(glyphIndex) * _px_scale;
                        float scaleForBmp = target_advW / memBitmap.Width;

                        MemBitmap scaledMemBmp = memBitmap.ScaleImage(scaleForBmp, scaleForBmp);

                        var glyphBitmap = new GlyphBitmap
                        {
                            Width  = scaledMemBmp.Width,
                            Height = scaledMemBmp.Height,
                            Bitmap = scaledMemBmp //**
                        };
                        return(glyphBitmap);
                    }
                }
            }
            return(null);
        }