Ejemplo n.º 1
0
        public double GetKerning(uint UnicodeA, uint UnicodeB)
        {
            if (Msdfgen.GetKerning(Fnt, UnicodeA, UnicodeB, out double K))
            {
                return(K);
            }

            return(0);
        }
Ejemplo n.º 2
0
        public FreetypeFont(byte[] FontFile, int Size = 12, int AtlasW = 512, int AtlasH = 512)
        {
            GlyphTexture = new Dictionary <uint, Glyph>();
            Fnt          = Msdfgen.LoadFontMemory(FontFile);
            FontSize     = Size;

            TextureAtlas = Texture.Empty(AtlasW, AtlasH);
            Packer       = new RectanglePacker(AtlasW, AtlasH);
        }
Ejemplo n.º 3
0
        public Glyph?GetGlyph(uint Unicode)
        {
            if (GlyphTexture.ContainsKey(Unicode))
            {
                return(GlyphTexture[Unicode]);
            }

            FontCharacter FChar = new FontCharacter();

            if (Msdfgen.LoadGlyphNormal(Fnt, Unicode, ref FChar))
            {
                if (FChar.Width == 0 || FChar.Height == 0)
                {
                    if (!GlyphTexture.ContainsKey(Unicode))
                    {
                        GlyphTexture.Add(Unicode, new Glyph(FChar, null));
                    }

                    return(GetGlyph(Unicode));
                }

                Glyph G = new Glyph(FChar, FChar.GetBitmap());
                if (!Packer.Pack(G.Bitmap.Width, G.Bitmap.Height, out G.X, out G.Y))
                {
                    throw new NotImplementedException("Cannot pack glyph");
                }

                G.Bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
                TextureAtlas.SubRect2D(G.Bitmap, G.X, G.Y);
                G.Bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);

                GlyphTexture.Add(Unicode, G);
                return(GetGlyph(Unicode));
            }

            return(null);
        }