internal static Bitmap RemakeTextureData(TextureInfo info)
        {
            FontDrawInfo stringInfo = info.Tag as FontDrawInfo;

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

            return(GetTextBitmap(stringInfo));
        }
        internal static Bitmap GetTextBitmap(FontDrawInfo info)
        {
            Tuple <int, int> fontkey = new Tuple <int, int>(info.FontID, info.FontSize);

            if (!FontCache.ContainsKey(fontkey))
            {
                FontCache.Add(fontkey, new Font(TypefaceCache[info.FontID], info.FontSize));
            }
            Font font = FontCache[fontkey];

            WorkspaceGraphics.Clear(Color.Transparent);
            var bounds = WorkspaceGraphics.MeasureString(info.Text, font);

            WorkspaceGraphics.DrawString(info.Text, font, Brushes.White, 10, 10);
            WorkspaceGraphics.Flush();

            Bitmap stringMap = Workspace.Clone(new Rectangle(10, 10, (int)(bounds.Width + 1), (int)(bounds.Height + 1)), PixelFormat.Format32bppArgb);

            return(stringMap);
        }
        public static FontDrawInfo DrawText(int fontID, int size, string text)
        {
            if (fontID < 0 || fontID >= TypefaceCache.Count)
            {
                return(null);
            }

            if (size < MiniumFontSize)
            {
                size = MiniumFontSize;
            }

            Tuple <int, int, string> infoId = new Tuple <int, int, string>(fontID, size, text);

            if (!StringCache.ContainsKey(infoId))
            {
                FontDrawInfo info = new FontDrawInfo();
                info.FontID   = fontID;
                info.FontSize = size;
                info.Text     = text;

                Bitmap stringMap = GetTextBitmap(info);

                info.CachedTexture = TextureManager.CreateTexture("FONTMAN:" + fontID.ToString() + ":" + size.ToString() + ":" + text, stringMap, TextureInfo.TextureFormats.Text);
                info.Size          = new Vector2(stringMap.Width, stringMap.Height);

                info.CachedTexture.Tag               = info;
                info.CachedTexture.CacheImageData    = false;
                info.CachedTexture.GenerateImageData = RemakeTextureData;

                StringCache.Add(infoId, info);

                return(info);
            }
            return(StringCache[infoId]);
        }