コード例 #1
0
ファイル: FontSystem.cs プロジェクト: kiates/SpriteFontPlus
 public void Dispose()
 {
     if (_fonts != null)
     {
         foreach (var font in _fonts)
         {
             font.Dispose();
         }
         _fonts.Clear();
     }
     Atlases?.Clear();
     _currentAtlas = null;
     _glyphs?.Clear();
 }
コード例 #2
0
ファイル: FontSystem.cs プロジェクト: kiates/SpriteFontPlus
        FontGlyph GetGlyphInternal(GraphicsDevice graphicsDevice, GlyphCollection glyphs, int codepoint)
        {
            var glyph = GetGlyphWithoutBitmap(glyphs, codepoint);

            if (glyph == null)
            {
                return(null);
            }

            if (graphicsDevice == null || glyph.Atlas != null)
            {
                return(glyph);
            }

            var currentAtlas = CurrentAtlas;
            int gx = 0, gy = 0;
            var gw = glyph.Bounds.Width;
            var gh = glyph.Bounds.Height;

            if (!currentAtlas.AddRect(gw, gh, ref gx, ref gy))
            {
                CurrentAtlasFull?.Invoke(this, EventArgs.Empty);

                // This code will force creation of new atlas
                _currentAtlas = null;
                currentAtlas  = CurrentAtlas;

                // Try to add again
                if (!currentAtlas.AddRect(gw, gh, ref gx, ref gy))
                {
                    throw new Exception(string.Format("Could not add rect to the newly created atlas. gw={0}, gh={1}", gw, gh));
                }
            }

            glyph.Bounds.X = gx;
            glyph.Bounds.Y = gy;

            currentAtlas.RenderGlyph(graphicsDevice, glyph, BlurAmount, StrokeAmount);

            glyph.Atlas = currentAtlas;

            return(glyph);
        }